blob: 7aa74d2326c4505473e427fa9d39772252aae3af [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
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001526 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1527 g_pars.l1_pars.ms_power_level, false,
1528 g_pars.l1_pars.ms_actual_ta);
1529
1530 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1531 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1532
1533 log("Sending Measurement Report: ", l1h, l2);
1534 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001535 repeat;
1536 }
1537}
1538
1539altstep as_l1_dcch() runs on ConnHdlr {
1540 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001541 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001542 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1543 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001544 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1545 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001546 repeat;
1547 }
1548}
1549
1550type record MeasElem {
1551 uint6_t rxlev,
1552 uint3_t rxqual
1553}
1554
1555type record MeasElemFS {
1556 MeasElem full,
1557 MeasElem sub
1558}
1559
1560type record ConnL1Pars {
1561 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001562 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001563 MeasElemFS meas_ul,
1564 int16_t timing_offset_256syms,
1565 uint5_t bs_power_level,
1566 uint5_t ms_power_level,
1567 uint8_t ms_actual_ta
1568}
1569
1570/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1571private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1572 return 63 + (toffs256s/256);
1573}
1574
Harald Welted5684392018-03-10 18:22:04 +01001575private function f_max(integer a, integer b) return integer {
1576 if (a > b) {
1577 return a;
1578 } else {
1579 return b;
1580 }
1581}
1582
1583private function f_min(integer a, integer b) return integer {
1584 if (a < b) {
1585 return a;
1586 } else {
1587 return b;
1588 }
1589}
1590
1591/* compute negative tolerance val-tolerance, ensure >= min */
1592private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1593 val := val - tolerance;
1594 return f_max(val, min);
1595}
1596
1597/* compute positive tolerance val+tolerance, ensure <= max */
1598private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1599 val := val + tolerance;
1600 return f_min(val, max);
1601}
1602
1603/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1604private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1605return template integer {
1606 var template integer ret;
1607 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1608 return ret;
1609}
1610
1611
Harald Welte70767382018-02-21 12:16:40 +01001612/* build a template for matching measurement results against */
1613private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1614 var ConnL1Pars l1p := g_pars.l1_pars;
1615 var template RSL_IE_UplinkMeas ul_meas := {
1616 len := 3,
1617 rfu := '0'B,
1618 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001619 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001620 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001621 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001622 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001623 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1624 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001625 supp_meas_info := omit
1626 };
Harald Welte685d5982018-02-27 20:42:05 +01001627 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001628 ul_meas.len := (3+8);
1629 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001630 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001631 toa256_min := ?,
1632 toa256_max := ?,
1633 toa256_std_dev := ?
1634 }
Harald Welte685d5982018-02-27 20:42:05 +01001635 }
Harald Welte70767382018-02-21 12:16:40 +01001636 var template RSL_IE_BS_Power bs_power := {
1637 reserved := 0,
1638 epc := false,
1639 fpc := false,
1640 power_level := l1p.bs_power_level
1641 };
1642 var template RSL_IE_L1Info l1_info := {
1643 ms_power_lvl := l1p.ms_power_level,
1644 fpc := false,
1645 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001646 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001647 };
1648 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001649 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001650 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1651 ?, t_toffs);
1652}
1653
1654/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001655altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001656 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001657 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001658 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1659 /* increment counter of next to-be-expected meas rep */
1660 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1661 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001662 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001663 repeat;
1664 }
1665 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001666 /* increment counter of next to-be-expected meas rep */
1667 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1668 if (g_first_meas_res) {
1669 g_first_meas_res := false;
1670 repeat;
1671 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001673 }
Harald Welte70767382018-02-21 12:16:40 +01001674 }
1675 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001677 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001678 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001680 }
1681}
1682
Harald Weltee613f962018-04-18 22:38:16 +02001683private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1684 select (rsl_alg_id) {
1685 case (RSL_ALG_ID_A5_0) { return 0; }
1686 case (RSL_ALG_ID_A5_1) { return 1; }
1687 case (RSL_ALG_ID_A5_2) { return 2; }
1688 case (RSL_ALG_ID_A5_3) { return 3; }
1689 case (RSL_ALG_ID_A5_4) { return 4; }
1690 case (RSL_ALG_ID_A5_5) { return 5; }
1691 case (RSL_ALG_ID_A5_6) { return 6; }
1692 case (RSL_ALG_ID_A5_7) { return 7; }
1693 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1695 /* Make compiler happy by calling mtc.stop here. It is already
1696 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001697 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001698 }
1699 }
1700}
1701
1702private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1703 select (rsl_alg_id) {
1704 case (RSL_ALG_ID_A5_1) { return '000'B; }
1705 case (RSL_ALG_ID_A5_2) { return '001'B; }
1706 case (RSL_ALG_ID_A5_3) { return '010'B; }
1707 case (RSL_ALG_ID_A5_4) { return '011'B; }
1708 case (RSL_ALG_ID_A5_5) { return '100'B; }
1709 case (RSL_ALG_ID_A5_6) { return '101'B; }
1710 case (RSL_ALG_ID_A5_7) { return '110'B; }
1711 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1713 /* Make compiler happy by calling mtc.stop here. It is already
1714 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001715 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001716 }
1717 }
1718}
1719
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001720/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1721private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1722 var GsmFrameNumber fn;
1723 timer T := 8.0;
1724
1725 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1726 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1727
1728 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1729 /* Send the actual RACH */
1730 fn := f_L1CTL_RACH(L1CTL, ra);
1731
1732 T.start;
1733 alt {
1734 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1735 [] T.timeout {
1736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1737 }
1738 }
1739 T.stop
1740 return fn;
1741}
Harald Weltee613f962018-04-18 22:38:16 +02001742
Harald Welte70767382018-02-21 12:16:40 +01001743/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001744private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001745 var GsmFrameNumber fn;
1746 var ImmediateAssignment imm_ass;
1747 var integer ra := 23;
1748
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001749 /* Send RACH request and wait for ChanReq */
1750 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001751
1752 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001753 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001754
1755 /* Send IMM.ASS via CCHAN */
1756 var ChannelDescription ch_desc := {
1757 chan_nr := g_pars.chan_nr,
1758 tsc := 7,
1759 h := false,
1760 arfcn := mp_trx0_arfcn,
1761 maio_hsn := omit
1762 };
1763 var MobileAllocation ma := {
1764 len := 0,
1765 ma := ''B
1766 };
1767 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1768 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1769
1770 /* receive IMM.ASS on MS side */
1771 var ImmediateAssignment ia_um;
1772 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1773 /* enable dedicated mode */
1774 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001775 /* enable encryption, if requested */
1776 if (encr_enable) {
1777 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1778 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1779 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001780
1781 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001782}
1783
1784/* establish DChan, verify existance + contents of measurement reports */
1785function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001786 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001787 RSL.clear;
1788
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001789 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001790 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001791 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1792 }
Harald Welte70767382018-02-21 12:16:40 +01001793
1794 f_est_dchan();
1795
1796 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1797 * RSL measurement reports on Abis side */
1798 timer T := 8.0;
1799 T.start;
1800 alt {
1801 [] as_l1_sacch();
1802 [] as_meas_res();
1803 [] as_l1_dcch();
1804 [] L1CTL.receive { repeat; }
1805 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001806 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001807 * of any earlier errors, so if we reach this timeout, we're good */
1808 setverdict(pass);
1809 }
1810 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001812 }
1813 }
1814 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001815 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001816}
Harald Welte0472ab42018-03-12 15:02:26 +01001817
Harald Welte70767382018-02-21 12:16:40 +01001818testcase TC_meas_res_sign_tchf() runs on test_CT {
1819 var ConnHdlr vc_conn;
1820 var ConnHdlrPars pars;
1821 f_init(testcasename());
1822 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1823 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1824 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1825 vc_conn.done;
1826 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001828}
1829testcase TC_meas_res_sign_tchh() runs on test_CT {
1830 var ConnHdlr vc_conn;
1831 var ConnHdlrPars pars;
1832 f_init(testcasename());
1833 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1834 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1835 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1836 vc_conn.done;
1837 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001839}
1840testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1841 var ConnHdlr vc_conn;
1842 var ConnHdlrPars pars;
1843 f_init(testcasename());
1844 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1845 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1846 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1847 vc_conn.done;
1848 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001850}
1851testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1852 var ConnHdlr vc_conn;
1853 var ConnHdlrPars pars;
1854 f_init(testcasename());
1855 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1856 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1857 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1858 vc_conn.done;
1859 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001861}
Harald Welte685d5982018-02-27 20:42:05 +01001862testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1863 var ConnHdlr vc_conn;
1864 var ConnHdlrPars pars;
1865 f_init(testcasename());
1866 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1867 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1868 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1869 pars.l1_pars.toa256_enabled := true;
1870 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1871 vc_conn.done;
1872 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001874}
1875
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001876/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1877 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1878function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1879 var L1ctlDlMessage l1_dl;
1880 var RSL_IE_MS_Power ms_power;
1881 var RSL_Message rsl;
1882 var uint5_t power_level := 0;
1883
1884 f_l1_tune(L1CTL);
1885 RSL.clear;
1886
1887 f_est_dchan();
1888
1889 ms_power.reserved := 0;
1890 ms_power.fpc_epc := false;
1891
1892 /* Send the first power control command. This will disable any BTS/TRX
1893 * internal power control and switch the MS (which is not in scope of
1894 * this test) to a constant power level. We start with a power level
1895 * of 0 */
1896 ms_power.power_level := power_level;
1897 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1898 RSL.send(rsl);
1899
1900 alt {
1901
1902 /* Pick all SACCH blocks for checking */
1903 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1904
1905 /* The first byte of the L1 header contains the power level.
1906 * The reserved bits and the fpc bit is set to 0, so we may
1907 * compare directly. */
1908 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1909 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1910 }
1911
1912 /* Signal a new power level via RSL for the next turn. */
1913 if (power_level < 31) {
1914 power_level := power_level + 1;
1915 ms_power.power_level := power_level;
1916 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1917 RSL.send(rsl);
1918 repeat;
1919 }
1920
1921 }
1922
1923 /* Ignore all other blocks */
1924 [] L1CTL.receive { repeat; }
1925
1926 }
1927
1928 f_rsl_chan_deact();
1929 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1930
1931 setverdict(pass);
1932}
1933
1934testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1935 var ConnHdlr vc_conn;
1936 var ConnHdlrPars pars;
1937 f_init(testcasename());
1938
1939 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1940 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1941 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1942 vc_conn.done;
1943 }
1944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1945}
Harald Welte70767382018-02-21 12:16:40 +01001946
Eric Wild6833cc92019-05-23 19:34:44 +02001947/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1948TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1949function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1950 var L1ctlDlMessage l1_dl;
1951 var uint5_t ta_to_test := 16;
1952
1953
1954 f_l1_tune(L1CTL);
1955 RSL.clear;
1956
1957 /* tell fake_trx to use a given timing offset for all bursts */
1958 f_trx_fake_toffs256(ta_to_test*256);
1959
1960 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1961
1962
1963 alt {
1964
1965 /* Pick all SACCH blocks for checking */
1966 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1967
1968 /* The second byte of the L1 header contains the TA. */
1969 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1970 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1971 }
1972
1973 }
1974
1975 /* Ignore all other blocks */
1976 [] L1CTL.receive { repeat; }
1977
1978 }
1979
1980 f_rsl_chan_deact();
1981 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1982
1983 setverdict(pass);
1984}
1985
1986testcase TC_rsl_chan_initial_ta() runs on test_CT {
1987 var ConnHdlr vc_conn;
1988 var ConnHdlrPars pars;
1989 f_init(testcasename());
1990 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1991 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1992 vc_conn.done;
1993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1994}
1995
Eric Wilde57e1a62019-05-28 13:30:55 +02001996/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
1997function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
1998 var L1ctlDlMessage l1_dl;
1999 var uint5_t ms_power_level := 7;
2000
2001 var RSL_IE_MS_Power ms_power;
2002 ms_power.reserved := 0;
2003 ms_power.fpc_epc := false;
2004 ms_power.power_level := ms_power_level;
2005
2006 f_l1_tune(L1CTL);
2007 RSL.clear;
2008
2009 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2010
2011 timer T := 1.0;
2012 T.start;
2013 alt {
2014 /* Pick all SACCH blocks for checking */
2015 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2016 /* The first byte of the L1 header contains the power level.. */
2017 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2018 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2019 }
2020 }
2021 /* Ignore all other blocks */
2022 [] L1CTL.receive { repeat; }
2023 [] T.timeout {
2024 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2025 }
2026 }
2027
2028 f_rsl_chan_deact();
2029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2030 setverdict(pass);
2031}
2032
2033testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2034 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2035 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2036}
2037
Harald Welte0472ab42018-03-12 15:02:26 +01002038/* 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 +01002039private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002040 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002041 RSL.clear;
2042
2043 f_est_dchan();
2044 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002045 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002046
2047 timer T := 40.0;
2048 T.start;
2049 alt {
2050 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2051 setverdict(pass)
2052 }
2053 [] RSL.receive { repeat };
2054 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002056 }
2057 }
2058 f_rsl_chan_deact();
2059}
2060testcase TC_conn_fail_crit() runs on test_CT {
2061 var ConnHdlr vc_conn;
2062 var ConnHdlrPars pars;
2063 f_init(testcasename());
2064 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2065 pars.t_guard := 60.0;
2066 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2067 vc_conn.done;
2068}
2069
Harald Welte93640c62018-02-25 16:59:33 +01002070/***********************************************************************
2071 * Paging
2072 ***********************************************************************/
2073
Harald Welte68e495b2018-02-25 00:05:57 +01002074function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2075 if (tmsi == 'FFFFFFFF'O) {
2076 return true;
2077 } else {
2078 return false;
2079 }
2080}
Harald Welte70767382018-02-21 12:16:40 +01002081
Philipp Maier82cb0b12018-08-31 14:41:39 +02002082type record allowedFn { integer frame_nr }
2083template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2084template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2085template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2086template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2087template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2088template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2089template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2090template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2091function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2092{
2093 var integer frame_nr_51;
2094 frame_nr_51 := frame_nr mod 51
2095
2096 var allowedFn fn_check;
2097 fn_check.frame_nr := frame_nr_51;
2098
2099 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002101 return;
2102 }
2103
2104 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2105 return;
2106 }
2107 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2108 return;
2109 }
2110 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2111 return;
2112 }
2113 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2114 return;
2115 }
2116 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2117 return;
2118 }
2119 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2120 return;
2121 }
2122 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2123 return;
2124 }
2125 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2126 return;
2127 }
2128
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002130 return;
2131}
2132
2133altstep 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 +01002134runs on test_CT {
2135 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002136 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002137 repeat;
2138 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002139 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002140 var octetstring without_plen :=
2141 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2142 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002143
2144 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2145
Harald Welte68e495b2018-02-25 00:05:57 +01002146 if (match(rr, tr_PAGING_REQ1)) {
2147 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2148 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2149 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2150 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2151 }
2152 } else if (match(rr, tr_PAGING_REQ2)) {
2153 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2154 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2155 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2156 }
2157 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2158 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2159 }
2160 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2161 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2162 }
2163 } else if (match(rr, tr_PAGING_REQ3)) {
2164 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2165 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2166 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2167 }
2168 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2169 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2170 }
2171 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2172 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2173 }
2174 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2175 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2176 }
2177 }
2178 repeat;
2179 }
2180}
2181
2182type record PagingTestCfg {
2183 boolean combined_ccch,
2184 integer bs_ag_blks_res,
2185 float load_factor,
2186 boolean exp_load_ind,
2187 boolean exp_overload,
2188 boolean use_tmsi
2189}
2190
2191type record PagingTestState {
2192 integer num_paging_sent,
2193 integer num_paging_rcv_msgs,
2194 integer num_paging_rcv_ids,
2195 integer num_overload
2196}
2197
2198/* receive + ignore RSL RF RES IND */
2199altstep as_rsl_res_ind() runs on test_CT {
2200 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2201 repeat;
2202 }
2203}
2204
2205/* Helper function for paging related testing */
2206private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2207 f_init(testcasename());
2208 f_init_l1ctl();
2209 f_l1_tune(L1CTL);
2210
2211 var PagingTestState st := {
2212 num_paging_sent := 0,
2213 num_paging_rcv_msgs := 0,
2214 num_paging_rcv_ids := 0,
2215 num_overload := 0
2216 };
2217
2218 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2219 var float max_pch_imsi_per_sec;
2220 if (cfg.use_tmsi) {
2221 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2222 } else {
2223 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2224 }
2225 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2226 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002227 var float time_total := 20.0;
2228 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2229 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002230
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002231 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2232 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002233
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002234 timer T_itv := 0.0;
2235 T_itv.start;
2236 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002237 alt {
2238 /* check for presence of CCCH LOAD IND (paging load) */
2239 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2240 st.num_overload := st.num_overload + 1;
2241 repeat;
2242 }
2243 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002245 }
2246 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2247 log("Rx LOAD_IND");
2248 /* FIXME: analyze/verify interval + contents */
2249 repeat;
2250 }
2251 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002252 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002253 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002254 [] T_itv.timeout {
2255 /* Send paging cmds based on elapsed time */
2256 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2257 while (st.num_paging_sent < new_sent) {
2258 /* build mobile Identity */
2259 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2260 if (cfg.use_tmsi) {
2261 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2262 } else {
2263 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2264 }
2265 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2266 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2267
2268 /* Send RSL PAGING COMMAND */
2269 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2270
2271 st.num_paging_sent := st.num_paging_sent + 1;
2272 }
2273 if (st.num_paging_sent < pkt_total) {
2274 /* Wait for interval to next PAGING COMMAND */
2275 var float time_now := T_total.read;
2276 var float next_sched := int2float(st.num_paging_sent)*interval;
2277 if (next_sched > time_now) {
2278 T_itv.start(next_sched - time_now);
2279 } else {
2280 T_itv.start(0.0);
2281 }
2282 } else {
2283 /* We are done, no need to keep counting */
2284 T_total.stop;
2285 }
2286 }
2287 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002288 [] as_rsl_res_ind();
2289 }
2290 }
2291
2292 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2293 timer T_wait := 18.0;
2294 T_wait.start;
2295 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002296 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002297 [] L1CTL.receive { repeat; }
2298 /* 65535 == empty paging queue, we can terminate*/
2299 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2300 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2301 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002303 }
2304 [] as_rsl_res_ind();
2305 }
2306
2307 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2308 " rcvd_ids=", st.num_paging_rcv_ids);
2309 return st;
2310}
2311
2312/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2313 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2314 * - that CCCH LOAD IND (PCH) are being generated
2315 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2316testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002317 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002318 var PagingTestCfg cfg := {
2319 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002320 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002321 load_factor := 0.8,
2322 exp_load_ind := true,
2323 exp_overload := false,
2324 use_tmsi := false
2325 };
2326 var PagingTestState st := f_TC_paging(cfg);
2327 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2329 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002330 } else {
2331 setverdict(pass);
2332 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002334}
2335
2336/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2337 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2338 * - that CCCH LOAD IND (PCH) are being generated
2339 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2340testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002341 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002342 var PagingTestCfg cfg := {
2343 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002344 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002345 load_factor := 0.8,
2346 exp_load_ind := true,
2347 exp_overload := false,
2348 use_tmsi := true
2349 };
2350 var PagingTestState st := f_TC_paging(cfg);
2351 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2353 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002354 } else {
2355 setverdict(pass);
2356 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002358}
2359
2360/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2361 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2362 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2363 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2364testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002365 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002366 var PagingTestCfg cfg := {
2367 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002368 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002369 load_factor := 2.0,
2370 exp_load_ind := true,
2371 exp_overload := true,
2372 use_tmsi := false
2373 };
2374 var PagingTestState st := f_TC_paging(cfg);
2375 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2376 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002377 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002378 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002379 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 +01002380 } else {
2381 setverdict(pass);
2382 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002384}
2385
2386/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2387 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2388 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2389 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2390testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002391 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002392 var PagingTestCfg cfg := {
2393 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002394 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002395 load_factor := 2.0,
2396 exp_load_ind := true,
2397 exp_overload := true,
2398 use_tmsi := true
2399 };
2400 var PagingTestState st := f_TC_paging(cfg);
2401 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2402 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002403 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002404 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 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 +01002406 } else {
2407 setverdict(pass);
2408 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002410}
2411
2412
Harald Welte93640c62018-02-25 16:59:33 +01002413/***********************************************************************
2414 * Immediate Assignment / AGCH
2415 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002416const MobileAllocation c_MA_null := {
2417 len := 0,
2418 ma := ''B
2419}
Harald Welte93640c62018-02-25 16:59:33 +01002420
Harald Weltee8d750e2018-06-10 21:41:35 +02002421template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2422 uint12_t arfcn := 871) := {
2423 chan_nr := chan_nr,
2424 tsc := tsc,
2425 h := false,
2426 arfcn := arfcn,
2427 maio_hsn := omit
2428}
2429
2430private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2431 return int2str(num_tx) & " sent, "
2432 & int2str(num_rx) & " received, "
2433 & int2str(num_del) & " deleted";
2434}
2435
2436private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2437 var L1ctlDlMessage l1_dl;
2438 timer T := 10.0;
2439 var integer num_tx := 0;
2440 var integer num_rx := 0;
2441 var integer num_del := 0;
2442 var charstring res_str;
2443 var float rx_ratio;
2444
Harald Welte68e495b2018-02-25 00:05:57 +01002445 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002446 f_init_l1ctl();
2447 f_l1_tune(L1CTL);
2448
2449 for (var integer i := 0; i < num_total; i := i+1) {
2450 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2451 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2452 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002453 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002454 num_tx := num_tx+1;
2455 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002456 }
2457 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002458 T.start;
2459 alt {
2460 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2461 num_del := num_del+1;
2462 repeat;
2463 }
2464 [] RSL_CCHAN.receive {
2465 repeat;
2466 }
2467 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2468 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2469 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2470 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2471 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002472 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002473 } else {
2474 num_rx := num_rx+1;
2475 }
2476 repeat;
2477 }
2478 [] L1CTL.receive { repeat; }
2479 [] T.timeout { }
2480 }
2481 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2482 log("AGCH test: " & res_str);
2483 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002485 }
2486 rx_ratio := int2float(num_rx) / int2float(num_tx);
2487 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002488 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 +02002489 } else {
2490 setverdict(pass);
2491 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002493}
2494
Harald Weltee8d750e2018-06-10 21:41:35 +02002495/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2496testcase TC_imm_ass_1000_20ms() runs on test_CT {
2497 f_TC_imm_ass(1000, 0.02, 0.25);
2498}
2499
2500/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2501testcase TC_imm_ass_200_0ms() runs on test_CT {
2502 f_TC_imm_ass(200, 0.0, 0.05);
2503}
2504
2505/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2506testcase TC_imm_ass_200_76ms() runs on test_CT {
2507 f_TC_imm_ass(150, 0.076, 1.00);
2508}
2509
2510
2511
Harald Welte48494ca2018-02-25 16:59:50 +01002512/***********************************************************************
2513 * BCCH
2514 ***********************************************************************/
2515
2516/* tuple of Frame Number + decoded SI */
2517type record SystemInformationFn {
2518 GsmFrameNumber frame_number,
2519 SystemInformation si
2520}
2521
2522/* an arbitrary-length vector of decoded SI + gsmtap header */
2523type record of SystemInformationFn SystemInformationVector;
2524
2525/* an array of SI-vectors indexed by TC value */
2526type SystemInformationVector SystemInformationVectorPerTc[8];
2527
2528/* determine if a given SI vector contains given SI type at least once */
2529function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2530 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2531 var integer fn_mod51 := arr[i].frame_number mod 51;
2532 if (not bcch_ext and fn_mod51 == 2 or
2533 bcch_ext and fn_mod51 == 6) {
2534 if (arr[i].si.header.message_type == key) {
2535 return true;
2536 }
2537 }
2538 }
2539 return false;
2540}
2541
2542/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2543function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2544 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002546 }
2547}
2548
2549/* check if a given SI vector contains given SI type at least once on any TC */
2550function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2551 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2552 if (f_si_vecslot_contains(arr[tc], key) or
2553 f_si_vecslot_contains(arr[tc], key, true)) {
2554 return true;
2555 }
2556 }
2557 return false;
2558}
2559
2560/* determine if a given SI vector contains given SI type at least N of M times */
2561function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2562 var integer count := 0;
2563 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002565 }
2566 for (var integer i:= 0; i < m; i := i + 1) {
2567 var integer fn_mod51 := arr[i].frame_number mod 51;
2568 if (not bcch_ext and fn_mod51 == 2 or
2569 bcch_ext and fn_mod51 == 6) {
2570 if (arr[i].si.header.message_type == key) {
2571 count := count + 1;
2572 }
2573 }
2574 }
2575 if (count >= n) {
2576 return true;
2577 } else {
2578 return false;
2579 }
2580}
2581
2582/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2583function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2584 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002586 }
2587}
2588
2589/* determine if a given SI vector contains given SI type at least once */
2590function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2591 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2592 var integer fn_mod51 := arr[i].frame_number mod 51;
2593 if (not bcch_ext and fn_mod51 == 2 or
2594 bcch_ext and fn_mod51 == 6) {
2595 if (arr[i].si.header.message_type != key) {
2596 return false;
2597 }
2598 }
2599 }
2600 return true;
2601}
2602
2603/* ensure a given TC slot of the SI vector contains only given SI type */
2604function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2605 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002607 }
2608}
2609
2610/* SI configuration of cell, against which we validate actual SI messages */
2611type set SystemInformationConfig {
2612 boolean bcch_extended,
2613 boolean si1_present,
2614 boolean si2bis_present,
2615 boolean si2ter_present,
2616 boolean si2quater_present,
2617 boolean si7_present,
2618 boolean si8_present,
2619 boolean si9_present,
2620 boolean si13_present,
2621 boolean si13alt_present,
2622 boolean si15_present,
2623 boolean si16_present,
2624 boolean si17_present,
2625 boolean si2n_present,
2626 boolean si21_present,
2627 boolean si22_present
2628}
2629
2630/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2631function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2632 var integer i;
2633 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2634 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002636 }
2637 }
2638 if (cfg.si1_present) {
2639 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2640 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2641 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2642 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2643 /* make sure *ALL* contain SI1 */
2644 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2645 }
2646 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2647 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2648 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2649 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2650 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2651 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2652
2653 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2654 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2655 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2656 * consecutive occurrences of TC = 4. */
2657 if (cfg.si2bis_present and not cfg.si2ter_present) {
2658 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2659 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2660 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2661 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2662 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2663 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2664 }
2665
2666 if (cfg.si7_present or cfg.si8_present) {
2667 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2668 * if System Information type 4 does not contain all information needed for cell
2669 * selection and reselection. */
2670 if (not cfg.bcch_extended) {
2671 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2672 }
2673 if (cfg.si7_present) {
2674 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2675 }
2676 if (cfg.si8_present) {
2677 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2678 }
2679 }
2680
2681 if (cfg.si2quater_present) {
2682 /* iii) System information type 2 quater is sent if needed, as determined by the system
2683 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2684 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2685 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2686 * within any of 4 consecutive occurrences of TC = 5. */
2687 if (not (cfg.bcch_extended)) {
2688 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2689 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2690 } else {
2691 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2692 }
2693 } else {
2694 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2695 }
2696 }
2697 if (cfg.si9_present) {
2698 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2699 * in system information type 3 as defined in 3GPP TS 44.018. */
2700 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2701 }
2702 if (cfg.si13_present) {
2703 /* vii) System Information type 13 is only related to the GPRS service. System Information
2704 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2705 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2706 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2707 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2708 * within any of 4 consecutive occurrences of TC=4. */
2709 if (not cfg.bcch_extended) {
2710 log("not-bccch-extended");
2711 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2712 } else {
2713 log("bccch-extended");
2714 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2715 }
2716 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002718 }
2719 }
2720 if (cfg.si16_present or cfg.si17_present) {
2721 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2722 * should not be sent in a cell where network sharing is used (see rule xv). */
2723 if (cfg.si22_present) {
2724 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2725 }
2726 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002728 }
2729 if (not cfg.bcch_extended) {
2730 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2731 }
2732 if (cfg.si16_present) {
2733 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2734 }
2735 if (cfg.si17_present) {
2736 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2737 }
2738 }
2739
2740 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2741 * broadcast information. The frequency with which they are sent is determined by the
2742 * system operator. System Information type 9 identifies the scheduling of System
2743 * Information type 18 and 20 messages. */
2744
2745 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2746 * Information Type 19 is present, then its scheduling shall be indicated in System
2747 * Information Type 9. */
2748
2749 if (cfg.si15_present) {
2750 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2751 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2752 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2753 * 4 consecutive occurrences of TC = 1. */
2754 if (not cfg.bcch_extended) {
2755 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2756 } else {
2757 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2758 }
2759 }
2760 if (cfg.si13alt_present) {
2761 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2762 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2763 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2764 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2765 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2766 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2767 * of TC = 4. */
2768 if (cfg.si13_present) {
2769 testcase.stop("Error: Cannot have SI13alt and SI13");
2770 }
2771 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002773 }
2774 if (not cfg.bcch_extended) {
2775 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2776 } else {
2777 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2778 }
2779 }
2780 if (cfg.si2n_present) {
2781 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2782 * as determined by the system operator. In the case that the message is sent on the
2783 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2784 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2785 * consecutive occurrences of TC = 4. */
2786 if (not cfg.bcch_extended) {
2787 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2788 } else {
2789 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2790 }
2791 }
2792 if (cfg.si21_present) {
2793 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2794 * determined by the system operator. If Extended Access Barring is in use in the cell
2795 * then this message is sent at least once within any of 4 consecutive occurrences of
2796 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2797 * cell then this message shall only be sent on BCCH Ext. */
2798 if (not cfg.bcch_extended) {
2799 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2800 } else {
2801 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2802 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002804 }
2805 }
2806 }
2807 if (cfg.si22_present) {
2808 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2809 * should not be sent in a cell where SoLSA is used (see rule viii). System
2810 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2811 * =2 and TC=6. */
2812 if (cfg.si16_present or cfg.si17_present) {
2813 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2814 }
2815 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2816 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002818 }
2819 if (not cfg.bcch_extended) {
2820 testcase.stop("Error: SI22 requires BCCH Extd!");
2821 } else {
2822 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2823 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2824 }
2825 }
2826}
2827
2828/* sample Systme Information for specified duration via L1CTL */
2829function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2830 timer T := duration;
2831 var SystemInformationVectorPerTc si_per_tc;
2832 var L1ctlDlMessage l1_dl;
2833
2834 /* initialize all per-TC vectors empty */
2835 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2836 si_per_tc[i] := {};
2837 }
2838
2839 /* flush all previous L1 queued msgs */
2840 pt.clear;
2841
2842 T.start;
2843 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002844 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002845 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2846 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2847 log("Ignoring non-RR SI ", l1_dl);
2848 repeat;
2849 }
2850 var SystemInformationFn sig := {
2851 frame_number := l1_dl.dl_info.frame_nr,
2852 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2853 }
2854 var integer tc := f_gsm_compute_tc(sig.frame_number);
2855 log("SI received at TC=", tc, ": ", sig.si);
2856 /* append to the per-TC bucket */
2857 si_per_tc[tc] := si_per_tc[tc] & { sig };
2858 repeat;
2859 }
2860 [] pt.receive { repeat; }
2861 [] T.timeout { }
2862 }
2863
2864 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2865 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2866 }
2867 log("si_per_tc=", si_per_tc);
2868 return si_per_tc;
2869}
2870
2871/* helper function: Set given SI via RSL + validate scheduling.
2872 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2873function f_TC_si_sched() runs on test_CT {
2874 var SystemInformationVectorPerTc si_per_tc;
2875 f_init_l1ctl();
2876 f_l1_tune(L1CTL);
2877
2878 /* Sample + Validate Scheduling */
2879 si_per_tc := f_l1_sample_si(L1CTL);
2880 f_validate_si_scheduling(si_cfg, si_per_tc);
2881
2882 setverdict(pass);
2883}
2884
2885testcase TC_si_sched_default() runs on test_CT {
2886 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002887 /* 2+3+4 are mandatory and set in f_init() */
2888 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002890}
2891
2892testcase TC_si_sched_1() runs on test_CT {
2893 f_init();
2894 si_cfg.si1_present := true;
2895 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002896 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002898}
2899
2900testcase TC_si_sched_2bis() runs on test_CT {
2901 f_init();
2902 si_cfg.si2bis_present := true;
2903 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2904 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002906}
2907
2908testcase TC_si_sched_2ter() runs on test_CT {
2909 f_init();
2910 si_cfg.si2ter_present := true;
2911 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2912 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002914}
2915
2916testcase TC_si_sched_2ter_2bis() runs on test_CT {
2917 f_init();
2918 si_cfg.si2bis_present := true;
2919 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2920 si_cfg.si2ter_present := true;
2921 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2922 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002924}
2925
2926testcase TC_si_sched_2quater() runs on test_CT {
2927 f_init();
2928 si_cfg.si2quater_present := true;
2929 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2930 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002932}
2933
2934testcase TC_si_sched_13() runs on test_CT {
2935 f_init();
2936 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002937 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002938 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002940}
2941
2942testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2943 f_init();
2944 si_cfg.si2bis_present := true;
2945 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2946 si_cfg.si2ter_present := true;
2947 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2948 si_cfg.si2quater_present := true;
2949 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2950 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002951 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002952 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002954}
2955
2956
Harald Welte68e495b2018-02-25 00:05:57 +01002957testcase TC_bcch_info() runs on test_CT {
2958 f_init(testcasename());
2959 /* FIXME: enable / disable individual BCCH info */
2960 //ts_RSL_BCCH_INFO(si_type, info);
2961 /* expect no ERROR REPORT after either of them *
2962 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002964}
2965
Harald Welte93640c62018-02-25 16:59:33 +01002966/***********************************************************************
2967 * Low-Level Protocol Errors / ERROR REPORT
2968 ***********************************************************************/
2969
Harald Welte01d982c2018-02-25 01:31:40 +01002970private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2971 timer T := 5.0;
2972 T.start;
2973 alt {
2974 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2975 setverdict(pass);
2976 }
2977 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002979 }
2980 [] RSL_CCHAN.receive {
2981 repeat;
2982 }
2983 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002985 }
2986 }
2987}
2988
2989/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2990testcase TC_rsl_protocol_error() runs on test_CT {
2991 f_init(testcasename());
2992 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2993 rsl.ies := omit;
2994 RSL_CCHAN.send(ts_RSL_UD(rsl));
2995
2996 f_exp_err_rep(RSL_ERR_PROTO);
2997}
2998
2999/* Provoke a mandatory IE error and match on ERROR REPORT */
3000testcase TC_rsl_mand_ie_error() runs on test_CT {
3001 f_init(testcasename());
3002
3003 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3004 rsl.ies := { rsl.ies[0] };
3005 RSL_CCHAN.send(ts_RSL_UD(rsl));
3006
3007 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3008}
3009
3010/* Provoke an IE content error and match on ERROR REPORT */
3011testcase TC_rsl_ie_content_error() runs on test_CT {
3012 f_init(testcasename());
3013 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3014 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3015 RSL_CCHAN.send(ts_RSL_UD(rsl));
3016
3017 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3018}
3019
Harald Welteee25aae2019-05-19 14:32:37 +02003020/* attempt to activate channel with wrong RSL Message Discriminator IE */
3021function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3022 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3023 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3024 RSL.send(rsl);
3025 f_rslem_unregister(0, g_chan_nr);
3026}
3027testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3028 var ConnHdlr vc_conn;
3029 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3030
3031 f_init(testcasename());
3032
3033 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3034 vc_conn.done;
3035 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3036
3037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3038}
3039
3040/* Send messages with wrong message type */
3041function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3042 var template (value) RSL_Message rsl_tx;
3043 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3044 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3045 RSL.send(rsl_tx);
3046 f_rslem_unregister(0, g_chan_nr);
3047}
3048function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3049 var template (value) RSL_Message rsl_tx;
3050 /* we first have to activate the dedicated channel */
3051 f_rsl_chan_act(g_pars.chan_mode);
3052 /* ... to then send an invalid RLL message */
3053 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3054 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3055 RSL.send(rsl_tx);
3056 f_rslem_unregister(0, g_chan_nr);
3057}
3058testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3059 var ConnHdlr vc_conn;
3060 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3061 var template (value) RSL_Message rsl_tx;
3062
3063 f_init(testcasename());
3064
3065 /* Common Channel with wrong message type */
3066 RSL_CCHAN.clear;
3067 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3068 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3069 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3070 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3071
3072 /* TRX Management */
3073 RSL_CCHAN.clear;
3074 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3075 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3076 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3077 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3078
3079 /* Dedicated Channel */
3080 RSL_CCHAN.clear;
3081 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3082 vc_conn.done;
3083 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3084
3085 /* RLL */
3086 RSL_CCHAN.clear;
3087 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3088 vc_conn.done;
3089 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3090}
3091
3092/* Send messages in wrong sequence (RLL to an inactive lchan) */
3093function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3094 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3095 f_rslem_unregister(0, g_chan_nr);
3096}
3097testcase TC_err_rep_wrong_sequence() runs on test_CT {
3098 var ConnHdlr vc_conn;
3099 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3100
3101 f_init(testcasename());
3102
3103 RSL_CCHAN.clear;
3104 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3105 vc_conn.done;
3106 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3107}
3108
Harald Welte93640c62018-02-25 16:59:33 +01003109/***********************************************************************
3110 * IPA CRCX/MDCX/DLCS media stream handling
3111 ***********************************************************************/
3112
Harald Weltea871a382018-02-25 02:03:14 +01003113/* Send IPA DLCX to inactive lchan */
3114function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003115 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3116 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003117}
3118testcase TC_ipa_dlcx_not_active() runs on test_CT {
3119 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3120 f_init(testcasename());
3121 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3122 vc_conn.done;
3123}
Harald Welte68e495b2018-02-25 00:05:57 +01003124
Harald Weltea3f1df92018-02-25 12:49:55 +01003125/* Send IPA CRCX twice to inactive lchan */
3126function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3127 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3128 "IPA CRCX ACK");
3129 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3130 "IPA CRCX NACK");
3131}
3132testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3133 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3134 f_init(testcasename());
3135 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3136 vc_conn.done;
3137}
3138
3139/* Regular sequence of CRCX/MDCX/DLCX */
3140function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3141 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3142 "IPA CRCX ACK");
3143 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3144 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3145 var uint7_t rtp_pt2 := f_rnd_int(127);
3146 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3147 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3148 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3149 "IPA MDCX ACK");
3150 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3151 "IPA DLCX ACK");
3152}
3153testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3154 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3155 f_init(testcasename());
3156 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3157 vc_conn.done;
3158}
3159
Harald Welte3ae11da2018-02-25 13:36:06 +01003160/* Sequence of CRCX, 2x MDCX, DLCX */
3161function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3162 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3163 "IPA CRCX ACK");
3164 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3165 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3166 var uint7_t rtp_pt2 := f_rnd_int(127);
3167 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3168 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3169 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3170 "IPA MDCX ACK");
3171 /* Second MDCX */
3172 remote_ip := f_rnd_int(c_UINT32_MAX);
3173 remote_port := f_rnd_int(c_UINT16_MAX);
3174 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3175 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3176 "IPA MDCX ACK");
3177 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3178 "IPA DLCX ACK");
3179}
3180testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3181 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3182 f_init(testcasename());
3183 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3184 vc_conn.done;
3185}
3186
Harald Welte9912eb52018-02-25 13:30:15 +01003187/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3188function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3189 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3190 "IPA CRCX NACK");
3191}
3192testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3193 var ConnHdlrPars pars;
3194 var ConnHdlr vc_conn;
3195 f_init(testcasename());
3196
3197 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3198 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3199 vc_conn.done;
3200
3201 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3202 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3203 vc_conn.done;
3204}
3205
Harald Weltea3f1df92018-02-25 12:49:55 +01003206
Harald Welte883340c2018-02-28 18:59:29 +01003207/***********************************************************************
3208 * PCU Socket related tests
3209 ***********************************************************************/
3210
Harald Welte07bd2d22019-05-25 11:03:30 +02003211/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003212friend 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 +01003213runs on test_CT {
3214 timer T := 3.0;
3215
3216 /* we don't expect any RTS.req before PDCH are active */
3217 T.start;
3218 alt {
3219 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003221 }
3222 [] PCU.receive { repeat; }
3223 [] T.timeout { }
3224 }
3225
3226 /* Send PDCH activate request for known PDCH timeslot */
3227 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3228
3229 /* we now expect RTS.req for this timeslot (only) */
3230 T.start;
3231 alt {
3232 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3233 setverdict(pass);
3234 }
3235 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3236 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003238 }
3239 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003241 }
3242 [] PCU.receive { repeat; }
3243 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003245 }
3246 [not exp_success] T.timeout {
3247 setverdict(pass);
3248 }
3249 }
3250}
3251
Harald Welte07bd2d22019-05-25 11:03:30 +02003252/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003253friend 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 +01003254runs on test_CT {
3255 timer T := 3.0;
3256
3257 /* Send PDCH activate request for known PDCH timeslot */
3258 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3259
3260 PCU.clear;
3261 /* we now expect no RTS.req for this timeslot */
3262 T.start;
3263 alt {
3264 [] 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 +02003265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003266 }
3267 [] PCU.receive { repeat; }
3268 [] T.timeout {
3269 setverdict(pass);
3270 }
3271 }
3272}
3273
Harald Weltead033dc2019-05-25 17:28:16 +02003274friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003275 f_init();
3276 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3277}
3278
Harald Welte883340c2018-02-28 18:59:29 +01003279/* PDCH activation via PCU socket; check for presence of RTS.req */
3280testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003281 f_init_pcu_test();
3282
Harald Welte883340c2018-02-28 18:59:29 +01003283 f_TC_pcu_act_req(0, 0, 7, true);
3284}
3285
3286/* PDCH activation via PCU socket on non-PDCU timeslot */
3287testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003288 f_init_pcu_test();
3289
Harald Welte883340c2018-02-28 18:59:29 +01003290 f_TC_pcu_act_req(0, 0, 1, false);
3291}
3292
3293/* PDCH activation via PCU socket on wrong BTS */
3294testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003295 f_init_pcu_test();
3296
Harald Welte883340c2018-02-28 18:59:29 +01003297 f_TC_pcu_act_req(23, 0, 7, false);
3298}
3299
3300/* PDCH activation via PCU socket on wrong TRX */
3301testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003302 f_init_pcu_test();
3303
Harald Welte883340c2018-02-28 18:59:29 +01003304 f_TC_pcu_act_req(0, 23, 7, false);
3305}
3306
3307/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3308testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003309 f_init_pcu_test();
3310
Harald Welte883340c2018-02-28 18:59:29 +01003311 /* Activate PDCH */
3312 f_TC_pcu_act_req(0, 0, 7, true);
3313 f_sleep(1.0);
3314 /* and De-Activate again */
3315 f_TC_pcu_deact_req(0, 0, 7);
3316}
3317
3318/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3319testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003320 f_init_pcu_test();
3321
Harald Welte883340c2018-02-28 18:59:29 +01003322 f_TC_pcu_deact_req(0, 0, 1);
3323}
3324
3325/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3326testcase TC_pcu_ver_si13() runs on test_CT {
3327 const octetstring si13 := '00010203040506070909'O;
3328 var PCUIF_send_data sd;
3329 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003330 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003331
3332 /* Set SI13 via RSL */
3333 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003334
Harald Welte883340c2018-02-28 18:59:29 +01003335 T.start;
3336 alt {
3337 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3338 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3339 setverdict(pass);
3340 } else {
3341 repeat;
3342 }
3343 }
3344 [] PCU.receive { repeat; }
3345 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003347 }
3348 }
3349}
3350
3351private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3352
3353/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003354friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003355 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3356runs on test_CT
3357{
3358 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3359 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3360}
3361
3362/* 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 +02003363friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3364 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003365runs on test_CT
3366{
3367 var PCUIF_send_data sd;
3368
3369 timer T := 3.0;
3370 T.start;
3371 alt {
3372 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3373 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3374 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3375 sd.data.u.rts_req.fn, sapi, data);
3376 }
3377 [] PCU.receive { repeat; }
3378 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003380 }
3381 }
3382}
3383
3384/* Send DATA.req on invalid BTS */
3385testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003386 var TfiUsfArr tua := f_TfiUsfArrInit();
3387 var octetstring data := '0000'O & f_rnd_octstring(21);
3388
3389 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003390
Harald Welte883340c2018-02-28 18:59:29 +01003391 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003392 f_TfiUsfArrSet(tua, 7, 0);
3393 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3394 f_sleep(1.0);
3395
3396 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003397}
3398
3399/* Send DATA.req on invalid TRX */
3400testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003401 var TfiUsfArr tua := f_TfiUsfArrInit();
3402 var octetstring data := '0000'O & f_rnd_octstring(21);
3403
3404 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003405
Harald Welte883340c2018-02-28 18:59:29 +01003406 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003407 f_TfiUsfArrSet(tua, 7, 0);
3408 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3409 f_sleep(1.0);
3410
3411 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003412}
3413
3414/* Send DATA.req on invalid timeslot */
3415testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003416 var TfiUsfArr tua := f_TfiUsfArrInit();
3417 var octetstring data := '0000'O & f_rnd_octstring(21);
3418
3419 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003420
Harald Welte883340c2018-02-28 18:59:29 +01003421 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003422 f_TfiUsfArrSet(tua, 7, 0);
3423 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3424 f_sleep(1.0);
3425
3426 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003427}
3428
3429/* Send DATA.req on timeslot that hasn't been activated */
3430testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003431 var TfiUsfArr tua := f_TfiUsfArrInit();
3432 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003433
Harald Welte7162a612019-05-26 12:56:09 +02003434 f_virtphy_common();
3435
3436 f_TfiUsfArrSet(tua, 7, 0);
3437 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3438 f_sleep(1.0);
3439
3440 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003441}
3442
Harald Weltead033dc2019-05-25 17:28:16 +02003443private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003444 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3445 boolean wait_rts := true)
3446runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003447 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003448 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003449
3450 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003451 if (wait_rts) {
3452 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3453 } else {
3454 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3455 }
Harald Weltead033dc2019-05-25 17:28:16 +02003456
3457 T.start;
3458 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003459 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003460 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3461 setverdict(pass);
3462 }
Harald Welte7162a612019-05-26 12:56:09 +02003463 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3464 setverdict(fail, "Received unexpected ", rx_dl);
3465 }
Harald Weltead033dc2019-05-25 17:28:16 +02003466 [] L1CTL.receive {
3467 repeat;
3468 }
Harald Welte7162a612019-05-26 12:56:09 +02003469 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003470 setverdict(fail, "Timeout waiting for ", data);
3471 }
Harald Welte7162a612019-05-26 12:56:09 +02003472 [not expect_data] T.timeout {
3473 setverdict(pass);
3474 }
Harald Weltead033dc2019-05-25 17:28:16 +02003475 }
3476}
3477
3478private function f_disable_dynamic_ts() runs on test_CT
3479{
3480 f_init_vty_bsc();
3481 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3482 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3483 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3484 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003485 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003486}
3487
3488private function f_virtphy_common() runs on test_CT {
3489 f_disable_dynamic_ts();
3490 f_init_l1ctl();
3491 f_l1_tune(L1CTL);
3492}
3493
3494testcase TC_pcu_data_req_pdtch() runs on test_CT {
3495 var TfiUsfArr tua := f_TfiUsfArrInit();
3496 var octetstring data := '0000'O & f_rnd_octstring(21);
3497
3498 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003499
Harald Welte883340c2018-02-28 18:59:29 +01003500 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003501 f_TfiUsfArrSet(tua, 7, 0);
3502 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3503 f_sleep(1.0);
3504
3505 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003506}
3507
3508testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003509 var TfiUsfArr tua := f_TfiUsfArrInit();
3510 var octetstring data := '0000'O & f_rnd_octstring(21);
3511
3512 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003513
Harald Welte883340c2018-02-28 18:59:29 +01003514 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003515 f_TfiUsfArrSet(tua, 7, 0);
3516 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3517 f_sleep(1.0);
3518
3519 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003520}
3521
3522/* Send AGCH from PCU; check it appears on Um side */
3523testcase TC_pcu_data_req_agch() runs on test_CT {
3524 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003525 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003526 f_init_l1ctl();
3527 f_l1_tune(L1CTL);
3528
3529 f_TC_pcu_act_req(0, 0, 7, true);
3530 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3531
3532 T.start;
3533 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003534 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003535 setverdict(pass);
3536 }
3537 [] L1CTL.receive { repeat; }
3538 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003540 }
3541 }
3542}
3543
Harald Welte928622b2019-05-26 13:22:59 +02003544/* Send AGCH from PCU; check it appears on Um side */
3545testcase TC_pcu_data_req_pch() runs on test_CT {
3546 timer T := 3.0;
3547 f_init_pcu_test();
3548 f_init_l1ctl();
3549 f_l1_tune(L1CTL);
3550
3551 f_TC_pcu_act_req(0, 0, 7, true);
3552 /* three characters prefix: last 3 digits of IMSI as ASCII */
3553 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3554
3555 T.start;
3556 alt {
3557 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3558 setverdict(pass);
3559 }
3560 [] L1CTL.receive { repeat; }
3561 [] T.timeout {
3562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3563 }
3564 }
3565}
3566
Harald Welte883340c2018-02-28 18:59:29 +01003567/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3568testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3569 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003570 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003571 f_init_l1ctl();
3572 f_l1_tune(L1CTL);
3573
3574 /* append 3 last imsi digits so BTS can compute pagng group */
3575 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3576
3577 timer T := 0.5;
3578 T.start;
3579 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003580 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003581 /* TODO: verify paging group */
3582 setverdict(pass);
3583 }
3584 [] L1CTL.receive { repeat; }
3585 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003586 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003587 }
3588 }
3589}
3590
3591/* Send RACH from Um side, expect it to show up on PCU socket */
3592testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003593 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003594 f_init_l1ctl();
3595 f_l1_tune(L1CTL);
3596
3597 var GsmFrameNumber fn_last := 0;
3598 for (var integer i := 0; i < 1000; i := i+1) {
3599 var OCT1 ra := f_rnd_ra_ps();
3600 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3601 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003603 }
3604 fn_last := fn;
3605
3606 timer T := 2.0;
3607 T.start;
3608 alt {
3609 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3610 T.stop;
3611 }
3612 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003614 }
3615 [] PCU.receive { repeat; }
3616 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003618 }
3619 }
3620 }
3621 setverdict(pass);
3622}
3623
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003624/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3625 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3626testcase TC_pcu_ext_rach_content() runs on test_CT {
3627 var template PCUIF_Message pcu_rach_ind;
3628 var GsmFrameNumber fn_last := 0;
3629 var L1ctlRachSynchSeq synch_seq;
3630 var PCUIF_BurstType pcu_bt;
3631 var GsmFrameNumber fn;
3632 var BIT11 ra11;
3633
3634 f_init_pcu_test();
3635 f_init_l1ctl();
3636 f_l1_tune(L1CTL);
3637
3638 for (var integer i := 0; i < 1000; i := i+1) {
3639 /* We need to test both TS1 & TS2 */
3640 if (i rem 2 == 0) {
3641 synch_seq := RACH_SYNCH_SEQ_TS1;
3642 pcu_bt := BURST_TYPE_1;
3643 } else {
3644 synch_seq := RACH_SYNCH_SEQ_TS2;
3645 pcu_bt := BURST_TYPE_2;
3646 }
3647
3648 ra11 := f_rnd_ra11_ps();
3649 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3650 if (fn == fn_last) {
3651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3652 "Two RACH in same FN?!?");
3653 }
3654 fn_last := fn;
3655
3656 /* Compose the expected message */
3657 pcu_rach_ind := tr_PCUIF_RACH_IND(
3658 bts_nr := 0,
3659 ra := bit2int(ra11),
3660 is_11bit := 1,
3661 burst_type := pcu_bt,
3662 fn := fn);
3663
3664 timer T := 2.0;
3665 T.start;
3666 alt {
3667 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3668 T.stop;
3669 }
3670 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3672 }
3673 [] PCU.receive { repeat; }
3674 [] T.timeout {
3675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3676 }
3677 }
3678 }
3679 setverdict(pass);
3680}
3681
Harald Welte883340c2018-02-28 18:59:29 +01003682/* Send PAGING via RSL, expect it to shw up on PCU socket */
3683testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003684 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003685
3686 for (var integer i := 0; i < 100; i := i+1) {
3687 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3688 timer T := 3.0;
3689 if (i < 50) {
3690 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3691 } else {
3692 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3693 }
3694 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3695 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3696 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3697
3698 /* Send RSL PAGING COMMAND */
3699 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3700 T.start;
3701 alt {
3702 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3703 }
3704 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003706 }
3707 [] PCU.receive { repeat; }
3708 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003710 }
3711 }
3712 }
3713 setverdict(pass);
3714}
3715
Harald Welted66c9b82019-05-25 09:03:15 +02003716/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3717testcase TC_pcu_time_ind() runs on test_CT {
3718 var PCUIF_send_data pcu_sd;
3719 var integer num_time_ind := 0;
3720 var integer first_fn, last_fn;
3721 var float test_duration := 5.0;
3722 timer T;
3723
3724 f_init_pcu_test();
3725 f_TC_pcu_act_req(0, 0, 7, true);
3726
3727 PCU.clear;
3728 T.start(test_duration);
3729 alt {
3730 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3731 num_time_ind := num_time_ind + 1;
3732 if (not isbound(first_fn)) {
3733 first_fn := pcu_sd.data.u.time_ind.fn;
3734 }
3735 last_fn := pcu_sd.data.u.time_ind.fn;
3736 repeat;
3737 }
3738 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3739 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3740 repeat;
3741 }
3742 [] PCU.receive {
3743 repeat;
3744 }
3745 [] T.timeout {}
3746 }
3747 var integer fn_expired := last_fn - first_fn;
3748 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3749
3750 /* verify the number of frames expired matches our expectation */
3751 const float c_GSM_FN_DURATION_MS := 4.61538;
3752 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003753 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003754 if (not match(fn_expired, t_fn_expected)) {
3755 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3756 }
3757
3758 /* There are three TIME.ind in every fn MOD 13 */
3759 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3760 /* Add some tolerance */
3761 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3762 if (not match(num_time_ind, t_time_ind_exp)) {
3763 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3764 }
3765
3766 setverdict(pass);
3767}
3768
Harald Welte4832c862019-05-25 14:57:18 +02003769/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3770testcase TC_pcu_rts_req() runs on test_CT {
3771 var PCUIF_send_data pcu_sd;
3772 var integer first_fn, last_fn;
3773 var integer num_rts_pdtch := 0;
3774 var integer num_rts_ptcch := 0;
3775 var float test_duration := 5.0;
3776 timer T;
3777
3778 f_init_pcu_test();
3779 f_TC_pcu_act_req(0, 0, 7, true);
3780
3781 PCU.clear;
3782 T.start(test_duration);
3783 alt {
3784 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3785 -> value pcu_sd {
3786 num_rts_pdtch := num_rts_pdtch + 1;
3787 if (not isbound(first_fn)) {
3788 first_fn := pcu_sd.data.u.rts_req.fn;
3789 }
3790 last_fn := pcu_sd.data.u.rts_req.fn;
3791 repeat;
3792 }
3793 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3794 -> value pcu_sd {
3795 num_rts_ptcch := num_rts_ptcch + 1;
3796 if (not isbound(first_fn)) {
3797 first_fn := pcu_sd.data.u.rts_req.fn;
3798 }
3799 last_fn := pcu_sd.data.u.rts_req.fn;
3800 repeat;
3801 }
3802 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3803 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3804 repeat;
3805 }
3806 [] PCU.receive {
3807 repeat;
3808 }
3809 [] T.timeout {}
3810 }
3811 var integer fn_expired := last_fn - first_fn;
3812 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3813 ", num_rts_ptcch=", num_rts_ptcch);
3814
3815 /* verify the number of frames expired matches our expectation */
3816 const float c_GSM_FN_DURATION_MS := 4.61538;
3817 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003818 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003819 if (not match(fn_expired, t_fn_expected)) {
3820 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3821 }
3822
3823 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3824 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3825 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3826 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3827 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3828 t_ptcch_exp);
3829 }
3830
3831 /* We have 12 PDTCH blocks every 52-multiframe */
3832 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3833 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3834 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3835 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3836 t_pdtch_exp);
3837 }
3838
3839 setverdict(pass);
3840}
3841
Harald Welte07bd2d22019-05-25 11:03:30 +02003842/* test for generating Abis side OML ALERT from the PCU */
3843testcase TC_pcu_oml_alert() runs on test_CT {
3844 var PCUIF_send_data pcu_sd;
3845 var integer num_time_ind := 0;
3846 var integer first_fn, last_fn;
3847 var float test_duration := 5.0;
3848 timer T;
3849
3850 f_init_pcu_test();
3851 f_TC_pcu_act_req(0, 0, 7, true);
3852
3853 /* re-connect CTRL port from BTS to BSC */
3854 f_ipa_ctrl_stop();
3855 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3856
3857 /* Send that OML Alert */
3858 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3859
3860 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3861 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3862 setverdict(pass);
3863}
3864
Harald Welteeaa9a862019-05-26 23:01:08 +02003865template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3866 template (value) RoutingAreaIdentificationV rai,
3867 template (value) OCT1 cause) := {
3868 discriminator := '0000'B, /* overwritten */
3869 tiOrSkip := {
3870 skipIndicator := '0000'B
3871 },
3872 msgs := {
3873 rrm := {
3874 gPRS_suspensionRequest := {
3875 messageType := '00110100'B,
3876 tLLI := tlli,
3877 routingAreaIdentification := rai,
3878 suspensionCause := cause,
3879 service_Support := omit
3880 }
3881 }
3882 }
3883}
3884
3885/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3886private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3887 var PCUIF_Message first_info;
3888 var integer pcu_conn_id := -1;
3889 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3890 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3891 var OCT4 tlli := '01020304'O;
3892 var OCT1 cause := '23'O;
3893 timer T := 5.0;
3894
3895 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3896
3897 f_l1_tune(L1CTL);
3898 RSL.clear;
3899
3900 f_est_dchan();
3901 L1CTL.clear;
3902
3903 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3904
3905 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3906 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3907 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3908
3909 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3910 T.start;
3911 alt {
3912 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3913 setverdict(pass);
3914 }
3915 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3916 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3917 }
3918 [] PCU.receive {
3919 repeat;
3920 }
3921 [] T.timeout {
3922 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3923 }
3924 }
3925}
3926testcase TC_pcu_rr_suspend() runs on test_CT {
3927 var ConnHdlrPars pars;
3928 var ConnHdlr vc_conn;
3929
3930 f_init();
3931
3932 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3933 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3934 vc_conn.done;
3935}
Harald Welte07bd2d22019-05-25 11:03:30 +02003936
Harald Weltea2e0e942019-05-27 18:12:53 +02003937/* Ensure that PCUIF socket can accept only a single connection */
3938testcase TC_pcu_socket_connect_multi() runs on test_CT {
3939 timer T := 5.0;
3940
3941 /* this (among other things) establishes the first connection to the PCUIF socket */
3942 f_init();
3943
3944 /* try to establish a second connection, expect it to fail */
3945 PCU.send(UD_connect:{mp_pcu_socket, -1});
3946 T.start;
3947 alt {
3948 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
3949 setverdict(pass);
3950 }
3951 [] PCU.receive(UD_connect_result:?) {
3952 setverdict(fail, "Unexpected unix domain connect result");
3953 }
3954 [] T.timeout {
3955 setverdict(pass);
3956 }
3957 }
3958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3959}
3960
Harald Weltec8effb72019-05-27 18:23:04 +02003961/* Ensure that PCUIF socket can disconnect + reconnect */
3962testcase TC_pcu_socket_reconnect() runs on test_CT {
3963 /* this (among other things) establishes the first connection to the PCUIF socket */
3964 f_init();
3965
3966 f_sleep(1.0);
3967
3968 f_pcuif_close(PCU, g_pcu_conn_id);
3969 g_pcu_conn_id := -1;
3970
3971 f_sleep(1.0);
3972
3973 /* re-connect */
3974 PCU.clear;
3975 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
3976 setverdict(pass);
3977
3978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3979}
3980
Harald Weltebe030482019-05-27 22:29:35 +02003981/* Ensure that GPRS capability is not advertised before PCU socket conncet */
3982private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
3983 var L1ctlDlMessage l1_dl;
3984 var SystemInformation si;
3985 timer T := 5.0;
3986 T.start;
3987 alt {
3988 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
3989 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3990 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3991 log("Ignoring non-RR SI ", l1_dl);
3992 repeat;
3993 }
3994 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3995 if (not ischosen(si.payload.si3)) {
3996 repeat;
3997 }
3998 }
3999 [] pt.receive {
4000 repeat;
4001 }
4002 [] T.timeout {
4003 setverdict(fail, "Timeout waiting for SI3");
4004 }
4005 }
4006 return si.payload.si3;
4007}
4008
4009/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4010private function f_bitpos_is_inv(integer idx) return boolean {
4011 select (idx mod 8) {
4012 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4013 case else { return false; } /* 0-bits of 0x2B */
4014 }
4015}
4016/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4017private function f_bit_is_high(bitstring str, integer idx) return boolean {
4018 var boolean invert := f_bitpos_is_inv(idx);
4019 if (invert) {
4020 if (str[idx] == '1'B) {
4021 return false;
4022 } else {
4023 return true;
4024 }
4025 } else {
4026 if (str[idx] == '1'B) {
4027 return true;
4028 } else {
4029 return false;
4030 }
4031 }
4032}
4033/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4034 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4035 we can replace this piece of code soon ... */
4036private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4037 var bitstring bits := oct2bit(si3_restoctets);
4038 var integer idx := 0;
4039
4040 if (f_bit_is_high(bits, idx)) {
4041 /* skip Optional selection parameters */
4042 idx := idx + 16;
4043 } else {
4044 idx := idx + 1;
4045 }
4046
4047 if (f_bit_is_high(bits, idx)) {
4048 /* skip Optional power offset */
4049 idx := idx + 3;
4050 } else {
4051 idx := idx + 1;
4052 }
4053
4054 /* skip SI2ter Indicator */
4055 idx := idx + 1;
4056
4057 /* skip Early CM Sending Control */
4058 idx := idx + 1;
4059
4060 /* skip Scheduling if and where */
4061 if (f_bit_is_high(bits, idx)) {
4062 idx := idx + 4;
4063 } else {
4064 idx := idx + 1;
4065 }
4066
4067 return f_bit_is_high(bits, idx);
4068}
4069
4070testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4071 var SystemInformationType3 si3;
4072 timer T := 5.0;
4073
4074 /* don't call f_init() as this would connect PCU socket */
4075 f_init_rsl(testcasename());
4076 T.start;
4077 alt {
4078 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4079 [] T.timeout {
4080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4081 }
4082 }
4083 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4084
4085 f_init_l1ctl();
4086 f_l1_tune(L1CTL);
4087
4088 f_sleep(2.0);
4089 L1CTL.clear;
4090 si3 := f_get_si3(L1CTL);
4091 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4092 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4093 } else {
4094 setverdict(pass);
4095 }
4096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4097}
4098
4099/* Ensure that GPRS capability is advertised after PCU socket connect */
4100testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4101 var SystemInformationType3 si3;
4102
4103 /* this (among other things) establishes the first connection to the PCUIF socket */
4104 f_init();
4105 f_init_l1ctl();
4106 f_l1_tune(L1CTL);
4107
4108 f_sleep(2.0);
4109 L1CTL.clear;
4110 si3 := f_get_si3(L1CTL);
4111 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4112 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4113 } else {
4114 setverdict(pass);
4115 }
4116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4117}
4118
4119/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4120testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4121 var SystemInformationType3 si3;
4122
4123 /* this (among other things) establishes the first connection to the PCUIF socket */
4124 f_init();
4125 f_init_l1ctl();
4126 f_l1_tune(L1CTL);
4127
4128 f_pcuif_close(PCU, g_pcu_conn_id);
4129 g_pcu_conn_id := -1;
4130
4131 f_sleep(1.0);
4132
4133 /* re-connect */
4134 PCU.clear;
4135 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4136
4137 f_sleep(2.0);
4138 L1CTL.clear;
4139 si3 := f_get_si3(L1CTL);
4140 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4141 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4142 } else {
4143 setverdict(pass);
4144 }
4145
4146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4147}
4148
Harald Welted66c9b82019-05-25 09:03:15 +02004149
Harald Welte3d04ae62018-04-04 20:29:05 +02004150/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004151 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004152 ***********************************************************************/
4153
4154private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4155runs on ConnHdlr {
4156 var PCUIF_send_data sd;
4157 /* Expect BTS to immediately acknowledge activation as PDCH */
4158 PCU.clear;
4159 f_rsl_chan_act(g_pars.chan_mode);
4160 /* expect INFO_IND on PCU interface listing TS as PDCH */
4161 alt {
4162 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4163 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 +02004164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004165 }
4166 }
4167 [] PCU.receive { repeat; }
4168 }
4169 /* try to activate this PDCH from the PCU point of view */
4170 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4171 /* FIXME: is there a response? */
4172}
4173
4174private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4175runs on ConnHdlr {
4176 var PCUIF_send_data sd;
4177 /* Send RSL CHAN REL (deactivate) */
4178 PCU.clear;
4179 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4180 /* expect BTS to ask PCU to deactivate the channel */
4181 alt {
4182 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4183 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 +02004184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004185 }
4186 }
4187 [] PCU.receive { repeat; }
4188 }
4189 /* Emulate PCU asking BTS to deactivate PDCH */
4190 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4191 alt {
4192 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4193 setverdict(pass);
4194 }
4195 [] RSL.receive { repeat; }
4196 }
4197}
4198
4199/* Activate Osmocom-style dynamic PDCH from BSC side */
4200function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4201 var PCUIF_Message first_info;
4202 var integer ts_nr := g_chan_nr.tn;
4203 var integer trx_nr := 0;
4204 var integer bts_nr := 0;
4205 var integer pcu_conn_id := -1;
4206
4207 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4208
4209 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4210 f_sleep(3.0);
4211 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4212 setverdict(pass);
4213}
4214testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4215 var ConnHdlrPars pars;
4216 var ConnHdlr vc_conn;
4217 f_init(testcasename());
4218
4219 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4220 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4221 vc_conn.done;
4222}
4223
4224/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4225function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4226 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004227 var integer pcu_conn_id := -1;
4228
4229 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4230
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004231 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4232 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4233 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004234 setverdict(pass);
4235}
4236testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4237 var ConnHdlrPars pars;
4238 var ConnHdlr vc_conn;
4239 f_init(testcasename());
4240
4241 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4242 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4243 vc_conn.done;
4244}
4245
4246/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4247function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4248 var PCUIF_Message first_info;
4249 var integer ts_nr := g_chan_nr.tn;
4250 var integer trx_nr := 0;
4251 var integer bts_nr := 0;
4252 var integer pcu_conn_id := -1;
4253
4254 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4255
4256 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004257 /* Send a second Chan Activ and expect it to be NACKed */
4258 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4259 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004260 setverdict(pass);
4261}
4262testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4263 var ConnHdlrPars pars;
4264 var ConnHdlr vc_conn;
4265 f_init(testcasename());
4266
4267 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4268 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4269 vc_conn.done;
4270}
4271
4272/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4273function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4274 var PCUIF_Message first_info;
4275 var integer ts_nr := g_chan_nr.tn;
4276 var integer trx_nr := 0;
4277 var integer bts_nr := 0;
4278 var integer pcu_conn_id := -1;
4279 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4280
4281 /* register for the TCH/F channel number */
4282 f_rslem_register(0, chan_nr);
4283
4284 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4285
4286 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4287 "RSL CHAN ACT");
4288 setverdict(pass);
4289}
4290testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4291 var ConnHdlrPars pars;
4292 var ConnHdlr vc_conn;
4293 f_init(testcasename());
4294
4295 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4296 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4297 vc_conn.done;
4298}
4299
4300/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4301function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4302 var PCUIF_Message first_info;
4303 var integer ts_nr := g_chan_nr.tn;
4304 var integer trx_nr := 0;
4305 var integer bts_nr := 0;
4306 var integer pcu_conn_id := -1;
4307 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4308 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4309
4310 /* register for the TCH/H channel numbers */
4311 f_rslem_register(0, chan_nr[0]);
4312 f_rslem_register(0, chan_nr[1]);
4313
4314 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4315
4316 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4317 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4318 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4319 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4320 setverdict(pass);
4321}
4322testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4323 var ConnHdlrPars pars;
4324 var ConnHdlr vc_conn;
4325 f_init(testcasename());
4326
4327 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4328 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4329 vc_conn.done;
4330}
4331
Harald Welte9bbbfb52018-04-05 09:33:19 +02004332/***********************************************************************
4333 * IPA Style Dynamic Timeslot Support
4334 ***********************************************************************/
4335
4336private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4337runs on ConnHdlr {
4338 var PCUIF_send_data sd;
4339 /* Expect BTS to immediately acknowledge activation as PDCH */
4340 PCU.clear;
4341 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4342 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004343 timer T_wait := 2.0;
4344 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004345 alt {
4346 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4347 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 +01004348 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4349 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4350 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004351 }
4352 }
4353 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004354 [] T_wait.timeout {
4355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4356 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4357 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004358 }
4359 /* try to activate this PDCH from the PCU point of view */
4360 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4361 /* FIXME: is there a response? */
4362
4363 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4364}
4365
4366private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4367runs on ConnHdlr {
4368 var PCUIF_send_data sd;
4369 /* Send RSL CHAN REL (deactivate) */
4370 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4371 PCU.clear;
4372 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004373 timer T_wait := 2.0;
4374 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004375 alt {
4376 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4377 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 +01004378 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4379 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4380 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004381 }
4382 }
4383 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004384 [] T_wait.timeout {
4385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4386 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4387 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004388 }
4389 /* Emulate PCU asking BTS to deactivate PDCH */
4390 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4391 alt {
4392 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4393 setverdict(pass);
4394 }
4395 [] RSL.receive { repeat; }
4396 }
4397}
4398
4399/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4400function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4401 var PCUIF_Message first_info;
4402 var integer ts_nr := g_chan_nr.tn;
4403 var integer trx_nr := 0;
4404 var integer bts_nr := 0;
4405 var integer pcu_conn_id := -1;
4406
4407 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4408
4409 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4410 f_sleep(3.0);
4411 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4412
4413 setverdict(pass);
4414
4415}
4416testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4417 var ConnHdlrPars pars;
4418 var ConnHdlr vc_conn;
4419 f_init();
4420
4421 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4422 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4423 vc_conn.done;
4424}
4425
4426/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4427function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4428 var PCUIF_Message first_info;
4429 var integer ts_nr := g_chan_nr.tn;
4430 var integer trx_nr := 0;
4431 var integer bts_nr := 0;
4432 var integer pcu_conn_id := -1;
4433
4434 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4435
4436 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4437 "RSL CHAN ACT");
4438 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4439 "RF CHAN REL", true);
4440 setverdict(pass);
4441}
4442testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4443 var ConnHdlrPars pars;
4444 var ConnHdlr vc_conn;
4445 f_init(testcasename());
4446
4447 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4448 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4449 vc_conn.done;
4450}
4451
4452/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4453function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4454 var PCUIF_Message first_info;
4455 var integer ts_nr := g_chan_nr.tn;
4456 var integer trx_nr := 0;
4457 var integer bts_nr := 0;
4458 var integer pcu_conn_id := -1;
4459
4460 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4461
4462 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4463 "RSL CHAN ACT");
4464
4465 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4466 alt {
4467 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4468 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004470 }
4471 [] RSL.receive { repeat; }
4472 }
4473
4474 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4475 "RF CHAN REL", true);
4476 setverdict(pass);
4477}
4478testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4479 var ConnHdlrPars pars;
4480 var ConnHdlr vc_conn;
4481 f_init(testcasename());
4482
4483 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4484 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4485 vc_conn.done;
4486}
4487
4488/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4489function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4490 var PCUIF_Message first_info;
4491 var integer ts_nr := g_chan_nr.tn;
4492 var integer trx_nr := 0;
4493 var integer bts_nr := 0;
4494 var integer pcu_conn_id := -1;
4495
4496 /* register for the TCH/F channel number */
4497 f_rslem_register(0, g_chan_nr);
4498
4499 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4500
4501 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4502
4503 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4504 "RSL CHAN ACT");
4505
4506 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4507
4508 setverdict(pass);
4509}
4510testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4511 var ConnHdlrPars pars;
4512 var ConnHdlr vc_conn;
4513 f_init(testcasename());
4514
4515 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4516 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4517 vc_conn.done;
4518}
4519
4520
Harald Welte0472ab42018-03-12 15:02:26 +01004521/***********************************************************************
4522 * LAPDm / RLL related
4523 ***********************************************************************/
4524
4525private function f_tx_lapdm(template (value) LapdmFrame l,
4526 template (value) RslLinkId link_id) runs on ConnHdlr {
4527 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004528 var template (value) SacchL1Header l1h;
4529
4530 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01004531 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004532 /* Compose dummy L1 header */
4533 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
4534 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1h, f_pad_oct(l2, 21, '2B'O)));
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004535 } else {
4536 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004537 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, f_pad_oct(l2, 23, '2B'O)));
Harald Welte0472ab42018-03-12 15:02:26 +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}