blob: 37a5e3c4e534a49be563368df4ed73b55c023602 [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 Weltebe030482019-05-27 22:29:35 +0200248 rest_octets := '2C2B2B2B'O /* GPRS present */
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
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700470private function f_trxc_fake_rssi(TRXC_RSSI 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
Eric Wilde57e1a62019-05-28 13:30:55 +02001993/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
1994function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
1995 var L1ctlDlMessage l1_dl;
1996 var uint5_t ms_power_level := 7;
1997
1998 var RSL_IE_MS_Power ms_power;
1999 ms_power.reserved := 0;
2000 ms_power.fpc_epc := false;
2001 ms_power.power_level := ms_power_level;
2002
2003 f_l1_tune(L1CTL);
2004 RSL.clear;
2005
2006 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2007
2008 timer T := 1.0;
2009 T.start;
2010 alt {
2011 /* Pick all SACCH blocks for checking */
2012 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2013 /* The first byte of the L1 header contains the power level.. */
2014 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2015 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2016 }
2017 }
2018 /* Ignore all other blocks */
2019 [] L1CTL.receive { repeat; }
2020 [] T.timeout {
2021 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2022 }
2023 }
2024
2025 f_rsl_chan_deact();
2026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2027 setverdict(pass);
2028}
2029
2030testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2031 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2032 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2033}
2034
Harald Welte0472ab42018-03-12 15:02:26 +01002035/* 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 +01002036private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002037 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002038 RSL.clear;
2039
2040 f_est_dchan();
2041 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002042 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002043
2044 timer T := 40.0;
2045 T.start;
2046 alt {
2047 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2048 setverdict(pass)
2049 }
2050 [] RSL.receive { repeat };
2051 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002053 }
2054 }
2055 f_rsl_chan_deact();
2056}
2057testcase TC_conn_fail_crit() runs on test_CT {
2058 var ConnHdlr vc_conn;
2059 var ConnHdlrPars pars;
2060 f_init(testcasename());
2061 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2062 pars.t_guard := 60.0;
2063 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2064 vc_conn.done;
2065}
2066
Harald Welte93640c62018-02-25 16:59:33 +01002067/***********************************************************************
2068 * Paging
2069 ***********************************************************************/
2070
Harald Welte68e495b2018-02-25 00:05:57 +01002071function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2072 if (tmsi == 'FFFFFFFF'O) {
2073 return true;
2074 } else {
2075 return false;
2076 }
2077}
Harald Welte70767382018-02-21 12:16:40 +01002078
Philipp Maier82cb0b12018-08-31 14:41:39 +02002079type record allowedFn { integer frame_nr }
2080template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2081template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2082template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2083template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2084template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2085template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2086template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2087template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2088function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2089{
2090 var integer frame_nr_51;
2091 frame_nr_51 := frame_nr mod 51
2092
2093 var allowedFn fn_check;
2094 fn_check.frame_nr := frame_nr_51;
2095
2096 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002098 return;
2099 }
2100
2101 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2102 return;
2103 }
2104 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2105 return;
2106 }
2107 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2108 return;
2109 }
2110 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2111 return;
2112 }
2113 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2114 return;
2115 }
2116 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2117 return;
2118 }
2119 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2120 return;
2121 }
2122 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2123 return;
2124 }
2125
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002127 return;
2128}
2129
2130altstep 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 +01002131runs on test_CT {
2132 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002133 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002134 repeat;
2135 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002136 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002137 var octetstring without_plen :=
2138 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2139 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002140
2141 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2142
Harald Welte68e495b2018-02-25 00:05:57 +01002143 if (match(rr, tr_PAGING_REQ1)) {
2144 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2145 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2146 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2147 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2148 }
2149 } else if (match(rr, tr_PAGING_REQ2)) {
2150 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2151 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2152 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2153 }
2154 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2155 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2156 }
2157 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2158 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2159 }
2160 } else if (match(rr, tr_PAGING_REQ3)) {
2161 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2162 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2163 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2164 }
2165 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2166 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2167 }
2168 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2169 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2170 }
2171 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2172 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2173 }
2174 }
2175 repeat;
2176 }
2177}
2178
2179type record PagingTestCfg {
2180 boolean combined_ccch,
2181 integer bs_ag_blks_res,
2182 float load_factor,
2183 boolean exp_load_ind,
2184 boolean exp_overload,
2185 boolean use_tmsi
2186}
2187
2188type record PagingTestState {
2189 integer num_paging_sent,
2190 integer num_paging_rcv_msgs,
2191 integer num_paging_rcv_ids,
2192 integer num_overload
2193}
2194
2195/* receive + ignore RSL RF RES IND */
2196altstep as_rsl_res_ind() runs on test_CT {
2197 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2198 repeat;
2199 }
2200}
2201
2202/* Helper function for paging related testing */
2203private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2204 f_init(testcasename());
2205 f_init_l1ctl();
2206 f_l1_tune(L1CTL);
2207
2208 var PagingTestState st := {
2209 num_paging_sent := 0,
2210 num_paging_rcv_msgs := 0,
2211 num_paging_rcv_ids := 0,
2212 num_overload := 0
2213 };
2214
2215 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2216 var float max_pch_imsi_per_sec;
2217 if (cfg.use_tmsi) {
2218 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2219 } else {
2220 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2221 }
2222 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2223 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002224 var float time_total := 20.0;
2225 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2226 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002227
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002228 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2229 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002230
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002231 timer T_itv := 0.0;
2232 T_itv.start;
2233 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002234 alt {
2235 /* check for presence of CCCH LOAD IND (paging load) */
2236 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2237 st.num_overload := st.num_overload + 1;
2238 repeat;
2239 }
2240 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002242 }
2243 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2244 log("Rx LOAD_IND");
2245 /* FIXME: analyze/verify interval + contents */
2246 repeat;
2247 }
2248 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002249 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002250 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002251 [] T_itv.timeout {
2252 /* Send paging cmds based on elapsed time */
2253 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2254 while (st.num_paging_sent < new_sent) {
2255 /* build mobile Identity */
2256 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2257 if (cfg.use_tmsi) {
2258 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2259 } else {
2260 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2261 }
2262 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2263 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2264
2265 /* Send RSL PAGING COMMAND */
2266 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2267
2268 st.num_paging_sent := st.num_paging_sent + 1;
2269 }
2270 if (st.num_paging_sent < pkt_total) {
2271 /* Wait for interval to next PAGING COMMAND */
2272 var float time_now := T_total.read;
2273 var float next_sched := int2float(st.num_paging_sent)*interval;
2274 if (next_sched > time_now) {
2275 T_itv.start(next_sched - time_now);
2276 } else {
2277 T_itv.start(0.0);
2278 }
2279 } else {
2280 /* We are done, no need to keep counting */
2281 T_total.stop;
2282 }
2283 }
2284 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002285 [] as_rsl_res_ind();
2286 }
2287 }
2288
2289 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2290 timer T_wait := 18.0;
2291 T_wait.start;
2292 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002293 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002294 [] L1CTL.receive { repeat; }
2295 /* 65535 == empty paging queue, we can terminate*/
2296 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2297 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2298 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002300 }
2301 [] as_rsl_res_ind();
2302 }
2303
2304 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2305 " rcvd_ids=", st.num_paging_rcv_ids);
2306 return st;
2307}
2308
2309/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2310 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2311 * - that CCCH LOAD IND (PCH) are being generated
2312 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2313testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002314 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002315 var PagingTestCfg cfg := {
2316 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002317 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002318 load_factor := 0.8,
2319 exp_load_ind := true,
2320 exp_overload := false,
2321 use_tmsi := false
2322 };
2323 var PagingTestState st := f_TC_paging(cfg);
2324 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2326 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002327 } else {
2328 setverdict(pass);
2329 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002331}
2332
2333/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2334 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2335 * - that CCCH LOAD IND (PCH) are being generated
2336 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2337testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002338 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002339 var PagingTestCfg cfg := {
2340 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002341 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002342 load_factor := 0.8,
2343 exp_load_ind := true,
2344 exp_overload := false,
2345 use_tmsi := true
2346 };
2347 var PagingTestState st := f_TC_paging(cfg);
2348 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2350 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002351 } else {
2352 setverdict(pass);
2353 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002355}
2356
2357/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2358 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2359 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2360 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2361testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002362 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002363 var PagingTestCfg cfg := {
2364 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002365 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002366 load_factor := 2.0,
2367 exp_load_ind := true,
2368 exp_overload := true,
2369 use_tmsi := false
2370 };
2371 var PagingTestState st := f_TC_paging(cfg);
2372 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2373 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002374 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002375 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002376 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 +01002377 } else {
2378 setverdict(pass);
2379 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002381}
2382
2383/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2384 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2385 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2386 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2387testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002388 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002389 var PagingTestCfg cfg := {
2390 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002391 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002392 load_factor := 2.0,
2393 exp_load_ind := true,
2394 exp_overload := true,
2395 use_tmsi := true
2396 };
2397 var PagingTestState st := f_TC_paging(cfg);
2398 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2399 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002400 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002401 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002402 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 +01002403 } else {
2404 setverdict(pass);
2405 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002407}
2408
2409
Harald Welte93640c62018-02-25 16:59:33 +01002410/***********************************************************************
2411 * Immediate Assignment / AGCH
2412 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002413const MobileAllocation c_MA_null := {
2414 len := 0,
2415 ma := ''B
2416}
Harald Welte93640c62018-02-25 16:59:33 +01002417
Harald Weltee8d750e2018-06-10 21:41:35 +02002418template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2419 uint12_t arfcn := 871) := {
2420 chan_nr := chan_nr,
2421 tsc := tsc,
2422 h := false,
2423 arfcn := arfcn,
2424 maio_hsn := omit
2425}
2426
2427private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2428 return int2str(num_tx) & " sent, "
2429 & int2str(num_rx) & " received, "
2430 & int2str(num_del) & " deleted";
2431}
2432
2433private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2434 var L1ctlDlMessage l1_dl;
2435 timer T := 10.0;
2436 var integer num_tx := 0;
2437 var integer num_rx := 0;
2438 var integer num_del := 0;
2439 var charstring res_str;
2440 var float rx_ratio;
2441
Harald Welte68e495b2018-02-25 00:05:57 +01002442 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002443 f_init_l1ctl();
2444 f_l1_tune(L1CTL);
2445
2446 for (var integer i := 0; i < num_total; i := i+1) {
2447 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2448 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2449 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002450 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002451 num_tx := num_tx+1;
2452 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002453 }
2454 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002455 T.start;
2456 alt {
2457 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2458 num_del := num_del+1;
2459 repeat;
2460 }
2461 [] RSL_CCHAN.receive {
2462 repeat;
2463 }
2464 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2465 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2466 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2467 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2468 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002469 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002470 } else {
2471 num_rx := num_rx+1;
2472 }
2473 repeat;
2474 }
2475 [] L1CTL.receive { repeat; }
2476 [] T.timeout { }
2477 }
2478 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2479 log("AGCH test: " & res_str);
2480 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002482 }
2483 rx_ratio := int2float(num_rx) / int2float(num_tx);
2484 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002485 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 +02002486 } else {
2487 setverdict(pass);
2488 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002490}
2491
Harald Weltee8d750e2018-06-10 21:41:35 +02002492/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2493testcase TC_imm_ass_1000_20ms() runs on test_CT {
2494 f_TC_imm_ass(1000, 0.02, 0.25);
2495}
2496
2497/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2498testcase TC_imm_ass_200_0ms() runs on test_CT {
2499 f_TC_imm_ass(200, 0.0, 0.05);
2500}
2501
2502/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2503testcase TC_imm_ass_200_76ms() runs on test_CT {
2504 f_TC_imm_ass(150, 0.076, 1.00);
2505}
2506
2507
2508
Harald Welte48494ca2018-02-25 16:59:50 +01002509/***********************************************************************
2510 * BCCH
2511 ***********************************************************************/
2512
2513/* tuple of Frame Number + decoded SI */
2514type record SystemInformationFn {
2515 GsmFrameNumber frame_number,
2516 SystemInformation si
2517}
2518
2519/* an arbitrary-length vector of decoded SI + gsmtap header */
2520type record of SystemInformationFn SystemInformationVector;
2521
2522/* an array of SI-vectors indexed by TC value */
2523type SystemInformationVector SystemInformationVectorPerTc[8];
2524
2525/* determine if a given SI vector contains given SI type at least once */
2526function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2527 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2528 var integer fn_mod51 := arr[i].frame_number mod 51;
2529 if (not bcch_ext and fn_mod51 == 2 or
2530 bcch_ext and fn_mod51 == 6) {
2531 if (arr[i].si.header.message_type == key) {
2532 return true;
2533 }
2534 }
2535 }
2536 return false;
2537}
2538
2539/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2540function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2541 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002543 }
2544}
2545
2546/* check if a given SI vector contains given SI type at least once on any TC */
2547function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2548 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2549 if (f_si_vecslot_contains(arr[tc], key) or
2550 f_si_vecslot_contains(arr[tc], key, true)) {
2551 return true;
2552 }
2553 }
2554 return false;
2555}
2556
2557/* determine if a given SI vector contains given SI type at least N of M times */
2558function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2559 var integer count := 0;
2560 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002562 }
2563 for (var integer i:= 0; i < m; i := i + 1) {
2564 var integer fn_mod51 := arr[i].frame_number mod 51;
2565 if (not bcch_ext and fn_mod51 == 2 or
2566 bcch_ext and fn_mod51 == 6) {
2567 if (arr[i].si.header.message_type == key) {
2568 count := count + 1;
2569 }
2570 }
2571 }
2572 if (count >= n) {
2573 return true;
2574 } else {
2575 return false;
2576 }
2577}
2578
2579/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2580function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2581 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002583 }
2584}
2585
2586/* determine if a given SI vector contains given SI type at least once */
2587function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2588 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2589 var integer fn_mod51 := arr[i].frame_number mod 51;
2590 if (not bcch_ext and fn_mod51 == 2 or
2591 bcch_ext and fn_mod51 == 6) {
2592 if (arr[i].si.header.message_type != key) {
2593 return false;
2594 }
2595 }
2596 }
2597 return true;
2598}
2599
2600/* ensure a given TC slot of the SI vector contains only given SI type */
2601function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2602 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002604 }
2605}
2606
2607/* SI configuration of cell, against which we validate actual SI messages */
2608type set SystemInformationConfig {
2609 boolean bcch_extended,
2610 boolean si1_present,
2611 boolean si2bis_present,
2612 boolean si2ter_present,
2613 boolean si2quater_present,
2614 boolean si7_present,
2615 boolean si8_present,
2616 boolean si9_present,
2617 boolean si13_present,
2618 boolean si13alt_present,
2619 boolean si15_present,
2620 boolean si16_present,
2621 boolean si17_present,
2622 boolean si2n_present,
2623 boolean si21_present,
2624 boolean si22_present
2625}
2626
2627/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2628function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2629 var integer i;
2630 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2631 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002633 }
2634 }
2635 if (cfg.si1_present) {
2636 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2637 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2638 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2639 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2640 /* make sure *ALL* contain SI1 */
2641 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2642 }
2643 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2644 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2645 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2646 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2647 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2648 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2649
2650 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2651 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2652 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2653 * consecutive occurrences of TC = 4. */
2654 if (cfg.si2bis_present and not cfg.si2ter_present) {
2655 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2656 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2657 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2658 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2659 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2660 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2661 }
2662
2663 if (cfg.si7_present or cfg.si8_present) {
2664 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2665 * if System Information type 4 does not contain all information needed for cell
2666 * selection and reselection. */
2667 if (not cfg.bcch_extended) {
2668 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2669 }
2670 if (cfg.si7_present) {
2671 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2672 }
2673 if (cfg.si8_present) {
2674 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2675 }
2676 }
2677
2678 if (cfg.si2quater_present) {
2679 /* iii) System information type 2 quater is sent if needed, as determined by the system
2680 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2681 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2682 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2683 * within any of 4 consecutive occurrences of TC = 5. */
2684 if (not (cfg.bcch_extended)) {
2685 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2686 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2687 } else {
2688 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2689 }
2690 } else {
2691 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2692 }
2693 }
2694 if (cfg.si9_present) {
2695 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2696 * in system information type 3 as defined in 3GPP TS 44.018. */
2697 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2698 }
2699 if (cfg.si13_present) {
2700 /* vii) System Information type 13 is only related to the GPRS service. System Information
2701 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2702 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2703 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2704 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2705 * within any of 4 consecutive occurrences of TC=4. */
2706 if (not cfg.bcch_extended) {
2707 log("not-bccch-extended");
2708 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2709 } else {
2710 log("bccch-extended");
2711 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2712 }
2713 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002715 }
2716 }
2717 if (cfg.si16_present or cfg.si17_present) {
2718 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2719 * should not be sent in a cell where network sharing is used (see rule xv). */
2720 if (cfg.si22_present) {
2721 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2722 }
2723 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002725 }
2726 if (not cfg.bcch_extended) {
2727 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2728 }
2729 if (cfg.si16_present) {
2730 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2731 }
2732 if (cfg.si17_present) {
2733 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2734 }
2735 }
2736
2737 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2738 * broadcast information. The frequency with which they are sent is determined by the
2739 * system operator. System Information type 9 identifies the scheduling of System
2740 * Information type 18 and 20 messages. */
2741
2742 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2743 * Information Type 19 is present, then its scheduling shall be indicated in System
2744 * Information Type 9. */
2745
2746 if (cfg.si15_present) {
2747 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2748 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2749 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2750 * 4 consecutive occurrences of TC = 1. */
2751 if (not cfg.bcch_extended) {
2752 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2753 } else {
2754 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2755 }
2756 }
2757 if (cfg.si13alt_present) {
2758 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2759 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2760 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2761 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2762 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2763 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2764 * of TC = 4. */
2765 if (cfg.si13_present) {
2766 testcase.stop("Error: Cannot have SI13alt and SI13");
2767 }
2768 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002770 }
2771 if (not cfg.bcch_extended) {
2772 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2773 } else {
2774 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2775 }
2776 }
2777 if (cfg.si2n_present) {
2778 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2779 * as determined by the system operator. In the case that the message is sent on the
2780 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2781 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2782 * consecutive occurrences of TC = 4. */
2783 if (not cfg.bcch_extended) {
2784 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2785 } else {
2786 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2787 }
2788 }
2789 if (cfg.si21_present) {
2790 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2791 * determined by the system operator. If Extended Access Barring is in use in the cell
2792 * then this message is sent at least once within any of 4 consecutive occurrences of
2793 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2794 * cell then this message shall only be sent on BCCH Ext. */
2795 if (not cfg.bcch_extended) {
2796 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2797 } else {
2798 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2799 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002801 }
2802 }
2803 }
2804 if (cfg.si22_present) {
2805 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2806 * should not be sent in a cell where SoLSA is used (see rule viii). System
2807 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2808 * =2 and TC=6. */
2809 if (cfg.si16_present or cfg.si17_present) {
2810 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2811 }
2812 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2813 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002815 }
2816 if (not cfg.bcch_extended) {
2817 testcase.stop("Error: SI22 requires BCCH Extd!");
2818 } else {
2819 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2820 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2821 }
2822 }
2823}
2824
2825/* sample Systme Information for specified duration via L1CTL */
2826function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2827 timer T := duration;
2828 var SystemInformationVectorPerTc si_per_tc;
2829 var L1ctlDlMessage l1_dl;
2830
2831 /* initialize all per-TC vectors empty */
2832 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2833 si_per_tc[i] := {};
2834 }
2835
2836 /* flush all previous L1 queued msgs */
2837 pt.clear;
2838
2839 T.start;
2840 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002841 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002842 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2843 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2844 log("Ignoring non-RR SI ", l1_dl);
2845 repeat;
2846 }
2847 var SystemInformationFn sig := {
2848 frame_number := l1_dl.dl_info.frame_nr,
2849 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2850 }
2851 var integer tc := f_gsm_compute_tc(sig.frame_number);
2852 log("SI received at TC=", tc, ": ", sig.si);
2853 /* append to the per-TC bucket */
2854 si_per_tc[tc] := si_per_tc[tc] & { sig };
2855 repeat;
2856 }
2857 [] pt.receive { repeat; }
2858 [] T.timeout { }
2859 }
2860
2861 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2862 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2863 }
2864 log("si_per_tc=", si_per_tc);
2865 return si_per_tc;
2866}
2867
2868/* helper function: Set given SI via RSL + validate scheduling.
2869 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2870function f_TC_si_sched() runs on test_CT {
2871 var SystemInformationVectorPerTc si_per_tc;
2872 f_init_l1ctl();
2873 f_l1_tune(L1CTL);
2874
2875 /* Sample + Validate Scheduling */
2876 si_per_tc := f_l1_sample_si(L1CTL);
2877 f_validate_si_scheduling(si_cfg, si_per_tc);
2878
2879 setverdict(pass);
2880}
2881
2882testcase TC_si_sched_default() runs on test_CT {
2883 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002884 /* 2+3+4 are mandatory and set in f_init() */
2885 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002887}
2888
2889testcase TC_si_sched_1() runs on test_CT {
2890 f_init();
2891 si_cfg.si1_present := true;
2892 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'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_2bis() 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 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002903}
2904
2905testcase TC_si_sched_2ter() runs on test_CT {
2906 f_init();
2907 si_cfg.si2ter_present := true;
2908 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2909 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002911}
2912
2913testcase TC_si_sched_2ter_2bis() runs on test_CT {
2914 f_init();
2915 si_cfg.si2bis_present := true;
2916 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2917 si_cfg.si2ter_present := true;
2918 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2919 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002921}
2922
2923testcase TC_si_sched_2quater() runs on test_CT {
2924 f_init();
2925 si_cfg.si2quater_present := true;
2926 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2927 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002929}
2930
2931testcase TC_si_sched_13() runs on test_CT {
2932 f_init();
2933 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002934 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002935 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002937}
2938
2939testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2940 f_init();
2941 si_cfg.si2bis_present := true;
2942 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2943 si_cfg.si2ter_present := true;
2944 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2945 si_cfg.si2quater_present := true;
2946 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2947 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002948 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002949 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002951}
2952
2953
Harald Welte68e495b2018-02-25 00:05:57 +01002954testcase TC_bcch_info() runs on test_CT {
2955 f_init(testcasename());
2956 /* FIXME: enable / disable individual BCCH info */
2957 //ts_RSL_BCCH_INFO(si_type, info);
2958 /* expect no ERROR REPORT after either of them *
2959 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002961}
2962
Harald Welte93640c62018-02-25 16:59:33 +01002963/***********************************************************************
2964 * Low-Level Protocol Errors / ERROR REPORT
2965 ***********************************************************************/
2966
Harald Welte01d982c2018-02-25 01:31:40 +01002967private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2968 timer T := 5.0;
2969 T.start;
2970 alt {
2971 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2972 setverdict(pass);
2973 }
2974 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002976 }
2977 [] RSL_CCHAN.receive {
2978 repeat;
2979 }
2980 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002982 }
2983 }
2984}
2985
2986/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2987testcase TC_rsl_protocol_error() runs on test_CT {
2988 f_init(testcasename());
2989 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2990 rsl.ies := omit;
2991 RSL_CCHAN.send(ts_RSL_UD(rsl));
2992
2993 f_exp_err_rep(RSL_ERR_PROTO);
2994}
2995
2996/* Provoke a mandatory IE error and match on ERROR REPORT */
2997testcase TC_rsl_mand_ie_error() runs on test_CT {
2998 f_init(testcasename());
2999
3000 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3001 rsl.ies := { rsl.ies[0] };
3002 RSL_CCHAN.send(ts_RSL_UD(rsl));
3003
3004 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3005}
3006
3007/* Provoke an IE content error and match on ERROR REPORT */
3008testcase TC_rsl_ie_content_error() runs on test_CT {
3009 f_init(testcasename());
3010 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3011 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3012 RSL_CCHAN.send(ts_RSL_UD(rsl));
3013
3014 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3015}
3016
Harald Welteee25aae2019-05-19 14:32:37 +02003017/* attempt to activate channel with wrong RSL Message Discriminator IE */
3018function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3019 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3020 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3021 RSL.send(rsl);
3022 f_rslem_unregister(0, g_chan_nr);
3023}
3024testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3025 var ConnHdlr vc_conn;
3026 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3027
3028 f_init(testcasename());
3029
3030 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3031 vc_conn.done;
3032 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3033
3034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3035}
3036
3037/* Send messages with wrong message type */
3038function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3039 var template (value) RSL_Message rsl_tx;
3040 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3041 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3042 RSL.send(rsl_tx);
3043 f_rslem_unregister(0, g_chan_nr);
3044}
3045function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3046 var template (value) RSL_Message rsl_tx;
3047 /* we first have to activate the dedicated channel */
3048 f_rsl_chan_act(g_pars.chan_mode);
3049 /* ... to then send an invalid RLL message */
3050 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3051 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3052 RSL.send(rsl_tx);
3053 f_rslem_unregister(0, g_chan_nr);
3054}
3055testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3056 var ConnHdlr vc_conn;
3057 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3058 var template (value) RSL_Message rsl_tx;
3059
3060 f_init(testcasename());
3061
3062 /* Common Channel with wrong message type */
3063 RSL_CCHAN.clear;
3064 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3065 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3066 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3067 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3068
3069 /* TRX Management */
3070 RSL_CCHAN.clear;
3071 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3072 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3073 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3074 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3075
3076 /* Dedicated Channel */
3077 RSL_CCHAN.clear;
3078 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3079 vc_conn.done;
3080 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3081
3082 /* RLL */
3083 RSL_CCHAN.clear;
3084 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3085 vc_conn.done;
3086 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3087}
3088
3089/* Send messages in wrong sequence (RLL to an inactive lchan) */
3090function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3091 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3092 f_rslem_unregister(0, g_chan_nr);
3093}
3094testcase TC_err_rep_wrong_sequence() runs on test_CT {
3095 var ConnHdlr vc_conn;
3096 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3097
3098 f_init(testcasename());
3099
3100 RSL_CCHAN.clear;
3101 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3102 vc_conn.done;
3103 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3104}
3105
Harald Welte93640c62018-02-25 16:59:33 +01003106/***********************************************************************
3107 * IPA CRCX/MDCX/DLCS media stream handling
3108 ***********************************************************************/
3109
Harald Weltea871a382018-02-25 02:03:14 +01003110/* Send IPA DLCX to inactive lchan */
3111function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003112 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3113 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003114}
3115testcase TC_ipa_dlcx_not_active() runs on test_CT {
3116 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3117 f_init(testcasename());
3118 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3119 vc_conn.done;
3120}
Harald Welte68e495b2018-02-25 00:05:57 +01003121
Harald Weltea3f1df92018-02-25 12:49:55 +01003122/* Send IPA CRCX twice to inactive lchan */
3123function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3124 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3125 "IPA CRCX ACK");
3126 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3127 "IPA CRCX NACK");
3128}
3129testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3130 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3131 f_init(testcasename());
3132 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3133 vc_conn.done;
3134}
3135
3136/* Regular sequence of CRCX/MDCX/DLCX */
3137function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3138 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3139 "IPA CRCX ACK");
3140 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3141 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3142 var uint7_t rtp_pt2 := f_rnd_int(127);
3143 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3144 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3145 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3146 "IPA MDCX ACK");
3147 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3148 "IPA DLCX ACK");
3149}
3150testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3151 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3152 f_init(testcasename());
3153 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3154 vc_conn.done;
3155}
3156
Harald Welte3ae11da2018-02-25 13:36:06 +01003157/* Sequence of CRCX, 2x MDCX, DLCX */
3158function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3159 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3160 "IPA CRCX ACK");
3161 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3162 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3163 var uint7_t rtp_pt2 := f_rnd_int(127);
3164 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3165 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3166 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3167 "IPA MDCX ACK");
3168 /* Second MDCX */
3169 remote_ip := f_rnd_int(c_UINT32_MAX);
3170 remote_port := f_rnd_int(c_UINT16_MAX);
3171 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3172 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3173 "IPA MDCX ACK");
3174 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3175 "IPA DLCX ACK");
3176}
3177testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3178 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3179 f_init(testcasename());
3180 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3181 vc_conn.done;
3182}
3183
Harald Welte9912eb52018-02-25 13:30:15 +01003184/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3185function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3186 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3187 "IPA CRCX NACK");
3188}
3189testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3190 var ConnHdlrPars pars;
3191 var ConnHdlr vc_conn;
3192 f_init(testcasename());
3193
3194 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3195 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3196 vc_conn.done;
3197
3198 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3199 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3200 vc_conn.done;
3201}
3202
Harald Weltea3f1df92018-02-25 12:49:55 +01003203
Harald Welte883340c2018-02-28 18:59:29 +01003204/***********************************************************************
3205 * PCU Socket related tests
3206 ***********************************************************************/
3207
Harald Welte07bd2d22019-05-25 11:03:30 +02003208/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003209friend 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 +01003210runs on test_CT {
3211 timer T := 3.0;
3212
3213 /* we don't expect any RTS.req before PDCH are active */
3214 T.start;
3215 alt {
3216 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003218 }
3219 [] PCU.receive { repeat; }
3220 [] T.timeout { }
3221 }
3222
3223 /* Send PDCH activate request for known PDCH timeslot */
3224 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3225
3226 /* we now expect RTS.req for this timeslot (only) */
3227 T.start;
3228 alt {
3229 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3230 setverdict(pass);
3231 }
3232 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3233 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003235 }
3236 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003238 }
3239 [] PCU.receive { repeat; }
3240 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003242 }
3243 [not exp_success] T.timeout {
3244 setverdict(pass);
3245 }
3246 }
3247}
3248
Harald Welte07bd2d22019-05-25 11:03:30 +02003249/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003250friend 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 +01003251runs on test_CT {
3252 timer T := 3.0;
3253
3254 /* Send PDCH activate request for known PDCH timeslot */
3255 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3256
3257 PCU.clear;
3258 /* we now expect no RTS.req for this timeslot */
3259 T.start;
3260 alt {
3261 [] 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 +02003262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003263 }
3264 [] PCU.receive { repeat; }
3265 [] T.timeout {
3266 setverdict(pass);
3267 }
3268 }
3269}
3270
Harald Weltead033dc2019-05-25 17:28:16 +02003271friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003272 f_init();
3273 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3274}
3275
Harald Welte883340c2018-02-28 18:59:29 +01003276/* PDCH activation via PCU socket; check for presence of RTS.req */
3277testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003278 f_init_pcu_test();
3279
Harald Welte883340c2018-02-28 18:59:29 +01003280 f_TC_pcu_act_req(0, 0, 7, true);
3281}
3282
3283/* PDCH activation via PCU socket on non-PDCU timeslot */
3284testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003285 f_init_pcu_test();
3286
Harald Welte883340c2018-02-28 18:59:29 +01003287 f_TC_pcu_act_req(0, 0, 1, false);
3288}
3289
3290/* PDCH activation via PCU socket on wrong BTS */
3291testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003292 f_init_pcu_test();
3293
Harald Welte883340c2018-02-28 18:59:29 +01003294 f_TC_pcu_act_req(23, 0, 7, false);
3295}
3296
3297/* PDCH activation via PCU socket on wrong TRX */
3298testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003299 f_init_pcu_test();
3300
Harald Welte883340c2018-02-28 18:59:29 +01003301 f_TC_pcu_act_req(0, 23, 7, false);
3302}
3303
3304/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3305testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003306 f_init_pcu_test();
3307
Harald Welte883340c2018-02-28 18:59:29 +01003308 /* Activate PDCH */
3309 f_TC_pcu_act_req(0, 0, 7, true);
3310 f_sleep(1.0);
3311 /* and De-Activate again */
3312 f_TC_pcu_deact_req(0, 0, 7);
3313}
3314
3315/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3316testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003317 f_init_pcu_test();
3318
Harald Welte883340c2018-02-28 18:59:29 +01003319 f_TC_pcu_deact_req(0, 0, 1);
3320}
3321
3322/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3323testcase TC_pcu_ver_si13() runs on test_CT {
3324 const octetstring si13 := '00010203040506070909'O;
3325 var PCUIF_send_data sd;
3326 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003327 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003328
3329 /* Set SI13 via RSL */
3330 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003331
Harald Welte883340c2018-02-28 18:59:29 +01003332 T.start;
3333 alt {
3334 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3335 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3336 setverdict(pass);
3337 } else {
3338 repeat;
3339 }
3340 }
3341 [] PCU.receive { repeat; }
3342 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003344 }
3345 }
3346}
3347
3348private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3349
3350/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003351friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003352 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3353runs on test_CT
3354{
3355 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3356 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3357}
3358
3359/* 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 +02003360friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3361 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003362runs on test_CT
3363{
3364 var PCUIF_send_data sd;
3365
3366 timer T := 3.0;
3367 T.start;
3368 alt {
3369 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3370 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3371 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3372 sd.data.u.rts_req.fn, sapi, data);
3373 }
3374 [] PCU.receive { repeat; }
3375 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003377 }
3378 }
3379}
3380
3381/* Send DATA.req on invalid BTS */
3382testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003383 var TfiUsfArr tua := f_TfiUsfArrInit();
3384 var octetstring data := '0000'O & f_rnd_octstring(21);
3385
3386 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003387
Harald Welte883340c2018-02-28 18:59:29 +01003388 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003389 f_TfiUsfArrSet(tua, 7, 0);
3390 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3391 f_sleep(1.0);
3392
3393 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003394}
3395
3396/* Send DATA.req on invalid TRX */
3397testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003398 var TfiUsfArr tua := f_TfiUsfArrInit();
3399 var octetstring data := '0000'O & f_rnd_octstring(21);
3400
3401 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003402
Harald Welte883340c2018-02-28 18:59:29 +01003403 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003404 f_TfiUsfArrSet(tua, 7, 0);
3405 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3406 f_sleep(1.0);
3407
3408 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003409}
3410
3411/* Send DATA.req on invalid timeslot */
3412testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003413 var TfiUsfArr tua := f_TfiUsfArrInit();
3414 var octetstring data := '0000'O & f_rnd_octstring(21);
3415
3416 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003417
Harald Welte883340c2018-02-28 18:59:29 +01003418 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003419 f_TfiUsfArrSet(tua, 7, 0);
3420 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3421 f_sleep(1.0);
3422
3423 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003424}
3425
3426/* Send DATA.req on timeslot that hasn't been activated */
3427testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003428 var TfiUsfArr tua := f_TfiUsfArrInit();
3429 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003430
Harald Welte7162a612019-05-26 12:56:09 +02003431 f_virtphy_common();
3432
3433 f_TfiUsfArrSet(tua, 7, 0);
3434 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3435 f_sleep(1.0);
3436
3437 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003438}
3439
Harald Weltead033dc2019-05-25 17:28:16 +02003440private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003441 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3442 boolean wait_rts := true)
3443runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003444 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003445 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003446
3447 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003448 if (wait_rts) {
3449 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3450 } else {
3451 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3452 }
Harald Weltead033dc2019-05-25 17:28:16 +02003453
3454 T.start;
3455 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003456 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003457 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3458 setverdict(pass);
3459 }
Harald Welte7162a612019-05-26 12:56:09 +02003460 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3461 setverdict(fail, "Received unexpected ", rx_dl);
3462 }
Harald Weltead033dc2019-05-25 17:28:16 +02003463 [] L1CTL.receive {
3464 repeat;
3465 }
Harald Welte7162a612019-05-26 12:56:09 +02003466 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003467 setverdict(fail, "Timeout waiting for ", data);
3468 }
Harald Welte7162a612019-05-26 12:56:09 +02003469 [not expect_data] T.timeout {
3470 setverdict(pass);
3471 }
Harald Weltead033dc2019-05-25 17:28:16 +02003472 }
3473}
3474
3475private function f_disable_dynamic_ts() runs on test_CT
3476{
3477 f_init_vty_bsc();
3478 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3479 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3480 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3481 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003482 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003483}
3484
3485private function f_virtphy_common() runs on test_CT {
3486 f_disable_dynamic_ts();
3487 f_init_l1ctl();
3488 f_l1_tune(L1CTL);
3489}
3490
3491testcase TC_pcu_data_req_pdtch() runs on test_CT {
3492 var TfiUsfArr tua := f_TfiUsfArrInit();
3493 var octetstring data := '0000'O & f_rnd_octstring(21);
3494
3495 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003496
Harald Welte883340c2018-02-28 18:59:29 +01003497 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003498 f_TfiUsfArrSet(tua, 7, 0);
3499 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3500 f_sleep(1.0);
3501
3502 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003503}
3504
3505testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003506 var TfiUsfArr tua := f_TfiUsfArrInit();
3507 var octetstring data := '0000'O & f_rnd_octstring(21);
3508
3509 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003510
Harald Welte883340c2018-02-28 18:59:29 +01003511 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003512 f_TfiUsfArrSet(tua, 7, 0);
3513 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3514 f_sleep(1.0);
3515
3516 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003517}
3518
3519/* Send AGCH from PCU; check it appears on Um side */
3520testcase TC_pcu_data_req_agch() runs on test_CT {
3521 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003522 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003523 f_init_l1ctl();
3524 f_l1_tune(L1CTL);
3525
3526 f_TC_pcu_act_req(0, 0, 7, true);
3527 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3528
3529 T.start;
3530 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003531 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003532 setverdict(pass);
3533 }
3534 [] L1CTL.receive { repeat; }
3535 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003537 }
3538 }
3539}
3540
Harald Welte928622b2019-05-26 13:22:59 +02003541/* Send AGCH from PCU; check it appears on Um side */
3542testcase TC_pcu_data_req_pch() runs on test_CT {
3543 timer T := 3.0;
3544 f_init_pcu_test();
3545 f_init_l1ctl();
3546 f_l1_tune(L1CTL);
3547
3548 f_TC_pcu_act_req(0, 0, 7, true);
3549 /* three characters prefix: last 3 digits of IMSI as ASCII */
3550 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3551
3552 T.start;
3553 alt {
3554 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3555 setverdict(pass);
3556 }
3557 [] L1CTL.receive { repeat; }
3558 [] T.timeout {
3559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3560 }
3561 }
3562}
3563
Harald Welte883340c2018-02-28 18:59:29 +01003564/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3565testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3566 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003567 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003568 f_init_l1ctl();
3569 f_l1_tune(L1CTL);
3570
3571 /* append 3 last imsi digits so BTS can compute pagng group */
3572 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3573
3574 timer T := 0.5;
3575 T.start;
3576 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003577 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003578 /* TODO: verify paging group */
3579 setverdict(pass);
3580 }
3581 [] L1CTL.receive { repeat; }
3582 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003584 }
3585 }
3586}
3587
3588/* Send RACH from Um side, expect it to show up on PCU socket */
3589testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003590 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003591 f_init_l1ctl();
3592 f_l1_tune(L1CTL);
3593
3594 var GsmFrameNumber fn_last := 0;
3595 for (var integer i := 0; i < 1000; i := i+1) {
3596 var OCT1 ra := f_rnd_ra_ps();
3597 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3598 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003600 }
3601 fn_last := fn;
3602
3603 timer T := 2.0;
3604 T.start;
3605 alt {
3606 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3607 T.stop;
3608 }
3609 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003611 }
3612 [] PCU.receive { repeat; }
3613 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003615 }
3616 }
3617 }
3618 setverdict(pass);
3619}
3620
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003621/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3622 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3623testcase TC_pcu_ext_rach_content() runs on test_CT {
3624 var template PCUIF_Message pcu_rach_ind;
3625 var GsmFrameNumber fn_last := 0;
3626 var L1ctlRachSynchSeq synch_seq;
3627 var PCUIF_BurstType pcu_bt;
3628 var GsmFrameNumber fn;
3629 var BIT11 ra11;
3630
3631 f_init_pcu_test();
3632 f_init_l1ctl();
3633 f_l1_tune(L1CTL);
3634
3635 for (var integer i := 0; i < 1000; i := i+1) {
3636 /* We need to test both TS1 & TS2 */
3637 if (i rem 2 == 0) {
3638 synch_seq := RACH_SYNCH_SEQ_TS1;
3639 pcu_bt := BURST_TYPE_1;
3640 } else {
3641 synch_seq := RACH_SYNCH_SEQ_TS2;
3642 pcu_bt := BURST_TYPE_2;
3643 }
3644
3645 ra11 := f_rnd_ra11_ps();
3646 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3647 if (fn == fn_last) {
3648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3649 "Two RACH in same FN?!?");
3650 }
3651 fn_last := fn;
3652
3653 /* Compose the expected message */
3654 pcu_rach_ind := tr_PCUIF_RACH_IND(
3655 bts_nr := 0,
3656 ra := bit2int(ra11),
3657 is_11bit := 1,
3658 burst_type := pcu_bt,
3659 fn := fn);
3660
3661 timer T := 2.0;
3662 T.start;
3663 alt {
3664 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3665 T.stop;
3666 }
3667 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3669 }
3670 [] PCU.receive { repeat; }
3671 [] T.timeout {
3672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3673 }
3674 }
3675 }
3676 setverdict(pass);
3677}
3678
Harald Welte883340c2018-02-28 18:59:29 +01003679/* Send PAGING via RSL, expect it to shw up on PCU socket */
3680testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003681 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003682
3683 for (var integer i := 0; i < 100; i := i+1) {
3684 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3685 timer T := 3.0;
3686 if (i < 50) {
3687 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3688 } else {
3689 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3690 }
3691 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3692 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3693 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3694
3695 /* Send RSL PAGING COMMAND */
3696 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3697 T.start;
3698 alt {
3699 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3700 }
3701 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003703 }
3704 [] PCU.receive { repeat; }
3705 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003707 }
3708 }
3709 }
3710 setverdict(pass);
3711}
3712
Harald Welted66c9b82019-05-25 09:03:15 +02003713/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3714testcase TC_pcu_time_ind() runs on test_CT {
3715 var PCUIF_send_data pcu_sd;
3716 var integer num_time_ind := 0;
3717 var integer first_fn, last_fn;
3718 var float test_duration := 5.0;
3719 timer T;
3720
3721 f_init_pcu_test();
3722 f_TC_pcu_act_req(0, 0, 7, true);
3723
3724 PCU.clear;
3725 T.start(test_duration);
3726 alt {
3727 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3728 num_time_ind := num_time_ind + 1;
3729 if (not isbound(first_fn)) {
3730 first_fn := pcu_sd.data.u.time_ind.fn;
3731 }
3732 last_fn := pcu_sd.data.u.time_ind.fn;
3733 repeat;
3734 }
3735 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3736 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3737 repeat;
3738 }
3739 [] PCU.receive {
3740 repeat;
3741 }
3742 [] T.timeout {}
3743 }
3744 var integer fn_expired := last_fn - first_fn;
3745 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3746
3747 /* verify the number of frames expired matches our expectation */
3748 const float c_GSM_FN_DURATION_MS := 4.61538;
3749 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003750 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003751 if (not match(fn_expired, t_fn_expected)) {
3752 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3753 }
3754
3755 /* There are three TIME.ind in every fn MOD 13 */
3756 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3757 /* Add some tolerance */
3758 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3759 if (not match(num_time_ind, t_time_ind_exp)) {
3760 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3761 }
3762
3763 setverdict(pass);
3764}
3765
Harald Welte4832c862019-05-25 14:57:18 +02003766/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3767testcase TC_pcu_rts_req() runs on test_CT {
3768 var PCUIF_send_data pcu_sd;
3769 var integer first_fn, last_fn;
3770 var integer num_rts_pdtch := 0;
3771 var integer num_rts_ptcch := 0;
3772 var float test_duration := 5.0;
3773 timer T;
3774
3775 f_init_pcu_test();
3776 f_TC_pcu_act_req(0, 0, 7, true);
3777
3778 PCU.clear;
3779 T.start(test_duration);
3780 alt {
3781 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3782 -> value pcu_sd {
3783 num_rts_pdtch := num_rts_pdtch + 1;
3784 if (not isbound(first_fn)) {
3785 first_fn := pcu_sd.data.u.rts_req.fn;
3786 }
3787 last_fn := pcu_sd.data.u.rts_req.fn;
3788 repeat;
3789 }
3790 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3791 -> value pcu_sd {
3792 num_rts_ptcch := num_rts_ptcch + 1;
3793 if (not isbound(first_fn)) {
3794 first_fn := pcu_sd.data.u.rts_req.fn;
3795 }
3796 last_fn := pcu_sd.data.u.rts_req.fn;
3797 repeat;
3798 }
3799 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3800 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3801 repeat;
3802 }
3803 [] PCU.receive {
3804 repeat;
3805 }
3806 [] T.timeout {}
3807 }
3808 var integer fn_expired := last_fn - first_fn;
3809 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3810 ", num_rts_ptcch=", num_rts_ptcch);
3811
3812 /* verify the number of frames expired matches our expectation */
3813 const float c_GSM_FN_DURATION_MS := 4.61538;
3814 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003815 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003816 if (not match(fn_expired, t_fn_expected)) {
3817 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3818 }
3819
3820 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3821 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3822 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3823 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3824 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3825 t_ptcch_exp);
3826 }
3827
3828 /* We have 12 PDTCH blocks every 52-multiframe */
3829 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3830 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3831 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3832 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3833 t_pdtch_exp);
3834 }
3835
3836 setverdict(pass);
3837}
3838
Harald Welte07bd2d22019-05-25 11:03:30 +02003839/* test for generating Abis side OML ALERT from the PCU */
3840testcase TC_pcu_oml_alert() runs on test_CT {
3841 var PCUIF_send_data pcu_sd;
3842 var integer num_time_ind := 0;
3843 var integer first_fn, last_fn;
3844 var float test_duration := 5.0;
3845 timer T;
3846
3847 f_init_pcu_test();
3848 f_TC_pcu_act_req(0, 0, 7, true);
3849
3850 /* re-connect CTRL port from BTS to BSC */
3851 f_ipa_ctrl_stop();
3852 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3853
3854 /* Send that OML Alert */
3855 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3856
3857 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3858 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3859 setverdict(pass);
3860}
3861
Harald Welteeaa9a862019-05-26 23:01:08 +02003862template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3863 template (value) RoutingAreaIdentificationV rai,
3864 template (value) OCT1 cause) := {
3865 discriminator := '0000'B, /* overwritten */
3866 tiOrSkip := {
3867 skipIndicator := '0000'B
3868 },
3869 msgs := {
3870 rrm := {
3871 gPRS_suspensionRequest := {
3872 messageType := '00110100'B,
3873 tLLI := tlli,
3874 routingAreaIdentification := rai,
3875 suspensionCause := cause,
3876 service_Support := omit
3877 }
3878 }
3879 }
3880}
3881
3882/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3883private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3884 var PCUIF_Message first_info;
3885 var integer pcu_conn_id := -1;
3886 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3887 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3888 var OCT4 tlli := '01020304'O;
3889 var OCT1 cause := '23'O;
3890 timer T := 5.0;
3891
3892 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3893
3894 f_l1_tune(L1CTL);
3895 RSL.clear;
3896
3897 f_est_dchan();
3898 L1CTL.clear;
3899
3900 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3901
3902 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3903 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3904 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3905
3906 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3907 T.start;
3908 alt {
3909 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3910 setverdict(pass);
3911 }
3912 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3913 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3914 }
3915 [] PCU.receive {
3916 repeat;
3917 }
3918 [] T.timeout {
3919 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3920 }
3921 }
3922}
3923testcase TC_pcu_rr_suspend() runs on test_CT {
3924 var ConnHdlrPars pars;
3925 var ConnHdlr vc_conn;
3926
3927 f_init();
3928
3929 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3930 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3931 vc_conn.done;
3932}
Harald Welte07bd2d22019-05-25 11:03:30 +02003933
Harald Weltea2e0e942019-05-27 18:12:53 +02003934/* Ensure that PCUIF socket can accept only a single connection */
3935testcase TC_pcu_socket_connect_multi() runs on test_CT {
3936 timer T := 5.0;
3937
3938 /* this (among other things) establishes the first connection to the PCUIF socket */
3939 f_init();
3940
3941 /* try to establish a second connection, expect it to fail */
3942 PCU.send(UD_connect:{mp_pcu_socket, -1});
3943 T.start;
3944 alt {
3945 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
3946 setverdict(pass);
3947 }
3948 [] PCU.receive(UD_connect_result:?) {
3949 setverdict(fail, "Unexpected unix domain connect result");
3950 }
3951 [] T.timeout {
3952 setverdict(pass);
3953 }
3954 }
3955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3956}
3957
Harald Weltec8effb72019-05-27 18:23:04 +02003958/* Ensure that PCUIF socket can disconnect + reconnect */
3959testcase TC_pcu_socket_reconnect() runs on test_CT {
3960 /* this (among other things) establishes the first connection to the PCUIF socket */
3961 f_init();
3962
3963 f_sleep(1.0);
3964
3965 f_pcuif_close(PCU, g_pcu_conn_id);
3966 g_pcu_conn_id := -1;
3967
3968 f_sleep(1.0);
3969
3970 /* re-connect */
3971 PCU.clear;
3972 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
3973 setverdict(pass);
3974
3975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3976}
3977
Harald Weltebe030482019-05-27 22:29:35 +02003978/* Ensure that GPRS capability is not advertised before PCU socket conncet */
3979private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
3980 var L1ctlDlMessage l1_dl;
3981 var SystemInformation si;
3982 timer T := 5.0;
3983 T.start;
3984 alt {
3985 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
3986 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3987 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3988 log("Ignoring non-RR SI ", l1_dl);
3989 repeat;
3990 }
3991 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3992 if (not ischosen(si.payload.si3)) {
3993 repeat;
3994 }
3995 }
3996 [] pt.receive {
3997 repeat;
3998 }
3999 [] T.timeout {
4000 setverdict(fail, "Timeout waiting for SI3");
4001 }
4002 }
4003 return si.payload.si3;
4004}
4005
4006/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4007private function f_bitpos_is_inv(integer idx) return boolean {
4008 select (idx mod 8) {
4009 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4010 case else { return false; } /* 0-bits of 0x2B */
4011 }
4012}
4013/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4014private function f_bit_is_high(bitstring str, integer idx) return boolean {
4015 var boolean invert := f_bitpos_is_inv(idx);
4016 if (invert) {
4017 if (str[idx] == '1'B) {
4018 return false;
4019 } else {
4020 return true;
4021 }
4022 } else {
4023 if (str[idx] == '1'B) {
4024 return true;
4025 } else {
4026 return false;
4027 }
4028 }
4029}
4030/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4031 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4032 we can replace this piece of code soon ... */
4033private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4034 var bitstring bits := oct2bit(si3_restoctets);
4035 var integer idx := 0;
4036
4037 if (f_bit_is_high(bits, idx)) {
4038 /* skip Optional selection parameters */
4039 idx := idx + 16;
4040 } else {
4041 idx := idx + 1;
4042 }
4043
4044 if (f_bit_is_high(bits, idx)) {
4045 /* skip Optional power offset */
4046 idx := idx + 3;
4047 } else {
4048 idx := idx + 1;
4049 }
4050
4051 /* skip SI2ter Indicator */
4052 idx := idx + 1;
4053
4054 /* skip Early CM Sending Control */
4055 idx := idx + 1;
4056
4057 /* skip Scheduling if and where */
4058 if (f_bit_is_high(bits, idx)) {
4059 idx := idx + 4;
4060 } else {
4061 idx := idx + 1;
4062 }
4063
4064 return f_bit_is_high(bits, idx);
4065}
4066
4067testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4068 var SystemInformationType3 si3;
4069 timer T := 5.0;
4070
4071 /* don't call f_init() as this would connect PCU socket */
4072 f_init_rsl(testcasename());
4073 T.start;
4074 alt {
4075 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4076 [] T.timeout {
4077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4078 }
4079 }
4080 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4081
4082 f_init_l1ctl();
4083 f_l1_tune(L1CTL);
4084
4085 f_sleep(2.0);
4086 L1CTL.clear;
4087 si3 := f_get_si3(L1CTL);
4088 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4089 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4090 } else {
4091 setverdict(pass);
4092 }
4093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4094}
4095
4096/* Ensure that GPRS capability is advertised after PCU socket connect */
4097testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4098 var SystemInformationType3 si3;
4099
4100 /* this (among other things) establishes the first connection to the PCUIF socket */
4101 f_init();
4102 f_init_l1ctl();
4103 f_l1_tune(L1CTL);
4104
4105 f_sleep(2.0);
4106 L1CTL.clear;
4107 si3 := f_get_si3(L1CTL);
4108 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4109 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4110 } else {
4111 setverdict(pass);
4112 }
4113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4114}
4115
4116/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4117testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4118 var SystemInformationType3 si3;
4119
4120 /* this (among other things) establishes the first connection to the PCUIF socket */
4121 f_init();
4122 f_init_l1ctl();
4123 f_l1_tune(L1CTL);
4124
4125 f_pcuif_close(PCU, g_pcu_conn_id);
4126 g_pcu_conn_id := -1;
4127
4128 f_sleep(1.0);
4129
4130 /* re-connect */
4131 PCU.clear;
4132 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4133
4134 f_sleep(2.0);
4135 L1CTL.clear;
4136 si3 := f_get_si3(L1CTL);
4137 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4138 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4139 } else {
4140 setverdict(pass);
4141 }
4142
4143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4144}
4145
Harald Welted66c9b82019-05-25 09:03:15 +02004146
Harald Welte3d04ae62018-04-04 20:29:05 +02004147/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004148 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004149 ***********************************************************************/
4150
4151private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4152runs on ConnHdlr {
4153 var PCUIF_send_data sd;
4154 /* Expect BTS to immediately acknowledge activation as PDCH */
4155 PCU.clear;
4156 f_rsl_chan_act(g_pars.chan_mode);
4157 /* expect INFO_IND on PCU interface listing TS as PDCH */
4158 alt {
4159 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4160 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 +02004161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004162 }
4163 }
4164 [] PCU.receive { repeat; }
4165 }
4166 /* try to activate this PDCH from the PCU point of view */
4167 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4168 /* FIXME: is there a response? */
4169}
4170
4171private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4172runs on ConnHdlr {
4173 var PCUIF_send_data sd;
4174 /* Send RSL CHAN REL (deactivate) */
4175 PCU.clear;
4176 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4177 /* expect BTS to ask PCU to deactivate the channel */
4178 alt {
4179 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4180 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 +02004181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004182 }
4183 }
4184 [] PCU.receive { repeat; }
4185 }
4186 /* Emulate PCU asking BTS to deactivate PDCH */
4187 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4188 alt {
4189 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4190 setverdict(pass);
4191 }
4192 [] RSL.receive { repeat; }
4193 }
4194}
4195
4196/* Activate Osmocom-style dynamic PDCH from BSC side */
4197function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4198 var PCUIF_Message first_info;
4199 var integer ts_nr := g_chan_nr.tn;
4200 var integer trx_nr := 0;
4201 var integer bts_nr := 0;
4202 var integer pcu_conn_id := -1;
4203
4204 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4205
4206 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4207 f_sleep(3.0);
4208 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4209 setverdict(pass);
4210}
4211testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4212 var ConnHdlrPars pars;
4213 var ConnHdlr vc_conn;
4214 f_init(testcasename());
4215
4216 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4217 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4218 vc_conn.done;
4219}
4220
4221/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4222function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4223 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004224 var integer pcu_conn_id := -1;
4225
4226 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4227
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004228 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4229 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4230 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004231 setverdict(pass);
4232}
4233testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4234 var ConnHdlrPars pars;
4235 var ConnHdlr vc_conn;
4236 f_init(testcasename());
4237
4238 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4239 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4240 vc_conn.done;
4241}
4242
4243/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4244function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4245 var PCUIF_Message first_info;
4246 var integer ts_nr := g_chan_nr.tn;
4247 var integer trx_nr := 0;
4248 var integer bts_nr := 0;
4249 var integer pcu_conn_id := -1;
4250
4251 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4252
4253 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004254 /* Send a second Chan Activ and expect it to be NACKed */
4255 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4256 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004257 setverdict(pass);
4258}
4259testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4260 var ConnHdlrPars pars;
4261 var ConnHdlr vc_conn;
4262 f_init(testcasename());
4263
4264 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4265 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4266 vc_conn.done;
4267}
4268
4269/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4270function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4271 var PCUIF_Message first_info;
4272 var integer ts_nr := g_chan_nr.tn;
4273 var integer trx_nr := 0;
4274 var integer bts_nr := 0;
4275 var integer pcu_conn_id := -1;
4276 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4277
4278 /* register for the TCH/F channel number */
4279 f_rslem_register(0, chan_nr);
4280
4281 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4282
4283 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4284 "RSL CHAN ACT");
4285 setverdict(pass);
4286}
4287testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4288 var ConnHdlrPars pars;
4289 var ConnHdlr vc_conn;
4290 f_init(testcasename());
4291
4292 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4293 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4294 vc_conn.done;
4295}
4296
4297/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4298function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4299 var PCUIF_Message first_info;
4300 var integer ts_nr := g_chan_nr.tn;
4301 var integer trx_nr := 0;
4302 var integer bts_nr := 0;
4303 var integer pcu_conn_id := -1;
4304 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4305 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4306
4307 /* register for the TCH/H channel numbers */
4308 f_rslem_register(0, chan_nr[0]);
4309 f_rslem_register(0, chan_nr[1]);
4310
4311 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4312
4313 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4314 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4315 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4316 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4317 setverdict(pass);
4318}
4319testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4320 var ConnHdlrPars pars;
4321 var ConnHdlr vc_conn;
4322 f_init(testcasename());
4323
4324 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4325 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4326 vc_conn.done;
4327}
4328
Harald Welte9bbbfb52018-04-05 09:33:19 +02004329/***********************************************************************
4330 * IPA Style Dynamic Timeslot Support
4331 ***********************************************************************/
4332
4333private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4334runs on ConnHdlr {
4335 var PCUIF_send_data sd;
4336 /* Expect BTS to immediately acknowledge activation as PDCH */
4337 PCU.clear;
4338 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4339 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004340 timer T_wait := 2.0;
4341 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004342 alt {
4343 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4344 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 +01004345 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4346 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4347 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004348 }
4349 }
4350 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004351 [] T_wait.timeout {
4352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4353 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4354 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004355 }
4356 /* try to activate this PDCH from the PCU point of view */
4357 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4358 /* FIXME: is there a response? */
4359
4360 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4361}
4362
4363private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4364runs on ConnHdlr {
4365 var PCUIF_send_data sd;
4366 /* Send RSL CHAN REL (deactivate) */
4367 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4368 PCU.clear;
4369 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004370 timer T_wait := 2.0;
4371 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004372 alt {
4373 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4374 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 +01004375 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4376 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4377 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004378 }
4379 }
4380 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004381 [] T_wait.timeout {
4382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4383 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4384 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004385 }
4386 /* Emulate PCU asking BTS to deactivate PDCH */
4387 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4388 alt {
4389 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4390 setverdict(pass);
4391 }
4392 [] RSL.receive { repeat; }
4393 }
4394}
4395
4396/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4397function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4398 var PCUIF_Message first_info;
4399 var integer ts_nr := g_chan_nr.tn;
4400 var integer trx_nr := 0;
4401 var integer bts_nr := 0;
4402 var integer pcu_conn_id := -1;
4403
4404 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4405
4406 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4407 f_sleep(3.0);
4408 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4409
4410 setverdict(pass);
4411
4412}
4413testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4414 var ConnHdlrPars pars;
4415 var ConnHdlr vc_conn;
4416 f_init();
4417
4418 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4419 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4420 vc_conn.done;
4421}
4422
4423/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4424function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4425 var PCUIF_Message first_info;
4426 var integer ts_nr := g_chan_nr.tn;
4427 var integer trx_nr := 0;
4428 var integer bts_nr := 0;
4429 var integer pcu_conn_id := -1;
4430
4431 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4432
4433 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4434 "RSL CHAN ACT");
4435 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4436 "RF CHAN REL", true);
4437 setverdict(pass);
4438}
4439testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4440 var ConnHdlrPars pars;
4441 var ConnHdlr vc_conn;
4442 f_init(testcasename());
4443
4444 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4445 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4446 vc_conn.done;
4447}
4448
4449/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4450function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4451 var PCUIF_Message first_info;
4452 var integer ts_nr := g_chan_nr.tn;
4453 var integer trx_nr := 0;
4454 var integer bts_nr := 0;
4455 var integer pcu_conn_id := -1;
4456
4457 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4458
4459 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4460 "RSL CHAN ACT");
4461
4462 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4463 alt {
4464 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4465 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004467 }
4468 [] RSL.receive { repeat; }
4469 }
4470
4471 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4472 "RF CHAN REL", true);
4473 setverdict(pass);
4474}
4475testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4476 var ConnHdlrPars pars;
4477 var ConnHdlr vc_conn;
4478 f_init(testcasename());
4479
4480 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4481 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4482 vc_conn.done;
4483}
4484
4485/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4486function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4487 var PCUIF_Message first_info;
4488 var integer ts_nr := g_chan_nr.tn;
4489 var integer trx_nr := 0;
4490 var integer bts_nr := 0;
4491 var integer pcu_conn_id := -1;
4492
4493 /* register for the TCH/F channel number */
4494 f_rslem_register(0, g_chan_nr);
4495
4496 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4497
4498 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4499
4500 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4501 "RSL CHAN ACT");
4502
4503 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4504
4505 setverdict(pass);
4506}
4507testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4508 var ConnHdlrPars pars;
4509 var ConnHdlr vc_conn;
4510 f_init(testcasename());
4511
4512 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4513 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4514 vc_conn.done;
4515}
4516
4517
Harald Welte0472ab42018-03-12 15:02:26 +01004518/***********************************************************************
4519 * LAPDm / RLL related
4520 ***********************************************************************/
4521
4522private function f_tx_lapdm(template (value) LapdmFrame l,
4523 template (value) RslLinkId link_id) runs on ConnHdlr {
4524 var octetstring l2 := enc_LapdmFrame(valueof(l));
4525 if (valueof(link_id.c) == SACCH) {
4526 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004527 var L1ctlDataReq l1hl2 := {
4528 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4529 l2_payload := f_pad_oct(l2, 21, '2B'O)
4530 }
4531 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4532 } else {
4533 /* If required, pad L2 frame with constant 0x2b filling */
4534 l2 := f_pad_oct(l2, 23, '2B'O);
4535
4536 log("encoding ", l, " to ", l2);
4537 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004538 }
Harald Welte0472ab42018-03-12 15:02:26 +01004539}
4540
4541type record RllTestCase {
4542 uint3_t sapi,
4543 RslLinkId link_id,
4544 octetstring l3,
4545 boolean exp
4546}
4547type record of RllTestCase RllTestCases;
4548template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4549 sapi := sapi,
4550 link_id := id,
4551 l3 := l3,
4552 exp := exp
4553}
4554
4555/* execute the same callback function with a set of different parameters (tcs) on a
4556 * variety of logical channels */
4557private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4558 var ConnHdlrPars pars;
4559 var ConnHdlr vc_conn;
4560 f_init(testcasename());
4561
4562 /* test on each of the channels we have */
4563 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4564 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4565
4566 /* test each of the test cases on the current channel */
4567 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4568 pars.spec.rll := tcs[j];
4569 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4570 vc_conn := f_start_handler(fn, pars);
4571 vc_conn.done;
4572 }
4573 }
4574
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004576}
4577
4578/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4579private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4580 var RllTestCase tc := g_pars.spec.rll;
4581 timer T := 3.0;
4582
4583 f_l1_tune(L1CTL);
4584 RSL.clear;
4585
4586 /* activate the logical channel */
4587 f_est_dchan();
4588 L1CTL.clear;
4589
4590 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4591 T.start;
4592 alt {
4593 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4594 if (tc.exp) {
4595 setverdict(pass);
4596 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004598 }
4599 }
4600 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4601 if (tc.exp) {
4602 setverdict(pass);
4603 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004605 }
4606 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004607 /* We also expect to receive the measurements */
4608 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004609 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004611 }
4612 [not tc.exp] T.timeout {
4613 setverdict(pass);
4614 }
4615 }
4616
4617 f_rsl_chan_deact();
4618 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4619 f_rslem_unregister(0, g_chan_nr);
4620}
4621testcase TC_rll_est_ind() runs on test_CT {
4622 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004623 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004624 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004625 /* normal SAPI0 establishment */
4626 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004627 /* SAPI 3 doesn't support contention resolution */
4628 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4629 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4630 /* normal SAPI3 establishment on main DCCH */
4631 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4632 /* normal SAPI3 establishment on SACCH */
4633 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4634 };
4635 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4636}
4637
4638/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4639private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4640 var RllTestCase tc := g_pars.spec.rll;
4641 var L1ctlDlMessage dl;
4642 timer T := 3.0;
4643
4644 f_l1_tune(L1CTL);
4645 RSL.clear;
4646
4647 /* activate the logical channel */
4648 f_est_dchan();
4649 L1CTL.clear;
4650
4651 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4652 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4653 T.start;
4654 alt {
4655 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4656 var LapdmFrame lapdm;
4657 var octetstring l2 := dl.payload.data_ind.payload;
4658 if (dl.dl_info.link_id.c == SACCH) {
4659 /* remove L1 header */
4660 l2 := substr(l2, 2, lengthof(l2)-2);
4661 }
4662 lapdm.ab := dec_LapdmFrameAB(l2);
4663 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4664 setverdict(pass);
4665 } else {
4666 repeat;
4667 }
4668 }
4669 [] L1CTL.receive { repeat; }
4670 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004672 }
4673 }
4674
4675 f_rsl_chan_deact();
4676 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4677 f_rslem_unregister(0, g_chan_nr);
4678}
4679testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4680 var RllTestCases tcs := {
4681 /* normal SAPI3 establishment on main DCCH */
4682 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4683 };
4684 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4685}
4686testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4687 var RllTestCases tcs := {
4688 /* normal SAPI3 establishment on SACCH */
4689 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4690 }
4691 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4692}
4693
4694/* altstep to receive a LAPDm frame matching the given template */
4695private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4696 var L1ctlDlMessage dl;
4697 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4698 var LapdmFrame lapdm;
4699 var octetstring l2 := dl.payload.data_ind.payload;
4700 if (dl.dl_info.link_id.c == SACCH) {
4701 /* remove L1 header */
4702 l2 := substr(l2, 2, lengthof(l2)-2);
4703 }
4704 if (ischosen(exp.ab)) {
4705 lapdm.ab := dec_LapdmFrameAB(l2);
4706 } else if (ischosen(exp.b4)) {
4707 lapdm.b4 := dec_LapdmFrameB4(l2);
4708 } else if (ischosen(exp.bbis)) {
4709 lapdm.bbis := dec_LapdmFrameBbis(l2);
4710 }
4711 log("Rx LAPDm ", lapdm);
4712 if (match(lapdm, exp)) {
4713 setverdict(pass);
4714 } else {
4715 repeat;
4716 }
4717 }
4718 [] L1CTL.receive { repeat; }
4719}
4720private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4721 timer T := t;
4722 T.start;
4723 alt {
4724 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004726 }
4727 [] as_l1_exp_lapdm(exp);
4728 }
4729}
4730
4731/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4732private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4733 /* send SABM from MS -> BTS */
4734 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4735 /* expect RLL EST IND on Abis */
4736 alt {
4737 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4738 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4739 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004741 }
4742 [] RSL.receive { repeat; }
4743 }
4744 /* expect UA from BTS -> MS */
4745 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4746}
4747
4748/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4749private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4750 var RllTestCase tc := g_pars.spec.rll;
4751
4752 f_l1_tune(L1CTL);
4753 RSL.clear;
4754
4755 /* activate the logical channel */
4756 f_est_dchan();
4757 L1CTL.clear;
4758
4759 /* first establish the link-layer */
4760 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4761
4762 /* then send the DISC */
4763 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4764 /* ... and expect the REL IND on the RSL side */
4765 alt {
4766 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4767 setverdict(pass);
4768 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004769 /* We also expect to receive the measurements */
4770 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004771 }
4772
4773 /* release the channel */
4774 f_rsl_chan_deact();
4775 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4776 f_rslem_unregister(0, g_chan_nr);
4777}
4778testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4779 var RllTestCases tcs := {
4780 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4781 };
4782 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4783}
4784
4785testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4786 var RllTestCases tcs := {
4787 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4788 };
4789 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4790}
4791testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4792 var RllTestCases tcs := {
4793 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4794 };
4795 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4796}
4797testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4798 var RllTestCases tcs := {
4799 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4800 };
4801 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4802}
4803
4804/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4805private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4806 var RllTestCase tc := g_pars.spec.rll;
4807 f_l1_tune(L1CTL);
4808 RSL.clear;
4809
4810 /* activate the logical channel */
4811 f_est_dchan();
4812 L1CTL.clear;
4813
4814 /* first establish the link-layer */
4815 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4816
4817 /* then send the REL REQ via RSL */
4818 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4819 /* ... and expect the DISC on the Um side */
4820 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004821 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004822 /* FIXME: send a UA in resposne to the DISC */
4823 }
4824 }
4825
4826 /* release the channel */
4827 f_rsl_chan_deact();
4828 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4829 f_rslem_unregister(0, g_chan_nr);
4830}
4831testcase TC_rll_rel_req() runs on test_CT {
4832 var RllTestCases tcs := {
4833 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4834 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4835 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4836 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4837 };
4838 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4839}
4840
4841/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4842testcase TC_rll_data_req() runs on test_CT {
4843}
4844
4845/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4846testcase TC_rll_data_ind() runs on test_CT {
4847}
4848
4849/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4850private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4851 var RllTestCase tc := g_pars.spec.rll;
4852
4853 f_l1_tune(L1CTL);
4854 RSL.clear;
4855
4856 f_est_dchan();
4857 L1CTL.clear;
4858
4859 /* Send UNITDATA REQ on RSL side */
4860 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4861 /* Expect it to arrive on the other side */
4862 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004863 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004864 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004865 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004866 }
4867
4868 /* release the channel */
4869 f_rsl_chan_deact();
4870 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4871 f_rslem_unregister(0, g_chan_nr);
4872}
4873testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4874 var octetstring l3 := f_rnd_octstring(15);
4875 var RllTestCases tcs := {
4876 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4877 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4878 };
4879 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4880}
4881testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4882 var octetstring l3 := f_rnd_octstring(19);
4883 var RllTestCases tcs := {
4884 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4885 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4886 };
4887 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4888}
4889
4890/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4891private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4892 var RllTestCase tc := g_pars.spec.rll;
4893
4894 f_l1_tune(L1CTL);
4895 RSL.clear;
4896
4897 f_est_dchan();
4898 L1CTL.clear;
4899
4900 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004901 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004902 /* Expdct RLL UNITDATA IND on RSL side */
4903 alt {
4904 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4905 setverdict(pass);
4906 }
4907 [] RSL.receive { repeat; }
4908 }
4909
4910 /* release the channel */
4911 f_rsl_chan_deact();
4912 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4913 f_rslem_unregister(0, g_chan_nr);
4914}
4915testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004916 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004917 var RllTestCases tcs := {
4918 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4919 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4920 };
4921 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4922}
4923testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4924 var octetstring l3 := f_rnd_octstring(18);
4925 var RllTestCases tcs := {
4926 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4927 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4928 };
4929 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4930}
4931
Harald Weltee613f962018-04-18 22:38:16 +02004932/***********************************************************************
4933 * Encryption Related
4934 ***********************************************************************/
4935
4936/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4937function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4938 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4939 if (link_id.c == SACCH) {
4940 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4941 } else {
4942 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4943 }
4944}
4945
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004946/* Expect (or not expect) other kinds of messages */
4947private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4948 [exp_any] RSL.receive { repeat; }
4949 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004951 }
4952}
4953
Harald Weltee613f962018-04-18 22:38:16 +02004954/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004955private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004956 RslLinkId link_id,
4957 octetstring l3,
4958 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004959 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004960) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004961 timer T := 3.0;
4962 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4963 T.start;
4964 /* Expect RLL UNITDATA IND on RSL side */
4965 alt {
4966 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4967 setverdict(pass);
4968 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004969 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004970 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004971 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004973 }
Harald Weltee613f962018-04-18 22:38:16 +02004974 }
4975}
4976
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004977/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4978private function f_data_mo(
4979 RslLinkId link_id,
4980 boolean p, uint3_t nr, uint3_t ns,
4981 octetstring l3,
4982 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004983 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004984) runs on ConnHdlr {
4985 timer T := 3.0;
4986 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4987 T.start;
4988 /* Expect RLL DATA IND on RSL side */
4989 alt {
4990 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4991 setverdict(pass);
4992 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004993 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004994 [] as_rsl_any_ind(exp_any);
4995 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004997 }
4998 }
4999}
5000
Harald Weltee613f962018-04-18 22:38:16 +02005001/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5002function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5003 f_l1_tune(L1CTL);
5004 f_est_dchan(true);
5005
5006 /* now we actually need to transmit some data both ways to check if the encryption works */
5007 var L1ctlDlMessage dl;
5008
Stefan Sperling603d98e2018-07-25 16:47:28 +02005009 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005010 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5011
5012 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5013 f_unitdata_mt(link_id, l3);
5014
5015 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5016 f_unitdata_mo(link_id, l3);
5017
5018 /* release the channel */
5019 f_rsl_chan_deact();
5020 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5021 f_rslem_unregister(0, g_chan_nr);
5022}
5023testcase TC_chan_act_a51() runs on test_CT {
5024 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5025 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5026 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5027}
5028testcase TC_chan_act_a52() runs on test_CT {
5029 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5030 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5031 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5032}
5033testcase TC_chan_act_a53() runs on test_CT {
5034 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5035 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5036 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5037}
5038
Eric Wildf1827a72019-05-28 17:37:35 +02005039/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5040 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5041function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5042 f_l1_tune(L1CTL);
5043 f_est_dchan(true);
5044
5045 /* now we actually need to transmit some data both ways to check if the encryption works */
5046 var L1ctlDlMessage dl;
5047
5048 var octetstring l3 := f_rnd_octstring(20);
5049 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5050
5051 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5052 f_unitdata_mt(link_id, l3);
5053
5054 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5055 f_unitdata_mo(link_id, l3);
5056
5057 var RSL_Message rsl;
5058 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5059
5060 /* modify key to break proper encryption */
5061 g_pars.encr.key := f_rnd_octstring(8);
5062 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5063 rsl.ies := rsl.ies & { ei };
5064 RSL.send(rsl);
5065
5066 timer T0 := 1.0;
5067 T0.start;
5068 /* Expect RSL MODIFY ACK */
5069 alt {
5070 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5071 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5073 }
5074 [] T0.timeout {
5075 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5076 }
5077 }
5078
5079 var octetstring l3msg := f_rnd_octstring(15);
5080 timer T1 := 3.0;
5081 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5082 due to broken encryption */
5083 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5084 T1.start;
5085 alt {
5086 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5088 }
5089 [] T1.timeout {
5090 setverdict(pass);
5091 }
5092 }
5093
5094 /* release the channel */
5095 f_rsl_chan_deact();
5096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5097 f_rslem_unregister(0, g_chan_nr);
5098}
5099testcase TC_rsl_modify_encr() runs on test_CT {
5100 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5101 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5102 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5103}
Harald Weltee613f962018-04-18 22:38:16 +02005104
5105/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5106function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5107 /* L3 payload doesn't matter, as it is passed transparently */
5108 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5109 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5110 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5111
5112 f_l1_tune(L1CTL);
5113
5114 /* first establish a dedicated channel in the clear */
5115 f_est_dchan(false);
5116
5117 /* Establish ABM */
5118 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5119
5120 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5121 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5122 /* expect the L3 to arrive still unencrypted on the MS side */
5123 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5124
5125 /* configure L1 to apply ciphering */
5126 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5127 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5128
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005129 /* send first ciphered I-frame in response and expect it on RSL */
5130 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005131
5132 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5133 * and hence enable encryption also on the downlink */
5134
5135 /* expect bi-directional communication work in encrypted mode */
5136 f_unitdata_mo(link_id, f_rnd_octstring(15));
5137 f_unitdata_mt(link_id, f_rnd_octstring(15));
5138
5139 /* release the channel */
5140 f_rsl_chan_deact();
5141 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5142 f_rslem_unregister(0, g_chan_nr);
5143}
5144testcase TC_encr_cmd_a51() runs on test_CT {
5145 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5146 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5147 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5148}
5149testcase TC_encr_cmd_a52() runs on test_CT {
5150 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5151 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5152 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5153}
5154testcase TC_encr_cmd_a53() runs on test_CT {
5155 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5156 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5157 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5158}
5159
5160private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5161 var LapdmFrame lf;
5162 var octetstring reenc;
5163
5164 /* decode the LAPDm frame */
5165 if (ischosen(exp_match.ab)) {
5166 lf.ab := dec_LapdmFrameAB(enc);
5167 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005169 }
5170
5171 /* check if decoder result matches expectation */
5172 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005174 } else {
5175 log(name, ": matched");
5176 setverdict(pass);
5177 }
5178
5179 /* test if re-encoded frame equals original input */
5180 reenc := enc_LapdmFrame(lf);
5181 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005183 } else {
5184 setverdict(pass);
5185 }
5186}
5187
5188testcase TC_lapdm_selftest() runs on test_CT {
5189 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5190 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5191 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5192 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5193 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5194 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5195 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5196}
5197
Stefan Sperling4880be42018-08-07 18:12:59 +02005198/***********************************************************************
5199 * DTX Related (see GSM 05.08, section 8.3)
5200 ***********************************************************************/
5201
5202/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5203function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5204 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5205 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5206 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5207 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5208}
5209function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5210 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5211 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5212}
5213function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5214 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5215 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5216 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5217 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5218}
5219function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5220 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5221 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5222 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5223 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5224 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5225 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5226 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5227 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5228}
5229
5230function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5231 var L1ctlDlMessage dl;
5232 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5233 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5234 var GsmFrameNumber first_fn;
5235 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005236 var integer nfill_frames_sacch := 0;
5237 var integer nfill_frames_nonsacch := 0;
5238 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005239 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5240 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005241 const integer frame_dtx_tchf_mod := 104;
5242 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5243 * which operates in terms of blocks rather than frames. */
5244 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5245 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005246 timer T := 5.0;
5247
5248 f_l1_tune(L1CTL);
5249 RSL.clear;
5250 L1CTL.clear;
5251
5252 /* activate TCHF signalling channel */
5253 f_est_dchan(false);
5254
5255 T.start;
5256 alt {
5257 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5258 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5259 var octetstring l2 := dl.payload.data_ind.payload;
5260
5261 if (is_first_frame) {
5262 is_first_frame := false;
5263 first_fn := dl.dl_info.frame_nr;
5264 }
5265
5266 if (dl.dl_info.link_id.c == SACCH) {
5267 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5268 if (not match(l2_fill_frame_sacch, l2)) {
5269 repeat;
5270 }
5271 } else if (not match(l2_fill_frame, l2)) {
5272 repeat;
5273 }
5274
5275 if (dtxd) {
5276 if (not f_g_chan_is_tchf()) {
5277 T.stop;
5278 f_rsl_chan_deact();
5279 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005280 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 +02005281 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005282 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005283 T.stop;
5284 f_rsl_chan_deact();
5285 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005286
5287 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5288 * 2 SACCH, 1 TCH/F */
5289 expected_fill_frames := 3;
5290
5291 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5292 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5293 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005295 } else {
5296 setverdict(pass);
5297 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005298 } else {
5299 if (dl.dl_info.link_id.c == SACCH) {
5300 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005301 repeat;
5302 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005303 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5304 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5305 * we should only see the subset of frames numbers which correspond to a block boundary.
5306 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5307 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5308 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5309 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5310 repeat;
5311 }
5312 }
5313 log("Received DTX TCH fill frame with bad frame number: ", fn,
5314 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5315 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5316 f_rsl_chan_deact();
5317 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005319 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005320 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005321 if (dl.dl_info.link_id.c == SACCH) {
5322 nfill_frames_sacch := nfill_frames_sacch + 1;
5323 } else {
5324 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5325 }
5326 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005327 T.stop;
5328 if (f_g_chan_is_tchf()) {
5329 /* Without DTX we can expect 25 fill frames for every 104 frames.
5330 * (24 FACCH + 1 SACCH filling) */
5331 expected_fill_frames := 25;
5332 } else if (f_g_chan_is_tchh()) {
5333 /* We can expect 2 fill frames for every 104 frames. */
5334 expected_fill_frames := 2;
5335 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5336 /* We can expect 5 fill frames for every 104 frames. */
5337 expected_fill_frames := 5;
5338 } else {
5339 f_rsl_chan_deact();
5340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005342 }
5343
5344 f_rsl_chan_deact();
5345 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005346
5347 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005348 setverdict(pass);
5349 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005350 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5351 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005353 }
5354 } else {
5355 repeat;
5356 }
5357 }
5358 }
5359 [] L1CTL.receive { repeat; }
5360 [] T.timeout {
5361 f_rsl_chan_deact();
5362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005364 }
5365 }
5366}
5367
5368function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5369 f_test_l2_fill_frames(false);
5370}
5371
5372function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5373 f_test_l2_fill_frames(true);
5374}
5375
5376function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5377 var ConnHdlr vc_conn;
5378 var ConnHdlrPars pars;
5379 pars.t_guard := 60.0;
5380 f_init(testcasename());
5381 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5382 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5383 if (dtxd) {
5384 if (i >= 4) { /* DTX is only allowed on TCH/F */
5385 break;
5386 }
5387 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5388 } else {
5389 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5390 }
5391 vc_conn.done;
5392 }
5393}
5394
5395/* Verify that L2 fill frames are sent on TCH in signaling mode if
5396 * there is nothing to transmit while DTX is disabled on downlink. */
5397testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5398 f_tch_sign_l2_fill_frame(false);
5399}
5400
5401/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5402 * there is nothing to transmit while DTX is enabled on downlink. */
5403testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5404 f_tch_sign_l2_fill_frame(true);
5405}
Harald Welte0472ab42018-03-12 15:02:26 +01005406
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005407testcase TC_chopped_ipa_ping() runs on test_CT {
5408 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5409}
5410
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005411testcase TC_chopped_ipa_payload() runs on test_CT {
5412 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5413}
5414
Harald Welte0472ab42018-03-12 15:02:26 +01005415/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5416/* protocol error as per 44.006 */
5417/* link layer failure (repetition of I-frame N200 times without ACK */
5418/* repetition of SABM or DISC N200 times without ACK */
5419/* receptiom of SABM in multi-frame established state */
5420
5421
Harald Welte68e495b2018-02-25 00:05:57 +01005422/* TODO Areas:
5423
5424* channel activation
5425** with BS_Power / MS_Power, bypassing power control loop
5426** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005427** with timing advance from initial activation on
5428* mode modify
5429** encryption
5430** multirate
5431* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005432** unsupported algorithm
5433* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005434* BS Power Control
5435* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005436* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005437* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005438** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005439* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005440** DATA_IND from BTS->PCU
5441** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005442
5443*/
Harald Welte70767382018-02-21 12:16:40 +01005444
5445control {
5446 execute( TC_chan_act_stress() );
5447 execute( TC_chan_act_react() );
5448 execute( TC_chan_deact_not_active() );
5449 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005450 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005451 execute( TC_sacch_filling() );
5452 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005453 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005454 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005455 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005456 execute( TC_sacch_chan_act_ho_async() );
5457 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005458 execute( TC_rach_content() );
5459 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005460 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005461 execute( TC_rach_load_idle_thresh0() );
5462 execute( TC_rach_load_idle_below_thresh() );
5463 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005464 execute( TC_meas_res_sign_tchf() );
5465 execute( TC_meas_res_sign_tchh() );
5466 execute( TC_meas_res_sign_sdcch4() );
5467 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005468 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005469 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005470 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005471 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005472 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005473 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005474 execute( TC_paging_imsi_80percent() );
5475 execute( TC_paging_tmsi_80percent() );
5476 execute( TC_paging_imsi_200percent() );
5477 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005478 execute( TC_rsl_protocol_error() );
5479 execute( TC_rsl_mand_ie_error() );
5480 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005481 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005482 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005483 execute( TC_si_sched_2bis() );
5484 execute( TC_si_sched_2ter() );
5485 execute( TC_si_sched_2ter_2bis() );
5486 execute( TC_si_sched_2quater() );
5487 execute( TC_si_sched_13() );
5488 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005489 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005490 execute( TC_ipa_crcx_twice_not_active() );
5491 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005492 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005493 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005494
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005495 if (mp_pcu_socket != "") {
5496 execute( TC_pcu_act_req() );
5497 execute( TC_pcu_act_req_wrong_ts() );
5498 execute( TC_pcu_act_req_wrong_bts() );
5499 execute( TC_pcu_act_req_wrong_trx() );
5500 execute( TC_pcu_deact_req() );
5501 execute( TC_pcu_deact_req_wrong_ts() );
5502 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005503 if (mp_l1_supports_gprs) {
5504 execute( TC_pcu_data_req_pdtch() );
5505 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005506 execute( TC_pcu_data_req_wrong_bts() );
5507 execute( TC_pcu_data_req_wrong_trx() );
5508 execute( TC_pcu_data_req_wrong_ts() );
5509 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005510 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005511 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005512 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005513 execute( TC_pcu_data_req_imm_ass_pch() );
5514 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005515 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005516 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005517 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005518 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005519 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005520 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005521 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005522 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02005523 execute( TC_pcu_socket_noconnect_nosi3gprs() );
5524 execute( TC_pcu_socket_connect_si3gprs() );
5525 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005526 } else {
5527 log("PCU socket path not available, skipping PCU tests");
5528 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005529
5530 execute( TC_dyn_osmo_pdch_act_deact() );
5531 execute( TC_dyn_osmo_pdch_unsol_deact() );
5532 execute( TC_dyn_osmo_pdch_double_act() );
5533 execute( TC_dyn_osmo_pdch_tchf_act() );
5534 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005535 execute( TC_dyn_ipa_pdch_act_deact() );
5536 execute( TC_dyn_ipa_pdch_tchf_act() );
5537 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5538 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005539
5540 execute( TC_rll_est_ind() );
5541 execute( TC_rll_est_req_DCCH_3() );
5542 execute( TC_rll_est_req_ACCH_3() );
5543 execute( TC_rll_rel_ind_DCCH_0() );
5544 execute( TC_rll_rel_ind_DCCH_3() );
5545 execute( TC_rll_rel_ind_ACCH_0() );
5546 execute( TC_rll_rel_ind_ACCH_3() );
5547 execute( TC_rll_rel_req() );
5548 execute( TC_rll_unit_data_req_DCCH() );
5549 execute( TC_rll_unit_data_req_ACCH() );
5550 execute( TC_rll_unit_data_ind_DCCH() );
5551 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005552
5553 execute( TC_chan_act_a51() );
5554 execute( TC_chan_act_a52() );
5555 execute( TC_chan_act_a53() );
5556 execute( TC_encr_cmd_a51() );
5557 execute( TC_encr_cmd_a52() );
5558 execute( TC_encr_cmd_a53() );
5559
Harald Welteee25aae2019-05-19 14:32:37 +02005560 execute( TC_err_rep_wrong_mdisc() );
5561 execute( TC_err_rep_wrong_msg_type() );
5562 execute( TC_err_rep_wrong_sequence() );
5563
Harald Weltee613f962018-04-18 22:38:16 +02005564 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005565
5566 execute( TC_tch_sign_l2_fill_frame() );
5567 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005568
5569 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005570 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005571}
5572
5573
5574}