blob: e10d967b0cc7e715c3d5a906c78642d712d88b79 [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,
196 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100197}
198
199/* Test-specific parameters */
200type union TestSpecUnion {
201 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100202}
203
Harald Welte82ccef72018-02-25 16:17:33 +0100204template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100205 max_retrans := RACH_MAX_RETRANS_7,
206 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100207 cell_barr_access := false,
208 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100209 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100210};
211
Harald Weltef10153f2018-02-25 16:34:05 +0100212template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100213 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200214 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100215 acs := '0'B,
216 neci := true,
217 rxlev_access_min := 0
218}
219
220template (value) LocationAreaIdentification ts_LAI_default := {
221 mcc_mnc := '262F42'H,
222 lac := 42
223}
224
Harald Welte7484fc42018-02-24 14:09:45 +0100225/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100226template (value) SystemInformation ts_SI3_default := {
227 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100228 payload := {
229 si3 := {
230 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100231 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100232 ctrl_chan_desc := {
233 msc_r99 := true,
234 att := true,
235 bs_ag_blks_res := 1,
236 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100237 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100238 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
239 spare := '00'B,
240 bs_pa_mfrms := 0, /* 2 multiframes */
241 t3212 := 1 /* 6 minutes */
242 },
Harald Welte82ccef72018-02-25 16:17:33 +0100243 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100244 dn_ind := false,
245 pwrc := false,
246 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100247 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100248 },
Harald Weltef10153f2018-02-25 16:34:05 +0100249 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100250 rach_control := ts_RachCtrl_default,
Harald Weltebe030482019-05-27 22:29:35 +0200251 rest_octets := '2C2B2B2B'O /* GPRS present */
Harald Welte7484fc42018-02-24 14:09:45 +0100252 }
253 }
254}
Harald Welte70767382018-02-21 12:16:40 +0100255
Harald Weltef8df4cb2018-03-10 15:15:08 +0100256template (value) SystemInformation ts_SI2_default := {
257 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100258 payload := {
259 si2 := {
260 bcch_freq_list := '00000000000000000000000000000000'O,
261 ncc_permitted := '11111111'B,
262 rach_control := ts_RachCtrl_default
263 }
264 }
265}
266
Harald Weltef8df4cb2018-03-10 15:15:08 +0100267template (value) SystemInformation ts_SI4_default := {
268 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100269 payload := {
270 si4 := {
271 lai := ts_LAI_default,
272 cell_sel_par := ts_CellSelPar_default,
273 rach_control := ts_RachCtrl_default,
274 cbch_chan_desc := omit,
275 cbch_mobile_alloc := omit,
276 rest_octets := ''O
277 }
278 }
279}
280
281function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
282runs on test_CT {
283 log("Setting ", rsl_si_type, ": ", si_enc);
284 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
285}
286
287function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
288runs on test_CT {
289 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
290 log("Setting ", rsl_si_type, ": ", si_dec);
291 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
292}
293
Harald Welte505cf9b2018-09-15 17:47:23 +0300294friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100295 map(self:BTSVTY, system:BTSVTY);
296 f_vty_set_prompts(BTSVTY);
297 f_vty_transceive(BTSVTY, "enable");
298}
299
Harald Welte505cf9b2018-09-15 17:47:23 +0300300friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200301 map(self:BSCVTY, system:BSCVTY);
302 f_vty_set_prompts(BSCVTY, "OsmoBSC");
303 f_vty_transceive(BSCVTY, "enable");
304}
305
Harald Welte883340c2018-02-28 18:59:29 +0100306/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200307private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
308 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100309 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200310 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
311 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100312 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200313 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100315 }
316}
317
Harald Weltef26de0b2018-04-04 20:28:05 +0200318private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
319 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100320 timer T := 2.0;
321 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100322 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200323 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100324 return;
325 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200326 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100327
328 T.start;
329 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200330 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100331 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100333 }
334 }
335}
336
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700337private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
338 out integer trxc_conn_id) {
339 var Result res;
340
341 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
342 "", -1, -1, { udp := {} }, {});
343 if (not ispresent(res.connId)) {
344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
345 "Could not connect to the control (TRXC) interface " &
346 "of FakeTRX, check your configuration");
347 }
348 trxc_conn_id := res.connId;
349}
350
Harald Welte70767382018-02-21 12:16:40 +0100351/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200352function f_init() runs on test_CT {
353 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100354 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100355 g_AllChannels := {
356 /* TS 1..4: TCH/F */
357 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
358 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
359 /* TS 5: TCH/H */
360 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
361 /* TS 0: SDCCH/4 */
362 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
363 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
364 /* TS 6: SDCCH/8 */
365 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
366 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
367 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
368 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
369 };
370
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200371 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700372 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200373 g_AllChanTypes := {
374 /* TS 1..4: TCH/F */
375 valueof(ts_RslChanNr_Bm(1)),
376 /* TS 5: TCH/H */
377 valueof(ts_RslChanNr_Lm(5,1)),
378 /* TS 0: SDCCH/4 */
379 valueof(ts_RslChanNr_SDCCH4(0,2)),
380 /* TS 6: SDCCH/8 */
381 valueof(ts_RslChanNr_SDCCH8(6,4))
382 };
383 } else {
384 g_AllChanTypes := {
385 /* TS 1..4: TCH/F */
386 valueof(ts_RslChanNr_Bm(1)),
387 /* TS 0: SDCCH/4 */
388 valueof(ts_RslChanNr_SDCCH4(0,2)),
389 /* TS 6: SDCCH/8 */
390 valueof(ts_RslChanNr_SDCCH8(6,4))
391 };
392 }
Harald Welte70767382018-02-21 12:16:40 +0100393 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200394 T.start;
395 alt {
396 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
397 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200399 }
400 }
Harald Welte2d142592018-02-25 13:19:44 +0100401 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100402 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200403 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100404
405 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100406 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
407 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
408 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
409 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100410
Harald Weltef26de0b2018-04-04 20:28:05 +0200411 map(self:PCU, system:PCU);
412 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100413
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700414 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100415 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700416
417 /* Init TRXC interface to FakeTRX */
418 map(self:BTS_TRXC, system:BTS_TRXC);
419 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
420
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700421 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700422 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 +0700423 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Harald Welte84271622018-03-10 17:21:03 +0100424 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200425
426 /* Wait some extra time to make sure the BTS emits a stable carrier.
427 * (this is only relevant when running the tests with a physical BTS.) */
428 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100429}
430
Harald Welte68e495b2018-02-25 00:05:57 +0100431/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
432function f_init_l1ctl() runs on test_CT {
433 map(self:L1CTL, system:L1CTL);
434 f_connect_reset(L1CTL);
435}
436
Harald Welte70767382018-02-21 12:16:40 +0100437type function void_fn(charstring id) runs on ConnHdlr;
438
439/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700440function f_start_handler(void_fn fn, ConnHdlrPars pars,
441 boolean pcu_comp := false,
442 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100443runs on test_CT return ConnHdlr {
444 var charstring id := testcasename();
445 var ConnHdlr vc_conn;
446
447 vc_conn := ConnHdlr.create(id);
448 /* connect to RSL Emulation main component */
449 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
450 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700451
452 /* The ConnHdlr component may want to talk to some ports directly,
453 * so we disconnect it from the test_CT and connect it to the component.
454 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200456 unmap(self:PCU, system:PCU);
457 map(vc_conn:PCU, system:PCU);
458 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700459 if (trxc_comp) {
460 unmap(self:BTS_TRXC, system:BTS_TRXC);
461 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
462 }
Harald Welte70767382018-02-21 12:16:40 +0100463
464 vc_conn.start(f_handler_init(fn, id, pars));
465 return vc_conn;
466}
467
Harald Welte7484fc42018-02-24 14:09:45 +0100468template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
469 streamId := sid,
470 rsl := rsl
471}
472
473template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
474 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
475 streamId := sid,
476 rsl := rsl
477}
478
Harald Welte70767382018-02-21 12:16:40 +0100479private altstep as_Tguard() runs on ConnHdlr {
480 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100482 }
483}
484
Harald Welte990a3612019-05-27 14:02:13 +0200485friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
486 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100487}
488
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700489private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100490 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700491 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100492}
493
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700494private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100495 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700496 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100497}
498
499/* first function started in ConnHdlr component */
500private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
501runs on ConnHdlr {
502 g_pars := pars;
503 g_chan_nr := pars.chan_nr;
504
505 map(self:L1CTL, system:L1CTL);
506 f_connect_reset(L1CTL);
507
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700508 if (mp_bts_trxc_port != -1) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700509 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100510 }
Harald Welte70767382018-02-21 12:16:40 +0100511
512 g_Tguard.start(pars.t_guard);
513 activate(as_Tguard());
514
515 f_rslem_register(0, pars.chan_nr);
516
517 /* call the user-supplied test case function */
518 fn.apply(id);
519}
520
Harald Welteb1726c92018-03-30 11:56:38 +0200521function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
522 boolean ignore_other := false)
523runs on ConnHdlr return RSL_Message {
524 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100525 timer T := 3.0;
526 RSL.send(tx);
527 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100528 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200529 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100530 T.stop;
531 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100532 }
Harald Welte1eba3742018-02-25 12:48:14 +0100533 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100535 }
Harald Welte21240e62018-03-11 21:43:35 +0100536 [not ignore_other] as_l1_sacch();
537 [not ignore_other] as_meas_res();
538 [not ignore_other] as_l1_dcch();
539 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100541 }
Harald Welte21240e62018-03-11 21:43:35 +0100542 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100543 }
Harald Welteb1726c92018-03-30 11:56:38 +0200544 return rx;
545}
546
547function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
548 boolean ignore_other := false)
549runs on ConnHdlr {
550 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100551}
552
Harald Welte8b01c792019-05-19 22:51:25 +0200553function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
554 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
555 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200556 if (encr_enable) {
557 /* append encryption related IEs, if requested */
558 var RSL_IE_EncryptionInfo encr_info;
559 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
560 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
561encr_info})) };
562 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200563 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200564 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100565}
566
Harald Welte70767382018-02-21 12:16:40 +0100567function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100568 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 +0100569 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100570}
571
Harald Welte2f2b2b72019-05-31 22:24:57 +0200572friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100573 template RSL_IE_ChannelMode chan_mode,
574 float t_guard := 20.0) := {
575 chan_nr := valueof(chan_nr),
576 chan_mode := valueof(chan_mode),
577 t_guard := t_guard,
578 l1_pars := {
579 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100580 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100581 meas_ul := {
582 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200583 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100584 rxqual := 0
585 },
586 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200587 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100588 rxqual := 0
589 }
590 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200591 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100592 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200593 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200594 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100595 },
Harald Weltee613f962018-04-18 22:38:16 +0200596 spec := omit,
597 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
Harald Welte93640c62018-02-25 16:59:33 +0100600/***********************************************************************
601 * Channel Activation / Deactivation
602 ***********************************************************************/
603
Harald Welte70767382018-02-21 12:16:40 +0100604/* Stress test: Do 500 channel activations/deactivations in rapid succession */
605function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
606 for (var integer i := 0; i < 500; i := i+1) {
607 f_rsl_chan_act(g_pars.chan_mode);
608 f_rsl_chan_deact();
609 }
610 setverdict(pass);
611}
612testcase TC_chan_act_stress() runs on test_CT {
613 var ConnHdlr vc_conn;
614 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200615 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100616 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
617 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100619}
620
621/* Test if re-activation of an already active channel fails as expected */
622function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
623 f_rsl_chan_act(g_pars.chan_mode);
624 /* attempt to activate the same lchan again -> expect reject */
625 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
626 alt {
627 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100629 }
630 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
631 setverdict(pass);
632 }
633 }
634 f_rsl_chan_deact();
635}
636testcase TC_chan_act_react() runs on test_CT {
637 var ConnHdlr vc_conn;
638 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100639 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100640 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
641 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
645/* Attempt to de-activate a channel that's not active */
646function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
647 timer T := 3.0;
648 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
649 T.start;
650 alt {
651 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
652 setverdict(pass);
653 }
654 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100656 }
657 }
658}
659testcase TC_chan_deact_not_active() runs on test_CT {
660 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100661 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100662 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
663 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100665}
666
667/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
668function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
669 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
670 alt {
671 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100673 }
674 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
675 setverdict(pass);
676 }
677 }
678}
679private type record WrongChanNrCase {
680 RslChannelNr chan_nr,
681 charstring description
682}
683private type record of WrongChanNrCase WrongChanNrCases;
684private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
685 chan_nr := chan_nr,
686 description := desc
687}
688
689testcase TC_chan_act_wrong_nr() runs on test_CT {
690 var ConnHdlr vc_conn;
691 var ConnHdlrPars pars;
692
Harald Welte294b0a22018-03-10 23:26:48 +0100693 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100694
695 var WrongChanNrCases wrong := {
696 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
697 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
698 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
699 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
700 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
701 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
702 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
703 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
704 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
705 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
706 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
707 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
708 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
709 };
710
711 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
712 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
713 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
714 vc_conn.done;
715 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100717}
718
Harald Weltee613f962018-04-18 22:38:16 +0200719/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200720friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200721 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200722 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200723
724 /* test on each of the channels we have */
725 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
726 pars.chan_nr := valueof(g_AllChanTypes[i]);
727
728 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
729 vc_conn := f_start_handler(fn, pars);
730 vc_conn.done;
731 }
732
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200734}
735
Harald Welte93640c62018-02-25 16:59:33 +0100736/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100737 * SACCH handling
738 ***********************************************************************/
739
740private function f_exp_sacch(boolean exp) runs on ConnHdlr {
741 timer T_sacch := 3.0;
742 T_sacch.start;
743 alt {
744 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100746 }
747 [not exp] T_sacch.timeout {
748 setverdict(pass);
749 }
750 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
751 setverdict(pass);
752 }
753 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100755 }
756 [] L1CTL.receive { repeat; }
757 [] RSL.receive { repeat; }
758 }
759}
760
761/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
762private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
763 f_l1_tune(L1CTL);
764 RSL.clear;
765
766 /* activate the logical channel */
767 f_est_dchan();
768 L1CTL.clear;
769
770 /* check that SACCH actually are received as expected */
771 f_exp_sacch(true);
772
773 /* deactivate SACCH on the logical channel */
774 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
775 f_sleep(1.0);
776 L1CTL.clear;
777
778 /* check that no SACCH are received anymore */
779 f_exp_sacch(false);
780
781 /* release the channel */
782 f_rsl_chan_deact();
783 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
784}
785testcase TC_deact_sacch() runs on test_CT {
786 var ConnHdlr vc_conn;
787 var ConnHdlrPars pars;
788 f_init();
789 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
790 //for (var integer i := 0; i < 1; i := i+1) {
791 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
792 log(testcasename(), ": Starting for ", g_AllChannels[i]);
793 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
794 vc_conn.done;
795 }
796 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100798}
799
Harald Welte55700662018-03-12 13:15:43 +0100800/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100801private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
802 var L1ctlDlMessage dl;
803 /* check that the specified SI5 value is actually sent */
804 timer T_sacch := 3.0;
805 L1CTL.clear;
806 T_sacch.start;
807 alt {
808 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
809 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
810 if (match(l3, l3_exp)) {
811 setverdict(pass);
812 } else {
813 repeat;
814 }
815 }
816 [] L1CTL.receive { repeat; }
817 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100819 }
820 }
821}
822
Harald Welte55700662018-03-12 13:15:43 +0100823/* verify that given SACCH payload is not present */
824private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
825 var L1ctlDlMessage dl;
826 /* check that the specified SI5 value is actually sent */
827 timer T_sacch := 3.0;
828 L1CTL.clear;
829 T_sacch.start;
830 alt {
831 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
832 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
833 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100835 } else {
836 repeat;
837 }
838 }
839 [] L1CTL.receive { repeat; }
840 [] T_sacch.timeout {
841 setverdict(pass);
842 }
843 }
844}
845
Harald Welte629cc6b2018-03-11 17:19:05 +0100846/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100847private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
848 /* Set a known default SACCH filling for SI5 */
849 var octetstring si5 := f_rnd_octstring(19);
850 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
851
852 f_l1_tune(L1CTL);
853 RSL.clear;
854
855 /* activate the logical channel */
856 f_est_dchan();
857
858 /* check that the specified SI5 value is actually sent */
859 f_sacch_present(si5);
860
861 /* release the channel */
862 RSL.clear;
863 f_rsl_chan_deact();
864 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
865}
866testcase TC_sacch_filling() runs on test_CT {
867 var ConnHdlr vc_conn;
868 var ConnHdlrPars pars;
869 f_init();
870 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
871 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
872 log(testcasename(), ": Starting for ", g_AllChannels[i]);
873 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
874 vc_conn.done;
875 }
876 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100878}
879
Harald Welte629cc6b2018-03-11 17:19:05 +0100880/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100881private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
882 /* Set a known default SACCH filling for SI5 */
883 var octetstring si5 := f_rnd_octstring(19);
884 var octetstring si5_diff := f_rnd_octstring(19);
885 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
886
887 f_l1_tune(L1CTL);
888 RSL.clear;
889
890 log("Activating channel, expecting standard SI5");
891 /* activate the logical channel */
892 f_est_dchan();
893 /* check that the specified SI5 value is actually sent */
894 f_sacch_present(si5);
895
896 /* set channel-specific different SI5 */
897 log("Setting channel specific SACCH INFO, expecting it");
898 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
899 /* check that the specified lchan-specific value is now used */
900 f_sacch_present(si5_diff);
901
902 /* deactivate the channel and re-activate it, this should result in default SI5 */
903 log("De-activating and re-activating channel, expecting standard SI5");
904 f_rsl_chan_deact();
905 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
906 /* Verify that the TRX-wide default SACCH filling is present again */
907 f_sacch_present(si5);
908
909 /* release the channel */
910 RSL.clear;
911 f_rsl_chan_deact();
912 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
913}
914testcase TC_sacch_info_mod() runs on test_CT {
915 var ConnHdlr vc_conn;
916 var ConnHdlrPars pars;
917 f_init();
918 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
919 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
920 log(testcasename(), ": Starting for ", g_AllChannels[i]);
921 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
922 vc_conn.done;
923 }
924 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100926}
927
Harald Welte075d84c2018-03-12 13:07:24 +0100928/* Test SACCH scheduling of multiple different SI message types */
929private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
930 var octetstring si5 := f_rnd_octstring(19);
931 var octetstring si5bis := f_rnd_octstring(19);
932 var octetstring si5ter := f_rnd_octstring(19);
933 var octetstring si6 := f_rnd_octstring(19);
934
935 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
936 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
937 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
938 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
939
940 f_l1_tune(L1CTL);
941 RSL.clear;
942
943 /* activate the logical channel */
944 f_est_dchan();
945 L1CTL.clear;
946
947 /* check that SACCH actually are received as expected */
948 f_sacch_present(si5);
949 f_sacch_present(si5bis);
950 f_sacch_present(si5ter);
951 f_sacch_present(si6);
952
953 /* release the channel */
954 f_rsl_chan_deact();
955 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
956}
957testcase TC_sacch_multi() runs on test_CT {
958 var ConnHdlr vc_conn;
959 var ConnHdlrPars pars;
960 f_init();
961 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
962 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
963 log(testcasename(), ": Starting for ", g_AllChannels[i]);
964 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
965 vc_conn.done;
966 }
967 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200968 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100969}
970
Harald Welte55700662018-03-12 13:15:43 +0100971/* Test if SACH information is modified as expected */
972private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
973 var octetstring si5 := f_rnd_octstring(19);
974 var octetstring si6 := f_rnd_octstring(19);
975
976 /* First, configure both SI5 and SI6 to be transmitted */
977 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
978 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
979
980 f_l1_tune(L1CTL);
981 RSL.clear;
982
983 /* activate the logical channel */
984 f_est_dchan();
985 L1CTL.clear;
986
987 /* check that SACCH actually are received as expected */
988 f_sacch_present(si5);
989 f_sacch_present(si6);
990
991 /* disable SI6 */
992 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
993
994 /* check that SI5 is still transmitted */
995 f_sacch_present(si5);
996 /* check if SI6 is now gone */
997 f_sacch_missing(si6);
998
999 /* release the channel */
1000 f_rsl_chan_deact();
1001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1002}
1003testcase TC_sacch_multi_chg() runs on test_CT {
1004 var ConnHdlr vc_conn;
1005 var ConnHdlrPars pars;
1006 f_init();
1007 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1008 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1009 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1010 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1011 vc_conn.done;
1012 }
1013 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001015}
1016
Harald Weltec8d363c2019-05-19 20:36:48 +02001017/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1018private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1019 var octetstring si5 := f_rnd_octstring(19);
1020 var octetstring si6 := f_rnd_octstring(19);
1021 var octetstring si5_specific := f_rnd_octstring(19);
1022 var octetstring si6_specific := f_rnd_octstring(19);
1023
1024 /* First, configure both SI5 and SI6 to be transmitted */
1025 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1026 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1027
1028 f_l1_tune(L1CTL);
1029 RSL.clear;
1030
1031 /* activate channel with different SACCH filling */
1032 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1033 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1034 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1035 }));
1036 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1037 RSL_IE_Body:{sacch_info := sacch_info})) };
1038 f_est_dchan(more_ies := addl_ies);
1039
1040 /* check that SACCH actually are received as expected */
1041 f_sacch_present(si5_specific);
1042 f_sacch_present(si6_specific);
1043
1044 /* release the channel */
1045 f_rsl_chan_deact();
1046 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1047}
1048testcase TC_sacch_chan_act() runs on test_CT {
1049 var ConnHdlr vc_conn;
1050 var ConnHdlrPars pars;
1051 f_init();
1052
1053 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1054 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1055 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1056 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1057 vc_conn.done;
1058 }
1059 /* TODO: do the above in parallel, rather than sequentially? */
1060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1061}
1062
Harald Welte8b01c792019-05-19 22:51:25 +02001063/* verify that SACCH DL transmission is started only if MS power IE present
1064 * see section 4.1.3 of 3GPP TS 48.058 */
1065private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1066 var octetstring si5 := f_rnd_octstring(19);
1067
1068 f_l1_tune(L1CTL);
1069 RSL.clear;
1070
1071 /* Step 1: Activate ASYNC HO channel without MS power IE */
1072
1073 /* Activate channel on BTS side */
1074 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1075 /* don't perform immediate assignment here, as we're testing non-IA case */
1076 /* enable dedicated mode */
1077 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1078
1079 /* Verify that no DL SACCH is being received */
1080 f_sacch_missing(?);
1081
1082 f_rsl_chan_deact();
1083 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1084
1085
1086 /* Step 2: Activate ASYNC HO channel with MS power IE */
1087
1088 /* Activate channel on BTS side */
1089 var RSL_IE_List addl_ies := {
1090 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1091 };
1092 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1093 /* don't perform immediate assignment here, as we're testing non-IA case */
1094 /* enable dedicated mode */
1095 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1096
1097 /* Verify that DL SACCH is being received */
1098 f_sacch_present(si5);
1099
1100 f_rsl_chan_deact();
1101 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1102}
1103testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1104 var ConnHdlr vc_conn;
1105 var ConnHdlrPars pars;
1106 f_init();
1107
1108 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1109 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1110 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1111 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1112 vc_conn.done;
1113 }
1114 /* TODO: do the above in parallel, rather than sequentially? */
1115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1116}
1117
1118/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1119 * see section 4.1.4 of 3GPP TS 48.058 */
1120private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1121 var octetstring si5 := f_rnd_octstring(19);
1122 var RSL_IE_List addl_ies;
1123
1124 f_l1_tune(L1CTL);
1125 RSL.clear;
1126
1127 /* Step 1: Activate SYNC HO channel without MS power IE */
1128
1129 /* Activate channel on BTS side */
1130 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1131 /* don't perform immediate assignment here, as we're testing non-IA case */
1132 /* enable dedicated mode */
1133 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1134
1135 /* Verify that no DL SACCH is being received */
1136 f_sacch_missing(?);
1137
1138 f_rsl_chan_deact();
1139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1140
1141
1142 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1143
1144 /* Activate channel on BTS side */
1145 addl_ies := {
1146 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1147 };
1148 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1149 /* don't perform immediate assignment here, as we're testing non-IA case */
1150 /* enable dedicated mode */
1151 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1152
1153 /* Verify that no DL SACCH is being received */
1154 f_sacch_missing(?);
1155
1156 f_rsl_chan_deact();
1157 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1158
1159
1160 /* Step 2b: Activate SYNC HO channel with TA IE */
1161
1162 /* Activate channel on BTS side */
1163 addl_ies := {
1164 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1165 };
1166 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1167 /* don't perform immediate assignment here, as we're testing non-IA case */
1168 /* enable dedicated mode */
1169 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1170
1171 /* Verify that no DL SACCH is being received */
1172 f_sacch_missing(?);
1173
1174 f_rsl_chan_deact();
1175 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1176
1177
1178 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1179
1180 /* Activate channel on BTS side */
1181 addl_ies := {
1182 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1183 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1184 };
1185 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1186 /* don't perform immediate assignment here, as we're testing non-IA case */
1187 /* enable dedicated mode */
1188 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1189
1190 /* Verify that DL SACCH is being received */
1191 f_sacch_present(si5);
1192
1193 f_rsl_chan_deact();
1194 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1195}
1196testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1197 var ConnHdlr vc_conn;
1198 var ConnHdlrPars pars;
1199 f_init();
1200
1201 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1202 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1203 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1204 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1205 vc_conn.done;
1206 }
1207 /* TODO: do the above in parallel, rather than sequentially? */
1208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1209}
Harald Welte629cc6b2018-03-11 17:19:05 +01001210
1211
1212/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001213 * RACH Handling
1214 ***********************************************************************/
1215
Harald Welte8c24c2b2018-02-26 08:31:31 +01001216/* like L1SAP_IS_PACKET_RACH */
1217private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001218 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001219 return true;
1220 }
1221 return false;
1222}
1223
1224/* generate a random RACH for circuit-switched */
1225private function f_rnd_ra_cs() return OCT1 {
1226 var OCT1 ra;
1227 do {
1228 ra := f_rnd_octstring(1);
1229 } while (ra_is_ps(ra));
1230 return ra;
1231}
1232
Harald Welte883340c2018-02-28 18:59:29 +01001233/* generate a random RACH for packet-switched */
1234private function f_rnd_ra_ps() return OCT1 {
1235 var OCT1 ra;
1236 do {
1237 ra := f_rnd_octstring(1);
1238 } while (not ra_is_ps(ra));
1239 return ra;
1240}
1241
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001242/* generate a random 11-bit RA (packet-switched only) */
1243private function f_rnd_ra11_ps() return BIT11 {
1244 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1245 return int2bit(ra11, 11);
1246}
1247
Harald Welte8c24c2b2018-02-26 08:31:31 +01001248/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1249testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001250 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001251 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001252 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001253
Harald Welte8c24c2b2018-02-26 08:31:31 +01001254 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001255 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001256 for (var integer i := 0; i < 1000; i := i+1) {
1257 var OCT1 ra := f_rnd_ra_cs();
1258 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1259 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001261 }
1262 fn_last := fn;
1263
1264 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001265 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001266 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001267 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001268 T.stop;
1269 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001270 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001272 }
1273 [] RSL_CCHAN.receive { repeat; }
1274 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001275 test_failed := true;
1276 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001277 }
1278 }
1279 }
Maxba06feb2019-03-05 10:52:46 +01001280 if (test_failed) {
1281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001282 }
Maxba06feb2019-03-05 10:52:46 +01001283 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001285}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001286
1287/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1288testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001289 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001290 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001291 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001292 f_l1_tune(L1CTL);
1293
1294 var GsmFrameNumber fn_last := 0;
1295 for (var integer i := 0; i < 1000; i := i+1) {
1296 var OCT1 ra := f_rnd_ra_cs();
1297 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1298 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001300 }
1301 fn_last := fn;
1302 }
1303 var integer rsl_chrqd := 0;
1304 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001305 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001306 alt {
1307 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1308 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001309 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001310 repeat;
1311 }
1312 [] RSL_CCHAN.receive { repeat; }
1313 [] T.timeout { }
1314 }
1315 if (rsl_chrqd == 1000) {
1316 setverdict(pass);
1317 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001319 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001321}
1322
Harald Welte3453ab42019-05-24 21:19:58 +02001323private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1324 var charstring bts_str := "bts " & int2str(bts_nr);
1325 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1326}
1327
1328/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1329private template integer tr_rach_slots_per_interval := (90 .. 130);
1330
1331/* Expect 0 RACH load on an idle BTS that has just started up */
1332testcase TC_rach_load_idle_thresh0() runs on test_CT {
1333 var ASP_RSL_Unitdata rx_ud;
1334
1335 f_init_vty_bsc();
1336 /* send load indications even at 0% load */
1337 f_vty_load_ind_thresh(0);
1338 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1339 f_sleep(2.0);
1340
1341 f_init();
1342
1343 timer T := 5.0;
1344 T.start;
1345 alt {
1346 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1347 setverdict(pass);
1348 repeat;
1349 }
1350 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1351 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1352 repeat;
1353 }
1354 [] RSL_CCHAN.receive {
1355 repeat;
1356 }
1357 [] T.timeout { }
1358 }
1359
1360 f_vty_load_ind_thresh(10);
1361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1362}
1363
1364/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1365testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1366 var ASP_RSL_Unitdata rx_ud;
1367
1368 f_init_vty_bsc();
1369 f_init();
1370
1371 timer T := 5.0;
1372 T.start;
1373 alt {
1374 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1375 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1376 repeat;
1377 }
1378 [] RSL_CCHAN.receive {
1379 repeat;
1380 }
1381 [] T.timeout {
1382 setverdict(pass);
1383 }
1384 }
1385
1386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1387}
1388
1389/* Expect 0 RACH load on an idle BTS that has just started up */
1390testcase TC_rach_load_count() runs on test_CT {
1391 var ASP_RSL_Unitdata rx_ud;
1392 var integer load_access_count := 0;
1393
1394 f_init_vty_bsc();
1395 /* send load indications even at 0% load */
1396 f_vty_load_ind_thresh(0);
1397 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1398 f_sleep(2.0);
1399 f_init();
1400
1401 f_init_l1ctl();
1402 f_sleep(1.0);
1403 f_l1_tune(L1CTL);
1404
1405 var GsmFrameNumber fn_last := 0;
1406 for (var integer i := 0; i < 1000; i := i+1) {
1407 var OCT1 ra := f_rnd_ra_cs();
1408 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1409 if (fn == fn_last) {
1410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1411 }
1412 fn_last := fn;
1413 }
1414
1415 timer T := 5.0;
1416 T.start;
1417 alt {
1418 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1419 -> value rx_ud {
1420 var RSL_IE_Body ie;
1421 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1422 load_access_count := load_access_count + ie.rach_load.access_count;
1423 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1424 setverdict(fail, "Access count cannot be < Busy count");
1425 }
1426 repeat;
1427 }
1428 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1429 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1430 repeat;
1431 }
1432 [] RSL_CCHAN.receive {
1433 repeat;
1434 }
1435 [] T.timeout { }
1436 }
1437 if (load_access_count == 1000) {
1438 setverdict(pass);
1439 } else {
1440 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1441 }
1442
1443 f_vty_load_ind_thresh(10);
1444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1445}
1446
Harald Welte54a2a2d2018-02-26 09:14:05 +01001447private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001448 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001449 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001450 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001451 f_sleep(0.5);
1452
1453 /* Transmit RACH request + wait for confirmation */
1454 var OCT1 ra := f_rnd_ra_cs();
1455 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1456
1457 /* Check for expected result */
1458 timer T := 1.5;
1459 T.start;
1460 alt {
1461 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1462 setverdict(pass);
1463 }
1464 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001466 }
1467 [] RSL_CCHAN.receive { repeat; }
1468 [not expect_pass] T.timeout {
1469 setverdict(pass);
1470 }
1471 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001473 }
1474 }
1475}
1476
1477/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1478testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001479 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001480 f_init_l1ctl();
1481 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001482 f_sleep(1.0);
1483
1484 /* default max-ta is 63 (full range of GSM timing advance */
1485
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001486 /* We allow early arrival up to 2 symbols */
1487 f_rach_toffs(-1*256, true);
1488 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001489 f_rach_toffs(-10*256, false);
1490
1491 /* 0 / 32 / 63 bits is legal / permitted */
1492 f_rach_toffs(0, true);
1493 f_rach_toffs(32*256, true);
1494 f_rach_toffs(63*256, true);
1495
1496 /* more than 63 bits is not legal / permitted */
1497 f_rach_toffs(64*256, false);
1498 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001500}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001501
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001502function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1503 var GsmFrameNumber fn;
1504 var RSL_Message rm;
1505
1506 f_l1_tune(L1CTL);
1507 RSL.clear;
1508
1509 /* Generate a random Handover Reference */
1510 var integer ho_ref := oct2int(f_rnd_octstring(1));
1511
1512 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1513 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1514 RSL_IE_Body:{ handover_ref := ho_ref }));
1515
1516 /* Activate a channel on the BTS side (no encryption) */
1517 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1518 act_type := t_RSL_IE_ActType_HO_SYNC);
1519
1520 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1521 * waiting for Immediate Assignment and sending Access Burst */
1522 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1523
1524 /* Send handover Access Burst */
1525 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1526
1527 /* TODO: test mismatching Handover Reference, and missing IE */
1528
1529 /* Wait for handover detection */
1530 timer T := 3.0;
1531 T.start;
1532 alt {
1533 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1534 log("Handover RACH has been detected: ", rm);
1535 setverdict(pass);
1536 }
1537 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1539 log2str("RSL_CHAN_RQD was not expected: ", rm));
1540 }
1541 [] RSL.receive { repeat; }
1542 [] T.timeout {
1543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1544 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1545 }
1546 }
1547
1548 /* Release the channel */
1549 f_rsl_chan_deact();
1550 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1551}
1552
1553/* Test handover RACH detection */
1554testcase TC_ho_rach() runs on test_CT {
1555 var ConnHdlrPars pars;
1556 var ConnHdlr vc_conn;
1557
1558 f_init();
1559
1560 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1561 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1562 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1563 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1564 vc_conn.done;
1565 }
1566
1567 /* TODO: do the above in parallel, rather than sequentially? */
1568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1569}
1570
Harald Welte93640c62018-02-25 16:59:33 +01001571/***********************************************************************
1572 * Measurement Processing / Reporting
1573 ***********************************************************************/
1574
Harald Welte70767382018-02-21 12:16:40 +01001575template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1576 spare := '0'B,
1577 lpd := 0,
1578 sapi := sapi,
1579 c_r := c_r,
1580 ea := true
1581}
1582
Harald Welted879bd92018-03-12 15:01:23 +01001583template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001584 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001585 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001586 len := 0, /* overwritten */
1587 m := false,
1588 el := 1,
1589 payload := pl
1590}
1591
1592/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1593altstep as_l1_sacch() runs on ConnHdlr {
1594 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001595 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001596 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001597 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 +01001598 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001599 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001600
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001601 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1602 g_pars.l1_pars.ms_power_level, false,
1603 g_pars.l1_pars.ms_actual_ta);
1604
1605 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1606 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1607
1608 log("Sending Measurement Report: ", l1h, l2);
1609 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001610 repeat;
1611 }
1612}
1613
1614altstep as_l1_dcch() runs on ConnHdlr {
1615 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001616 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001617 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1618 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001619 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1620 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001621 repeat;
1622 }
1623}
1624
1625type record MeasElem {
1626 uint6_t rxlev,
1627 uint3_t rxqual
1628}
1629
1630type record MeasElemFS {
1631 MeasElem full,
1632 MeasElem sub
1633}
1634
1635type record ConnL1Pars {
1636 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001637 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001638 MeasElemFS meas_ul,
1639 int16_t timing_offset_256syms,
1640 uint5_t bs_power_level,
1641 uint5_t ms_power_level,
1642 uint8_t ms_actual_ta
1643}
1644
1645/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1646private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1647 return 63 + (toffs256s/256);
1648}
1649
Harald Welted5684392018-03-10 18:22:04 +01001650private function f_max(integer a, integer b) return integer {
1651 if (a > b) {
1652 return a;
1653 } else {
1654 return b;
1655 }
1656}
1657
1658private function f_min(integer a, integer b) return integer {
1659 if (a < b) {
1660 return a;
1661 } else {
1662 return b;
1663 }
1664}
1665
1666/* compute negative tolerance val-tolerance, ensure >= min */
1667private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1668 val := val - tolerance;
1669 return f_max(val, min);
1670}
1671
1672/* compute positive tolerance val+tolerance, ensure <= max */
1673private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1674 val := val + tolerance;
1675 return f_min(val, max);
1676}
1677
1678/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1679private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1680return template integer {
1681 var template integer ret;
1682 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1683 return ret;
1684}
1685
1686
Harald Welte70767382018-02-21 12:16:40 +01001687/* build a template for matching measurement results against */
1688private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1689 var ConnL1Pars l1p := g_pars.l1_pars;
1690 var template RSL_IE_UplinkMeas ul_meas := {
1691 len := 3,
1692 rfu := '0'B,
1693 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001694 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001695 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001696 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001697 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001698 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1699 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001700 supp_meas_info := omit
1701 };
Harald Welte685d5982018-02-27 20:42:05 +01001702 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001703 ul_meas.len := (3+8);
1704 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001705 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001706 toa256_min := ?,
1707 toa256_max := ?,
1708 toa256_std_dev := ?
1709 }
Harald Welte685d5982018-02-27 20:42:05 +01001710 }
Harald Welte70767382018-02-21 12:16:40 +01001711 var template RSL_IE_BS_Power bs_power := {
1712 reserved := 0,
1713 epc := false,
1714 fpc := false,
1715 power_level := l1p.bs_power_level
1716 };
1717 var template RSL_IE_L1Info l1_info := {
1718 ms_power_lvl := l1p.ms_power_level,
1719 fpc := false,
1720 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001721 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001722 };
1723 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001724 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001725 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1726 ?, t_toffs);
1727}
1728
1729/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001730altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001731 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001732 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001733 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1734 /* increment counter of next to-be-expected meas rep */
1735 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1736 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001737 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001738 repeat;
1739 }
1740 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001741 /* increment counter of next to-be-expected meas rep */
1742 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1743 if (g_first_meas_res) {
1744 g_first_meas_res := false;
1745 repeat;
1746 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001748 }
Harald Welte70767382018-02-21 12:16:40 +01001749 }
1750 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001752 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001753 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001755 }
1756}
1757
Harald Weltee613f962018-04-18 22:38:16 +02001758private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1759 select (rsl_alg_id) {
1760 case (RSL_ALG_ID_A5_0) { return 0; }
1761 case (RSL_ALG_ID_A5_1) { return 1; }
1762 case (RSL_ALG_ID_A5_2) { return 2; }
1763 case (RSL_ALG_ID_A5_3) { return 3; }
1764 case (RSL_ALG_ID_A5_4) { return 4; }
1765 case (RSL_ALG_ID_A5_5) { return 5; }
1766 case (RSL_ALG_ID_A5_6) { return 6; }
1767 case (RSL_ALG_ID_A5_7) { return 7; }
1768 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1770 /* Make compiler happy by calling mtc.stop here. It is already
1771 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001772 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001773 }
1774 }
1775}
1776
1777private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1778 select (rsl_alg_id) {
1779 case (RSL_ALG_ID_A5_1) { return '000'B; }
1780 case (RSL_ALG_ID_A5_2) { return '001'B; }
1781 case (RSL_ALG_ID_A5_3) { return '010'B; }
1782 case (RSL_ALG_ID_A5_4) { return '011'B; }
1783 case (RSL_ALG_ID_A5_5) { return '100'B; }
1784 case (RSL_ALG_ID_A5_6) { return '101'B; }
1785 case (RSL_ALG_ID_A5_7) { return '110'B; }
1786 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1788 /* Make compiler happy by calling mtc.stop here. It is already
1789 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001790 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001791 }
1792 }
1793}
1794
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001795/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1796private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1797 var GsmFrameNumber fn;
1798 timer T := 8.0;
1799
1800 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1801 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1802
1803 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1804 /* Send the actual RACH */
1805 fn := f_L1CTL_RACH(L1CTL, ra);
1806
1807 T.start;
1808 alt {
1809 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1810 [] T.timeout {
1811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1812 }
1813 }
1814 T.stop
1815 return fn;
1816}
Harald Weltee613f962018-04-18 22:38:16 +02001817
Harald Welte70767382018-02-21 12:16:40 +01001818/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001819private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001820 var GsmFrameNumber fn;
1821 var ImmediateAssignment imm_ass;
1822 var integer ra := 23;
1823
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001824 /* Send RACH request and wait for ChanReq */
1825 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001826
1827 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001828 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001829
1830 /* Send IMM.ASS via CCHAN */
1831 var ChannelDescription ch_desc := {
1832 chan_nr := g_pars.chan_nr,
1833 tsc := 7,
1834 h := false,
1835 arfcn := mp_trx0_arfcn,
1836 maio_hsn := omit
1837 };
1838 var MobileAllocation ma := {
1839 len := 0,
1840 ma := ''B
1841 };
1842 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1843 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1844
1845 /* receive IMM.ASS on MS side */
1846 var ImmediateAssignment ia_um;
1847 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1848 /* enable dedicated mode */
1849 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001850 /* enable encryption, if requested */
1851 if (encr_enable) {
1852 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1853 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1854 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001855
1856 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001857}
1858
1859/* establish DChan, verify existance + contents of measurement reports */
1860function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001861 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001862 RSL.clear;
1863
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001864 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001865 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001866 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001867 }
Harald Welte70767382018-02-21 12:16:40 +01001868
1869 f_est_dchan();
1870
1871 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1872 * RSL measurement reports on Abis side */
1873 timer T := 8.0;
1874 T.start;
1875 alt {
1876 [] as_l1_sacch();
1877 [] as_meas_res();
1878 [] as_l1_dcch();
1879 [] L1CTL.receive { repeat; }
1880 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001881 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001882 * of any earlier errors, so if we reach this timeout, we're good */
1883 setverdict(pass);
1884 }
1885 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001887 }
1888 }
1889 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001890 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001891}
Harald Welte0472ab42018-03-12 15:02:26 +01001892
Harald Welte70767382018-02-21 12:16:40 +01001893testcase TC_meas_res_sign_tchf() runs on test_CT {
1894 var ConnHdlr vc_conn;
1895 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001896 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001897 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1898 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07001899 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
1900 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01001901 vc_conn.done;
1902 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001904}
1905testcase TC_meas_res_sign_tchh() runs on test_CT {
1906 var ConnHdlr vc_conn;
1907 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001908 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001909 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1910 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1911 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1912 vc_conn.done;
1913 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001915}
1916testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1917 var ConnHdlr vc_conn;
1918 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001919 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001920 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1921 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1922 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1923 vc_conn.done;
1924 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001926}
1927testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1928 var ConnHdlr vc_conn;
1929 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001930 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001931 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1932 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1933 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1934 vc_conn.done;
1935 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001937}
Harald Welte685d5982018-02-27 20:42:05 +01001938testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1939 var ConnHdlr vc_conn;
1940 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001941 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01001942 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1943 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1944 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1945 pars.l1_pars.toa256_enabled := true;
1946 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1947 vc_conn.done;
1948 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001950}
1951
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001952/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1953 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1954function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1955 var L1ctlDlMessage l1_dl;
1956 var RSL_IE_MS_Power ms_power;
1957 var RSL_Message rsl;
1958 var uint5_t power_level := 0;
1959
1960 f_l1_tune(L1CTL);
1961 RSL.clear;
1962
1963 f_est_dchan();
1964
1965 ms_power.reserved := 0;
1966 ms_power.fpc_epc := false;
1967
1968 /* Send the first power control command. This will disable any BTS/TRX
1969 * internal power control and switch the MS (which is not in scope of
1970 * this test) to a constant power level. We start with a power level
1971 * of 0 */
1972 ms_power.power_level := power_level;
1973 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1974 RSL.send(rsl);
1975
1976 alt {
1977
1978 /* Pick all SACCH blocks for checking */
1979 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1980
1981 /* The first byte of the L1 header contains the power level.
1982 * The reserved bits and the fpc bit is set to 0, so we may
1983 * compare directly. */
1984 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1985 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1986 }
1987
1988 /* Signal a new power level via RSL for the next turn. */
1989 if (power_level < 31) {
1990 power_level := power_level + 1;
1991 ms_power.power_level := power_level;
1992 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1993 RSL.send(rsl);
1994 repeat;
1995 }
1996
1997 }
1998
1999 /* Ignore all other blocks */
2000 [] L1CTL.receive { repeat; }
2001
2002 }
2003
2004 f_rsl_chan_deact();
2005 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2006
2007 setverdict(pass);
2008}
2009
2010testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2011 var ConnHdlr vc_conn;
2012 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002013 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002014
2015 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2016 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2017 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2018 vc_conn.done;
2019 }
2020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2021}
Harald Welte70767382018-02-21 12:16:40 +01002022
Eric Wild6833cc92019-05-23 19:34:44 +02002023/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2024TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2025function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2026 var L1ctlDlMessage l1_dl;
2027 var uint5_t ta_to_test := 16;
2028
2029
2030 f_l1_tune(L1CTL);
2031 RSL.clear;
2032
2033 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002034 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002035
2036 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2037
2038
2039 alt {
2040
2041 /* Pick all SACCH blocks for checking */
2042 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2043
2044 /* The second byte of the L1 header contains the TA. */
2045 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2046 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2047 }
2048
2049 }
2050
2051 /* Ignore all other blocks */
2052 [] L1CTL.receive { repeat; }
2053
2054 }
2055
2056 f_rsl_chan_deact();
2057 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2058
2059 setverdict(pass);
2060}
2061
2062testcase TC_rsl_chan_initial_ta() runs on test_CT {
2063 var ConnHdlr vc_conn;
2064 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002065 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002066 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002067 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2068 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002069 vc_conn.done;
2070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2071}
2072
Eric Wilde57e1a62019-05-28 13:30:55 +02002073/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2074function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2075 var L1ctlDlMessage l1_dl;
2076 var uint5_t ms_power_level := 7;
2077
2078 var RSL_IE_MS_Power ms_power;
2079 ms_power.reserved := 0;
2080 ms_power.fpc_epc := false;
2081 ms_power.power_level := ms_power_level;
2082
2083 f_l1_tune(L1CTL);
2084 RSL.clear;
2085
2086 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2087
2088 timer T := 1.0;
2089 T.start;
2090 alt {
2091 /* Pick all SACCH blocks for checking */
2092 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2093 /* The first byte of the L1 header contains the power level.. */
2094 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2095 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2096 }
2097 }
2098 /* Ignore all other blocks */
2099 [] L1CTL.receive { repeat; }
2100 [] T.timeout {
2101 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2102 }
2103 }
2104
2105 f_rsl_chan_deact();
2106 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2107 setverdict(pass);
2108}
2109
2110testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2111 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2112 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2113}
2114
Harald Welte0472ab42018-03-12 15:02:26 +01002115/* 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 +01002116private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002117 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002118 RSL.clear;
2119
2120 f_est_dchan();
2121 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002122 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002123
2124 timer T := 40.0;
2125 T.start;
2126 alt {
2127 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2128 setverdict(pass)
2129 }
2130 [] RSL.receive { repeat };
2131 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002133 }
2134 }
2135 f_rsl_chan_deact();
2136}
2137testcase TC_conn_fail_crit() runs on test_CT {
2138 var ConnHdlr vc_conn;
2139 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002140 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002141 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2142 pars.t_guard := 60.0;
2143 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2144 vc_conn.done;
2145}
2146
Harald Welte93640c62018-02-25 16:59:33 +01002147/***********************************************************************
2148 * Paging
2149 ***********************************************************************/
2150
Harald Welte68e495b2018-02-25 00:05:57 +01002151function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2152 if (tmsi == 'FFFFFFFF'O) {
2153 return true;
2154 } else {
2155 return false;
2156 }
2157}
Harald Welte70767382018-02-21 12:16:40 +01002158
Philipp Maier82cb0b12018-08-31 14:41:39 +02002159type record allowedFn { integer frame_nr }
2160template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2161template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2162template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2163template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2164template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2165template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2166template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2167template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2168function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2169{
2170 var integer frame_nr_51;
2171 frame_nr_51 := frame_nr mod 51
2172
2173 var allowedFn fn_check;
2174 fn_check.frame_nr := frame_nr_51;
2175
2176 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002178 return;
2179 }
2180
2181 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2182 return;
2183 }
2184 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2185 return;
2186 }
2187 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2188 return;
2189 }
2190 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2191 return;
2192 }
2193 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2194 return;
2195 }
2196 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2197 return;
2198 }
2199 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2200 return;
2201 }
2202 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2203 return;
2204 }
2205
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002207 return;
2208}
2209
2210altstep 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 +01002211runs on test_CT {
2212 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002213 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002214 repeat;
2215 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002216 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002217 var octetstring without_plen :=
2218 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2219 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002220
2221 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2222
Harald Welte68e495b2018-02-25 00:05:57 +01002223 if (match(rr, tr_PAGING_REQ1)) {
2224 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2225 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2226 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2227 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2228 }
2229 } else if (match(rr, tr_PAGING_REQ2)) {
2230 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2231 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2232 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2233 }
2234 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2235 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2236 }
2237 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2238 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2239 }
2240 } else if (match(rr, tr_PAGING_REQ3)) {
2241 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2242 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2243 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2244 }
2245 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2246 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2247 }
2248 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2249 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2250 }
2251 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2252 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2253 }
2254 }
2255 repeat;
2256 }
2257}
2258
2259type record PagingTestCfg {
2260 boolean combined_ccch,
2261 integer bs_ag_blks_res,
2262 float load_factor,
2263 boolean exp_load_ind,
2264 boolean exp_overload,
2265 boolean use_tmsi
2266}
2267
2268type record PagingTestState {
2269 integer num_paging_sent,
2270 integer num_paging_rcv_msgs,
2271 integer num_paging_rcv_ids,
2272 integer num_overload
2273}
2274
2275/* receive + ignore RSL RF RES IND */
2276altstep as_rsl_res_ind() runs on test_CT {
2277 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2278 repeat;
2279 }
2280}
2281
2282/* Helper function for paging related testing */
2283private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002284 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002285 f_init_l1ctl();
2286 f_l1_tune(L1CTL);
2287
2288 var PagingTestState st := {
2289 num_paging_sent := 0,
2290 num_paging_rcv_msgs := 0,
2291 num_paging_rcv_ids := 0,
2292 num_overload := 0
2293 };
2294
2295 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2296 var float max_pch_imsi_per_sec;
2297 if (cfg.use_tmsi) {
2298 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2299 } else {
2300 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2301 }
2302 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2303 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002304 var float time_total := 20.0;
2305 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2306 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002307
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002308 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2309 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002310
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002311 timer T_itv := 0.0;
2312 T_itv.start;
2313 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002314 alt {
2315 /* check for presence of CCCH LOAD IND (paging load) */
2316 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2317 st.num_overload := st.num_overload + 1;
2318 repeat;
2319 }
2320 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002322 }
2323 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2324 log("Rx LOAD_IND");
2325 /* FIXME: analyze/verify interval + contents */
2326 repeat;
2327 }
2328 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002329 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002330 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002331 [] T_itv.timeout {
2332 /* Send paging cmds based on elapsed time */
2333 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2334 while (st.num_paging_sent < new_sent) {
2335 /* build mobile Identity */
2336 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2337 if (cfg.use_tmsi) {
2338 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2339 } else {
2340 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2341 }
2342 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2343 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2344
2345 /* Send RSL PAGING COMMAND */
2346 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2347
2348 st.num_paging_sent := st.num_paging_sent + 1;
2349 }
2350 if (st.num_paging_sent < pkt_total) {
2351 /* Wait for interval to next PAGING COMMAND */
2352 var float time_now := T_total.read;
2353 var float next_sched := int2float(st.num_paging_sent)*interval;
2354 if (next_sched > time_now) {
2355 T_itv.start(next_sched - time_now);
2356 } else {
2357 T_itv.start(0.0);
2358 }
2359 } else {
2360 /* We are done, no need to keep counting */
2361 T_total.stop;
2362 }
2363 }
2364 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002365 [] as_rsl_res_ind();
2366 }
2367 }
2368
2369 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2370 timer T_wait := 18.0;
2371 T_wait.start;
2372 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002373 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002374 [] L1CTL.receive { repeat; }
2375 /* 65535 == empty paging queue, we can terminate*/
2376 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2377 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2378 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002380 }
2381 [] as_rsl_res_ind();
2382 }
2383
2384 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2385 " rcvd_ids=", st.num_paging_rcv_ids);
2386 return st;
2387}
2388
2389/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2390 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2391 * - that CCCH LOAD IND (PCH) are being generated
2392 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2393testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002394 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002395 var PagingTestCfg cfg := {
2396 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002397 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002398 load_factor := 0.8,
2399 exp_load_ind := true,
2400 exp_overload := false,
2401 use_tmsi := false
2402 };
2403 var PagingTestState st := f_TC_paging(cfg);
2404 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2406 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002407 } else {
2408 setverdict(pass);
2409 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002411}
2412
2413/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2414 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2415 * - that CCCH LOAD IND (PCH) are being generated
2416 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2417testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002418 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002419 var PagingTestCfg cfg := {
2420 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002421 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002422 load_factor := 0.8,
2423 exp_load_ind := true,
2424 exp_overload := false,
2425 use_tmsi := true
2426 };
2427 var PagingTestState st := f_TC_paging(cfg);
2428 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2430 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002431 } else {
2432 setverdict(pass);
2433 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002435}
2436
2437/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2438 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2439 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2440 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2441testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002442 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002443 var PagingTestCfg cfg := {
2444 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002445 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002446 load_factor := 2.0,
2447 exp_load_ind := true,
2448 exp_overload := true,
2449 use_tmsi := false
2450 };
2451 var PagingTestState st := f_TC_paging(cfg);
2452 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2453 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002454 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002455 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002456 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 +01002457 } else {
2458 setverdict(pass);
2459 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002461}
2462
2463/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2464 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2465 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2466 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2467testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002468 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002469 var PagingTestCfg cfg := {
2470 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002471 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002472 load_factor := 2.0,
2473 exp_load_ind := true,
2474 exp_overload := true,
2475 use_tmsi := true
2476 };
2477 var PagingTestState st := f_TC_paging(cfg);
2478 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2479 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002480 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002481 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002482 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 +01002483 } else {
2484 setverdict(pass);
2485 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002487}
2488
2489
Harald Welte93640c62018-02-25 16:59:33 +01002490/***********************************************************************
2491 * Immediate Assignment / AGCH
2492 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002493const MobileAllocation c_MA_null := {
2494 len := 0,
2495 ma := ''B
2496}
Harald Welte93640c62018-02-25 16:59:33 +01002497
Harald Weltee8d750e2018-06-10 21:41:35 +02002498template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2499 uint12_t arfcn := 871) := {
2500 chan_nr := chan_nr,
2501 tsc := tsc,
2502 h := false,
2503 arfcn := arfcn,
2504 maio_hsn := omit
2505}
2506
2507private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2508 return int2str(num_tx) & " sent, "
2509 & int2str(num_rx) & " received, "
2510 & int2str(num_del) & " deleted";
2511}
2512
2513private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2514 var L1ctlDlMessage l1_dl;
2515 timer T := 10.0;
2516 var integer num_tx := 0;
2517 var integer num_rx := 0;
2518 var integer num_del := 0;
2519 var charstring res_str;
2520 var float rx_ratio;
2521
Harald Welte10474062019-05-30 16:48:17 +02002522 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02002523 f_init_l1ctl();
2524 f_l1_tune(L1CTL);
2525
2526 for (var integer i := 0; i < num_total; i := i+1) {
2527 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2528 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2529 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002530 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002531 num_tx := num_tx+1;
2532 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002533 }
2534 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002535 T.start;
2536 alt {
2537 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2538 num_del := num_del+1;
2539 repeat;
2540 }
2541 [] RSL_CCHAN.receive {
2542 repeat;
2543 }
2544 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2545 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2546 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2547 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2548 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002549 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002550 } else {
2551 num_rx := num_rx+1;
2552 }
2553 repeat;
2554 }
2555 [] L1CTL.receive { repeat; }
2556 [] T.timeout { }
2557 }
2558 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2559 log("AGCH test: " & res_str);
2560 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002562 }
2563 rx_ratio := int2float(num_rx) / int2float(num_tx);
2564 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002565 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 +02002566 } else {
2567 setverdict(pass);
2568 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002570}
2571
Harald Weltee8d750e2018-06-10 21:41:35 +02002572/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2573testcase TC_imm_ass_1000_20ms() runs on test_CT {
2574 f_TC_imm_ass(1000, 0.02, 0.25);
2575}
2576
2577/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2578testcase TC_imm_ass_200_0ms() runs on test_CT {
2579 f_TC_imm_ass(200, 0.0, 0.05);
2580}
2581
2582/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2583testcase TC_imm_ass_200_76ms() runs on test_CT {
2584 f_TC_imm_ass(150, 0.076, 1.00);
2585}
2586
2587
2588
Harald Welte48494ca2018-02-25 16:59:50 +01002589/***********************************************************************
2590 * BCCH
2591 ***********************************************************************/
2592
2593/* tuple of Frame Number + decoded SI */
2594type record SystemInformationFn {
2595 GsmFrameNumber frame_number,
2596 SystemInformation si
2597}
2598
2599/* an arbitrary-length vector of decoded SI + gsmtap header */
2600type record of SystemInformationFn SystemInformationVector;
2601
2602/* an array of SI-vectors indexed by TC value */
2603type SystemInformationVector SystemInformationVectorPerTc[8];
2604
2605/* determine if a given SI vector contains given SI type at least once */
2606function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2607 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2608 var integer fn_mod51 := arr[i].frame_number mod 51;
2609 if (not bcch_ext and fn_mod51 == 2 or
2610 bcch_ext and fn_mod51 == 6) {
2611 if (arr[i].si.header.message_type == key) {
2612 return true;
2613 }
2614 }
2615 }
2616 return false;
2617}
2618
2619/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2620function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2621 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002623 }
2624}
2625
2626/* check if a given SI vector contains given SI type at least once on any TC */
2627function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2628 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2629 if (f_si_vecslot_contains(arr[tc], key) or
2630 f_si_vecslot_contains(arr[tc], key, true)) {
2631 return true;
2632 }
2633 }
2634 return false;
2635}
2636
2637/* determine if a given SI vector contains given SI type at least N of M times */
2638function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2639 var integer count := 0;
2640 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002642 }
2643 for (var integer i:= 0; i < m; i := i + 1) {
2644 var integer fn_mod51 := arr[i].frame_number mod 51;
2645 if (not bcch_ext and fn_mod51 == 2 or
2646 bcch_ext and fn_mod51 == 6) {
2647 if (arr[i].si.header.message_type == key) {
2648 count := count + 1;
2649 }
2650 }
2651 }
2652 if (count >= n) {
2653 return true;
2654 } else {
2655 return false;
2656 }
2657}
2658
2659/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2660function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2661 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002663 }
2664}
2665
2666/* determine if a given SI vector contains given SI type at least once */
2667function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2668 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2669 var integer fn_mod51 := arr[i].frame_number mod 51;
2670 if (not bcch_ext and fn_mod51 == 2 or
2671 bcch_ext and fn_mod51 == 6) {
2672 if (arr[i].si.header.message_type != key) {
2673 return false;
2674 }
2675 }
2676 }
2677 return true;
2678}
2679
2680/* ensure a given TC slot of the SI vector contains only given SI type */
2681function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2682 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002684 }
2685}
2686
2687/* SI configuration of cell, against which we validate actual SI messages */
2688type set SystemInformationConfig {
2689 boolean bcch_extended,
2690 boolean si1_present,
2691 boolean si2bis_present,
2692 boolean si2ter_present,
2693 boolean si2quater_present,
2694 boolean si7_present,
2695 boolean si8_present,
2696 boolean si9_present,
2697 boolean si13_present,
2698 boolean si13alt_present,
2699 boolean si15_present,
2700 boolean si16_present,
2701 boolean si17_present,
2702 boolean si2n_present,
2703 boolean si21_present,
2704 boolean si22_present
2705}
2706
2707/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2708function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2709 var integer i;
2710 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2711 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002713 }
2714 }
2715 if (cfg.si1_present) {
2716 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2717 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2718 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2719 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2720 /* make sure *ALL* contain SI1 */
2721 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2722 }
2723 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2724 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2725 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2726 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2727 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2728 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2729
2730 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2731 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2732 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2733 * consecutive occurrences of TC = 4. */
2734 if (cfg.si2bis_present and not cfg.si2ter_present) {
2735 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2736 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2737 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2738 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2739 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2740 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2741 }
2742
2743 if (cfg.si7_present or cfg.si8_present) {
2744 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2745 * if System Information type 4 does not contain all information needed for cell
2746 * selection and reselection. */
2747 if (not cfg.bcch_extended) {
2748 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2749 }
2750 if (cfg.si7_present) {
2751 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2752 }
2753 if (cfg.si8_present) {
2754 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2755 }
2756 }
2757
2758 if (cfg.si2quater_present) {
2759 /* iii) System information type 2 quater is sent if needed, as determined by the system
2760 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2761 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2762 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2763 * within any of 4 consecutive occurrences of TC = 5. */
2764 if (not (cfg.bcch_extended)) {
2765 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2766 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2767 } else {
2768 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2769 }
2770 } else {
2771 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2772 }
2773 }
2774 if (cfg.si9_present) {
2775 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2776 * in system information type 3 as defined in 3GPP TS 44.018. */
2777 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2778 }
2779 if (cfg.si13_present) {
2780 /* vii) System Information type 13 is only related to the GPRS service. System Information
2781 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2782 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2783 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2784 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2785 * within any of 4 consecutive occurrences of TC=4. */
2786 if (not cfg.bcch_extended) {
2787 log("not-bccch-extended");
2788 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2789 } else {
2790 log("bccch-extended");
2791 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2792 }
2793 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002795 }
2796 }
2797 if (cfg.si16_present or cfg.si17_present) {
2798 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2799 * should not be sent in a cell where network sharing is used (see rule xv). */
2800 if (cfg.si22_present) {
2801 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2802 }
2803 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002805 }
2806 if (not cfg.bcch_extended) {
2807 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2808 }
2809 if (cfg.si16_present) {
2810 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2811 }
2812 if (cfg.si17_present) {
2813 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2814 }
2815 }
2816
2817 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2818 * broadcast information. The frequency with which they are sent is determined by the
2819 * system operator. System Information type 9 identifies the scheduling of System
2820 * Information type 18 and 20 messages. */
2821
2822 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2823 * Information Type 19 is present, then its scheduling shall be indicated in System
2824 * Information Type 9. */
2825
2826 if (cfg.si15_present) {
2827 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2828 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2829 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2830 * 4 consecutive occurrences of TC = 1. */
2831 if (not cfg.bcch_extended) {
2832 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2833 } else {
2834 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2835 }
2836 }
2837 if (cfg.si13alt_present) {
2838 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2839 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2840 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2841 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2842 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2843 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2844 * of TC = 4. */
2845 if (cfg.si13_present) {
2846 testcase.stop("Error: Cannot have SI13alt and SI13");
2847 }
2848 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002850 }
2851 if (not cfg.bcch_extended) {
2852 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2853 } else {
2854 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2855 }
2856 }
2857 if (cfg.si2n_present) {
2858 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2859 * as determined by the system operator. In the case that the message is sent on the
2860 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2861 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2862 * consecutive occurrences of TC = 4. */
2863 if (not cfg.bcch_extended) {
2864 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2865 } else {
2866 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2867 }
2868 }
2869 if (cfg.si21_present) {
2870 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2871 * determined by the system operator. If Extended Access Barring is in use in the cell
2872 * then this message is sent at least once within any of 4 consecutive occurrences of
2873 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2874 * cell then this message shall only be sent on BCCH Ext. */
2875 if (not cfg.bcch_extended) {
2876 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2877 } else {
2878 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2879 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002881 }
2882 }
2883 }
2884 if (cfg.si22_present) {
2885 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2886 * should not be sent in a cell where SoLSA is used (see rule viii). System
2887 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2888 * =2 and TC=6. */
2889 if (cfg.si16_present or cfg.si17_present) {
2890 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2891 }
2892 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2893 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002895 }
2896 if (not cfg.bcch_extended) {
2897 testcase.stop("Error: SI22 requires BCCH Extd!");
2898 } else {
2899 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2900 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2901 }
2902 }
2903}
2904
2905/* sample Systme Information for specified duration via L1CTL */
2906function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2907 timer T := duration;
2908 var SystemInformationVectorPerTc si_per_tc;
2909 var L1ctlDlMessage l1_dl;
2910
2911 /* initialize all per-TC vectors empty */
2912 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2913 si_per_tc[i] := {};
2914 }
2915
2916 /* flush all previous L1 queued msgs */
2917 pt.clear;
2918
2919 T.start;
2920 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002921 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002922 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2923 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2924 log("Ignoring non-RR SI ", l1_dl);
2925 repeat;
2926 }
2927 var SystemInformationFn sig := {
2928 frame_number := l1_dl.dl_info.frame_nr,
2929 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2930 }
2931 var integer tc := f_gsm_compute_tc(sig.frame_number);
2932 log("SI received at TC=", tc, ": ", sig.si);
2933 /* append to the per-TC bucket */
2934 si_per_tc[tc] := si_per_tc[tc] & { sig };
2935 repeat;
2936 }
2937 [] pt.receive { repeat; }
2938 [] T.timeout { }
2939 }
2940
2941 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2942 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2943 }
2944 log("si_per_tc=", si_per_tc);
2945 return si_per_tc;
2946}
2947
2948/* helper function: Set given SI via RSL + validate scheduling.
2949 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2950function f_TC_si_sched() runs on test_CT {
2951 var SystemInformationVectorPerTc si_per_tc;
2952 f_init_l1ctl();
2953 f_l1_tune(L1CTL);
2954
2955 /* Sample + Validate Scheduling */
2956 si_per_tc := f_l1_sample_si(L1CTL);
2957 f_validate_si_scheduling(si_cfg, si_per_tc);
2958
2959 setverdict(pass);
2960}
2961
2962testcase TC_si_sched_default() runs on test_CT {
2963 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002964 /* 2+3+4 are mandatory and set in f_init() */
2965 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002967}
2968
2969testcase TC_si_sched_1() runs on test_CT {
2970 f_init();
2971 si_cfg.si1_present := true;
2972 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002973 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002975}
2976
2977testcase TC_si_sched_2bis() runs on test_CT {
2978 f_init();
2979 si_cfg.si2bis_present := true;
2980 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2981 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002983}
2984
2985testcase TC_si_sched_2ter() runs on test_CT {
2986 f_init();
2987 si_cfg.si2ter_present := true;
2988 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2989 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002991}
2992
2993testcase TC_si_sched_2ter_2bis() runs on test_CT {
2994 f_init();
2995 si_cfg.si2bis_present := true;
2996 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2997 si_cfg.si2ter_present := true;
2998 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2999 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003001}
3002
3003testcase TC_si_sched_2quater() runs on test_CT {
3004 f_init();
3005 si_cfg.si2quater_present := true;
3006 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3007 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003009}
3010
3011testcase TC_si_sched_13() runs on test_CT {
3012 f_init();
3013 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003014 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003015 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003017}
3018
3019testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3020 f_init();
3021 si_cfg.si2bis_present := true;
3022 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3023 si_cfg.si2ter_present := true;
3024 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3025 si_cfg.si2quater_present := true;
3026 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3027 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003028 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003029 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003031}
3032
3033
Harald Welte68e495b2018-02-25 00:05:57 +01003034testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003035 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003036 /* FIXME: enable / disable individual BCCH info */
3037 //ts_RSL_BCCH_INFO(si_type, info);
3038 /* expect no ERROR REPORT after either of them *
3039 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003041}
3042
Harald Welte93640c62018-02-25 16:59:33 +01003043/***********************************************************************
3044 * Low-Level Protocol Errors / ERROR REPORT
3045 ***********************************************************************/
3046
Harald Welte01d982c2018-02-25 01:31:40 +01003047private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3048 timer T := 5.0;
3049 T.start;
3050 alt {
3051 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3052 setverdict(pass);
3053 }
3054 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003056 }
3057 [] RSL_CCHAN.receive {
3058 repeat;
3059 }
3060 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003062 }
3063 }
3064}
3065
3066/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3067testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003068 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003069 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3070 rsl.ies := omit;
3071 RSL_CCHAN.send(ts_RSL_UD(rsl));
3072
3073 f_exp_err_rep(RSL_ERR_PROTO);
3074}
3075
3076/* Provoke a mandatory IE error and match on ERROR REPORT */
3077testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003078 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003079
3080 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3081 rsl.ies := { rsl.ies[0] };
3082 RSL_CCHAN.send(ts_RSL_UD(rsl));
3083
3084 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3085}
3086
3087/* Provoke an IE content error and match on ERROR REPORT */
3088testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003089 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003090 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3091 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3092 RSL_CCHAN.send(ts_RSL_UD(rsl));
3093
3094 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3095}
3096
Harald Welteee25aae2019-05-19 14:32:37 +02003097/* attempt to activate channel with wrong RSL Message Discriminator IE */
3098function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3099 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3100 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3101 RSL.send(rsl);
3102 f_rslem_unregister(0, g_chan_nr);
3103}
3104testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3105 var ConnHdlr vc_conn;
3106 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3107
Harald Welte10474062019-05-30 16:48:17 +02003108 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003109
3110 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3111 vc_conn.done;
3112 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3113
3114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3115}
3116
3117/* Send messages with wrong message type */
3118function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3119 var template (value) RSL_Message rsl_tx;
3120 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3121 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3122 RSL.send(rsl_tx);
3123 f_rslem_unregister(0, g_chan_nr);
3124}
3125function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3126 var template (value) RSL_Message rsl_tx;
3127 /* we first have to activate the dedicated channel */
3128 f_rsl_chan_act(g_pars.chan_mode);
3129 /* ... to then send an invalid RLL message */
3130 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3131 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3132 RSL.send(rsl_tx);
3133 f_rslem_unregister(0, g_chan_nr);
3134}
3135testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3136 var ConnHdlr vc_conn;
3137 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3138 var template (value) RSL_Message rsl_tx;
3139
Harald Welte10474062019-05-30 16:48:17 +02003140 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003141
3142 /* Common Channel with wrong message type */
3143 RSL_CCHAN.clear;
3144 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3145 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3146 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3147 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3148
3149 /* TRX Management */
3150 RSL_CCHAN.clear;
3151 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3152 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3153 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3154 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3155
3156 /* Dedicated Channel */
3157 RSL_CCHAN.clear;
3158 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3159 vc_conn.done;
3160 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3161
3162 /* RLL */
3163 RSL_CCHAN.clear;
3164 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3165 vc_conn.done;
3166 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3167}
3168
3169/* Send messages in wrong sequence (RLL to an inactive lchan) */
3170function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3171 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3172 f_rslem_unregister(0, g_chan_nr);
3173}
3174testcase TC_err_rep_wrong_sequence() runs on test_CT {
3175 var ConnHdlr vc_conn;
3176 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3177
Harald Welte10474062019-05-30 16:48:17 +02003178 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003179
3180 RSL_CCHAN.clear;
3181 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3182 vc_conn.done;
3183 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3184}
3185
Harald Welte93640c62018-02-25 16:59:33 +01003186/***********************************************************************
3187 * IPA CRCX/MDCX/DLCS media stream handling
3188 ***********************************************************************/
3189
Harald Weltea871a382018-02-25 02:03:14 +01003190/* Send IPA DLCX to inactive lchan */
3191function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003192 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3193 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003194}
3195testcase TC_ipa_dlcx_not_active() runs on test_CT {
3196 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003197 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003198 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3199 vc_conn.done;
3200}
Harald Welte68e495b2018-02-25 00:05:57 +01003201
Harald Weltea3f1df92018-02-25 12:49:55 +01003202/* Send IPA CRCX twice to inactive lchan */
3203function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3204 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3205 "IPA CRCX ACK");
3206 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3207 "IPA CRCX NACK");
3208}
3209testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3210 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003211 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003212 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3213 vc_conn.done;
3214}
3215
3216/* Regular sequence of CRCX/MDCX/DLCX */
3217function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3218 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3219 "IPA CRCX ACK");
3220 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3221 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3222 var uint7_t rtp_pt2 := f_rnd_int(127);
3223 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3224 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3225 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3226 "IPA MDCX ACK");
3227 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3228 "IPA DLCX ACK");
3229}
3230testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3231 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003232 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003233 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3234 vc_conn.done;
3235}
3236
Harald Welte3ae11da2018-02-25 13:36:06 +01003237/* Sequence of CRCX, 2x MDCX, DLCX */
3238function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3239 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3240 "IPA CRCX ACK");
3241 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3242 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3243 var uint7_t rtp_pt2 := f_rnd_int(127);
3244 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3245 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3246 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3247 "IPA MDCX ACK");
3248 /* Second MDCX */
3249 remote_ip := f_rnd_int(c_UINT32_MAX);
3250 remote_port := f_rnd_int(c_UINT16_MAX);
3251 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3252 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3253 "IPA MDCX ACK");
3254 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3255 "IPA DLCX ACK");
3256}
3257testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3258 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003259 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003260 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3261 vc_conn.done;
3262}
3263
Harald Welte9912eb52018-02-25 13:30:15 +01003264/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3265function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3266 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3267 "IPA CRCX NACK");
3268}
3269testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3270 var ConnHdlrPars pars;
3271 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003272 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003273
3274 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3275 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3276 vc_conn.done;
3277
3278 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3279 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3280 vc_conn.done;
3281}
3282
Harald Weltea3f1df92018-02-25 12:49:55 +01003283
Harald Welte883340c2018-02-28 18:59:29 +01003284/***********************************************************************
3285 * PCU Socket related tests
3286 ***********************************************************************/
3287
Harald Welte07bd2d22019-05-25 11:03:30 +02003288/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003289friend 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 +01003290runs on test_CT {
3291 timer T := 3.0;
3292
3293 /* we don't expect any RTS.req before PDCH are active */
3294 T.start;
3295 alt {
3296 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003298 }
3299 [] PCU.receive { repeat; }
3300 [] T.timeout { }
3301 }
3302
3303 /* Send PDCH activate request for known PDCH timeslot */
3304 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3305
3306 /* we now expect RTS.req for this timeslot (only) */
3307 T.start;
3308 alt {
3309 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3310 setverdict(pass);
3311 }
3312 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3313 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003315 }
3316 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003318 }
3319 [] PCU.receive { repeat; }
3320 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003322 }
3323 [not exp_success] T.timeout {
3324 setverdict(pass);
3325 }
3326 }
3327}
3328
Harald Welte07bd2d22019-05-25 11:03:30 +02003329/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003330friend 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 +01003331runs on test_CT {
3332 timer T := 3.0;
3333
3334 /* Send PDCH activate request for known PDCH timeslot */
3335 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3336
3337 PCU.clear;
3338 /* we now expect no RTS.req for this timeslot */
3339 T.start;
3340 alt {
3341 [] 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 +02003342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003343 }
3344 [] PCU.receive { repeat; }
3345 [] T.timeout {
3346 setverdict(pass);
3347 }
3348 }
3349}
3350
Harald Weltead033dc2019-05-25 17:28:16 +02003351friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003352 f_init();
3353 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3354}
3355
Harald Welte883340c2018-02-28 18:59:29 +01003356/* PDCH activation via PCU socket; check for presence of RTS.req */
3357testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003358 f_init_pcu_test();
3359
Harald Welte883340c2018-02-28 18:59:29 +01003360 f_TC_pcu_act_req(0, 0, 7, true);
3361}
3362
3363/* PDCH activation via PCU socket on non-PDCU timeslot */
3364testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003365 f_init_pcu_test();
3366
Harald Welte883340c2018-02-28 18:59:29 +01003367 f_TC_pcu_act_req(0, 0, 1, false);
3368}
3369
3370/* PDCH activation via PCU socket on wrong BTS */
3371testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003372 f_init_pcu_test();
3373
Harald Welte883340c2018-02-28 18:59:29 +01003374 f_TC_pcu_act_req(23, 0, 7, false);
3375}
3376
3377/* PDCH activation via PCU socket on wrong TRX */
3378testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003379 f_init_pcu_test();
3380
Harald Welte883340c2018-02-28 18:59:29 +01003381 f_TC_pcu_act_req(0, 23, 7, false);
3382}
3383
3384/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3385testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003386 f_init_pcu_test();
3387
Harald Welte883340c2018-02-28 18:59:29 +01003388 /* Activate PDCH */
3389 f_TC_pcu_act_req(0, 0, 7, true);
3390 f_sleep(1.0);
3391 /* and De-Activate again */
3392 f_TC_pcu_deact_req(0, 0, 7);
3393}
3394
3395/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3396testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003397 f_init_pcu_test();
3398
Harald Welte883340c2018-02-28 18:59:29 +01003399 f_TC_pcu_deact_req(0, 0, 1);
3400}
3401
3402/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3403testcase TC_pcu_ver_si13() runs on test_CT {
3404 const octetstring si13 := '00010203040506070909'O;
3405 var PCUIF_send_data sd;
3406 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003407 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003408
3409 /* Set SI13 via RSL */
3410 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003411
Harald Welte883340c2018-02-28 18:59:29 +01003412 T.start;
3413 alt {
3414 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3415 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3416 setverdict(pass);
3417 } else {
3418 repeat;
3419 }
3420 }
3421 [] PCU.receive { repeat; }
3422 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003424 }
3425 }
3426}
3427
3428private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3429
3430/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003431friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003432 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3433runs on test_CT
3434{
3435 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3436 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3437}
3438
3439/* 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 +02003440friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3441 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003442runs on test_CT
3443{
3444 var PCUIF_send_data sd;
3445
3446 timer T := 3.0;
3447 T.start;
3448 alt {
3449 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3450 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3451 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3452 sd.data.u.rts_req.fn, sapi, data);
3453 }
3454 [] PCU.receive { repeat; }
3455 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003457 }
3458 }
3459}
3460
3461/* Send DATA.req on invalid BTS */
3462testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003463 var TfiUsfArr tua := f_TfiUsfArrInit();
3464 var octetstring data := '0000'O & f_rnd_octstring(21);
3465
3466 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003467
Harald Welte883340c2018-02-28 18:59:29 +01003468 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003469 f_TfiUsfArrSet(tua, 7, 0);
3470 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3471 f_sleep(1.0);
3472
3473 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003474}
3475
3476/* Send DATA.req on invalid TRX */
3477testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003478 var TfiUsfArr tua := f_TfiUsfArrInit();
3479 var octetstring data := '0000'O & f_rnd_octstring(21);
3480
3481 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003482
Harald Welte883340c2018-02-28 18:59:29 +01003483 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003484 f_TfiUsfArrSet(tua, 7, 0);
3485 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3486 f_sleep(1.0);
3487
3488 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003489}
3490
3491/* Send DATA.req on invalid timeslot */
3492testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003493 var TfiUsfArr tua := f_TfiUsfArrInit();
3494 var octetstring data := '0000'O & f_rnd_octstring(21);
3495
3496 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003497
Harald Welte883340c2018-02-28 18:59:29 +01003498 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003499 f_TfiUsfArrSet(tua, 7, 0);
3500 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3501 f_sleep(1.0);
3502
3503 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003504}
3505
3506/* Send DATA.req on timeslot that hasn't been activated */
3507testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003508 var TfiUsfArr tua := f_TfiUsfArrInit();
3509 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003510
Harald Welte7162a612019-05-26 12:56:09 +02003511 f_virtphy_common();
3512
3513 f_TfiUsfArrSet(tua, 7, 0);
3514 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3515 f_sleep(1.0);
3516
3517 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003518}
3519
Harald Weltead033dc2019-05-25 17:28:16 +02003520private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003521 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3522 boolean wait_rts := true)
3523runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003524 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003525 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003526
3527 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003528 if (wait_rts) {
3529 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3530 } else {
3531 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3532 }
Harald Weltead033dc2019-05-25 17:28:16 +02003533
3534 T.start;
3535 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003536 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003537 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3538 setverdict(pass);
3539 }
Harald Welte7162a612019-05-26 12:56:09 +02003540 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3541 setverdict(fail, "Received unexpected ", rx_dl);
3542 }
Harald Weltead033dc2019-05-25 17:28:16 +02003543 [] L1CTL.receive {
3544 repeat;
3545 }
Harald Welte7162a612019-05-26 12:56:09 +02003546 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003547 setverdict(fail, "Timeout waiting for ", data);
3548 }
Harald Welte7162a612019-05-26 12:56:09 +02003549 [not expect_data] T.timeout {
3550 setverdict(pass);
3551 }
Harald Weltead033dc2019-05-25 17:28:16 +02003552 }
3553}
3554
3555private function f_disable_dynamic_ts() runs on test_CT
3556{
3557 f_init_vty_bsc();
3558 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3559 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3560 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3561 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003562 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003563}
3564
3565private function f_virtphy_common() runs on test_CT {
3566 f_disable_dynamic_ts();
3567 f_init_l1ctl();
3568 f_l1_tune(L1CTL);
3569}
3570
3571testcase TC_pcu_data_req_pdtch() runs on test_CT {
3572 var TfiUsfArr tua := f_TfiUsfArrInit();
3573 var octetstring data := '0000'O & f_rnd_octstring(21);
3574
3575 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003576
Harald Welte883340c2018-02-28 18:59:29 +01003577 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003578 f_TfiUsfArrSet(tua, 7, 0);
3579 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3580 f_sleep(1.0);
3581
3582 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003583}
3584
3585testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003586 var TfiUsfArr tua := f_TfiUsfArrInit();
3587 var octetstring data := '0000'O & f_rnd_octstring(21);
3588
3589 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003590
Harald Welte883340c2018-02-28 18:59:29 +01003591 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003592 f_TfiUsfArrSet(tua, 7, 0);
3593 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3594 f_sleep(1.0);
3595
3596 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003597}
3598
3599/* Send AGCH from PCU; check it appears on Um side */
3600testcase TC_pcu_data_req_agch() runs on test_CT {
3601 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003602 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003603 f_init_l1ctl();
3604 f_l1_tune(L1CTL);
3605
3606 f_TC_pcu_act_req(0, 0, 7, true);
3607 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3608
3609 T.start;
3610 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003611 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003612 setverdict(pass);
3613 }
3614 [] L1CTL.receive { repeat; }
3615 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003617 }
3618 }
3619}
3620
Harald Welte928622b2019-05-26 13:22:59 +02003621/* Send AGCH from PCU; check it appears on Um side */
3622testcase TC_pcu_data_req_pch() runs on test_CT {
3623 timer T := 3.0;
3624 f_init_pcu_test();
3625 f_init_l1ctl();
3626 f_l1_tune(L1CTL);
3627
3628 f_TC_pcu_act_req(0, 0, 7, true);
3629 /* three characters prefix: last 3 digits of IMSI as ASCII */
3630 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3631
3632 T.start;
3633 alt {
3634 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3635 setverdict(pass);
3636 }
3637 [] L1CTL.receive { repeat; }
3638 [] T.timeout {
3639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3640 }
3641 }
3642}
3643
Harald Welte883340c2018-02-28 18:59:29 +01003644/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3645testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3646 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003647 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003648 f_init_l1ctl();
3649 f_l1_tune(L1CTL);
3650
3651 /* append 3 last imsi digits so BTS can compute pagng group */
3652 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3653
3654 timer T := 0.5;
3655 T.start;
3656 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003657 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003658 /* TODO: verify paging group */
3659 setverdict(pass);
3660 }
3661 [] L1CTL.receive { repeat; }
3662 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003664 }
3665 }
3666}
3667
3668/* Send RACH from Um side, expect it to show up on PCU socket */
3669testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003670 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003671 f_init_l1ctl();
3672 f_l1_tune(L1CTL);
3673
3674 var GsmFrameNumber fn_last := 0;
3675 for (var integer i := 0; i < 1000; i := i+1) {
3676 var OCT1 ra := f_rnd_ra_ps();
3677 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3678 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003680 }
3681 fn_last := fn;
3682
3683 timer T := 2.0;
3684 T.start;
3685 alt {
3686 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3687 T.stop;
3688 }
3689 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003691 }
3692 [] PCU.receive { repeat; }
3693 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003695 }
3696 }
3697 }
3698 setverdict(pass);
3699}
3700
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003701/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3702 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3703testcase TC_pcu_ext_rach_content() runs on test_CT {
3704 var template PCUIF_Message pcu_rach_ind;
3705 var GsmFrameNumber fn_last := 0;
3706 var L1ctlRachSynchSeq synch_seq;
3707 var PCUIF_BurstType pcu_bt;
3708 var GsmFrameNumber fn;
3709 var BIT11 ra11;
3710
3711 f_init_pcu_test();
3712 f_init_l1ctl();
3713 f_l1_tune(L1CTL);
3714
3715 for (var integer i := 0; i < 1000; i := i+1) {
3716 /* We need to test both TS1 & TS2 */
3717 if (i rem 2 == 0) {
3718 synch_seq := RACH_SYNCH_SEQ_TS1;
3719 pcu_bt := BURST_TYPE_1;
3720 } else {
3721 synch_seq := RACH_SYNCH_SEQ_TS2;
3722 pcu_bt := BURST_TYPE_2;
3723 }
3724
3725 ra11 := f_rnd_ra11_ps();
3726 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3727 if (fn == fn_last) {
3728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3729 "Two RACH in same FN?!?");
3730 }
3731 fn_last := fn;
3732
3733 /* Compose the expected message */
3734 pcu_rach_ind := tr_PCUIF_RACH_IND(
3735 bts_nr := 0,
3736 ra := bit2int(ra11),
3737 is_11bit := 1,
3738 burst_type := pcu_bt,
3739 fn := fn);
3740
3741 timer T := 2.0;
3742 T.start;
3743 alt {
3744 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3745 T.stop;
3746 }
3747 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3749 }
3750 [] PCU.receive { repeat; }
3751 [] T.timeout {
3752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3753 }
3754 }
3755 }
3756 setverdict(pass);
3757}
3758
Harald Welte883340c2018-02-28 18:59:29 +01003759/* Send PAGING via RSL, expect it to shw up on PCU socket */
3760testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003761 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003762
3763 for (var integer i := 0; i < 100; i := i+1) {
3764 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3765 timer T := 3.0;
3766 if (i < 50) {
3767 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3768 } else {
3769 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3770 }
3771 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3772 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3773 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3774
3775 /* Send RSL PAGING COMMAND */
3776 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3777 T.start;
3778 alt {
3779 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3780 }
3781 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003783 }
3784 [] PCU.receive { repeat; }
3785 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003787 }
3788 }
3789 }
3790 setverdict(pass);
3791}
3792
Harald Welted66c9b82019-05-25 09:03:15 +02003793/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3794testcase TC_pcu_time_ind() runs on test_CT {
3795 var PCUIF_send_data pcu_sd;
3796 var integer num_time_ind := 0;
3797 var integer first_fn, last_fn;
3798 var float test_duration := 5.0;
3799 timer T;
3800
3801 f_init_pcu_test();
3802 f_TC_pcu_act_req(0, 0, 7, true);
3803
3804 PCU.clear;
3805 T.start(test_duration);
3806 alt {
3807 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3808 num_time_ind := num_time_ind + 1;
3809 if (not isbound(first_fn)) {
3810 first_fn := pcu_sd.data.u.time_ind.fn;
3811 }
3812 last_fn := pcu_sd.data.u.time_ind.fn;
3813 repeat;
3814 }
3815 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3816 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3817 repeat;
3818 }
3819 [] PCU.receive {
3820 repeat;
3821 }
3822 [] T.timeout {}
3823 }
3824 var integer fn_expired := last_fn - first_fn;
3825 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3826
3827 /* verify the number of frames expired matches our expectation */
3828 const float c_GSM_FN_DURATION_MS := 4.61538;
3829 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003830 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003831 if (not match(fn_expired, t_fn_expected)) {
3832 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3833 }
3834
3835 /* There are three TIME.ind in every fn MOD 13 */
3836 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3837 /* Add some tolerance */
3838 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3839 if (not match(num_time_ind, t_time_ind_exp)) {
3840 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3841 }
3842
3843 setverdict(pass);
3844}
3845
Harald Welte4832c862019-05-25 14:57:18 +02003846/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3847testcase TC_pcu_rts_req() runs on test_CT {
3848 var PCUIF_send_data pcu_sd;
3849 var integer first_fn, last_fn;
3850 var integer num_rts_pdtch := 0;
3851 var integer num_rts_ptcch := 0;
3852 var float test_duration := 5.0;
3853 timer T;
3854
3855 f_init_pcu_test();
3856 f_TC_pcu_act_req(0, 0, 7, true);
3857
3858 PCU.clear;
3859 T.start(test_duration);
3860 alt {
3861 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3862 -> value pcu_sd {
3863 num_rts_pdtch := num_rts_pdtch + 1;
3864 if (not isbound(first_fn)) {
3865 first_fn := pcu_sd.data.u.rts_req.fn;
3866 }
3867 last_fn := pcu_sd.data.u.rts_req.fn;
3868 repeat;
3869 }
3870 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3871 -> value pcu_sd {
3872 num_rts_ptcch := num_rts_ptcch + 1;
3873 if (not isbound(first_fn)) {
3874 first_fn := pcu_sd.data.u.rts_req.fn;
3875 }
3876 last_fn := pcu_sd.data.u.rts_req.fn;
3877 repeat;
3878 }
3879 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3880 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3881 repeat;
3882 }
3883 [] PCU.receive {
3884 repeat;
3885 }
3886 [] T.timeout {}
3887 }
3888 var integer fn_expired := last_fn - first_fn;
3889 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3890 ", num_rts_ptcch=", num_rts_ptcch);
3891
3892 /* verify the number of frames expired matches our expectation */
3893 const float c_GSM_FN_DURATION_MS := 4.61538;
3894 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003895 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003896 if (not match(fn_expired, t_fn_expected)) {
3897 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3898 }
3899
3900 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3901 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3902 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3903 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3904 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3905 t_ptcch_exp);
3906 }
3907
3908 /* We have 12 PDTCH blocks every 52-multiframe */
3909 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3910 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3911 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3912 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3913 t_pdtch_exp);
3914 }
3915
3916 setverdict(pass);
3917}
3918
Harald Welte07bd2d22019-05-25 11:03:30 +02003919/* test for generating Abis side OML ALERT from the PCU */
3920testcase TC_pcu_oml_alert() runs on test_CT {
3921 var PCUIF_send_data pcu_sd;
3922 var integer num_time_ind := 0;
3923 var integer first_fn, last_fn;
3924 var float test_duration := 5.0;
3925 timer T;
3926
3927 f_init_pcu_test();
3928 f_TC_pcu_act_req(0, 0, 7, true);
3929
3930 /* re-connect CTRL port from BTS to BSC */
3931 f_ipa_ctrl_stop();
3932 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3933
3934 /* Send that OML Alert */
3935 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3936
3937 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3938 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3939 setverdict(pass);
3940}
3941
Harald Welteeaa9a862019-05-26 23:01:08 +02003942template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3943 template (value) RoutingAreaIdentificationV rai,
3944 template (value) OCT1 cause) := {
3945 discriminator := '0000'B, /* overwritten */
3946 tiOrSkip := {
3947 skipIndicator := '0000'B
3948 },
3949 msgs := {
3950 rrm := {
3951 gPRS_suspensionRequest := {
3952 messageType := '00110100'B,
3953 tLLI := tlli,
3954 routingAreaIdentification := rai,
3955 suspensionCause := cause,
3956 service_Support := omit
3957 }
3958 }
3959 }
3960}
3961
3962/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3963private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3964 var PCUIF_Message first_info;
3965 var integer pcu_conn_id := -1;
3966 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3967 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3968 var OCT4 tlli := '01020304'O;
3969 var OCT1 cause := '23'O;
3970 timer T := 5.0;
3971
3972 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3973
3974 f_l1_tune(L1CTL);
3975 RSL.clear;
3976
3977 f_est_dchan();
3978 L1CTL.clear;
3979
3980 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3981
3982 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3983 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3984 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3985
3986 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3987 T.start;
3988 alt {
3989 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3990 setverdict(pass);
3991 }
3992 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3993 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3994 }
3995 [] PCU.receive {
3996 repeat;
3997 }
3998 [] T.timeout {
3999 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4000 }
4001 }
4002}
4003testcase TC_pcu_rr_suspend() runs on test_CT {
4004 var ConnHdlrPars pars;
4005 var ConnHdlr vc_conn;
4006
4007 f_init();
4008
4009 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4010 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4011 vc_conn.done;
4012}
Harald Welte07bd2d22019-05-25 11:03:30 +02004013
Harald Weltea2e0e942019-05-27 18:12:53 +02004014/* Ensure that PCUIF socket can accept only a single connection */
4015testcase TC_pcu_socket_connect_multi() runs on test_CT {
4016 timer T := 5.0;
4017
4018 /* this (among other things) establishes the first connection to the PCUIF socket */
4019 f_init();
4020
4021 /* try to establish a second connection, expect it to fail */
4022 PCU.send(UD_connect:{mp_pcu_socket, -1});
4023 T.start;
4024 alt {
4025 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4026 setverdict(pass);
4027 }
4028 [] PCU.receive(UD_connect_result:?) {
4029 setverdict(fail, "Unexpected unix domain connect result");
4030 }
4031 [] T.timeout {
4032 setverdict(pass);
4033 }
4034 }
4035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4036}
4037
Harald Weltec8effb72019-05-27 18:23:04 +02004038/* Ensure that PCUIF socket can disconnect + reconnect */
4039testcase TC_pcu_socket_reconnect() runs on test_CT {
4040 /* this (among other things) establishes the first connection to the PCUIF socket */
4041 f_init();
4042
4043 f_sleep(1.0);
4044
4045 f_pcuif_close(PCU, g_pcu_conn_id);
4046 g_pcu_conn_id := -1;
4047
4048 f_sleep(1.0);
4049
4050 /* re-connect */
4051 PCU.clear;
4052 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4053 setverdict(pass);
4054
4055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4056}
4057
Harald Weltebe030482019-05-27 22:29:35 +02004058/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4059private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4060 var L1ctlDlMessage l1_dl;
4061 var SystemInformation si;
4062 timer T := 5.0;
4063 T.start;
4064 alt {
4065 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4066 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4067 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4068 log("Ignoring non-RR SI ", l1_dl);
4069 repeat;
4070 }
4071 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4072 if (not ischosen(si.payload.si3)) {
4073 repeat;
4074 }
4075 }
4076 [] pt.receive {
4077 repeat;
4078 }
4079 [] T.timeout {
4080 setverdict(fail, "Timeout waiting for SI3");
4081 }
4082 }
4083 return si.payload.si3;
4084}
4085
4086/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4087private function f_bitpos_is_inv(integer idx) return boolean {
4088 select (idx mod 8) {
4089 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4090 case else { return false; } /* 0-bits of 0x2B */
4091 }
4092}
4093/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4094private function f_bit_is_high(bitstring str, integer idx) return boolean {
4095 var boolean invert := f_bitpos_is_inv(idx);
4096 if (invert) {
4097 if (str[idx] == '1'B) {
4098 return false;
4099 } else {
4100 return true;
4101 }
4102 } else {
4103 if (str[idx] == '1'B) {
4104 return true;
4105 } else {
4106 return false;
4107 }
4108 }
4109}
4110/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4111 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4112 we can replace this piece of code soon ... */
4113private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4114 var bitstring bits := oct2bit(si3_restoctets);
4115 var integer idx := 0;
4116
4117 if (f_bit_is_high(bits, idx)) {
4118 /* skip Optional selection parameters */
4119 idx := idx + 16;
4120 } else {
4121 idx := idx + 1;
4122 }
4123
4124 if (f_bit_is_high(bits, idx)) {
4125 /* skip Optional power offset */
4126 idx := idx + 3;
4127 } else {
4128 idx := idx + 1;
4129 }
4130
4131 /* skip SI2ter Indicator */
4132 idx := idx + 1;
4133
4134 /* skip Early CM Sending Control */
4135 idx := idx + 1;
4136
4137 /* skip Scheduling if and where */
4138 if (f_bit_is_high(bits, idx)) {
4139 idx := idx + 4;
4140 } else {
4141 idx := idx + 1;
4142 }
4143
4144 return f_bit_is_high(bits, idx);
4145}
4146
4147testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4148 var SystemInformationType3 si3;
4149 timer T := 5.0;
4150
4151 /* don't call f_init() as this would connect PCU socket */
4152 f_init_rsl(testcasename());
4153 T.start;
4154 alt {
4155 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4156 [] T.timeout {
4157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4158 }
4159 }
4160 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4161
4162 f_init_l1ctl();
4163 f_l1_tune(L1CTL);
4164
4165 f_sleep(2.0);
4166 L1CTL.clear;
4167 si3 := f_get_si3(L1CTL);
4168 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4169 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4170 } else {
4171 setverdict(pass);
4172 }
4173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4174}
4175
4176/* Ensure that GPRS capability is advertised after PCU socket connect */
4177testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4178 var SystemInformationType3 si3;
4179
4180 /* this (among other things) establishes the first connection to the PCUIF socket */
4181 f_init();
4182 f_init_l1ctl();
4183 f_l1_tune(L1CTL);
4184
4185 f_sleep(2.0);
4186 L1CTL.clear;
4187 si3 := f_get_si3(L1CTL);
4188 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4189 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4190 } else {
4191 setverdict(pass);
4192 }
4193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4194}
4195
4196/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4197testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4198 var SystemInformationType3 si3;
4199
4200 /* this (among other things) establishes the first connection to the PCUIF socket */
4201 f_init();
4202 f_init_l1ctl();
4203 f_l1_tune(L1CTL);
4204
4205 f_pcuif_close(PCU, g_pcu_conn_id);
4206 g_pcu_conn_id := -1;
4207
4208 f_sleep(1.0);
4209
4210 /* re-connect */
4211 PCU.clear;
4212 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4213
4214 f_sleep(2.0);
4215 L1CTL.clear;
4216 si3 := f_get_si3(L1CTL);
4217 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4218 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4219 } else {
4220 setverdict(pass);
4221 }
4222
4223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4224}
4225
Harald Welted66c9b82019-05-25 09:03:15 +02004226
Harald Welte3d04ae62018-04-04 20:29:05 +02004227/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004228 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004229 ***********************************************************************/
4230
4231private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4232runs on ConnHdlr {
4233 var PCUIF_send_data sd;
4234 /* Expect BTS to immediately acknowledge activation as PDCH */
4235 PCU.clear;
4236 f_rsl_chan_act(g_pars.chan_mode);
4237 /* expect INFO_IND on PCU interface listing TS as PDCH */
4238 alt {
4239 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4240 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004242 }
4243 }
4244 [] PCU.receive { repeat; }
4245 }
4246 /* try to activate this PDCH from the PCU point of view */
4247 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4248 /* FIXME: is there a response? */
4249}
4250
4251private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4252runs on ConnHdlr {
4253 var PCUIF_send_data sd;
4254 /* Send RSL CHAN REL (deactivate) */
4255 PCU.clear;
4256 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4257 /* expect BTS to ask PCU to deactivate the channel */
4258 alt {
4259 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4260 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004262 }
4263 }
4264 [] PCU.receive { repeat; }
4265 }
4266 /* Emulate PCU asking BTS to deactivate PDCH */
4267 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4268 alt {
4269 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4270 setverdict(pass);
4271 }
4272 [] RSL.receive { repeat; }
4273 }
4274}
4275
4276/* Activate Osmocom-style dynamic PDCH from BSC side */
4277function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4278 var PCUIF_Message first_info;
4279 var integer ts_nr := g_chan_nr.tn;
4280 var integer trx_nr := 0;
4281 var integer bts_nr := 0;
4282 var integer pcu_conn_id := -1;
4283
4284 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4285
4286 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4287 f_sleep(3.0);
4288 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4289 setverdict(pass);
4290}
4291testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4292 var ConnHdlrPars pars;
4293 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004294 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004295
4296 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4297 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4298 vc_conn.done;
4299}
4300
4301/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4302function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4303 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004304 var integer pcu_conn_id := -1;
4305
4306 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4307
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004308 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4309 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4310 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004311 setverdict(pass);
4312}
4313testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4314 var ConnHdlrPars pars;
4315 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004316 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004317
4318 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4319 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4320 vc_conn.done;
4321}
4322
4323/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4324function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4325 var PCUIF_Message first_info;
4326 var integer ts_nr := g_chan_nr.tn;
4327 var integer trx_nr := 0;
4328 var integer bts_nr := 0;
4329 var integer pcu_conn_id := -1;
4330
4331 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4332
4333 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004334 /* Send a second Chan Activ and expect it to be NACKed */
4335 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4336 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004337 setverdict(pass);
4338}
4339testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4340 var ConnHdlrPars pars;
4341 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004342 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004343
4344 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4345 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4346 vc_conn.done;
4347}
4348
4349/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4350function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4351 var PCUIF_Message first_info;
4352 var integer ts_nr := g_chan_nr.tn;
4353 var integer trx_nr := 0;
4354 var integer bts_nr := 0;
4355 var integer pcu_conn_id := -1;
4356 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4357
4358 /* register for the TCH/F channel number */
4359 f_rslem_register(0, chan_nr);
4360
4361 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4362
4363 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4364 "RSL CHAN ACT");
4365 setverdict(pass);
4366}
4367testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4368 var ConnHdlrPars pars;
4369 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004370 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004371
4372 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4373 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4374 vc_conn.done;
4375}
4376
4377/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4378function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4379 var PCUIF_Message first_info;
4380 var integer ts_nr := g_chan_nr.tn;
4381 var integer trx_nr := 0;
4382 var integer bts_nr := 0;
4383 var integer pcu_conn_id := -1;
4384 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4385 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4386
4387 /* register for the TCH/H channel numbers */
4388 f_rslem_register(0, chan_nr[0]);
4389 f_rslem_register(0, chan_nr[1]);
4390
4391 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4392
4393 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4394 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4395 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4396 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4397 setverdict(pass);
4398}
4399testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4400 var ConnHdlrPars pars;
4401 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004402 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004403
4404 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4405 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4406 vc_conn.done;
4407}
4408
Harald Welte9bbbfb52018-04-05 09:33:19 +02004409/***********************************************************************
4410 * IPA Style Dynamic Timeslot Support
4411 ***********************************************************************/
4412
4413private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4414runs on ConnHdlr {
4415 var PCUIF_send_data sd;
4416 /* Expect BTS to immediately acknowledge activation as PDCH */
4417 PCU.clear;
4418 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4419 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004420 timer T_wait := 2.0;
4421 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004422 alt {
4423 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4424 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 +01004425 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4426 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4427 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004428 }
4429 }
4430 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004431 [] T_wait.timeout {
4432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4433 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4434 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004435 }
4436 /* try to activate this PDCH from the PCU point of view */
4437 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4438 /* FIXME: is there a response? */
4439
4440 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4441}
4442
4443private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4444runs on ConnHdlr {
4445 var PCUIF_send_data sd;
4446 /* Send RSL CHAN REL (deactivate) */
4447 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4448 PCU.clear;
4449 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004450 timer T_wait := 2.0;
4451 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004452 alt {
4453 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4454 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 +01004455 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4456 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4457 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004458 }
4459 }
4460 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004461 [] T_wait.timeout {
4462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4463 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4464 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004465 }
4466 /* Emulate PCU asking BTS to deactivate PDCH */
4467 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4468 alt {
4469 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4470 setverdict(pass);
4471 }
4472 [] RSL.receive { repeat; }
4473 }
4474}
4475
4476/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4477function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4478 var PCUIF_Message first_info;
4479 var integer ts_nr := g_chan_nr.tn;
4480 var integer trx_nr := 0;
4481 var integer bts_nr := 0;
4482 var integer pcu_conn_id := -1;
4483
4484 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4485
4486 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4487 f_sleep(3.0);
4488 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4489
4490 setverdict(pass);
4491
4492}
4493testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4494 var ConnHdlrPars pars;
4495 var ConnHdlr vc_conn;
4496 f_init();
4497
4498 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4499 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4500 vc_conn.done;
4501}
4502
4503/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4504function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4505 var PCUIF_Message first_info;
4506 var integer ts_nr := g_chan_nr.tn;
4507 var integer trx_nr := 0;
4508 var integer bts_nr := 0;
4509 var integer pcu_conn_id := -1;
4510
4511 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4512
4513 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4514 "RSL CHAN ACT");
4515 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4516 "RF CHAN REL", true);
4517 setverdict(pass);
4518}
4519testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4520 var ConnHdlrPars pars;
4521 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004522 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004523
4524 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4525 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4526 vc_conn.done;
4527}
4528
4529/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4530function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4531 var PCUIF_Message first_info;
4532 var integer ts_nr := g_chan_nr.tn;
4533 var integer trx_nr := 0;
4534 var integer bts_nr := 0;
4535 var integer pcu_conn_id := -1;
4536
4537 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4538
4539 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4540 "RSL CHAN ACT");
4541
4542 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4543 alt {
4544 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4545 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004547 }
4548 [] RSL.receive { repeat; }
4549 }
4550
4551 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4552 "RF CHAN REL", true);
4553 setverdict(pass);
4554}
4555testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4556 var ConnHdlrPars pars;
4557 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004558 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004559
4560 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4561 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4562 vc_conn.done;
4563}
4564
4565/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4566function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4567 var PCUIF_Message first_info;
4568 var integer ts_nr := g_chan_nr.tn;
4569 var integer trx_nr := 0;
4570 var integer bts_nr := 0;
4571 var integer pcu_conn_id := -1;
4572
4573 /* register for the TCH/F channel number */
4574 f_rslem_register(0, g_chan_nr);
4575
4576 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4577
4578 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4579
4580 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4581 "RSL CHAN ACT");
4582
4583 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4584
4585 setverdict(pass);
4586}
4587testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4588 var ConnHdlrPars pars;
4589 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004590 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004591
4592 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4593 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4594 vc_conn.done;
4595}
4596
4597
Harald Welte0472ab42018-03-12 15:02:26 +01004598/***********************************************************************
4599 * LAPDm / RLL related
4600 ***********************************************************************/
4601
4602private function f_tx_lapdm(template (value) LapdmFrame l,
4603 template (value) RslLinkId link_id) runs on ConnHdlr {
4604 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004605 var template (value) SacchL1Header l1h;
4606
4607 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01004608 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004609 /* Compose dummy L1 header */
4610 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
4611 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 +02004612 } else {
4613 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004614 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 +01004615 }
Harald Welte0472ab42018-03-12 15:02:26 +01004616}
4617
4618type record RllTestCase {
4619 uint3_t sapi,
4620 RslLinkId link_id,
4621 octetstring l3,
4622 boolean exp
4623}
4624type record of RllTestCase RllTestCases;
4625template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4626 sapi := sapi,
4627 link_id := id,
4628 l3 := l3,
4629 exp := exp
4630}
4631
4632/* execute the same callback function with a set of different parameters (tcs) on a
4633 * variety of logical channels */
4634private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4635 var ConnHdlrPars pars;
4636 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004637 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01004638
4639 /* test on each of the channels we have */
4640 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4641 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4642
4643 /* test each of the test cases on the current channel */
4644 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4645 pars.spec.rll := tcs[j];
4646 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4647 vc_conn := f_start_handler(fn, pars);
4648 vc_conn.done;
4649 }
4650 }
4651
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004653}
4654
4655/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4656private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4657 var RllTestCase tc := g_pars.spec.rll;
4658 timer T := 3.0;
4659
4660 f_l1_tune(L1CTL);
4661 RSL.clear;
4662
4663 /* activate the logical channel */
4664 f_est_dchan();
4665 L1CTL.clear;
4666
4667 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4668 T.start;
4669 alt {
4670 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4671 if (tc.exp) {
4672 setverdict(pass);
4673 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004675 }
4676 }
4677 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4678 if (tc.exp) {
4679 setverdict(pass);
4680 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004682 }
4683 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004684 /* We also expect to receive the measurements */
4685 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004686 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004688 }
4689 [not tc.exp] T.timeout {
4690 setverdict(pass);
4691 }
4692 }
4693
4694 f_rsl_chan_deact();
4695 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4696 f_rslem_unregister(0, g_chan_nr);
4697}
4698testcase TC_rll_est_ind() runs on test_CT {
4699 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004700 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004701 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004702 /* normal SAPI0 establishment */
4703 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004704 /* SAPI 3 doesn't support contention resolution */
4705 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4706 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4707 /* normal SAPI3 establishment on main DCCH */
4708 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4709 /* normal SAPI3 establishment on SACCH */
4710 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4711 };
4712 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4713}
4714
4715/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4716private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4717 var RllTestCase tc := g_pars.spec.rll;
4718 var L1ctlDlMessage dl;
4719 timer T := 3.0;
4720
4721 f_l1_tune(L1CTL);
4722 RSL.clear;
4723
4724 /* activate the logical channel */
4725 f_est_dchan();
4726 L1CTL.clear;
4727
4728 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4729 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4730 T.start;
4731 alt {
4732 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4733 var LapdmFrame lapdm;
4734 var octetstring l2 := dl.payload.data_ind.payload;
4735 if (dl.dl_info.link_id.c == SACCH) {
4736 /* remove L1 header */
4737 l2 := substr(l2, 2, lengthof(l2)-2);
4738 }
4739 lapdm.ab := dec_LapdmFrameAB(l2);
4740 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4741 setverdict(pass);
4742 } else {
4743 repeat;
4744 }
4745 }
4746 [] L1CTL.receive { repeat; }
4747 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004749 }
4750 }
4751
4752 f_rsl_chan_deact();
4753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4754 f_rslem_unregister(0, g_chan_nr);
4755}
4756testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4757 var RllTestCases tcs := {
4758 /* normal SAPI3 establishment on main DCCH */
4759 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4760 };
4761 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4762}
4763testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4764 var RllTestCases tcs := {
4765 /* normal SAPI3 establishment on SACCH */
4766 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4767 }
4768 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4769}
4770
4771/* altstep to receive a LAPDm frame matching the given template */
4772private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4773 var L1ctlDlMessage dl;
4774 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4775 var LapdmFrame lapdm;
4776 var octetstring l2 := dl.payload.data_ind.payload;
4777 if (dl.dl_info.link_id.c == SACCH) {
4778 /* remove L1 header */
4779 l2 := substr(l2, 2, lengthof(l2)-2);
4780 }
4781 if (ischosen(exp.ab)) {
4782 lapdm.ab := dec_LapdmFrameAB(l2);
4783 } else if (ischosen(exp.b4)) {
4784 lapdm.b4 := dec_LapdmFrameB4(l2);
4785 } else if (ischosen(exp.bbis)) {
4786 lapdm.bbis := dec_LapdmFrameBbis(l2);
4787 }
4788 log("Rx LAPDm ", lapdm);
4789 if (match(lapdm, exp)) {
4790 setverdict(pass);
4791 } else {
4792 repeat;
4793 }
4794 }
4795 [] L1CTL.receive { repeat; }
4796}
4797private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4798 timer T := t;
4799 T.start;
4800 alt {
4801 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004803 }
4804 [] as_l1_exp_lapdm(exp);
4805 }
4806}
4807
4808/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4809private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4810 /* send SABM from MS -> BTS */
4811 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4812 /* expect RLL EST IND on Abis */
4813 alt {
4814 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4815 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4816 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004818 }
4819 [] RSL.receive { repeat; }
4820 }
4821 /* expect UA from BTS -> MS */
4822 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4823}
4824
4825/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4826private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4827 var RllTestCase tc := g_pars.spec.rll;
4828
4829 f_l1_tune(L1CTL);
4830 RSL.clear;
4831
4832 /* activate the logical channel */
4833 f_est_dchan();
4834 L1CTL.clear;
4835
4836 /* first establish the link-layer */
4837 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4838
4839 /* then send the DISC */
4840 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4841 /* ... and expect the REL IND on the RSL side */
4842 alt {
4843 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4844 setverdict(pass);
4845 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004846 /* We also expect to receive the measurements */
4847 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004848 }
4849
4850 /* release the channel */
4851 f_rsl_chan_deact();
4852 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4853 f_rslem_unregister(0, g_chan_nr);
4854}
4855testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4856 var RllTestCases tcs := {
4857 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4858 };
4859 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4860}
4861
4862testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4863 var RllTestCases tcs := {
4864 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4865 };
4866 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4867}
4868testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4869 var RllTestCases tcs := {
4870 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4871 };
4872 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4873}
4874testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4875 var RllTestCases tcs := {
4876 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4877 };
4878 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4879}
4880
4881/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4882private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4883 var RllTestCase tc := g_pars.spec.rll;
4884 f_l1_tune(L1CTL);
4885 RSL.clear;
4886
4887 /* activate the logical channel */
4888 f_est_dchan();
4889 L1CTL.clear;
4890
4891 /* first establish the link-layer */
4892 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4893
4894 /* then send the REL REQ via RSL */
4895 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4896 /* ... and expect the DISC on the Um side */
4897 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004898 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004899 /* FIXME: send a UA in resposne to the DISC */
4900 }
4901 }
4902
4903 /* release the channel */
4904 f_rsl_chan_deact();
4905 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4906 f_rslem_unregister(0, g_chan_nr);
4907}
4908testcase TC_rll_rel_req() runs on test_CT {
4909 var RllTestCases tcs := {
4910 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4911 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4912 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4913 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4914 };
4915 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4916}
4917
4918/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4919testcase TC_rll_data_req() runs on test_CT {
4920}
4921
4922/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4923testcase TC_rll_data_ind() runs on test_CT {
4924}
4925
4926/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4927private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4928 var RllTestCase tc := g_pars.spec.rll;
4929
4930 f_l1_tune(L1CTL);
4931 RSL.clear;
4932
4933 f_est_dchan();
4934 L1CTL.clear;
4935
4936 /* Send UNITDATA REQ on RSL side */
4937 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4938 /* Expect it to arrive on the other side */
4939 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004940 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004941 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004942 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004943 }
4944
4945 /* release the channel */
4946 f_rsl_chan_deact();
4947 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4948 f_rslem_unregister(0, g_chan_nr);
4949}
4950testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4951 var octetstring l3 := f_rnd_octstring(15);
4952 var RllTestCases tcs := {
4953 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4954 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4955 };
4956 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4957}
4958testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4959 var octetstring l3 := f_rnd_octstring(19);
4960 var RllTestCases tcs := {
4961 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4962 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4963 };
4964 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4965}
4966
4967/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4968private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4969 var RllTestCase tc := g_pars.spec.rll;
4970
4971 f_l1_tune(L1CTL);
4972 RSL.clear;
4973
4974 f_est_dchan();
4975 L1CTL.clear;
4976
4977 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004978 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004979 /* Expdct RLL UNITDATA IND on RSL side */
4980 alt {
4981 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4982 setverdict(pass);
4983 }
4984 [] RSL.receive { repeat; }
4985 }
4986
4987 /* release the channel */
4988 f_rsl_chan_deact();
4989 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4990 f_rslem_unregister(0, g_chan_nr);
4991}
4992testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004993 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004994 var RllTestCases tcs := {
4995 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4996 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4997 };
4998 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4999}
5000testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5001 var octetstring l3 := f_rnd_octstring(18);
5002 var RllTestCases tcs := {
5003 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5004 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5005 };
5006 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5007}
5008
Harald Weltee613f962018-04-18 22:38:16 +02005009/***********************************************************************
5010 * Encryption Related
5011 ***********************************************************************/
5012
5013/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5014function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5015 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5016 if (link_id.c == SACCH) {
5017 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5018 } else {
5019 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5020 }
5021}
5022
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005023/* Expect (or not expect) other kinds of messages */
5024private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5025 [exp_any] RSL.receive { repeat; }
5026 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005028 }
5029}
5030
Harald Weltee613f962018-04-18 22:38:16 +02005031/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005032private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005033 RslLinkId link_id,
5034 octetstring l3,
5035 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005036 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005037) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005038 timer T := 3.0;
5039 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5040 T.start;
5041 /* Expect RLL UNITDATA IND on RSL side */
5042 alt {
5043 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5044 setverdict(pass);
5045 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005046 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005047 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005048 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005050 }
Harald Weltee613f962018-04-18 22:38:16 +02005051 }
5052}
5053
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005054/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5055private function f_data_mo(
5056 RslLinkId link_id,
5057 boolean p, uint3_t nr, uint3_t ns,
5058 octetstring l3,
5059 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005060 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005061) runs on ConnHdlr {
5062 timer T := 3.0;
5063 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5064 T.start;
5065 /* Expect RLL DATA IND on RSL side */
5066 alt {
5067 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5068 setverdict(pass);
5069 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005070 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005071 [] as_rsl_any_ind(exp_any);
5072 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005074 }
5075 }
5076}
5077
Harald Weltee613f962018-04-18 22:38:16 +02005078/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5079function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5080 f_l1_tune(L1CTL);
5081 f_est_dchan(true);
5082
5083 /* now we actually need to transmit some data both ways to check if the encryption works */
5084 var L1ctlDlMessage dl;
5085
Stefan Sperling603d98e2018-07-25 16:47:28 +02005086 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005087 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5088
5089 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5090 f_unitdata_mt(link_id, l3);
5091
5092 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5093 f_unitdata_mo(link_id, l3);
5094
5095 /* release the channel */
5096 f_rsl_chan_deact();
5097 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5098 f_rslem_unregister(0, g_chan_nr);
5099}
5100testcase TC_chan_act_a51() runs on test_CT {
5101 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5102 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5103 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5104}
5105testcase TC_chan_act_a52() runs on test_CT {
5106 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5107 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5108 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5109}
5110testcase TC_chan_act_a53() runs on test_CT {
5111 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5112 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5113 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5114}
5115
Eric Wildf1827a72019-05-28 17:37:35 +02005116/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5117 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5118function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5119 f_l1_tune(L1CTL);
5120 f_est_dchan(true);
5121
5122 /* now we actually need to transmit some data both ways to check if the encryption works */
5123 var L1ctlDlMessage dl;
5124
5125 var octetstring l3 := f_rnd_octstring(20);
5126 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5127
5128 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5129 f_unitdata_mt(link_id, l3);
5130
5131 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5132 f_unitdata_mo(link_id, l3);
5133
5134 var RSL_Message rsl;
5135 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5136
5137 /* modify key to break proper encryption */
5138 g_pars.encr.key := f_rnd_octstring(8);
5139 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5140 rsl.ies := rsl.ies & { ei };
5141 RSL.send(rsl);
5142
5143 timer T0 := 1.0;
5144 T0.start;
5145 /* Expect RSL MODIFY ACK */
5146 alt {
5147 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5148 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5150 }
5151 [] T0.timeout {
5152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5153 }
5154 }
5155
5156 var octetstring l3msg := f_rnd_octstring(15);
5157 timer T1 := 3.0;
5158 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5159 due to broken encryption */
5160 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5161 T1.start;
5162 alt {
5163 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5165 }
5166 [] T1.timeout {
5167 setverdict(pass);
5168 }
5169 }
5170
5171 /* release the channel */
5172 f_rsl_chan_deact();
5173 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5174 f_rslem_unregister(0, g_chan_nr);
5175}
5176testcase TC_rsl_modify_encr() runs on test_CT {
5177 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5178 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5179 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5180}
Harald Weltee613f962018-04-18 22:38:16 +02005181
5182/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5183function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5184 /* L3 payload doesn't matter, as it is passed transparently */
5185 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5186 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5187 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5188
5189 f_l1_tune(L1CTL);
5190
5191 /* first establish a dedicated channel in the clear */
5192 f_est_dchan(false);
5193
5194 /* Establish ABM */
5195 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5196
5197 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5198 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5199 /* expect the L3 to arrive still unencrypted on the MS side */
5200 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5201
5202 /* configure L1 to apply ciphering */
5203 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5204 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5205
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005206 /* send first ciphered I-frame in response and expect it on RSL */
5207 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005208
5209 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5210 * and hence enable encryption also on the downlink */
5211
5212 /* expect bi-directional communication work in encrypted mode */
5213 f_unitdata_mo(link_id, f_rnd_octstring(15));
5214 f_unitdata_mt(link_id, f_rnd_octstring(15));
5215
5216 /* release the channel */
5217 f_rsl_chan_deact();
5218 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5219 f_rslem_unregister(0, g_chan_nr);
5220}
5221testcase TC_encr_cmd_a51() runs on test_CT {
5222 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5223 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5224 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5225}
5226testcase TC_encr_cmd_a52() runs on test_CT {
5227 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5228 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5229 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5230}
5231testcase TC_encr_cmd_a53() runs on test_CT {
5232 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5233 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5234 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5235}
5236
5237private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5238 var LapdmFrame lf;
5239 var octetstring reenc;
5240
5241 /* decode the LAPDm frame */
5242 if (ischosen(exp_match.ab)) {
5243 lf.ab := dec_LapdmFrameAB(enc);
5244 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005246 }
5247
5248 /* check if decoder result matches expectation */
5249 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005251 } else {
5252 log(name, ": matched");
5253 setverdict(pass);
5254 }
5255
5256 /* test if re-encoded frame equals original input */
5257 reenc := enc_LapdmFrame(lf);
5258 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005260 } else {
5261 setverdict(pass);
5262 }
5263}
5264
5265testcase TC_lapdm_selftest() runs on test_CT {
5266 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5267 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5268 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5269 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5270 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5271 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5272 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5273}
5274
Stefan Sperling4880be42018-08-07 18:12:59 +02005275/***********************************************************************
5276 * DTX Related (see GSM 05.08, section 8.3)
5277 ***********************************************************************/
5278
5279/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5280function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5281 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5282 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5283 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5284 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5285}
5286function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5287 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5288 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5289}
5290function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5291 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5292 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5293 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5294 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5295}
5296function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5297 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5298 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5299 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5300 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5301 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5302 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5303 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5304 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5305}
5306
5307function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5308 var L1ctlDlMessage dl;
5309 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5310 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5311 var GsmFrameNumber first_fn;
5312 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005313 var integer nfill_frames_sacch := 0;
5314 var integer nfill_frames_nonsacch := 0;
5315 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005316 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5317 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005318 const integer frame_dtx_tchf_mod := 104;
5319 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5320 * which operates in terms of blocks rather than frames. */
5321 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5322 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005323 timer T := 5.0;
5324
5325 f_l1_tune(L1CTL);
5326 RSL.clear;
5327 L1CTL.clear;
5328
5329 /* activate TCHF signalling channel */
5330 f_est_dchan(false);
5331
5332 T.start;
5333 alt {
5334 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5335 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5336 var octetstring l2 := dl.payload.data_ind.payload;
5337
5338 if (is_first_frame) {
5339 is_first_frame := false;
5340 first_fn := dl.dl_info.frame_nr;
5341 }
5342
5343 if (dl.dl_info.link_id.c == SACCH) {
5344 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5345 if (not match(l2_fill_frame_sacch, l2)) {
5346 repeat;
5347 }
5348 } else if (not match(l2_fill_frame, l2)) {
5349 repeat;
5350 }
5351
5352 if (dtxd) {
5353 if (not f_g_chan_is_tchf()) {
5354 T.stop;
5355 f_rsl_chan_deact();
5356 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005357 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 +02005358 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005359 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005360 T.stop;
5361 f_rsl_chan_deact();
5362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005363
5364 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5365 * 2 SACCH, 1 TCH/F */
5366 expected_fill_frames := 3;
5367
5368 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5369 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5370 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005372 } else {
5373 setverdict(pass);
5374 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005375 } else {
5376 if (dl.dl_info.link_id.c == SACCH) {
5377 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005378 repeat;
5379 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005380 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5381 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5382 * we should only see the subset of frames numbers which correspond to a block boundary.
5383 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5384 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5385 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5386 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5387 repeat;
5388 }
5389 }
5390 log("Received DTX TCH fill frame with bad frame number: ", fn,
5391 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5392 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5393 f_rsl_chan_deact();
5394 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005396 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005397 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005398 if (dl.dl_info.link_id.c == SACCH) {
5399 nfill_frames_sacch := nfill_frames_sacch + 1;
5400 } else {
5401 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5402 }
5403 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005404 T.stop;
5405 if (f_g_chan_is_tchf()) {
5406 /* Without DTX we can expect 25 fill frames for every 104 frames.
5407 * (24 FACCH + 1 SACCH filling) */
5408 expected_fill_frames := 25;
5409 } else if (f_g_chan_is_tchh()) {
5410 /* We can expect 2 fill frames for every 104 frames. */
5411 expected_fill_frames := 2;
5412 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5413 /* We can expect 5 fill frames for every 104 frames. */
5414 expected_fill_frames := 5;
5415 } else {
5416 f_rsl_chan_deact();
5417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005419 }
5420
5421 f_rsl_chan_deact();
5422 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005423
5424 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005425 setverdict(pass);
5426 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005427 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5428 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005430 }
5431 } else {
5432 repeat;
5433 }
5434 }
5435 }
5436 [] L1CTL.receive { repeat; }
5437 [] T.timeout {
5438 f_rsl_chan_deact();
5439 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005441 }
5442 }
5443}
5444
5445function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5446 f_test_l2_fill_frames(false);
5447}
5448
5449function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5450 f_test_l2_fill_frames(true);
5451}
5452
5453function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5454 var ConnHdlr vc_conn;
5455 var ConnHdlrPars pars;
5456 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02005457 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02005458 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5459 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5460 if (dtxd) {
5461 if (i >= 4) { /* DTX is only allowed on TCH/F */
5462 break;
5463 }
5464 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5465 } else {
5466 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5467 }
5468 vc_conn.done;
5469 }
5470}
5471
5472/* Verify that L2 fill frames are sent on TCH in signaling mode if
5473 * there is nothing to transmit while DTX is disabled on downlink. */
5474testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5475 f_tch_sign_l2_fill_frame(false);
5476}
5477
5478/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5479 * there is nothing to transmit while DTX is enabled on downlink. */
5480testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5481 f_tch_sign_l2_fill_frame(true);
5482}
Harald Welte0472ab42018-03-12 15:02:26 +01005483
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005484testcase TC_chopped_ipa_ping() runs on test_CT {
5485 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5486}
5487
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005488testcase TC_chopped_ipa_payload() runs on test_CT {
5489 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5490}
5491
Harald Welte0472ab42018-03-12 15:02:26 +01005492/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5493/* protocol error as per 44.006 */
5494/* link layer failure (repetition of I-frame N200 times without ACK */
5495/* repetition of SABM or DISC N200 times without ACK */
5496/* receptiom of SABM in multi-frame established state */
5497
5498
Harald Welte68e495b2018-02-25 00:05:57 +01005499/* TODO Areas:
5500
5501* channel activation
5502** with BS_Power / MS_Power, bypassing power control loop
5503** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005504** with timing advance from initial activation on
5505* mode modify
5506** encryption
5507** multirate
5508* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005509** unsupported algorithm
5510* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005511* BS Power Control
5512* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005513* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005514* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005515** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005516* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005517** DATA_IND from BTS->PCU
5518** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005519
5520*/
Harald Welte70767382018-02-21 12:16:40 +01005521
5522control {
5523 execute( TC_chan_act_stress() );
5524 execute( TC_chan_act_react() );
5525 execute( TC_chan_deact_not_active() );
5526 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005527 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005528 execute( TC_sacch_filling() );
5529 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005530 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005531 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005532 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005533 execute( TC_sacch_chan_act_ho_async() );
5534 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005535 execute( TC_rach_content() );
5536 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005537 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07005538 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02005539 execute( TC_rach_load_idle_thresh0() );
5540 execute( TC_rach_load_idle_below_thresh() );
5541 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005542 execute( TC_meas_res_sign_tchf() );
5543 execute( TC_meas_res_sign_tchh() );
5544 execute( TC_meas_res_sign_sdcch4() );
5545 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005546 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005547 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005548 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005549 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005550 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005551 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005552 execute( TC_paging_imsi_80percent() );
5553 execute( TC_paging_tmsi_80percent() );
5554 execute( TC_paging_imsi_200percent() );
5555 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005556 execute( TC_rsl_protocol_error() );
5557 execute( TC_rsl_mand_ie_error() );
5558 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005559 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005560 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005561 execute( TC_si_sched_2bis() );
5562 execute( TC_si_sched_2ter() );
5563 execute( TC_si_sched_2ter_2bis() );
5564 execute( TC_si_sched_2quater() );
5565 execute( TC_si_sched_13() );
5566 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005567 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005568 execute( TC_ipa_crcx_twice_not_active() );
5569 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005570 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005571 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005572
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005573 if (mp_pcu_socket != "") {
5574 execute( TC_pcu_act_req() );
5575 execute( TC_pcu_act_req_wrong_ts() );
5576 execute( TC_pcu_act_req_wrong_bts() );
5577 execute( TC_pcu_act_req_wrong_trx() );
5578 execute( TC_pcu_deact_req() );
5579 execute( TC_pcu_deact_req_wrong_ts() );
5580 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005581 if (mp_l1_supports_gprs) {
5582 execute( TC_pcu_data_req_pdtch() );
5583 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005584 execute( TC_pcu_data_req_wrong_bts() );
5585 execute( TC_pcu_data_req_wrong_trx() );
5586 execute( TC_pcu_data_req_wrong_ts() );
5587 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005588 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005589 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005590 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005591 execute( TC_pcu_data_req_imm_ass_pch() );
5592 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005593 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005594 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005595 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005596 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005597 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005598 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005599 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005600 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02005601 execute( TC_pcu_socket_noconnect_nosi3gprs() );
5602 execute( TC_pcu_socket_connect_si3gprs() );
5603 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005604 } else {
5605 log("PCU socket path not available, skipping PCU tests");
5606 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005607
5608 execute( TC_dyn_osmo_pdch_act_deact() );
5609 execute( TC_dyn_osmo_pdch_unsol_deact() );
5610 execute( TC_dyn_osmo_pdch_double_act() );
5611 execute( TC_dyn_osmo_pdch_tchf_act() );
5612 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005613 execute( TC_dyn_ipa_pdch_act_deact() );
5614 execute( TC_dyn_ipa_pdch_tchf_act() );
5615 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5616 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005617
5618 execute( TC_rll_est_ind() );
5619 execute( TC_rll_est_req_DCCH_3() );
5620 execute( TC_rll_est_req_ACCH_3() );
5621 execute( TC_rll_rel_ind_DCCH_0() );
5622 execute( TC_rll_rel_ind_DCCH_3() );
5623 execute( TC_rll_rel_ind_ACCH_0() );
5624 execute( TC_rll_rel_ind_ACCH_3() );
5625 execute( TC_rll_rel_req() );
5626 execute( TC_rll_unit_data_req_DCCH() );
5627 execute( TC_rll_unit_data_req_ACCH() );
5628 execute( TC_rll_unit_data_ind_DCCH() );
5629 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005630
5631 execute( TC_chan_act_a51() );
5632 execute( TC_chan_act_a52() );
5633 execute( TC_chan_act_a53() );
5634 execute( TC_encr_cmd_a51() );
5635 execute( TC_encr_cmd_a52() );
5636 execute( TC_encr_cmd_a53() );
5637
Harald Welteee25aae2019-05-19 14:32:37 +02005638 execute( TC_err_rep_wrong_mdisc() );
5639 execute( TC_err_rep_wrong_msg_type() );
5640 execute( TC_err_rep_wrong_sequence() );
5641
Harald Weltee613f962018-04-18 22:38:16 +02005642 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005643
5644 execute( TC_tch_sign_l2_fill_frame() );
5645 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005646
5647 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005648 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005649}
5650
5651
5652}