blob: 3683306df870f615b34e2e2ebe1c6ebda0651714 [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)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700425 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
426 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100427 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200428
429 /* Wait some extra time to make sure the BTS emits a stable carrier.
430 * (this is only relevant when running the tests with a physical BTS.) */
431 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100432}
433
Harald Welte68e495b2018-02-25 00:05:57 +0100434/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
435function f_init_l1ctl() runs on test_CT {
436 map(self:L1CTL, system:L1CTL);
437 f_connect_reset(L1CTL);
438}
439
Harald Welte70767382018-02-21 12:16:40 +0100440type function void_fn(charstring id) runs on ConnHdlr;
441
442/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700443function f_start_handler(void_fn fn, ConnHdlrPars pars,
444 boolean pcu_comp := false,
445 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100446runs on test_CT return ConnHdlr {
447 var charstring id := testcasename();
448 var ConnHdlr vc_conn;
449
450 vc_conn := ConnHdlr.create(id);
451 /* connect to RSL Emulation main component */
452 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
453 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700454
455 /* The ConnHdlr component may want to talk to some ports directly,
456 * so we disconnect it from the test_CT and connect it to the component.
457 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200458 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 unmap(self:PCU, system:PCU);
460 map(vc_conn:PCU, system:PCU);
461 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700462 if (trxc_comp) {
463 unmap(self:BTS_TRXC, system:BTS_TRXC);
464 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
465 }
Harald Welte70767382018-02-21 12:16:40 +0100466
467 vc_conn.start(f_handler_init(fn, id, pars));
468 return vc_conn;
469}
470
Harald Welte7484fc42018-02-24 14:09:45 +0100471template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
472 streamId := sid,
473 rsl := rsl
474}
475
476template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
477 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
478 streamId := sid,
479 rsl := rsl
480}
481
Harald Welte70767382018-02-21 12:16:40 +0100482private altstep as_Tguard() runs on ConnHdlr {
483 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100485 }
486}
487
Harald Welte990a3612019-05-27 14:02:13 +0200488friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
489 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100490}
491
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700492private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100493 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700494 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100495}
496
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700497private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100498 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700499 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100500}
501
502/* first function started in ConnHdlr component */
503private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
504runs on ConnHdlr {
505 g_pars := pars;
506 g_chan_nr := pars.chan_nr;
507
508 map(self:L1CTL, system:L1CTL);
509 f_connect_reset(L1CTL);
510
Harald Welted48c0c72019-06-05 10:01:15 +0200511 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700512 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100513 }
Harald Welte70767382018-02-21 12:16:40 +0100514
515 g_Tguard.start(pars.t_guard);
516 activate(as_Tguard());
517
518 f_rslem_register(0, pars.chan_nr);
519
520 /* call the user-supplied test case function */
521 fn.apply(id);
522}
523
Harald Welteb1726c92018-03-30 11:56:38 +0200524function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
525 boolean ignore_other := false)
526runs on ConnHdlr return RSL_Message {
527 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100528 timer T := 3.0;
529 RSL.send(tx);
530 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100531 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200532 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100533 T.stop;
534 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100535 }
Harald Welte1eba3742018-02-25 12:48:14 +0100536 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100538 }
Harald Welte21240e62018-03-11 21:43:35 +0100539 [not ignore_other] as_l1_sacch();
540 [not ignore_other] as_meas_res();
541 [not ignore_other] as_l1_dcch();
542 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100544 }
Harald Welte21240e62018-03-11 21:43:35 +0100545 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100546 }
Harald Welteb1726c92018-03-30 11:56:38 +0200547 return rx;
548}
549
550function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
551 boolean ignore_other := false)
552runs on ConnHdlr {
553 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100554}
555
Harald Welte8b01c792019-05-19 22:51:25 +0200556function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
557 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
558 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200559 if (encr_enable) {
560 /* append encryption related IEs, if requested */
561 var RSL_IE_EncryptionInfo encr_info;
562 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
563 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
564encr_info})) };
565 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200566 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200567 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100568}
569
Harald Welte70767382018-02-21 12:16:40 +0100570function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100571 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 +0100572 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100573}
574
Harald Welte2f2b2b72019-05-31 22:24:57 +0200575friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100576 template RSL_IE_ChannelMode chan_mode,
577 float t_guard := 20.0) := {
578 chan_nr := valueof(chan_nr),
579 chan_mode := valueof(chan_mode),
580 t_guard := t_guard,
581 l1_pars := {
582 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100583 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100584 meas_ul := {
585 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200586 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100587 rxqual := 0
588 },
589 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200590 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100591 rxqual := 0
592 }
593 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200594 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100595 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200596 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200597 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100598 },
Harald Weltee613f962018-04-18 22:38:16 +0200599 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200600 encr := omit,
601 bts0_band := omit
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Harald Welte93640c62018-02-25 16:59:33 +0100604/***********************************************************************
605 * Channel Activation / Deactivation
606 ***********************************************************************/
607
Harald Welte70767382018-02-21 12:16:40 +0100608/* Stress test: Do 500 channel activations/deactivations in rapid succession */
609function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
610 for (var integer i := 0; i < 500; i := i+1) {
611 f_rsl_chan_act(g_pars.chan_mode);
612 f_rsl_chan_deact();
613 }
614 setverdict(pass);
615}
616testcase TC_chan_act_stress() runs on test_CT {
617 var ConnHdlr vc_conn;
618 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200619 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100620 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
621 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100623}
624
625/* Test if re-activation of an already active channel fails as expected */
626function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
627 f_rsl_chan_act(g_pars.chan_mode);
628 /* attempt to activate the same lchan again -> expect reject */
629 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
630 alt {
631 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100633 }
634 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
635 setverdict(pass);
636 }
637 }
638 f_rsl_chan_deact();
639}
640testcase TC_chan_act_react() runs on test_CT {
641 var ConnHdlr vc_conn;
642 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100643 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100644 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
645 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100647}
648
649/* Attempt to de-activate a channel that's not active */
650function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
651 timer T := 3.0;
652 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
653 T.start;
654 alt {
655 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
656 setverdict(pass);
657 }
658 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100660 }
661 }
662}
663testcase TC_chan_deact_not_active() runs on test_CT {
664 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100665 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100666 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
667 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100669}
670
671/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
672function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
673 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
674 alt {
675 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100677 }
678 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
679 setverdict(pass);
680 }
681 }
682}
683private type record WrongChanNrCase {
684 RslChannelNr chan_nr,
685 charstring description
686}
687private type record of WrongChanNrCase WrongChanNrCases;
688private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
689 chan_nr := chan_nr,
690 description := desc
691}
692
693testcase TC_chan_act_wrong_nr() runs on test_CT {
694 var ConnHdlr vc_conn;
695 var ConnHdlrPars pars;
696
Harald Welte294b0a22018-03-10 23:26:48 +0100697 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100698
699 var WrongChanNrCases wrong := {
700 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
701 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
702 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
703 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
704 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
705 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
706 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
707 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
708 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
709 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
710 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
711 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
712 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
713 };
714
715 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
716 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
717 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
718 vc_conn.done;
719 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100721}
722
Harald Weltee613f962018-04-18 22:38:16 +0200723/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200724friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200725 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200726 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200727
728 /* test on each of the channels we have */
729 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
730 pars.chan_nr := valueof(g_AllChanTypes[i]);
731
732 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
733 vc_conn := f_start_handler(fn, pars);
734 vc_conn.done;
735 }
736
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200738}
739
Harald Welte93640c62018-02-25 16:59:33 +0100740/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100741 * SACCH handling
742 ***********************************************************************/
743
744private function f_exp_sacch(boolean exp) runs on ConnHdlr {
745 timer T_sacch := 3.0;
746 T_sacch.start;
747 alt {
748 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100750 }
751 [not exp] T_sacch.timeout {
752 setverdict(pass);
753 }
754 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
755 setverdict(pass);
756 }
757 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100759 }
760 [] L1CTL.receive { repeat; }
761 [] RSL.receive { repeat; }
762 }
763}
764
765/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
766private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
767 f_l1_tune(L1CTL);
768 RSL.clear;
769
770 /* activate the logical channel */
771 f_est_dchan();
772 L1CTL.clear;
773
774 /* check that SACCH actually are received as expected */
775 f_exp_sacch(true);
776
777 /* deactivate SACCH on the logical channel */
778 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
779 f_sleep(1.0);
780 L1CTL.clear;
781
782 /* check that no SACCH are received anymore */
783 f_exp_sacch(false);
784
785 /* release the channel */
786 f_rsl_chan_deact();
787 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
788}
789testcase TC_deact_sacch() runs on test_CT {
790 var ConnHdlr vc_conn;
791 var ConnHdlrPars pars;
792 f_init();
793 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
794 //for (var integer i := 0; i < 1; i := i+1) {
795 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
796 log(testcasename(), ": Starting for ", g_AllChannels[i]);
797 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
798 vc_conn.done;
799 }
800 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100802}
803
Harald Welte55700662018-03-12 13:15:43 +0100804/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100805private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
806 var L1ctlDlMessage dl;
807 /* check that the specified SI5 value is actually sent */
808 timer T_sacch := 3.0;
809 L1CTL.clear;
810 T_sacch.start;
811 alt {
812 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
813 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
814 if (match(l3, l3_exp)) {
815 setverdict(pass);
816 } else {
817 repeat;
818 }
819 }
820 [] L1CTL.receive { repeat; }
821 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100823 }
824 }
825}
826
Harald Welte55700662018-03-12 13:15:43 +0100827/* verify that given SACCH payload is not present */
828private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
829 var L1ctlDlMessage dl;
830 /* check that the specified SI5 value is actually sent */
831 timer T_sacch := 3.0;
832 L1CTL.clear;
833 T_sacch.start;
834 alt {
835 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
836 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
837 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100839 } else {
840 repeat;
841 }
842 }
843 [] L1CTL.receive { repeat; }
844 [] T_sacch.timeout {
845 setverdict(pass);
846 }
847 }
848}
849
Harald Welte629cc6b2018-03-11 17:19:05 +0100850/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100851private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
852 /* Set a known default SACCH filling for SI5 */
853 var octetstring si5 := f_rnd_octstring(19);
854 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
855
856 f_l1_tune(L1CTL);
857 RSL.clear;
858
859 /* activate the logical channel */
860 f_est_dchan();
861
862 /* check that the specified SI5 value is actually sent */
863 f_sacch_present(si5);
864
865 /* release the channel */
866 RSL.clear;
867 f_rsl_chan_deact();
868 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
869}
870testcase TC_sacch_filling() runs on test_CT {
871 var ConnHdlr vc_conn;
872 var ConnHdlrPars pars;
873 f_init();
874 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
875 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
876 log(testcasename(), ": Starting for ", g_AllChannels[i]);
877 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
878 vc_conn.done;
879 }
880 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100882}
883
Harald Welte629cc6b2018-03-11 17:19:05 +0100884/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100885private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
886 /* Set a known default SACCH filling for SI5 */
887 var octetstring si5 := f_rnd_octstring(19);
888 var octetstring si5_diff := f_rnd_octstring(19);
889 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
890
891 f_l1_tune(L1CTL);
892 RSL.clear;
893
894 log("Activating channel, expecting standard SI5");
895 /* activate the logical channel */
896 f_est_dchan();
897 /* check that the specified SI5 value is actually sent */
898 f_sacch_present(si5);
899
900 /* set channel-specific different SI5 */
901 log("Setting channel specific SACCH INFO, expecting it");
902 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
903 /* check that the specified lchan-specific value is now used */
904 f_sacch_present(si5_diff);
905
906 /* deactivate the channel and re-activate it, this should result in default SI5 */
907 log("De-activating and re-activating channel, expecting standard SI5");
908 f_rsl_chan_deact();
909 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
910 /* Verify that the TRX-wide default SACCH filling is present again */
911 f_sacch_present(si5);
912
913 /* release the channel */
914 RSL.clear;
915 f_rsl_chan_deact();
916 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
917}
918testcase TC_sacch_info_mod() runs on test_CT {
919 var ConnHdlr vc_conn;
920 var ConnHdlrPars pars;
921 f_init();
922 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
923 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
924 log(testcasename(), ": Starting for ", g_AllChannels[i]);
925 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
926 vc_conn.done;
927 }
928 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100930}
931
Harald Welte075d84c2018-03-12 13:07:24 +0100932/* Test SACCH scheduling of multiple different SI message types */
933private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
934 var octetstring si5 := f_rnd_octstring(19);
935 var octetstring si5bis := f_rnd_octstring(19);
936 var octetstring si5ter := f_rnd_octstring(19);
937 var octetstring si6 := f_rnd_octstring(19);
938
939 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
940 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
941 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
942 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
943
944 f_l1_tune(L1CTL);
945 RSL.clear;
946
947 /* activate the logical channel */
948 f_est_dchan();
949 L1CTL.clear;
950
951 /* check that SACCH actually are received as expected */
952 f_sacch_present(si5);
953 f_sacch_present(si5bis);
954 f_sacch_present(si5ter);
955 f_sacch_present(si6);
956
957 /* release the channel */
958 f_rsl_chan_deact();
959 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
960}
961testcase TC_sacch_multi() runs on test_CT {
962 var ConnHdlr vc_conn;
963 var ConnHdlrPars pars;
964 f_init();
965 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
966 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
967 log(testcasename(), ": Starting for ", g_AllChannels[i]);
968 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
969 vc_conn.done;
970 }
971 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100973}
974
Harald Welte55700662018-03-12 13:15:43 +0100975/* Test if SACH information is modified as expected */
976private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
977 var octetstring si5 := f_rnd_octstring(19);
978 var octetstring si6 := f_rnd_octstring(19);
979
980 /* First, configure both SI5 and SI6 to be transmitted */
981 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
982 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
983
984 f_l1_tune(L1CTL);
985 RSL.clear;
986
987 /* activate the logical channel */
988 f_est_dchan();
989 L1CTL.clear;
990
991 /* check that SACCH actually are received as expected */
992 f_sacch_present(si5);
993 f_sacch_present(si6);
994
995 /* disable SI6 */
996 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
997
998 /* check that SI5 is still transmitted */
999 f_sacch_present(si5);
1000 /* check if SI6 is now gone */
1001 f_sacch_missing(si6);
1002
1003 /* release the channel */
1004 f_rsl_chan_deact();
1005 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1006}
1007testcase TC_sacch_multi_chg() runs on test_CT {
1008 var ConnHdlr vc_conn;
1009 var ConnHdlrPars pars;
1010 f_init();
1011 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1012 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1013 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1014 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1015 vc_conn.done;
1016 }
1017 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001019}
1020
Harald Weltec8d363c2019-05-19 20:36:48 +02001021/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1022private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1023 var octetstring si5 := f_rnd_octstring(19);
1024 var octetstring si6 := f_rnd_octstring(19);
1025 var octetstring si5_specific := f_rnd_octstring(19);
1026 var octetstring si6_specific := f_rnd_octstring(19);
1027
1028 /* First, configure both SI5 and SI6 to be transmitted */
1029 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1030 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1031
1032 f_l1_tune(L1CTL);
1033 RSL.clear;
1034
1035 /* activate channel with different SACCH filling */
1036 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1037 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1038 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1039 }));
1040 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1041 RSL_IE_Body:{sacch_info := sacch_info})) };
1042 f_est_dchan(more_ies := addl_ies);
1043
1044 /* check that SACCH actually are received as expected */
1045 f_sacch_present(si5_specific);
1046 f_sacch_present(si6_specific);
1047
1048 /* release the channel */
1049 f_rsl_chan_deact();
1050 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1051}
1052testcase TC_sacch_chan_act() runs on test_CT {
1053 var ConnHdlr vc_conn;
1054 var ConnHdlrPars pars;
1055 f_init();
1056
1057 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1058 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1059 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1060 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1061 vc_conn.done;
1062 }
1063 /* TODO: do the above in parallel, rather than sequentially? */
1064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1065}
1066
Harald Welte8b01c792019-05-19 22:51:25 +02001067/* verify that SACCH DL transmission is started only if MS power IE present
1068 * see section 4.1.3 of 3GPP TS 48.058 */
1069private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1070 var octetstring si5 := f_rnd_octstring(19);
1071
1072 f_l1_tune(L1CTL);
1073 RSL.clear;
1074
1075 /* Step 1: Activate ASYNC HO channel without MS power IE */
1076
1077 /* Activate channel on BTS side */
1078 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1079 /* don't perform immediate assignment here, as we're testing non-IA case */
1080 /* enable dedicated mode */
1081 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1082
1083 /* Verify that no DL SACCH is being received */
1084 f_sacch_missing(?);
1085
1086 f_rsl_chan_deact();
1087 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1088
1089
1090 /* Step 2: Activate ASYNC HO channel with MS power IE */
1091
1092 /* Activate channel on BTS side */
1093 var RSL_IE_List addl_ies := {
1094 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1095 };
1096 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1097 /* don't perform immediate assignment here, as we're testing non-IA case */
1098 /* enable dedicated mode */
1099 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1100
1101 /* Verify that DL SACCH is being received */
1102 f_sacch_present(si5);
1103
1104 f_rsl_chan_deact();
1105 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1106}
1107testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1108 var ConnHdlr vc_conn;
1109 var ConnHdlrPars pars;
1110 f_init();
1111
1112 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1113 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1114 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1115 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1116 vc_conn.done;
1117 }
1118 /* TODO: do the above in parallel, rather than sequentially? */
1119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1120}
1121
1122/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1123 * see section 4.1.4 of 3GPP TS 48.058 */
1124private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1125 var octetstring si5 := f_rnd_octstring(19);
1126 var RSL_IE_List addl_ies;
1127
1128 f_l1_tune(L1CTL);
1129 RSL.clear;
1130
1131 /* Step 1: Activate SYNC HO channel without MS power IE */
1132
1133 /* Activate channel on BTS side */
1134 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1135 /* don't perform immediate assignment here, as we're testing non-IA case */
1136 /* enable dedicated mode */
1137 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1138
1139 /* Verify that no DL SACCH is being received */
1140 f_sacch_missing(?);
1141
1142 f_rsl_chan_deact();
1143 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1144
1145
1146 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1147
1148 /* Activate channel on BTS side */
1149 addl_ies := {
1150 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1151 };
1152 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1153 /* don't perform immediate assignment here, as we're testing non-IA case */
1154 /* enable dedicated mode */
1155 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1156
1157 /* Verify that no DL SACCH is being received */
1158 f_sacch_missing(?);
1159
1160 f_rsl_chan_deact();
1161 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1162
1163
1164 /* Step 2b: Activate SYNC HO channel with TA IE */
1165
1166 /* Activate channel on BTS side */
1167 addl_ies := {
1168 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1169 };
1170 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1171 /* don't perform immediate assignment here, as we're testing non-IA case */
1172 /* enable dedicated mode */
1173 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1174
1175 /* Verify that no DL SACCH is being received */
1176 f_sacch_missing(?);
1177
1178 f_rsl_chan_deact();
1179 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1180
1181
1182 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1183
1184 /* Activate channel on BTS side */
1185 addl_ies := {
1186 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1187 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1188 };
1189 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1190 /* don't perform immediate assignment here, as we're testing non-IA case */
1191 /* enable dedicated mode */
1192 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1193
1194 /* Verify that DL SACCH is being received */
1195 f_sacch_present(si5);
1196
1197 f_rsl_chan_deact();
1198 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1199}
1200testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1201 var ConnHdlr vc_conn;
1202 var ConnHdlrPars pars;
1203 f_init();
1204
1205 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1206 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1207 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1208 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1209 vc_conn.done;
1210 }
1211 /* TODO: do the above in parallel, rather than sequentially? */
1212 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1213}
Harald Welte629cc6b2018-03-11 17:19:05 +01001214
1215
1216/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001217 * RACH Handling
1218 ***********************************************************************/
1219
Harald Welte8c24c2b2018-02-26 08:31:31 +01001220/* like L1SAP_IS_PACKET_RACH */
1221private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001222 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001223 return true;
1224 }
1225 return false;
1226}
1227
1228/* generate a random RACH for circuit-switched */
1229private function f_rnd_ra_cs() return OCT1 {
1230 var OCT1 ra;
1231 do {
1232 ra := f_rnd_octstring(1);
1233 } while (ra_is_ps(ra));
1234 return ra;
1235}
1236
Harald Welte883340c2018-02-28 18:59:29 +01001237/* generate a random RACH for packet-switched */
1238private function f_rnd_ra_ps() return OCT1 {
1239 var OCT1 ra;
1240 do {
1241 ra := f_rnd_octstring(1);
1242 } while (not ra_is_ps(ra));
1243 return ra;
1244}
1245
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001246/* generate a random 11-bit RA (packet-switched only) */
1247private function f_rnd_ra11_ps() return BIT11 {
1248 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1249 return int2bit(ra11, 11);
1250}
1251
Harald Welte8c24c2b2018-02-26 08:31:31 +01001252/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1253testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001254 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001255 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001256 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001257
Harald Welte8c24c2b2018-02-26 08:31:31 +01001258 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001259 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001260 for (var integer i := 0; i < 1000; i := i+1) {
1261 var OCT1 ra := f_rnd_ra_cs();
1262 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1263 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001265 }
1266 fn_last := fn;
1267
1268 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001269 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001270 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001271 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001272 T.stop;
1273 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001274 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276 }
1277 [] RSL_CCHAN.receive { repeat; }
1278 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001279 test_failed := true;
1280 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001281 }
1282 }
1283 }
Maxba06feb2019-03-05 10:52:46 +01001284 if (test_failed) {
1285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001286 }
Maxba06feb2019-03-05 10:52:46 +01001287 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001289}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001290
1291/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1292testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001293 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001295 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001296 f_l1_tune(L1CTL);
1297
1298 var GsmFrameNumber fn_last := 0;
1299 for (var integer i := 0; i < 1000; i := i+1) {
1300 var OCT1 ra := f_rnd_ra_cs();
1301 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1302 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001304 }
1305 fn_last := fn;
1306 }
1307 var integer rsl_chrqd := 0;
1308 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001309 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001310 alt {
1311 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1312 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001313 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001314 repeat;
1315 }
1316 [] RSL_CCHAN.receive { repeat; }
1317 [] T.timeout { }
1318 }
1319 if (rsl_chrqd == 1000) {
1320 setverdict(pass);
1321 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001323 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001325}
1326
Harald Welte3453ab42019-05-24 21:19:58 +02001327private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1328 var charstring bts_str := "bts " & int2str(bts_nr);
1329 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1330}
1331
1332/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1333private template integer tr_rach_slots_per_interval := (90 .. 130);
1334
1335/* Expect 0 RACH load on an idle BTS that has just started up */
1336testcase TC_rach_load_idle_thresh0() runs on test_CT {
1337 var ASP_RSL_Unitdata rx_ud;
1338
1339 f_init_vty_bsc();
1340 /* send load indications even at 0% load */
1341 f_vty_load_ind_thresh(0);
1342 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1343 f_sleep(2.0);
1344
1345 f_init();
1346
1347 timer T := 5.0;
1348 T.start;
1349 alt {
1350 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1351 setverdict(pass);
1352 repeat;
1353 }
1354 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1355 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1356 repeat;
1357 }
1358 [] RSL_CCHAN.receive {
1359 repeat;
1360 }
1361 [] T.timeout { }
1362 }
1363
1364 f_vty_load_ind_thresh(10);
1365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1366}
1367
1368/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1369testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1370 var ASP_RSL_Unitdata rx_ud;
1371
1372 f_init_vty_bsc();
1373 f_init();
1374
1375 timer T := 5.0;
1376 T.start;
1377 alt {
1378 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1379 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1380 repeat;
1381 }
1382 [] RSL_CCHAN.receive {
1383 repeat;
1384 }
1385 [] T.timeout {
1386 setverdict(pass);
1387 }
1388 }
1389
1390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1391}
1392
1393/* Expect 0 RACH load on an idle BTS that has just started up */
1394testcase TC_rach_load_count() runs on test_CT {
1395 var ASP_RSL_Unitdata rx_ud;
1396 var integer load_access_count := 0;
1397
1398 f_init_vty_bsc();
1399 /* send load indications even at 0% load */
1400 f_vty_load_ind_thresh(0);
1401 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1402 f_sleep(2.0);
1403 f_init();
1404
1405 f_init_l1ctl();
1406 f_sleep(1.0);
1407 f_l1_tune(L1CTL);
1408
1409 var GsmFrameNumber fn_last := 0;
1410 for (var integer i := 0; i < 1000; i := i+1) {
1411 var OCT1 ra := f_rnd_ra_cs();
1412 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1413 if (fn == fn_last) {
1414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1415 }
1416 fn_last := fn;
1417 }
1418
1419 timer T := 5.0;
1420 T.start;
1421 alt {
1422 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1423 -> value rx_ud {
1424 var RSL_IE_Body ie;
1425 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1426 load_access_count := load_access_count + ie.rach_load.access_count;
1427 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1428 setverdict(fail, "Access count cannot be < Busy count");
1429 }
1430 repeat;
1431 }
1432 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1433 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1434 repeat;
1435 }
1436 [] RSL_CCHAN.receive {
1437 repeat;
1438 }
1439 [] T.timeout { }
1440 }
1441 if (load_access_count == 1000) {
1442 setverdict(pass);
1443 } else {
1444 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1445 }
1446
1447 f_vty_load_ind_thresh(10);
1448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1449}
1450
Harald Welte54a2a2d2018-02-26 09:14:05 +01001451private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001452 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001453 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001454 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001455 f_sleep(0.5);
1456
1457 /* Transmit RACH request + wait for confirmation */
1458 var OCT1 ra := f_rnd_ra_cs();
1459 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1460
1461 /* Check for expected result */
1462 timer T := 1.5;
1463 T.start;
1464 alt {
1465 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1466 setverdict(pass);
1467 }
1468 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001470 }
1471 [] RSL_CCHAN.receive { repeat; }
1472 [not expect_pass] T.timeout {
1473 setverdict(pass);
1474 }
1475 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001477 }
1478 }
1479}
1480
1481/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1482testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001483 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001484 f_init_l1ctl();
1485 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001486 f_sleep(1.0);
1487
1488 /* default max-ta is 63 (full range of GSM timing advance */
1489
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001490 /* We allow early arrival up to 2 symbols */
1491 f_rach_toffs(-1*256, true);
1492 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001493 f_rach_toffs(-10*256, false);
1494
1495 /* 0 / 32 / 63 bits is legal / permitted */
1496 f_rach_toffs(0, true);
1497 f_rach_toffs(32*256, true);
1498 f_rach_toffs(63*256, true);
1499
1500 /* more than 63 bits is not legal / permitted */
1501 f_rach_toffs(64*256, false);
1502 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001504}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001505
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001506function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1507 var GsmFrameNumber fn;
1508 var RSL_Message rm;
1509
1510 f_l1_tune(L1CTL);
1511 RSL.clear;
1512
1513 /* Generate a random Handover Reference */
1514 var integer ho_ref := oct2int(f_rnd_octstring(1));
1515
1516 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1517 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1518 RSL_IE_Body:{ handover_ref := ho_ref }));
1519
1520 /* Activate a channel on the BTS side (no encryption) */
1521 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1522 act_type := t_RSL_IE_ActType_HO_SYNC);
1523
1524 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1525 * waiting for Immediate Assignment and sending Access Burst */
1526 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1527
1528 /* Send handover Access Burst */
1529 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1530
1531 /* TODO: test mismatching Handover Reference, and missing IE */
1532
1533 /* Wait for handover detection */
1534 timer T := 3.0;
1535 T.start;
1536 alt {
1537 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1538 log("Handover RACH has been detected: ", rm);
1539 setverdict(pass);
1540 }
1541 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1543 log2str("RSL_CHAN_RQD was not expected: ", rm));
1544 }
1545 [] RSL.receive { repeat; }
1546 [] T.timeout {
1547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1548 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1549 }
1550 }
1551
1552 /* Release the channel */
1553 f_rsl_chan_deact();
1554 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1555}
1556
1557/* Test handover RACH detection */
1558testcase TC_ho_rach() runs on test_CT {
1559 var ConnHdlrPars pars;
1560 var ConnHdlr vc_conn;
1561
1562 f_init();
1563
1564 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1565 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1566 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1567 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1568 vc_conn.done;
1569 }
1570
1571 /* TODO: do the above in parallel, rather than sequentially? */
1572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1573}
1574
Harald Welte93640c62018-02-25 16:59:33 +01001575/***********************************************************************
1576 * Measurement Processing / Reporting
1577 ***********************************************************************/
1578
Harald Welte70767382018-02-21 12:16:40 +01001579template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1580 spare := '0'B,
1581 lpd := 0,
1582 sapi := sapi,
1583 c_r := c_r,
1584 ea := true
1585}
1586
Harald Welted879bd92018-03-12 15:01:23 +01001587template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001588 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001589 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001590 len := 0, /* overwritten */
1591 m := false,
1592 el := 1,
1593 payload := pl
1594}
1595
1596/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1597altstep as_l1_sacch() runs on ConnHdlr {
1598 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001599 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001600 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001601 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 +01001602 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001603 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001604
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001605 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1606 g_pars.l1_pars.ms_power_level, false,
1607 g_pars.l1_pars.ms_actual_ta);
1608
1609 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1610 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1611
1612 log("Sending Measurement Report: ", l1h, l2);
1613 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001614 repeat;
1615 }
1616}
1617
1618altstep as_l1_dcch() runs on ConnHdlr {
1619 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001620 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001621 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1622 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001623 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1624 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001625 repeat;
1626 }
1627}
1628
1629type record MeasElem {
1630 uint6_t rxlev,
1631 uint3_t rxqual
1632}
1633
1634type record MeasElemFS {
1635 MeasElem full,
1636 MeasElem sub
1637}
1638
1639type record ConnL1Pars {
1640 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001641 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001642 MeasElemFS meas_ul,
1643 int16_t timing_offset_256syms,
1644 uint5_t bs_power_level,
1645 uint5_t ms_power_level,
1646 uint8_t ms_actual_ta
1647}
1648
1649/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1650private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1651 return 63 + (toffs256s/256);
1652}
1653
Harald Welted5684392018-03-10 18:22:04 +01001654private function f_max(integer a, integer b) return integer {
1655 if (a > b) {
1656 return a;
1657 } else {
1658 return b;
1659 }
1660}
1661
1662private function f_min(integer a, integer b) return integer {
1663 if (a < b) {
1664 return a;
1665 } else {
1666 return b;
1667 }
1668}
1669
1670/* compute negative tolerance val-tolerance, ensure >= min */
1671private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1672 val := val - tolerance;
1673 return f_max(val, min);
1674}
1675
1676/* compute positive tolerance val+tolerance, ensure <= max */
1677private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1678 val := val + tolerance;
1679 return f_min(val, max);
1680}
1681
1682/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1683private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1684return template integer {
1685 var template integer ret;
1686 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1687 return ret;
1688}
1689
1690
Harald Welte70767382018-02-21 12:16:40 +01001691/* build a template for matching measurement results against */
1692private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1693 var ConnL1Pars l1p := g_pars.l1_pars;
1694 var template RSL_IE_UplinkMeas ul_meas := {
1695 len := 3,
1696 rfu := '0'B,
1697 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001698 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001699 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001700 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001701 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001702 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1703 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001704 supp_meas_info := omit
1705 };
Harald Welte685d5982018-02-27 20:42:05 +01001706 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001707 ul_meas.len := (3+8);
1708 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001709 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001710 toa256_min := ?,
1711 toa256_max := ?,
1712 toa256_std_dev := ?
1713 }
Harald Welte685d5982018-02-27 20:42:05 +01001714 }
Harald Welte70767382018-02-21 12:16:40 +01001715 var template RSL_IE_BS_Power bs_power := {
1716 reserved := 0,
1717 epc := false,
1718 fpc := false,
1719 power_level := l1p.bs_power_level
1720 };
1721 var template RSL_IE_L1Info l1_info := {
1722 ms_power_lvl := l1p.ms_power_level,
1723 fpc := false,
1724 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001725 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001726 };
1727 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001728 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001729 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1730 ?, t_toffs);
1731}
1732
Philipp Maierdd841d32019-12-17 14:44:54 +01001733/* build a template for matching measurement results that do not contain any
1734 * MS related measurement (l1_info, l3_info and ms timing offset). */
1735private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1736 var ConnL1Pars l1p := g_pars.l1_pars;
1737 var template RSL_IE_UplinkMeas ul_meas := {
1738 len := 3,
1739 rfu := '0'B,
1740 dtx_d := l1p.dtx_enabled,
1741 rxlev_f_u := ?,
1742 reserved1 := '00'B,
1743 rxlev_s_u := ?,
1744 reserved2 := '00'B,
1745 rxq_f_u := ?,
1746 rxq_s_u := ?,
1747 supp_meas_info := omit
1748 };
1749 if (l1p.toa256_enabled) {
1750 ul_meas.len := (3+8);
1751 ul_meas.supp_meas_info := {
1752 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1753 toa256_min := ?,
1754 toa256_max := ?,
1755 toa256_std_dev := ?
1756 }
1757 }
1758 var template RSL_IE_BS_Power bs_power := {
1759 reserved := 0,
1760 epc := false,
1761 fpc := false,
1762 power_level := l1p.bs_power_level
1763 };
1764
1765 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1766}
1767
Harald Welte70767382018-02-21 12:16:40 +01001768/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001769altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001770 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001771 var boolean chan_est := false;
1772
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001773 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001774
1775 /* Receive osmocom specific measurement reports. This is the normal
1776 * case. Here we verify that the measurement reports we sent are
1777 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001778 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1779 /* increment counter of next to-be-expected meas rep */
1780 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1781 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001782 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001783
1784 /* The following two cases may only happen in the beginning
1785 * of the channel establishment phase. Once we have received
1786 * the "our" measurement report the first time, the channel
1787 * is established and empty or hardcoded TRXCON reports must
1788 * not occur anymore. */
1789 chan_est := true;
1790
1791 repeat;
1792 }
1793
1794 /* When the BTS has established the channel, the MS might need slightly
1795 * more time to establish the channel and actually start sending. The
1796 * result is then a measurement report that just lacks the measurement
1797 * information of the MS. This is normal and we tolerate this behavior. */
1798 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1799 /* increment counter of next to-be-expected meas rep */
1800 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1801 /* Re-start the timer expecting the next MEAS RES */
1802 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001803 repeat;
1804 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001805
1806 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1807 * measurements if the TTCN3 side does not supply measurement input in
1808 * time. In those cases TRXCON will either use a cached measurement
1809 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1810 * report the templates above will not match. We tolerate this
1811 * behavior, but only once. */
1812 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001813 /* increment counter of next to-be-expected meas rep */
1814 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1815 if (g_first_meas_res) {
1816 g_first_meas_res := false;
1817 repeat;
1818 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001820 }
Harald Welte70767382018-02-21 12:16:40 +01001821 }
1822 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001824 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001825 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001827 }
1828}
1829
Harald Weltee613f962018-04-18 22:38:16 +02001830private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1831 select (rsl_alg_id) {
1832 case (RSL_ALG_ID_A5_0) { return 0; }
1833 case (RSL_ALG_ID_A5_1) { return 1; }
1834 case (RSL_ALG_ID_A5_2) { return 2; }
1835 case (RSL_ALG_ID_A5_3) { return 3; }
1836 case (RSL_ALG_ID_A5_4) { return 4; }
1837 case (RSL_ALG_ID_A5_5) { return 5; }
1838 case (RSL_ALG_ID_A5_6) { return 6; }
1839 case (RSL_ALG_ID_A5_7) { return 7; }
1840 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1842 /* Make compiler happy by calling mtc.stop here. It is already
1843 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001844 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001845 }
1846 }
1847}
1848
1849private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1850 select (rsl_alg_id) {
1851 case (RSL_ALG_ID_A5_1) { return '000'B; }
1852 case (RSL_ALG_ID_A5_2) { return '001'B; }
1853 case (RSL_ALG_ID_A5_3) { return '010'B; }
1854 case (RSL_ALG_ID_A5_4) { return '011'B; }
1855 case (RSL_ALG_ID_A5_5) { return '100'B; }
1856 case (RSL_ALG_ID_A5_6) { return '101'B; }
1857 case (RSL_ALG_ID_A5_7) { return '110'B; }
1858 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1860 /* Make compiler happy by calling mtc.stop here. It is already
1861 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001862 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001863 }
1864 }
1865}
1866
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001867/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1868private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1869 var GsmFrameNumber fn;
1870 timer T := 8.0;
1871
1872 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1873 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1874
1875 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1876 /* Send the actual RACH */
1877 fn := f_L1CTL_RACH(L1CTL, ra);
1878
1879 T.start;
1880 alt {
1881 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1882 [] T.timeout {
1883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1884 }
1885 }
1886 T.stop
1887 return fn;
1888}
Harald Weltee613f962018-04-18 22:38:16 +02001889
Harald Welte70767382018-02-21 12:16:40 +01001890/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001891private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001892 var GsmFrameNumber fn;
1893 var ImmediateAssignment imm_ass;
1894 var integer ra := 23;
1895
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001896 /* Send RACH request and wait for ChanReq */
1897 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001898
1899 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001900 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001901
1902 /* Send IMM.ASS via CCHAN */
1903 var ChannelDescription ch_desc := {
1904 chan_nr := g_pars.chan_nr,
1905 tsc := 7,
1906 h := false,
1907 arfcn := mp_trx0_arfcn,
1908 maio_hsn := omit
1909 };
1910 var MobileAllocation ma := {
1911 len := 0,
1912 ma := ''B
1913 };
1914 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1915 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1916
1917 /* receive IMM.ASS on MS side */
1918 var ImmediateAssignment ia_um;
1919 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1920 /* enable dedicated mode */
1921 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001922 /* enable encryption, if requested */
1923 if (encr_enable) {
1924 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1925 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1926 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001927
1928 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001929}
1930
1931/* establish DChan, verify existance + contents of measurement reports */
1932function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001933 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001934 RSL.clear;
1935
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001936 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001937 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001938 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001939 }
Harald Welte70767382018-02-21 12:16:40 +01001940
1941 f_est_dchan();
1942
1943 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1944 * RSL measurement reports on Abis side */
1945 timer T := 8.0;
1946 T.start;
1947 alt {
1948 [] as_l1_sacch();
1949 [] as_meas_res();
1950 [] as_l1_dcch();
1951 [] L1CTL.receive { repeat; }
1952 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001953 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001954 * of any earlier errors, so if we reach this timeout, we're good */
1955 setverdict(pass);
1956 }
1957 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001959 }
1960 }
1961 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001962 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001963}
Harald Welte0472ab42018-03-12 15:02:26 +01001964
Eric Wildae8f2622019-06-18 17:05:11 +02001965function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
1966 timer T := 8.0;
1967 T.start;
1968 var RSL_Message rsl;
1969 alt {
1970 [] as_l1_sacch();
1971 [] L1CTL.receive { repeat; }
1972 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
1973 if (rsl.ies[3].body.bs_power.power_level == level) {
1974 setverdict(pass)
1975 } else {
1976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
1977 }
1978 }
1979 [] T.timeout {
1980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
1981 }
1982 }
1983}
1984
1985/* see if the rsl meas res contains our expeced bs power level
1986bs power set during assignment */
1987function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
1988 f_l1_tune(L1CTL);
1989 RSL.clear;
1990
1991 if (mp_bts_trxc_port != -1) {
1992 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
1993 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1994 }
1995
1996 var uint5_t pwr_var := 1;
1997 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
1998 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
1999
2000 f_est_dchan(more_ies :={valueof(pwr)});
2001
2002 f_check_meas_bs_power_level(pwr_var);
2003
2004 f_rsl_chan_deact();
2005 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2006}
2007
2008/* see if the rsl meas res contains our expeced bs power level
2009bs power set after assignment */
2010function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2011 f_l1_tune(L1CTL);
2012 RSL.clear;
2013
2014 if (mp_bts_trxc_port != -1) {
2015 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2016 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2017 }
2018
2019 var uint5_t pwr_var := 1;
2020 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2021
2022 f_est_dchan();
2023
2024 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2025
2026 f_check_meas_bs_power_level(pwr_var);
2027
2028 f_rsl_chan_deact();
2029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2030}
2031
2032testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2033 var ConnHdlr vc_conn;
2034 var ConnHdlrPars pars;
2035 f_init();
2036 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2037 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2038 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2039 pcu_comp := false, trxc_comp := true);
2040 vc_conn.done;
2041 }
2042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2043}
2044
2045testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2046 var ConnHdlr vc_conn;
2047 var ConnHdlrPars pars;
2048 f_init();
2049 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2050 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2051 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2052 pcu_comp := false, trxc_comp := true);
2053 vc_conn.done;
2054 }
2055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2056}
2057
Eric Wild61edb7e2019-06-03 12:38:31 +02002058/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2059second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2060These power levels are valid for all bands and require no special handling */
2061function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2062 var uint5_t pwr_var := 7;
2063 var L1ctlDlMessage l1_dl;
2064
2065 f_trxc_fake_rssi(rxlev2dbm(10));
2066 f_l1_tune(L1CTL);
2067 RSL.clear;
2068
2069 var RSL_IE_List addl_ies;
2070 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2071
2072 addl_ies := {
2073 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2074 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2075 };
2076
2077 /* establish with power parameters */
2078 f_est_dchan(more_ies := addl_ies);
2079
2080 /* set a high value to ensure L1 power control level increases */
2081 f_trxc_fake_rssi(rxlev2dbm(20));
2082
2083 timer T2 := 6.0;
2084 T2.start;
2085 alt {
2086 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002087 /* Update sent MS power to follow what BTS requests */
2088 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2089 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002090 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002091 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002092 T2.stop;
2093 }
2094 [] L1CTL.receive { repeat; }
2095 [] T2.timeout {
2096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2097 "Power Level in L1 header has not increased sufficiently");
2098 }
2099 }
2100
2101 /* set a low value to ensure L1 power control level decreases */
2102 f_trxc_fake_rssi(rxlev2dbm(0));
2103
2104 timer T4 := 6.0;
2105 T4.start;
2106 alt {
2107 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002108 /* Update sent MS power to follow what BTS requests */
2109 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2110 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002111 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002112 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002113 T4.stop;
2114 setverdict(pass, "Power level in L1 decreased/increased as expected");
2115 }
2116 [] L1CTL.receive { repeat; }
2117 [] T4.timeout {
2118 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2119 "Power Level in L1 header has not decreased sufficiently");
2120 }
2121 }
2122
2123 f_rsl_chan_deact();
2124 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2125
2126}
2127
2128/* check that we do not exceed the max power */
2129function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2130 var uint5_t pwr_var := 7;
2131 var L1ctlDlMessage l1_dl;
2132
2133 /* set a low value to ensure power increases */
2134 f_trxc_fake_rssi(rxlev2dbm(10));
2135 f_l1_tune(L1CTL);
2136 RSL.clear;
2137
2138 var RSL_IE_List addl_ies;
2139 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2140
2141 addl_ies := {
2142 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2143 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2144 };
2145
2146 /* establish with power parameters */
2147 f_est_dchan(more_ies := addl_ies);
2148
2149 timer T1 := 10.0;
2150 T1.start;
2151 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002152 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2153 /* Update sent MS power to follow what BTS requests */
2154 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2155 repeat;
2156 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002157 [] L1CTL.receive { repeat; }
2158 [] T1.timeout {
2159 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2160 setverdict(fail, "Power level in L1 header should not have changed");
2161 }
2162 }
2163 }
2164
2165 f_rsl_chan_deact();
2166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2167
2168}
2169
2170/* see if we reach the band max power */
2171function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2172 var L1ctlDlMessage l1_dl;
2173 var uint5_t pwr_var := 15;
2174 var uint5_t pwr_max_var := f_get_max_power_from_band();
2175
2176 /* set a low value to ensure power increases */
2177 f_trxc_fake_rssi(rxlev2dbm(10));
2178 f_l1_tune(L1CTL);
2179 RSL.clear;
2180
2181 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2182 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2183
2184 /* establish with fixed power level */
2185 f_est_dchan(more_ies :={valueof(pwr)});
2186
2187 /* check our initial power level */
2188 f_wait_for_l1_power_level(pwr_var);
2189
2190 /* update power param to enable power loop
2191 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2192 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2193
2194 /* wait, then check that our power level was reduced */
2195 timer T1 := 10.0;
2196 T1.start;
2197 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002198 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2199 /* Update sent MS power to follow what BTS requests */
2200 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2201 repeat;
2202 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002203 [] L1CTL.receive { repeat; }
2204 [] T1.timeout {
2205 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2206 if( f_power_level_is_highest_dbm(rcv) ){
2207 setverdict(pass, "Power level in L1 header reduced as expected");
2208 } else {
2209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2210 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2211 }
2212 }
2213 }
2214
2215 f_rsl_chan_deact();
2216 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2217
2218}
2219
2220/* see if we reach the band min power */
2221function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2222 var L1ctlDlMessage l1_dl;
2223
2224 /* set a high value to ensure power decreases */
2225 f_trxc_fake_rssi(rxlev2dbm(50));
2226 f_l1_tune(L1CTL);
2227 RSL.clear;
2228
2229 var uint5_t pwr_var := 5;
2230 var uint5_t pwr_target_val := 15;
2231
2232 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2233 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2234
2235 /* establish with fixed power level */
2236 f_est_dchan(more_ies :={valueof(pwr)});
2237
2238 /* check our initial power level */
2239 f_wait_for_l1_power_level(pwr_var);
2240
2241 /* update power param to enable power loop
2242 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002243 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002244
2245 /* wait, then check that our power level was increased */
2246 timer T1 := 10.0;
2247 T1.start;
2248 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002249 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2250 /* Update sent MS power to follow what BTS requests */
2251 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2252 repeat;
2253 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002254 [] L1CTL.receive { repeat; }
2255 [] T1.timeout {
2256 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2257 setverdict(pass, "Power level in L1 header increased to lowest power value");
2258 } else {
2259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2260 "Power level in L1 header NOT increased to lowest power value");
2261 }
2262 }
2263 }
2264
2265 f_rsl_chan_deact();
2266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2267
2268}
2269
Eric Wild095024b2019-06-17 15:08:57 +02002270/* see if we change the power level without receiving power parameters, which should not happen
2271rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002272function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2273 var L1ctlDlMessage l1_dl;
2274
2275 /* set a high value to ensure power decreases */
2276 f_trxc_fake_rssi(rxlev2dbm(50));
2277 f_l1_tune(L1CTL);
2278 RSL.clear;
2279
2280 var uint5_t pwr_var := 5;
2281
2282 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2283 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2284
2285 /* establish with fixed power level */
2286 f_est_dchan(more_ies :={valueof(pwr)});
2287
2288 /* check our initial power level */
2289 f_wait_for_l1_power_level(pwr_var);
2290
2291 /* wait, then check that our power level did not change */
2292 timer T1 := 10.0;
2293 T1.start;
2294 alt {
2295 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2296 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2298 "BS power control should not be active unless we receive a power parameters IE!");
2299 }
2300 repeat;
2301 }
2302 [] L1CTL.receive { repeat; }
2303 [] T1.timeout { setverdict(pass); }
2304 }
2305
2306 f_rsl_chan_deact();
2307 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2308
2309}
2310
Eric Wild095024b2019-06-17 15:08:57 +02002311/* see if we change the power level without receiving power parameters, which should not happen
2312ms power control WITHOUT power parameters */
2313function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2314 var L1ctlDlMessage l1_dl;
2315
2316 /* set a high value to ensure power decreases */
2317 f_trxc_fake_rssi(rxlev2dbm(50));
2318 f_l1_tune(L1CTL);
2319 RSL.clear;
2320
2321 var uint5_t pwr_var := 5;
2322
2323 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2324 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2325
2326 /* establish with fixed power level */
2327 f_est_dchan(more_ies :={valueof(pwr)});
2328
2329 /* check our initial power level */
2330 f_wait_for_l1_power_level(pwr_var);
2331
2332 /* pwr control without power params IE, should NOT activate MS power control*/
2333 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2334
2335 /* wait, then check that our power level did not change */
2336 timer T1 := 10.0;
2337 T1.start;
2338 alt {
2339 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2340 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2342 "BS power control should not be active unless we receive a power parameters IE!");
2343 }
2344 repeat;
2345 }
2346 [] L1CTL.receive { repeat; }
2347 [] T1.timeout { setverdict(pass); }
2348 }
2349
2350 f_rsl_chan_deact();
2351 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2352
2353}
2354
Eric Wild61edb7e2019-06-03 12:38:31 +02002355function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2356 var L1ctlDlMessage l1_dl;
2357 timer T0 := 10.0;
2358 T0.start;
2359 alt {
2360 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2361 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2363 "Power level in L1 header != signaled (RSL) power level.");
2364 }
2365 }
2366 [] L1CTL.receive { repeat; }
2367 [] T0.timeout {
2368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2369 "Timeout waiting for initial power level");
2370 }
2371 }
2372 T0.stop;
2373}
2374
2375private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2376 var IntegerRecord min_dbm_level;
2377 var IntegerRecord max_dbm_level;
2378 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2379
2380 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2381 if (min_dbm_level[i] == level) {
2382 return true;
2383 }
2384 }
2385 return false;
2386}
2387
2388private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2389 var IntegerRecord min_dbm_level;
2390 var IntegerRecord max_dbm_level;
2391 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2392
2393 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2394 if (max_dbm_level[i] == level) {
2395 return true;
2396 }
2397 }
2398 return false;
2399}
2400
2401private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2402 var IntegerRecord min_dbm_level;
2403 var IntegerRecord max_dbm_level;
2404 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2405 return max_dbm_level[0];
2406}
2407
2408type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2409template charstring BtsBand_allGSM:= pattern "GSM???";
2410private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2411 // 45.005 4.1.1
2412 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2413 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2414 2, 1, 0};
2415 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2416 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2417 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2418 var IntegerRecord rv;
2419
2420 select(band){
2421 case (BtsBand_allGSM){
2422 rv := gsm_power;
2423 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2424 max_dbm_level := {2, 1, 0};
2425 }
2426 case("DCS1800"){
2427 rv := dcs_power;
2428 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2429 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2430 }
2431 case("PCS1900"){
2432 rv := pcs_power;
2433 min_dbm_level := {15};
2434 max_dbm_level := {30};
2435 }
2436 }
2437
2438 return rv;
2439}
2440
2441private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2442 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2443}
2444
2445testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2446 var ConnHdlr vc_conn;
2447 var ConnHdlrPars pars;
2448 f_init();
2449 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2450 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2451 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2452 pars.bts0_band := f_vty_get_bts0_band();
2453 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2454 vc_conn.done;
2455 }
2456 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2458}
2459
2460testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2461 var ConnHdlr vc_conn;
2462 var ConnHdlrPars pars;
2463 f_init();
2464 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2465 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2466 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2467 pars.bts0_band := f_vty_get_bts0_band();
2468 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2469 vc_conn.done;
2470 }
2471 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2473}
2474
2475testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2476 var ConnHdlr vc_conn;
2477 var ConnHdlrPars pars;
2478 f_init();
2479 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2480 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2481 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2482 pars.bts0_band := f_vty_get_bts0_band();
2483 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2484 vc_conn.done;
2485 }
2486 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2488}
2489
2490testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2491 var ConnHdlr vc_conn;
2492 var ConnHdlrPars pars;
2493 f_init();
2494 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2495 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2496 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2497 pars.bts0_band := f_vty_get_bts0_band();
2498 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2499 vc_conn.done;
2500 }
2501 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2503}
2504
Eric Wild280ccb82019-06-17 11:11:52 +02002505testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2506 var ConnHdlr vc_conn;
2507 var ConnHdlrPars pars;
2508 f_init();
2509 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2510 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2511 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2512 pars.bts0_band := f_vty_get_bts0_band();
2513 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2514 vc_conn.done;
2515 }
2516 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2518}
2519
Eric Wild095024b2019-06-17 15:08:57 +02002520testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2521 var ConnHdlr vc_conn;
2522 var ConnHdlrPars pars;
2523 f_init();
2524 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2525 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2526 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2527 pars.bts0_band := f_vty_get_bts0_band();
2528 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2529 vc_conn.done;
2530 }
2531 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2533}
2534
Harald Welte70767382018-02-21 12:16:40 +01002535testcase TC_meas_res_sign_tchf() runs on test_CT {
2536 var ConnHdlr vc_conn;
2537 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002538 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002539 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2540 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002541 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2542 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002543 vc_conn.done;
2544 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002546}
2547testcase TC_meas_res_sign_tchh() runs on test_CT {
2548 var ConnHdlr vc_conn;
2549 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002550 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002551 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2552 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002553 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2554 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002555 vc_conn.done;
2556 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002558}
2559testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2560 var ConnHdlr vc_conn;
2561 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002562 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002563 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2564 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002565 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2566 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002567 vc_conn.done;
2568 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002570}
2571testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2572 var ConnHdlr vc_conn;
2573 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002574 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002575 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2576 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002577 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2578 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002579 vc_conn.done;
2580 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002582}
Harald Welte685d5982018-02-27 20:42:05 +01002583testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2584 var ConnHdlr vc_conn;
2585 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002586 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002587 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2588 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2589 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2590 pars.l1_pars.toa256_enabled := true;
2591 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2592 vc_conn.done;
2593 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002595}
2596
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002597/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2598 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2599function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2600 var L1ctlDlMessage l1_dl;
2601 var RSL_IE_MS_Power ms_power;
2602 var RSL_Message rsl;
2603 var uint5_t power_level := 0;
2604
2605 f_l1_tune(L1CTL);
2606 RSL.clear;
2607
2608 f_est_dchan();
2609
2610 ms_power.reserved := 0;
2611 ms_power.fpc_epc := false;
2612
2613 /* Send the first power control command. This will disable any BTS/TRX
2614 * internal power control and switch the MS (which is not in scope of
2615 * this test) to a constant power level. We start with a power level
2616 * of 0 */
2617 ms_power.power_level := power_level;
2618 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2619 RSL.send(rsl);
2620
2621 alt {
2622
2623 /* Pick all SACCH blocks for checking */
2624 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2625
2626 /* The first byte of the L1 header contains the power level.
2627 * The reserved bits and the fpc bit is set to 0, so we may
2628 * compare directly. */
2629 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2630 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2631 }
2632
2633 /* Signal a new power level via RSL for the next turn. */
2634 if (power_level < 31) {
2635 power_level := power_level + 1;
2636 ms_power.power_level := power_level;
2637 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2638 RSL.send(rsl);
2639 repeat;
2640 }
2641
2642 }
2643
2644 /* Ignore all other blocks */
2645 [] L1CTL.receive { repeat; }
2646
2647 }
2648
2649 f_rsl_chan_deact();
2650 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2651
2652 setverdict(pass);
2653}
2654
2655testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2656 var ConnHdlr vc_conn;
2657 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002658 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002659
2660 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2661 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2662 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2663 vc_conn.done;
2664 }
2665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2666}
Harald Welte70767382018-02-21 12:16:40 +01002667
Eric Wild6833cc92019-05-23 19:34:44 +02002668/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2669TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2670function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2671 var L1ctlDlMessage l1_dl;
2672 var uint5_t ta_to_test := 16;
2673
2674
2675 f_l1_tune(L1CTL);
2676 RSL.clear;
2677
2678 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002679 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002680
2681 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2682
2683
2684 alt {
2685
2686 /* Pick all SACCH blocks for checking */
2687 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2688
2689 /* The second byte of the L1 header contains the TA. */
2690 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2691 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2692 }
2693
2694 }
2695
2696 /* Ignore all other blocks */
2697 [] L1CTL.receive { repeat; }
2698
2699 }
2700
2701 f_rsl_chan_deact();
2702 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2703
2704 setverdict(pass);
2705}
2706
2707testcase TC_rsl_chan_initial_ta() runs on test_CT {
2708 var ConnHdlr vc_conn;
2709 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002710 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002711 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002712 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2713 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002714 vc_conn.done;
2715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2716}
2717
Eric Wilde57e1a62019-05-28 13:30:55 +02002718/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2719function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2720 var L1ctlDlMessage l1_dl;
2721 var uint5_t ms_power_level := 7;
2722
2723 var RSL_IE_MS_Power ms_power;
2724 ms_power.reserved := 0;
2725 ms_power.fpc_epc := false;
2726 ms_power.power_level := ms_power_level;
2727
2728 f_l1_tune(L1CTL);
2729 RSL.clear;
2730
2731 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2732
2733 timer T := 1.0;
2734 T.start;
2735 alt {
2736 /* Pick all SACCH blocks for checking */
2737 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2738 /* The first byte of the L1 header contains the power level.. */
2739 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2740 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2741 }
2742 }
2743 /* Ignore all other blocks */
2744 [] L1CTL.receive { repeat; }
2745 [] T.timeout {
2746 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2747 }
2748 }
2749
2750 f_rsl_chan_deact();
2751 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2752 setverdict(pass);
2753}
2754
2755testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2756 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2757 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2758}
2759
Harald Welte0472ab42018-03-12 15:02:26 +01002760/* 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 +01002761private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002762 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002763 RSL.clear;
2764
2765 f_est_dchan();
2766 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002767 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002768
2769 timer T := 40.0;
2770 T.start;
2771 alt {
2772 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2773 setverdict(pass)
2774 }
2775 [] RSL.receive { repeat };
2776 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002778 }
2779 }
2780 f_rsl_chan_deact();
2781}
2782testcase TC_conn_fail_crit() runs on test_CT {
2783 var ConnHdlr vc_conn;
2784 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002785 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002786 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2787 pars.t_guard := 60.0;
2788 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2789 vc_conn.done;
2790}
2791
Harald Welte93640c62018-02-25 16:59:33 +01002792/***********************************************************************
2793 * Paging
2794 ***********************************************************************/
2795
Harald Welte68e495b2018-02-25 00:05:57 +01002796function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2797 if (tmsi == 'FFFFFFFF'O) {
2798 return true;
2799 } else {
2800 return false;
2801 }
2802}
Harald Welte70767382018-02-21 12:16:40 +01002803
Philipp Maier82cb0b12018-08-31 14:41:39 +02002804type record allowedFn { integer frame_nr }
2805template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2806template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2807template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2808template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2809template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2810template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2811template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2812template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2813function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2814{
2815 var integer frame_nr_51;
2816 frame_nr_51 := frame_nr mod 51
2817
2818 var allowedFn fn_check;
2819 fn_check.frame_nr := frame_nr_51;
2820
2821 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002823 return;
2824 }
2825
2826 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2827 return;
2828 }
2829 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2830 return;
2831 }
2832 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2833 return;
2834 }
2835 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2836 return;
2837 }
2838 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2839 return;
2840 }
2841 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2842 return;
2843 }
2844 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2845 return;
2846 }
2847 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2848 return;
2849 }
2850
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002852 return;
2853}
2854
2855altstep 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 +01002856runs on test_CT {
2857 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002858 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002859 repeat;
2860 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002861 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002862 var octetstring without_plen :=
2863 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2864 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002865
2866 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2867
Harald Welte68e495b2018-02-25 00:05:57 +01002868 if (match(rr, tr_PAGING_REQ1)) {
2869 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2870 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2871 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2872 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2873 }
2874 } else if (match(rr, tr_PAGING_REQ2)) {
2875 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2876 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2877 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2878 }
2879 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2880 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2881 }
2882 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2883 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2884 }
2885 } else if (match(rr, tr_PAGING_REQ3)) {
2886 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2887 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2889 }
2890 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2891 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2892 }
2893 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2894 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2895 }
2896 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2897 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2898 }
2899 }
2900 repeat;
2901 }
2902}
2903
2904type record PagingTestCfg {
2905 boolean combined_ccch,
2906 integer bs_ag_blks_res,
2907 float load_factor,
2908 boolean exp_load_ind,
2909 boolean exp_overload,
2910 boolean use_tmsi
2911}
2912
2913type record PagingTestState {
2914 integer num_paging_sent,
2915 integer num_paging_rcv_msgs,
2916 integer num_paging_rcv_ids,
2917 integer num_overload
2918}
2919
2920/* receive + ignore RSL RF RES IND */
2921altstep as_rsl_res_ind() runs on test_CT {
2922 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2923 repeat;
2924 }
2925}
2926
2927/* Helper function for paging related testing */
2928private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002929 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002930 f_init_l1ctl();
2931 f_l1_tune(L1CTL);
2932
2933 var PagingTestState st := {
2934 num_paging_sent := 0,
2935 num_paging_rcv_msgs := 0,
2936 num_paging_rcv_ids := 0,
2937 num_overload := 0
2938 };
2939
2940 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2941 var float max_pch_imsi_per_sec;
2942 if (cfg.use_tmsi) {
2943 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2944 } else {
2945 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2946 }
2947 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2948 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002949 var float time_total := 20.0;
2950 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2951 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002952
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002953 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2954 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002955
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002956 timer T_itv := 0.0;
2957 T_itv.start;
2958 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002959 alt {
2960 /* check for presence of CCCH LOAD IND (paging load) */
2961 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2962 st.num_overload := st.num_overload + 1;
2963 repeat;
2964 }
2965 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002967 }
2968 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2969 log("Rx LOAD_IND");
2970 /* FIXME: analyze/verify interval + contents */
2971 repeat;
2972 }
2973 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002974 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002975 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002976 [] T_itv.timeout {
2977 /* Send paging cmds based on elapsed time */
2978 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2979 while (st.num_paging_sent < new_sent) {
2980 /* build mobile Identity */
2981 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2982 if (cfg.use_tmsi) {
2983 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2984 } else {
2985 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2986 }
2987 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2988 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2989
2990 /* Send RSL PAGING COMMAND */
2991 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2992
2993 st.num_paging_sent := st.num_paging_sent + 1;
2994 }
2995 if (st.num_paging_sent < pkt_total) {
2996 /* Wait for interval to next PAGING COMMAND */
2997 var float time_now := T_total.read;
2998 var float next_sched := int2float(st.num_paging_sent)*interval;
2999 if (next_sched > time_now) {
3000 T_itv.start(next_sched - time_now);
3001 } else {
3002 T_itv.start(0.0);
3003 }
3004 } else {
3005 /* We are done, no need to keep counting */
3006 T_total.stop;
3007 }
3008 }
3009 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003010 [] as_rsl_res_ind();
3011 }
3012 }
3013
3014 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3015 timer T_wait := 18.0;
3016 T_wait.start;
3017 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003018 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003019 [] L1CTL.receive { repeat; }
3020 /* 65535 == empty paging queue, we can terminate*/
3021 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3022 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
3023 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003025 }
3026 [] as_rsl_res_ind();
3027 }
3028
3029 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3030 " rcvd_ids=", st.num_paging_rcv_ids);
3031 return st;
3032}
3033
3034/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3035 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3036 * - that CCCH LOAD IND (PCH) are being generated
3037 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3038testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003039 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003040 var PagingTestCfg cfg := {
3041 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003042 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003043 load_factor := 0.8,
3044 exp_load_ind := true,
3045 exp_overload := false,
3046 use_tmsi := false
3047 };
3048 var PagingTestState st := f_TC_paging(cfg);
3049 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3051 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003052 } else {
3053 setverdict(pass);
3054 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003056}
3057
3058/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3059 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3060 * - that CCCH LOAD IND (PCH) are being generated
3061 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3062testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003063 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003064 var PagingTestCfg cfg := {
3065 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003066 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003067 load_factor := 0.8,
3068 exp_load_ind := true,
3069 exp_overload := false,
3070 use_tmsi := true
3071 };
3072 var PagingTestState st := f_TC_paging(cfg);
3073 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3075 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003076 } else {
3077 setverdict(pass);
3078 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003080}
3081
3082/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3083 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3084 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3085 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3086testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003087 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003088 var PagingTestCfg cfg := {
3089 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003090 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003091 load_factor := 2.0,
3092 exp_load_ind := true,
3093 exp_overload := true,
3094 use_tmsi := false
3095 };
3096 var PagingTestState st := f_TC_paging(cfg);
3097 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3098 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003099 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003100 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003101 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 +01003102 } else {
3103 setverdict(pass);
3104 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003106}
3107
3108/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3109 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3110 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3111 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3112testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003113 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003114 var PagingTestCfg cfg := {
3115 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003116 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003117 load_factor := 2.0,
3118 exp_load_ind := true,
3119 exp_overload := true,
3120 use_tmsi := true
3121 };
3122 var PagingTestState st := f_TC_paging(cfg);
3123 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3124 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003125 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003126 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003127 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 +01003128 } else {
3129 setverdict(pass);
3130 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003132}
3133
3134
Harald Welte93640c62018-02-25 16:59:33 +01003135/***********************************************************************
3136 * Immediate Assignment / AGCH
3137 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02003138const MobileAllocation c_MA_null := {
3139 len := 0,
3140 ma := ''B
3141}
Harald Welte93640c62018-02-25 16:59:33 +01003142
Harald Weltee8d750e2018-06-10 21:41:35 +02003143template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3144 uint12_t arfcn := 871) := {
3145 chan_nr := chan_nr,
3146 tsc := tsc,
3147 h := false,
3148 arfcn := arfcn,
3149 maio_hsn := omit
3150}
3151
3152private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3153 return int2str(num_tx) & " sent, "
3154 & int2str(num_rx) & " received, "
3155 & int2str(num_del) & " deleted";
3156}
3157
3158private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3159 var L1ctlDlMessage l1_dl;
3160 timer T := 10.0;
3161 var integer num_tx := 0;
3162 var integer num_rx := 0;
3163 var integer num_del := 0;
3164 var charstring res_str;
3165 var float rx_ratio;
3166
Harald Welte10474062019-05-30 16:48:17 +02003167 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003168 f_init_l1ctl();
3169 f_l1_tune(L1CTL);
3170
3171 for (var integer i := 0; i < num_total; i := i+1) {
3172 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
3173 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3174 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01003175 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003176 num_tx := num_tx+1;
3177 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003178 }
3179 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003180 T.start;
3181 alt {
3182 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
3183 num_del := num_del+1;
3184 repeat;
3185 }
3186 [] RSL_CCHAN.receive {
3187 repeat;
3188 }
3189 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3190 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3191 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3192 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3193 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003194 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003195 } else {
3196 num_rx := num_rx+1;
3197 }
3198 repeat;
3199 }
3200 [] L1CTL.receive { repeat; }
3201 [] T.timeout { }
3202 }
3203 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3204 log("AGCH test: " & res_str);
3205 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003207 }
3208 rx_ratio := int2float(num_rx) / int2float(num_tx);
3209 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003210 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 +02003211 } else {
3212 setverdict(pass);
3213 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003215}
3216
Harald Weltee8d750e2018-06-10 21:41:35 +02003217/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3218testcase TC_imm_ass_1000_20ms() runs on test_CT {
3219 f_TC_imm_ass(1000, 0.02, 0.25);
3220}
3221
3222/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3223testcase TC_imm_ass_200_0ms() runs on test_CT {
3224 f_TC_imm_ass(200, 0.0, 0.05);
3225}
3226
3227/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3228testcase TC_imm_ass_200_76ms() runs on test_CT {
3229 f_TC_imm_ass(150, 0.076, 1.00);
3230}
3231
3232
3233
Harald Welte48494ca2018-02-25 16:59:50 +01003234/***********************************************************************
3235 * BCCH
3236 ***********************************************************************/
3237
3238/* tuple of Frame Number + decoded SI */
3239type record SystemInformationFn {
3240 GsmFrameNumber frame_number,
3241 SystemInformation si
3242}
3243
3244/* an arbitrary-length vector of decoded SI + gsmtap header */
3245type record of SystemInformationFn SystemInformationVector;
3246
3247/* an array of SI-vectors indexed by TC value */
3248type SystemInformationVector SystemInformationVectorPerTc[8];
3249
3250/* determine if a given SI vector contains given SI type at least once */
3251function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3252 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3253 var integer fn_mod51 := arr[i].frame_number mod 51;
3254 if (not bcch_ext and fn_mod51 == 2 or
3255 bcch_ext and fn_mod51 == 6) {
3256 if (arr[i].si.header.message_type == key) {
3257 return true;
3258 }
3259 }
3260 }
3261 return false;
3262}
3263
3264/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3265function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3266 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003268 }
3269}
3270
3271/* check if a given SI vector contains given SI type at least once on any TC */
3272function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3273 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3274 if (f_si_vecslot_contains(arr[tc], key) or
3275 f_si_vecslot_contains(arr[tc], key, true)) {
3276 return true;
3277 }
3278 }
3279 return false;
3280}
3281
3282/* determine if a given SI vector contains given SI type at least N of M times */
3283function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3284 var integer count := 0;
3285 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003287 }
3288 for (var integer i:= 0; i < m; i := i + 1) {
3289 var integer fn_mod51 := arr[i].frame_number mod 51;
3290 if (not bcch_ext and fn_mod51 == 2 or
3291 bcch_ext and fn_mod51 == 6) {
3292 if (arr[i].si.header.message_type == key) {
3293 count := count + 1;
3294 }
3295 }
3296 }
3297 if (count >= n) {
3298 return true;
3299 } else {
3300 return false;
3301 }
3302}
3303
3304/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3305function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3306 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003308 }
3309}
3310
3311/* determine if a given SI vector contains given SI type at least once */
3312function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3313 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3314 var integer fn_mod51 := arr[i].frame_number mod 51;
3315 if (not bcch_ext and fn_mod51 == 2 or
3316 bcch_ext and fn_mod51 == 6) {
3317 if (arr[i].si.header.message_type != key) {
3318 return false;
3319 }
3320 }
3321 }
3322 return true;
3323}
3324
3325/* ensure a given TC slot of the SI vector contains only given SI type */
3326function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3327 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003329 }
3330}
3331
3332/* SI configuration of cell, against which we validate actual SI messages */
3333type set SystemInformationConfig {
3334 boolean bcch_extended,
3335 boolean si1_present,
3336 boolean si2bis_present,
3337 boolean si2ter_present,
3338 boolean si2quater_present,
3339 boolean si7_present,
3340 boolean si8_present,
3341 boolean si9_present,
3342 boolean si13_present,
3343 boolean si13alt_present,
3344 boolean si15_present,
3345 boolean si16_present,
3346 boolean si17_present,
3347 boolean si2n_present,
3348 boolean si21_present,
3349 boolean si22_present
3350}
3351
3352/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3353function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3354 var integer i;
3355 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3356 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003358 }
3359 }
3360 if (cfg.si1_present) {
3361 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3362 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3363 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3364 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3365 /* make sure *ALL* contain SI1 */
3366 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3367 }
3368 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3369 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3370 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3371 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3372 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3373 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3374
3375 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3376 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3377 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3378 * consecutive occurrences of TC = 4. */
3379 if (cfg.si2bis_present and not cfg.si2ter_present) {
3380 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3381 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3382 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3383 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3384 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3385 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3386 }
3387
3388 if (cfg.si7_present or cfg.si8_present) {
3389 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3390 * if System Information type 4 does not contain all information needed for cell
3391 * selection and reselection. */
3392 if (not cfg.bcch_extended) {
3393 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3394 }
3395 if (cfg.si7_present) {
3396 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3397 }
3398 if (cfg.si8_present) {
3399 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3400 }
3401 }
3402
3403 if (cfg.si2quater_present) {
3404 /* iii) System information type 2 quater is sent if needed, as determined by the system
3405 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3406 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3407 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3408 * within any of 4 consecutive occurrences of TC = 5. */
3409 if (not (cfg.bcch_extended)) {
3410 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3411 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3412 } else {
3413 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3414 }
3415 } else {
3416 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3417 }
3418 }
3419 if (cfg.si9_present) {
3420 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3421 * in system information type 3 as defined in 3GPP TS 44.018. */
3422 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3423 }
3424 if (cfg.si13_present) {
3425 /* vii) System Information type 13 is only related to the GPRS service. System Information
3426 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3427 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3428 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3429 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3430 * within any of 4 consecutive occurrences of TC=4. */
3431 if (not cfg.bcch_extended) {
3432 log("not-bccch-extended");
3433 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3434 } else {
3435 log("bccch-extended");
3436 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3437 }
3438 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003440 }
3441 }
3442 if (cfg.si16_present or cfg.si17_present) {
3443 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3444 * should not be sent in a cell where network sharing is used (see rule xv). */
3445 if (cfg.si22_present) {
3446 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3447 }
3448 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003450 }
3451 if (not cfg.bcch_extended) {
3452 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3453 }
3454 if (cfg.si16_present) {
3455 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3456 }
3457 if (cfg.si17_present) {
3458 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3459 }
3460 }
3461
3462 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3463 * broadcast information. The frequency with which they are sent is determined by the
3464 * system operator. System Information type 9 identifies the scheduling of System
3465 * Information type 18 and 20 messages. */
3466
3467 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3468 * Information Type 19 is present, then its scheduling shall be indicated in System
3469 * Information Type 9. */
3470
3471 if (cfg.si15_present) {
3472 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3473 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3474 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3475 * 4 consecutive occurrences of TC = 1. */
3476 if (not cfg.bcch_extended) {
3477 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3478 } else {
3479 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3480 }
3481 }
3482 if (cfg.si13alt_present) {
3483 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3484 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3485 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3486 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3487 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3488 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3489 * of TC = 4. */
3490 if (cfg.si13_present) {
3491 testcase.stop("Error: Cannot have SI13alt and SI13");
3492 }
3493 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003495 }
3496 if (not cfg.bcch_extended) {
3497 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3498 } else {
3499 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3500 }
3501 }
3502 if (cfg.si2n_present) {
3503 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3504 * as determined by the system operator. In the case that the message is sent on the
3505 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3506 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3507 * consecutive occurrences of TC = 4. */
3508 if (not cfg.bcch_extended) {
3509 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3510 } else {
3511 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3512 }
3513 }
3514 if (cfg.si21_present) {
3515 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3516 * determined by the system operator. If Extended Access Barring is in use in the cell
3517 * then this message is sent at least once within any of 4 consecutive occurrences of
3518 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3519 * cell then this message shall only be sent on BCCH Ext. */
3520 if (not cfg.bcch_extended) {
3521 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3522 } else {
3523 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3524 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003526 }
3527 }
3528 }
3529 if (cfg.si22_present) {
3530 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3531 * should not be sent in a cell where SoLSA is used (see rule viii). System
3532 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3533 * =2 and TC=6. */
3534 if (cfg.si16_present or cfg.si17_present) {
3535 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3536 }
3537 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3538 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003540 }
3541 if (not cfg.bcch_extended) {
3542 testcase.stop("Error: SI22 requires BCCH Extd!");
3543 } else {
3544 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3545 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3546 }
3547 }
3548}
3549
3550/* sample Systme Information for specified duration via L1CTL */
3551function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3552 timer T := duration;
3553 var SystemInformationVectorPerTc si_per_tc;
3554 var L1ctlDlMessage l1_dl;
3555
3556 /* initialize all per-TC vectors empty */
3557 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3558 si_per_tc[i] := {};
3559 }
3560
3561 /* flush all previous L1 queued msgs */
3562 pt.clear;
3563
3564 T.start;
3565 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003566 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003567 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3568 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3569 log("Ignoring non-RR SI ", l1_dl);
3570 repeat;
3571 }
3572 var SystemInformationFn sig := {
3573 frame_number := l1_dl.dl_info.frame_nr,
3574 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3575 }
3576 var integer tc := f_gsm_compute_tc(sig.frame_number);
3577 log("SI received at TC=", tc, ": ", sig.si);
3578 /* append to the per-TC bucket */
3579 si_per_tc[tc] := si_per_tc[tc] & { sig };
3580 repeat;
3581 }
3582 [] pt.receive { repeat; }
3583 [] T.timeout { }
3584 }
3585
3586 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3587 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3588 }
3589 log("si_per_tc=", si_per_tc);
3590 return si_per_tc;
3591}
3592
3593/* helper function: Set given SI via RSL + validate scheduling.
3594 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3595function f_TC_si_sched() runs on test_CT {
3596 var SystemInformationVectorPerTc si_per_tc;
3597 f_init_l1ctl();
3598 f_l1_tune(L1CTL);
3599
3600 /* Sample + Validate Scheduling */
3601 si_per_tc := f_l1_sample_si(L1CTL);
3602 f_validate_si_scheduling(si_cfg, si_per_tc);
3603
3604 setverdict(pass);
3605}
3606
3607testcase TC_si_sched_default() runs on test_CT {
3608 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003609 /* 2+3+4 are mandatory and set in f_init() */
3610 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003612}
3613
3614testcase TC_si_sched_1() runs on test_CT {
3615 f_init();
3616 si_cfg.si1_present := true;
3617 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003618 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003620}
3621
3622testcase TC_si_sched_2bis() runs on test_CT {
3623 f_init();
3624 si_cfg.si2bis_present := true;
3625 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3626 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003628}
3629
3630testcase TC_si_sched_2ter() runs on test_CT {
3631 f_init();
3632 si_cfg.si2ter_present := true;
3633 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3634 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003636}
3637
3638testcase TC_si_sched_2ter_2bis() runs on test_CT {
3639 f_init();
3640 si_cfg.si2bis_present := true;
3641 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3642 si_cfg.si2ter_present := true;
3643 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3644 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003646}
3647
3648testcase TC_si_sched_2quater() runs on test_CT {
3649 f_init();
3650 si_cfg.si2quater_present := true;
3651 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3652 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003654}
3655
3656testcase TC_si_sched_13() runs on test_CT {
3657 f_init();
3658 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003659 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003660 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003662}
3663
3664testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3665 f_init();
3666 si_cfg.si2bis_present := true;
3667 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3668 si_cfg.si2ter_present := true;
3669 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3670 si_cfg.si2quater_present := true;
3671 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3672 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003673 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003674 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003676}
3677
3678
Harald Welte68e495b2018-02-25 00:05:57 +01003679testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003680 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003681 /* FIXME: enable / disable individual BCCH info */
3682 //ts_RSL_BCCH_INFO(si_type, info);
3683 /* expect no ERROR REPORT after either of them *
3684 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003686}
3687
Harald Welte93640c62018-02-25 16:59:33 +01003688/***********************************************************************
3689 * Low-Level Protocol Errors / ERROR REPORT
3690 ***********************************************************************/
3691
Harald Welte01d982c2018-02-25 01:31:40 +01003692private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3693 timer T := 5.0;
3694 T.start;
3695 alt {
3696 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3697 setverdict(pass);
3698 }
3699 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003701 }
3702 [] RSL_CCHAN.receive {
3703 repeat;
3704 }
3705 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003707 }
3708 }
3709}
3710
3711/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3712testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003713 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003714 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3715 rsl.ies := omit;
3716 RSL_CCHAN.send(ts_RSL_UD(rsl));
3717
3718 f_exp_err_rep(RSL_ERR_PROTO);
3719}
3720
3721/* Provoke a mandatory IE error and match on ERROR REPORT */
3722testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003723 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003724
3725 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3726 rsl.ies := { rsl.ies[0] };
3727 RSL_CCHAN.send(ts_RSL_UD(rsl));
3728
3729 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3730}
3731
3732/* Provoke an IE content error and match on ERROR REPORT */
3733testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003734 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003735 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3736 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3737 RSL_CCHAN.send(ts_RSL_UD(rsl));
3738
3739 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3740}
3741
Harald Welteee25aae2019-05-19 14:32:37 +02003742/* attempt to activate channel with wrong RSL Message Discriminator IE */
3743function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3744 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3745 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3746 RSL.send(rsl);
3747 f_rslem_unregister(0, g_chan_nr);
3748}
3749testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3750 var ConnHdlr vc_conn;
3751 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3752
Harald Welte10474062019-05-30 16:48:17 +02003753 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003754
3755 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3756 vc_conn.done;
3757 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3758
3759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3760}
3761
3762/* Send messages with wrong message type */
3763function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3764 var template (value) RSL_Message rsl_tx;
3765 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3766 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3767 RSL.send(rsl_tx);
3768 f_rslem_unregister(0, g_chan_nr);
3769}
3770function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3771 var template (value) RSL_Message rsl_tx;
3772 /* we first have to activate the dedicated channel */
3773 f_rsl_chan_act(g_pars.chan_mode);
3774 /* ... to then send an invalid RLL message */
3775 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3776 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3777 RSL.send(rsl_tx);
3778 f_rslem_unregister(0, g_chan_nr);
3779}
3780testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3781 var ConnHdlr vc_conn;
3782 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3783 var template (value) RSL_Message rsl_tx;
3784
Harald Welte10474062019-05-30 16:48:17 +02003785 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003786
3787 /* Common Channel with wrong message type */
3788 RSL_CCHAN.clear;
3789 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3790 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3791 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3792 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3793
3794 /* TRX Management */
3795 RSL_CCHAN.clear;
3796 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3797 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3798 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3799 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3800
3801 /* Dedicated Channel */
3802 RSL_CCHAN.clear;
3803 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3804 vc_conn.done;
3805 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3806
3807 /* RLL */
3808 RSL_CCHAN.clear;
3809 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3810 vc_conn.done;
3811 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3812}
3813
3814/* Send messages in wrong sequence (RLL to an inactive lchan) */
3815function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3816 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3817 f_rslem_unregister(0, g_chan_nr);
3818}
3819testcase TC_err_rep_wrong_sequence() runs on test_CT {
3820 var ConnHdlr vc_conn;
3821 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3822
Harald Welte10474062019-05-30 16:48:17 +02003823 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003824
3825 RSL_CCHAN.clear;
3826 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3827 vc_conn.done;
3828 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3829}
3830
Harald Welte93640c62018-02-25 16:59:33 +01003831/***********************************************************************
3832 * IPA CRCX/MDCX/DLCS media stream handling
3833 ***********************************************************************/
3834
Harald Weltea871a382018-02-25 02:03:14 +01003835/* Send IPA DLCX to inactive lchan */
3836function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003837 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3838 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003839}
3840testcase TC_ipa_dlcx_not_active() runs on test_CT {
3841 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003842 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003843 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3844 vc_conn.done;
3845}
Harald Welte68e495b2018-02-25 00:05:57 +01003846
Harald Weltea3f1df92018-02-25 12:49:55 +01003847/* Send IPA CRCX twice to inactive lchan */
3848function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3849 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3850 "IPA CRCX ACK");
3851 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3852 "IPA CRCX NACK");
3853}
3854testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3855 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003856 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003857 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3858 vc_conn.done;
3859}
3860
3861/* Regular sequence of CRCX/MDCX/DLCX */
3862function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3863 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3864 "IPA CRCX ACK");
3865 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3866 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3867 var uint7_t rtp_pt2 := f_rnd_int(127);
3868 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3869 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3870 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3871 "IPA MDCX ACK");
3872 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3873 "IPA DLCX ACK");
3874}
3875testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3876 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003877 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003878 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3879 vc_conn.done;
3880}
3881
Harald Welte3ae11da2018-02-25 13:36:06 +01003882/* Sequence of CRCX, 2x MDCX, DLCX */
3883function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3884 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3885 "IPA CRCX ACK");
3886 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3887 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3888 var uint7_t rtp_pt2 := f_rnd_int(127);
3889 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3890 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3891 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3892 "IPA MDCX ACK");
3893 /* Second MDCX */
3894 remote_ip := f_rnd_int(c_UINT32_MAX);
3895 remote_port := f_rnd_int(c_UINT16_MAX);
3896 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3897 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3898 "IPA MDCX ACK");
3899 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3900 "IPA DLCX ACK");
3901}
3902testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3903 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003904 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003905 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3906 vc_conn.done;
3907}
3908
Harald Welte9912eb52018-02-25 13:30:15 +01003909/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3910function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3911 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3912 "IPA CRCX NACK");
3913}
3914testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3915 var ConnHdlrPars pars;
3916 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003917 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003918
3919 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3920 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3921 vc_conn.done;
3922
3923 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3924 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3925 vc_conn.done;
3926}
3927
Harald Weltea3f1df92018-02-25 12:49:55 +01003928
Harald Welte883340c2018-02-28 18:59:29 +01003929/***********************************************************************
3930 * PCU Socket related tests
3931 ***********************************************************************/
3932
Harald Welte07bd2d22019-05-25 11:03:30 +02003933/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003934friend 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 +01003935runs on test_CT {
3936 timer T := 3.0;
3937
3938 /* we don't expect any RTS.req before PDCH are active */
3939 T.start;
3940 alt {
3941 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003943 }
3944 [] PCU.receive { repeat; }
3945 [] T.timeout { }
3946 }
3947
3948 /* Send PDCH activate request for known PDCH timeslot */
3949 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3950
3951 /* we now expect RTS.req for this timeslot (only) */
3952 T.start;
3953 alt {
3954 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3955 setverdict(pass);
3956 }
3957 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3958 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003960 }
3961 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003963 }
3964 [] PCU.receive { repeat; }
3965 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003967 }
3968 [not exp_success] T.timeout {
3969 setverdict(pass);
3970 }
3971 }
3972}
3973
Harald Welte07bd2d22019-05-25 11:03:30 +02003974/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003975friend 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 +01003976runs on test_CT {
3977 timer T := 3.0;
3978
3979 /* Send PDCH activate request for known PDCH timeslot */
3980 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3981
3982 PCU.clear;
3983 /* we now expect no RTS.req for this timeslot */
3984 T.start;
3985 alt {
3986 [] 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 +02003987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003988 }
3989 [] PCU.receive { repeat; }
3990 [] T.timeout {
3991 setverdict(pass);
3992 }
3993 }
3994}
3995
Harald Weltead033dc2019-05-25 17:28:16 +02003996friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003997 f_init();
3998 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3999}
4000
Harald Welte883340c2018-02-28 18:59:29 +01004001/* PDCH activation via PCU socket; check for presence of RTS.req */
4002testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004003 f_init_pcu_test();
4004
Harald Welte883340c2018-02-28 18:59:29 +01004005 f_TC_pcu_act_req(0, 0, 7, true);
4006}
4007
4008/* PDCH activation via PCU socket on non-PDCU timeslot */
4009testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004010 f_init_pcu_test();
4011
Harald Welte883340c2018-02-28 18:59:29 +01004012 f_TC_pcu_act_req(0, 0, 1, false);
4013}
4014
4015/* PDCH activation via PCU socket on wrong BTS */
4016testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004017 f_init_pcu_test();
4018
Harald Welte883340c2018-02-28 18:59:29 +01004019 f_TC_pcu_act_req(23, 0, 7, false);
4020}
4021
4022/* PDCH activation via PCU socket on wrong TRX */
4023testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004024 f_init_pcu_test();
4025
Harald Welte883340c2018-02-28 18:59:29 +01004026 f_TC_pcu_act_req(0, 23, 7, false);
4027}
4028
4029/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4030testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004031 f_init_pcu_test();
4032
Harald Welte883340c2018-02-28 18:59:29 +01004033 /* Activate PDCH */
4034 f_TC_pcu_act_req(0, 0, 7, true);
4035 f_sleep(1.0);
4036 /* and De-Activate again */
4037 f_TC_pcu_deact_req(0, 0, 7);
4038}
4039
4040/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4041testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004042 f_init_pcu_test();
4043
Harald Welte883340c2018-02-28 18:59:29 +01004044 f_TC_pcu_deact_req(0, 0, 1);
4045}
4046
4047/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4048testcase TC_pcu_ver_si13() runs on test_CT {
4049 const octetstring si13 := '00010203040506070909'O;
4050 var PCUIF_send_data sd;
4051 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004052 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004053
4054 /* Set SI13 via RSL */
4055 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004056
Harald Welte883340c2018-02-28 18:59:29 +01004057 T.start;
4058 alt {
4059 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4060 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4061 setverdict(pass);
4062 } else {
4063 repeat;
4064 }
4065 }
4066 [] PCU.receive { repeat; }
4067 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004069 }
4070 }
4071}
4072
4073private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4074
4075/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004076friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004077 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4078runs on test_CT
4079{
4080 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4081 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4082}
4083
4084/* 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 +02004085friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4086 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004087runs on test_CT
4088{
4089 var PCUIF_send_data sd;
4090
4091 timer T := 3.0;
4092 T.start;
4093 alt {
4094 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4095 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4096 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4097 sd.data.u.rts_req.fn, sapi, data);
4098 }
4099 [] PCU.receive { repeat; }
4100 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004102 }
4103 }
4104}
4105
4106/* Send DATA.req on invalid BTS */
4107testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004108 var TfiUsfArr tua := f_TfiUsfArrInit();
4109 var octetstring data := '0000'O & f_rnd_octstring(21);
4110
4111 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004112
Harald Welte883340c2018-02-28 18:59:29 +01004113 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004114 f_TfiUsfArrSet(tua, 7, 0);
4115 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4116 f_sleep(1.0);
4117
4118 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004119}
4120
4121/* Send DATA.req on invalid TRX */
4122testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004123 var TfiUsfArr tua := f_TfiUsfArrInit();
4124 var octetstring data := '0000'O & f_rnd_octstring(21);
4125
4126 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004127
Harald Welte883340c2018-02-28 18:59:29 +01004128 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004129 f_TfiUsfArrSet(tua, 7, 0);
4130 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4131 f_sleep(1.0);
4132
4133 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004134}
4135
4136/* Send DATA.req on invalid timeslot */
4137testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004138 var TfiUsfArr tua := f_TfiUsfArrInit();
4139 var octetstring data := '0000'O & f_rnd_octstring(21);
4140
4141 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004142
Harald Welte883340c2018-02-28 18:59:29 +01004143 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004144 f_TfiUsfArrSet(tua, 7, 0);
4145 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4146 f_sleep(1.0);
4147
4148 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004149}
4150
4151/* Send DATA.req on timeslot that hasn't been activated */
4152testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004153 var TfiUsfArr tua := f_TfiUsfArrInit();
4154 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004155
Harald Welte7162a612019-05-26 12:56:09 +02004156 f_virtphy_common();
4157
4158 f_TfiUsfArrSet(tua, 7, 0);
4159 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4160 f_sleep(1.0);
4161
4162 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004163}
4164
Harald Weltead033dc2019-05-25 17:28:16 +02004165private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004166 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4167 boolean wait_rts := true)
4168runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004169 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004170 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004171
4172 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004173 if (wait_rts) {
4174 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4175 } else {
4176 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4177 }
Harald Weltead033dc2019-05-25 17:28:16 +02004178
4179 T.start;
4180 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004181 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004182 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4183 setverdict(pass);
4184 }
Harald Welte7162a612019-05-26 12:56:09 +02004185 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4186 setverdict(fail, "Received unexpected ", rx_dl);
4187 }
Harald Weltead033dc2019-05-25 17:28:16 +02004188 [] L1CTL.receive {
4189 repeat;
4190 }
Harald Welte7162a612019-05-26 12:56:09 +02004191 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004192 setverdict(fail, "Timeout waiting for ", data);
4193 }
Harald Welte7162a612019-05-26 12:56:09 +02004194 [not expect_data] T.timeout {
4195 setverdict(pass);
4196 }
Harald Weltead033dc2019-05-25 17:28:16 +02004197 }
4198}
4199
4200private function f_disable_dynamic_ts() runs on test_CT
4201{
4202 f_init_vty_bsc();
4203 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4204 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4205 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4206 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004207 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004208}
4209
4210private function f_virtphy_common() runs on test_CT {
4211 f_disable_dynamic_ts();
4212 f_init_l1ctl();
4213 f_l1_tune(L1CTL);
4214}
4215
4216testcase TC_pcu_data_req_pdtch() runs on test_CT {
4217 var TfiUsfArr tua := f_TfiUsfArrInit();
4218 var octetstring data := '0000'O & f_rnd_octstring(21);
4219
4220 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004221
Harald Welte883340c2018-02-28 18:59:29 +01004222 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004223 f_TfiUsfArrSet(tua, 7, 0);
4224 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4225 f_sleep(1.0);
4226
4227 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004228}
4229
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004230/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004231testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004232 var TfiUsfArr tua := f_TfiUsfArrInit();
4233 var octetstring data := '0000'O & f_rnd_octstring(21);
4234
4235 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004236
Harald Welte883340c2018-02-28 18:59:29 +01004237 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004238 f_TfiUsfArrSet(tua, 7, 0);
4239 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4240 f_sleep(1.0);
4241
4242 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004243}
4244
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004245private function f_TC_pcu_ptcch_ul(uint16_t ra)
4246runs on test_CT {
4247 var template PCUIF_Message pcu_rach_ind;
4248 var PCUIF_send_data sd;
4249 var GsmFrameNumber fn;
4250 timer T;
4251
4252 /* Send an Access Burst on PTCCH/U over the Um-interface */
4253 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4254 chan_nr := ts_RslChanNr_PDCH(7),
4255 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4256
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004257 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4258 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004259
4260 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4261 T.start(52.0 * 4.615 / 1000.0);
4262 alt {
4263 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4264 log("Rx an Access Burst on the PCU interface: ", sd.data);
4265 setverdict(pass);
4266 T.stop;
4267 }
4268 [] PCU.receive { repeat; }
4269 [] T.timeout {
4270 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4271 /* Keep going, that's not the end of the world */
4272 }
4273 }
4274}
4275
4276testcase TC_pcu_ptcch() runs on test_CT {
4277 var L1ctlDlMessage dl;
4278 var octetstring data;
4279 timer T;
4280
4281 f_init_pcu_test();
4282 f_init_l1ctl();
4283 f_l1_tune(L1CTL);
4284
4285 /* Activate PDCH channel on TS7 */
4286 f_TC_pcu_act_req(0, 0, 7, true);
4287
4288 /* Tune trxcon to that PDCH channel */
4289 L1CTL.send(ts_L1CTL_DM_EST_REQ(arfcn := { false, mp_trx0_arfcn },
4290 chan_nr := valueof(ts_RslChanNr_PDCH(7)),
4291 tsc := 7));
4292
4293 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4294 for (var integer i := 0; i < 16; i := i + 1) {
4295 log("Sending an Access Burst towards the L1CTL interface");
4296 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4297 }
4298
4299 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4300 data := f_rnd_octstring(23);
4301
4302 /* Verify PTCCH/D: send a random data block, make sure it's received */
4303 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4304 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4305
4306 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4307 * let's give it more time in case if we miss the beginning. */
4308 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4309 alt {
4310 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4311 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4312 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4313 frame := data)) -> value dl {
4314 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4315 setverdict(pass);
4316 T.stop;
4317 }
4318 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4319 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4320 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4321 l2_data := data)) -> value dl {
4322 log("Rx PTCCH/D data block on L1CTL: ", dl);
4323 setverdict(pass);
4324 T.stop;
4325 }
4326 [] L1CTL.receive { repeat; }
4327 [] T.timeout {
4328 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4329 }
4330 }
4331}
4332
Harald Welte883340c2018-02-28 18:59:29 +01004333/* Send AGCH from PCU; check it appears on Um side */
4334testcase TC_pcu_data_req_agch() runs on test_CT {
4335 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004336 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004337 f_init_l1ctl();
4338 f_l1_tune(L1CTL);
4339
4340 f_TC_pcu_act_req(0, 0, 7, true);
4341 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4342
4343 T.start;
4344 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004345 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004346 setverdict(pass);
4347 }
4348 [] L1CTL.receive { repeat; }
4349 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004351 }
4352 }
4353}
4354
Harald Welte928622b2019-05-26 13:22:59 +02004355/* Send AGCH from PCU; check it appears on Um side */
4356testcase TC_pcu_data_req_pch() runs on test_CT {
4357 timer T := 3.0;
4358 f_init_pcu_test();
4359 f_init_l1ctl();
4360 f_l1_tune(L1CTL);
4361
4362 f_TC_pcu_act_req(0, 0, 7, true);
4363 /* three characters prefix: last 3 digits of IMSI as ASCII */
4364 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4365
4366 T.start;
4367 alt {
4368 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4369 setverdict(pass);
4370 }
4371 [] L1CTL.receive { repeat; }
4372 [] T.timeout {
4373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4374 }
4375 }
4376}
4377
Harald Welte883340c2018-02-28 18:59:29 +01004378/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4379testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4380 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004381 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004382 f_init_l1ctl();
4383 f_l1_tune(L1CTL);
4384
4385 /* append 3 last imsi digits so BTS can compute pagng group */
4386 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4387
4388 timer T := 0.5;
4389 T.start;
4390 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004391 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004392 /* TODO: verify paging group */
4393 setverdict(pass);
4394 }
4395 [] L1CTL.receive { repeat; }
4396 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004398 }
4399 }
4400}
4401
4402/* Send RACH from Um side, expect it to show up on PCU socket */
4403testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004404 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004405 f_init_l1ctl();
4406 f_l1_tune(L1CTL);
4407
4408 var GsmFrameNumber fn_last := 0;
4409 for (var integer i := 0; i < 1000; i := i+1) {
4410 var OCT1 ra := f_rnd_ra_ps();
4411 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4412 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004414 }
4415 fn_last := fn;
4416
4417 timer T := 2.0;
4418 T.start;
4419 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004420 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, 0, 0, oct2int(ra), 0, ?, fn))) {
Harald Welte883340c2018-02-28 18:59:29 +01004421 T.stop;
4422 }
4423 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004425 }
4426 [] PCU.receive { repeat; }
4427 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004429 }
4430 }
4431 }
4432 setverdict(pass);
4433}
4434
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004435/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4436 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4437testcase TC_pcu_ext_rach_content() runs on test_CT {
4438 var template PCUIF_Message pcu_rach_ind;
4439 var GsmFrameNumber fn_last := 0;
4440 var L1ctlRachSynchSeq synch_seq;
4441 var PCUIF_BurstType pcu_bt;
4442 var GsmFrameNumber fn;
4443 var BIT11 ra11;
4444
4445 f_init_pcu_test();
4446 f_init_l1ctl();
4447 f_l1_tune(L1CTL);
4448
4449 for (var integer i := 0; i < 1000; i := i+1) {
4450 /* We need to test both TS1 & TS2 */
4451 if (i rem 2 == 0) {
4452 synch_seq := RACH_SYNCH_SEQ_TS1;
4453 pcu_bt := BURST_TYPE_1;
4454 } else {
4455 synch_seq := RACH_SYNCH_SEQ_TS2;
4456 pcu_bt := BURST_TYPE_2;
4457 }
4458
4459 ra11 := f_rnd_ra11_ps();
4460 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4461 if (fn == fn_last) {
4462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4463 "Two RACH in same FN?!?");
4464 }
4465 fn_last := fn;
4466
4467 /* Compose the expected message */
4468 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004469 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004470 ra := bit2int(ra11),
4471 is_11bit := 1,
4472 burst_type := pcu_bt,
4473 fn := fn);
4474
4475 timer T := 2.0;
4476 T.start;
4477 alt {
4478 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4479 T.stop;
4480 }
4481 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4483 }
4484 [] PCU.receive { repeat; }
4485 [] T.timeout {
4486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4487 }
4488 }
4489 }
4490 setverdict(pass);
4491}
4492
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004493private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4494runs on test_CT {
4495 var template PCUIF_send_data sdt;
4496 var PCUIF_send_data sd;
4497 var int16_t lqual_cb;
4498 timer T := 1.0;
4499
4500 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4501 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4502
4503 /* Send a random PDTCH frame over Um */
4504 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4505 '0000'O & f_rnd_octstring(21)));
4506
4507 T.start;
4508 alt {
4509 /* If expected link quality is above the threshold */
4510 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4511 lqual_cb := sd.data.u.data_ind.lqual_cb;
4512 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4513
4514 /* Make sure the actual link quality matches the expected value */
4515 if (not match(lqual_cb, lqual_cb_exp)) {
4516 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4517 "expected value ", lqual_cb_exp));
4518 } else {
4519 setverdict(pass);
4520 }
4521 }
4522 /* If expected link quality is below the threshold */
4523 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4525 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4526 }
4527 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4528 [] PCU.receive { repeat; }
4529 [lqual_cb_exp < thresh] T.timeout {
4530 log("Rx nothing, as expected");
4531 setverdict(pass);
4532 }
4533 [lqual_cb_exp >= thresh] T.timeout {
4534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4535 "Timeout waiting for PCUIF_DATA.ind");
4536 }
4537 }
4538}
4539
4540/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4541testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4542 f_init_pcu_test();
4543 PCU.clear;
4544
4545 f_init_l1ctl();
4546 f_l1_tune(L1CTL);
4547
4548 /* Activate a PDCH channel on TS7 */
4549 f_TC_pcu_act_req(0, 0, 7, true);
4550
4551 /* Tune trxcon to that PDCH channel on TS7 */
4552 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn },
4553 valueof(ts_RslChanNr_PDCH(7)), 7);
4554
4555 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4556 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4557 var TrxcMessage ret;
4558
4559 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4560 valueof(ts_TRXC_FAKE_CI(i)));
4561
4562 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4563 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4564 }
4565}
4566
Harald Welte883340c2018-02-28 18:59:29 +01004567/* Send PAGING via RSL, expect it to shw up on PCU socket */
4568testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004569 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004570
4571 for (var integer i := 0; i < 100; i := i+1) {
4572 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
4573 timer T := 3.0;
4574 if (i < 50) {
4575 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
4576 } else {
4577 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
4578 }
4579 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
4580 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
4581 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
4582
4583 /* Send RSL PAGING COMMAND */
4584 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
4585 T.start;
4586 alt {
4587 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
4588 }
4589 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004591 }
4592 [] PCU.receive { repeat; }
4593 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004595 }
4596 }
4597 }
4598 setverdict(pass);
4599}
4600
Harald Welted66c9b82019-05-25 09:03:15 +02004601/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4602testcase TC_pcu_time_ind() runs on test_CT {
4603 var PCUIF_send_data pcu_sd;
4604 var integer num_time_ind := 0;
4605 var integer first_fn, last_fn;
4606 var float test_duration := 5.0;
4607 timer T;
4608
4609 f_init_pcu_test();
4610 f_TC_pcu_act_req(0, 0, 7, true);
4611
4612 PCU.clear;
4613 T.start(test_duration);
4614 alt {
4615 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4616 num_time_ind := num_time_ind + 1;
4617 if (not isbound(first_fn)) {
4618 first_fn := pcu_sd.data.u.time_ind.fn;
4619 }
4620 last_fn := pcu_sd.data.u.time_ind.fn;
4621 repeat;
4622 }
4623 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4624 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4625 repeat;
4626 }
4627 [] PCU.receive {
4628 repeat;
4629 }
4630 [] T.timeout {}
4631 }
4632 var integer fn_expired := last_fn - first_fn;
4633 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4634
4635 /* verify the number of frames expired matches our expectation */
4636 const float c_GSM_FN_DURATION_MS := 4.61538;
4637 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004638 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004639 if (not match(fn_expired, t_fn_expected)) {
4640 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4641 }
4642
4643 /* There are three TIME.ind in every fn MOD 13 */
4644 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4645 /* Add some tolerance */
4646 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4647 if (not match(num_time_ind, t_time_ind_exp)) {
4648 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4649 }
4650
4651 setverdict(pass);
4652}
4653
Harald Welte4832c862019-05-25 14:57:18 +02004654/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4655testcase TC_pcu_rts_req() runs on test_CT {
4656 var PCUIF_send_data pcu_sd;
4657 var integer first_fn, last_fn;
4658 var integer num_rts_pdtch := 0;
4659 var integer num_rts_ptcch := 0;
4660 var float test_duration := 5.0;
4661 timer T;
4662
4663 f_init_pcu_test();
4664 f_TC_pcu_act_req(0, 0, 7, true);
4665
4666 PCU.clear;
4667 T.start(test_duration);
4668 alt {
4669 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4670 -> value pcu_sd {
4671 num_rts_pdtch := num_rts_pdtch + 1;
4672 if (not isbound(first_fn)) {
4673 first_fn := pcu_sd.data.u.rts_req.fn;
4674 }
4675 last_fn := pcu_sd.data.u.rts_req.fn;
4676 repeat;
4677 }
4678 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4679 -> value pcu_sd {
4680 num_rts_ptcch := num_rts_ptcch + 1;
4681 if (not isbound(first_fn)) {
4682 first_fn := pcu_sd.data.u.rts_req.fn;
4683 }
4684 last_fn := pcu_sd.data.u.rts_req.fn;
4685 repeat;
4686 }
4687 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4688 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4689 repeat;
4690 }
4691 [] PCU.receive {
4692 repeat;
4693 }
4694 [] T.timeout {}
4695 }
4696 var integer fn_expired := last_fn - first_fn;
4697 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4698 ", num_rts_ptcch=", num_rts_ptcch);
4699
4700 /* verify the number of frames expired matches our expectation */
4701 const float c_GSM_FN_DURATION_MS := 4.61538;
4702 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004703 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004704 if (not match(fn_expired, t_fn_expected)) {
4705 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4706 }
4707
4708 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4709 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4710 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4711 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4712 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4713 t_ptcch_exp);
4714 }
4715
4716 /* We have 12 PDTCH blocks every 52-multiframe */
4717 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4718 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4719 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4720 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4721 t_pdtch_exp);
4722 }
4723
4724 setverdict(pass);
4725}
4726
Harald Welte07bd2d22019-05-25 11:03:30 +02004727/* test for generating Abis side OML ALERT from the PCU */
4728testcase TC_pcu_oml_alert() runs on test_CT {
4729 var PCUIF_send_data pcu_sd;
4730 var integer num_time_ind := 0;
4731 var integer first_fn, last_fn;
4732 var float test_duration := 5.0;
4733 timer T;
4734
4735 f_init_pcu_test();
4736 f_TC_pcu_act_req(0, 0, 7, true);
4737
4738 /* re-connect CTRL port from BTS to BSC */
4739 f_ipa_ctrl_stop();
4740 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4741
4742 /* Send that OML Alert */
4743 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4744
4745 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4746 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4747 setverdict(pass);
4748}
4749
Harald Welteeaa9a862019-05-26 23:01:08 +02004750template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4751 template (value) RoutingAreaIdentificationV rai,
4752 template (value) OCT1 cause) := {
4753 discriminator := '0000'B, /* overwritten */
4754 tiOrSkip := {
4755 skipIndicator := '0000'B
4756 },
4757 msgs := {
4758 rrm := {
4759 gPRS_suspensionRequest := {
4760 messageType := '00110100'B,
4761 tLLI := tlli,
4762 routingAreaIdentification := rai,
4763 suspensionCause := cause,
4764 service_Support := omit
4765 }
4766 }
4767 }
4768}
4769
4770/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4771private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4772 var PCUIF_Message first_info;
4773 var integer pcu_conn_id := -1;
4774 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4775 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4776 var OCT4 tlli := '01020304'O;
4777 var OCT1 cause := '23'O;
4778 timer T := 5.0;
4779
4780 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4781
4782 f_l1_tune(L1CTL);
4783 RSL.clear;
4784
4785 f_est_dchan();
4786 L1CTL.clear;
4787
4788 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4789
4790 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4791 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4792 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4793
4794 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4795 T.start;
4796 alt {
4797 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4798 setverdict(pass);
4799 }
4800 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4801 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4802 }
4803 [] PCU.receive {
4804 repeat;
4805 }
4806 [] T.timeout {
4807 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4808 }
4809 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004810
4811 /* release the channel */
4812 f_rsl_chan_deact();
4813 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4814 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004815}
4816testcase TC_pcu_rr_suspend() runs on test_CT {
4817 var ConnHdlrPars pars;
4818 var ConnHdlr vc_conn;
4819
4820 f_init();
4821
4822 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4823 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4824 vc_conn.done;
4825}
Harald Welte07bd2d22019-05-25 11:03:30 +02004826
Harald Weltea2e0e942019-05-27 18:12:53 +02004827/* Ensure that PCUIF socket can accept only a single connection */
4828testcase TC_pcu_socket_connect_multi() runs on test_CT {
4829 timer T := 5.0;
4830
4831 /* this (among other things) establishes the first connection to the PCUIF socket */
4832 f_init();
4833
4834 /* try to establish a second connection, expect it to fail */
4835 PCU.send(UD_connect:{mp_pcu_socket, -1});
4836 T.start;
4837 alt {
4838 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4839 setverdict(pass);
4840 }
4841 [] PCU.receive(UD_connect_result:?) {
4842 setverdict(fail, "Unexpected unix domain connect result");
4843 }
4844 [] T.timeout {
4845 setverdict(pass);
4846 }
4847 }
4848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4849}
4850
Harald Weltec8effb72019-05-27 18:23:04 +02004851/* Ensure that PCUIF socket can disconnect + reconnect */
4852testcase TC_pcu_socket_reconnect() runs on test_CT {
4853 /* this (among other things) establishes the first connection to the PCUIF socket */
4854 f_init();
4855
4856 f_sleep(1.0);
4857
4858 f_pcuif_close(PCU, g_pcu_conn_id);
4859 g_pcu_conn_id := -1;
4860
4861 f_sleep(1.0);
4862
4863 /* re-connect */
4864 PCU.clear;
4865 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4866 setverdict(pass);
4867
4868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4869}
4870
Harald Weltebe030482019-05-27 22:29:35 +02004871/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4872private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4873 var L1ctlDlMessage l1_dl;
4874 var SystemInformation si;
4875 timer T := 5.0;
4876 T.start;
4877 alt {
4878 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4879 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4880 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4881 log("Ignoring non-RR SI ", l1_dl);
4882 repeat;
4883 }
4884 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4885 if (not ischosen(si.payload.si3)) {
4886 repeat;
4887 }
4888 }
4889 [] pt.receive {
4890 repeat;
4891 }
4892 [] T.timeout {
4893 setverdict(fail, "Timeout waiting for SI3");
4894 }
4895 }
4896 return si.payload.si3;
4897}
4898
4899/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4900private function f_bitpos_is_inv(integer idx) return boolean {
4901 select (idx mod 8) {
4902 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4903 case else { return false; } /* 0-bits of 0x2B */
4904 }
4905}
4906/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4907private function f_bit_is_high(bitstring str, integer idx) return boolean {
4908 var boolean invert := f_bitpos_is_inv(idx);
4909 if (invert) {
4910 if (str[idx] == '1'B) {
4911 return false;
4912 } else {
4913 return true;
4914 }
4915 } else {
4916 if (str[idx] == '1'B) {
4917 return true;
4918 } else {
4919 return false;
4920 }
4921 }
4922}
4923/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4924 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4925 we can replace this piece of code soon ... */
4926private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4927 var bitstring bits := oct2bit(si3_restoctets);
4928 var integer idx := 0;
4929
4930 if (f_bit_is_high(bits, idx)) {
4931 /* skip Optional selection parameters */
4932 idx := idx + 16;
4933 } else {
4934 idx := idx + 1;
4935 }
4936
4937 if (f_bit_is_high(bits, idx)) {
4938 /* skip Optional power offset */
4939 idx := idx + 3;
4940 } else {
4941 idx := idx + 1;
4942 }
4943
4944 /* skip SI2ter Indicator */
4945 idx := idx + 1;
4946
4947 /* skip Early CM Sending Control */
4948 idx := idx + 1;
4949
4950 /* skip Scheduling if and where */
4951 if (f_bit_is_high(bits, idx)) {
4952 idx := idx + 4;
4953 } else {
4954 idx := idx + 1;
4955 }
4956
4957 return f_bit_is_high(bits, idx);
4958}
4959
4960testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4961 var SystemInformationType3 si3;
4962 timer T := 5.0;
4963
4964 /* don't call f_init() as this would connect PCU socket */
4965 f_init_rsl(testcasename());
4966 T.start;
4967 alt {
4968 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4969 [] T.timeout {
4970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4971 }
4972 }
4973 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4974
4975 f_init_l1ctl();
4976 f_l1_tune(L1CTL);
4977
4978 f_sleep(2.0);
4979 L1CTL.clear;
4980 si3 := f_get_si3(L1CTL);
4981 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4982 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4983 } else {
4984 setverdict(pass);
4985 }
4986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4987}
4988
4989/* Ensure that GPRS capability is advertised after PCU socket connect */
4990testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4991 var SystemInformationType3 si3;
4992
4993 /* this (among other things) establishes the first connection to the PCUIF socket */
4994 f_init();
4995 f_init_l1ctl();
4996 f_l1_tune(L1CTL);
4997
4998 f_sleep(2.0);
4999 L1CTL.clear;
5000 si3 := f_get_si3(L1CTL);
5001 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
5002 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
5003 } else {
5004 setverdict(pass);
5005 }
5006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5007}
5008
5009/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5010testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5011 var SystemInformationType3 si3;
5012
5013 /* this (among other things) establishes the first connection to the PCUIF socket */
5014 f_init();
5015 f_init_l1ctl();
5016 f_l1_tune(L1CTL);
5017
5018 f_pcuif_close(PCU, g_pcu_conn_id);
5019 g_pcu_conn_id := -1;
5020
5021 f_sleep(1.0);
5022
5023 /* re-connect */
5024 PCU.clear;
5025 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5026
5027 f_sleep(2.0);
5028 L1CTL.clear;
5029 si3 := f_get_si3(L1CTL);
5030 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
5031 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
5032 } else {
5033 setverdict(pass);
5034 }
5035
5036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5037}
5038
Oliver Smithf5239c72019-08-28 10:01:25 +02005039/* Verify that the cell_id of SI3 (TS 04.08 9.1.35) and other values are passed properly to the PCU socket (OS#3854) */
5040testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5041 var SystemInformation si3 := valueof(ts_SI3_default);
5042
5043 f_init();
5044
5045 /* Verify cell_id */
5046 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5047 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5048 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005049 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5050 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5051 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005052 }
5053
5054 /* Verify LAC */
5055 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5056 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5057 if (lac_si3 != lac_pcu) {
5058 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5059 }
5060
5061 setverdict(pass);
5062}
Harald Welted66c9b82019-05-25 09:03:15 +02005063
Harald Welte3d04ae62018-04-04 20:29:05 +02005064/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005065 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005066 ***********************************************************************/
5067
5068private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5069runs on ConnHdlr {
5070 var PCUIF_send_data sd;
5071 /* Expect BTS to immediately acknowledge activation as PDCH */
5072 PCU.clear;
5073 f_rsl_chan_act(g_pars.chan_mode);
5074 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005075 timer T_wait := 2.0;
5076 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005077 alt {
5078 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5079 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005080 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5081 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5082 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005083 }
5084 }
5085 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005086 [] T_wait.timeout {
5087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5088 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5089 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005090 }
5091 /* try to activate this PDCH from the PCU point of view */
5092 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5093 /* FIXME: is there a response? */
5094}
5095
5096private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5097runs on ConnHdlr {
5098 var PCUIF_send_data sd;
5099 /* Send RSL CHAN REL (deactivate) */
5100 PCU.clear;
5101 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5102 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005103 timer T_wait := 2.0;
5104 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005105 alt {
5106 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5107 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005108 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5109 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5110 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005111 }
5112 }
5113 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005114 [] T_wait.timeout {
5115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5116 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5117 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005118 }
5119 /* Emulate PCU asking BTS to deactivate PDCH */
5120 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5121 alt {
5122 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5123 setverdict(pass);
5124 }
5125 [] RSL.receive { repeat; }
5126 }
5127}
5128
5129/* Activate Osmocom-style dynamic PDCH from BSC side */
5130function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5131 var PCUIF_Message first_info;
5132 var integer ts_nr := g_chan_nr.tn;
5133 var integer trx_nr := 0;
5134 var integer bts_nr := 0;
5135 var integer pcu_conn_id := -1;
5136
5137 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5138
5139 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5140 f_sleep(3.0);
5141 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5142 setverdict(pass);
5143}
5144testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5145 var ConnHdlrPars pars;
5146 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005147 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005148
5149 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5150 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5151 vc_conn.done;
5152}
5153
5154/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5155function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5156 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005157 var integer pcu_conn_id := -1;
5158
5159 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5160
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005161 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5162 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5163 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005164 setverdict(pass);
5165}
5166testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5167 var ConnHdlrPars pars;
5168 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005169 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005170
5171 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5172 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5173 vc_conn.done;
5174}
5175
5176/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5177function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5178 var PCUIF_Message first_info;
5179 var integer ts_nr := g_chan_nr.tn;
5180 var integer trx_nr := 0;
5181 var integer bts_nr := 0;
5182 var integer pcu_conn_id := -1;
5183
5184 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5185
5186 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005187 /* Send a second Chan Activ and expect it to be NACKed */
5188 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5189 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005190 setverdict(pass);
5191}
5192testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5193 var ConnHdlrPars pars;
5194 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005195 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005196
5197 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5198 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5199 vc_conn.done;
5200}
5201
5202/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5203function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5204 var PCUIF_Message first_info;
5205 var integer ts_nr := g_chan_nr.tn;
5206 var integer trx_nr := 0;
5207 var integer bts_nr := 0;
5208 var integer pcu_conn_id := -1;
5209 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5210
5211 /* register for the TCH/F channel number */
5212 f_rslem_register(0, chan_nr);
5213
5214 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5215
5216 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5217 "RSL CHAN ACT");
5218 setverdict(pass);
5219}
5220testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5221 var ConnHdlrPars pars;
5222 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005223 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005224
5225 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5226 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5227 vc_conn.done;
5228}
5229
5230/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5231function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5232 var PCUIF_Message first_info;
5233 var integer ts_nr := g_chan_nr.tn;
5234 var integer trx_nr := 0;
5235 var integer bts_nr := 0;
5236 var integer pcu_conn_id := -1;
5237 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5238 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5239
5240 /* register for the TCH/H channel numbers */
5241 f_rslem_register(0, chan_nr[0]);
5242 f_rslem_register(0, chan_nr[1]);
5243
5244 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5245
5246 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5247 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5248 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5249 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5250 setverdict(pass);
5251}
5252testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5253 var ConnHdlrPars pars;
5254 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005255 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005256
5257 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5258 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5259 vc_conn.done;
5260}
5261
Harald Welte9bbbfb52018-04-05 09:33:19 +02005262/***********************************************************************
5263 * IPA Style Dynamic Timeslot Support
5264 ***********************************************************************/
5265
5266private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5267runs on ConnHdlr {
5268 var PCUIF_send_data sd;
5269 /* Expect BTS to immediately acknowledge activation as PDCH */
5270 PCU.clear;
5271 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5272 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005273 timer T_wait := 2.0;
5274 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005275 alt {
5276 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5277 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 +01005278 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5279 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5280 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005281 }
5282 }
5283 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005284 [] T_wait.timeout {
5285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5286 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5287 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005288 }
5289 /* try to activate this PDCH from the PCU point of view */
5290 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5291 /* FIXME: is there a response? */
5292
5293 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5294}
5295
5296private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5297runs on ConnHdlr {
5298 var PCUIF_send_data sd;
5299 /* Send RSL CHAN REL (deactivate) */
5300 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5301 PCU.clear;
5302 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005303 timer T_wait := 2.0;
5304 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005305 alt {
5306 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5307 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 +01005308 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5309 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5310 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005311 }
5312 }
5313 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005314 [] T_wait.timeout {
5315 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5316 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5317 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005318 }
5319 /* Emulate PCU asking BTS to deactivate PDCH */
5320 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5321 alt {
5322 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5323 setverdict(pass);
5324 }
5325 [] RSL.receive { repeat; }
5326 }
5327}
5328
5329/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5330function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5331 var PCUIF_Message first_info;
5332 var integer ts_nr := g_chan_nr.tn;
5333 var integer trx_nr := 0;
5334 var integer bts_nr := 0;
5335 var integer pcu_conn_id := -1;
5336
5337 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5338
5339 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5340 f_sleep(3.0);
5341 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5342
5343 setverdict(pass);
5344
5345}
5346testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5347 var ConnHdlrPars pars;
5348 var ConnHdlr vc_conn;
5349 f_init();
5350
5351 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5352 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5353 vc_conn.done;
5354}
5355
5356/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5357function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5358 var PCUIF_Message first_info;
5359 var integer ts_nr := g_chan_nr.tn;
5360 var integer trx_nr := 0;
5361 var integer bts_nr := 0;
5362 var integer pcu_conn_id := -1;
5363
5364 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5365
5366 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5367 "RSL CHAN ACT");
5368 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5369 "RF CHAN REL", true);
5370 setverdict(pass);
5371}
5372testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5373 var ConnHdlrPars pars;
5374 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005375 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005376
5377 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5378 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5379 vc_conn.done;
5380}
5381
5382/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5383function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5384 var PCUIF_Message first_info;
5385 var integer ts_nr := g_chan_nr.tn;
5386 var integer trx_nr := 0;
5387 var integer bts_nr := 0;
5388 var integer pcu_conn_id := -1;
5389
5390 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5391
5392 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5393 "RSL CHAN ACT");
5394
5395 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5396 alt {
5397 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5398 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005400 }
5401 [] RSL.receive { repeat; }
5402 }
5403
5404 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5405 "RF CHAN REL", true);
5406 setverdict(pass);
5407}
5408testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5409 var ConnHdlrPars pars;
5410 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005411 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005412
5413 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5414 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5415 vc_conn.done;
5416}
5417
5418/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5419function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5420 var PCUIF_Message first_info;
5421 var integer ts_nr := g_chan_nr.tn;
5422 var integer trx_nr := 0;
5423 var integer bts_nr := 0;
5424 var integer pcu_conn_id := -1;
5425
5426 /* register for the TCH/F channel number */
5427 f_rslem_register(0, g_chan_nr);
5428
5429 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5430
5431 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5432
5433 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5434 "RSL CHAN ACT");
5435
5436 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5437
5438 setverdict(pass);
5439}
5440testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5441 var ConnHdlrPars pars;
5442 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005443 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005444
5445 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5446 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5447 vc_conn.done;
5448}
5449
5450
Harald Welte0472ab42018-03-12 15:02:26 +01005451/***********************************************************************
5452 * LAPDm / RLL related
5453 ***********************************************************************/
5454
5455private function f_tx_lapdm(template (value) LapdmFrame l,
5456 template (value) RslLinkId link_id) runs on ConnHdlr {
5457 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005458 var template (value) SacchL1Header l1h;
5459
5460 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005461 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005462 /* Compose dummy L1 header */
5463 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5464 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 +02005465 } else {
5466 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005467 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 +01005468 }
Harald Welte0472ab42018-03-12 15:02:26 +01005469}
5470
5471type record RllTestCase {
5472 uint3_t sapi,
5473 RslLinkId link_id,
5474 octetstring l3,
5475 boolean exp
5476}
5477type record of RllTestCase RllTestCases;
5478template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5479 sapi := sapi,
5480 link_id := id,
5481 l3 := l3,
5482 exp := exp
5483}
5484
5485/* execute the same callback function with a set of different parameters (tcs) on a
5486 * variety of logical channels */
5487private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5488 var ConnHdlrPars pars;
5489 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005490 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005491
5492 /* test on each of the channels we have */
5493 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5494 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5495
5496 /* test each of the test cases on the current channel */
5497 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5498 pars.spec.rll := tcs[j];
5499 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5500 vc_conn := f_start_handler(fn, pars);
5501 vc_conn.done;
5502 }
5503 }
5504
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005506}
5507
5508/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5509private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5510 var RllTestCase tc := g_pars.spec.rll;
5511 timer T := 3.0;
5512
5513 f_l1_tune(L1CTL);
5514 RSL.clear;
5515
5516 /* activate the logical channel */
5517 f_est_dchan();
5518 L1CTL.clear;
5519
5520 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5521 T.start;
5522 alt {
5523 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5524 if (tc.exp) {
5525 setverdict(pass);
5526 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005528 }
5529 }
5530 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5531 if (tc.exp) {
5532 setverdict(pass);
5533 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005535 }
5536 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005537 /* We also expect to receive the measurements */
5538 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005539 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005541 }
5542 [not tc.exp] T.timeout {
5543 setverdict(pass);
5544 }
5545 }
5546
5547 f_rsl_chan_deact();
5548 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5549 f_rslem_unregister(0, g_chan_nr);
5550}
5551testcase TC_rll_est_ind() runs on test_CT {
5552 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005553 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005554 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005555 /* normal SAPI0 establishment */
5556 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005557 /* SAPI 3 doesn't support contention resolution */
5558 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5559 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5560 /* normal SAPI3 establishment on main DCCH */
5561 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5562 /* normal SAPI3 establishment on SACCH */
5563 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5564 };
5565 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5566}
5567
5568/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5569private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5570 var RllTestCase tc := g_pars.spec.rll;
5571 var L1ctlDlMessage dl;
5572 timer T := 3.0;
5573
5574 f_l1_tune(L1CTL);
5575 RSL.clear;
5576
5577 /* activate the logical channel */
5578 f_est_dchan();
5579 L1CTL.clear;
5580
5581 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5582 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5583 T.start;
5584 alt {
5585 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5586 var LapdmFrame lapdm;
5587 var octetstring l2 := dl.payload.data_ind.payload;
5588 if (dl.dl_info.link_id.c == SACCH) {
5589 /* remove L1 header */
5590 l2 := substr(l2, 2, lengthof(l2)-2);
5591 }
5592 lapdm.ab := dec_LapdmFrameAB(l2);
5593 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5594 setverdict(pass);
5595 } else {
5596 repeat;
5597 }
5598 }
5599 [] L1CTL.receive { repeat; }
5600 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005602 }
5603 }
5604
5605 f_rsl_chan_deact();
5606 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5607 f_rslem_unregister(0, g_chan_nr);
5608}
5609testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5610 var RllTestCases tcs := {
5611 /* normal SAPI3 establishment on main DCCH */
5612 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5613 };
5614 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5615}
5616testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5617 var RllTestCases tcs := {
5618 /* normal SAPI3 establishment on SACCH */
5619 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5620 }
5621 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5622}
5623
5624/* altstep to receive a LAPDm frame matching the given template */
5625private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5626 var L1ctlDlMessage dl;
5627 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5628 var LapdmFrame lapdm;
5629 var octetstring l2 := dl.payload.data_ind.payload;
5630 if (dl.dl_info.link_id.c == SACCH) {
5631 /* remove L1 header */
5632 l2 := substr(l2, 2, lengthof(l2)-2);
5633 }
5634 if (ischosen(exp.ab)) {
5635 lapdm.ab := dec_LapdmFrameAB(l2);
5636 } else if (ischosen(exp.b4)) {
5637 lapdm.b4 := dec_LapdmFrameB4(l2);
5638 } else if (ischosen(exp.bbis)) {
5639 lapdm.bbis := dec_LapdmFrameBbis(l2);
5640 }
5641 log("Rx LAPDm ", lapdm);
5642 if (match(lapdm, exp)) {
5643 setverdict(pass);
5644 } else {
5645 repeat;
5646 }
5647 }
5648 [] L1CTL.receive { repeat; }
5649}
5650private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5651 timer T := t;
5652 T.start;
5653 alt {
5654 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005656 }
5657 [] as_l1_exp_lapdm(exp);
5658 }
5659}
5660
5661/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5662private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5663 /* send SABM from MS -> BTS */
5664 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5665 /* expect RLL EST IND on Abis */
5666 alt {
5667 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5668 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5669 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005671 }
5672 [] RSL.receive { repeat; }
5673 }
5674 /* expect UA from BTS -> MS */
5675 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5676}
5677
5678/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5679private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5680 var RllTestCase tc := g_pars.spec.rll;
5681
5682 f_l1_tune(L1CTL);
5683 RSL.clear;
5684
5685 /* activate the logical channel */
5686 f_est_dchan();
5687 L1CTL.clear;
5688
5689 /* first establish the link-layer */
5690 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5691
5692 /* then send the DISC */
5693 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5694 /* ... and expect the REL IND on the RSL side */
5695 alt {
5696 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5697 setverdict(pass);
5698 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005699 /* We also expect to receive the measurements */
5700 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005701 }
5702
5703 /* release the channel */
5704 f_rsl_chan_deact();
5705 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5706 f_rslem_unregister(0, g_chan_nr);
5707}
5708testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5709 var RllTestCases tcs := {
5710 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5711 };
5712 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5713}
5714
5715testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5716 var RllTestCases tcs := {
5717 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5718 };
5719 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5720}
5721testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5722 var RllTestCases tcs := {
5723 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5724 };
5725 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5726}
5727testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5728 var RllTestCases tcs := {
5729 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5730 };
5731 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5732}
5733
5734/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5735private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5736 var RllTestCase tc := g_pars.spec.rll;
5737 f_l1_tune(L1CTL);
5738 RSL.clear;
5739
5740 /* activate the logical channel */
5741 f_est_dchan();
5742 L1CTL.clear;
5743
5744 /* first establish the link-layer */
5745 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5746
5747 /* then send the REL REQ via RSL */
5748 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5749 /* ... and expect the DISC on the Um side */
5750 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005751 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005752 /* FIXME: send a UA in resposne to the DISC */
5753 }
5754 }
5755
5756 /* release the channel */
5757 f_rsl_chan_deact();
5758 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5759 f_rslem_unregister(0, g_chan_nr);
5760}
5761testcase TC_rll_rel_req() runs on test_CT {
5762 var RllTestCases tcs := {
5763 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5764 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5765 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5766 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5767 };
5768 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5769}
5770
5771/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5772testcase TC_rll_data_req() runs on test_CT {
5773}
5774
5775/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5776testcase TC_rll_data_ind() runs on test_CT {
5777}
5778
5779/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5780private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5781 var RllTestCase tc := g_pars.spec.rll;
5782
5783 f_l1_tune(L1CTL);
5784 RSL.clear;
5785
5786 f_est_dchan();
5787 L1CTL.clear;
5788
5789 /* Send UNITDATA REQ on RSL side */
5790 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5791 /* Expect it to arrive on the other side */
5792 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005793 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005794 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005795 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005796 }
5797
5798 /* release the channel */
5799 f_rsl_chan_deact();
5800 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5801 f_rslem_unregister(0, g_chan_nr);
5802}
5803testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5804 var octetstring l3 := f_rnd_octstring(15);
5805 var RllTestCases tcs := {
5806 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5807 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5808 };
5809 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5810}
5811testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5812 var octetstring l3 := f_rnd_octstring(19);
5813 var RllTestCases tcs := {
5814 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5815 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5816 };
5817 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5818}
5819
5820/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5821private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5822 var RllTestCase tc := g_pars.spec.rll;
5823
5824 f_l1_tune(L1CTL);
5825 RSL.clear;
5826
5827 f_est_dchan();
5828 L1CTL.clear;
5829
5830 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005831 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005832 /* Expdct RLL UNITDATA IND on RSL side */
5833 alt {
5834 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5835 setverdict(pass);
5836 }
5837 [] RSL.receive { repeat; }
5838 }
5839
5840 /* release the channel */
5841 f_rsl_chan_deact();
5842 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5843 f_rslem_unregister(0, g_chan_nr);
5844}
5845testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005846 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005847 var RllTestCases tcs := {
5848 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5849 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5850 };
5851 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5852}
5853testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5854 var octetstring l3 := f_rnd_octstring(18);
5855 var RllTestCases tcs := {
5856 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5857 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5858 };
5859 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5860}
5861
Harald Weltee613f962018-04-18 22:38:16 +02005862/***********************************************************************
5863 * Encryption Related
5864 ***********************************************************************/
5865
5866/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5867function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5868 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5869 if (link_id.c == SACCH) {
5870 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5871 } else {
5872 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5873 }
5874}
5875
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005876/* Expect (or not expect) other kinds of messages */
5877private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5878 [exp_any] RSL.receive { repeat; }
5879 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005881 }
5882}
5883
Harald Weltee613f962018-04-18 22:38:16 +02005884/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005885private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005886 RslLinkId link_id,
5887 octetstring l3,
5888 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005889 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005890) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005891 timer T := 3.0;
5892 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5893 T.start;
5894 /* Expect RLL UNITDATA IND on RSL side */
5895 alt {
5896 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5897 setverdict(pass);
5898 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005899 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005900 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005901 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005903 }
Harald Weltee613f962018-04-18 22:38:16 +02005904 }
5905}
5906
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005907/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5908private function f_data_mo(
5909 RslLinkId link_id,
5910 boolean p, uint3_t nr, uint3_t ns,
5911 octetstring l3,
5912 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005913 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005914) runs on ConnHdlr {
5915 timer T := 3.0;
5916 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5917 T.start;
5918 /* Expect RLL DATA IND on RSL side */
5919 alt {
5920 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5921 setverdict(pass);
5922 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005923 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005924 [] as_rsl_any_ind(exp_any);
5925 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005927 }
5928 }
5929}
5930
Harald Weltee613f962018-04-18 22:38:16 +02005931/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5932function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5933 f_l1_tune(L1CTL);
5934 f_est_dchan(true);
5935
5936 /* now we actually need to transmit some data both ways to check if the encryption works */
5937 var L1ctlDlMessage dl;
5938
Stefan Sperling603d98e2018-07-25 16:47:28 +02005939 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005940 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5941
5942 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5943 f_unitdata_mt(link_id, l3);
5944
5945 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5946 f_unitdata_mo(link_id, l3);
5947
5948 /* release the channel */
5949 f_rsl_chan_deact();
5950 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5951 f_rslem_unregister(0, g_chan_nr);
5952}
5953testcase TC_chan_act_a51() runs on test_CT {
5954 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5955 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5956 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5957}
5958testcase TC_chan_act_a52() runs on test_CT {
5959 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5960 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5961 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5962}
5963testcase TC_chan_act_a53() runs on test_CT {
5964 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5965 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5966 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5967}
5968
Eric Wildf1827a72019-05-28 17:37:35 +02005969/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5970 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5971function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5972 f_l1_tune(L1CTL);
5973 f_est_dchan(true);
5974
5975 /* now we actually need to transmit some data both ways to check if the encryption works */
5976 var L1ctlDlMessage dl;
5977
5978 var octetstring l3 := f_rnd_octstring(20);
5979 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5980
5981 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5982 f_unitdata_mt(link_id, l3);
5983
5984 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5985 f_unitdata_mo(link_id, l3);
5986
5987 var RSL_Message rsl;
5988 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5989
5990 /* modify key to break proper encryption */
5991 g_pars.encr.key := f_rnd_octstring(8);
5992 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5993 rsl.ies := rsl.ies & { ei };
5994 RSL.send(rsl);
5995
5996 timer T0 := 1.0;
5997 T0.start;
5998 /* Expect RSL MODIFY ACK */
5999 alt {
6000 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6001 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6003 }
6004 [] T0.timeout {
6005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6006 }
6007 }
6008
6009 var octetstring l3msg := f_rnd_octstring(15);
6010 timer T1 := 3.0;
6011 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6012 due to broken encryption */
6013 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6014 T1.start;
6015 alt {
6016 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6018 }
6019 [] T1.timeout {
6020 setverdict(pass);
6021 }
6022 }
6023
6024 /* release the channel */
6025 f_rsl_chan_deact();
6026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6027 f_rslem_unregister(0, g_chan_nr);
6028}
6029testcase TC_rsl_modify_encr() runs on test_CT {
6030 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6031 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6032 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6033}
Harald Weltee613f962018-04-18 22:38:16 +02006034
6035/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6036function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6037 /* L3 payload doesn't matter, as it is passed transparently */
6038 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6039 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6040 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6041
6042 f_l1_tune(L1CTL);
6043
6044 /* first establish a dedicated channel in the clear */
6045 f_est_dchan(false);
6046
6047 /* Establish ABM */
6048 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6049
6050 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6051 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6052 /* expect the L3 to arrive still unencrypted on the MS side */
6053 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6054
6055 /* configure L1 to apply ciphering */
6056 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6057 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6058
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006059 /* send first ciphered I-frame in response and expect it on RSL */
6060 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006061
6062 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6063 * and hence enable encryption also on the downlink */
6064
6065 /* expect bi-directional communication work in encrypted mode */
6066 f_unitdata_mo(link_id, f_rnd_octstring(15));
6067 f_unitdata_mt(link_id, f_rnd_octstring(15));
6068
6069 /* release the channel */
6070 f_rsl_chan_deact();
6071 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6072 f_rslem_unregister(0, g_chan_nr);
6073}
6074testcase TC_encr_cmd_a51() runs on test_CT {
6075 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6076 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6077 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6078}
6079testcase TC_encr_cmd_a52() runs on test_CT {
6080 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6081 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6082 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6083}
6084testcase TC_encr_cmd_a53() runs on test_CT {
6085 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6086 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6087 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6088}
6089
6090private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6091 var LapdmFrame lf;
6092 var octetstring reenc;
6093
6094 /* decode the LAPDm frame */
6095 if (ischosen(exp_match.ab)) {
6096 lf.ab := dec_LapdmFrameAB(enc);
6097 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006099 }
6100
6101 /* check if decoder result matches expectation */
6102 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006104 } else {
6105 log(name, ": matched");
6106 setverdict(pass);
6107 }
6108
6109 /* test if re-encoded frame equals original input */
6110 reenc := enc_LapdmFrame(lf);
6111 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006113 } else {
6114 setverdict(pass);
6115 }
6116}
6117
6118testcase TC_lapdm_selftest() runs on test_CT {
6119 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6120 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6121 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6122 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6123 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6124 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6125 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6126}
6127
Stefan Sperling4880be42018-08-07 18:12:59 +02006128/***********************************************************************
6129 * DTX Related (see GSM 05.08, section 8.3)
6130 ***********************************************************************/
6131
6132/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6133function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6134 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6135 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6136 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6137 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6138}
6139function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6140 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6141 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6142}
6143function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6144 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6145 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6146 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6147 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6148}
6149function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6150 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6151 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6152 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6153 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6154 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6155 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6156 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6157 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6158}
6159
6160function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6161 var L1ctlDlMessage dl;
6162 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6163 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6164 var GsmFrameNumber first_fn;
6165 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006166 var integer nfill_frames_sacch := 0;
6167 var integer nfill_frames_nonsacch := 0;
6168 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006169 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6170 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006171 const integer frame_dtx_tchf_mod := 104;
6172 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6173 * which operates in terms of blocks rather than frames. */
6174 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6175 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006176 timer T := 5.0;
6177
6178 f_l1_tune(L1CTL);
6179 RSL.clear;
6180 L1CTL.clear;
6181
6182 /* activate TCHF signalling channel */
6183 f_est_dchan(false);
6184
6185 T.start;
6186 alt {
6187 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6188 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6189 var octetstring l2 := dl.payload.data_ind.payload;
6190
6191 if (is_first_frame) {
6192 is_first_frame := false;
6193 first_fn := dl.dl_info.frame_nr;
6194 }
6195
6196 if (dl.dl_info.link_id.c == SACCH) {
6197 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6198 if (not match(l2_fill_frame_sacch, l2)) {
6199 repeat;
6200 }
6201 } else if (not match(l2_fill_frame, l2)) {
6202 repeat;
6203 }
6204
6205 if (dtxd) {
6206 if (not f_g_chan_is_tchf()) {
6207 T.stop;
6208 f_rsl_chan_deact();
6209 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006210 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 +02006211 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006212 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006213 T.stop;
6214 f_rsl_chan_deact();
6215 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006216
6217 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6218 * 2 SACCH, 1 TCH/F */
6219 expected_fill_frames := 3;
6220
6221 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6222 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6223 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006225 } else {
6226 setverdict(pass);
6227 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006228 } else {
6229 if (dl.dl_info.link_id.c == SACCH) {
6230 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006231 repeat;
6232 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006233 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6234 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6235 * we should only see the subset of frames numbers which correspond to a block boundary.
6236 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6237 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6238 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6239 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6240 repeat;
6241 }
6242 }
6243 log("Received DTX TCH fill frame with bad frame number: ", fn,
6244 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6245 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6246 f_rsl_chan_deact();
6247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006249 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006250 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006251 if (dl.dl_info.link_id.c == SACCH) {
6252 nfill_frames_sacch := nfill_frames_sacch + 1;
6253 } else {
6254 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6255 }
6256 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006257 T.stop;
6258 if (f_g_chan_is_tchf()) {
6259 /* Without DTX we can expect 25 fill frames for every 104 frames.
6260 * (24 FACCH + 1 SACCH filling) */
6261 expected_fill_frames := 25;
6262 } else if (f_g_chan_is_tchh()) {
6263 /* We can expect 2 fill frames for every 104 frames. */
6264 expected_fill_frames := 2;
6265 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6266 /* We can expect 5 fill frames for every 104 frames. */
6267 expected_fill_frames := 5;
6268 } else {
6269 f_rsl_chan_deact();
6270 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006272 }
6273
6274 f_rsl_chan_deact();
6275 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006276
6277 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006278 setverdict(pass);
6279 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006280 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6281 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006283 }
6284 } else {
6285 repeat;
6286 }
6287 }
6288 }
6289 [] L1CTL.receive { repeat; }
6290 [] T.timeout {
6291 f_rsl_chan_deact();
6292 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006294 }
6295 }
6296}
6297
6298function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6299 f_test_l2_fill_frames(false);
6300}
6301
6302function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6303 f_test_l2_fill_frames(true);
6304}
6305
6306function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6307 var ConnHdlr vc_conn;
6308 var ConnHdlrPars pars;
6309 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006310 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006311 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6312 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6313 if (dtxd) {
6314 if (i >= 4) { /* DTX is only allowed on TCH/F */
6315 break;
6316 }
6317 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6318 } else {
6319 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6320 }
6321 vc_conn.done;
6322 }
6323}
6324
6325/* Verify that L2 fill frames are sent on TCH in signaling mode if
6326 * there is nothing to transmit while DTX is disabled on downlink. */
6327testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6328 f_tch_sign_l2_fill_frame(false);
6329}
6330
6331/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6332 * there is nothing to transmit while DTX is enabled on downlink. */
6333testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6334 f_tch_sign_l2_fill_frame(true);
6335}
Harald Welte0472ab42018-03-12 15:02:26 +01006336
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006337testcase TC_chopped_ipa_ping() runs on test_CT {
6338 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6339}
6340
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006341testcase TC_chopped_ipa_payload() runs on test_CT {
6342 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6343}
6344
Harald Welte0472ab42018-03-12 15:02:26 +01006345/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6346/* protocol error as per 44.006 */
6347/* link layer failure (repetition of I-frame N200 times without ACK */
6348/* repetition of SABM or DISC N200 times without ACK */
6349/* receptiom of SABM in multi-frame established state */
6350
6351
Harald Welte68e495b2018-02-25 00:05:57 +01006352/* TODO Areas:
6353
6354* channel activation
6355** with BS_Power / MS_Power, bypassing power control loop
6356** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006357** with timing advance from initial activation on
6358* mode modify
6359** encryption
6360** multirate
6361* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006362** unsupported algorithm
6363* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006364* BS Power Control
6365* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006366* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006367* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006368** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006369* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006370** DATA_IND from BTS->PCU
6371** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006372
6373*/
Harald Welte70767382018-02-21 12:16:40 +01006374
6375control {
6376 execute( TC_chan_act_stress() );
6377 execute( TC_chan_act_react() );
6378 execute( TC_chan_deact_not_active() );
6379 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006380 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006381 execute( TC_sacch_filling() );
6382 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006383 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006384 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006385 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006386 execute( TC_sacch_chan_act_ho_async() );
6387 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006388 execute( TC_rach_content() );
6389 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006390 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006391 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006392 execute( TC_rach_load_idle_thresh0() );
6393 execute( TC_rach_load_idle_below_thresh() );
6394 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006395 execute( TC_meas_res_sign_tchf() );
6396 execute( TC_meas_res_sign_tchh() );
6397 execute( TC_meas_res_sign_sdcch4() );
6398 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006399 execute( TC_meas_res_sign_tchh_toa256() );
Eric Wildae8f2622019-06-18 17:05:11 +02006400 execute( TC_rsl_bs_pwr_static_ass() );
6401 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006402 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006403 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006404 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006405 execute( TC_rsl_ms_pwr_dyn_up() );
6406 execute( TC_rsl_ms_pwr_dyn_down() );
6407 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6408 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006409 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006410 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006411 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006412 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006413 execute( TC_paging_imsi_80percent() );
6414 execute( TC_paging_tmsi_80percent() );
6415 execute( TC_paging_imsi_200percent() );
6416 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006417 execute( TC_rsl_protocol_error() );
6418 execute( TC_rsl_mand_ie_error() );
6419 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006420 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006421 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006422 execute( TC_si_sched_2bis() );
6423 execute( TC_si_sched_2ter() );
6424 execute( TC_si_sched_2ter_2bis() );
6425 execute( TC_si_sched_2quater() );
6426 execute( TC_si_sched_13() );
6427 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006428 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006429 execute( TC_ipa_crcx_twice_not_active() );
6430 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006431 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006432 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006433
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006434 if (mp_pcu_socket != "") {
6435 execute( TC_pcu_act_req() );
6436 execute( TC_pcu_act_req_wrong_ts() );
6437 execute( TC_pcu_act_req_wrong_bts() );
6438 execute( TC_pcu_act_req_wrong_trx() );
6439 execute( TC_pcu_deact_req() );
6440 execute( TC_pcu_deact_req_wrong_ts() );
6441 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006442 if (mp_l1_supports_gprs) {
6443 execute( TC_pcu_data_req_pdtch() );
6444 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006445 execute( TC_pcu_data_req_wrong_bts() );
6446 execute( TC_pcu_data_req_wrong_trx() );
6447 execute( TC_pcu_data_req_wrong_ts() );
6448 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006449 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006450 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006451 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006452 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006453 execute( TC_pcu_data_req_imm_ass_pch() );
6454 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006455 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006456 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006457 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006458 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006459 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006460 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006461 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006462 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006463 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006464 execute( TC_pcu_socket_noconnect_nosi3gprs() );
6465 execute( TC_pcu_socket_connect_si3gprs() );
6466 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006467 execute( TC_pcu_socket_verify_info_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006468 } else {
6469 log("PCU socket path not available, skipping PCU tests");
6470 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006471
6472 execute( TC_dyn_osmo_pdch_act_deact() );
6473 execute( TC_dyn_osmo_pdch_unsol_deact() );
6474 execute( TC_dyn_osmo_pdch_double_act() );
6475 execute( TC_dyn_osmo_pdch_tchf_act() );
6476 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006477 execute( TC_dyn_ipa_pdch_act_deact() );
6478 execute( TC_dyn_ipa_pdch_tchf_act() );
6479 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
6480 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006481
6482 execute( TC_rll_est_ind() );
6483 execute( TC_rll_est_req_DCCH_3() );
6484 execute( TC_rll_est_req_ACCH_3() );
6485 execute( TC_rll_rel_ind_DCCH_0() );
6486 execute( TC_rll_rel_ind_DCCH_3() );
6487 execute( TC_rll_rel_ind_ACCH_0() );
6488 execute( TC_rll_rel_ind_ACCH_3() );
6489 execute( TC_rll_rel_req() );
6490 execute( TC_rll_unit_data_req_DCCH() );
6491 execute( TC_rll_unit_data_req_ACCH() );
6492 execute( TC_rll_unit_data_ind_DCCH() );
6493 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006494
6495 execute( TC_chan_act_a51() );
6496 execute( TC_chan_act_a52() );
6497 execute( TC_chan_act_a53() );
6498 execute( TC_encr_cmd_a51() );
6499 execute( TC_encr_cmd_a52() );
6500 execute( TC_encr_cmd_a53() );
6501
Harald Welteee25aae2019-05-19 14:32:37 +02006502 execute( TC_err_rep_wrong_mdisc() );
6503 execute( TC_err_rep_wrong_msg_type() );
6504 execute( TC_err_rep_wrong_sequence() );
6505
Harald Weltee613f962018-04-18 22:38:16 +02006506 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006507
6508 execute( TC_tch_sign_l2_fill_frame() );
6509 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006510
6511 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006512 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006513}
6514
6515
6516}