blob: ed1d8e18c10f216e789174b6078c0cfd0e36ad12 [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 {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001248 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001249 T.stop;
1250 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001251 [] 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
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001496function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1497 var GsmFrameNumber fn;
1498 var RSL_Message rm;
1499
1500 f_l1_tune(L1CTL);
1501 RSL.clear;
1502
1503 /* Generate a random Handover Reference */
1504 var integer ho_ref := oct2int(f_rnd_octstring(1));
1505
1506 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1507 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1508 RSL_IE_Body:{ handover_ref := ho_ref }));
1509
1510 /* Activate a channel on the BTS side (no encryption) */
1511 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1512 act_type := t_RSL_IE_ActType_HO_SYNC);
1513
1514 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1515 * waiting for Immediate Assignment and sending Access Burst */
1516 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1517
1518 /* Send handover Access Burst */
1519 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1520
1521 /* TODO: test mismatching Handover Reference, and missing IE */
1522
1523 /* Wait for handover detection */
1524 timer T := 3.0;
1525 T.start;
1526 alt {
1527 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1528 log("Handover RACH has been detected: ", rm);
1529 setverdict(pass);
1530 }
1531 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1533 log2str("RSL_CHAN_RQD was not expected: ", rm));
1534 }
1535 [] RSL.receive { repeat; }
1536 [] T.timeout {
1537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1538 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1539 }
1540 }
1541
1542 /* Release the channel */
1543 f_rsl_chan_deact();
1544 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1545}
1546
1547/* Test handover RACH detection */
1548testcase TC_ho_rach() runs on test_CT {
1549 var ConnHdlrPars pars;
1550 var ConnHdlr vc_conn;
1551
1552 f_init();
1553
1554 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1555 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1556 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1557 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1558 vc_conn.done;
1559 }
1560
1561 /* TODO: do the above in parallel, rather than sequentially? */
1562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1563}
1564
Harald Welte93640c62018-02-25 16:59:33 +01001565/***********************************************************************
1566 * Measurement Processing / Reporting
1567 ***********************************************************************/
1568
Harald Welte70767382018-02-21 12:16:40 +01001569template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1570 spare := '0'B,
1571 lpd := 0,
1572 sapi := sapi,
1573 c_r := c_r,
1574 ea := true
1575}
1576
Harald Welted879bd92018-03-12 15:01:23 +01001577template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001578 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001579 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001580 len := 0, /* overwritten */
1581 m := false,
1582 el := 1,
1583 payload := pl
1584}
1585
1586/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1587altstep as_l1_sacch() runs on ConnHdlr {
1588 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001589 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001590 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001591 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 +01001592 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001593 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001594
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001595 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1596 g_pars.l1_pars.ms_power_level, false,
1597 g_pars.l1_pars.ms_actual_ta);
1598
1599 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1600 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1601
1602 log("Sending Measurement Report: ", l1h, l2);
1603 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001604 repeat;
1605 }
1606}
1607
1608altstep as_l1_dcch() runs on ConnHdlr {
1609 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001610 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001611 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1612 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001613 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1614 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001615 repeat;
1616 }
1617}
1618
1619type record MeasElem {
1620 uint6_t rxlev,
1621 uint3_t rxqual
1622}
1623
1624type record MeasElemFS {
1625 MeasElem full,
1626 MeasElem sub
1627}
1628
1629type record ConnL1Pars {
1630 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001631 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001632 MeasElemFS meas_ul,
1633 int16_t timing_offset_256syms,
1634 uint5_t bs_power_level,
1635 uint5_t ms_power_level,
1636 uint8_t ms_actual_ta
1637}
1638
1639/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1640private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1641 return 63 + (toffs256s/256);
1642}
1643
Harald Welted5684392018-03-10 18:22:04 +01001644private function f_max(integer a, integer b) return integer {
1645 if (a > b) {
1646 return a;
1647 } else {
1648 return b;
1649 }
1650}
1651
1652private function f_min(integer a, integer b) return integer {
1653 if (a < b) {
1654 return a;
1655 } else {
1656 return b;
1657 }
1658}
1659
1660/* compute negative tolerance val-tolerance, ensure >= min */
1661private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1662 val := val - tolerance;
1663 return f_max(val, min);
1664}
1665
1666/* compute positive tolerance val+tolerance, ensure <= max */
1667private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1668 val := val + tolerance;
1669 return f_min(val, max);
1670}
1671
1672/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1673private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1674return template integer {
1675 var template integer ret;
1676 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1677 return ret;
1678}
1679
1680
Harald Welte70767382018-02-21 12:16:40 +01001681/* build a template for matching measurement results against */
1682private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1683 var ConnL1Pars l1p := g_pars.l1_pars;
1684 var template RSL_IE_UplinkMeas ul_meas := {
1685 len := 3,
1686 rfu := '0'B,
1687 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001688 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001689 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001690 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001691 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001692 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1693 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001694 supp_meas_info := omit
1695 };
Harald Welte685d5982018-02-27 20:42:05 +01001696 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001697 ul_meas.len := (3+8);
1698 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001699 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001700 toa256_min := ?,
1701 toa256_max := ?,
1702 toa256_std_dev := ?
1703 }
Harald Welte685d5982018-02-27 20:42:05 +01001704 }
Harald Welte70767382018-02-21 12:16:40 +01001705 var template RSL_IE_BS_Power bs_power := {
1706 reserved := 0,
1707 epc := false,
1708 fpc := false,
1709 power_level := l1p.bs_power_level
1710 };
1711 var template RSL_IE_L1Info l1_info := {
1712 ms_power_lvl := l1p.ms_power_level,
1713 fpc := false,
1714 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001715 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001716 };
1717 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001718 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001719 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1720 ?, t_toffs);
1721}
1722
1723/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001724altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001725 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001726 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001727 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1728 /* increment counter of next to-be-expected meas rep */
1729 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1730 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001731 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001732 repeat;
1733 }
1734 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001735 /* increment counter of next to-be-expected meas rep */
1736 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1737 if (g_first_meas_res) {
1738 g_first_meas_res := false;
1739 repeat;
1740 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001742 }
Harald Welte70767382018-02-21 12:16:40 +01001743 }
1744 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001746 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001747 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001749 }
1750}
1751
Harald Weltee613f962018-04-18 22:38:16 +02001752private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1753 select (rsl_alg_id) {
1754 case (RSL_ALG_ID_A5_0) { return 0; }
1755 case (RSL_ALG_ID_A5_1) { return 1; }
1756 case (RSL_ALG_ID_A5_2) { return 2; }
1757 case (RSL_ALG_ID_A5_3) { return 3; }
1758 case (RSL_ALG_ID_A5_4) { return 4; }
1759 case (RSL_ALG_ID_A5_5) { return 5; }
1760 case (RSL_ALG_ID_A5_6) { return 6; }
1761 case (RSL_ALG_ID_A5_7) { return 7; }
1762 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1764 /* Make compiler happy by calling mtc.stop here. It is already
1765 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001766 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001767 }
1768 }
1769}
1770
1771private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1772 select (rsl_alg_id) {
1773 case (RSL_ALG_ID_A5_1) { return '000'B; }
1774 case (RSL_ALG_ID_A5_2) { return '001'B; }
1775 case (RSL_ALG_ID_A5_3) { return '010'B; }
1776 case (RSL_ALG_ID_A5_4) { return '011'B; }
1777 case (RSL_ALG_ID_A5_5) { return '100'B; }
1778 case (RSL_ALG_ID_A5_6) { return '101'B; }
1779 case (RSL_ALG_ID_A5_7) { return '110'B; }
1780 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1782 /* Make compiler happy by calling mtc.stop here. It is already
1783 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001784 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001785 }
1786 }
1787}
1788
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001789/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1790private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1791 var GsmFrameNumber fn;
1792 timer T := 8.0;
1793
1794 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1795 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1796
1797 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1798 /* Send the actual RACH */
1799 fn := f_L1CTL_RACH(L1CTL, ra);
1800
1801 T.start;
1802 alt {
1803 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1804 [] T.timeout {
1805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1806 }
1807 }
1808 T.stop
1809 return fn;
1810}
Harald Weltee613f962018-04-18 22:38:16 +02001811
Harald Welte70767382018-02-21 12:16:40 +01001812/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001813private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001814 var GsmFrameNumber fn;
1815 var ImmediateAssignment imm_ass;
1816 var integer ra := 23;
1817
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001818 /* Send RACH request and wait for ChanReq */
1819 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001820
1821 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001822 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001823
1824 /* Send IMM.ASS via CCHAN */
1825 var ChannelDescription ch_desc := {
1826 chan_nr := g_pars.chan_nr,
1827 tsc := 7,
1828 h := false,
1829 arfcn := mp_trx0_arfcn,
1830 maio_hsn := omit
1831 };
1832 var MobileAllocation ma := {
1833 len := 0,
1834 ma := ''B
1835 };
1836 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1837 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1838
1839 /* receive IMM.ASS on MS side */
1840 var ImmediateAssignment ia_um;
1841 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1842 /* enable dedicated mode */
1843 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001844 /* enable encryption, if requested */
1845 if (encr_enable) {
1846 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1847 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1848 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001849
1850 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001851}
1852
1853/* establish DChan, verify existance + contents of measurement reports */
1854function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001855 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001856 RSL.clear;
1857
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001858 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001859 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001860 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1861 }
Harald Welte70767382018-02-21 12:16:40 +01001862
1863 f_est_dchan();
1864
1865 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1866 * RSL measurement reports on Abis side */
1867 timer T := 8.0;
1868 T.start;
1869 alt {
1870 [] as_l1_sacch();
1871 [] as_meas_res();
1872 [] as_l1_dcch();
1873 [] L1CTL.receive { repeat; }
1874 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001876 * of any earlier errors, so if we reach this timeout, we're good */
1877 setverdict(pass);
1878 }
1879 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001881 }
1882 }
1883 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001884 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001885}
Harald Welte0472ab42018-03-12 15:02:26 +01001886
Harald Welte70767382018-02-21 12:16:40 +01001887testcase TC_meas_res_sign_tchf() runs on test_CT {
1888 var ConnHdlr vc_conn;
1889 var ConnHdlrPars pars;
1890 f_init(testcasename());
1891 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1892 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1893 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1894 vc_conn.done;
1895 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001897}
1898testcase TC_meas_res_sign_tchh() runs on test_CT {
1899 var ConnHdlr vc_conn;
1900 var ConnHdlrPars pars;
1901 f_init(testcasename());
1902 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1903 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1904 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1905 vc_conn.done;
1906 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001908}
1909testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1910 var ConnHdlr vc_conn;
1911 var ConnHdlrPars pars;
1912 f_init(testcasename());
1913 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1914 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1915 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1916 vc_conn.done;
1917 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001919}
1920testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1921 var ConnHdlr vc_conn;
1922 var ConnHdlrPars pars;
1923 f_init(testcasename());
1924 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1925 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1926 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1927 vc_conn.done;
1928 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001930}
Harald Welte685d5982018-02-27 20:42:05 +01001931testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1932 var ConnHdlr vc_conn;
1933 var ConnHdlrPars pars;
1934 f_init(testcasename());
1935 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1936 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1937 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1938 pars.l1_pars.toa256_enabled := true;
1939 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1940 vc_conn.done;
1941 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001943}
1944
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001945/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1946 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1947function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1948 var L1ctlDlMessage l1_dl;
1949 var RSL_IE_MS_Power ms_power;
1950 var RSL_Message rsl;
1951 var uint5_t power_level := 0;
1952
1953 f_l1_tune(L1CTL);
1954 RSL.clear;
1955
1956 f_est_dchan();
1957
1958 ms_power.reserved := 0;
1959 ms_power.fpc_epc := false;
1960
1961 /* Send the first power control command. This will disable any BTS/TRX
1962 * internal power control and switch the MS (which is not in scope of
1963 * this test) to a constant power level. We start with a power level
1964 * of 0 */
1965 ms_power.power_level := power_level;
1966 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1967 RSL.send(rsl);
1968
1969 alt {
1970
1971 /* Pick all SACCH blocks for checking */
1972 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1973
1974 /* The first byte of the L1 header contains the power level.
1975 * The reserved bits and the fpc bit is set to 0, so we may
1976 * compare directly. */
1977 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1978 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1979 }
1980
1981 /* Signal a new power level via RSL for the next turn. */
1982 if (power_level < 31) {
1983 power_level := power_level + 1;
1984 ms_power.power_level := power_level;
1985 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1986 RSL.send(rsl);
1987 repeat;
1988 }
1989
1990 }
1991
1992 /* Ignore all other blocks */
1993 [] L1CTL.receive { repeat; }
1994
1995 }
1996
1997 f_rsl_chan_deact();
1998 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1999
2000 setverdict(pass);
2001}
2002
2003testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2004 var ConnHdlr vc_conn;
2005 var ConnHdlrPars pars;
2006 f_init(testcasename());
2007
2008 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2009 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2010 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2011 vc_conn.done;
2012 }
2013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2014}
Harald Welte70767382018-02-21 12:16:40 +01002015
Eric Wild6833cc92019-05-23 19:34:44 +02002016/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2017TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2018function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2019 var L1ctlDlMessage l1_dl;
2020 var uint5_t ta_to_test := 16;
2021
2022
2023 f_l1_tune(L1CTL);
2024 RSL.clear;
2025
2026 /* tell fake_trx to use a given timing offset for all bursts */
2027 f_trx_fake_toffs256(ta_to_test*256);
2028
2029 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2030
2031
2032 alt {
2033
2034 /* Pick all SACCH blocks for checking */
2035 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2036
2037 /* The second byte of the L1 header contains the TA. */
2038 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2039 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2040 }
2041
2042 }
2043
2044 /* Ignore all other blocks */
2045 [] L1CTL.receive { repeat; }
2046
2047 }
2048
2049 f_rsl_chan_deact();
2050 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2051
2052 setverdict(pass);
2053}
2054
2055testcase TC_rsl_chan_initial_ta() runs on test_CT {
2056 var ConnHdlr vc_conn;
2057 var ConnHdlrPars pars;
2058 f_init(testcasename());
2059 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2060 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
2061 vc_conn.done;
2062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2063}
2064
Eric Wilde57e1a62019-05-28 13:30:55 +02002065/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2066function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2067 var L1ctlDlMessage l1_dl;
2068 var uint5_t ms_power_level := 7;
2069
2070 var RSL_IE_MS_Power ms_power;
2071 ms_power.reserved := 0;
2072 ms_power.fpc_epc := false;
2073 ms_power.power_level := ms_power_level;
2074
2075 f_l1_tune(L1CTL);
2076 RSL.clear;
2077
2078 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2079
2080 timer T := 1.0;
2081 T.start;
2082 alt {
2083 /* Pick all SACCH blocks for checking */
2084 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2085 /* The first byte of the L1 header contains the power level.. */
2086 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2087 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2088 }
2089 }
2090 /* Ignore all other blocks */
2091 [] L1CTL.receive { repeat; }
2092 [] T.timeout {
2093 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2094 }
2095 }
2096
2097 f_rsl_chan_deact();
2098 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2099 setverdict(pass);
2100}
2101
2102testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2103 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2104 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2105}
2106
Harald Welte0472ab42018-03-12 15:02:26 +01002107/* 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 +01002108private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002109 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002110 RSL.clear;
2111
2112 f_est_dchan();
2113 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002114 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002115
2116 timer T := 40.0;
2117 T.start;
2118 alt {
2119 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2120 setverdict(pass)
2121 }
2122 [] RSL.receive { repeat };
2123 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002124 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002125 }
2126 }
2127 f_rsl_chan_deact();
2128}
2129testcase TC_conn_fail_crit() runs on test_CT {
2130 var ConnHdlr vc_conn;
2131 var ConnHdlrPars pars;
2132 f_init(testcasename());
2133 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2134 pars.t_guard := 60.0;
2135 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2136 vc_conn.done;
2137}
2138
Harald Welte93640c62018-02-25 16:59:33 +01002139/***********************************************************************
2140 * Paging
2141 ***********************************************************************/
2142
Harald Welte68e495b2018-02-25 00:05:57 +01002143function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2144 if (tmsi == 'FFFFFFFF'O) {
2145 return true;
2146 } else {
2147 return false;
2148 }
2149}
Harald Welte70767382018-02-21 12:16:40 +01002150
Philipp Maier82cb0b12018-08-31 14:41:39 +02002151type record allowedFn { integer frame_nr }
2152template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2153template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2154template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2155template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2156template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2157template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2158template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2159template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2160function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2161{
2162 var integer frame_nr_51;
2163 frame_nr_51 := frame_nr mod 51
2164
2165 var allowedFn fn_check;
2166 fn_check.frame_nr := frame_nr_51;
2167
2168 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002170 return;
2171 }
2172
2173 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2174 return;
2175 }
2176 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2177 return;
2178 }
2179 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2180 return;
2181 }
2182 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2183 return;
2184 }
2185 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2186 return;
2187 }
2188 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2189 return;
2190 }
2191 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2192 return;
2193 }
2194 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2195 return;
2196 }
2197
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002199 return;
2200}
2201
2202altstep 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 +01002203runs on test_CT {
2204 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002205 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002206 repeat;
2207 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002208 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002209 var octetstring without_plen :=
2210 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2211 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002212
2213 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2214
Harald Welte68e495b2018-02-25 00:05:57 +01002215 if (match(rr, tr_PAGING_REQ1)) {
2216 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2217 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2218 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2219 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2220 }
2221 } else if (match(rr, tr_PAGING_REQ2)) {
2222 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2223 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2224 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2225 }
2226 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2227 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2228 }
2229 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2230 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2231 }
2232 } else if (match(rr, tr_PAGING_REQ3)) {
2233 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2234 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2235 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2236 }
2237 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2238 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2239 }
2240 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2241 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2242 }
2243 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2244 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2245 }
2246 }
2247 repeat;
2248 }
2249}
2250
2251type record PagingTestCfg {
2252 boolean combined_ccch,
2253 integer bs_ag_blks_res,
2254 float load_factor,
2255 boolean exp_load_ind,
2256 boolean exp_overload,
2257 boolean use_tmsi
2258}
2259
2260type record PagingTestState {
2261 integer num_paging_sent,
2262 integer num_paging_rcv_msgs,
2263 integer num_paging_rcv_ids,
2264 integer num_overload
2265}
2266
2267/* receive + ignore RSL RF RES IND */
2268altstep as_rsl_res_ind() runs on test_CT {
2269 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2270 repeat;
2271 }
2272}
2273
2274/* Helper function for paging related testing */
2275private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2276 f_init(testcasename());
2277 f_init_l1ctl();
2278 f_l1_tune(L1CTL);
2279
2280 var PagingTestState st := {
2281 num_paging_sent := 0,
2282 num_paging_rcv_msgs := 0,
2283 num_paging_rcv_ids := 0,
2284 num_overload := 0
2285 };
2286
2287 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2288 var float max_pch_imsi_per_sec;
2289 if (cfg.use_tmsi) {
2290 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2291 } else {
2292 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2293 }
2294 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2295 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002296 var float time_total := 20.0;
2297 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2298 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002299
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002300 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2301 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002302
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002303 timer T_itv := 0.0;
2304 T_itv.start;
2305 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002306 alt {
2307 /* check for presence of CCCH LOAD IND (paging load) */
2308 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2309 st.num_overload := st.num_overload + 1;
2310 repeat;
2311 }
2312 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002314 }
2315 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2316 log("Rx LOAD_IND");
2317 /* FIXME: analyze/verify interval + contents */
2318 repeat;
2319 }
2320 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002321 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002322 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002323 [] T_itv.timeout {
2324 /* Send paging cmds based on elapsed time */
2325 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2326 while (st.num_paging_sent < new_sent) {
2327 /* build mobile Identity */
2328 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2329 if (cfg.use_tmsi) {
2330 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2331 } else {
2332 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2333 }
2334 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2335 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2336
2337 /* Send RSL PAGING COMMAND */
2338 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2339
2340 st.num_paging_sent := st.num_paging_sent + 1;
2341 }
2342 if (st.num_paging_sent < pkt_total) {
2343 /* Wait for interval to next PAGING COMMAND */
2344 var float time_now := T_total.read;
2345 var float next_sched := int2float(st.num_paging_sent)*interval;
2346 if (next_sched > time_now) {
2347 T_itv.start(next_sched - time_now);
2348 } else {
2349 T_itv.start(0.0);
2350 }
2351 } else {
2352 /* We are done, no need to keep counting */
2353 T_total.stop;
2354 }
2355 }
2356 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002357 [] as_rsl_res_ind();
2358 }
2359 }
2360
2361 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2362 timer T_wait := 18.0;
2363 T_wait.start;
2364 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002365 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002366 [] L1CTL.receive { repeat; }
2367 /* 65535 == empty paging queue, we can terminate*/
2368 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2369 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2370 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002372 }
2373 [] as_rsl_res_ind();
2374 }
2375
2376 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2377 " rcvd_ids=", st.num_paging_rcv_ids);
2378 return st;
2379}
2380
2381/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2382 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2383 * - that CCCH LOAD IND (PCH) are being generated
2384 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2385testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002386 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002387 var PagingTestCfg cfg := {
2388 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002389 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002390 load_factor := 0.8,
2391 exp_load_ind := true,
2392 exp_overload := false,
2393 use_tmsi := false
2394 };
2395 var PagingTestState st := f_TC_paging(cfg);
2396 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2398 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002399 } else {
2400 setverdict(pass);
2401 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002403}
2404
2405/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2406 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2407 * - that CCCH LOAD IND (PCH) are being generated
2408 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2409testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002410 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002411 var PagingTestCfg cfg := {
2412 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002413 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002414 load_factor := 0.8,
2415 exp_load_ind := true,
2416 exp_overload := false,
2417 use_tmsi := true
2418 };
2419 var PagingTestState st := f_TC_paging(cfg);
2420 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2422 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002423 } else {
2424 setverdict(pass);
2425 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002427}
2428
2429/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2430 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2431 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2432 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2433testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002434 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002435 var PagingTestCfg cfg := {
2436 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002437 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002438 load_factor := 2.0,
2439 exp_load_ind := true,
2440 exp_overload := true,
2441 use_tmsi := false
2442 };
2443 var PagingTestState st := f_TC_paging(cfg);
2444 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2445 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002446 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002447 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002448 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 +01002449 } else {
2450 setverdict(pass);
2451 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002453}
2454
2455/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2456 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2457 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2458 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2459testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002460 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002461 var PagingTestCfg cfg := {
2462 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002463 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002464 load_factor := 2.0,
2465 exp_load_ind := true,
2466 exp_overload := true,
2467 use_tmsi := true
2468 };
2469 var PagingTestState st := f_TC_paging(cfg);
2470 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2471 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002472 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002473 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002474 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 +01002475 } else {
2476 setverdict(pass);
2477 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002479}
2480
2481
Harald Welte93640c62018-02-25 16:59:33 +01002482/***********************************************************************
2483 * Immediate Assignment / AGCH
2484 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002485const MobileAllocation c_MA_null := {
2486 len := 0,
2487 ma := ''B
2488}
Harald Welte93640c62018-02-25 16:59:33 +01002489
Harald Weltee8d750e2018-06-10 21:41:35 +02002490template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2491 uint12_t arfcn := 871) := {
2492 chan_nr := chan_nr,
2493 tsc := tsc,
2494 h := false,
2495 arfcn := arfcn,
2496 maio_hsn := omit
2497}
2498
2499private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2500 return int2str(num_tx) & " sent, "
2501 & int2str(num_rx) & " received, "
2502 & int2str(num_del) & " deleted";
2503}
2504
2505private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2506 var L1ctlDlMessage l1_dl;
2507 timer T := 10.0;
2508 var integer num_tx := 0;
2509 var integer num_rx := 0;
2510 var integer num_del := 0;
2511 var charstring res_str;
2512 var float rx_ratio;
2513
Harald Welte68e495b2018-02-25 00:05:57 +01002514 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002515 f_init_l1ctl();
2516 f_l1_tune(L1CTL);
2517
2518 for (var integer i := 0; i < num_total; i := i+1) {
2519 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2520 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2521 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002522 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002523 num_tx := num_tx+1;
2524 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002525 }
2526 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002527 T.start;
2528 alt {
2529 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2530 num_del := num_del+1;
2531 repeat;
2532 }
2533 [] RSL_CCHAN.receive {
2534 repeat;
2535 }
2536 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2537 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2538 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2539 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2540 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002541 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002542 } else {
2543 num_rx := num_rx+1;
2544 }
2545 repeat;
2546 }
2547 [] L1CTL.receive { repeat; }
2548 [] T.timeout { }
2549 }
2550 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2551 log("AGCH test: " & res_str);
2552 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002553 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002554 }
2555 rx_ratio := int2float(num_rx) / int2float(num_tx);
2556 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002557 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 +02002558 } else {
2559 setverdict(pass);
2560 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002562}
2563
Harald Weltee8d750e2018-06-10 21:41:35 +02002564/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2565testcase TC_imm_ass_1000_20ms() runs on test_CT {
2566 f_TC_imm_ass(1000, 0.02, 0.25);
2567}
2568
2569/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2570testcase TC_imm_ass_200_0ms() runs on test_CT {
2571 f_TC_imm_ass(200, 0.0, 0.05);
2572}
2573
2574/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2575testcase TC_imm_ass_200_76ms() runs on test_CT {
2576 f_TC_imm_ass(150, 0.076, 1.00);
2577}
2578
2579
2580
Harald Welte48494ca2018-02-25 16:59:50 +01002581/***********************************************************************
2582 * BCCH
2583 ***********************************************************************/
2584
2585/* tuple of Frame Number + decoded SI */
2586type record SystemInformationFn {
2587 GsmFrameNumber frame_number,
2588 SystemInformation si
2589}
2590
2591/* an arbitrary-length vector of decoded SI + gsmtap header */
2592type record of SystemInformationFn SystemInformationVector;
2593
2594/* an array of SI-vectors indexed by TC value */
2595type SystemInformationVector SystemInformationVectorPerTc[8];
2596
2597/* determine if a given SI vector contains given SI type at least once */
2598function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2599 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2600 var integer fn_mod51 := arr[i].frame_number mod 51;
2601 if (not bcch_ext and fn_mod51 == 2 or
2602 bcch_ext and fn_mod51 == 6) {
2603 if (arr[i].si.header.message_type == key) {
2604 return true;
2605 }
2606 }
2607 }
2608 return false;
2609}
2610
2611/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2612function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2613 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002615 }
2616}
2617
2618/* check if a given SI vector contains given SI type at least once on any TC */
2619function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2620 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2621 if (f_si_vecslot_contains(arr[tc], key) or
2622 f_si_vecslot_contains(arr[tc], key, true)) {
2623 return true;
2624 }
2625 }
2626 return false;
2627}
2628
2629/* determine if a given SI vector contains given SI type at least N of M times */
2630function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2631 var integer count := 0;
2632 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002634 }
2635 for (var integer i:= 0; i < m; i := i + 1) {
2636 var integer fn_mod51 := arr[i].frame_number mod 51;
2637 if (not bcch_ext and fn_mod51 == 2 or
2638 bcch_ext and fn_mod51 == 6) {
2639 if (arr[i].si.header.message_type == key) {
2640 count := count + 1;
2641 }
2642 }
2643 }
2644 if (count >= n) {
2645 return true;
2646 } else {
2647 return false;
2648 }
2649}
2650
2651/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2652function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2653 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002655 }
2656}
2657
2658/* determine if a given SI vector contains given SI type at least once */
2659function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2660 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2661 var integer fn_mod51 := arr[i].frame_number mod 51;
2662 if (not bcch_ext and fn_mod51 == 2 or
2663 bcch_ext and fn_mod51 == 6) {
2664 if (arr[i].si.header.message_type != key) {
2665 return false;
2666 }
2667 }
2668 }
2669 return true;
2670}
2671
2672/* ensure a given TC slot of the SI vector contains only given SI type */
2673function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2674 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002676 }
2677}
2678
2679/* SI configuration of cell, against which we validate actual SI messages */
2680type set SystemInformationConfig {
2681 boolean bcch_extended,
2682 boolean si1_present,
2683 boolean si2bis_present,
2684 boolean si2ter_present,
2685 boolean si2quater_present,
2686 boolean si7_present,
2687 boolean si8_present,
2688 boolean si9_present,
2689 boolean si13_present,
2690 boolean si13alt_present,
2691 boolean si15_present,
2692 boolean si16_present,
2693 boolean si17_present,
2694 boolean si2n_present,
2695 boolean si21_present,
2696 boolean si22_present
2697}
2698
2699/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2700function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2701 var integer i;
2702 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2703 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002705 }
2706 }
2707 if (cfg.si1_present) {
2708 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2709 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2710 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2711 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2712 /* make sure *ALL* contain SI1 */
2713 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2714 }
2715 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2716 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2717 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2718 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2719 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2720 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2721
2722 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2723 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2724 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2725 * consecutive occurrences of TC = 4. */
2726 if (cfg.si2bis_present and not cfg.si2ter_present) {
2727 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2728 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2729 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2730 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2731 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2732 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2733 }
2734
2735 if (cfg.si7_present or cfg.si8_present) {
2736 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2737 * if System Information type 4 does not contain all information needed for cell
2738 * selection and reselection. */
2739 if (not cfg.bcch_extended) {
2740 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2741 }
2742 if (cfg.si7_present) {
2743 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2744 }
2745 if (cfg.si8_present) {
2746 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2747 }
2748 }
2749
2750 if (cfg.si2quater_present) {
2751 /* iii) System information type 2 quater is sent if needed, as determined by the system
2752 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2753 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2754 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2755 * within any of 4 consecutive occurrences of TC = 5. */
2756 if (not (cfg.bcch_extended)) {
2757 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2758 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2759 } else {
2760 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2761 }
2762 } else {
2763 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2764 }
2765 }
2766 if (cfg.si9_present) {
2767 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2768 * in system information type 3 as defined in 3GPP TS 44.018. */
2769 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2770 }
2771 if (cfg.si13_present) {
2772 /* vii) System Information type 13 is only related to the GPRS service. System Information
2773 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2774 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2775 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2776 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2777 * within any of 4 consecutive occurrences of TC=4. */
2778 if (not cfg.bcch_extended) {
2779 log("not-bccch-extended");
2780 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2781 } else {
2782 log("bccch-extended");
2783 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2784 }
2785 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002787 }
2788 }
2789 if (cfg.si16_present or cfg.si17_present) {
2790 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2791 * should not be sent in a cell where network sharing is used (see rule xv). */
2792 if (cfg.si22_present) {
2793 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2794 }
2795 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002797 }
2798 if (not cfg.bcch_extended) {
2799 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2800 }
2801 if (cfg.si16_present) {
2802 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2803 }
2804 if (cfg.si17_present) {
2805 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2806 }
2807 }
2808
2809 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2810 * broadcast information. The frequency with which they are sent is determined by the
2811 * system operator. System Information type 9 identifies the scheduling of System
2812 * Information type 18 and 20 messages. */
2813
2814 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2815 * Information Type 19 is present, then its scheduling shall be indicated in System
2816 * Information Type 9. */
2817
2818 if (cfg.si15_present) {
2819 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2820 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2821 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2822 * 4 consecutive occurrences of TC = 1. */
2823 if (not cfg.bcch_extended) {
2824 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2825 } else {
2826 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2827 }
2828 }
2829 if (cfg.si13alt_present) {
2830 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2831 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2832 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2833 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2834 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2835 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2836 * of TC = 4. */
2837 if (cfg.si13_present) {
2838 testcase.stop("Error: Cannot have SI13alt and SI13");
2839 }
2840 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002842 }
2843 if (not cfg.bcch_extended) {
2844 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2845 } else {
2846 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2847 }
2848 }
2849 if (cfg.si2n_present) {
2850 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2851 * as determined by the system operator. In the case that the message is sent on the
2852 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2853 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2854 * consecutive occurrences of TC = 4. */
2855 if (not cfg.bcch_extended) {
2856 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2857 } else {
2858 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2859 }
2860 }
2861 if (cfg.si21_present) {
2862 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2863 * determined by the system operator. If Extended Access Barring is in use in the cell
2864 * then this message is sent at least once within any of 4 consecutive occurrences of
2865 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2866 * cell then this message shall only be sent on BCCH Ext. */
2867 if (not cfg.bcch_extended) {
2868 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2869 } else {
2870 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2871 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002873 }
2874 }
2875 }
2876 if (cfg.si22_present) {
2877 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2878 * should not be sent in a cell where SoLSA is used (see rule viii). System
2879 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2880 * =2 and TC=6. */
2881 if (cfg.si16_present or cfg.si17_present) {
2882 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2883 }
2884 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2885 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002887 }
2888 if (not cfg.bcch_extended) {
2889 testcase.stop("Error: SI22 requires BCCH Extd!");
2890 } else {
2891 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2892 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2893 }
2894 }
2895}
2896
2897/* sample Systme Information for specified duration via L1CTL */
2898function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2899 timer T := duration;
2900 var SystemInformationVectorPerTc si_per_tc;
2901 var L1ctlDlMessage l1_dl;
2902
2903 /* initialize all per-TC vectors empty */
2904 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2905 si_per_tc[i] := {};
2906 }
2907
2908 /* flush all previous L1 queued msgs */
2909 pt.clear;
2910
2911 T.start;
2912 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002913 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002914 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2915 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2916 log("Ignoring non-RR SI ", l1_dl);
2917 repeat;
2918 }
2919 var SystemInformationFn sig := {
2920 frame_number := l1_dl.dl_info.frame_nr,
2921 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2922 }
2923 var integer tc := f_gsm_compute_tc(sig.frame_number);
2924 log("SI received at TC=", tc, ": ", sig.si);
2925 /* append to the per-TC bucket */
2926 si_per_tc[tc] := si_per_tc[tc] & { sig };
2927 repeat;
2928 }
2929 [] pt.receive { repeat; }
2930 [] T.timeout { }
2931 }
2932
2933 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2934 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2935 }
2936 log("si_per_tc=", si_per_tc);
2937 return si_per_tc;
2938}
2939
2940/* helper function: Set given SI via RSL + validate scheduling.
2941 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2942function f_TC_si_sched() runs on test_CT {
2943 var SystemInformationVectorPerTc si_per_tc;
2944 f_init_l1ctl();
2945 f_l1_tune(L1CTL);
2946
2947 /* Sample + Validate Scheduling */
2948 si_per_tc := f_l1_sample_si(L1CTL);
2949 f_validate_si_scheduling(si_cfg, si_per_tc);
2950
2951 setverdict(pass);
2952}
2953
2954testcase TC_si_sched_default() runs on test_CT {
2955 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002956 /* 2+3+4 are mandatory and set in f_init() */
2957 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002959}
2960
2961testcase TC_si_sched_1() runs on test_CT {
2962 f_init();
2963 si_cfg.si1_present := true;
2964 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002965 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002967}
2968
2969testcase TC_si_sched_2bis() runs on test_CT {
2970 f_init();
2971 si_cfg.si2bis_present := true;
2972 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2973 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002975}
2976
2977testcase TC_si_sched_2ter() runs on test_CT {
2978 f_init();
2979 si_cfg.si2ter_present := true;
2980 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2981 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002983}
2984
2985testcase TC_si_sched_2ter_2bis() runs on test_CT {
2986 f_init();
2987 si_cfg.si2bis_present := true;
2988 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2989 si_cfg.si2ter_present := true;
2990 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2991 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002993}
2994
2995testcase TC_si_sched_2quater() runs on test_CT {
2996 f_init();
2997 si_cfg.si2quater_present := true;
2998 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2999 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003001}
3002
3003testcase TC_si_sched_13() runs on test_CT {
3004 f_init();
3005 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003006 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003007 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003009}
3010
3011testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3012 f_init();
3013 si_cfg.si2bis_present := true;
3014 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3015 si_cfg.si2ter_present := true;
3016 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3017 si_cfg.si2quater_present := true;
3018 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3019 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003020 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003021 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003023}
3024
3025
Harald Welte68e495b2018-02-25 00:05:57 +01003026testcase TC_bcch_info() runs on test_CT {
3027 f_init(testcasename());
3028 /* FIXME: enable / disable individual BCCH info */
3029 //ts_RSL_BCCH_INFO(si_type, info);
3030 /* expect no ERROR REPORT after either of them *
3031 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003033}
3034
Harald Welte93640c62018-02-25 16:59:33 +01003035/***********************************************************************
3036 * Low-Level Protocol Errors / ERROR REPORT
3037 ***********************************************************************/
3038
Harald Welte01d982c2018-02-25 01:31:40 +01003039private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3040 timer T := 5.0;
3041 T.start;
3042 alt {
3043 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3044 setverdict(pass);
3045 }
3046 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003048 }
3049 [] RSL_CCHAN.receive {
3050 repeat;
3051 }
3052 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003054 }
3055 }
3056}
3057
3058/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3059testcase TC_rsl_protocol_error() runs on test_CT {
3060 f_init(testcasename());
3061 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3062 rsl.ies := omit;
3063 RSL_CCHAN.send(ts_RSL_UD(rsl));
3064
3065 f_exp_err_rep(RSL_ERR_PROTO);
3066}
3067
3068/* Provoke a mandatory IE error and match on ERROR REPORT */
3069testcase TC_rsl_mand_ie_error() runs on test_CT {
3070 f_init(testcasename());
3071
3072 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3073 rsl.ies := { rsl.ies[0] };
3074 RSL_CCHAN.send(ts_RSL_UD(rsl));
3075
3076 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3077}
3078
3079/* Provoke an IE content error and match on ERROR REPORT */
3080testcase TC_rsl_ie_content_error() runs on test_CT {
3081 f_init(testcasename());
3082 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3083 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3084 RSL_CCHAN.send(ts_RSL_UD(rsl));
3085
3086 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3087}
3088
Harald Welteee25aae2019-05-19 14:32:37 +02003089/* attempt to activate channel with wrong RSL Message Discriminator IE */
3090function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3091 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3092 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3093 RSL.send(rsl);
3094 f_rslem_unregister(0, g_chan_nr);
3095}
3096testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3097 var ConnHdlr vc_conn;
3098 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3099
3100 f_init(testcasename());
3101
3102 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3103 vc_conn.done;
3104 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3105
3106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3107}
3108
3109/* Send messages with wrong message type */
3110function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3111 var template (value) RSL_Message rsl_tx;
3112 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3113 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3114 RSL.send(rsl_tx);
3115 f_rslem_unregister(0, g_chan_nr);
3116}
3117function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3118 var template (value) RSL_Message rsl_tx;
3119 /* we first have to activate the dedicated channel */
3120 f_rsl_chan_act(g_pars.chan_mode);
3121 /* ... to then send an invalid RLL message */
3122 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3123 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3124 RSL.send(rsl_tx);
3125 f_rslem_unregister(0, g_chan_nr);
3126}
3127testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3128 var ConnHdlr vc_conn;
3129 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3130 var template (value) RSL_Message rsl_tx;
3131
3132 f_init(testcasename());
3133
3134 /* Common Channel with wrong message type */
3135 RSL_CCHAN.clear;
3136 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3137 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3138 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3139 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3140
3141 /* TRX Management */
3142 RSL_CCHAN.clear;
3143 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3144 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3145 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3146 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3147
3148 /* Dedicated Channel */
3149 RSL_CCHAN.clear;
3150 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3151 vc_conn.done;
3152 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3153
3154 /* RLL */
3155 RSL_CCHAN.clear;
3156 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3157 vc_conn.done;
3158 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3159}
3160
3161/* Send messages in wrong sequence (RLL to an inactive lchan) */
3162function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3163 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3164 f_rslem_unregister(0, g_chan_nr);
3165}
3166testcase TC_err_rep_wrong_sequence() runs on test_CT {
3167 var ConnHdlr vc_conn;
3168 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3169
3170 f_init(testcasename());
3171
3172 RSL_CCHAN.clear;
3173 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3174 vc_conn.done;
3175 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3176}
3177
Harald Welte93640c62018-02-25 16:59:33 +01003178/***********************************************************************
3179 * IPA CRCX/MDCX/DLCS media stream handling
3180 ***********************************************************************/
3181
Harald Weltea871a382018-02-25 02:03:14 +01003182/* Send IPA DLCX to inactive lchan */
3183function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003184 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3185 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003186}
3187testcase TC_ipa_dlcx_not_active() runs on test_CT {
3188 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3189 f_init(testcasename());
3190 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3191 vc_conn.done;
3192}
Harald Welte68e495b2018-02-25 00:05:57 +01003193
Harald Weltea3f1df92018-02-25 12:49:55 +01003194/* Send IPA CRCX twice to inactive lchan */
3195function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3196 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3197 "IPA CRCX ACK");
3198 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3199 "IPA CRCX NACK");
3200}
3201testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3202 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3203 f_init(testcasename());
3204 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3205 vc_conn.done;
3206}
3207
3208/* Regular sequence of CRCX/MDCX/DLCX */
3209function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3210 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3211 "IPA CRCX ACK");
3212 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3213 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3214 var uint7_t rtp_pt2 := f_rnd_int(127);
3215 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3216 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3217 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3218 "IPA MDCX ACK");
3219 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3220 "IPA DLCX ACK");
3221}
3222testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3223 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3224 f_init(testcasename());
3225 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3226 vc_conn.done;
3227}
3228
Harald Welte3ae11da2018-02-25 13:36:06 +01003229/* Sequence of CRCX, 2x MDCX, DLCX */
3230function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3231 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3232 "IPA CRCX ACK");
3233 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3234 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3235 var uint7_t rtp_pt2 := f_rnd_int(127);
3236 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3237 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3238 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3239 "IPA MDCX ACK");
3240 /* Second MDCX */
3241 remote_ip := f_rnd_int(c_UINT32_MAX);
3242 remote_port := f_rnd_int(c_UINT16_MAX);
3243 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3244 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3245 "IPA MDCX ACK");
3246 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3247 "IPA DLCX ACK");
3248}
3249testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3250 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3251 f_init(testcasename());
3252 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3253 vc_conn.done;
3254}
3255
Harald Welte9912eb52018-02-25 13:30:15 +01003256/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3257function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3258 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3259 "IPA CRCX NACK");
3260}
3261testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3262 var ConnHdlrPars pars;
3263 var ConnHdlr vc_conn;
3264 f_init(testcasename());
3265
3266 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3267 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3268 vc_conn.done;
3269
3270 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3271 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3272 vc_conn.done;
3273}
3274
Harald Weltea3f1df92018-02-25 12:49:55 +01003275
Harald Welte883340c2018-02-28 18:59:29 +01003276/***********************************************************************
3277 * PCU Socket related tests
3278 ***********************************************************************/
3279
Harald Welte07bd2d22019-05-25 11:03:30 +02003280/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003281friend 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 +01003282runs on test_CT {
3283 timer T := 3.0;
3284
3285 /* we don't expect any RTS.req before PDCH are active */
3286 T.start;
3287 alt {
3288 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003290 }
3291 [] PCU.receive { repeat; }
3292 [] T.timeout { }
3293 }
3294
3295 /* Send PDCH activate request for known PDCH timeslot */
3296 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3297
3298 /* we now expect RTS.req for this timeslot (only) */
3299 T.start;
3300 alt {
3301 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3302 setverdict(pass);
3303 }
3304 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3305 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003307 }
3308 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003310 }
3311 [] PCU.receive { repeat; }
3312 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003314 }
3315 [not exp_success] T.timeout {
3316 setverdict(pass);
3317 }
3318 }
3319}
3320
Harald Welte07bd2d22019-05-25 11:03:30 +02003321/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003322friend 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 +01003323runs on test_CT {
3324 timer T := 3.0;
3325
3326 /* Send PDCH activate request for known PDCH timeslot */
3327 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3328
3329 PCU.clear;
3330 /* we now expect no RTS.req for this timeslot */
3331 T.start;
3332 alt {
3333 [] 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 +02003334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003335 }
3336 [] PCU.receive { repeat; }
3337 [] T.timeout {
3338 setverdict(pass);
3339 }
3340 }
3341}
3342
Harald Weltead033dc2019-05-25 17:28:16 +02003343friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003344 f_init();
3345 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3346}
3347
Harald Welte883340c2018-02-28 18:59:29 +01003348/* PDCH activation via PCU socket; check for presence of RTS.req */
3349testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003350 f_init_pcu_test();
3351
Harald Welte883340c2018-02-28 18:59:29 +01003352 f_TC_pcu_act_req(0, 0, 7, true);
3353}
3354
3355/* PDCH activation via PCU socket on non-PDCU timeslot */
3356testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003357 f_init_pcu_test();
3358
Harald Welte883340c2018-02-28 18:59:29 +01003359 f_TC_pcu_act_req(0, 0, 1, false);
3360}
3361
3362/* PDCH activation via PCU socket on wrong BTS */
3363testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003364 f_init_pcu_test();
3365
Harald Welte883340c2018-02-28 18:59:29 +01003366 f_TC_pcu_act_req(23, 0, 7, false);
3367}
3368
3369/* PDCH activation via PCU socket on wrong TRX */
3370testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003371 f_init_pcu_test();
3372
Harald Welte883340c2018-02-28 18:59:29 +01003373 f_TC_pcu_act_req(0, 23, 7, false);
3374}
3375
3376/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3377testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003378 f_init_pcu_test();
3379
Harald Welte883340c2018-02-28 18:59:29 +01003380 /* Activate PDCH */
3381 f_TC_pcu_act_req(0, 0, 7, true);
3382 f_sleep(1.0);
3383 /* and De-Activate again */
3384 f_TC_pcu_deact_req(0, 0, 7);
3385}
3386
3387/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3388testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003389 f_init_pcu_test();
3390
Harald Welte883340c2018-02-28 18:59:29 +01003391 f_TC_pcu_deact_req(0, 0, 1);
3392}
3393
3394/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3395testcase TC_pcu_ver_si13() runs on test_CT {
3396 const octetstring si13 := '00010203040506070909'O;
3397 var PCUIF_send_data sd;
3398 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003399 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003400
3401 /* Set SI13 via RSL */
3402 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003403
Harald Welte883340c2018-02-28 18:59:29 +01003404 T.start;
3405 alt {
3406 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3407 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3408 setverdict(pass);
3409 } else {
3410 repeat;
3411 }
3412 }
3413 [] PCU.receive { repeat; }
3414 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003416 }
3417 }
3418}
3419
3420private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3421
3422/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003423friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003424 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3425runs on test_CT
3426{
3427 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3428 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3429}
3430
3431/* 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 +02003432friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3433 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003434runs on test_CT
3435{
3436 var PCUIF_send_data sd;
3437
3438 timer T := 3.0;
3439 T.start;
3440 alt {
3441 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3442 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3443 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3444 sd.data.u.rts_req.fn, sapi, data);
3445 }
3446 [] PCU.receive { repeat; }
3447 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003449 }
3450 }
3451}
3452
3453/* Send DATA.req on invalid BTS */
3454testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003455 var TfiUsfArr tua := f_TfiUsfArrInit();
3456 var octetstring data := '0000'O & f_rnd_octstring(21);
3457
3458 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003459
Harald Welte883340c2018-02-28 18:59:29 +01003460 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003461 f_TfiUsfArrSet(tua, 7, 0);
3462 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3463 f_sleep(1.0);
3464
3465 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003466}
3467
3468/* Send DATA.req on invalid TRX */
3469testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003470 var TfiUsfArr tua := f_TfiUsfArrInit();
3471 var octetstring data := '0000'O & f_rnd_octstring(21);
3472
3473 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003474
Harald Welte883340c2018-02-28 18:59:29 +01003475 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003476 f_TfiUsfArrSet(tua, 7, 0);
3477 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3478 f_sleep(1.0);
3479
3480 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003481}
3482
3483/* Send DATA.req on invalid timeslot */
3484testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003485 var TfiUsfArr tua := f_TfiUsfArrInit();
3486 var octetstring data := '0000'O & f_rnd_octstring(21);
3487
3488 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003489
Harald Welte883340c2018-02-28 18:59:29 +01003490 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003491 f_TfiUsfArrSet(tua, 7, 0);
3492 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3493 f_sleep(1.0);
3494
3495 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003496}
3497
3498/* Send DATA.req on timeslot that hasn't been activated */
3499testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003500 var TfiUsfArr tua := f_TfiUsfArrInit();
3501 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003502
Harald Welte7162a612019-05-26 12:56:09 +02003503 f_virtphy_common();
3504
3505 f_TfiUsfArrSet(tua, 7, 0);
3506 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3507 f_sleep(1.0);
3508
3509 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003510}
3511
Harald Weltead033dc2019-05-25 17:28:16 +02003512private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003513 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3514 boolean wait_rts := true)
3515runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003516 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003517 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003518
3519 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003520 if (wait_rts) {
3521 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3522 } else {
3523 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3524 }
Harald Weltead033dc2019-05-25 17:28:16 +02003525
3526 T.start;
3527 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003528 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003529 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3530 setverdict(pass);
3531 }
Harald Welte7162a612019-05-26 12:56:09 +02003532 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3533 setverdict(fail, "Received unexpected ", rx_dl);
3534 }
Harald Weltead033dc2019-05-25 17:28:16 +02003535 [] L1CTL.receive {
3536 repeat;
3537 }
Harald Welte7162a612019-05-26 12:56:09 +02003538 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003539 setverdict(fail, "Timeout waiting for ", data);
3540 }
Harald Welte7162a612019-05-26 12:56:09 +02003541 [not expect_data] T.timeout {
3542 setverdict(pass);
3543 }
Harald Weltead033dc2019-05-25 17:28:16 +02003544 }
3545}
3546
3547private function f_disable_dynamic_ts() runs on test_CT
3548{
3549 f_init_vty_bsc();
3550 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3551 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3552 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3553 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003554 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003555}
3556
3557private function f_virtphy_common() runs on test_CT {
3558 f_disable_dynamic_ts();
3559 f_init_l1ctl();
3560 f_l1_tune(L1CTL);
3561}
3562
3563testcase TC_pcu_data_req_pdtch() runs on test_CT {
3564 var TfiUsfArr tua := f_TfiUsfArrInit();
3565 var octetstring data := '0000'O & f_rnd_octstring(21);
3566
3567 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003568
Harald Welte883340c2018-02-28 18:59:29 +01003569 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003570 f_TfiUsfArrSet(tua, 7, 0);
3571 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3572 f_sleep(1.0);
3573
3574 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003575}
3576
3577testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003578 var TfiUsfArr tua := f_TfiUsfArrInit();
3579 var octetstring data := '0000'O & f_rnd_octstring(21);
3580
3581 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003582
Harald Welte883340c2018-02-28 18:59:29 +01003583 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003584 f_TfiUsfArrSet(tua, 7, 0);
3585 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3586 f_sleep(1.0);
3587
3588 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003589}
3590
3591/* Send AGCH from PCU; check it appears on Um side */
3592testcase TC_pcu_data_req_agch() runs on test_CT {
3593 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003594 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003595 f_init_l1ctl();
3596 f_l1_tune(L1CTL);
3597
3598 f_TC_pcu_act_req(0, 0, 7, true);
3599 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3600
3601 T.start;
3602 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003603 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003604 setverdict(pass);
3605 }
3606 [] L1CTL.receive { repeat; }
3607 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003609 }
3610 }
3611}
3612
Harald Welte928622b2019-05-26 13:22:59 +02003613/* Send AGCH from PCU; check it appears on Um side */
3614testcase TC_pcu_data_req_pch() runs on test_CT {
3615 timer T := 3.0;
3616 f_init_pcu_test();
3617 f_init_l1ctl();
3618 f_l1_tune(L1CTL);
3619
3620 f_TC_pcu_act_req(0, 0, 7, true);
3621 /* three characters prefix: last 3 digits of IMSI as ASCII */
3622 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3623
3624 T.start;
3625 alt {
3626 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3627 setverdict(pass);
3628 }
3629 [] L1CTL.receive { repeat; }
3630 [] T.timeout {
3631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3632 }
3633 }
3634}
3635
Harald Welte883340c2018-02-28 18:59:29 +01003636/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3637testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3638 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003639 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003640 f_init_l1ctl();
3641 f_l1_tune(L1CTL);
3642
3643 /* append 3 last imsi digits so BTS can compute pagng group */
3644 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3645
3646 timer T := 0.5;
3647 T.start;
3648 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003649 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003650 /* TODO: verify paging group */
3651 setverdict(pass);
3652 }
3653 [] L1CTL.receive { repeat; }
3654 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003656 }
3657 }
3658}
3659
3660/* Send RACH from Um side, expect it to show up on PCU socket */
3661testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003662 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003663 f_init_l1ctl();
3664 f_l1_tune(L1CTL);
3665
3666 var GsmFrameNumber fn_last := 0;
3667 for (var integer i := 0; i < 1000; i := i+1) {
3668 var OCT1 ra := f_rnd_ra_ps();
3669 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3670 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003672 }
3673 fn_last := fn;
3674
3675 timer T := 2.0;
3676 T.start;
3677 alt {
3678 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3679 T.stop;
3680 }
3681 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003683 }
3684 [] PCU.receive { repeat; }
3685 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003687 }
3688 }
3689 }
3690 setverdict(pass);
3691}
3692
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003693/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3694 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3695testcase TC_pcu_ext_rach_content() runs on test_CT {
3696 var template PCUIF_Message pcu_rach_ind;
3697 var GsmFrameNumber fn_last := 0;
3698 var L1ctlRachSynchSeq synch_seq;
3699 var PCUIF_BurstType pcu_bt;
3700 var GsmFrameNumber fn;
3701 var BIT11 ra11;
3702
3703 f_init_pcu_test();
3704 f_init_l1ctl();
3705 f_l1_tune(L1CTL);
3706
3707 for (var integer i := 0; i < 1000; i := i+1) {
3708 /* We need to test both TS1 & TS2 */
3709 if (i rem 2 == 0) {
3710 synch_seq := RACH_SYNCH_SEQ_TS1;
3711 pcu_bt := BURST_TYPE_1;
3712 } else {
3713 synch_seq := RACH_SYNCH_SEQ_TS2;
3714 pcu_bt := BURST_TYPE_2;
3715 }
3716
3717 ra11 := f_rnd_ra11_ps();
3718 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3719 if (fn == fn_last) {
3720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3721 "Two RACH in same FN?!?");
3722 }
3723 fn_last := fn;
3724
3725 /* Compose the expected message */
3726 pcu_rach_ind := tr_PCUIF_RACH_IND(
3727 bts_nr := 0,
3728 ra := bit2int(ra11),
3729 is_11bit := 1,
3730 burst_type := pcu_bt,
3731 fn := fn);
3732
3733 timer T := 2.0;
3734 T.start;
3735 alt {
3736 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3737 T.stop;
3738 }
3739 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3741 }
3742 [] PCU.receive { repeat; }
3743 [] T.timeout {
3744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3745 }
3746 }
3747 }
3748 setverdict(pass);
3749}
3750
Harald Welte883340c2018-02-28 18:59:29 +01003751/* Send PAGING via RSL, expect it to shw up on PCU socket */
3752testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003753 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003754
3755 for (var integer i := 0; i < 100; i := i+1) {
3756 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3757 timer T := 3.0;
3758 if (i < 50) {
3759 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3760 } else {
3761 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3762 }
3763 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3764 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3765 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3766
3767 /* Send RSL PAGING COMMAND */
3768 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3769 T.start;
3770 alt {
3771 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3772 }
3773 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003775 }
3776 [] PCU.receive { repeat; }
3777 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003779 }
3780 }
3781 }
3782 setverdict(pass);
3783}
3784
Harald Welted66c9b82019-05-25 09:03:15 +02003785/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3786testcase TC_pcu_time_ind() runs on test_CT {
3787 var PCUIF_send_data pcu_sd;
3788 var integer num_time_ind := 0;
3789 var integer first_fn, last_fn;
3790 var float test_duration := 5.0;
3791 timer T;
3792
3793 f_init_pcu_test();
3794 f_TC_pcu_act_req(0, 0, 7, true);
3795
3796 PCU.clear;
3797 T.start(test_duration);
3798 alt {
3799 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3800 num_time_ind := num_time_ind + 1;
3801 if (not isbound(first_fn)) {
3802 first_fn := pcu_sd.data.u.time_ind.fn;
3803 }
3804 last_fn := pcu_sd.data.u.time_ind.fn;
3805 repeat;
3806 }
3807 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3808 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3809 repeat;
3810 }
3811 [] PCU.receive {
3812 repeat;
3813 }
3814 [] T.timeout {}
3815 }
3816 var integer fn_expired := last_fn - first_fn;
3817 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3818
3819 /* verify the number of frames expired matches our expectation */
3820 const float c_GSM_FN_DURATION_MS := 4.61538;
3821 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003822 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003823 if (not match(fn_expired, t_fn_expected)) {
3824 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3825 }
3826
3827 /* There are three TIME.ind in every fn MOD 13 */
3828 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3829 /* Add some tolerance */
3830 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3831 if (not match(num_time_ind, t_time_ind_exp)) {
3832 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3833 }
3834
3835 setverdict(pass);
3836}
3837
Harald Welte4832c862019-05-25 14:57:18 +02003838/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3839testcase TC_pcu_rts_req() runs on test_CT {
3840 var PCUIF_send_data pcu_sd;
3841 var integer first_fn, last_fn;
3842 var integer num_rts_pdtch := 0;
3843 var integer num_rts_ptcch := 0;
3844 var float test_duration := 5.0;
3845 timer T;
3846
3847 f_init_pcu_test();
3848 f_TC_pcu_act_req(0, 0, 7, true);
3849
3850 PCU.clear;
3851 T.start(test_duration);
3852 alt {
3853 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3854 -> value pcu_sd {
3855 num_rts_pdtch := num_rts_pdtch + 1;
3856 if (not isbound(first_fn)) {
3857 first_fn := pcu_sd.data.u.rts_req.fn;
3858 }
3859 last_fn := pcu_sd.data.u.rts_req.fn;
3860 repeat;
3861 }
3862 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3863 -> value pcu_sd {
3864 num_rts_ptcch := num_rts_ptcch + 1;
3865 if (not isbound(first_fn)) {
3866 first_fn := pcu_sd.data.u.rts_req.fn;
3867 }
3868 last_fn := pcu_sd.data.u.rts_req.fn;
3869 repeat;
3870 }
3871 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3872 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3873 repeat;
3874 }
3875 [] PCU.receive {
3876 repeat;
3877 }
3878 [] T.timeout {}
3879 }
3880 var integer fn_expired := last_fn - first_fn;
3881 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3882 ", num_rts_ptcch=", num_rts_ptcch);
3883
3884 /* verify the number of frames expired matches our expectation */
3885 const float c_GSM_FN_DURATION_MS := 4.61538;
3886 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003887 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003888 if (not match(fn_expired, t_fn_expected)) {
3889 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3890 }
3891
3892 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3893 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3894 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3895 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3896 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3897 t_ptcch_exp);
3898 }
3899
3900 /* We have 12 PDTCH blocks every 52-multiframe */
3901 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3902 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3903 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3904 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3905 t_pdtch_exp);
3906 }
3907
3908 setverdict(pass);
3909}
3910
Harald Welte07bd2d22019-05-25 11:03:30 +02003911/* test for generating Abis side OML ALERT from the PCU */
3912testcase TC_pcu_oml_alert() runs on test_CT {
3913 var PCUIF_send_data pcu_sd;
3914 var integer num_time_ind := 0;
3915 var integer first_fn, last_fn;
3916 var float test_duration := 5.0;
3917 timer T;
3918
3919 f_init_pcu_test();
3920 f_TC_pcu_act_req(0, 0, 7, true);
3921
3922 /* re-connect CTRL port from BTS to BSC */
3923 f_ipa_ctrl_stop();
3924 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3925
3926 /* Send that OML Alert */
3927 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3928
3929 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3930 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3931 setverdict(pass);
3932}
3933
Harald Welteeaa9a862019-05-26 23:01:08 +02003934template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3935 template (value) RoutingAreaIdentificationV rai,
3936 template (value) OCT1 cause) := {
3937 discriminator := '0000'B, /* overwritten */
3938 tiOrSkip := {
3939 skipIndicator := '0000'B
3940 },
3941 msgs := {
3942 rrm := {
3943 gPRS_suspensionRequest := {
3944 messageType := '00110100'B,
3945 tLLI := tlli,
3946 routingAreaIdentification := rai,
3947 suspensionCause := cause,
3948 service_Support := omit
3949 }
3950 }
3951 }
3952}
3953
3954/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3955private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3956 var PCUIF_Message first_info;
3957 var integer pcu_conn_id := -1;
3958 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3959 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3960 var OCT4 tlli := '01020304'O;
3961 var OCT1 cause := '23'O;
3962 timer T := 5.0;
3963
3964 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3965
3966 f_l1_tune(L1CTL);
3967 RSL.clear;
3968
3969 f_est_dchan();
3970 L1CTL.clear;
3971
3972 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3973
3974 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3975 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3976 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3977
3978 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3979 T.start;
3980 alt {
3981 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3982 setverdict(pass);
3983 }
3984 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3985 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3986 }
3987 [] PCU.receive {
3988 repeat;
3989 }
3990 [] T.timeout {
3991 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3992 }
3993 }
3994}
3995testcase TC_pcu_rr_suspend() runs on test_CT {
3996 var ConnHdlrPars pars;
3997 var ConnHdlr vc_conn;
3998
3999 f_init();
4000
4001 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4002 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4003 vc_conn.done;
4004}
Harald Welte07bd2d22019-05-25 11:03:30 +02004005
Harald Weltea2e0e942019-05-27 18:12:53 +02004006/* Ensure that PCUIF socket can accept only a single connection */
4007testcase TC_pcu_socket_connect_multi() runs on test_CT {
4008 timer T := 5.0;
4009
4010 /* this (among other things) establishes the first connection to the PCUIF socket */
4011 f_init();
4012
4013 /* try to establish a second connection, expect it to fail */
4014 PCU.send(UD_connect:{mp_pcu_socket, -1});
4015 T.start;
4016 alt {
4017 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4018 setverdict(pass);
4019 }
4020 [] PCU.receive(UD_connect_result:?) {
4021 setverdict(fail, "Unexpected unix domain connect result");
4022 }
4023 [] T.timeout {
4024 setverdict(pass);
4025 }
4026 }
4027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4028}
4029
Harald Weltec8effb72019-05-27 18:23:04 +02004030/* Ensure that PCUIF socket can disconnect + reconnect */
4031testcase TC_pcu_socket_reconnect() runs on test_CT {
4032 /* this (among other things) establishes the first connection to the PCUIF socket */
4033 f_init();
4034
4035 f_sleep(1.0);
4036
4037 f_pcuif_close(PCU, g_pcu_conn_id);
4038 g_pcu_conn_id := -1;
4039
4040 f_sleep(1.0);
4041
4042 /* re-connect */
4043 PCU.clear;
4044 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4045 setverdict(pass);
4046
4047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4048}
4049
Harald Weltebe030482019-05-27 22:29:35 +02004050/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4051private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4052 var L1ctlDlMessage l1_dl;
4053 var SystemInformation si;
4054 timer T := 5.0;
4055 T.start;
4056 alt {
4057 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4058 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4059 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4060 log("Ignoring non-RR SI ", l1_dl);
4061 repeat;
4062 }
4063 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4064 if (not ischosen(si.payload.si3)) {
4065 repeat;
4066 }
4067 }
4068 [] pt.receive {
4069 repeat;
4070 }
4071 [] T.timeout {
4072 setverdict(fail, "Timeout waiting for SI3");
4073 }
4074 }
4075 return si.payload.si3;
4076}
4077
4078/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4079private function f_bitpos_is_inv(integer idx) return boolean {
4080 select (idx mod 8) {
4081 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4082 case else { return false; } /* 0-bits of 0x2B */
4083 }
4084}
4085/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4086private function f_bit_is_high(bitstring str, integer idx) return boolean {
4087 var boolean invert := f_bitpos_is_inv(idx);
4088 if (invert) {
4089 if (str[idx] == '1'B) {
4090 return false;
4091 } else {
4092 return true;
4093 }
4094 } else {
4095 if (str[idx] == '1'B) {
4096 return true;
4097 } else {
4098 return false;
4099 }
4100 }
4101}
4102/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4103 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4104 we can replace this piece of code soon ... */
4105private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4106 var bitstring bits := oct2bit(si3_restoctets);
4107 var integer idx := 0;
4108
4109 if (f_bit_is_high(bits, idx)) {
4110 /* skip Optional selection parameters */
4111 idx := idx + 16;
4112 } else {
4113 idx := idx + 1;
4114 }
4115
4116 if (f_bit_is_high(bits, idx)) {
4117 /* skip Optional power offset */
4118 idx := idx + 3;
4119 } else {
4120 idx := idx + 1;
4121 }
4122
4123 /* skip SI2ter Indicator */
4124 idx := idx + 1;
4125
4126 /* skip Early CM Sending Control */
4127 idx := idx + 1;
4128
4129 /* skip Scheduling if and where */
4130 if (f_bit_is_high(bits, idx)) {
4131 idx := idx + 4;
4132 } else {
4133 idx := idx + 1;
4134 }
4135
4136 return f_bit_is_high(bits, idx);
4137}
4138
4139testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4140 var SystemInformationType3 si3;
4141 timer T := 5.0;
4142
4143 /* don't call f_init() as this would connect PCU socket */
4144 f_init_rsl(testcasename());
4145 T.start;
4146 alt {
4147 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4148 [] T.timeout {
4149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4150 }
4151 }
4152 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4153
4154 f_init_l1ctl();
4155 f_l1_tune(L1CTL);
4156
4157 f_sleep(2.0);
4158 L1CTL.clear;
4159 si3 := f_get_si3(L1CTL);
4160 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4161 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4162 } else {
4163 setverdict(pass);
4164 }
4165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4166}
4167
4168/* Ensure that GPRS capability is advertised after PCU socket connect */
4169testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4170 var SystemInformationType3 si3;
4171
4172 /* this (among other things) establishes the first connection to the PCUIF socket */
4173 f_init();
4174 f_init_l1ctl();
4175 f_l1_tune(L1CTL);
4176
4177 f_sleep(2.0);
4178 L1CTL.clear;
4179 si3 := f_get_si3(L1CTL);
4180 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4181 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4182 } else {
4183 setverdict(pass);
4184 }
4185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4186}
4187
4188/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4189testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4190 var SystemInformationType3 si3;
4191
4192 /* this (among other things) establishes the first connection to the PCUIF socket */
4193 f_init();
4194 f_init_l1ctl();
4195 f_l1_tune(L1CTL);
4196
4197 f_pcuif_close(PCU, g_pcu_conn_id);
4198 g_pcu_conn_id := -1;
4199
4200 f_sleep(1.0);
4201
4202 /* re-connect */
4203 PCU.clear;
4204 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4205
4206 f_sleep(2.0);
4207 L1CTL.clear;
4208 si3 := f_get_si3(L1CTL);
4209 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4210 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4211 } else {
4212 setverdict(pass);
4213 }
4214
4215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4216}
4217
Harald Welted66c9b82019-05-25 09:03:15 +02004218
Harald Welte3d04ae62018-04-04 20:29:05 +02004219/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004220 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004221 ***********************************************************************/
4222
4223private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4224runs on ConnHdlr {
4225 var PCUIF_send_data sd;
4226 /* Expect BTS to immediately acknowledge activation as PDCH */
4227 PCU.clear;
4228 f_rsl_chan_act(g_pars.chan_mode);
4229 /* expect INFO_IND on PCU interface listing TS as PDCH */
4230 alt {
4231 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4232 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 +02004233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004234 }
4235 }
4236 [] PCU.receive { repeat; }
4237 }
4238 /* try to activate this PDCH from the PCU point of view */
4239 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4240 /* FIXME: is there a response? */
4241}
4242
4243private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4244runs on ConnHdlr {
4245 var PCUIF_send_data sd;
4246 /* Send RSL CHAN REL (deactivate) */
4247 PCU.clear;
4248 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4249 /* expect BTS to ask PCU to deactivate the channel */
4250 alt {
4251 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4252 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 +02004253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004254 }
4255 }
4256 [] PCU.receive { repeat; }
4257 }
4258 /* Emulate PCU asking BTS to deactivate PDCH */
4259 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4260 alt {
4261 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4262 setverdict(pass);
4263 }
4264 [] RSL.receive { repeat; }
4265 }
4266}
4267
4268/* Activate Osmocom-style dynamic PDCH from BSC side */
4269function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4270 var PCUIF_Message first_info;
4271 var integer ts_nr := g_chan_nr.tn;
4272 var integer trx_nr := 0;
4273 var integer bts_nr := 0;
4274 var integer pcu_conn_id := -1;
4275
4276 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4277
4278 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4279 f_sleep(3.0);
4280 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4281 setverdict(pass);
4282}
4283testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4284 var ConnHdlrPars pars;
4285 var ConnHdlr vc_conn;
4286 f_init(testcasename());
4287
4288 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4289 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4290 vc_conn.done;
4291}
4292
4293/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4294function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4295 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004296 var integer pcu_conn_id := -1;
4297
4298 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4299
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004300 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4301 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4302 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004303 setverdict(pass);
4304}
4305testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4306 var ConnHdlrPars pars;
4307 var ConnHdlr vc_conn;
4308 f_init(testcasename());
4309
4310 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4311 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4312 vc_conn.done;
4313}
4314
4315/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4316function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4317 var PCUIF_Message first_info;
4318 var integer ts_nr := g_chan_nr.tn;
4319 var integer trx_nr := 0;
4320 var integer bts_nr := 0;
4321 var integer pcu_conn_id := -1;
4322
4323 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4324
4325 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004326 /* Send a second Chan Activ and expect it to be NACKed */
4327 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4328 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004329 setverdict(pass);
4330}
4331testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4332 var ConnHdlrPars pars;
4333 var ConnHdlr vc_conn;
4334 f_init(testcasename());
4335
4336 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4337 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4338 vc_conn.done;
4339}
4340
4341/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4342function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4343 var PCUIF_Message first_info;
4344 var integer ts_nr := g_chan_nr.tn;
4345 var integer trx_nr := 0;
4346 var integer bts_nr := 0;
4347 var integer pcu_conn_id := -1;
4348 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4349
4350 /* register for the TCH/F channel number */
4351 f_rslem_register(0, chan_nr);
4352
4353 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4354
4355 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4356 "RSL CHAN ACT");
4357 setverdict(pass);
4358}
4359testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4360 var ConnHdlrPars pars;
4361 var ConnHdlr vc_conn;
4362 f_init(testcasename());
4363
4364 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4365 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4366 vc_conn.done;
4367}
4368
4369/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4370function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4371 var PCUIF_Message first_info;
4372 var integer ts_nr := g_chan_nr.tn;
4373 var integer trx_nr := 0;
4374 var integer bts_nr := 0;
4375 var integer pcu_conn_id := -1;
4376 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4377 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4378
4379 /* register for the TCH/H channel numbers */
4380 f_rslem_register(0, chan_nr[0]);
4381 f_rslem_register(0, chan_nr[1]);
4382
4383 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4384
4385 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4386 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4387 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4388 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4389 setverdict(pass);
4390}
4391testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4392 var ConnHdlrPars pars;
4393 var ConnHdlr vc_conn;
4394 f_init(testcasename());
4395
4396 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4397 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4398 vc_conn.done;
4399}
4400
Harald Welte9bbbfb52018-04-05 09:33:19 +02004401/***********************************************************************
4402 * IPA Style Dynamic Timeslot Support
4403 ***********************************************************************/
4404
4405private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4406runs on ConnHdlr {
4407 var PCUIF_send_data sd;
4408 /* Expect BTS to immediately acknowledge activation as PDCH */
4409 PCU.clear;
4410 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4411 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004412 timer T_wait := 2.0;
4413 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004414 alt {
4415 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4416 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 +01004417 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4418 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4419 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004420 }
4421 }
4422 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004423 [] T_wait.timeout {
4424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4425 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4426 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004427 }
4428 /* try to activate this PDCH from the PCU point of view */
4429 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4430 /* FIXME: is there a response? */
4431
4432 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4433}
4434
4435private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4436runs on ConnHdlr {
4437 var PCUIF_send_data sd;
4438 /* Send RSL CHAN REL (deactivate) */
4439 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4440 PCU.clear;
4441 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004442 timer T_wait := 2.0;
4443 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004444 alt {
4445 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4446 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 +01004447 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4448 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4449 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004450 }
4451 }
4452 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004453 [] T_wait.timeout {
4454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4455 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4456 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004457 }
4458 /* Emulate PCU asking BTS to deactivate PDCH */
4459 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4460 alt {
4461 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4462 setverdict(pass);
4463 }
4464 [] RSL.receive { repeat; }
4465 }
4466}
4467
4468/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4469function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4470 var PCUIF_Message first_info;
4471 var integer ts_nr := g_chan_nr.tn;
4472 var integer trx_nr := 0;
4473 var integer bts_nr := 0;
4474 var integer pcu_conn_id := -1;
4475
4476 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4477
4478 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4479 f_sleep(3.0);
4480 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4481
4482 setverdict(pass);
4483
4484}
4485testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4486 var ConnHdlrPars pars;
4487 var ConnHdlr vc_conn;
4488 f_init();
4489
4490 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4491 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4492 vc_conn.done;
4493}
4494
4495/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4496function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4497 var PCUIF_Message first_info;
4498 var integer ts_nr := g_chan_nr.tn;
4499 var integer trx_nr := 0;
4500 var integer bts_nr := 0;
4501 var integer pcu_conn_id := -1;
4502
4503 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4504
4505 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4506 "RSL CHAN ACT");
4507 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4508 "RF CHAN REL", true);
4509 setverdict(pass);
4510}
4511testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4512 var ConnHdlrPars pars;
4513 var ConnHdlr vc_conn;
4514 f_init(testcasename());
4515
4516 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4517 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4518 vc_conn.done;
4519}
4520
4521/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4522function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4523 var PCUIF_Message first_info;
4524 var integer ts_nr := g_chan_nr.tn;
4525 var integer trx_nr := 0;
4526 var integer bts_nr := 0;
4527 var integer pcu_conn_id := -1;
4528
4529 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4530
4531 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4532 "RSL CHAN ACT");
4533
4534 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4535 alt {
4536 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4537 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004539 }
4540 [] RSL.receive { repeat; }
4541 }
4542
4543 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4544 "RF CHAN REL", true);
4545 setverdict(pass);
4546}
4547testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4548 var ConnHdlrPars pars;
4549 var ConnHdlr vc_conn;
4550 f_init(testcasename());
4551
4552 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4553 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4554 vc_conn.done;
4555}
4556
4557/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4558function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4559 var PCUIF_Message first_info;
4560 var integer ts_nr := g_chan_nr.tn;
4561 var integer trx_nr := 0;
4562 var integer bts_nr := 0;
4563 var integer pcu_conn_id := -1;
4564
4565 /* register for the TCH/F channel number */
4566 f_rslem_register(0, g_chan_nr);
4567
4568 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4569
4570 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4571
4572 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4573 "RSL CHAN ACT");
4574
4575 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4576
4577 setverdict(pass);
4578}
4579testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4580 var ConnHdlrPars pars;
4581 var ConnHdlr vc_conn;
4582 f_init(testcasename());
4583
4584 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4585 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4586 vc_conn.done;
4587}
4588
4589
Harald Welte0472ab42018-03-12 15:02:26 +01004590/***********************************************************************
4591 * LAPDm / RLL related
4592 ***********************************************************************/
4593
4594private function f_tx_lapdm(template (value) LapdmFrame l,
4595 template (value) RslLinkId link_id) runs on ConnHdlr {
4596 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004597 var template (value) SacchL1Header l1h;
4598
4599 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01004600 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004601 /* Compose dummy L1 header */
4602 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
4603 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 +02004604 } else {
4605 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004606 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 +01004607 }
Harald Welte0472ab42018-03-12 15:02:26 +01004608}
4609
4610type record RllTestCase {
4611 uint3_t sapi,
4612 RslLinkId link_id,
4613 octetstring l3,
4614 boolean exp
4615}
4616type record of RllTestCase RllTestCases;
4617template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4618 sapi := sapi,
4619 link_id := id,
4620 l3 := l3,
4621 exp := exp
4622}
4623
4624/* execute the same callback function with a set of different parameters (tcs) on a
4625 * variety of logical channels */
4626private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4627 var ConnHdlrPars pars;
4628 var ConnHdlr vc_conn;
4629 f_init(testcasename());
4630
4631 /* test on each of the channels we have */
4632 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4633 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4634
4635 /* test each of the test cases on the current channel */
4636 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4637 pars.spec.rll := tcs[j];
4638 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4639 vc_conn := f_start_handler(fn, pars);
4640 vc_conn.done;
4641 }
4642 }
4643
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004645}
4646
4647/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4648private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4649 var RllTestCase tc := g_pars.spec.rll;
4650 timer T := 3.0;
4651
4652 f_l1_tune(L1CTL);
4653 RSL.clear;
4654
4655 /* activate the logical channel */
4656 f_est_dchan();
4657 L1CTL.clear;
4658
4659 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4660 T.start;
4661 alt {
4662 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4663 if (tc.exp) {
4664 setverdict(pass);
4665 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004667 }
4668 }
4669 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4670 if (tc.exp) {
4671 setverdict(pass);
4672 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004674 }
4675 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004676 /* We also expect to receive the measurements */
4677 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004678 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004680 }
4681 [not tc.exp] T.timeout {
4682 setverdict(pass);
4683 }
4684 }
4685
4686 f_rsl_chan_deact();
4687 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4688 f_rslem_unregister(0, g_chan_nr);
4689}
4690testcase TC_rll_est_ind() runs on test_CT {
4691 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004692 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004693 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004694 /* normal SAPI0 establishment */
4695 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004696 /* SAPI 3 doesn't support contention resolution */
4697 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4698 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4699 /* normal SAPI3 establishment on main DCCH */
4700 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4701 /* normal SAPI3 establishment on SACCH */
4702 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4703 };
4704 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4705}
4706
4707/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4708private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4709 var RllTestCase tc := g_pars.spec.rll;
4710 var L1ctlDlMessage dl;
4711 timer T := 3.0;
4712
4713 f_l1_tune(L1CTL);
4714 RSL.clear;
4715
4716 /* activate the logical channel */
4717 f_est_dchan();
4718 L1CTL.clear;
4719
4720 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4721 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4722 T.start;
4723 alt {
4724 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4725 var LapdmFrame lapdm;
4726 var octetstring l2 := dl.payload.data_ind.payload;
4727 if (dl.dl_info.link_id.c == SACCH) {
4728 /* remove L1 header */
4729 l2 := substr(l2, 2, lengthof(l2)-2);
4730 }
4731 lapdm.ab := dec_LapdmFrameAB(l2);
4732 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4733 setverdict(pass);
4734 } else {
4735 repeat;
4736 }
4737 }
4738 [] L1CTL.receive { repeat; }
4739 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004741 }
4742 }
4743
4744 f_rsl_chan_deact();
4745 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4746 f_rslem_unregister(0, g_chan_nr);
4747}
4748testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4749 var RllTestCases tcs := {
4750 /* normal SAPI3 establishment on main DCCH */
4751 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4752 };
4753 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4754}
4755testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4756 var RllTestCases tcs := {
4757 /* normal SAPI3 establishment on SACCH */
4758 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4759 }
4760 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4761}
4762
4763/* altstep to receive a LAPDm frame matching the given template */
4764private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4765 var L1ctlDlMessage dl;
4766 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4767 var LapdmFrame lapdm;
4768 var octetstring l2 := dl.payload.data_ind.payload;
4769 if (dl.dl_info.link_id.c == SACCH) {
4770 /* remove L1 header */
4771 l2 := substr(l2, 2, lengthof(l2)-2);
4772 }
4773 if (ischosen(exp.ab)) {
4774 lapdm.ab := dec_LapdmFrameAB(l2);
4775 } else if (ischosen(exp.b4)) {
4776 lapdm.b4 := dec_LapdmFrameB4(l2);
4777 } else if (ischosen(exp.bbis)) {
4778 lapdm.bbis := dec_LapdmFrameBbis(l2);
4779 }
4780 log("Rx LAPDm ", lapdm);
4781 if (match(lapdm, exp)) {
4782 setverdict(pass);
4783 } else {
4784 repeat;
4785 }
4786 }
4787 [] L1CTL.receive { repeat; }
4788}
4789private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4790 timer T := t;
4791 T.start;
4792 alt {
4793 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004795 }
4796 [] as_l1_exp_lapdm(exp);
4797 }
4798}
4799
4800/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4801private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4802 /* send SABM from MS -> BTS */
4803 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4804 /* expect RLL EST IND on Abis */
4805 alt {
4806 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4807 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4808 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004810 }
4811 [] RSL.receive { repeat; }
4812 }
4813 /* expect UA from BTS -> MS */
4814 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4815}
4816
4817/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4818private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4819 var RllTestCase tc := g_pars.spec.rll;
4820
4821 f_l1_tune(L1CTL);
4822 RSL.clear;
4823
4824 /* activate the logical channel */
4825 f_est_dchan();
4826 L1CTL.clear;
4827
4828 /* first establish the link-layer */
4829 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4830
4831 /* then send the DISC */
4832 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4833 /* ... and expect the REL IND on the RSL side */
4834 alt {
4835 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4836 setverdict(pass);
4837 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004838 /* We also expect to receive the measurements */
4839 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004840 }
4841
4842 /* release the channel */
4843 f_rsl_chan_deact();
4844 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4845 f_rslem_unregister(0, g_chan_nr);
4846}
4847testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4848 var RllTestCases tcs := {
4849 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4850 };
4851 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4852}
4853
4854testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4855 var RllTestCases tcs := {
4856 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4857 };
4858 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4859}
4860testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4861 var RllTestCases tcs := {
4862 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4863 };
4864 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4865}
4866testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4867 var RllTestCases tcs := {
4868 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4869 };
4870 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4871}
4872
4873/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4874private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4875 var RllTestCase tc := g_pars.spec.rll;
4876 f_l1_tune(L1CTL);
4877 RSL.clear;
4878
4879 /* activate the logical channel */
4880 f_est_dchan();
4881 L1CTL.clear;
4882
4883 /* first establish the link-layer */
4884 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4885
4886 /* then send the REL REQ via RSL */
4887 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4888 /* ... and expect the DISC on the Um side */
4889 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004890 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004891 /* FIXME: send a UA in resposne to the DISC */
4892 }
4893 }
4894
4895 /* release the channel */
4896 f_rsl_chan_deact();
4897 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4898 f_rslem_unregister(0, g_chan_nr);
4899}
4900testcase TC_rll_rel_req() runs on test_CT {
4901 var RllTestCases tcs := {
4902 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4903 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4904 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4905 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4906 };
4907 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4908}
4909
4910/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4911testcase TC_rll_data_req() runs on test_CT {
4912}
4913
4914/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4915testcase TC_rll_data_ind() runs on test_CT {
4916}
4917
4918/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4919private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4920 var RllTestCase tc := g_pars.spec.rll;
4921
4922 f_l1_tune(L1CTL);
4923 RSL.clear;
4924
4925 f_est_dchan();
4926 L1CTL.clear;
4927
4928 /* Send UNITDATA REQ on RSL side */
4929 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4930 /* Expect it to arrive on the other side */
4931 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004932 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004933 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004934 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004935 }
4936
4937 /* release the channel */
4938 f_rsl_chan_deact();
4939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4940 f_rslem_unregister(0, g_chan_nr);
4941}
4942testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4943 var octetstring l3 := f_rnd_octstring(15);
4944 var RllTestCases tcs := {
4945 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4946 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4947 };
4948 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4949}
4950testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4951 var octetstring l3 := f_rnd_octstring(19);
4952 var RllTestCases tcs := {
4953 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4954 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4955 };
4956 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4957}
4958
4959/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4960private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4961 var RllTestCase tc := g_pars.spec.rll;
4962
4963 f_l1_tune(L1CTL);
4964 RSL.clear;
4965
4966 f_est_dchan();
4967 L1CTL.clear;
4968
4969 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004970 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004971 /* Expdct RLL UNITDATA IND on RSL side */
4972 alt {
4973 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4974 setverdict(pass);
4975 }
4976 [] RSL.receive { repeat; }
4977 }
4978
4979 /* release the channel */
4980 f_rsl_chan_deact();
4981 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4982 f_rslem_unregister(0, g_chan_nr);
4983}
4984testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004985 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004986 var RllTestCases tcs := {
4987 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4988 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4989 };
4990 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4991}
4992testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4993 var octetstring l3 := f_rnd_octstring(18);
4994 var RllTestCases tcs := {
4995 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4996 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4997 };
4998 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4999}
5000
Harald Weltee613f962018-04-18 22:38:16 +02005001/***********************************************************************
5002 * Encryption Related
5003 ***********************************************************************/
5004
5005/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5006function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5007 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5008 if (link_id.c == SACCH) {
5009 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5010 } else {
5011 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5012 }
5013}
5014
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005015/* Expect (or not expect) other kinds of messages */
5016private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5017 [exp_any] RSL.receive { repeat; }
5018 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005020 }
5021}
5022
Harald Weltee613f962018-04-18 22:38:16 +02005023/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005024private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005025 RslLinkId link_id,
5026 octetstring l3,
5027 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005028 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005029) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005030 timer T := 3.0;
5031 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5032 T.start;
5033 /* Expect RLL UNITDATA IND on RSL side */
5034 alt {
5035 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5036 setverdict(pass);
5037 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005038 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005039 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005040 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005042 }
Harald Weltee613f962018-04-18 22:38:16 +02005043 }
5044}
5045
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005046/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5047private function f_data_mo(
5048 RslLinkId link_id,
5049 boolean p, uint3_t nr, uint3_t ns,
5050 octetstring l3,
5051 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005052 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005053) runs on ConnHdlr {
5054 timer T := 3.0;
5055 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5056 T.start;
5057 /* Expect RLL DATA IND on RSL side */
5058 alt {
5059 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5060 setverdict(pass);
5061 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005062 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005063 [] as_rsl_any_ind(exp_any);
5064 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005066 }
5067 }
5068}
5069
Harald Weltee613f962018-04-18 22:38:16 +02005070/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5071function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5072 f_l1_tune(L1CTL);
5073 f_est_dchan(true);
5074
5075 /* now we actually need to transmit some data both ways to check if the encryption works */
5076 var L1ctlDlMessage dl;
5077
Stefan Sperling603d98e2018-07-25 16:47:28 +02005078 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005079 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5080
5081 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5082 f_unitdata_mt(link_id, l3);
5083
5084 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5085 f_unitdata_mo(link_id, l3);
5086
5087 /* release the channel */
5088 f_rsl_chan_deact();
5089 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5090 f_rslem_unregister(0, g_chan_nr);
5091}
5092testcase TC_chan_act_a51() runs on test_CT {
5093 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5094 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5095 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5096}
5097testcase TC_chan_act_a52() runs on test_CT {
5098 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5099 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5100 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5101}
5102testcase TC_chan_act_a53() runs on test_CT {
5103 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5104 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5105 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5106}
5107
Eric Wildf1827a72019-05-28 17:37:35 +02005108/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5109 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5110function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5111 f_l1_tune(L1CTL);
5112 f_est_dchan(true);
5113
5114 /* now we actually need to transmit some data both ways to check if the encryption works */
5115 var L1ctlDlMessage dl;
5116
5117 var octetstring l3 := f_rnd_octstring(20);
5118 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5119
5120 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5121 f_unitdata_mt(link_id, l3);
5122
5123 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5124 f_unitdata_mo(link_id, l3);
5125
5126 var RSL_Message rsl;
5127 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5128
5129 /* modify key to break proper encryption */
5130 g_pars.encr.key := f_rnd_octstring(8);
5131 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5132 rsl.ies := rsl.ies & { ei };
5133 RSL.send(rsl);
5134
5135 timer T0 := 1.0;
5136 T0.start;
5137 /* Expect RSL MODIFY ACK */
5138 alt {
5139 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5140 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5142 }
5143 [] T0.timeout {
5144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5145 }
5146 }
5147
5148 var octetstring l3msg := f_rnd_octstring(15);
5149 timer T1 := 3.0;
5150 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5151 due to broken encryption */
5152 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5153 T1.start;
5154 alt {
5155 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5157 }
5158 [] T1.timeout {
5159 setverdict(pass);
5160 }
5161 }
5162
5163 /* release the channel */
5164 f_rsl_chan_deact();
5165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5166 f_rslem_unregister(0, g_chan_nr);
5167}
5168testcase TC_rsl_modify_encr() runs on test_CT {
5169 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5170 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5171 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5172}
Harald Weltee613f962018-04-18 22:38:16 +02005173
5174/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5175function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5176 /* L3 payload doesn't matter, as it is passed transparently */
5177 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5178 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5179 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5180
5181 f_l1_tune(L1CTL);
5182
5183 /* first establish a dedicated channel in the clear */
5184 f_est_dchan(false);
5185
5186 /* Establish ABM */
5187 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5188
5189 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5190 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5191 /* expect the L3 to arrive still unencrypted on the MS side */
5192 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5193
5194 /* configure L1 to apply ciphering */
5195 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5196 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5197
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005198 /* send first ciphered I-frame in response and expect it on RSL */
5199 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005200
5201 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5202 * and hence enable encryption also on the downlink */
5203
5204 /* expect bi-directional communication work in encrypted mode */
5205 f_unitdata_mo(link_id, f_rnd_octstring(15));
5206 f_unitdata_mt(link_id, f_rnd_octstring(15));
5207
5208 /* release the channel */
5209 f_rsl_chan_deact();
5210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5211 f_rslem_unregister(0, g_chan_nr);
5212}
5213testcase TC_encr_cmd_a51() runs on test_CT {
5214 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5215 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5216 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5217}
5218testcase TC_encr_cmd_a52() runs on test_CT {
5219 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5220 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5221 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5222}
5223testcase TC_encr_cmd_a53() runs on test_CT {
5224 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5225 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5226 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5227}
5228
5229private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5230 var LapdmFrame lf;
5231 var octetstring reenc;
5232
5233 /* decode the LAPDm frame */
5234 if (ischosen(exp_match.ab)) {
5235 lf.ab := dec_LapdmFrameAB(enc);
5236 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005238 }
5239
5240 /* check if decoder result matches expectation */
5241 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005243 } else {
5244 log(name, ": matched");
5245 setverdict(pass);
5246 }
5247
5248 /* test if re-encoded frame equals original input */
5249 reenc := enc_LapdmFrame(lf);
5250 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005252 } else {
5253 setverdict(pass);
5254 }
5255}
5256
5257testcase TC_lapdm_selftest() runs on test_CT {
5258 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5259 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5260 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5261 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5262 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5263 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5264 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5265}
5266
Stefan Sperling4880be42018-08-07 18:12:59 +02005267/***********************************************************************
5268 * DTX Related (see GSM 05.08, section 8.3)
5269 ***********************************************************************/
5270
5271/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5272function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5273 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5274 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5275 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5276 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5277}
5278function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5279 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5280 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5281}
5282function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5283 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5284 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5285 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5286 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5287}
5288function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5289 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5290 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5291 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5292 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5293 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5294 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5295 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5296 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5297}
5298
5299function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5300 var L1ctlDlMessage dl;
5301 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5302 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5303 var GsmFrameNumber first_fn;
5304 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005305 var integer nfill_frames_sacch := 0;
5306 var integer nfill_frames_nonsacch := 0;
5307 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005308 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5309 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005310 const integer frame_dtx_tchf_mod := 104;
5311 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5312 * which operates in terms of blocks rather than frames. */
5313 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5314 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005315 timer T := 5.0;
5316
5317 f_l1_tune(L1CTL);
5318 RSL.clear;
5319 L1CTL.clear;
5320
5321 /* activate TCHF signalling channel */
5322 f_est_dchan(false);
5323
5324 T.start;
5325 alt {
5326 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5327 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5328 var octetstring l2 := dl.payload.data_ind.payload;
5329
5330 if (is_first_frame) {
5331 is_first_frame := false;
5332 first_fn := dl.dl_info.frame_nr;
5333 }
5334
5335 if (dl.dl_info.link_id.c == SACCH) {
5336 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5337 if (not match(l2_fill_frame_sacch, l2)) {
5338 repeat;
5339 }
5340 } else if (not match(l2_fill_frame, l2)) {
5341 repeat;
5342 }
5343
5344 if (dtxd) {
5345 if (not f_g_chan_is_tchf()) {
5346 T.stop;
5347 f_rsl_chan_deact();
5348 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005349 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 +02005350 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005351 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005352 T.stop;
5353 f_rsl_chan_deact();
5354 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005355
5356 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5357 * 2 SACCH, 1 TCH/F */
5358 expected_fill_frames := 3;
5359
5360 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5361 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5362 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005364 } else {
5365 setverdict(pass);
5366 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005367 } else {
5368 if (dl.dl_info.link_id.c == SACCH) {
5369 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005370 repeat;
5371 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005372 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5373 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5374 * we should only see the subset of frames numbers which correspond to a block boundary.
5375 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5376 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5377 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5378 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5379 repeat;
5380 }
5381 }
5382 log("Received DTX TCH fill frame with bad frame number: ", fn,
5383 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5384 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5385 f_rsl_chan_deact();
5386 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005388 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005389 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005390 if (dl.dl_info.link_id.c == SACCH) {
5391 nfill_frames_sacch := nfill_frames_sacch + 1;
5392 } else {
5393 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5394 }
5395 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005396 T.stop;
5397 if (f_g_chan_is_tchf()) {
5398 /* Without DTX we can expect 25 fill frames for every 104 frames.
5399 * (24 FACCH + 1 SACCH filling) */
5400 expected_fill_frames := 25;
5401 } else if (f_g_chan_is_tchh()) {
5402 /* We can expect 2 fill frames for every 104 frames. */
5403 expected_fill_frames := 2;
5404 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5405 /* We can expect 5 fill frames for every 104 frames. */
5406 expected_fill_frames := 5;
5407 } else {
5408 f_rsl_chan_deact();
5409 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005411 }
5412
5413 f_rsl_chan_deact();
5414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005415
5416 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005417 setverdict(pass);
5418 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005419 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5420 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005422 }
5423 } else {
5424 repeat;
5425 }
5426 }
5427 }
5428 [] L1CTL.receive { repeat; }
5429 [] T.timeout {
5430 f_rsl_chan_deact();
5431 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005433 }
5434 }
5435}
5436
5437function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5438 f_test_l2_fill_frames(false);
5439}
5440
5441function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5442 f_test_l2_fill_frames(true);
5443}
5444
5445function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5446 var ConnHdlr vc_conn;
5447 var ConnHdlrPars pars;
5448 pars.t_guard := 60.0;
5449 f_init(testcasename());
5450 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5451 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5452 if (dtxd) {
5453 if (i >= 4) { /* DTX is only allowed on TCH/F */
5454 break;
5455 }
5456 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5457 } else {
5458 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5459 }
5460 vc_conn.done;
5461 }
5462}
5463
5464/* Verify that L2 fill frames are sent on TCH in signaling mode if
5465 * there is nothing to transmit while DTX is disabled on downlink. */
5466testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5467 f_tch_sign_l2_fill_frame(false);
5468}
5469
5470/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5471 * there is nothing to transmit while DTX is enabled on downlink. */
5472testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5473 f_tch_sign_l2_fill_frame(true);
5474}
Harald Welte0472ab42018-03-12 15:02:26 +01005475
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005476testcase TC_chopped_ipa_ping() runs on test_CT {
5477 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5478}
5479
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005480testcase TC_chopped_ipa_payload() runs on test_CT {
5481 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5482}
5483
Harald Welte0472ab42018-03-12 15:02:26 +01005484/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5485/* protocol error as per 44.006 */
5486/* link layer failure (repetition of I-frame N200 times without ACK */
5487/* repetition of SABM or DISC N200 times without ACK */
5488/* receptiom of SABM in multi-frame established state */
5489
5490
Harald Welte68e495b2018-02-25 00:05:57 +01005491/* TODO Areas:
5492
5493* channel activation
5494** with BS_Power / MS_Power, bypassing power control loop
5495** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005496** with timing advance from initial activation on
5497* mode modify
5498** encryption
5499** multirate
5500* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005501** unsupported algorithm
5502* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005503* BS Power Control
5504* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005505* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005506* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005507** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005508* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005509** DATA_IND from BTS->PCU
5510** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005511
5512*/
Harald Welte70767382018-02-21 12:16:40 +01005513
5514control {
5515 execute( TC_chan_act_stress() );
5516 execute( TC_chan_act_react() );
5517 execute( TC_chan_deact_not_active() );
5518 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005519 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005520 execute( TC_sacch_filling() );
5521 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005522 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005523 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005524 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005525 execute( TC_sacch_chan_act_ho_async() );
5526 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005527 execute( TC_rach_content() );
5528 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005529 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07005530 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02005531 execute( TC_rach_load_idle_thresh0() );
5532 execute( TC_rach_load_idle_below_thresh() );
5533 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005534 execute( TC_meas_res_sign_tchf() );
5535 execute( TC_meas_res_sign_tchh() );
5536 execute( TC_meas_res_sign_sdcch4() );
5537 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005538 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005539 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005540 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005541 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005542 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005543 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005544 execute( TC_paging_imsi_80percent() );
5545 execute( TC_paging_tmsi_80percent() );
5546 execute( TC_paging_imsi_200percent() );
5547 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005548 execute( TC_rsl_protocol_error() );
5549 execute( TC_rsl_mand_ie_error() );
5550 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005551 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005552 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005553 execute( TC_si_sched_2bis() );
5554 execute( TC_si_sched_2ter() );
5555 execute( TC_si_sched_2ter_2bis() );
5556 execute( TC_si_sched_2quater() );
5557 execute( TC_si_sched_13() );
5558 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005559 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005560 execute( TC_ipa_crcx_twice_not_active() );
5561 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005562 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005563 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005564
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005565 if (mp_pcu_socket != "") {
5566 execute( TC_pcu_act_req() );
5567 execute( TC_pcu_act_req_wrong_ts() );
5568 execute( TC_pcu_act_req_wrong_bts() );
5569 execute( TC_pcu_act_req_wrong_trx() );
5570 execute( TC_pcu_deact_req() );
5571 execute( TC_pcu_deact_req_wrong_ts() );
5572 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005573 if (mp_l1_supports_gprs) {
5574 execute( TC_pcu_data_req_pdtch() );
5575 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005576 execute( TC_pcu_data_req_wrong_bts() );
5577 execute( TC_pcu_data_req_wrong_trx() );
5578 execute( TC_pcu_data_req_wrong_ts() );
5579 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005580 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005581 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005582 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005583 execute( TC_pcu_data_req_imm_ass_pch() );
5584 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005585 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005586 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005587 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005588 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005589 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005590 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005591 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005592 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02005593 execute( TC_pcu_socket_noconnect_nosi3gprs() );
5594 execute( TC_pcu_socket_connect_si3gprs() );
5595 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005596 } else {
5597 log("PCU socket path not available, skipping PCU tests");
5598 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005599
5600 execute( TC_dyn_osmo_pdch_act_deact() );
5601 execute( TC_dyn_osmo_pdch_unsol_deact() );
5602 execute( TC_dyn_osmo_pdch_double_act() );
5603 execute( TC_dyn_osmo_pdch_tchf_act() );
5604 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005605 execute( TC_dyn_ipa_pdch_act_deact() );
5606 execute( TC_dyn_ipa_pdch_tchf_act() );
5607 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5608 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005609
5610 execute( TC_rll_est_ind() );
5611 execute( TC_rll_est_req_DCCH_3() );
5612 execute( TC_rll_est_req_ACCH_3() );
5613 execute( TC_rll_rel_ind_DCCH_0() );
5614 execute( TC_rll_rel_ind_DCCH_3() );
5615 execute( TC_rll_rel_ind_ACCH_0() );
5616 execute( TC_rll_rel_ind_ACCH_3() );
5617 execute( TC_rll_rel_req() );
5618 execute( TC_rll_unit_data_req_DCCH() );
5619 execute( TC_rll_unit_data_req_ACCH() );
5620 execute( TC_rll_unit_data_ind_DCCH() );
5621 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005622
5623 execute( TC_chan_act_a51() );
5624 execute( TC_chan_act_a52() );
5625 execute( TC_chan_act_a53() );
5626 execute( TC_encr_cmd_a51() );
5627 execute( TC_encr_cmd_a52() );
5628 execute( TC_encr_cmd_a53() );
5629
Harald Welteee25aae2019-05-19 14:32:37 +02005630 execute( TC_err_rep_wrong_mdisc() );
5631 execute( TC_err_rep_wrong_msg_type() );
5632 execute( TC_err_rep_wrong_sequence() );
5633
Harald Weltee613f962018-04-18 22:38:16 +02005634 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005635
5636 execute( TC_tch_sign_l2_fill_frame() );
5637 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005638
5639 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005640 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005641}
5642
5643
5644}