blob: 9184f6adb399d86aa59bba5e3e34ede19e6494a5 [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;
Harald Welte2f2b2b72019-05-31 22:24:57 +020064import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010065
Harald Welte505cf9b2018-09-15 17:47:23 +030066friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020067friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068friend module BTS_Tests_LAPDm;
Harald Welte505cf9b2018-09-15 17:47:23 +030069
Harald Welte70767382018-02-21 12:16:40 +010070/* The tests assume a BTS with the following timeslot configuration:
71 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020072 * TS1 : TCH/F
73 * TS2 : TCH/F
74 * TS3 : TCH/F_PDCH (IPA Style)
75 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010076 * TS5 : TCH/H
77 * TS6 : SDCCH/8
78 * TS7 : PDCH
79 */
80
81modulepar {
82 charstring mp_rsl_ip := "127.0.0.2";
83 integer mp_rsl_port := 3003;
84 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070085 charstring mp_bts_trxc_ip := "127.0.0.1";
86 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010087 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020088 charstring mp_ctrl_ip := "127.0.0.1";
89 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020090 charstring mp_bsc_ctrl_ip := "127.0.0.1";
91 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020092 integer mp_tolerance_rxqual := 1;
93 integer mp_tolerance_rxlev := 3;
94 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020095 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020096 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020097 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_ms_actual_ta_exp := 0;
99 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100100 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200101 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200102 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200103 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
104 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100105}
106
Harald Welte629cc6b2018-03-11 17:19:05 +0100107type record of RslChannelNr ChannelNrs;
108
Harald Welte70767382018-02-21 12:16:40 +0100109type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100110 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100111 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100113 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100114 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100115 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100116
117 /* L1CTL port (for classic tests) */
118 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100119
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700120 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700121 port TRXC_CODEC_PT BTS_TRXC;
122 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100123
Harald Weltef50e3ae2018-09-10 10:27:56 +0200124 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100125 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200126 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100127
Harald Welte883340c2018-02-28 18:59:29 +0100128 /* PCU Interface of BTS */
129 port PCUIF_CODEC_PT PCU;
130 var integer g_pcu_conn_id;
131 /* Last PCU INFO IND we received */
132 var PCUIF_Message g_pcu_last_info;
133
Harald Welte48494ca2018-02-25 16:59:50 +0100134 /* SI configuration */
135 var SystemInformationConfig si_cfg := {
136 bcch_extended := false,
137 si1_present := false,
138 si2bis_present := false,
139 si2ter_present := false,
140 si2quater_present := false,
141 si7_present := false,
142 si8_present := false,
143 si9_present := false,
144 si13_present := false,
145 si13alt_present := false,
146 si15_present := false,
147 si16_present := false,
148 si17_present := false,
149 si2n_present := false,
150 si21_present := false,
151 si22_present := false
152 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100153
154 /* all logical channels available on the BTS */
155 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100156 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100157}
158
159/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200160type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100161 port L1CTL_PT L1CTL;
162
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700163 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700164 port TRXC_CODEC_PT BTS_TRXC;
165 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100166
167 timer g_Tguard;
168 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
169
170 var ConnHdlrPars g_pars;
171 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100172 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200173
174 /* PCU Interface of BTS */
175 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100176}
177
178function f_init_rsl(charstring id) runs on test_CT {
179 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
180 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
181
182 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
183 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
184 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
185
186 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
187 vc_RSL.start(RSL_Emulation.main(false));
188}
189
190type record ConnHdlrPars {
191 RslChannelNr chan_nr,
192 RSL_IE_ChannelMode chan_mode,
193 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100194 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200195 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200196 RSL_IE_EncryptionInfo encr optional,
197 BtsBand bts0_band optional
Harald Welte0472ab42018-03-12 15:02:26 +0100198}
199
200/* Test-specific parameters */
201type union TestSpecUnion {
202 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100203}
204
Harald Welte82ccef72018-02-25 16:17:33 +0100205template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100206 max_retrans := RACH_MAX_RETRANS_7,
207 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100208 cell_barr_access := false,
209 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100210 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100211};
212
Harald Weltef10153f2018-02-25 16:34:05 +0100213template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100214 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200215 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100216 acs := '0'B,
217 neci := true,
218 rxlev_access_min := 0
219}
220
221template (value) LocationAreaIdentification ts_LAI_default := {
222 mcc_mnc := '262F42'H,
223 lac := 42
224}
225
Harald Welte7484fc42018-02-24 14:09:45 +0100226/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100227template (value) SystemInformation ts_SI3_default := {
228 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100229 payload := {
230 si3 := {
231 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100232 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100233 ctrl_chan_desc := {
234 msc_r99 := true,
235 att := true,
236 bs_ag_blks_res := 1,
237 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100238 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100239 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
240 spare := '00'B,
241 bs_pa_mfrms := 0, /* 2 multiframes */
242 t3212 := 1 /* 6 minutes */
243 },
Harald Welte82ccef72018-02-25 16:17:33 +0100244 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100245 dn_ind := false,
246 pwrc := false,
247 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100248 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100249 },
Harald Weltef10153f2018-02-25 16:34:05 +0100250 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100251 rach_control := ts_RachCtrl_default,
Harald Weltebe030482019-05-27 22:29:35 +0200252 rest_octets := '2C2B2B2B'O /* GPRS present */
Harald Welte7484fc42018-02-24 14:09:45 +0100253 }
254 }
255}
Harald Welte70767382018-02-21 12:16:40 +0100256
Harald Weltef8df4cb2018-03-10 15:15:08 +0100257template (value) SystemInformation ts_SI2_default := {
258 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100259 payload := {
260 si2 := {
261 bcch_freq_list := '00000000000000000000000000000000'O,
262 ncc_permitted := '11111111'B,
263 rach_control := ts_RachCtrl_default
264 }
265 }
266}
267
Harald Weltef8df4cb2018-03-10 15:15:08 +0100268template (value) SystemInformation ts_SI4_default := {
269 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100270 payload := {
271 si4 := {
272 lai := ts_LAI_default,
273 cell_sel_par := ts_CellSelPar_default,
274 rach_control := ts_RachCtrl_default,
275 cbch_chan_desc := omit,
276 cbch_mobile_alloc := omit,
277 rest_octets := ''O
278 }
279 }
280}
281
282function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
283runs on test_CT {
284 log("Setting ", rsl_si_type, ": ", si_enc);
285 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
286}
287
288function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
289runs on test_CT {
290 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
291 log("Setting ", rsl_si_type, ": ", si_dec);
292 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
293}
294
Harald Welte505cf9b2018-09-15 17:47:23 +0300295friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100296 map(self:BTSVTY, system:BTSVTY);
297 f_vty_set_prompts(BTSVTY);
298 f_vty_transceive(BTSVTY, "enable");
299}
300
Harald Welte505cf9b2018-09-15 17:47:23 +0300301friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200302 map(self:BSCVTY, system:BSCVTY);
303 f_vty_set_prompts(BSCVTY, "OsmoBSC");
304 f_vty_transceive(BSCVTY, "enable");
305}
306
Harald Welte883340c2018-02-28 18:59:29 +0100307/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200308private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
309 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100310 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200311 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
312 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100313 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200314 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200315 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100316 }
317}
318
Harald Weltef26de0b2018-04-04 20:28:05 +0200319private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
320 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100321 timer T := 2.0;
322 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100323 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200324 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100325 return;
326 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200327 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100328
329 T.start;
330 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200331 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100332 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100334 }
335 }
336}
337
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700338private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
339 out integer trxc_conn_id) {
340 var Result res;
341
342 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
343 "", -1, -1, { udp := {} }, {});
344 if (not ispresent(res.connId)) {
345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
346 "Could not connect to the control (TRXC) interface " &
347 "of FakeTRX, check your configuration");
348 }
349 trxc_conn_id := res.connId;
350}
351
Harald Welte70767382018-02-21 12:16:40 +0100352/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200353function f_init() runs on test_CT {
354 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100355 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100356 g_AllChannels := {
357 /* TS 1..4: TCH/F */
358 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
359 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
360 /* TS 5: TCH/H */
361 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
362 /* TS 0: SDCCH/4 */
363 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
364 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
365 /* TS 6: SDCCH/8 */
366 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
367 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
368 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
369 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
370 };
371
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200372 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700373 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200374 g_AllChanTypes := {
375 /* TS 1..4: TCH/F */
376 valueof(ts_RslChanNr_Bm(1)),
377 /* TS 5: TCH/H */
378 valueof(ts_RslChanNr_Lm(5,1)),
379 /* TS 0: SDCCH/4 */
380 valueof(ts_RslChanNr_SDCCH4(0,2)),
381 /* TS 6: SDCCH/8 */
382 valueof(ts_RslChanNr_SDCCH8(6,4))
383 };
384 } else {
385 g_AllChanTypes := {
386 /* TS 1..4: TCH/F */
387 valueof(ts_RslChanNr_Bm(1)),
388 /* TS 0: SDCCH/4 */
389 valueof(ts_RslChanNr_SDCCH4(0,2)),
390 /* TS 6: SDCCH/8 */
391 valueof(ts_RslChanNr_SDCCH8(6,4))
392 };
393 }
Harald Welte70767382018-02-21 12:16:40 +0100394 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200395 T.start;
396 alt {
397 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
398 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200400 }
401 }
Harald Welte2d142592018-02-25 13:19:44 +0100402 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100403 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200404 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100405
406 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100407 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
408 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
409 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
410 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100411
Harald Weltef26de0b2018-04-04 20:28:05 +0200412 map(self:PCU, system:PCU);
413 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100414
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700415 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100416 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700417
418 /* Init TRXC interface to FakeTRX */
419 map(self:BTS_TRXC, system:BTS_TRXC);
420 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
421
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700422 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700423 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700424 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Harald Welte84271622018-03-10 17:21:03 +0100425 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200426
427 /* Wait some extra time to make sure the BTS emits a stable carrier.
428 * (this is only relevant when running the tests with a physical BTS.) */
429 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100430}
431
Harald Welte68e495b2018-02-25 00:05:57 +0100432/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
433function f_init_l1ctl() runs on test_CT {
434 map(self:L1CTL, system:L1CTL);
435 f_connect_reset(L1CTL);
436}
437
Harald Welte70767382018-02-21 12:16:40 +0100438type function void_fn(charstring id) runs on ConnHdlr;
439
440/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700441function f_start_handler(void_fn fn, ConnHdlrPars pars,
442 boolean pcu_comp := false,
443 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100444runs on test_CT return ConnHdlr {
445 var charstring id := testcasename();
446 var ConnHdlr vc_conn;
447
448 vc_conn := ConnHdlr.create(id);
449 /* connect to RSL Emulation main component */
450 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
451 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700452
453 /* The ConnHdlr component may want to talk to some ports directly,
454 * so we disconnect it from the test_CT and connect it to the component.
455 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200456 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200457 unmap(self:PCU, system:PCU);
458 map(vc_conn:PCU, system:PCU);
459 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700460 if (trxc_comp) {
461 unmap(self:BTS_TRXC, system:BTS_TRXC);
462 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
463 }
Harald Welte70767382018-02-21 12:16:40 +0100464
465 vc_conn.start(f_handler_init(fn, id, pars));
466 return vc_conn;
467}
468
Harald Welte7484fc42018-02-24 14:09:45 +0100469template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
470 streamId := sid,
471 rsl := rsl
472}
473
474template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
475 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
476 streamId := sid,
477 rsl := rsl
478}
479
Harald Welte70767382018-02-21 12:16:40 +0100480private altstep as_Tguard() runs on ConnHdlr {
481 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100483 }
484}
485
Harald Welte990a3612019-05-27 14:02:13 +0200486friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
487 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100488}
489
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700490private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100491 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700492 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100493}
494
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700495private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100496 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700497 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100498}
499
500/* first function started in ConnHdlr component */
501private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
502runs on ConnHdlr {
503 g_pars := pars;
504 g_chan_nr := pars.chan_nr;
505
506 map(self:L1CTL, system:L1CTL);
507 f_connect_reset(L1CTL);
508
Harald Welted48c0c72019-06-05 10:01:15 +0200509 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700510 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100511 }
Harald Welte70767382018-02-21 12:16:40 +0100512
513 g_Tguard.start(pars.t_guard);
514 activate(as_Tguard());
515
516 f_rslem_register(0, pars.chan_nr);
517
518 /* call the user-supplied test case function */
519 fn.apply(id);
520}
521
Harald Welteb1726c92018-03-30 11:56:38 +0200522function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
523 boolean ignore_other := false)
524runs on ConnHdlr return RSL_Message {
525 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100526 timer T := 3.0;
527 RSL.send(tx);
528 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100529 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200530 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100531 T.stop;
532 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100533 }
Harald Welte1eba3742018-02-25 12:48:14 +0100534 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100536 }
Harald Welte21240e62018-03-11 21:43:35 +0100537 [not ignore_other] as_l1_sacch();
538 [not ignore_other] as_meas_res();
539 [not ignore_other] as_l1_dcch();
540 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100542 }
Harald Welte21240e62018-03-11 21:43:35 +0100543 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100544 }
Harald Welteb1726c92018-03-30 11:56:38 +0200545 return rx;
546}
547
548function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
549 boolean ignore_other := false)
550runs on ConnHdlr {
551 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100552}
553
Harald Welte8b01c792019-05-19 22:51:25 +0200554function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
555 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
556 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200557 if (encr_enable) {
558 /* append encryption related IEs, if requested */
559 var RSL_IE_EncryptionInfo encr_info;
560 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
561 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
562encr_info})) };
563 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200564 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200565 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100566}
567
Harald Welte70767382018-02-21 12:16:40 +0100568function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100569 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 +0100570 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100571}
572
Harald Welte2f2b2b72019-05-31 22:24:57 +0200573friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100574 template RSL_IE_ChannelMode chan_mode,
575 float t_guard := 20.0) := {
576 chan_nr := valueof(chan_nr),
577 chan_mode := valueof(chan_mode),
578 t_guard := t_guard,
579 l1_pars := {
580 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100581 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100582 meas_ul := {
583 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200584 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100585 rxqual := 0
586 },
587 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200588 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100589 rxqual := 0
590 }
591 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200592 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100593 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200594 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200595 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100596 },
Harald Weltee613f962018-04-18 22:38:16 +0200597 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200598 encr := omit,
599 bts0_band := omit
Harald Welte70767382018-02-21 12:16:40 +0100600}
601
Harald Welte93640c62018-02-25 16:59:33 +0100602/***********************************************************************
603 * Channel Activation / Deactivation
604 ***********************************************************************/
605
Harald Welte70767382018-02-21 12:16:40 +0100606/* Stress test: Do 500 channel activations/deactivations in rapid succession */
607function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
608 for (var integer i := 0; i < 500; i := i+1) {
609 f_rsl_chan_act(g_pars.chan_mode);
610 f_rsl_chan_deact();
611 }
612 setverdict(pass);
613}
614testcase TC_chan_act_stress() runs on test_CT {
615 var ConnHdlr vc_conn;
616 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200617 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100618 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
619 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100621}
622
623/* Test if re-activation of an already active channel fails as expected */
624function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
625 f_rsl_chan_act(g_pars.chan_mode);
626 /* attempt to activate the same lchan again -> expect reject */
627 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
628 alt {
629 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100631 }
632 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
633 setverdict(pass);
634 }
635 }
636 f_rsl_chan_deact();
637}
638testcase TC_chan_act_react() runs on test_CT {
639 var ConnHdlr vc_conn;
640 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100641 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100642 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
643 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100645}
646
647/* Attempt to de-activate a channel that's not active */
648function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
649 timer T := 3.0;
650 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
651 T.start;
652 alt {
653 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
654 setverdict(pass);
655 }
656 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100658 }
659 }
660}
661testcase TC_chan_deact_not_active() runs on test_CT {
662 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100663 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100664 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
665 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100667}
668
669/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
670function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
671 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
672 alt {
673 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100675 }
676 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
677 setverdict(pass);
678 }
679 }
680}
681private type record WrongChanNrCase {
682 RslChannelNr chan_nr,
683 charstring description
684}
685private type record of WrongChanNrCase WrongChanNrCases;
686private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
687 chan_nr := chan_nr,
688 description := desc
689}
690
691testcase TC_chan_act_wrong_nr() runs on test_CT {
692 var ConnHdlr vc_conn;
693 var ConnHdlrPars pars;
694
Harald Welte294b0a22018-03-10 23:26:48 +0100695 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100696
697 var WrongChanNrCases wrong := {
698 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
699 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
700 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
701 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
702 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
703 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
704 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
705 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
706 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
707 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
708 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
709 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
710 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
711 };
712
713 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
714 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
715 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
716 vc_conn.done;
717 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100719}
720
Harald Weltee613f962018-04-18 22:38:16 +0200721/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200722friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200723 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200724 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200725
726 /* test on each of the channels we have */
727 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
728 pars.chan_nr := valueof(g_AllChanTypes[i]);
729
730 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
731 vc_conn := f_start_handler(fn, pars);
732 vc_conn.done;
733 }
734
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200736}
737
Harald Welte93640c62018-02-25 16:59:33 +0100738/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100739 * SACCH handling
740 ***********************************************************************/
741
742private function f_exp_sacch(boolean exp) runs on ConnHdlr {
743 timer T_sacch := 3.0;
744 T_sacch.start;
745 alt {
746 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100748 }
749 [not exp] T_sacch.timeout {
750 setverdict(pass);
751 }
752 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
753 setverdict(pass);
754 }
755 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100757 }
758 [] L1CTL.receive { repeat; }
759 [] RSL.receive { repeat; }
760 }
761}
762
763/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
764private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
765 f_l1_tune(L1CTL);
766 RSL.clear;
767
768 /* activate the logical channel */
769 f_est_dchan();
770 L1CTL.clear;
771
772 /* check that SACCH actually are received as expected */
773 f_exp_sacch(true);
774
775 /* deactivate SACCH on the logical channel */
776 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
777 f_sleep(1.0);
778 L1CTL.clear;
779
780 /* check that no SACCH are received anymore */
781 f_exp_sacch(false);
782
783 /* release the channel */
784 f_rsl_chan_deact();
785 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
786}
787testcase TC_deact_sacch() runs on test_CT {
788 var ConnHdlr vc_conn;
789 var ConnHdlrPars pars;
790 f_init();
791 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
792 //for (var integer i := 0; i < 1; i := i+1) {
793 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
794 log(testcasename(), ": Starting for ", g_AllChannels[i]);
795 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
796 vc_conn.done;
797 }
798 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100800}
801
Harald Welte55700662018-03-12 13:15:43 +0100802/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100803private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
804 var L1ctlDlMessage dl;
805 /* check that the specified SI5 value is actually sent */
806 timer T_sacch := 3.0;
807 L1CTL.clear;
808 T_sacch.start;
809 alt {
810 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
811 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
812 if (match(l3, l3_exp)) {
813 setverdict(pass);
814 } else {
815 repeat;
816 }
817 }
818 [] L1CTL.receive { repeat; }
819 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100821 }
822 }
823}
824
Harald Welte55700662018-03-12 13:15:43 +0100825/* verify that given SACCH payload is not present */
826private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
827 var L1ctlDlMessage dl;
828 /* check that the specified SI5 value is actually sent */
829 timer T_sacch := 3.0;
830 L1CTL.clear;
831 T_sacch.start;
832 alt {
833 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
834 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
835 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100837 } else {
838 repeat;
839 }
840 }
841 [] L1CTL.receive { repeat; }
842 [] T_sacch.timeout {
843 setverdict(pass);
844 }
845 }
846}
847
Harald Welte629cc6b2018-03-11 17:19:05 +0100848/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100849private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
850 /* Set a known default SACCH filling for SI5 */
851 var octetstring si5 := f_rnd_octstring(19);
852 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
853
854 f_l1_tune(L1CTL);
855 RSL.clear;
856
857 /* activate the logical channel */
858 f_est_dchan();
859
860 /* check that the specified SI5 value is actually sent */
861 f_sacch_present(si5);
862
863 /* release the channel */
864 RSL.clear;
865 f_rsl_chan_deact();
866 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
867}
868testcase TC_sacch_filling() runs on test_CT {
869 var ConnHdlr vc_conn;
870 var ConnHdlrPars pars;
871 f_init();
872 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
873 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
874 log(testcasename(), ": Starting for ", g_AllChannels[i]);
875 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
876 vc_conn.done;
877 }
878 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100880}
881
Harald Welte629cc6b2018-03-11 17:19:05 +0100882/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100883private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
884 /* Set a known default SACCH filling for SI5 */
885 var octetstring si5 := f_rnd_octstring(19);
886 var octetstring si5_diff := f_rnd_octstring(19);
887 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
888
889 f_l1_tune(L1CTL);
890 RSL.clear;
891
892 log("Activating channel, expecting standard SI5");
893 /* activate the logical channel */
894 f_est_dchan();
895 /* check that the specified SI5 value is actually sent */
896 f_sacch_present(si5);
897
898 /* set channel-specific different SI5 */
899 log("Setting channel specific SACCH INFO, expecting it");
900 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
901 /* check that the specified lchan-specific value is now used */
902 f_sacch_present(si5_diff);
903
904 /* deactivate the channel and re-activate it, this should result in default SI5 */
905 log("De-activating and re-activating channel, expecting standard SI5");
906 f_rsl_chan_deact();
907 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
908 /* Verify that the TRX-wide default SACCH filling is present again */
909 f_sacch_present(si5);
910
911 /* release the channel */
912 RSL.clear;
913 f_rsl_chan_deact();
914 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
915}
916testcase TC_sacch_info_mod() runs on test_CT {
917 var ConnHdlr vc_conn;
918 var ConnHdlrPars pars;
919 f_init();
920 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
921 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
922 log(testcasename(), ": Starting for ", g_AllChannels[i]);
923 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
924 vc_conn.done;
925 }
926 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100928}
929
Harald Welte075d84c2018-03-12 13:07:24 +0100930/* Test SACCH scheduling of multiple different SI message types */
931private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
932 var octetstring si5 := f_rnd_octstring(19);
933 var octetstring si5bis := f_rnd_octstring(19);
934 var octetstring si5ter := f_rnd_octstring(19);
935 var octetstring si6 := f_rnd_octstring(19);
936
937 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
938 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
939 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
940 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
941
942 f_l1_tune(L1CTL);
943 RSL.clear;
944
945 /* activate the logical channel */
946 f_est_dchan();
947 L1CTL.clear;
948
949 /* check that SACCH actually are received as expected */
950 f_sacch_present(si5);
951 f_sacch_present(si5bis);
952 f_sacch_present(si5ter);
953 f_sacch_present(si6);
954
955 /* release the channel */
956 f_rsl_chan_deact();
957 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
958}
959testcase TC_sacch_multi() runs on test_CT {
960 var ConnHdlr vc_conn;
961 var ConnHdlrPars pars;
962 f_init();
963 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
964 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
965 log(testcasename(), ": Starting for ", g_AllChannels[i]);
966 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
967 vc_conn.done;
968 }
969 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100971}
972
Harald Welte55700662018-03-12 13:15:43 +0100973/* Test if SACH information is modified as expected */
974private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
975 var octetstring si5 := f_rnd_octstring(19);
976 var octetstring si6 := f_rnd_octstring(19);
977
978 /* First, configure both SI5 and SI6 to be transmitted */
979 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
980 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
981
982 f_l1_tune(L1CTL);
983 RSL.clear;
984
985 /* activate the logical channel */
986 f_est_dchan();
987 L1CTL.clear;
988
989 /* check that SACCH actually are received as expected */
990 f_sacch_present(si5);
991 f_sacch_present(si6);
992
993 /* disable SI6 */
994 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
995
996 /* check that SI5 is still transmitted */
997 f_sacch_present(si5);
998 /* check if SI6 is now gone */
999 f_sacch_missing(si6);
1000
1001 /* release the channel */
1002 f_rsl_chan_deact();
1003 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1004}
1005testcase TC_sacch_multi_chg() runs on test_CT {
1006 var ConnHdlr vc_conn;
1007 var ConnHdlrPars pars;
1008 f_init();
1009 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1010 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1011 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1012 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1013 vc_conn.done;
1014 }
1015 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001017}
1018
Harald Weltec8d363c2019-05-19 20:36:48 +02001019/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1020private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1021 var octetstring si5 := f_rnd_octstring(19);
1022 var octetstring si6 := f_rnd_octstring(19);
1023 var octetstring si5_specific := f_rnd_octstring(19);
1024 var octetstring si6_specific := f_rnd_octstring(19);
1025
1026 /* First, configure both SI5 and SI6 to be transmitted */
1027 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1028 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1029
1030 f_l1_tune(L1CTL);
1031 RSL.clear;
1032
1033 /* activate channel with different SACCH filling */
1034 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1035 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1036 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1037 }));
1038 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1039 RSL_IE_Body:{sacch_info := sacch_info})) };
1040 f_est_dchan(more_ies := addl_ies);
1041
1042 /* check that SACCH actually are received as expected */
1043 f_sacch_present(si5_specific);
1044 f_sacch_present(si6_specific);
1045
1046 /* release the channel */
1047 f_rsl_chan_deact();
1048 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1049}
1050testcase TC_sacch_chan_act() runs on test_CT {
1051 var ConnHdlr vc_conn;
1052 var ConnHdlrPars pars;
1053 f_init();
1054
1055 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1056 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1057 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1058 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1059 vc_conn.done;
1060 }
1061 /* TODO: do the above in parallel, rather than sequentially? */
1062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1063}
1064
Harald Welte8b01c792019-05-19 22:51:25 +02001065/* verify that SACCH DL transmission is started only if MS power IE present
1066 * see section 4.1.3 of 3GPP TS 48.058 */
1067private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1068 var octetstring si5 := f_rnd_octstring(19);
1069
1070 f_l1_tune(L1CTL);
1071 RSL.clear;
1072
1073 /* Step 1: Activate ASYNC HO channel without MS power IE */
1074
1075 /* Activate channel on BTS side */
1076 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1077 /* don't perform immediate assignment here, as we're testing non-IA case */
1078 /* enable dedicated mode */
1079 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1080
1081 /* Verify that no DL SACCH is being received */
1082 f_sacch_missing(?);
1083
1084 f_rsl_chan_deact();
1085 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1086
1087
1088 /* Step 2: Activate ASYNC HO channel with MS power IE */
1089
1090 /* Activate channel on BTS side */
1091 var RSL_IE_List addl_ies := {
1092 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1093 };
1094 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1095 /* don't perform immediate assignment here, as we're testing non-IA case */
1096 /* enable dedicated mode */
1097 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1098
1099 /* Verify that DL SACCH is being received */
1100 f_sacch_present(si5);
1101
1102 f_rsl_chan_deact();
1103 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1104}
1105testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1106 var ConnHdlr vc_conn;
1107 var ConnHdlrPars pars;
1108 f_init();
1109
1110 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1111 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1112 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1113 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1114 vc_conn.done;
1115 }
1116 /* TODO: do the above in parallel, rather than sequentially? */
1117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1118}
1119
1120/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1121 * see section 4.1.4 of 3GPP TS 48.058 */
1122private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1123 var octetstring si5 := f_rnd_octstring(19);
1124 var RSL_IE_List addl_ies;
1125
1126 f_l1_tune(L1CTL);
1127 RSL.clear;
1128
1129 /* Step 1: Activate SYNC HO channel without MS power IE */
1130
1131 /* Activate channel on BTS side */
1132 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1133 /* don't perform immediate assignment here, as we're testing non-IA case */
1134 /* enable dedicated mode */
1135 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1136
1137 /* Verify that no DL SACCH is being received */
1138 f_sacch_missing(?);
1139
1140 f_rsl_chan_deact();
1141 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1142
1143
1144 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1145
1146 /* Activate channel on BTS side */
1147 addl_ies := {
1148 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1149 };
1150 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1151 /* don't perform immediate assignment here, as we're testing non-IA case */
1152 /* enable dedicated mode */
1153 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1154
1155 /* Verify that no DL SACCH is being received */
1156 f_sacch_missing(?);
1157
1158 f_rsl_chan_deact();
1159 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1160
1161
1162 /* Step 2b: Activate SYNC HO channel with TA IE */
1163
1164 /* Activate channel on BTS side */
1165 addl_ies := {
1166 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1167 };
1168 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1169 /* don't perform immediate assignment here, as we're testing non-IA case */
1170 /* enable dedicated mode */
1171 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1172
1173 /* Verify that no DL SACCH is being received */
1174 f_sacch_missing(?);
1175
1176 f_rsl_chan_deact();
1177 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1178
1179
1180 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1181
1182 /* Activate channel on BTS side */
1183 addl_ies := {
1184 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1185 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1186 };
1187 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1188 /* don't perform immediate assignment here, as we're testing non-IA case */
1189 /* enable dedicated mode */
1190 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1191
1192 /* Verify that DL SACCH is being received */
1193 f_sacch_present(si5);
1194
1195 f_rsl_chan_deact();
1196 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1197}
1198testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1199 var ConnHdlr vc_conn;
1200 var ConnHdlrPars pars;
1201 f_init();
1202
1203 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1204 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1205 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1206 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1207 vc_conn.done;
1208 }
1209 /* TODO: do the above in parallel, rather than sequentially? */
1210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1211}
Harald Welte629cc6b2018-03-11 17:19:05 +01001212
1213
1214/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001215 * RACH Handling
1216 ***********************************************************************/
1217
Harald Welte8c24c2b2018-02-26 08:31:31 +01001218/* like L1SAP_IS_PACKET_RACH */
1219private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001220 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001221 return true;
1222 }
1223 return false;
1224}
1225
1226/* generate a random RACH for circuit-switched */
1227private function f_rnd_ra_cs() return OCT1 {
1228 var OCT1 ra;
1229 do {
1230 ra := f_rnd_octstring(1);
1231 } while (ra_is_ps(ra));
1232 return ra;
1233}
1234
Harald Welte883340c2018-02-28 18:59:29 +01001235/* generate a random RACH for packet-switched */
1236private function f_rnd_ra_ps() return OCT1 {
1237 var OCT1 ra;
1238 do {
1239 ra := f_rnd_octstring(1);
1240 } while (not ra_is_ps(ra));
1241 return ra;
1242}
1243
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001244/* generate a random 11-bit RA (packet-switched only) */
1245private function f_rnd_ra11_ps() return BIT11 {
1246 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1247 return int2bit(ra11, 11);
1248}
1249
Harald Welte8c24c2b2018-02-26 08:31:31 +01001250/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1251testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001252 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001253 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001254 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001255
Harald Welte8c24c2b2018-02-26 08:31:31 +01001256 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001257 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001258 for (var integer i := 0; i < 1000; i := i+1) {
1259 var OCT1 ra := f_rnd_ra_cs();
1260 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1261 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001263 }
1264 fn_last := fn;
1265
1266 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001267 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001268 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001269 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001270 T.stop;
1271 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001272 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001274 }
1275 [] RSL_CCHAN.receive { repeat; }
1276 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001277 test_failed := true;
1278 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001279 }
1280 }
1281 }
Maxba06feb2019-03-05 10:52:46 +01001282 if (test_failed) {
1283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001284 }
Maxba06feb2019-03-05 10:52:46 +01001285 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001287}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001288
1289/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1290testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001291 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001292 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001293 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 f_l1_tune(L1CTL);
1295
1296 var GsmFrameNumber fn_last := 0;
1297 for (var integer i := 0; i < 1000; i := i+1) {
1298 var OCT1 ra := f_rnd_ra_cs();
1299 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1300 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001302 }
1303 fn_last := fn;
1304 }
1305 var integer rsl_chrqd := 0;
1306 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001307 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001308 alt {
1309 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1310 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001311 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001312 repeat;
1313 }
1314 [] RSL_CCHAN.receive { repeat; }
1315 [] T.timeout { }
1316 }
1317 if (rsl_chrqd == 1000) {
1318 setverdict(pass);
1319 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001321 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001323}
1324
Harald Welte3453ab42019-05-24 21:19:58 +02001325private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1326 var charstring bts_str := "bts " & int2str(bts_nr);
1327 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1328}
1329
1330/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1331private template integer tr_rach_slots_per_interval := (90 .. 130);
1332
1333/* Expect 0 RACH load on an idle BTS that has just started up */
1334testcase TC_rach_load_idle_thresh0() runs on test_CT {
1335 var ASP_RSL_Unitdata rx_ud;
1336
1337 f_init_vty_bsc();
1338 /* send load indications even at 0% load */
1339 f_vty_load_ind_thresh(0);
1340 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1341 f_sleep(2.0);
1342
1343 f_init();
1344
1345 timer T := 5.0;
1346 T.start;
1347 alt {
1348 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1349 setverdict(pass);
1350 repeat;
1351 }
1352 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1353 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1354 repeat;
1355 }
1356 [] RSL_CCHAN.receive {
1357 repeat;
1358 }
1359 [] T.timeout { }
1360 }
1361
1362 f_vty_load_ind_thresh(10);
1363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1364}
1365
1366/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1367testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1368 var ASP_RSL_Unitdata rx_ud;
1369
1370 f_init_vty_bsc();
1371 f_init();
1372
1373 timer T := 5.0;
1374 T.start;
1375 alt {
1376 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1377 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1378 repeat;
1379 }
1380 [] RSL_CCHAN.receive {
1381 repeat;
1382 }
1383 [] T.timeout {
1384 setverdict(pass);
1385 }
1386 }
1387
1388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1389}
1390
1391/* Expect 0 RACH load on an idle BTS that has just started up */
1392testcase TC_rach_load_count() runs on test_CT {
1393 var ASP_RSL_Unitdata rx_ud;
1394 var integer load_access_count := 0;
1395
1396 f_init_vty_bsc();
1397 /* send load indications even at 0% load */
1398 f_vty_load_ind_thresh(0);
1399 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1400 f_sleep(2.0);
1401 f_init();
1402
1403 f_init_l1ctl();
1404 f_sleep(1.0);
1405 f_l1_tune(L1CTL);
1406
1407 var GsmFrameNumber fn_last := 0;
1408 for (var integer i := 0; i < 1000; i := i+1) {
1409 var OCT1 ra := f_rnd_ra_cs();
1410 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1411 if (fn == fn_last) {
1412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1413 }
1414 fn_last := fn;
1415 }
1416
1417 timer T := 5.0;
1418 T.start;
1419 alt {
1420 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1421 -> value rx_ud {
1422 var RSL_IE_Body ie;
1423 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1424 load_access_count := load_access_count + ie.rach_load.access_count;
1425 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1426 setverdict(fail, "Access count cannot be < Busy count");
1427 }
1428 repeat;
1429 }
1430 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1431 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1432 repeat;
1433 }
1434 [] RSL_CCHAN.receive {
1435 repeat;
1436 }
1437 [] T.timeout { }
1438 }
1439 if (load_access_count == 1000) {
1440 setverdict(pass);
1441 } else {
1442 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1443 }
1444
1445 f_vty_load_ind_thresh(10);
1446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1447}
1448
Harald Welte54a2a2d2018-02-26 09:14:05 +01001449private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001450 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001451 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001452 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001453 f_sleep(0.5);
1454
1455 /* Transmit RACH request + wait for confirmation */
1456 var OCT1 ra := f_rnd_ra_cs();
1457 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1458
1459 /* Check for expected result */
1460 timer T := 1.5;
1461 T.start;
1462 alt {
1463 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1464 setverdict(pass);
1465 }
1466 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001468 }
1469 [] RSL_CCHAN.receive { repeat; }
1470 [not expect_pass] T.timeout {
1471 setverdict(pass);
1472 }
1473 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001475 }
1476 }
1477}
1478
1479/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1480testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001481 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001482 f_init_l1ctl();
1483 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001484 f_sleep(1.0);
1485
1486 /* default max-ta is 63 (full range of GSM timing advance */
1487
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001488 /* We allow early arrival up to 2 symbols */
1489 f_rach_toffs(-1*256, true);
1490 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001491 f_rach_toffs(-10*256, false);
1492
1493 /* 0 / 32 / 63 bits is legal / permitted */
1494 f_rach_toffs(0, true);
1495 f_rach_toffs(32*256, true);
1496 f_rach_toffs(63*256, true);
1497
1498 /* more than 63 bits is not legal / permitted */
1499 f_rach_toffs(64*256, false);
1500 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001502}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001503
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001504function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1505 var GsmFrameNumber fn;
1506 var RSL_Message rm;
1507
1508 f_l1_tune(L1CTL);
1509 RSL.clear;
1510
1511 /* Generate a random Handover Reference */
1512 var integer ho_ref := oct2int(f_rnd_octstring(1));
1513
1514 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1515 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1516 RSL_IE_Body:{ handover_ref := ho_ref }));
1517
1518 /* Activate a channel on the BTS side (no encryption) */
1519 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1520 act_type := t_RSL_IE_ActType_HO_SYNC);
1521
1522 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1523 * waiting for Immediate Assignment and sending Access Burst */
1524 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1525
1526 /* Send handover Access Burst */
1527 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1528
1529 /* TODO: test mismatching Handover Reference, and missing IE */
1530
1531 /* Wait for handover detection */
1532 timer T := 3.0;
1533 T.start;
1534 alt {
1535 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1536 log("Handover RACH has been detected: ", rm);
1537 setverdict(pass);
1538 }
1539 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1541 log2str("RSL_CHAN_RQD was not expected: ", rm));
1542 }
1543 [] RSL.receive { repeat; }
1544 [] T.timeout {
1545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1546 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1547 }
1548 }
1549
1550 /* Release the channel */
1551 f_rsl_chan_deact();
1552 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1553}
1554
1555/* Test handover RACH detection */
1556testcase TC_ho_rach() runs on test_CT {
1557 var ConnHdlrPars pars;
1558 var ConnHdlr vc_conn;
1559
1560 f_init();
1561
1562 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1563 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1564 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1565 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1566 vc_conn.done;
1567 }
1568
1569 /* TODO: do the above in parallel, rather than sequentially? */
1570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1571}
1572
Harald Welte93640c62018-02-25 16:59:33 +01001573/***********************************************************************
1574 * Measurement Processing / Reporting
1575 ***********************************************************************/
1576
Harald Welte70767382018-02-21 12:16:40 +01001577template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1578 spare := '0'B,
1579 lpd := 0,
1580 sapi := sapi,
1581 c_r := c_r,
1582 ea := true
1583}
1584
Harald Welted879bd92018-03-12 15:01:23 +01001585template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001586 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001587 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001588 len := 0, /* overwritten */
1589 m := false,
1590 el := 1,
1591 payload := pl
1592}
1593
1594/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1595altstep as_l1_sacch() runs on ConnHdlr {
1596 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001597 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001598 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001599 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 +01001600 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001601 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001602
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001603 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1604 g_pars.l1_pars.ms_power_level, false,
1605 g_pars.l1_pars.ms_actual_ta);
1606
1607 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1608 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1609
1610 log("Sending Measurement Report: ", l1h, l2);
1611 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001612 repeat;
1613 }
1614}
1615
1616altstep as_l1_dcch() runs on ConnHdlr {
1617 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001618 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001619 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1620 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001621 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1622 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001623 repeat;
1624 }
1625}
1626
1627type record MeasElem {
1628 uint6_t rxlev,
1629 uint3_t rxqual
1630}
1631
1632type record MeasElemFS {
1633 MeasElem full,
1634 MeasElem sub
1635}
1636
1637type record ConnL1Pars {
1638 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001639 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001640 MeasElemFS meas_ul,
1641 int16_t timing_offset_256syms,
1642 uint5_t bs_power_level,
1643 uint5_t ms_power_level,
1644 uint8_t ms_actual_ta
1645}
1646
1647/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1648private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1649 return 63 + (toffs256s/256);
1650}
1651
Harald Welted5684392018-03-10 18:22:04 +01001652private function f_max(integer a, integer b) return integer {
1653 if (a > b) {
1654 return a;
1655 } else {
1656 return b;
1657 }
1658}
1659
1660private function f_min(integer a, integer b) return integer {
1661 if (a < b) {
1662 return a;
1663 } else {
1664 return b;
1665 }
1666}
1667
1668/* compute negative tolerance val-tolerance, ensure >= min */
1669private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1670 val := val - tolerance;
1671 return f_max(val, min);
1672}
1673
1674/* compute positive tolerance val+tolerance, ensure <= max */
1675private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1676 val := val + tolerance;
1677 return f_min(val, max);
1678}
1679
1680/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1681private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1682return template integer {
1683 var template integer ret;
1684 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1685 return ret;
1686}
1687
1688
Harald Welte70767382018-02-21 12:16:40 +01001689/* build a template for matching measurement results against */
1690private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1691 var ConnL1Pars l1p := g_pars.l1_pars;
1692 var template RSL_IE_UplinkMeas ul_meas := {
1693 len := 3,
1694 rfu := '0'B,
1695 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001696 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001697 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001698 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001699 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001700 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1701 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001702 supp_meas_info := omit
1703 };
Harald Welte685d5982018-02-27 20:42:05 +01001704 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001705 ul_meas.len := (3+8);
1706 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001707 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001708 toa256_min := ?,
1709 toa256_max := ?,
1710 toa256_std_dev := ?
1711 }
Harald Welte685d5982018-02-27 20:42:05 +01001712 }
Harald Welte70767382018-02-21 12:16:40 +01001713 var template RSL_IE_BS_Power bs_power := {
1714 reserved := 0,
1715 epc := false,
1716 fpc := false,
1717 power_level := l1p.bs_power_level
1718 };
1719 var template RSL_IE_L1Info l1_info := {
1720 ms_power_lvl := l1p.ms_power_level,
1721 fpc := false,
1722 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001723 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001724 };
1725 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001726 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001727 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1728 ?, t_toffs);
1729}
1730
1731/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001732altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001733 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001734 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001735 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1736 /* increment counter of next to-be-expected meas rep */
1737 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1738 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001739 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001740 repeat;
1741 }
1742 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001743 /* increment counter of next to-be-expected meas rep */
1744 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1745 if (g_first_meas_res) {
1746 g_first_meas_res := false;
1747 repeat;
1748 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001750 }
Harald Welte70767382018-02-21 12:16:40 +01001751 }
1752 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001754 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001755 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001757 }
1758}
1759
Harald Weltee613f962018-04-18 22:38:16 +02001760private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1761 select (rsl_alg_id) {
1762 case (RSL_ALG_ID_A5_0) { return 0; }
1763 case (RSL_ALG_ID_A5_1) { return 1; }
1764 case (RSL_ALG_ID_A5_2) { return 2; }
1765 case (RSL_ALG_ID_A5_3) { return 3; }
1766 case (RSL_ALG_ID_A5_4) { return 4; }
1767 case (RSL_ALG_ID_A5_5) { return 5; }
1768 case (RSL_ALG_ID_A5_6) { return 6; }
1769 case (RSL_ALG_ID_A5_7) { return 7; }
1770 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1772 /* Make compiler happy by calling mtc.stop here. It is already
1773 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001774 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001775 }
1776 }
1777}
1778
1779private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1780 select (rsl_alg_id) {
1781 case (RSL_ALG_ID_A5_1) { return '000'B; }
1782 case (RSL_ALG_ID_A5_2) { return '001'B; }
1783 case (RSL_ALG_ID_A5_3) { return '010'B; }
1784 case (RSL_ALG_ID_A5_4) { return '011'B; }
1785 case (RSL_ALG_ID_A5_5) { return '100'B; }
1786 case (RSL_ALG_ID_A5_6) { return '101'B; }
1787 case (RSL_ALG_ID_A5_7) { return '110'B; }
1788 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1790 /* Make compiler happy by calling mtc.stop here. It is already
1791 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001792 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001793 }
1794 }
1795}
1796
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001797/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1798private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1799 var GsmFrameNumber fn;
1800 timer T := 8.0;
1801
1802 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1803 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1804
1805 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1806 /* Send the actual RACH */
1807 fn := f_L1CTL_RACH(L1CTL, ra);
1808
1809 T.start;
1810 alt {
1811 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1812 [] T.timeout {
1813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1814 }
1815 }
1816 T.stop
1817 return fn;
1818}
Harald Weltee613f962018-04-18 22:38:16 +02001819
Harald Welte70767382018-02-21 12:16:40 +01001820/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001821private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001822 var GsmFrameNumber fn;
1823 var ImmediateAssignment imm_ass;
1824 var integer ra := 23;
1825
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001826 /* Send RACH request and wait for ChanReq */
1827 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001828
1829 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001830 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001831
1832 /* Send IMM.ASS via CCHAN */
1833 var ChannelDescription ch_desc := {
1834 chan_nr := g_pars.chan_nr,
1835 tsc := 7,
1836 h := false,
1837 arfcn := mp_trx0_arfcn,
1838 maio_hsn := omit
1839 };
1840 var MobileAllocation ma := {
1841 len := 0,
1842 ma := ''B
1843 };
1844 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1845 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1846
1847 /* receive IMM.ASS on MS side */
1848 var ImmediateAssignment ia_um;
1849 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1850 /* enable dedicated mode */
1851 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001852 /* enable encryption, if requested */
1853 if (encr_enable) {
1854 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1855 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1856 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001857
1858 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001859}
1860
1861/* establish DChan, verify existance + contents of measurement reports */
1862function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001863 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001864 RSL.clear;
1865
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001866 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001867 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001868 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001869 }
Harald Welte70767382018-02-21 12:16:40 +01001870
1871 f_est_dchan();
1872
1873 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1874 * RSL measurement reports on Abis side */
1875 timer T := 8.0;
1876 T.start;
1877 alt {
1878 [] as_l1_sacch();
1879 [] as_meas_res();
1880 [] as_l1_dcch();
1881 [] L1CTL.receive { repeat; }
1882 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001883 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001884 * of any earlier errors, so if we reach this timeout, we're good */
1885 setverdict(pass);
1886 }
1887 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001889 }
1890 }
1891 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001892 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001893}
Harald Welte0472ab42018-03-12 15:02:26 +01001894
Eric Wild61edb7e2019-06-03 12:38:31 +02001895/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
1896second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
1897These power levels are valid for all bands and require no special handling */
1898function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
1899 var uint5_t pwr_var := 7;
1900 var L1ctlDlMessage l1_dl;
1901
1902 f_trxc_fake_rssi(rxlev2dbm(10));
1903 f_l1_tune(L1CTL);
1904 RSL.clear;
1905
1906 var RSL_IE_List addl_ies;
1907 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
1908
1909 addl_ies := {
1910 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
1911 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
1912 };
1913
1914 /* establish with power parameters */
1915 f_est_dchan(more_ies := addl_ies);
1916
1917 /* set a high value to ensure L1 power control level increases */
1918 f_trxc_fake_rssi(rxlev2dbm(20));
1919
1920 timer T2 := 6.0;
1921 T2.start;
1922 alt {
1923 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1924 if( not(oct2int(l1_dl.payload.data_ind.payload[0]) > (pwr_var+6))){
1925 repeat;
1926 }
1927 T2.stop;
1928 }
1929 [] L1CTL.receive { repeat; }
1930 [] T2.timeout {
1931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1932 "Power Level in L1 header has not increased sufficiently");
1933 }
1934 }
1935
1936 /* set a low value to ensure L1 power control level decreases */
1937 f_trxc_fake_rssi(rxlev2dbm(0));
1938
1939 timer T4 := 6.0;
1940 T4.start;
1941 alt {
1942 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1943 if( not(oct2int(l1_dl.payload.data_ind.payload[0]) <= (pwr_var))){
1944 repeat;
1945 }
1946 T4.stop;
1947 setverdict(pass, "Power level in L1 decreased/increased as expected");
1948 }
1949 [] L1CTL.receive { repeat; }
1950 [] T4.timeout {
1951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1952 "Power Level in L1 header has not decreased sufficiently");
1953 }
1954 }
1955
1956 f_rsl_chan_deact();
1957 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1958
1959}
1960
1961/* check that we do not exceed the max power */
1962function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
1963 var uint5_t pwr_var := 7;
1964 var L1ctlDlMessage l1_dl;
1965
1966 /* set a low value to ensure power increases */
1967 f_trxc_fake_rssi(rxlev2dbm(10));
1968 f_l1_tune(L1CTL);
1969 RSL.clear;
1970
1971 var RSL_IE_List addl_ies;
1972 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
1973
1974 addl_ies := {
1975 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
1976 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
1977 };
1978
1979 /* establish with power parameters */
1980 f_est_dchan(more_ies := addl_ies);
1981
1982 timer T1 := 10.0;
1983 T1.start;
1984 alt {
1985 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl { repeat; }
1986 [] L1CTL.receive { repeat; }
1987 [] T1.timeout {
1988 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
1989 setverdict(fail, "Power level in L1 header should not have changed");
1990 }
1991 }
1992 }
1993
1994 f_rsl_chan_deact();
1995 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1996
1997}
1998
1999/* see if we reach the band max power */
2000function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2001 var L1ctlDlMessage l1_dl;
2002 var uint5_t pwr_var := 15;
2003 var uint5_t pwr_max_var := f_get_max_power_from_band();
2004
2005 /* set a low value to ensure power increases */
2006 f_trxc_fake_rssi(rxlev2dbm(10));
2007 f_l1_tune(L1CTL);
2008 RSL.clear;
2009
2010 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2011 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2012
2013 /* establish with fixed power level */
2014 f_est_dchan(more_ies :={valueof(pwr)});
2015
2016 /* check our initial power level */
2017 f_wait_for_l1_power_level(pwr_var);
2018
2019 /* update power param to enable power loop
2020 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2021 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2022
2023 /* wait, then check that our power level was reduced */
2024 timer T1 := 10.0;
2025 T1.start;
2026 alt {
2027 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl { repeat; }
2028 [] L1CTL.receive { repeat; }
2029 [] T1.timeout {
2030 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2031 if( f_power_level_is_highest_dbm(rcv) ){
2032 setverdict(pass, "Power level in L1 header reduced as expected");
2033 } else {
2034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2035 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2036 }
2037 }
2038 }
2039
2040 f_rsl_chan_deact();
2041 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2042
2043}
2044
2045/* see if we reach the band min power */
2046function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2047 var L1ctlDlMessage l1_dl;
2048
2049 /* set a high value to ensure power decreases */
2050 f_trxc_fake_rssi(rxlev2dbm(50));
2051 f_l1_tune(L1CTL);
2052 RSL.clear;
2053
2054 var uint5_t pwr_var := 5;
2055 var uint5_t pwr_target_val := 15;
2056
2057 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2058 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2059
2060 /* establish with fixed power level */
2061 f_est_dchan(more_ies :={valueof(pwr)});
2062
2063 /* check our initial power level */
2064 f_wait_for_l1_power_level(pwr_var);
2065
2066 /* update power param to enable power loop
2067 as per spec the supplied ms power IE should set the max allowed power...*/
2068 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_var));
2069
2070 /* wait, then check that our power level was increased */
2071 timer T1 := 10.0;
2072 T1.start;
2073 alt {
2074 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl { repeat; }
2075 [] L1CTL.receive { repeat; }
2076 [] T1.timeout {
2077 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2078 setverdict(pass, "Power level in L1 header increased to lowest power value");
2079 } else {
2080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2081 "Power level in L1 header NOT increased to lowest power value");
2082 }
2083 }
2084 }
2085
2086 f_rsl_chan_deact();
2087 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2088
2089}
2090
Eric Wild280ccb82019-06-17 11:11:52 +02002091/* see if we change the power level without receiving power parameters, which should not happen */
2092function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2093 var L1ctlDlMessage l1_dl;
2094
2095 /* set a high value to ensure power decreases */
2096 f_trxc_fake_rssi(rxlev2dbm(50));
2097 f_l1_tune(L1CTL);
2098 RSL.clear;
2099
2100 var uint5_t pwr_var := 5;
2101
2102 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2103 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2104
2105 /* establish with fixed power level */
2106 f_est_dchan(more_ies :={valueof(pwr)});
2107
2108 /* check our initial power level */
2109 f_wait_for_l1_power_level(pwr_var);
2110
2111 /* wait, then check that our power level did not change */
2112 timer T1 := 10.0;
2113 T1.start;
2114 alt {
2115 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2116 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2118 "BS power control should not be active unless we receive a power parameters IE!");
2119 }
2120 repeat;
2121 }
2122 [] L1CTL.receive { repeat; }
2123 [] T1.timeout { setverdict(pass); }
2124 }
2125
2126 f_rsl_chan_deact();
2127 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2128
2129}
2130
Eric Wild61edb7e2019-06-03 12:38:31 +02002131function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2132 var L1ctlDlMessage l1_dl;
2133 timer T0 := 10.0;
2134 T0.start;
2135 alt {
2136 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2137 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2139 "Power level in L1 header != signaled (RSL) power level.");
2140 }
2141 }
2142 [] L1CTL.receive { repeat; }
2143 [] T0.timeout {
2144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2145 "Timeout waiting for initial power level");
2146 }
2147 }
2148 T0.stop;
2149}
2150
2151private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2152 var IntegerRecord min_dbm_level;
2153 var IntegerRecord max_dbm_level;
2154 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2155
2156 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2157 if (min_dbm_level[i] == level) {
2158 return true;
2159 }
2160 }
2161 return false;
2162}
2163
2164private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2165 var IntegerRecord min_dbm_level;
2166 var IntegerRecord max_dbm_level;
2167 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2168
2169 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2170 if (max_dbm_level[i] == level) {
2171 return true;
2172 }
2173 }
2174 return false;
2175}
2176
2177private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2178 var IntegerRecord min_dbm_level;
2179 var IntegerRecord max_dbm_level;
2180 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2181 return max_dbm_level[0];
2182}
2183
2184type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2185template charstring BtsBand_allGSM:= pattern "GSM???";
2186private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2187 // 45.005 4.1.1
2188 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2189 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2190 2, 1, 0};
2191 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2192 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2193 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2194 var IntegerRecord rv;
2195
2196 select(band){
2197 case (BtsBand_allGSM){
2198 rv := gsm_power;
2199 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2200 max_dbm_level := {2, 1, 0};
2201 }
2202 case("DCS1800"){
2203 rv := dcs_power;
2204 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2205 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2206 }
2207 case("PCS1900"){
2208 rv := pcs_power;
2209 min_dbm_level := {15};
2210 max_dbm_level := {30};
2211 }
2212 }
2213
2214 return rv;
2215}
2216
2217private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2218 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2219}
2220
2221testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2222 var ConnHdlr vc_conn;
2223 var ConnHdlrPars pars;
2224 f_init();
2225 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2226 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2227 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2228 pars.bts0_band := f_vty_get_bts0_band();
2229 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2230 vc_conn.done;
2231 }
2232 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2234}
2235
2236testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2237 var ConnHdlr vc_conn;
2238 var ConnHdlrPars pars;
2239 f_init();
2240 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2241 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2242 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2243 pars.bts0_band := f_vty_get_bts0_band();
2244 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2245 vc_conn.done;
2246 }
2247 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2249}
2250
2251testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2252 var ConnHdlr vc_conn;
2253 var ConnHdlrPars pars;
2254 f_init();
2255 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2256 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2257 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2258 pars.bts0_band := f_vty_get_bts0_band();
2259 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2260 vc_conn.done;
2261 }
2262 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2264}
2265
2266testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2267 var ConnHdlr vc_conn;
2268 var ConnHdlrPars pars;
2269 f_init();
2270 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2271 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2272 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2273 pars.bts0_band := f_vty_get_bts0_band();
2274 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2275 vc_conn.done;
2276 }
2277 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2279}
2280
Eric Wild280ccb82019-06-17 11:11:52 +02002281testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2282 var ConnHdlr vc_conn;
2283 var ConnHdlrPars pars;
2284 f_init();
2285 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2286 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2287 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2288 pars.bts0_band := f_vty_get_bts0_band();
2289 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2290 vc_conn.done;
2291 }
2292 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2294}
2295
Harald Welte70767382018-02-21 12:16:40 +01002296testcase TC_meas_res_sign_tchf() runs on test_CT {
2297 var ConnHdlr vc_conn;
2298 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002299 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002300 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2301 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002302 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2303 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002304 vc_conn.done;
2305 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002307}
2308testcase TC_meas_res_sign_tchh() runs on test_CT {
2309 var ConnHdlr vc_conn;
2310 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002311 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002312 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2313 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2314 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2315 vc_conn.done;
2316 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002318}
2319testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2320 var ConnHdlr vc_conn;
2321 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002322 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002323 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2324 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
2325 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2326 vc_conn.done;
2327 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002329}
2330testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2331 var ConnHdlr vc_conn;
2332 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002333 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002334 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2335 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
2336 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2337 vc_conn.done;
2338 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002340}
Harald Welte685d5982018-02-27 20:42:05 +01002341testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2342 var ConnHdlr vc_conn;
2343 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002344 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002345 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2346 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2347 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2348 pars.l1_pars.toa256_enabled := true;
2349 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2350 vc_conn.done;
2351 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002353}
2354
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002355/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2356 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2357function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2358 var L1ctlDlMessage l1_dl;
2359 var RSL_IE_MS_Power ms_power;
2360 var RSL_Message rsl;
2361 var uint5_t power_level := 0;
2362
2363 f_l1_tune(L1CTL);
2364 RSL.clear;
2365
2366 f_est_dchan();
2367
2368 ms_power.reserved := 0;
2369 ms_power.fpc_epc := false;
2370
2371 /* Send the first power control command. This will disable any BTS/TRX
2372 * internal power control and switch the MS (which is not in scope of
2373 * this test) to a constant power level. We start with a power level
2374 * of 0 */
2375 ms_power.power_level := power_level;
2376 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2377 RSL.send(rsl);
2378
2379 alt {
2380
2381 /* Pick all SACCH blocks for checking */
2382 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2383
2384 /* The first byte of the L1 header contains the power level.
2385 * The reserved bits and the fpc bit is set to 0, so we may
2386 * compare directly. */
2387 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2388 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2389 }
2390
2391 /* Signal a new power level via RSL for the next turn. */
2392 if (power_level < 31) {
2393 power_level := power_level + 1;
2394 ms_power.power_level := power_level;
2395 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2396 RSL.send(rsl);
2397 repeat;
2398 }
2399
2400 }
2401
2402 /* Ignore all other blocks */
2403 [] L1CTL.receive { repeat; }
2404
2405 }
2406
2407 f_rsl_chan_deact();
2408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2409
2410 setverdict(pass);
2411}
2412
2413testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2414 var ConnHdlr vc_conn;
2415 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002416 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002417
2418 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2419 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2420 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2421 vc_conn.done;
2422 }
2423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2424}
Harald Welte70767382018-02-21 12:16:40 +01002425
Eric Wild6833cc92019-05-23 19:34:44 +02002426/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2427TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2428function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2429 var L1ctlDlMessage l1_dl;
2430 var uint5_t ta_to_test := 16;
2431
2432
2433 f_l1_tune(L1CTL);
2434 RSL.clear;
2435
2436 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002437 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002438
2439 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2440
2441
2442 alt {
2443
2444 /* Pick all SACCH blocks for checking */
2445 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2446
2447 /* The second byte of the L1 header contains the TA. */
2448 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2449 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2450 }
2451
2452 }
2453
2454 /* Ignore all other blocks */
2455 [] L1CTL.receive { repeat; }
2456
2457 }
2458
2459 f_rsl_chan_deact();
2460 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2461
2462 setverdict(pass);
2463}
2464
2465testcase TC_rsl_chan_initial_ta() runs on test_CT {
2466 var ConnHdlr vc_conn;
2467 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002468 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002469 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002470 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2471 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002472 vc_conn.done;
2473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2474}
2475
Eric Wilde57e1a62019-05-28 13:30:55 +02002476/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2477function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2478 var L1ctlDlMessage l1_dl;
2479 var uint5_t ms_power_level := 7;
2480
2481 var RSL_IE_MS_Power ms_power;
2482 ms_power.reserved := 0;
2483 ms_power.fpc_epc := false;
2484 ms_power.power_level := ms_power_level;
2485
2486 f_l1_tune(L1CTL);
2487 RSL.clear;
2488
2489 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2490
2491 timer T := 1.0;
2492 T.start;
2493 alt {
2494 /* Pick all SACCH blocks for checking */
2495 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2496 /* The first byte of the L1 header contains the power level.. */
2497 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2498 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2499 }
2500 }
2501 /* Ignore all other blocks */
2502 [] L1CTL.receive { repeat; }
2503 [] T.timeout {
2504 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2505 }
2506 }
2507
2508 f_rsl_chan_deact();
2509 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2510 setverdict(pass);
2511}
2512
2513testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2514 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2515 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2516}
2517
Harald Welte0472ab42018-03-12 15:02:26 +01002518/* 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 +01002519private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002520 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002521 RSL.clear;
2522
2523 f_est_dchan();
2524 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002525 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002526
2527 timer T := 40.0;
2528 T.start;
2529 alt {
2530 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2531 setverdict(pass)
2532 }
2533 [] RSL.receive { repeat };
2534 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002536 }
2537 }
2538 f_rsl_chan_deact();
2539}
2540testcase TC_conn_fail_crit() runs on test_CT {
2541 var ConnHdlr vc_conn;
2542 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002543 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002544 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2545 pars.t_guard := 60.0;
2546 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2547 vc_conn.done;
2548}
2549
Harald Welte93640c62018-02-25 16:59:33 +01002550/***********************************************************************
2551 * Paging
2552 ***********************************************************************/
2553
Harald Welte68e495b2018-02-25 00:05:57 +01002554function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2555 if (tmsi == 'FFFFFFFF'O) {
2556 return true;
2557 } else {
2558 return false;
2559 }
2560}
Harald Welte70767382018-02-21 12:16:40 +01002561
Philipp Maier82cb0b12018-08-31 14:41:39 +02002562type record allowedFn { integer frame_nr }
2563template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2564template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2565template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2566template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2567template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2568template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2569template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2570template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2571function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2572{
2573 var integer frame_nr_51;
2574 frame_nr_51 := frame_nr mod 51
2575
2576 var allowedFn fn_check;
2577 fn_check.frame_nr := frame_nr_51;
2578
2579 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002581 return;
2582 }
2583
2584 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2585 return;
2586 }
2587 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2588 return;
2589 }
2590 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2591 return;
2592 }
2593 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2594 return;
2595 }
2596 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2597 return;
2598 }
2599 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2600 return;
2601 }
2602 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2603 return;
2604 }
2605 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2606 return;
2607 }
2608
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002610 return;
2611}
2612
2613altstep 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 +01002614runs on test_CT {
2615 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002616 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002617 repeat;
2618 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002619 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002620 var octetstring without_plen :=
2621 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2622 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002623
2624 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2625
Harald Welte68e495b2018-02-25 00:05:57 +01002626 if (match(rr, tr_PAGING_REQ1)) {
2627 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2628 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2629 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2630 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2631 }
2632 } else if (match(rr, tr_PAGING_REQ2)) {
2633 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2634 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2635 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2636 }
2637 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2638 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2639 }
2640 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2641 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2642 }
2643 } else if (match(rr, tr_PAGING_REQ3)) {
2644 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2645 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2646 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2647 }
2648 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2649 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2650 }
2651 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2652 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2653 }
2654 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2655 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2656 }
2657 }
2658 repeat;
2659 }
2660}
2661
2662type record PagingTestCfg {
2663 boolean combined_ccch,
2664 integer bs_ag_blks_res,
2665 float load_factor,
2666 boolean exp_load_ind,
2667 boolean exp_overload,
2668 boolean use_tmsi
2669}
2670
2671type record PagingTestState {
2672 integer num_paging_sent,
2673 integer num_paging_rcv_msgs,
2674 integer num_paging_rcv_ids,
2675 integer num_overload
2676}
2677
2678/* receive + ignore RSL RF RES IND */
2679altstep as_rsl_res_ind() runs on test_CT {
2680 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2681 repeat;
2682 }
2683}
2684
2685/* Helper function for paging related testing */
2686private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002687 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002688 f_init_l1ctl();
2689 f_l1_tune(L1CTL);
2690
2691 var PagingTestState st := {
2692 num_paging_sent := 0,
2693 num_paging_rcv_msgs := 0,
2694 num_paging_rcv_ids := 0,
2695 num_overload := 0
2696 };
2697
2698 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2699 var float max_pch_imsi_per_sec;
2700 if (cfg.use_tmsi) {
2701 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2702 } else {
2703 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2704 }
2705 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2706 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002707 var float time_total := 20.0;
2708 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2709 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002710
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002711 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2712 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002713
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002714 timer T_itv := 0.0;
2715 T_itv.start;
2716 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002717 alt {
2718 /* check for presence of CCCH LOAD IND (paging load) */
2719 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2720 st.num_overload := st.num_overload + 1;
2721 repeat;
2722 }
2723 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002725 }
2726 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2727 log("Rx LOAD_IND");
2728 /* FIXME: analyze/verify interval + contents */
2729 repeat;
2730 }
2731 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002732 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002733 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002734 [] T_itv.timeout {
2735 /* Send paging cmds based on elapsed time */
2736 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2737 while (st.num_paging_sent < new_sent) {
2738 /* build mobile Identity */
2739 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2740 if (cfg.use_tmsi) {
2741 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2742 } else {
2743 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2744 }
2745 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2746 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2747
2748 /* Send RSL PAGING COMMAND */
2749 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2750
2751 st.num_paging_sent := st.num_paging_sent + 1;
2752 }
2753 if (st.num_paging_sent < pkt_total) {
2754 /* Wait for interval to next PAGING COMMAND */
2755 var float time_now := T_total.read;
2756 var float next_sched := int2float(st.num_paging_sent)*interval;
2757 if (next_sched > time_now) {
2758 T_itv.start(next_sched - time_now);
2759 } else {
2760 T_itv.start(0.0);
2761 }
2762 } else {
2763 /* We are done, no need to keep counting */
2764 T_total.stop;
2765 }
2766 }
2767 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002768 [] as_rsl_res_ind();
2769 }
2770 }
2771
2772 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2773 timer T_wait := 18.0;
2774 T_wait.start;
2775 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002776 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002777 [] L1CTL.receive { repeat; }
2778 /* 65535 == empty paging queue, we can terminate*/
2779 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2780 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2781 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002783 }
2784 [] as_rsl_res_ind();
2785 }
2786
2787 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2788 " rcvd_ids=", st.num_paging_rcv_ids);
2789 return st;
2790}
2791
2792/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2793 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2794 * - that CCCH LOAD IND (PCH) are being generated
2795 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2796testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002797 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002798 var PagingTestCfg cfg := {
2799 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002800 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002801 load_factor := 0.8,
2802 exp_load_ind := true,
2803 exp_overload := false,
2804 use_tmsi := false
2805 };
2806 var PagingTestState st := f_TC_paging(cfg);
2807 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2809 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002810 } else {
2811 setverdict(pass);
2812 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002814}
2815
2816/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2817 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2818 * - that CCCH LOAD IND (PCH) are being generated
2819 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2820testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002821 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002822 var PagingTestCfg cfg := {
2823 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002824 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002825 load_factor := 0.8,
2826 exp_load_ind := true,
2827 exp_overload := false,
2828 use_tmsi := true
2829 };
2830 var PagingTestState st := f_TC_paging(cfg);
2831 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2833 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002834 } else {
2835 setverdict(pass);
2836 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002838}
2839
2840/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2841 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2842 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2843 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2844testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002845 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002846 var PagingTestCfg cfg := {
2847 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002848 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002849 load_factor := 2.0,
2850 exp_load_ind := true,
2851 exp_overload := true,
2852 use_tmsi := false
2853 };
2854 var PagingTestState st := f_TC_paging(cfg);
2855 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2856 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002857 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002858 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002859 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 +01002860 } else {
2861 setverdict(pass);
2862 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002864}
2865
2866/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2867 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2868 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2869 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2870testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002871 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002872 var PagingTestCfg cfg := {
2873 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002874 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002875 load_factor := 2.0,
2876 exp_load_ind := true,
2877 exp_overload := true,
2878 use_tmsi := true
2879 };
2880 var PagingTestState st := f_TC_paging(cfg);
2881 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2882 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002883 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002884 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002885 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 +01002886 } else {
2887 setverdict(pass);
2888 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002890}
2891
2892
Harald Welte93640c62018-02-25 16:59:33 +01002893/***********************************************************************
2894 * Immediate Assignment / AGCH
2895 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002896const MobileAllocation c_MA_null := {
2897 len := 0,
2898 ma := ''B
2899}
Harald Welte93640c62018-02-25 16:59:33 +01002900
Harald Weltee8d750e2018-06-10 21:41:35 +02002901template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2902 uint12_t arfcn := 871) := {
2903 chan_nr := chan_nr,
2904 tsc := tsc,
2905 h := false,
2906 arfcn := arfcn,
2907 maio_hsn := omit
2908}
2909
2910private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2911 return int2str(num_tx) & " sent, "
2912 & int2str(num_rx) & " received, "
2913 & int2str(num_del) & " deleted";
2914}
2915
2916private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2917 var L1ctlDlMessage l1_dl;
2918 timer T := 10.0;
2919 var integer num_tx := 0;
2920 var integer num_rx := 0;
2921 var integer num_del := 0;
2922 var charstring res_str;
2923 var float rx_ratio;
2924
Harald Welte10474062019-05-30 16:48:17 +02002925 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02002926 f_init_l1ctl();
2927 f_l1_tune(L1CTL);
2928
2929 for (var integer i := 0; i < num_total; i := i+1) {
2930 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2931 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2932 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002933 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002934 num_tx := num_tx+1;
2935 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002936 }
2937 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002938 T.start;
2939 alt {
2940 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2941 num_del := num_del+1;
2942 repeat;
2943 }
2944 [] RSL_CCHAN.receive {
2945 repeat;
2946 }
2947 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2948 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2949 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2950 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2951 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002952 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002953 } else {
2954 num_rx := num_rx+1;
2955 }
2956 repeat;
2957 }
2958 [] L1CTL.receive { repeat; }
2959 [] T.timeout { }
2960 }
2961 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2962 log("AGCH test: " & res_str);
2963 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002965 }
2966 rx_ratio := int2float(num_rx) / int2float(num_tx);
2967 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002968 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 +02002969 } else {
2970 setverdict(pass);
2971 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002973}
2974
Harald Weltee8d750e2018-06-10 21:41:35 +02002975/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2976testcase TC_imm_ass_1000_20ms() runs on test_CT {
2977 f_TC_imm_ass(1000, 0.02, 0.25);
2978}
2979
2980/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2981testcase TC_imm_ass_200_0ms() runs on test_CT {
2982 f_TC_imm_ass(200, 0.0, 0.05);
2983}
2984
2985/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2986testcase TC_imm_ass_200_76ms() runs on test_CT {
2987 f_TC_imm_ass(150, 0.076, 1.00);
2988}
2989
2990
2991
Harald Welte48494ca2018-02-25 16:59:50 +01002992/***********************************************************************
2993 * BCCH
2994 ***********************************************************************/
2995
2996/* tuple of Frame Number + decoded SI */
2997type record SystemInformationFn {
2998 GsmFrameNumber frame_number,
2999 SystemInformation si
3000}
3001
3002/* an arbitrary-length vector of decoded SI + gsmtap header */
3003type record of SystemInformationFn SystemInformationVector;
3004
3005/* an array of SI-vectors indexed by TC value */
3006type SystemInformationVector SystemInformationVectorPerTc[8];
3007
3008/* determine if a given SI vector contains given SI type at least once */
3009function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3010 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3011 var integer fn_mod51 := arr[i].frame_number mod 51;
3012 if (not bcch_ext and fn_mod51 == 2 or
3013 bcch_ext and fn_mod51 == 6) {
3014 if (arr[i].si.header.message_type == key) {
3015 return true;
3016 }
3017 }
3018 }
3019 return false;
3020}
3021
3022/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3023function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3024 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003026 }
3027}
3028
3029/* check if a given SI vector contains given SI type at least once on any TC */
3030function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3031 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3032 if (f_si_vecslot_contains(arr[tc], key) or
3033 f_si_vecslot_contains(arr[tc], key, true)) {
3034 return true;
3035 }
3036 }
3037 return false;
3038}
3039
3040/* determine if a given SI vector contains given SI type at least N of M times */
3041function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3042 var integer count := 0;
3043 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003045 }
3046 for (var integer i:= 0; i < m; i := i + 1) {
3047 var integer fn_mod51 := arr[i].frame_number mod 51;
3048 if (not bcch_ext and fn_mod51 == 2 or
3049 bcch_ext and fn_mod51 == 6) {
3050 if (arr[i].si.header.message_type == key) {
3051 count := count + 1;
3052 }
3053 }
3054 }
3055 if (count >= n) {
3056 return true;
3057 } else {
3058 return false;
3059 }
3060}
3061
3062/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3063function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3064 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003066 }
3067}
3068
3069/* determine if a given SI vector contains given SI type at least once */
3070function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3071 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3072 var integer fn_mod51 := arr[i].frame_number mod 51;
3073 if (not bcch_ext and fn_mod51 == 2 or
3074 bcch_ext and fn_mod51 == 6) {
3075 if (arr[i].si.header.message_type != key) {
3076 return false;
3077 }
3078 }
3079 }
3080 return true;
3081}
3082
3083/* ensure a given TC slot of the SI vector contains only given SI type */
3084function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3085 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003087 }
3088}
3089
3090/* SI configuration of cell, against which we validate actual SI messages */
3091type set SystemInformationConfig {
3092 boolean bcch_extended,
3093 boolean si1_present,
3094 boolean si2bis_present,
3095 boolean si2ter_present,
3096 boolean si2quater_present,
3097 boolean si7_present,
3098 boolean si8_present,
3099 boolean si9_present,
3100 boolean si13_present,
3101 boolean si13alt_present,
3102 boolean si15_present,
3103 boolean si16_present,
3104 boolean si17_present,
3105 boolean si2n_present,
3106 boolean si21_present,
3107 boolean si22_present
3108}
3109
3110/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3111function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3112 var integer i;
3113 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3114 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003116 }
3117 }
3118 if (cfg.si1_present) {
3119 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3120 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3121 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3122 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3123 /* make sure *ALL* contain SI1 */
3124 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3125 }
3126 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3127 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3128 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3129 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3130 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3131 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3132
3133 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3134 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3135 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3136 * consecutive occurrences of TC = 4. */
3137 if (cfg.si2bis_present and not cfg.si2ter_present) {
3138 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3139 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3140 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3141 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3142 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3143 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3144 }
3145
3146 if (cfg.si7_present or cfg.si8_present) {
3147 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3148 * if System Information type 4 does not contain all information needed for cell
3149 * selection and reselection. */
3150 if (not cfg.bcch_extended) {
3151 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3152 }
3153 if (cfg.si7_present) {
3154 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3155 }
3156 if (cfg.si8_present) {
3157 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3158 }
3159 }
3160
3161 if (cfg.si2quater_present) {
3162 /* iii) System information type 2 quater is sent if needed, as determined by the system
3163 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3164 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3165 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3166 * within any of 4 consecutive occurrences of TC = 5. */
3167 if (not (cfg.bcch_extended)) {
3168 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3169 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3170 } else {
3171 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3172 }
3173 } else {
3174 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3175 }
3176 }
3177 if (cfg.si9_present) {
3178 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3179 * in system information type 3 as defined in 3GPP TS 44.018. */
3180 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3181 }
3182 if (cfg.si13_present) {
3183 /* vii) System Information type 13 is only related to the GPRS service. System Information
3184 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3185 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3186 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3187 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3188 * within any of 4 consecutive occurrences of TC=4. */
3189 if (not cfg.bcch_extended) {
3190 log("not-bccch-extended");
3191 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3192 } else {
3193 log("bccch-extended");
3194 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3195 }
3196 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003198 }
3199 }
3200 if (cfg.si16_present or cfg.si17_present) {
3201 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3202 * should not be sent in a cell where network sharing is used (see rule xv). */
3203 if (cfg.si22_present) {
3204 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3205 }
3206 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003208 }
3209 if (not cfg.bcch_extended) {
3210 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3211 }
3212 if (cfg.si16_present) {
3213 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3214 }
3215 if (cfg.si17_present) {
3216 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3217 }
3218 }
3219
3220 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3221 * broadcast information. The frequency with which they are sent is determined by the
3222 * system operator. System Information type 9 identifies the scheduling of System
3223 * Information type 18 and 20 messages. */
3224
3225 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3226 * Information Type 19 is present, then its scheduling shall be indicated in System
3227 * Information Type 9. */
3228
3229 if (cfg.si15_present) {
3230 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3231 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3232 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3233 * 4 consecutive occurrences of TC = 1. */
3234 if (not cfg.bcch_extended) {
3235 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3236 } else {
3237 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3238 }
3239 }
3240 if (cfg.si13alt_present) {
3241 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3242 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3243 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3244 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3245 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3246 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3247 * of TC = 4. */
3248 if (cfg.si13_present) {
3249 testcase.stop("Error: Cannot have SI13alt and SI13");
3250 }
3251 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003253 }
3254 if (not cfg.bcch_extended) {
3255 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3256 } else {
3257 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3258 }
3259 }
3260 if (cfg.si2n_present) {
3261 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3262 * as determined by the system operator. In the case that the message is sent on the
3263 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3264 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3265 * consecutive occurrences of TC = 4. */
3266 if (not cfg.bcch_extended) {
3267 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3268 } else {
3269 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3270 }
3271 }
3272 if (cfg.si21_present) {
3273 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3274 * determined by the system operator. If Extended Access Barring is in use in the cell
3275 * then this message is sent at least once within any of 4 consecutive occurrences of
3276 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3277 * cell then this message shall only be sent on BCCH Ext. */
3278 if (not cfg.bcch_extended) {
3279 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3280 } else {
3281 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3282 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003284 }
3285 }
3286 }
3287 if (cfg.si22_present) {
3288 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3289 * should not be sent in a cell where SoLSA is used (see rule viii). System
3290 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3291 * =2 and TC=6. */
3292 if (cfg.si16_present or cfg.si17_present) {
3293 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3294 }
3295 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3296 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003298 }
3299 if (not cfg.bcch_extended) {
3300 testcase.stop("Error: SI22 requires BCCH Extd!");
3301 } else {
3302 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3303 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3304 }
3305 }
3306}
3307
3308/* sample Systme Information for specified duration via L1CTL */
3309function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3310 timer T := duration;
3311 var SystemInformationVectorPerTc si_per_tc;
3312 var L1ctlDlMessage l1_dl;
3313
3314 /* initialize all per-TC vectors empty */
3315 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3316 si_per_tc[i] := {};
3317 }
3318
3319 /* flush all previous L1 queued msgs */
3320 pt.clear;
3321
3322 T.start;
3323 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003324 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003325 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3326 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3327 log("Ignoring non-RR SI ", l1_dl);
3328 repeat;
3329 }
3330 var SystemInformationFn sig := {
3331 frame_number := l1_dl.dl_info.frame_nr,
3332 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3333 }
3334 var integer tc := f_gsm_compute_tc(sig.frame_number);
3335 log("SI received at TC=", tc, ": ", sig.si);
3336 /* append to the per-TC bucket */
3337 si_per_tc[tc] := si_per_tc[tc] & { sig };
3338 repeat;
3339 }
3340 [] pt.receive { repeat; }
3341 [] T.timeout { }
3342 }
3343
3344 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3345 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3346 }
3347 log("si_per_tc=", si_per_tc);
3348 return si_per_tc;
3349}
3350
3351/* helper function: Set given SI via RSL + validate scheduling.
3352 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3353function f_TC_si_sched() runs on test_CT {
3354 var SystemInformationVectorPerTc si_per_tc;
3355 f_init_l1ctl();
3356 f_l1_tune(L1CTL);
3357
3358 /* Sample + Validate Scheduling */
3359 si_per_tc := f_l1_sample_si(L1CTL);
3360 f_validate_si_scheduling(si_cfg, si_per_tc);
3361
3362 setverdict(pass);
3363}
3364
3365testcase TC_si_sched_default() runs on test_CT {
3366 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003367 /* 2+3+4 are mandatory and set in f_init() */
3368 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003370}
3371
3372testcase TC_si_sched_1() runs on test_CT {
3373 f_init();
3374 si_cfg.si1_present := true;
3375 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003376 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003378}
3379
3380testcase TC_si_sched_2bis() runs on test_CT {
3381 f_init();
3382 si_cfg.si2bis_present := true;
3383 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3384 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003386}
3387
3388testcase TC_si_sched_2ter() runs on test_CT {
3389 f_init();
3390 si_cfg.si2ter_present := true;
3391 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3392 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003394}
3395
3396testcase TC_si_sched_2ter_2bis() runs on test_CT {
3397 f_init();
3398 si_cfg.si2bis_present := true;
3399 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3400 si_cfg.si2ter_present := true;
3401 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3402 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003404}
3405
3406testcase TC_si_sched_2quater() runs on test_CT {
3407 f_init();
3408 si_cfg.si2quater_present := true;
3409 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3410 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003412}
3413
3414testcase TC_si_sched_13() runs on test_CT {
3415 f_init();
3416 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003417 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003418 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003420}
3421
3422testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3423 f_init();
3424 si_cfg.si2bis_present := true;
3425 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3426 si_cfg.si2ter_present := true;
3427 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3428 si_cfg.si2quater_present := true;
3429 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3430 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003431 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003432 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003434}
3435
3436
Harald Welte68e495b2018-02-25 00:05:57 +01003437testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003438 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003439 /* FIXME: enable / disable individual BCCH info */
3440 //ts_RSL_BCCH_INFO(si_type, info);
3441 /* expect no ERROR REPORT after either of them *
3442 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003444}
3445
Harald Welte93640c62018-02-25 16:59:33 +01003446/***********************************************************************
3447 * Low-Level Protocol Errors / ERROR REPORT
3448 ***********************************************************************/
3449
Harald Welte01d982c2018-02-25 01:31:40 +01003450private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3451 timer T := 5.0;
3452 T.start;
3453 alt {
3454 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3455 setverdict(pass);
3456 }
3457 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003459 }
3460 [] RSL_CCHAN.receive {
3461 repeat;
3462 }
3463 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003465 }
3466 }
3467}
3468
3469/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3470testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003471 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003472 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3473 rsl.ies := omit;
3474 RSL_CCHAN.send(ts_RSL_UD(rsl));
3475
3476 f_exp_err_rep(RSL_ERR_PROTO);
3477}
3478
3479/* Provoke a mandatory IE error and match on ERROR REPORT */
3480testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003481 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003482
3483 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3484 rsl.ies := { rsl.ies[0] };
3485 RSL_CCHAN.send(ts_RSL_UD(rsl));
3486
3487 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3488}
3489
3490/* Provoke an IE content error and match on ERROR REPORT */
3491testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003492 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003493 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3494 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3495 RSL_CCHAN.send(ts_RSL_UD(rsl));
3496
3497 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3498}
3499
Harald Welteee25aae2019-05-19 14:32:37 +02003500/* attempt to activate channel with wrong RSL Message Discriminator IE */
3501function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3502 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3503 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3504 RSL.send(rsl);
3505 f_rslem_unregister(0, g_chan_nr);
3506}
3507testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3508 var ConnHdlr vc_conn;
3509 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3510
Harald Welte10474062019-05-30 16:48:17 +02003511 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003512
3513 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3514 vc_conn.done;
3515 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3516
3517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3518}
3519
3520/* Send messages with wrong message type */
3521function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3522 var template (value) RSL_Message rsl_tx;
3523 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3524 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3525 RSL.send(rsl_tx);
3526 f_rslem_unregister(0, g_chan_nr);
3527}
3528function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3529 var template (value) RSL_Message rsl_tx;
3530 /* we first have to activate the dedicated channel */
3531 f_rsl_chan_act(g_pars.chan_mode);
3532 /* ... to then send an invalid RLL message */
3533 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3534 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3535 RSL.send(rsl_tx);
3536 f_rslem_unregister(0, g_chan_nr);
3537}
3538testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3539 var ConnHdlr vc_conn;
3540 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3541 var template (value) RSL_Message rsl_tx;
3542
Harald Welte10474062019-05-30 16:48:17 +02003543 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003544
3545 /* Common Channel with wrong message type */
3546 RSL_CCHAN.clear;
3547 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3548 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3549 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3550 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3551
3552 /* TRX Management */
3553 RSL_CCHAN.clear;
3554 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3555 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3556 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3557 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3558
3559 /* Dedicated Channel */
3560 RSL_CCHAN.clear;
3561 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3562 vc_conn.done;
3563 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3564
3565 /* RLL */
3566 RSL_CCHAN.clear;
3567 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3568 vc_conn.done;
3569 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3570}
3571
3572/* Send messages in wrong sequence (RLL to an inactive lchan) */
3573function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3574 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3575 f_rslem_unregister(0, g_chan_nr);
3576}
3577testcase TC_err_rep_wrong_sequence() runs on test_CT {
3578 var ConnHdlr vc_conn;
3579 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3580
Harald Welte10474062019-05-30 16:48:17 +02003581 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003582
3583 RSL_CCHAN.clear;
3584 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3585 vc_conn.done;
3586 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3587}
3588
Harald Welte93640c62018-02-25 16:59:33 +01003589/***********************************************************************
3590 * IPA CRCX/MDCX/DLCS media stream handling
3591 ***********************************************************************/
3592
Harald Weltea871a382018-02-25 02:03:14 +01003593/* Send IPA DLCX to inactive lchan */
3594function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003595 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3596 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003597}
3598testcase TC_ipa_dlcx_not_active() runs on test_CT {
3599 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003600 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003601 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3602 vc_conn.done;
3603}
Harald Welte68e495b2018-02-25 00:05:57 +01003604
Harald Weltea3f1df92018-02-25 12:49:55 +01003605/* Send IPA CRCX twice to inactive lchan */
3606function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3607 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3608 "IPA CRCX ACK");
3609 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3610 "IPA CRCX NACK");
3611}
3612testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3613 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003614 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003615 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3616 vc_conn.done;
3617}
3618
3619/* Regular sequence of CRCX/MDCX/DLCX */
3620function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3621 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3622 "IPA CRCX ACK");
3623 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3624 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3625 var uint7_t rtp_pt2 := f_rnd_int(127);
3626 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3627 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3628 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3629 "IPA MDCX ACK");
3630 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3631 "IPA DLCX ACK");
3632}
3633testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3634 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003635 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003636 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3637 vc_conn.done;
3638}
3639
Harald Welte3ae11da2018-02-25 13:36:06 +01003640/* Sequence of CRCX, 2x MDCX, DLCX */
3641function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3642 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3643 "IPA CRCX ACK");
3644 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3645 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3646 var uint7_t rtp_pt2 := f_rnd_int(127);
3647 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3648 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3649 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3650 "IPA MDCX ACK");
3651 /* Second MDCX */
3652 remote_ip := f_rnd_int(c_UINT32_MAX);
3653 remote_port := f_rnd_int(c_UINT16_MAX);
3654 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3655 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3656 "IPA MDCX ACK");
3657 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3658 "IPA DLCX ACK");
3659}
3660testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3661 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003662 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003663 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3664 vc_conn.done;
3665}
3666
Harald Welte9912eb52018-02-25 13:30:15 +01003667/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3668function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3669 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3670 "IPA CRCX NACK");
3671}
3672testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3673 var ConnHdlrPars pars;
3674 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003675 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003676
3677 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3678 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3679 vc_conn.done;
3680
3681 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3682 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3683 vc_conn.done;
3684}
3685
Harald Weltea3f1df92018-02-25 12:49:55 +01003686
Harald Welte883340c2018-02-28 18:59:29 +01003687/***********************************************************************
3688 * PCU Socket related tests
3689 ***********************************************************************/
3690
Harald Welte07bd2d22019-05-25 11:03:30 +02003691/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003692friend 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 +01003693runs on test_CT {
3694 timer T := 3.0;
3695
3696 /* we don't expect any RTS.req before PDCH are active */
3697 T.start;
3698 alt {
3699 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003701 }
3702 [] PCU.receive { repeat; }
3703 [] T.timeout { }
3704 }
3705
3706 /* Send PDCH activate request for known PDCH timeslot */
3707 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3708
3709 /* we now expect RTS.req for this timeslot (only) */
3710 T.start;
3711 alt {
3712 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3713 setverdict(pass);
3714 }
3715 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3716 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003718 }
3719 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003721 }
3722 [] PCU.receive { repeat; }
3723 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003725 }
3726 [not exp_success] T.timeout {
3727 setverdict(pass);
3728 }
3729 }
3730}
3731
Harald Welte07bd2d22019-05-25 11:03:30 +02003732/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003733friend 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 +01003734runs on test_CT {
3735 timer T := 3.0;
3736
3737 /* Send PDCH activate request for known PDCH timeslot */
3738 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3739
3740 PCU.clear;
3741 /* we now expect no RTS.req for this timeslot */
3742 T.start;
3743 alt {
3744 [] 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 +02003745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003746 }
3747 [] PCU.receive { repeat; }
3748 [] T.timeout {
3749 setverdict(pass);
3750 }
3751 }
3752}
3753
Harald Weltead033dc2019-05-25 17:28:16 +02003754friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003755 f_init();
3756 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3757}
3758
Harald Welte883340c2018-02-28 18:59:29 +01003759/* PDCH activation via PCU socket; check for presence of RTS.req */
3760testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003761 f_init_pcu_test();
3762
Harald Welte883340c2018-02-28 18:59:29 +01003763 f_TC_pcu_act_req(0, 0, 7, true);
3764}
3765
3766/* PDCH activation via PCU socket on non-PDCU timeslot */
3767testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003768 f_init_pcu_test();
3769
Harald Welte883340c2018-02-28 18:59:29 +01003770 f_TC_pcu_act_req(0, 0, 1, false);
3771}
3772
3773/* PDCH activation via PCU socket on wrong BTS */
3774testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003775 f_init_pcu_test();
3776
Harald Welte883340c2018-02-28 18:59:29 +01003777 f_TC_pcu_act_req(23, 0, 7, false);
3778}
3779
3780/* PDCH activation via PCU socket on wrong TRX */
3781testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003782 f_init_pcu_test();
3783
Harald Welte883340c2018-02-28 18:59:29 +01003784 f_TC_pcu_act_req(0, 23, 7, false);
3785}
3786
3787/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3788testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003789 f_init_pcu_test();
3790
Harald Welte883340c2018-02-28 18:59:29 +01003791 /* Activate PDCH */
3792 f_TC_pcu_act_req(0, 0, 7, true);
3793 f_sleep(1.0);
3794 /* and De-Activate again */
3795 f_TC_pcu_deact_req(0, 0, 7);
3796}
3797
3798/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3799testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003800 f_init_pcu_test();
3801
Harald Welte883340c2018-02-28 18:59:29 +01003802 f_TC_pcu_deact_req(0, 0, 1);
3803}
3804
3805/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3806testcase TC_pcu_ver_si13() runs on test_CT {
3807 const octetstring si13 := '00010203040506070909'O;
3808 var PCUIF_send_data sd;
3809 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003810 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003811
3812 /* Set SI13 via RSL */
3813 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003814
Harald Welte883340c2018-02-28 18:59:29 +01003815 T.start;
3816 alt {
3817 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3818 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3819 setverdict(pass);
3820 } else {
3821 repeat;
3822 }
3823 }
3824 [] PCU.receive { repeat; }
3825 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003827 }
3828 }
3829}
3830
3831private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3832
3833/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003834friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003835 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3836runs on test_CT
3837{
3838 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3839 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3840}
3841
3842/* 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 +02003843friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3844 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003845runs on test_CT
3846{
3847 var PCUIF_send_data sd;
3848
3849 timer T := 3.0;
3850 T.start;
3851 alt {
3852 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3853 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3854 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3855 sd.data.u.rts_req.fn, sapi, data);
3856 }
3857 [] PCU.receive { repeat; }
3858 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003860 }
3861 }
3862}
3863
3864/* Send DATA.req on invalid BTS */
3865testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003866 var TfiUsfArr tua := f_TfiUsfArrInit();
3867 var octetstring data := '0000'O & f_rnd_octstring(21);
3868
3869 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003870
Harald Welte883340c2018-02-28 18:59:29 +01003871 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003872 f_TfiUsfArrSet(tua, 7, 0);
3873 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3874 f_sleep(1.0);
3875
3876 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003877}
3878
3879/* Send DATA.req on invalid TRX */
3880testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003881 var TfiUsfArr tua := f_TfiUsfArrInit();
3882 var octetstring data := '0000'O & f_rnd_octstring(21);
3883
3884 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003885
Harald Welte883340c2018-02-28 18:59:29 +01003886 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003887 f_TfiUsfArrSet(tua, 7, 0);
3888 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3889 f_sleep(1.0);
3890
3891 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003892}
3893
3894/* Send DATA.req on invalid timeslot */
3895testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003896 var TfiUsfArr tua := f_TfiUsfArrInit();
3897 var octetstring data := '0000'O & f_rnd_octstring(21);
3898
3899 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003900
Harald Welte883340c2018-02-28 18:59:29 +01003901 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003902 f_TfiUsfArrSet(tua, 7, 0);
3903 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3904 f_sleep(1.0);
3905
3906 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003907}
3908
3909/* Send DATA.req on timeslot that hasn't been activated */
3910testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003911 var TfiUsfArr tua := f_TfiUsfArrInit();
3912 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003913
Harald Welte7162a612019-05-26 12:56:09 +02003914 f_virtphy_common();
3915
3916 f_TfiUsfArrSet(tua, 7, 0);
3917 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3918 f_sleep(1.0);
3919
3920 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003921}
3922
Harald Weltead033dc2019-05-25 17:28:16 +02003923private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003924 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3925 boolean wait_rts := true)
3926runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003927 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003928 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003929
3930 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003931 if (wait_rts) {
3932 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3933 } else {
3934 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3935 }
Harald Weltead033dc2019-05-25 17:28:16 +02003936
3937 T.start;
3938 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003939 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003940 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3941 setverdict(pass);
3942 }
Harald Welte7162a612019-05-26 12:56:09 +02003943 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3944 setverdict(fail, "Received unexpected ", rx_dl);
3945 }
Harald Weltead033dc2019-05-25 17:28:16 +02003946 [] L1CTL.receive {
3947 repeat;
3948 }
Harald Welte7162a612019-05-26 12:56:09 +02003949 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003950 setverdict(fail, "Timeout waiting for ", data);
3951 }
Harald Welte7162a612019-05-26 12:56:09 +02003952 [not expect_data] T.timeout {
3953 setverdict(pass);
3954 }
Harald Weltead033dc2019-05-25 17:28:16 +02003955 }
3956}
3957
3958private function f_disable_dynamic_ts() runs on test_CT
3959{
3960 f_init_vty_bsc();
3961 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3962 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3963 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3964 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003965 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003966}
3967
3968private function f_virtphy_common() runs on test_CT {
3969 f_disable_dynamic_ts();
3970 f_init_l1ctl();
3971 f_l1_tune(L1CTL);
3972}
3973
3974testcase TC_pcu_data_req_pdtch() runs on test_CT {
3975 var TfiUsfArr tua := f_TfiUsfArrInit();
3976 var octetstring data := '0000'O & f_rnd_octstring(21);
3977
3978 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003979
Harald Welte883340c2018-02-28 18:59:29 +01003980 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003981 f_TfiUsfArrSet(tua, 7, 0);
3982 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3983 f_sleep(1.0);
3984
3985 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003986}
3987
3988testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003989 var TfiUsfArr tua := f_TfiUsfArrInit();
3990 var octetstring data := '0000'O & f_rnd_octstring(21);
3991
3992 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003993
Harald Welte883340c2018-02-28 18:59:29 +01003994 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003995 f_TfiUsfArrSet(tua, 7, 0);
3996 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3997 f_sleep(1.0);
3998
3999 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004000}
4001
4002/* Send AGCH from PCU; check it appears on Um side */
4003testcase TC_pcu_data_req_agch() runs on test_CT {
4004 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004005 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004006 f_init_l1ctl();
4007 f_l1_tune(L1CTL);
4008
4009 f_TC_pcu_act_req(0, 0, 7, true);
4010 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4011
4012 T.start;
4013 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004014 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004015 setverdict(pass);
4016 }
4017 [] L1CTL.receive { repeat; }
4018 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004020 }
4021 }
4022}
4023
Harald Welte928622b2019-05-26 13:22:59 +02004024/* Send AGCH from PCU; check it appears on Um side */
4025testcase TC_pcu_data_req_pch() runs on test_CT {
4026 timer T := 3.0;
4027 f_init_pcu_test();
4028 f_init_l1ctl();
4029 f_l1_tune(L1CTL);
4030
4031 f_TC_pcu_act_req(0, 0, 7, true);
4032 /* three characters prefix: last 3 digits of IMSI as ASCII */
4033 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4034
4035 T.start;
4036 alt {
4037 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4038 setverdict(pass);
4039 }
4040 [] L1CTL.receive { repeat; }
4041 [] T.timeout {
4042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4043 }
4044 }
4045}
4046
Harald Welte883340c2018-02-28 18:59:29 +01004047/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4048testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4049 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004050 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004051 f_init_l1ctl();
4052 f_l1_tune(L1CTL);
4053
4054 /* append 3 last imsi digits so BTS can compute pagng group */
4055 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4056
4057 timer T := 0.5;
4058 T.start;
4059 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004060 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004061 /* TODO: verify paging group */
4062 setverdict(pass);
4063 }
4064 [] L1CTL.receive { repeat; }
4065 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004067 }
4068 }
4069}
4070
4071/* Send RACH from Um side, expect it to show up on PCU socket */
4072testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004073 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004074 f_init_l1ctl();
4075 f_l1_tune(L1CTL);
4076
4077 var GsmFrameNumber fn_last := 0;
4078 for (var integer i := 0; i < 1000; i := i+1) {
4079 var OCT1 ra := f_rnd_ra_ps();
4080 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4081 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004083 }
4084 fn_last := fn;
4085
4086 timer T := 2.0;
4087 T.start;
4088 alt {
4089 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
4090 T.stop;
4091 }
4092 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004094 }
4095 [] PCU.receive { repeat; }
4096 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004098 }
4099 }
4100 }
4101 setverdict(pass);
4102}
4103
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004104/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4105 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4106testcase TC_pcu_ext_rach_content() runs on test_CT {
4107 var template PCUIF_Message pcu_rach_ind;
4108 var GsmFrameNumber fn_last := 0;
4109 var L1ctlRachSynchSeq synch_seq;
4110 var PCUIF_BurstType pcu_bt;
4111 var GsmFrameNumber fn;
4112 var BIT11 ra11;
4113
4114 f_init_pcu_test();
4115 f_init_l1ctl();
4116 f_l1_tune(L1CTL);
4117
4118 for (var integer i := 0; i < 1000; i := i+1) {
4119 /* We need to test both TS1 & TS2 */
4120 if (i rem 2 == 0) {
4121 synch_seq := RACH_SYNCH_SEQ_TS1;
4122 pcu_bt := BURST_TYPE_1;
4123 } else {
4124 synch_seq := RACH_SYNCH_SEQ_TS2;
4125 pcu_bt := BURST_TYPE_2;
4126 }
4127
4128 ra11 := f_rnd_ra11_ps();
4129 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4130 if (fn == fn_last) {
4131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4132 "Two RACH in same FN?!?");
4133 }
4134 fn_last := fn;
4135
4136 /* Compose the expected message */
4137 pcu_rach_ind := tr_PCUIF_RACH_IND(
4138 bts_nr := 0,
4139 ra := bit2int(ra11),
4140 is_11bit := 1,
4141 burst_type := pcu_bt,
4142 fn := fn);
4143
4144 timer T := 2.0;
4145 T.start;
4146 alt {
4147 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4148 T.stop;
4149 }
4150 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4152 }
4153 [] PCU.receive { repeat; }
4154 [] T.timeout {
4155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4156 }
4157 }
4158 }
4159 setverdict(pass);
4160}
4161
Harald Welte883340c2018-02-28 18:59:29 +01004162/* Send PAGING via RSL, expect it to shw up on PCU socket */
4163testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004164 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004165
4166 for (var integer i := 0; i < 100; i := i+1) {
4167 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
4168 timer T := 3.0;
4169 if (i < 50) {
4170 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
4171 } else {
4172 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
4173 }
4174 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
4175 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
4176 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
4177
4178 /* Send RSL PAGING COMMAND */
4179 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
4180 T.start;
4181 alt {
4182 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
4183 }
4184 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004186 }
4187 [] PCU.receive { repeat; }
4188 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004190 }
4191 }
4192 }
4193 setverdict(pass);
4194}
4195
Harald Welted66c9b82019-05-25 09:03:15 +02004196/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4197testcase TC_pcu_time_ind() runs on test_CT {
4198 var PCUIF_send_data pcu_sd;
4199 var integer num_time_ind := 0;
4200 var integer first_fn, last_fn;
4201 var float test_duration := 5.0;
4202 timer T;
4203
4204 f_init_pcu_test();
4205 f_TC_pcu_act_req(0, 0, 7, true);
4206
4207 PCU.clear;
4208 T.start(test_duration);
4209 alt {
4210 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4211 num_time_ind := num_time_ind + 1;
4212 if (not isbound(first_fn)) {
4213 first_fn := pcu_sd.data.u.time_ind.fn;
4214 }
4215 last_fn := pcu_sd.data.u.time_ind.fn;
4216 repeat;
4217 }
4218 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4219 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4220 repeat;
4221 }
4222 [] PCU.receive {
4223 repeat;
4224 }
4225 [] T.timeout {}
4226 }
4227 var integer fn_expired := last_fn - first_fn;
4228 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4229
4230 /* verify the number of frames expired matches our expectation */
4231 const float c_GSM_FN_DURATION_MS := 4.61538;
4232 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004233 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004234 if (not match(fn_expired, t_fn_expected)) {
4235 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4236 }
4237
4238 /* There are three TIME.ind in every fn MOD 13 */
4239 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4240 /* Add some tolerance */
4241 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4242 if (not match(num_time_ind, t_time_ind_exp)) {
4243 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4244 }
4245
4246 setverdict(pass);
4247}
4248
Harald Welte4832c862019-05-25 14:57:18 +02004249/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4250testcase TC_pcu_rts_req() runs on test_CT {
4251 var PCUIF_send_data pcu_sd;
4252 var integer first_fn, last_fn;
4253 var integer num_rts_pdtch := 0;
4254 var integer num_rts_ptcch := 0;
4255 var float test_duration := 5.0;
4256 timer T;
4257
4258 f_init_pcu_test();
4259 f_TC_pcu_act_req(0, 0, 7, true);
4260
4261 PCU.clear;
4262 T.start(test_duration);
4263 alt {
4264 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4265 -> value pcu_sd {
4266 num_rts_pdtch := num_rts_pdtch + 1;
4267 if (not isbound(first_fn)) {
4268 first_fn := pcu_sd.data.u.rts_req.fn;
4269 }
4270 last_fn := pcu_sd.data.u.rts_req.fn;
4271 repeat;
4272 }
4273 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4274 -> value pcu_sd {
4275 num_rts_ptcch := num_rts_ptcch + 1;
4276 if (not isbound(first_fn)) {
4277 first_fn := pcu_sd.data.u.rts_req.fn;
4278 }
4279 last_fn := pcu_sd.data.u.rts_req.fn;
4280 repeat;
4281 }
4282 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4283 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4284 repeat;
4285 }
4286 [] PCU.receive {
4287 repeat;
4288 }
4289 [] T.timeout {}
4290 }
4291 var integer fn_expired := last_fn - first_fn;
4292 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4293 ", num_rts_ptcch=", num_rts_ptcch);
4294
4295 /* verify the number of frames expired matches our expectation */
4296 const float c_GSM_FN_DURATION_MS := 4.61538;
4297 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004298 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004299 if (not match(fn_expired, t_fn_expected)) {
4300 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4301 }
4302
4303 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4304 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4305 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4306 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4307 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4308 t_ptcch_exp);
4309 }
4310
4311 /* We have 12 PDTCH blocks every 52-multiframe */
4312 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4313 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4314 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4315 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4316 t_pdtch_exp);
4317 }
4318
4319 setverdict(pass);
4320}
4321
Harald Welte07bd2d22019-05-25 11:03:30 +02004322/* test for generating Abis side OML ALERT from the PCU */
4323testcase TC_pcu_oml_alert() runs on test_CT {
4324 var PCUIF_send_data pcu_sd;
4325 var integer num_time_ind := 0;
4326 var integer first_fn, last_fn;
4327 var float test_duration := 5.0;
4328 timer T;
4329
4330 f_init_pcu_test();
4331 f_TC_pcu_act_req(0, 0, 7, true);
4332
4333 /* re-connect CTRL port from BTS to BSC */
4334 f_ipa_ctrl_stop();
4335 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4336
4337 /* Send that OML Alert */
4338 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4339
4340 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4341 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4342 setverdict(pass);
4343}
4344
Harald Welteeaa9a862019-05-26 23:01:08 +02004345template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4346 template (value) RoutingAreaIdentificationV rai,
4347 template (value) OCT1 cause) := {
4348 discriminator := '0000'B, /* overwritten */
4349 tiOrSkip := {
4350 skipIndicator := '0000'B
4351 },
4352 msgs := {
4353 rrm := {
4354 gPRS_suspensionRequest := {
4355 messageType := '00110100'B,
4356 tLLI := tlli,
4357 routingAreaIdentification := rai,
4358 suspensionCause := cause,
4359 service_Support := omit
4360 }
4361 }
4362 }
4363}
4364
4365/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4366private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4367 var PCUIF_Message first_info;
4368 var integer pcu_conn_id := -1;
4369 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4370 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4371 var OCT4 tlli := '01020304'O;
4372 var OCT1 cause := '23'O;
4373 timer T := 5.0;
4374
4375 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4376
4377 f_l1_tune(L1CTL);
4378 RSL.clear;
4379
4380 f_est_dchan();
4381 L1CTL.clear;
4382
4383 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4384
4385 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4386 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4387 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4388
4389 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4390 T.start;
4391 alt {
4392 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4393 setverdict(pass);
4394 }
4395 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4396 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4397 }
4398 [] PCU.receive {
4399 repeat;
4400 }
4401 [] T.timeout {
4402 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4403 }
4404 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004405
4406 /* release the channel */
4407 f_rsl_chan_deact();
4408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4409 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004410}
4411testcase TC_pcu_rr_suspend() runs on test_CT {
4412 var ConnHdlrPars pars;
4413 var ConnHdlr vc_conn;
4414
4415 f_init();
4416
4417 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4418 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4419 vc_conn.done;
4420}
Harald Welte07bd2d22019-05-25 11:03:30 +02004421
Harald Weltea2e0e942019-05-27 18:12:53 +02004422/* Ensure that PCUIF socket can accept only a single connection */
4423testcase TC_pcu_socket_connect_multi() runs on test_CT {
4424 timer T := 5.0;
4425
4426 /* this (among other things) establishes the first connection to the PCUIF socket */
4427 f_init();
4428
4429 /* try to establish a second connection, expect it to fail */
4430 PCU.send(UD_connect:{mp_pcu_socket, -1});
4431 T.start;
4432 alt {
4433 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4434 setverdict(pass);
4435 }
4436 [] PCU.receive(UD_connect_result:?) {
4437 setverdict(fail, "Unexpected unix domain connect result");
4438 }
4439 [] T.timeout {
4440 setverdict(pass);
4441 }
4442 }
4443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4444}
4445
Harald Weltec8effb72019-05-27 18:23:04 +02004446/* Ensure that PCUIF socket can disconnect + reconnect */
4447testcase TC_pcu_socket_reconnect() runs on test_CT {
4448 /* this (among other things) establishes the first connection to the PCUIF socket */
4449 f_init();
4450
4451 f_sleep(1.0);
4452
4453 f_pcuif_close(PCU, g_pcu_conn_id);
4454 g_pcu_conn_id := -1;
4455
4456 f_sleep(1.0);
4457
4458 /* re-connect */
4459 PCU.clear;
4460 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4461 setverdict(pass);
4462
4463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4464}
4465
Harald Weltebe030482019-05-27 22:29:35 +02004466/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4467private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4468 var L1ctlDlMessage l1_dl;
4469 var SystemInformation si;
4470 timer T := 5.0;
4471 T.start;
4472 alt {
4473 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4474 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4475 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4476 log("Ignoring non-RR SI ", l1_dl);
4477 repeat;
4478 }
4479 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4480 if (not ischosen(si.payload.si3)) {
4481 repeat;
4482 }
4483 }
4484 [] pt.receive {
4485 repeat;
4486 }
4487 [] T.timeout {
4488 setverdict(fail, "Timeout waiting for SI3");
4489 }
4490 }
4491 return si.payload.si3;
4492}
4493
4494/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4495private function f_bitpos_is_inv(integer idx) return boolean {
4496 select (idx mod 8) {
4497 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4498 case else { return false; } /* 0-bits of 0x2B */
4499 }
4500}
4501/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4502private function f_bit_is_high(bitstring str, integer idx) return boolean {
4503 var boolean invert := f_bitpos_is_inv(idx);
4504 if (invert) {
4505 if (str[idx] == '1'B) {
4506 return false;
4507 } else {
4508 return true;
4509 }
4510 } else {
4511 if (str[idx] == '1'B) {
4512 return true;
4513 } else {
4514 return false;
4515 }
4516 }
4517}
4518/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4519 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4520 we can replace this piece of code soon ... */
4521private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4522 var bitstring bits := oct2bit(si3_restoctets);
4523 var integer idx := 0;
4524
4525 if (f_bit_is_high(bits, idx)) {
4526 /* skip Optional selection parameters */
4527 idx := idx + 16;
4528 } else {
4529 idx := idx + 1;
4530 }
4531
4532 if (f_bit_is_high(bits, idx)) {
4533 /* skip Optional power offset */
4534 idx := idx + 3;
4535 } else {
4536 idx := idx + 1;
4537 }
4538
4539 /* skip SI2ter Indicator */
4540 idx := idx + 1;
4541
4542 /* skip Early CM Sending Control */
4543 idx := idx + 1;
4544
4545 /* skip Scheduling if and where */
4546 if (f_bit_is_high(bits, idx)) {
4547 idx := idx + 4;
4548 } else {
4549 idx := idx + 1;
4550 }
4551
4552 return f_bit_is_high(bits, idx);
4553}
4554
4555testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4556 var SystemInformationType3 si3;
4557 timer T := 5.0;
4558
4559 /* don't call f_init() as this would connect PCU socket */
4560 f_init_rsl(testcasename());
4561 T.start;
4562 alt {
4563 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4564 [] T.timeout {
4565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4566 }
4567 }
4568 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4569
4570 f_init_l1ctl();
4571 f_l1_tune(L1CTL);
4572
4573 f_sleep(2.0);
4574 L1CTL.clear;
4575 si3 := f_get_si3(L1CTL);
4576 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4577 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4578 } else {
4579 setverdict(pass);
4580 }
4581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4582}
4583
4584/* Ensure that GPRS capability is advertised after PCU socket connect */
4585testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4586 var SystemInformationType3 si3;
4587
4588 /* this (among other things) establishes the first connection to the PCUIF socket */
4589 f_init();
4590 f_init_l1ctl();
4591 f_l1_tune(L1CTL);
4592
4593 f_sleep(2.0);
4594 L1CTL.clear;
4595 si3 := f_get_si3(L1CTL);
4596 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4597 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4598 } else {
4599 setverdict(pass);
4600 }
4601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4602}
4603
4604/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4605testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4606 var SystemInformationType3 si3;
4607
4608 /* this (among other things) establishes the first connection to the PCUIF socket */
4609 f_init();
4610 f_init_l1ctl();
4611 f_l1_tune(L1CTL);
4612
4613 f_pcuif_close(PCU, g_pcu_conn_id);
4614 g_pcu_conn_id := -1;
4615
4616 f_sleep(1.0);
4617
4618 /* re-connect */
4619 PCU.clear;
4620 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4621
4622 f_sleep(2.0);
4623 L1CTL.clear;
4624 si3 := f_get_si3(L1CTL);
4625 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4626 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4627 } else {
4628 setverdict(pass);
4629 }
4630
4631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4632}
4633
Harald Welted66c9b82019-05-25 09:03:15 +02004634
Harald Welte3d04ae62018-04-04 20:29:05 +02004635/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004636 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004637 ***********************************************************************/
4638
4639private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4640runs on ConnHdlr {
4641 var PCUIF_send_data sd;
4642 /* Expect BTS to immediately acknowledge activation as PDCH */
4643 PCU.clear;
4644 f_rsl_chan_act(g_pars.chan_mode);
4645 /* expect INFO_IND on PCU interface listing TS as PDCH */
4646 alt {
4647 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4648 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 +02004649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004650 }
4651 }
4652 [] PCU.receive { repeat; }
4653 }
4654 /* try to activate this PDCH from the PCU point of view */
4655 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4656 /* FIXME: is there a response? */
4657}
4658
4659private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4660runs on ConnHdlr {
4661 var PCUIF_send_data sd;
4662 /* Send RSL CHAN REL (deactivate) */
4663 PCU.clear;
4664 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4665 /* expect BTS to ask PCU to deactivate the channel */
4666 alt {
4667 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4668 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 +02004669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004670 }
4671 }
4672 [] PCU.receive { repeat; }
4673 }
4674 /* Emulate PCU asking BTS to deactivate PDCH */
4675 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4676 alt {
4677 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4678 setverdict(pass);
4679 }
4680 [] RSL.receive { repeat; }
4681 }
4682}
4683
4684/* Activate Osmocom-style dynamic PDCH from BSC side */
4685function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4686 var PCUIF_Message first_info;
4687 var integer ts_nr := g_chan_nr.tn;
4688 var integer trx_nr := 0;
4689 var integer bts_nr := 0;
4690 var integer pcu_conn_id := -1;
4691
4692 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4693
4694 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4695 f_sleep(3.0);
4696 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4697 setverdict(pass);
4698}
4699testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4700 var ConnHdlrPars pars;
4701 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004702 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004703
4704 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4705 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4706 vc_conn.done;
4707}
4708
4709/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4710function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4711 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004712 var integer pcu_conn_id := -1;
4713
4714 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4715
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004716 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4717 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4718 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004719 setverdict(pass);
4720}
4721testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4722 var ConnHdlrPars pars;
4723 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004724 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004725
4726 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4727 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4728 vc_conn.done;
4729}
4730
4731/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4732function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4733 var PCUIF_Message first_info;
4734 var integer ts_nr := g_chan_nr.tn;
4735 var integer trx_nr := 0;
4736 var integer bts_nr := 0;
4737 var integer pcu_conn_id := -1;
4738
4739 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4740
4741 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004742 /* Send a second Chan Activ and expect it to be NACKed */
4743 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4744 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004745 setverdict(pass);
4746}
4747testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4748 var ConnHdlrPars pars;
4749 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004750 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004751
4752 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4753 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4754 vc_conn.done;
4755}
4756
4757/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4758function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4759 var PCUIF_Message first_info;
4760 var integer ts_nr := g_chan_nr.tn;
4761 var integer trx_nr := 0;
4762 var integer bts_nr := 0;
4763 var integer pcu_conn_id := -1;
4764 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4765
4766 /* register for the TCH/F channel number */
4767 f_rslem_register(0, chan_nr);
4768
4769 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4770
4771 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4772 "RSL CHAN ACT");
4773 setverdict(pass);
4774}
4775testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4776 var ConnHdlrPars pars;
4777 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004778 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004779
4780 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4781 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4782 vc_conn.done;
4783}
4784
4785/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4786function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4787 var PCUIF_Message first_info;
4788 var integer ts_nr := g_chan_nr.tn;
4789 var integer trx_nr := 0;
4790 var integer bts_nr := 0;
4791 var integer pcu_conn_id := -1;
4792 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4793 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4794
4795 /* register for the TCH/H channel numbers */
4796 f_rslem_register(0, chan_nr[0]);
4797 f_rslem_register(0, chan_nr[1]);
4798
4799 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4800
4801 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4802 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4803 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4804 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4805 setverdict(pass);
4806}
4807testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4808 var ConnHdlrPars pars;
4809 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004810 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004811
4812 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4813 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4814 vc_conn.done;
4815}
4816
Harald Welte9bbbfb52018-04-05 09:33:19 +02004817/***********************************************************************
4818 * IPA Style Dynamic Timeslot Support
4819 ***********************************************************************/
4820
4821private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4822runs on ConnHdlr {
4823 var PCUIF_send_data sd;
4824 /* Expect BTS to immediately acknowledge activation as PDCH */
4825 PCU.clear;
4826 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4827 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004828 timer T_wait := 2.0;
4829 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004830 alt {
4831 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4832 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 +01004833 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4834 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4835 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004836 }
4837 }
4838 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004839 [] T_wait.timeout {
4840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4841 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4842 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004843 }
4844 /* try to activate this PDCH from the PCU point of view */
4845 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4846 /* FIXME: is there a response? */
4847
4848 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4849}
4850
4851private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4852runs on ConnHdlr {
4853 var PCUIF_send_data sd;
4854 /* Send RSL CHAN REL (deactivate) */
4855 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4856 PCU.clear;
4857 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004858 timer T_wait := 2.0;
4859 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004860 alt {
4861 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4862 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 +01004863 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4864 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4865 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004866 }
4867 }
4868 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004869 [] T_wait.timeout {
4870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4871 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4872 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004873 }
4874 /* Emulate PCU asking BTS to deactivate PDCH */
4875 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4876 alt {
4877 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4878 setverdict(pass);
4879 }
4880 [] RSL.receive { repeat; }
4881 }
4882}
4883
4884/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4885function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4886 var PCUIF_Message first_info;
4887 var integer ts_nr := g_chan_nr.tn;
4888 var integer trx_nr := 0;
4889 var integer bts_nr := 0;
4890 var integer pcu_conn_id := -1;
4891
4892 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4893
4894 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4895 f_sleep(3.0);
4896 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4897
4898 setverdict(pass);
4899
4900}
4901testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4902 var ConnHdlrPars pars;
4903 var ConnHdlr vc_conn;
4904 f_init();
4905
4906 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4907 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4908 vc_conn.done;
4909}
4910
4911/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4912function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4913 var PCUIF_Message first_info;
4914 var integer ts_nr := g_chan_nr.tn;
4915 var integer trx_nr := 0;
4916 var integer bts_nr := 0;
4917 var integer pcu_conn_id := -1;
4918
4919 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4920
4921 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4922 "RSL CHAN ACT");
4923 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4924 "RF CHAN REL", true);
4925 setverdict(pass);
4926}
4927testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4928 var ConnHdlrPars pars;
4929 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004930 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004931
4932 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4933 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4934 vc_conn.done;
4935}
4936
4937/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4938function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4939 var PCUIF_Message first_info;
4940 var integer ts_nr := g_chan_nr.tn;
4941 var integer trx_nr := 0;
4942 var integer bts_nr := 0;
4943 var integer pcu_conn_id := -1;
4944
4945 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4946
4947 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4948 "RSL CHAN ACT");
4949
4950 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4951 alt {
4952 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4953 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004955 }
4956 [] RSL.receive { repeat; }
4957 }
4958
4959 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4960 "RF CHAN REL", true);
4961 setverdict(pass);
4962}
4963testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4964 var ConnHdlrPars pars;
4965 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004966 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004967
4968 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4969 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4970 vc_conn.done;
4971}
4972
4973/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4974function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4975 var PCUIF_Message first_info;
4976 var integer ts_nr := g_chan_nr.tn;
4977 var integer trx_nr := 0;
4978 var integer bts_nr := 0;
4979 var integer pcu_conn_id := -1;
4980
4981 /* register for the TCH/F channel number */
4982 f_rslem_register(0, g_chan_nr);
4983
4984 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4985
4986 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4987
4988 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4989 "RSL CHAN ACT");
4990
4991 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4992
4993 setverdict(pass);
4994}
4995testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4996 var ConnHdlrPars pars;
4997 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004998 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004999
5000 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5001 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5002 vc_conn.done;
5003}
5004
5005
Harald Welte0472ab42018-03-12 15:02:26 +01005006/***********************************************************************
5007 * LAPDm / RLL related
5008 ***********************************************************************/
5009
5010private function f_tx_lapdm(template (value) LapdmFrame l,
5011 template (value) RslLinkId link_id) runs on ConnHdlr {
5012 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005013 var template (value) SacchL1Header l1h;
5014
5015 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005016 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005017 /* Compose dummy L1 header */
5018 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5019 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 +02005020 } else {
5021 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005022 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 +01005023 }
Harald Welte0472ab42018-03-12 15:02:26 +01005024}
5025
5026type record RllTestCase {
5027 uint3_t sapi,
5028 RslLinkId link_id,
5029 octetstring l3,
5030 boolean exp
5031}
5032type record of RllTestCase RllTestCases;
5033template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5034 sapi := sapi,
5035 link_id := id,
5036 l3 := l3,
5037 exp := exp
5038}
5039
5040/* execute the same callback function with a set of different parameters (tcs) on a
5041 * variety of logical channels */
5042private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5043 var ConnHdlrPars pars;
5044 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005045 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005046
5047 /* test on each of the channels we have */
5048 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5049 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5050
5051 /* test each of the test cases on the current channel */
5052 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5053 pars.spec.rll := tcs[j];
5054 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5055 vc_conn := f_start_handler(fn, pars);
5056 vc_conn.done;
5057 }
5058 }
5059
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005061}
5062
5063/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5064private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5065 var RllTestCase tc := g_pars.spec.rll;
5066 timer T := 3.0;
5067
5068 f_l1_tune(L1CTL);
5069 RSL.clear;
5070
5071 /* activate the logical channel */
5072 f_est_dchan();
5073 L1CTL.clear;
5074
5075 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5076 T.start;
5077 alt {
5078 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5079 if (tc.exp) {
5080 setverdict(pass);
5081 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005083 }
5084 }
5085 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5086 if (tc.exp) {
5087 setverdict(pass);
5088 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005090 }
5091 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005092 /* We also expect to receive the measurements */
5093 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005094 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005096 }
5097 [not tc.exp] T.timeout {
5098 setverdict(pass);
5099 }
5100 }
5101
5102 f_rsl_chan_deact();
5103 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5104 f_rslem_unregister(0, g_chan_nr);
5105}
5106testcase TC_rll_est_ind() runs on test_CT {
5107 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005108 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005109 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005110 /* normal SAPI0 establishment */
5111 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005112 /* SAPI 3 doesn't support contention resolution */
5113 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5114 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5115 /* normal SAPI3 establishment on main DCCH */
5116 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5117 /* normal SAPI3 establishment on SACCH */
5118 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5119 };
5120 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5121}
5122
5123/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5124private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5125 var RllTestCase tc := g_pars.spec.rll;
5126 var L1ctlDlMessage dl;
5127 timer T := 3.0;
5128
5129 f_l1_tune(L1CTL);
5130 RSL.clear;
5131
5132 /* activate the logical channel */
5133 f_est_dchan();
5134 L1CTL.clear;
5135
5136 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5137 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5138 T.start;
5139 alt {
5140 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5141 var LapdmFrame lapdm;
5142 var octetstring l2 := dl.payload.data_ind.payload;
5143 if (dl.dl_info.link_id.c == SACCH) {
5144 /* remove L1 header */
5145 l2 := substr(l2, 2, lengthof(l2)-2);
5146 }
5147 lapdm.ab := dec_LapdmFrameAB(l2);
5148 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5149 setverdict(pass);
5150 } else {
5151 repeat;
5152 }
5153 }
5154 [] L1CTL.receive { repeat; }
5155 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005157 }
5158 }
5159
5160 f_rsl_chan_deact();
5161 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5162 f_rslem_unregister(0, g_chan_nr);
5163}
5164testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5165 var RllTestCases tcs := {
5166 /* normal SAPI3 establishment on main DCCH */
5167 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5168 };
5169 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5170}
5171testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5172 var RllTestCases tcs := {
5173 /* normal SAPI3 establishment on SACCH */
5174 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5175 }
5176 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5177}
5178
5179/* altstep to receive a LAPDm frame matching the given template */
5180private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5181 var L1ctlDlMessage dl;
5182 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5183 var LapdmFrame lapdm;
5184 var octetstring l2 := dl.payload.data_ind.payload;
5185 if (dl.dl_info.link_id.c == SACCH) {
5186 /* remove L1 header */
5187 l2 := substr(l2, 2, lengthof(l2)-2);
5188 }
5189 if (ischosen(exp.ab)) {
5190 lapdm.ab := dec_LapdmFrameAB(l2);
5191 } else if (ischosen(exp.b4)) {
5192 lapdm.b4 := dec_LapdmFrameB4(l2);
5193 } else if (ischosen(exp.bbis)) {
5194 lapdm.bbis := dec_LapdmFrameBbis(l2);
5195 }
5196 log("Rx LAPDm ", lapdm);
5197 if (match(lapdm, exp)) {
5198 setverdict(pass);
5199 } else {
5200 repeat;
5201 }
5202 }
5203 [] L1CTL.receive { repeat; }
5204}
5205private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5206 timer T := t;
5207 T.start;
5208 alt {
5209 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005211 }
5212 [] as_l1_exp_lapdm(exp);
5213 }
5214}
5215
5216/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5217private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5218 /* send SABM from MS -> BTS */
5219 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5220 /* expect RLL EST IND on Abis */
5221 alt {
5222 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5223 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5224 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005226 }
5227 [] RSL.receive { repeat; }
5228 }
5229 /* expect UA from BTS -> MS */
5230 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5231}
5232
5233/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5234private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5235 var RllTestCase tc := g_pars.spec.rll;
5236
5237 f_l1_tune(L1CTL);
5238 RSL.clear;
5239
5240 /* activate the logical channel */
5241 f_est_dchan();
5242 L1CTL.clear;
5243
5244 /* first establish the link-layer */
5245 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5246
5247 /* then send the DISC */
5248 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5249 /* ... and expect the REL IND on the RSL side */
5250 alt {
5251 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5252 setverdict(pass);
5253 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005254 /* We also expect to receive the measurements */
5255 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005256 }
5257
5258 /* release the channel */
5259 f_rsl_chan_deact();
5260 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5261 f_rslem_unregister(0, g_chan_nr);
5262}
5263testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5264 var RllTestCases tcs := {
5265 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5266 };
5267 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5268}
5269
5270testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5271 var RllTestCases tcs := {
5272 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5273 };
5274 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5275}
5276testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5277 var RllTestCases tcs := {
5278 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5279 };
5280 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5281}
5282testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5283 var RllTestCases tcs := {
5284 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5285 };
5286 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5287}
5288
5289/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5290private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5291 var RllTestCase tc := g_pars.spec.rll;
5292 f_l1_tune(L1CTL);
5293 RSL.clear;
5294
5295 /* activate the logical channel */
5296 f_est_dchan();
5297 L1CTL.clear;
5298
5299 /* first establish the link-layer */
5300 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5301
5302 /* then send the REL REQ via RSL */
5303 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5304 /* ... and expect the DISC on the Um side */
5305 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005306 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005307 /* FIXME: send a UA in resposne to the DISC */
5308 }
5309 }
5310
5311 /* release the channel */
5312 f_rsl_chan_deact();
5313 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5314 f_rslem_unregister(0, g_chan_nr);
5315}
5316testcase TC_rll_rel_req() runs on test_CT {
5317 var RllTestCases tcs := {
5318 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5319 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5320 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5321 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5322 };
5323 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5324}
5325
5326/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5327testcase TC_rll_data_req() runs on test_CT {
5328}
5329
5330/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5331testcase TC_rll_data_ind() runs on test_CT {
5332}
5333
5334/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5335private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5336 var RllTestCase tc := g_pars.spec.rll;
5337
5338 f_l1_tune(L1CTL);
5339 RSL.clear;
5340
5341 f_est_dchan();
5342 L1CTL.clear;
5343
5344 /* Send UNITDATA REQ on RSL side */
5345 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5346 /* Expect it to arrive on the other side */
5347 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005348 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005349 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005350 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005351 }
5352
5353 /* release the channel */
5354 f_rsl_chan_deact();
5355 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5356 f_rslem_unregister(0, g_chan_nr);
5357}
5358testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5359 var octetstring l3 := f_rnd_octstring(15);
5360 var RllTestCases tcs := {
5361 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5362 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5363 };
5364 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5365}
5366testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5367 var octetstring l3 := f_rnd_octstring(19);
5368 var RllTestCases tcs := {
5369 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5370 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5371 };
5372 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5373}
5374
5375/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5376private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5377 var RllTestCase tc := g_pars.spec.rll;
5378
5379 f_l1_tune(L1CTL);
5380 RSL.clear;
5381
5382 f_est_dchan();
5383 L1CTL.clear;
5384
5385 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005386 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005387 /* Expdct RLL UNITDATA IND on RSL side */
5388 alt {
5389 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5390 setverdict(pass);
5391 }
5392 [] RSL.receive { repeat; }
5393 }
5394
5395 /* release the channel */
5396 f_rsl_chan_deact();
5397 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5398 f_rslem_unregister(0, g_chan_nr);
5399}
5400testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005401 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005402 var RllTestCases tcs := {
5403 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5404 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5405 };
5406 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5407}
5408testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5409 var octetstring l3 := f_rnd_octstring(18);
5410 var RllTestCases tcs := {
5411 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5412 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5413 };
5414 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5415}
5416
Harald Weltee613f962018-04-18 22:38:16 +02005417/***********************************************************************
5418 * Encryption Related
5419 ***********************************************************************/
5420
5421/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5422function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5423 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5424 if (link_id.c == SACCH) {
5425 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5426 } else {
5427 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5428 }
5429}
5430
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005431/* Expect (or not expect) other kinds of messages */
5432private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5433 [exp_any] RSL.receive { repeat; }
5434 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005436 }
5437}
5438
Harald Weltee613f962018-04-18 22:38:16 +02005439/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005440private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005441 RslLinkId link_id,
5442 octetstring l3,
5443 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005444 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005445) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005446 timer T := 3.0;
5447 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5448 T.start;
5449 /* Expect RLL UNITDATA IND on RSL side */
5450 alt {
5451 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5452 setverdict(pass);
5453 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005454 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005455 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005456 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005458 }
Harald Weltee613f962018-04-18 22:38:16 +02005459 }
5460}
5461
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005462/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5463private function f_data_mo(
5464 RslLinkId link_id,
5465 boolean p, uint3_t nr, uint3_t ns,
5466 octetstring l3,
5467 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005468 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005469) runs on ConnHdlr {
5470 timer T := 3.0;
5471 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5472 T.start;
5473 /* Expect RLL DATA IND on RSL side */
5474 alt {
5475 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5476 setverdict(pass);
5477 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005478 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005479 [] as_rsl_any_ind(exp_any);
5480 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005482 }
5483 }
5484}
5485
Harald Weltee613f962018-04-18 22:38:16 +02005486/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5487function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5488 f_l1_tune(L1CTL);
5489 f_est_dchan(true);
5490
5491 /* now we actually need to transmit some data both ways to check if the encryption works */
5492 var L1ctlDlMessage dl;
5493
Stefan Sperling603d98e2018-07-25 16:47:28 +02005494 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005495 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5496
5497 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5498 f_unitdata_mt(link_id, l3);
5499
5500 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5501 f_unitdata_mo(link_id, l3);
5502
5503 /* release the channel */
5504 f_rsl_chan_deact();
5505 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5506 f_rslem_unregister(0, g_chan_nr);
5507}
5508testcase TC_chan_act_a51() runs on test_CT {
5509 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5510 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5511 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5512}
5513testcase TC_chan_act_a52() runs on test_CT {
5514 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5515 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5516 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5517}
5518testcase TC_chan_act_a53() runs on test_CT {
5519 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5520 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5521 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5522}
5523
Eric Wildf1827a72019-05-28 17:37:35 +02005524/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5525 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5526function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5527 f_l1_tune(L1CTL);
5528 f_est_dchan(true);
5529
5530 /* now we actually need to transmit some data both ways to check if the encryption works */
5531 var L1ctlDlMessage dl;
5532
5533 var octetstring l3 := f_rnd_octstring(20);
5534 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5535
5536 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5537 f_unitdata_mt(link_id, l3);
5538
5539 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5540 f_unitdata_mo(link_id, l3);
5541
5542 var RSL_Message rsl;
5543 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5544
5545 /* modify key to break proper encryption */
5546 g_pars.encr.key := f_rnd_octstring(8);
5547 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5548 rsl.ies := rsl.ies & { ei };
5549 RSL.send(rsl);
5550
5551 timer T0 := 1.0;
5552 T0.start;
5553 /* Expect RSL MODIFY ACK */
5554 alt {
5555 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5556 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5558 }
5559 [] T0.timeout {
5560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5561 }
5562 }
5563
5564 var octetstring l3msg := f_rnd_octstring(15);
5565 timer T1 := 3.0;
5566 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5567 due to broken encryption */
5568 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5569 T1.start;
5570 alt {
5571 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5573 }
5574 [] T1.timeout {
5575 setverdict(pass);
5576 }
5577 }
5578
5579 /* release the channel */
5580 f_rsl_chan_deact();
5581 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5582 f_rslem_unregister(0, g_chan_nr);
5583}
5584testcase TC_rsl_modify_encr() runs on test_CT {
5585 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5586 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5587 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5588}
Harald Weltee613f962018-04-18 22:38:16 +02005589
5590/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5591function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5592 /* L3 payload doesn't matter, as it is passed transparently */
5593 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5594 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5595 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5596
5597 f_l1_tune(L1CTL);
5598
5599 /* first establish a dedicated channel in the clear */
5600 f_est_dchan(false);
5601
5602 /* Establish ABM */
5603 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5604
5605 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5606 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5607 /* expect the L3 to arrive still unencrypted on the MS side */
5608 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5609
5610 /* configure L1 to apply ciphering */
5611 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5612 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5613
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005614 /* send first ciphered I-frame in response and expect it on RSL */
5615 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005616
5617 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5618 * and hence enable encryption also on the downlink */
5619
5620 /* expect bi-directional communication work in encrypted mode */
5621 f_unitdata_mo(link_id, f_rnd_octstring(15));
5622 f_unitdata_mt(link_id, f_rnd_octstring(15));
5623
5624 /* release the channel */
5625 f_rsl_chan_deact();
5626 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5627 f_rslem_unregister(0, g_chan_nr);
5628}
5629testcase TC_encr_cmd_a51() runs on test_CT {
5630 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5631 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5632 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5633}
5634testcase TC_encr_cmd_a52() runs on test_CT {
5635 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5636 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5637 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5638}
5639testcase TC_encr_cmd_a53() runs on test_CT {
5640 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5641 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5642 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5643}
5644
5645private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5646 var LapdmFrame lf;
5647 var octetstring reenc;
5648
5649 /* decode the LAPDm frame */
5650 if (ischosen(exp_match.ab)) {
5651 lf.ab := dec_LapdmFrameAB(enc);
5652 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005654 }
5655
5656 /* check if decoder result matches expectation */
5657 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005659 } else {
5660 log(name, ": matched");
5661 setverdict(pass);
5662 }
5663
5664 /* test if re-encoded frame equals original input */
5665 reenc := enc_LapdmFrame(lf);
5666 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005668 } else {
5669 setverdict(pass);
5670 }
5671}
5672
5673testcase TC_lapdm_selftest() runs on test_CT {
5674 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5675 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5676 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5677 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5678 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5679 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5680 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5681}
5682
Stefan Sperling4880be42018-08-07 18:12:59 +02005683/***********************************************************************
5684 * DTX Related (see GSM 05.08, section 8.3)
5685 ***********************************************************************/
5686
5687/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5688function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5689 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5690 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5691 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5692 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5693}
5694function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5695 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5696 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5697}
5698function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5699 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5700 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5701 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5702 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5703}
5704function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5705 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5706 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5707 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5708 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5709 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5710 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5711 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5712 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5713}
5714
5715function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5716 var L1ctlDlMessage dl;
5717 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5718 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5719 var GsmFrameNumber first_fn;
5720 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005721 var integer nfill_frames_sacch := 0;
5722 var integer nfill_frames_nonsacch := 0;
5723 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005724 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5725 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005726 const integer frame_dtx_tchf_mod := 104;
5727 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5728 * which operates in terms of blocks rather than frames. */
5729 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5730 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005731 timer T := 5.0;
5732
5733 f_l1_tune(L1CTL);
5734 RSL.clear;
5735 L1CTL.clear;
5736
5737 /* activate TCHF signalling channel */
5738 f_est_dchan(false);
5739
5740 T.start;
5741 alt {
5742 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5743 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5744 var octetstring l2 := dl.payload.data_ind.payload;
5745
5746 if (is_first_frame) {
5747 is_first_frame := false;
5748 first_fn := dl.dl_info.frame_nr;
5749 }
5750
5751 if (dl.dl_info.link_id.c == SACCH) {
5752 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5753 if (not match(l2_fill_frame_sacch, l2)) {
5754 repeat;
5755 }
5756 } else if (not match(l2_fill_frame, l2)) {
5757 repeat;
5758 }
5759
5760 if (dtxd) {
5761 if (not f_g_chan_is_tchf()) {
5762 T.stop;
5763 f_rsl_chan_deact();
5764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005765 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 +02005766 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005767 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005768 T.stop;
5769 f_rsl_chan_deact();
5770 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005771
5772 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5773 * 2 SACCH, 1 TCH/F */
5774 expected_fill_frames := 3;
5775
5776 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5777 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5778 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005780 } else {
5781 setverdict(pass);
5782 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005783 } else {
5784 if (dl.dl_info.link_id.c == SACCH) {
5785 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005786 repeat;
5787 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005788 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5789 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5790 * we should only see the subset of frames numbers which correspond to a block boundary.
5791 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5792 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5793 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5794 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5795 repeat;
5796 }
5797 }
5798 log("Received DTX TCH fill frame with bad frame number: ", fn,
5799 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5800 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5801 f_rsl_chan_deact();
5802 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005804 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005805 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005806 if (dl.dl_info.link_id.c == SACCH) {
5807 nfill_frames_sacch := nfill_frames_sacch + 1;
5808 } else {
5809 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5810 }
5811 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005812 T.stop;
5813 if (f_g_chan_is_tchf()) {
5814 /* Without DTX we can expect 25 fill frames for every 104 frames.
5815 * (24 FACCH + 1 SACCH filling) */
5816 expected_fill_frames := 25;
5817 } else if (f_g_chan_is_tchh()) {
5818 /* We can expect 2 fill frames for every 104 frames. */
5819 expected_fill_frames := 2;
5820 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5821 /* We can expect 5 fill frames for every 104 frames. */
5822 expected_fill_frames := 5;
5823 } else {
5824 f_rsl_chan_deact();
5825 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005827 }
5828
5829 f_rsl_chan_deact();
5830 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005831
5832 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005833 setverdict(pass);
5834 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005835 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5836 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005838 }
5839 } else {
5840 repeat;
5841 }
5842 }
5843 }
5844 [] L1CTL.receive { repeat; }
5845 [] T.timeout {
5846 f_rsl_chan_deact();
5847 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005849 }
5850 }
5851}
5852
5853function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5854 f_test_l2_fill_frames(false);
5855}
5856
5857function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5858 f_test_l2_fill_frames(true);
5859}
5860
5861function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5862 var ConnHdlr vc_conn;
5863 var ConnHdlrPars pars;
5864 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02005865 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02005866 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5867 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5868 if (dtxd) {
5869 if (i >= 4) { /* DTX is only allowed on TCH/F */
5870 break;
5871 }
5872 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5873 } else {
5874 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5875 }
5876 vc_conn.done;
5877 }
5878}
5879
5880/* Verify that L2 fill frames are sent on TCH in signaling mode if
5881 * there is nothing to transmit while DTX is disabled on downlink. */
5882testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5883 f_tch_sign_l2_fill_frame(false);
5884}
5885
5886/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5887 * there is nothing to transmit while DTX is enabled on downlink. */
5888testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5889 f_tch_sign_l2_fill_frame(true);
5890}
Harald Welte0472ab42018-03-12 15:02:26 +01005891
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005892testcase TC_chopped_ipa_ping() runs on test_CT {
5893 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5894}
5895
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005896testcase TC_chopped_ipa_payload() runs on test_CT {
5897 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5898}
5899
Harald Welte0472ab42018-03-12 15:02:26 +01005900/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5901/* protocol error as per 44.006 */
5902/* link layer failure (repetition of I-frame N200 times without ACK */
5903/* repetition of SABM or DISC N200 times without ACK */
5904/* receptiom of SABM in multi-frame established state */
5905
5906
Harald Welte68e495b2018-02-25 00:05:57 +01005907/* TODO Areas:
5908
5909* channel activation
5910** with BS_Power / MS_Power, bypassing power control loop
5911** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005912** with timing advance from initial activation on
5913* mode modify
5914** encryption
5915** multirate
5916* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005917** unsupported algorithm
5918* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005919* BS Power Control
5920* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005921* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005922* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005923** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005924* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005925** DATA_IND from BTS->PCU
5926** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005927
5928*/
Harald Welte70767382018-02-21 12:16:40 +01005929
5930control {
5931 execute( TC_chan_act_stress() );
5932 execute( TC_chan_act_react() );
5933 execute( TC_chan_deact_not_active() );
5934 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005935 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005936 execute( TC_sacch_filling() );
5937 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005938 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005939 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005940 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005941 execute( TC_sacch_chan_act_ho_async() );
5942 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005943 execute( TC_rach_content() );
5944 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005945 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07005946 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02005947 execute( TC_rach_load_idle_thresh0() );
5948 execute( TC_rach_load_idle_below_thresh() );
5949 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005950 execute( TC_meas_res_sign_tchf() );
5951 execute( TC_meas_res_sign_tchh() );
5952 execute( TC_meas_res_sign_sdcch4() );
5953 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005954 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005955 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02005956 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild61edb7e2019-06-03 12:38:31 +02005957 execute( TC_rsl_ms_pwr_dyn_up() );
5958 execute( TC_rsl_ms_pwr_dyn_down() );
5959 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
5960 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005961 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005962 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005963 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005964 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005965 execute( TC_paging_imsi_80percent() );
5966 execute( TC_paging_tmsi_80percent() );
5967 execute( TC_paging_imsi_200percent() );
5968 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005969 execute( TC_rsl_protocol_error() );
5970 execute( TC_rsl_mand_ie_error() );
5971 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005972 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005973 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005974 execute( TC_si_sched_2bis() );
5975 execute( TC_si_sched_2ter() );
5976 execute( TC_si_sched_2ter_2bis() );
5977 execute( TC_si_sched_2quater() );
5978 execute( TC_si_sched_13() );
5979 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005980 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005981 execute( TC_ipa_crcx_twice_not_active() );
5982 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005983 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005984 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005985
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005986 if (mp_pcu_socket != "") {
5987 execute( TC_pcu_act_req() );
5988 execute( TC_pcu_act_req_wrong_ts() );
5989 execute( TC_pcu_act_req_wrong_bts() );
5990 execute( TC_pcu_act_req_wrong_trx() );
5991 execute( TC_pcu_deact_req() );
5992 execute( TC_pcu_deact_req_wrong_ts() );
5993 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005994 if (mp_l1_supports_gprs) {
5995 execute( TC_pcu_data_req_pdtch() );
5996 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005997 execute( TC_pcu_data_req_wrong_bts() );
5998 execute( TC_pcu_data_req_wrong_trx() );
5999 execute( TC_pcu_data_req_wrong_ts() );
6000 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006001 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006002 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006003 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006004 execute( TC_pcu_data_req_imm_ass_pch() );
6005 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006006 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006007 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006008 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006009 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006010 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006011 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006012 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006013 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006014 execute( TC_pcu_socket_noconnect_nosi3gprs() );
6015 execute( TC_pcu_socket_connect_si3gprs() );
6016 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006017 } else {
6018 log("PCU socket path not available, skipping PCU tests");
6019 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006020
6021 execute( TC_dyn_osmo_pdch_act_deact() );
6022 execute( TC_dyn_osmo_pdch_unsol_deact() );
6023 execute( TC_dyn_osmo_pdch_double_act() );
6024 execute( TC_dyn_osmo_pdch_tchf_act() );
6025 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006026 execute( TC_dyn_ipa_pdch_act_deact() );
6027 execute( TC_dyn_ipa_pdch_tchf_act() );
6028 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
6029 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006030
6031 execute( TC_rll_est_ind() );
6032 execute( TC_rll_est_req_DCCH_3() );
6033 execute( TC_rll_est_req_ACCH_3() );
6034 execute( TC_rll_rel_ind_DCCH_0() );
6035 execute( TC_rll_rel_ind_DCCH_3() );
6036 execute( TC_rll_rel_ind_ACCH_0() );
6037 execute( TC_rll_rel_ind_ACCH_3() );
6038 execute( TC_rll_rel_req() );
6039 execute( TC_rll_unit_data_req_DCCH() );
6040 execute( TC_rll_unit_data_req_ACCH() );
6041 execute( TC_rll_unit_data_ind_DCCH() );
6042 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006043
6044 execute( TC_chan_act_a51() );
6045 execute( TC_chan_act_a52() );
6046 execute( TC_chan_act_a53() );
6047 execute( TC_encr_cmd_a51() );
6048 execute( TC_encr_cmd_a52() );
6049 execute( TC_encr_cmd_a53() );
6050
Harald Welteee25aae2019-05-19 14:32:37 +02006051 execute( TC_err_rep_wrong_mdisc() );
6052 execute( TC_err_rep_wrong_msg_type() );
6053 execute( TC_err_rep_wrong_sequence() );
6054
Harald Weltee613f962018-04-18 22:38:16 +02006055 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006056
6057 execute( TC_tch_sign_l2_fill_frame() );
6058 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006059
6060 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006061 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006062}
6063
6064
6065}