blob: 4466ad47ba39b28be8c444ce46363940c1cc2ce4 [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;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010038import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020039import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010040
41import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010042import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010043import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020044import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010045import from RSL_Emulation all;
46
47import from IPL4asp_Types all;
48import from TRXC_Types all;
49import from TRXC_CodecPort all;
50import from TRXC_CodecPort_CtrlFunct all;
51
Harald Welte883340c2018-02-28 18:59:29 +010052import from PCUIF_Types all;
53import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020054import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010055
Harald Welte7484fc42018-02-24 14:09:45 +010056import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010057import from MobileL3_RRM_Types all;
58import from MobileL3_Types all;
59import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020060import from L3_Common all;
61import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010062
Harald Welte8da48242018-02-27 20:41:32 +010063import from Osmocom_VTY_Functions all;
64import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020065import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010066
Harald Welte505cf9b2018-09-15 17:47:23 +030067friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020068friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020069friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010070friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030071
Harald Welte70767382018-02-21 12:16:40 +010072/* The tests assume a BTS with the following timeslot configuration:
73 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020074 * TS1 : TCH/F
75 * TS2 : TCH/F
76 * TS3 : TCH/F_PDCH (IPA Style)
77 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010078 * TS5 : TCH/H
79 * TS6 : SDCCH/8
80 * TS7 : PDCH
81 */
82
83modulepar {
84 charstring mp_rsl_ip := "127.0.0.2";
85 integer mp_rsl_port := 3003;
86 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070087 charstring mp_bts_trxc_ip := "127.0.0.1";
88 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010089 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020090 charstring mp_ctrl_ip := "127.0.0.1";
91 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020092 charstring mp_bsc_ctrl_ip := "127.0.0.1";
93 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020094 integer mp_tolerance_rxqual := 1;
95 integer mp_tolerance_rxlev := 3;
96 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020097 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020098 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020099 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_ms_actual_ta_exp := 0;
101 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100102 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200103 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200104 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200105 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
106 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100107}
108
Harald Welte629cc6b2018-03-11 17:19:05 +0100109type record of RslChannelNr ChannelNrs;
110
Harald Welte70767382018-02-21 12:16:40 +0100111type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100113 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100114 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100115 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100116 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100117 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100118
119 /* L1CTL port (for classic tests) */
120 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100121
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700122 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700123 port TRXC_CODEC_PT BTS_TRXC;
124 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100125
Harald Weltef50e3ae2018-09-10 10:27:56 +0200126 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100127 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200128 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100129
Harald Welte883340c2018-02-28 18:59:29 +0100130 /* PCU Interface of BTS */
131 port PCUIF_CODEC_PT PCU;
132 var integer g_pcu_conn_id;
133 /* Last PCU INFO IND we received */
134 var PCUIF_Message g_pcu_last_info;
135
Harald Welte48494ca2018-02-25 16:59:50 +0100136 /* SI configuration */
137 var SystemInformationConfig si_cfg := {
138 bcch_extended := false,
139 si1_present := false,
140 si2bis_present := false,
141 si2ter_present := false,
142 si2quater_present := false,
143 si7_present := false,
144 si8_present := false,
145 si9_present := false,
146 si13_present := false,
147 si13alt_present := false,
148 si15_present := false,
149 si16_present := false,
150 si17_present := false,
151 si2n_present := false,
152 si21_present := false,
153 si22_present := false
154 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100155
156 /* all logical channels available on the BTS */
157 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100158 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100159}
160
161/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200162type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100163 port L1CTL_PT L1CTL;
164
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700165 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700166 port TRXC_CODEC_PT BTS_TRXC;
167 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100168
169 timer g_Tguard;
170 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
171
172 var ConnHdlrPars g_pars;
173 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100174 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200175
176 /* PCU Interface of BTS */
177 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100178}
179
180function f_init_rsl(charstring id) runs on test_CT {
181 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
182 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
183
184 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
185 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
186 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
187
188 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
189 vc_RSL.start(RSL_Emulation.main(false));
190}
191
192type record ConnHdlrPars {
193 RslChannelNr chan_nr,
194 RSL_IE_ChannelMode chan_mode,
195 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100196 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200197 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200198 RSL_IE_EncryptionInfo encr optional,
199 BtsBand bts0_band optional
Harald Welte0472ab42018-03-12 15:02:26 +0100200}
201
202/* Test-specific parameters */
203type union TestSpecUnion {
204 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100205}
206
Harald Welte82ccef72018-02-25 16:17:33 +0100207template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100208 max_retrans := RACH_MAX_RETRANS_7,
209 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100210 cell_barr_access := false,
211 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100212 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100213};
214
Harald Weltef10153f2018-02-25 16:34:05 +0100215template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100216 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200217 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100218 acs := '0'B,
219 neci := true,
220 rxlev_access_min := 0
221}
222
223template (value) LocationAreaIdentification ts_LAI_default := {
224 mcc_mnc := '262F42'H,
225 lac := 42
226}
227
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700228private template (value) GPRSIndicator ts_GPRSIndicator_def := {
229 ra_colour := 0,
230 si13_pos := '0'B
231}
232
233private template (value) SI3RestOctets ts_SI3RestOctets_def
234modifies ts_SI3RestOctets := {
235 gprs_ind := {
236 presence := CSN1_H,
237 ind := ts_GPRSIndicator_def
238 }
239}
240
241private template (value) SI4RestOctets ts_SI4RestOctets_def
242modifies ts_SI4RestOctets := {
243 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700244 presence := CSN1_H,
245 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700246 }
247}
248
Harald Welte7484fc42018-02-24 14:09:45 +0100249/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100250template (value) SystemInformation ts_SI3_default := {
251 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100252 payload := {
253 si3 := {
254 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100255 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100256 ctrl_chan_desc := {
257 msc_r99 := true,
258 att := true,
259 bs_ag_blks_res := 1,
260 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100261 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100262 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
263 spare := '00'B,
264 bs_pa_mfrms := 0, /* 2 multiframes */
265 t3212 := 1 /* 6 minutes */
266 },
Harald Welte82ccef72018-02-25 16:17:33 +0100267 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100268 dn_ind := false,
269 pwrc := false,
270 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100271 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100272 },
Harald Weltef10153f2018-02-25 16:34:05 +0100273 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100274 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700275 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100276 }
277 }
278}
Harald Welte70767382018-02-21 12:16:40 +0100279
Harald Weltef8df4cb2018-03-10 15:15:08 +0100280template (value) SystemInformation ts_SI2_default := {
281 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100282 payload := {
283 si2 := {
284 bcch_freq_list := '00000000000000000000000000000000'O,
285 ncc_permitted := '11111111'B,
286 rach_control := ts_RachCtrl_default
287 }
288 }
289}
290
Harald Weltef8df4cb2018-03-10 15:15:08 +0100291template (value) SystemInformation ts_SI4_default := {
292 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100293 payload := {
294 si4 := {
295 lai := ts_LAI_default,
296 cell_sel_par := ts_CellSelPar_default,
297 rach_control := ts_RachCtrl_default,
298 cbch_chan_desc := omit,
299 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700300 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100301 }
302 }
303}
304
305function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
306runs on test_CT {
307 log("Setting ", rsl_si_type, ": ", si_enc);
308 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
309}
310
311function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
312runs on test_CT {
313 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
314 log("Setting ", rsl_si_type, ": ", si_dec);
315 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
316}
317
Harald Welte505cf9b2018-09-15 17:47:23 +0300318friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100319 map(self:BTSVTY, system:BTSVTY);
320 f_vty_set_prompts(BTSVTY);
321 f_vty_transceive(BTSVTY, "enable");
322}
323
Harald Welte505cf9b2018-09-15 17:47:23 +0300324friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200325 map(self:BSCVTY, system:BSCVTY);
326 f_vty_set_prompts(BSCVTY, "OsmoBSC");
327 f_vty_transceive(BSCVTY, "enable");
328}
329
Harald Welte883340c2018-02-28 18:59:29 +0100330/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200331private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
332 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100333 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200334 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
335 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100336 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200337 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100339 }
340}
341
Harald Weltef26de0b2018-04-04 20:28:05 +0200342private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
343 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100344 timer T := 2.0;
345 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100346 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200347 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100348 return;
349 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200350 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100351
352 T.start;
353 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200354 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100355 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100357 }
358 }
359}
360
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700361private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
362 out integer trxc_conn_id) {
363 var Result res;
364
365 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
366 "", -1, -1, { udp := {} }, {});
367 if (not ispresent(res.connId)) {
368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
369 "Could not connect to the control (TRXC) interface " &
370 "of FakeTRX, check your configuration");
371 }
372 trxc_conn_id := res.connId;
373}
374
Harald Welte70767382018-02-21 12:16:40 +0100375/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200376function f_init() runs on test_CT {
377 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100378 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100379 g_AllChannels := {
380 /* TS 1..4: TCH/F */
381 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
382 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
383 /* TS 5: TCH/H */
384 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
385 /* TS 0: SDCCH/4 */
386 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
387 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
388 /* TS 6: SDCCH/8 */
389 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
390 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
391 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
392 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
393 };
394
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200395 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700396 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200397 g_AllChanTypes := {
398 /* TS 1..4: TCH/F */
399 valueof(ts_RslChanNr_Bm(1)),
400 /* TS 5: TCH/H */
401 valueof(ts_RslChanNr_Lm(5,1)),
402 /* TS 0: SDCCH/4 */
403 valueof(ts_RslChanNr_SDCCH4(0,2)),
404 /* TS 6: SDCCH/8 */
405 valueof(ts_RslChanNr_SDCCH8(6,4))
406 };
407 } else {
408 g_AllChanTypes := {
409 /* TS 1..4: TCH/F */
410 valueof(ts_RslChanNr_Bm(1)),
411 /* TS 0: SDCCH/4 */
412 valueof(ts_RslChanNr_SDCCH4(0,2)),
413 /* TS 6: SDCCH/8 */
414 valueof(ts_RslChanNr_SDCCH8(6,4))
415 };
416 }
Harald Welte70767382018-02-21 12:16:40 +0100417 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200418 T.start;
419 alt {
420 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
421 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200423 }
424 }
Harald Welte2d142592018-02-25 13:19:44 +0100425 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100426 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200427 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100428
429 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100430 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
431 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
432 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
433 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100434
Harald Weltef26de0b2018-04-04 20:28:05 +0200435 map(self:PCU, system:PCU);
436 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100437
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700438 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100439 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700440
441 /* Init TRXC interface to FakeTRX */
442 map(self:BTS_TRXC, system:BTS_TRXC);
443 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
444
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700445 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700446 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 +0700447 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700448 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
449 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100450 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200451
452 /* Wait some extra time to make sure the BTS emits a stable carrier.
453 * (this is only relevant when running the tests with a physical BTS.) */
454 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100455}
456
Harald Welte68e495b2018-02-25 00:05:57 +0100457/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
458function f_init_l1ctl() runs on test_CT {
459 map(self:L1CTL, system:L1CTL);
460 f_connect_reset(L1CTL);
461}
462
Harald Welte70767382018-02-21 12:16:40 +0100463type function void_fn(charstring id) runs on ConnHdlr;
464
465/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700466function f_start_handler(void_fn fn, ConnHdlrPars pars,
467 boolean pcu_comp := false,
468 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100469runs on test_CT return ConnHdlr {
470 var charstring id := testcasename();
471 var ConnHdlr vc_conn;
472
473 vc_conn := ConnHdlr.create(id);
474 /* connect to RSL Emulation main component */
475 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
476 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700477
478 /* The ConnHdlr component may want to talk to some ports directly,
479 * so we disconnect it from the test_CT and connect it to the component.
480 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200481 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200482 unmap(self:PCU, system:PCU);
483 map(vc_conn:PCU, system:PCU);
484 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700485 if (trxc_comp) {
486 unmap(self:BTS_TRXC, system:BTS_TRXC);
487 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
488 }
Harald Welte70767382018-02-21 12:16:40 +0100489
490 vc_conn.start(f_handler_init(fn, id, pars));
491 return vc_conn;
492}
493
Harald Welte7484fc42018-02-24 14:09:45 +0100494template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
495 streamId := sid,
496 rsl := rsl
497}
498
499template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
500 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
501 streamId := sid,
502 rsl := rsl
503}
504
Harald Welte70767382018-02-21 12:16:40 +0100505private altstep as_Tguard() runs on ConnHdlr {
506 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100508 }
509}
510
Harald Welte990a3612019-05-27 14:02:13 +0200511friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
512 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100513}
514
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700515private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100516 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700517 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100518}
519
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700520private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100521 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700522 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100523}
524
525/* first function started in ConnHdlr component */
526private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
527runs on ConnHdlr {
528 g_pars := pars;
529 g_chan_nr := pars.chan_nr;
530
531 map(self:L1CTL, system:L1CTL);
532 f_connect_reset(L1CTL);
533
Harald Welted48c0c72019-06-05 10:01:15 +0200534 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700535 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100536 }
Harald Welte70767382018-02-21 12:16:40 +0100537
538 g_Tguard.start(pars.t_guard);
539 activate(as_Tguard());
540
541 f_rslem_register(0, pars.chan_nr);
542
543 /* call the user-supplied test case function */
544 fn.apply(id);
545}
546
Harald Welteb1726c92018-03-30 11:56:38 +0200547function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
548 boolean ignore_other := false)
549runs on ConnHdlr return RSL_Message {
550 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100551 timer T := 3.0;
552 RSL.send(tx);
553 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100554 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200555 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100556 T.stop;
557 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100558 }
Harald Welte1eba3742018-02-25 12:48:14 +0100559 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100561 }
Harald Welte21240e62018-03-11 21:43:35 +0100562 [not ignore_other] as_l1_sacch();
563 [not ignore_other] as_meas_res();
564 [not ignore_other] as_l1_dcch();
565 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100567 }
Harald Welte21240e62018-03-11 21:43:35 +0100568 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100569 }
Harald Welteb1726c92018-03-30 11:56:38 +0200570 return rx;
571}
572
573function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
574 boolean ignore_other := false)
575runs on ConnHdlr {
576 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100577}
578
Harald Welte8b01c792019-05-19 22:51:25 +0200579function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
580 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
581 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200582 if (encr_enable) {
583 /* append encryption related IEs, if requested */
584 var RSL_IE_EncryptionInfo encr_info;
585 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
586 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
587encr_info})) };
588 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200589 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200590 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100591}
592
Harald Welte70767382018-02-21 12:16:40 +0100593function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100594 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 +0100595 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100596}
597
Harald Welte2f2b2b72019-05-31 22:24:57 +0200598friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100599 template RSL_IE_ChannelMode chan_mode,
600 float t_guard := 20.0) := {
601 chan_nr := valueof(chan_nr),
602 chan_mode := valueof(chan_mode),
603 t_guard := t_guard,
604 l1_pars := {
605 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100606 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100607 meas_ul := {
608 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200609 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100610 rxqual := 0
611 },
612 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200613 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100614 rxqual := 0
615 }
616 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200617 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100618 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200619 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200620 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100621 },
Harald Weltee613f962018-04-18 22:38:16 +0200622 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200623 encr := omit,
624 bts0_band := omit
Harald Welte70767382018-02-21 12:16:40 +0100625}
626
Harald Welte93640c62018-02-25 16:59:33 +0100627/***********************************************************************
628 * Channel Activation / Deactivation
629 ***********************************************************************/
630
Harald Welte70767382018-02-21 12:16:40 +0100631/* Stress test: Do 500 channel activations/deactivations in rapid succession */
632function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
633 for (var integer i := 0; i < 500; i := i+1) {
634 f_rsl_chan_act(g_pars.chan_mode);
635 f_rsl_chan_deact();
636 }
637 setverdict(pass);
638}
639testcase TC_chan_act_stress() runs on test_CT {
640 var ConnHdlr vc_conn;
641 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200642 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100643 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
644 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100646}
647
648/* Test if re-activation of an already active channel fails as expected */
649function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
650 f_rsl_chan_act(g_pars.chan_mode);
651 /* attempt to activate the same lchan again -> expect reject */
652 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
653 alt {
654 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100656 }
657 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
658 setverdict(pass);
659 }
660 }
661 f_rsl_chan_deact();
662}
663testcase TC_chan_act_react() runs on test_CT {
664 var ConnHdlr vc_conn;
665 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100666 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100667 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
668 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100670}
671
672/* Attempt to de-activate a channel that's not active */
673function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
674 timer T := 3.0;
675 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
676 T.start;
677 alt {
678 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
679 setverdict(pass);
680 }
681 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100683 }
684 }
685}
686testcase TC_chan_deact_not_active() runs on test_CT {
687 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100688 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100689 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
690 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100692}
693
694/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
695function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
696 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
697 alt {
698 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100700 }
701 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
702 setverdict(pass);
703 }
704 }
705}
706private type record WrongChanNrCase {
707 RslChannelNr chan_nr,
708 charstring description
709}
710private type record of WrongChanNrCase WrongChanNrCases;
711private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
712 chan_nr := chan_nr,
713 description := desc
714}
715
716testcase TC_chan_act_wrong_nr() runs on test_CT {
717 var ConnHdlr vc_conn;
718 var ConnHdlrPars pars;
719
Harald Welte294b0a22018-03-10 23:26:48 +0100720 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100721
722 var WrongChanNrCases wrong := {
723 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
724 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
725 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
726 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
727 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
728 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
729 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
730 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
731 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
732 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
733 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
734 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
735 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
736 };
737
738 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
739 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
740 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
741 vc_conn.done;
742 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100744}
745
Harald Weltee613f962018-04-18 22:38:16 +0200746/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200747friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200748 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200749 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200750
751 /* test on each of the channels we have */
752 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
753 pars.chan_nr := valueof(g_AllChanTypes[i]);
754
755 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
756 vc_conn := f_start_handler(fn, pars);
757 vc_conn.done;
758 }
759
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200761}
762
Harald Welte93640c62018-02-25 16:59:33 +0100763/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100764 * SACCH handling
765 ***********************************************************************/
766
767private function f_exp_sacch(boolean exp) runs on ConnHdlr {
768 timer T_sacch := 3.0;
769 T_sacch.start;
770 alt {
771 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100773 }
774 [not exp] T_sacch.timeout {
775 setverdict(pass);
776 }
777 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
778 setverdict(pass);
779 }
780 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100782 }
783 [] L1CTL.receive { repeat; }
784 [] RSL.receive { repeat; }
785 }
786}
787
788/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
789private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
790 f_l1_tune(L1CTL);
791 RSL.clear;
792
793 /* activate the logical channel */
794 f_est_dchan();
795 L1CTL.clear;
796
797 /* check that SACCH actually are received as expected */
798 f_exp_sacch(true);
799
800 /* deactivate SACCH on the logical channel */
801 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
802 f_sleep(1.0);
803 L1CTL.clear;
804
805 /* check that no SACCH are received anymore */
806 f_exp_sacch(false);
807
808 /* release the channel */
809 f_rsl_chan_deact();
810 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
811}
812testcase TC_deact_sacch() runs on test_CT {
813 var ConnHdlr vc_conn;
814 var ConnHdlrPars pars;
815 f_init();
816 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
817 //for (var integer i := 0; i < 1; i := i+1) {
818 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
819 log(testcasename(), ": Starting for ", g_AllChannels[i]);
820 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
821 vc_conn.done;
822 }
823 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100825}
826
Harald Welte55700662018-03-12 13:15:43 +0100827/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100828private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
829 var L1ctlDlMessage dl;
830 /* check that the specified SI5 value is actually sent */
831 timer T_sacch := 3.0;
832 L1CTL.clear;
833 T_sacch.start;
834 alt {
835 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
836 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
837 if (match(l3, l3_exp)) {
838 setverdict(pass);
839 } else {
840 repeat;
841 }
842 }
843 [] L1CTL.receive { repeat; }
844 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100846 }
847 }
848}
849
Harald Welte55700662018-03-12 13:15:43 +0100850/* verify that given SACCH payload is not present */
851private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
852 var L1ctlDlMessage dl;
853 /* check that the specified SI5 value is actually sent */
854 timer T_sacch := 3.0;
855 L1CTL.clear;
856 T_sacch.start;
857 alt {
858 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
859 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
860 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100862 } else {
863 repeat;
864 }
865 }
866 [] L1CTL.receive { repeat; }
867 [] T_sacch.timeout {
868 setverdict(pass);
869 }
870 }
871}
872
Harald Welte629cc6b2018-03-11 17:19:05 +0100873/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100874private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
875 /* Set a known default SACCH filling for SI5 */
876 var octetstring si5 := f_rnd_octstring(19);
877 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
878
879 f_l1_tune(L1CTL);
880 RSL.clear;
881
882 /* activate the logical channel */
883 f_est_dchan();
884
885 /* check that the specified SI5 value is actually sent */
886 f_sacch_present(si5);
887
888 /* release the channel */
889 RSL.clear;
890 f_rsl_chan_deact();
891 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
892}
893testcase TC_sacch_filling() runs on test_CT {
894 var ConnHdlr vc_conn;
895 var ConnHdlrPars pars;
896 f_init();
897 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
898 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
899 log(testcasename(), ": Starting for ", g_AllChannels[i]);
900 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
901 vc_conn.done;
902 }
903 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100905}
906
Harald Welte629cc6b2018-03-11 17:19:05 +0100907/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100908private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
909 /* Set a known default SACCH filling for SI5 */
910 var octetstring si5 := f_rnd_octstring(19);
911 var octetstring si5_diff := f_rnd_octstring(19);
912 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
913
914 f_l1_tune(L1CTL);
915 RSL.clear;
916
917 log("Activating channel, expecting standard SI5");
918 /* activate the logical channel */
919 f_est_dchan();
920 /* check that the specified SI5 value is actually sent */
921 f_sacch_present(si5);
922
923 /* set channel-specific different SI5 */
924 log("Setting channel specific SACCH INFO, expecting it");
925 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
926 /* check that the specified lchan-specific value is now used */
927 f_sacch_present(si5_diff);
928
929 /* deactivate the channel and re-activate it, this should result in default SI5 */
930 log("De-activating and re-activating channel, expecting standard SI5");
931 f_rsl_chan_deact();
932 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
933 /* Verify that the TRX-wide default SACCH filling is present again */
934 f_sacch_present(si5);
935
936 /* release the channel */
937 RSL.clear;
938 f_rsl_chan_deact();
939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
940}
941testcase TC_sacch_info_mod() runs on test_CT {
942 var ConnHdlr vc_conn;
943 var ConnHdlrPars pars;
944 f_init();
945 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
946 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
947 log(testcasename(), ": Starting for ", g_AllChannels[i]);
948 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
949 vc_conn.done;
950 }
951 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100953}
954
Harald Welte075d84c2018-03-12 13:07:24 +0100955/* Test SACCH scheduling of multiple different SI message types */
956private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
957 var octetstring si5 := f_rnd_octstring(19);
958 var octetstring si5bis := f_rnd_octstring(19);
959 var octetstring si5ter := f_rnd_octstring(19);
960 var octetstring si6 := f_rnd_octstring(19);
961
962 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
963 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
964 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
965 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
966
967 f_l1_tune(L1CTL);
968 RSL.clear;
969
970 /* activate the logical channel */
971 f_est_dchan();
972 L1CTL.clear;
973
974 /* check that SACCH actually are received as expected */
975 f_sacch_present(si5);
976 f_sacch_present(si5bis);
977 f_sacch_present(si5ter);
978 f_sacch_present(si6);
979
980 /* release the channel */
981 f_rsl_chan_deact();
982 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
983}
984testcase TC_sacch_multi() runs on test_CT {
985 var ConnHdlr vc_conn;
986 var ConnHdlrPars pars;
987 f_init();
988 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
989 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
990 log(testcasename(), ": Starting for ", g_AllChannels[i]);
991 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
992 vc_conn.done;
993 }
994 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100996}
997
Harald Welte55700662018-03-12 13:15:43 +0100998/* Test if SACH information is modified as expected */
999private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1000 var octetstring si5 := f_rnd_octstring(19);
1001 var octetstring si6 := f_rnd_octstring(19);
1002
1003 /* First, configure both SI5 and SI6 to be transmitted */
1004 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1005 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1006
1007 f_l1_tune(L1CTL);
1008 RSL.clear;
1009
1010 /* activate the logical channel */
1011 f_est_dchan();
1012 L1CTL.clear;
1013
1014 /* check that SACCH actually are received as expected */
1015 f_sacch_present(si5);
1016 f_sacch_present(si6);
1017
1018 /* disable SI6 */
1019 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1020
1021 /* check that SI5 is still transmitted */
1022 f_sacch_present(si5);
1023 /* check if SI6 is now gone */
1024 f_sacch_missing(si6);
1025
1026 /* release the channel */
1027 f_rsl_chan_deact();
1028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1029}
1030testcase TC_sacch_multi_chg() runs on test_CT {
1031 var ConnHdlr vc_conn;
1032 var ConnHdlrPars pars;
1033 f_init();
1034 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1035 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1036 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1037 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1038 vc_conn.done;
1039 }
1040 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001042}
1043
Harald Weltec8d363c2019-05-19 20:36:48 +02001044/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1045private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1046 var octetstring si5 := f_rnd_octstring(19);
1047 var octetstring si6 := f_rnd_octstring(19);
1048 var octetstring si5_specific := f_rnd_octstring(19);
1049 var octetstring si6_specific := f_rnd_octstring(19);
1050
1051 /* First, configure both SI5 and SI6 to be transmitted */
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 /* activate channel with different SACCH filling */
1059 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1060 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1061 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1062 }));
1063 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1064 RSL_IE_Body:{sacch_info := sacch_info})) };
1065 f_est_dchan(more_ies := addl_ies);
1066
1067 /* check that SACCH actually are received as expected */
1068 f_sacch_present(si5_specific);
1069 f_sacch_present(si6_specific);
1070
1071 /* release the channel */
1072 f_rsl_chan_deact();
1073 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1074}
1075testcase TC_sacch_chan_act() runs on test_CT {
1076 var ConnHdlr vc_conn;
1077 var ConnHdlrPars pars;
1078 f_init();
1079
1080 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1081 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1082 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1083 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1084 vc_conn.done;
1085 }
1086 /* TODO: do the above in parallel, rather than sequentially? */
1087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1088}
1089
Harald Welte8b01c792019-05-19 22:51:25 +02001090/* verify that SACCH DL transmission is started only if MS power IE present
1091 * see section 4.1.3 of 3GPP TS 48.058 */
1092private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1093 var octetstring si5 := f_rnd_octstring(19);
1094
1095 f_l1_tune(L1CTL);
1096 RSL.clear;
1097
1098 /* Step 1: Activate ASYNC HO channel without MS power IE */
1099
1100 /* Activate channel on BTS side */
1101 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1102 /* don't perform immediate assignment here, as we're testing non-IA case */
1103 /* enable dedicated mode */
1104 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1105
1106 /* Verify that no DL SACCH is being received */
1107 f_sacch_missing(?);
1108
1109 f_rsl_chan_deact();
1110 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1111
1112
1113 /* Step 2: Activate ASYNC HO channel with MS power IE */
1114
1115 /* Activate channel on BTS side */
1116 var RSL_IE_List addl_ies := {
1117 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1118 };
1119 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1120 /* don't perform immediate assignment here, as we're testing non-IA case */
1121 /* enable dedicated mode */
1122 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1123
1124 /* Verify that DL SACCH is being received */
1125 f_sacch_present(si5);
1126
1127 f_rsl_chan_deact();
1128 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1129}
1130testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1131 var ConnHdlr vc_conn;
1132 var ConnHdlrPars pars;
1133 f_init();
1134
1135 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1136 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1137 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1138 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1139 vc_conn.done;
1140 }
1141 /* TODO: do the above in parallel, rather than sequentially? */
1142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1143}
1144
1145/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1146 * see section 4.1.4 of 3GPP TS 48.058 */
1147private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1148 var octetstring si5 := f_rnd_octstring(19);
1149 var RSL_IE_List addl_ies;
1150
1151 f_l1_tune(L1CTL);
1152 RSL.clear;
1153
1154 /* Step 1: Activate SYNC HO channel without MS power IE */
1155
1156 /* Activate channel on BTS side */
1157 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1158 /* don't perform immediate assignment here, as we're testing non-IA case */
1159 /* enable dedicated mode */
1160 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1161
1162 /* Verify that no DL SACCH is being received */
1163 f_sacch_missing(?);
1164
1165 f_rsl_chan_deact();
1166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1167
1168
1169 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1170
1171 /* Activate channel on BTS side */
1172 addl_ies := {
1173 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1174 };
1175 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1176 /* don't perform immediate assignment here, as we're testing non-IA case */
1177 /* enable dedicated mode */
1178 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1179
1180 /* Verify that no DL SACCH is being received */
1181 f_sacch_missing(?);
1182
1183 f_rsl_chan_deact();
1184 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1185
1186
1187 /* Step 2b: Activate SYNC HO channel with TA IE */
1188
1189 /* Activate channel on BTS side */
1190 addl_ies := {
1191 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1192 };
1193 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1194 /* don't perform immediate assignment here, as we're testing non-IA case */
1195 /* enable dedicated mode */
1196 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1197
1198 /* Verify that no DL SACCH is being received */
1199 f_sacch_missing(?);
1200
1201 f_rsl_chan_deact();
1202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1203
1204
1205 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1206
1207 /* Activate channel on BTS side */
1208 addl_ies := {
1209 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1210 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1211 };
1212 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1213 /* don't perform immediate assignment here, as we're testing non-IA case */
1214 /* enable dedicated mode */
1215 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1216
1217 /* Verify that DL SACCH is being received */
1218 f_sacch_present(si5);
1219
1220 f_rsl_chan_deact();
1221 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1222}
1223testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1224 var ConnHdlr vc_conn;
1225 var ConnHdlrPars pars;
1226 f_init();
1227
1228 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1229 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1230 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1231 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1232 vc_conn.done;
1233 }
1234 /* TODO: do the above in parallel, rather than sequentially? */
1235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1236}
Harald Welte629cc6b2018-03-11 17:19:05 +01001237
1238
1239/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001240 * RACH Handling
1241 ***********************************************************************/
1242
Harald Welte8c24c2b2018-02-26 08:31:31 +01001243/* like L1SAP_IS_PACKET_RACH */
1244private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001245 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001246 return true;
1247 }
1248 return false;
1249}
1250
1251/* generate a random RACH for circuit-switched */
1252private function f_rnd_ra_cs() return OCT1 {
1253 var OCT1 ra;
1254 do {
1255 ra := f_rnd_octstring(1);
1256 } while (ra_is_ps(ra));
1257 return ra;
1258}
1259
Harald Welte883340c2018-02-28 18:59:29 +01001260/* generate a random RACH for packet-switched */
1261private function f_rnd_ra_ps() return OCT1 {
1262 var OCT1 ra;
1263 do {
1264 ra := f_rnd_octstring(1);
1265 } while (not ra_is_ps(ra));
1266 return ra;
1267}
1268
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001269/* generate a random 11-bit RA (packet-switched only) */
1270private function f_rnd_ra11_ps() return BIT11 {
1271 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1272 return int2bit(ra11, 11);
1273}
1274
Harald Welte8c24c2b2018-02-26 08:31:31 +01001275/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1276testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001277 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001278 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001279 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001280
Harald Welte8c24c2b2018-02-26 08:31:31 +01001281 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001282 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001283 for (var integer i := 0; i < 1000; i := i+1) {
1284 var OCT1 ra := f_rnd_ra_cs();
1285 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1286 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001288 }
1289 fn_last := fn;
1290
1291 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001292 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001293 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001294 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001295 T.stop;
1296 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001297 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001299 }
1300 [] RSL_CCHAN.receive { repeat; }
1301 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001302 test_failed := true;
1303 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001304 }
1305 }
1306 }
Maxba06feb2019-03-05 10:52:46 +01001307 if (test_failed) {
1308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001309 }
Maxba06feb2019-03-05 10:52:46 +01001310 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001312}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001313
1314/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1315testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001316 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001317 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001318 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001319 f_l1_tune(L1CTL);
1320
1321 var GsmFrameNumber fn_last := 0;
1322 for (var integer i := 0; i < 1000; i := i+1) {
1323 var OCT1 ra := f_rnd_ra_cs();
1324 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1325 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001327 }
1328 fn_last := fn;
1329 }
1330 var integer rsl_chrqd := 0;
1331 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001332 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001333 alt {
1334 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1335 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001336 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001337 repeat;
1338 }
1339 [] RSL_CCHAN.receive { repeat; }
1340 [] T.timeout { }
1341 }
1342 if (rsl_chrqd == 1000) {
1343 setverdict(pass);
1344 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001346 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001348}
1349
Harald Welte3453ab42019-05-24 21:19:58 +02001350private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1351 var charstring bts_str := "bts " & int2str(bts_nr);
1352 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1353}
1354
1355/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1356private template integer tr_rach_slots_per_interval := (90 .. 130);
1357
1358/* Expect 0 RACH load on an idle BTS that has just started up */
1359testcase TC_rach_load_idle_thresh0() runs on test_CT {
1360 var ASP_RSL_Unitdata rx_ud;
1361
1362 f_init_vty_bsc();
1363 /* send load indications even at 0% load */
1364 f_vty_load_ind_thresh(0);
1365 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1366 f_sleep(2.0);
1367
1368 f_init();
1369
1370 timer T := 5.0;
1371 T.start;
1372 alt {
1373 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1374 setverdict(pass);
1375 repeat;
1376 }
1377 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1378 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1379 repeat;
1380 }
1381 [] RSL_CCHAN.receive {
1382 repeat;
1383 }
1384 [] T.timeout { }
1385 }
1386
1387 f_vty_load_ind_thresh(10);
1388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1389}
1390
1391/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1392testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1393 var ASP_RSL_Unitdata rx_ud;
1394
1395 f_init_vty_bsc();
1396 f_init();
1397
1398 timer T := 5.0;
1399 T.start;
1400 alt {
1401 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1402 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1403 repeat;
1404 }
1405 [] RSL_CCHAN.receive {
1406 repeat;
1407 }
1408 [] T.timeout {
1409 setverdict(pass);
1410 }
1411 }
1412
1413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1414}
1415
1416/* Expect 0 RACH load on an idle BTS that has just started up */
1417testcase TC_rach_load_count() runs on test_CT {
1418 var ASP_RSL_Unitdata rx_ud;
1419 var integer load_access_count := 0;
1420
1421 f_init_vty_bsc();
1422 /* send load indications even at 0% load */
1423 f_vty_load_ind_thresh(0);
1424 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1425 f_sleep(2.0);
1426 f_init();
1427
1428 f_init_l1ctl();
1429 f_sleep(1.0);
1430 f_l1_tune(L1CTL);
1431
1432 var GsmFrameNumber fn_last := 0;
1433 for (var integer i := 0; i < 1000; i := i+1) {
1434 var OCT1 ra := f_rnd_ra_cs();
1435 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1436 if (fn == fn_last) {
1437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1438 }
1439 fn_last := fn;
1440 }
1441
1442 timer T := 5.0;
1443 T.start;
1444 alt {
1445 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1446 -> value rx_ud {
1447 var RSL_IE_Body ie;
1448 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1449 load_access_count := load_access_count + ie.rach_load.access_count;
1450 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1451 setverdict(fail, "Access count cannot be < Busy count");
1452 }
1453 repeat;
1454 }
1455 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1456 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1457 repeat;
1458 }
1459 [] RSL_CCHAN.receive {
1460 repeat;
1461 }
1462 [] T.timeout { }
1463 }
1464 if (load_access_count == 1000) {
1465 setverdict(pass);
1466 } else {
1467 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1468 }
1469
1470 f_vty_load_ind_thresh(10);
1471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1472}
1473
Harald Welte54a2a2d2018-02-26 09:14:05 +01001474private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001475 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001476 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001477 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001478 f_sleep(0.5);
1479
1480 /* Transmit RACH request + wait for confirmation */
1481 var OCT1 ra := f_rnd_ra_cs();
1482 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1483
1484 /* Check for expected result */
1485 timer T := 1.5;
1486 T.start;
1487 alt {
1488 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1489 setverdict(pass);
1490 }
1491 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001493 }
1494 [] RSL_CCHAN.receive { repeat; }
1495 [not expect_pass] T.timeout {
1496 setverdict(pass);
1497 }
1498 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001500 }
1501 }
1502}
1503
1504/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1505testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001506 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001507 f_init_l1ctl();
1508 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001509 f_sleep(1.0);
1510
1511 /* default max-ta is 63 (full range of GSM timing advance */
1512
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001513 /* We allow early arrival up to 2 symbols */
1514 f_rach_toffs(-1*256, true);
1515 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001516 f_rach_toffs(-10*256, false);
1517
1518 /* 0 / 32 / 63 bits is legal / permitted */
1519 f_rach_toffs(0, true);
1520 f_rach_toffs(32*256, true);
1521 f_rach_toffs(63*256, true);
1522
1523 /* more than 63 bits is not legal / permitted */
1524 f_rach_toffs(64*256, false);
1525 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001527}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001528
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001529function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1530 var GsmFrameNumber fn;
1531 var RSL_Message rm;
1532
1533 f_l1_tune(L1CTL);
1534 RSL.clear;
1535
1536 /* Generate a random Handover Reference */
1537 var integer ho_ref := oct2int(f_rnd_octstring(1));
1538
1539 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1540 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1541 RSL_IE_Body:{ handover_ref := ho_ref }));
1542
1543 /* Activate a channel on the BTS side (no encryption) */
1544 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1545 act_type := t_RSL_IE_ActType_HO_SYNC);
1546
1547 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1548 * waiting for Immediate Assignment and sending Access Burst */
1549 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1550
1551 /* Send handover Access Burst */
1552 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1553
1554 /* TODO: test mismatching Handover Reference, and missing IE */
1555
1556 /* Wait for handover detection */
1557 timer T := 3.0;
1558 T.start;
1559 alt {
1560 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1561 log("Handover RACH has been detected: ", rm);
1562 setverdict(pass);
1563 }
1564 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1566 log2str("RSL_CHAN_RQD was not expected: ", rm));
1567 }
1568 [] RSL.receive { repeat; }
1569 [] T.timeout {
1570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1571 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1572 }
1573 }
1574
1575 /* Release the channel */
1576 f_rsl_chan_deact();
1577 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1578}
1579
1580/* Test handover RACH detection */
1581testcase TC_ho_rach() runs on test_CT {
1582 var ConnHdlrPars pars;
1583 var ConnHdlr vc_conn;
1584
1585 f_init();
1586
1587 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1588 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1589 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1590 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1591 vc_conn.done;
1592 }
1593
1594 /* TODO: do the above in parallel, rather than sequentially? */
1595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1596}
1597
Harald Welte93640c62018-02-25 16:59:33 +01001598/***********************************************************************
1599 * Measurement Processing / Reporting
1600 ***********************************************************************/
1601
Harald Welte70767382018-02-21 12:16:40 +01001602template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1603 spare := '0'B,
1604 lpd := 0,
1605 sapi := sapi,
1606 c_r := c_r,
1607 ea := true
1608}
1609
Harald Welted879bd92018-03-12 15:01:23 +01001610template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001611 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001612 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001613 len := 0, /* overwritten */
1614 m := false,
1615 el := 1,
1616 payload := pl
1617}
1618
1619/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1620altstep as_l1_sacch() runs on ConnHdlr {
1621 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001622 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001623 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001624 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 +01001625 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001626 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001627
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001628 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1629 g_pars.l1_pars.ms_power_level, false,
1630 g_pars.l1_pars.ms_actual_ta);
1631
1632 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1633 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1634
1635 log("Sending Measurement Report: ", l1h, l2);
1636 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001637 repeat;
1638 }
1639}
1640
1641altstep as_l1_dcch() runs on ConnHdlr {
1642 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001643 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001644 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1645 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001646 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1647 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001648 repeat;
1649 }
1650}
1651
1652type record MeasElem {
1653 uint6_t rxlev,
1654 uint3_t rxqual
1655}
1656
1657type record MeasElemFS {
1658 MeasElem full,
1659 MeasElem sub
1660}
1661
1662type record ConnL1Pars {
1663 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001664 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001665 MeasElemFS meas_ul,
1666 int16_t timing_offset_256syms,
1667 uint5_t bs_power_level,
1668 uint5_t ms_power_level,
1669 uint8_t ms_actual_ta
1670}
1671
1672/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1673private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1674 return 63 + (toffs256s/256);
1675}
1676
Harald Welted5684392018-03-10 18:22:04 +01001677private function f_max(integer a, integer b) return integer {
1678 if (a > b) {
1679 return a;
1680 } else {
1681 return b;
1682 }
1683}
1684
1685private function f_min(integer a, integer b) return integer {
1686 if (a < b) {
1687 return a;
1688 } else {
1689 return b;
1690 }
1691}
1692
1693/* compute negative tolerance val-tolerance, ensure >= min */
1694private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1695 val := val - tolerance;
1696 return f_max(val, min);
1697}
1698
1699/* compute positive tolerance val+tolerance, ensure <= max */
1700private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1701 val := val + tolerance;
1702 return f_min(val, max);
1703}
1704
1705/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1706private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1707return template integer {
1708 var template integer ret;
1709 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1710 return ret;
1711}
1712
1713
Harald Welte70767382018-02-21 12:16:40 +01001714/* build a template for matching measurement results against */
1715private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1716 var ConnL1Pars l1p := g_pars.l1_pars;
1717 var template RSL_IE_UplinkMeas ul_meas := {
1718 len := 3,
1719 rfu := '0'B,
1720 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001721 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001722 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001723 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001724 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001725 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1726 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001727 supp_meas_info := omit
1728 };
Harald Welte685d5982018-02-27 20:42:05 +01001729 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001730 ul_meas.len := (3+8);
1731 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001732 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001733 toa256_min := ?,
1734 toa256_max := ?,
1735 toa256_std_dev := ?
1736 }
Harald Welte685d5982018-02-27 20:42:05 +01001737 }
Harald Welte70767382018-02-21 12:16:40 +01001738 var template RSL_IE_BS_Power bs_power := {
1739 reserved := 0,
1740 epc := false,
1741 fpc := false,
1742 power_level := l1p.bs_power_level
1743 };
1744 var template RSL_IE_L1Info l1_info := {
1745 ms_power_lvl := l1p.ms_power_level,
1746 fpc := false,
1747 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001748 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001749 };
1750 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001751 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001752 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1753 ?, t_toffs);
1754}
1755
Philipp Maierdd841d32019-12-17 14:44:54 +01001756/* build a template for matching measurement results that do not contain any
1757 * MS related measurement (l1_info, l3_info and ms timing offset). */
1758private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1759 var ConnL1Pars l1p := g_pars.l1_pars;
1760 var template RSL_IE_UplinkMeas ul_meas := {
1761 len := 3,
1762 rfu := '0'B,
1763 dtx_d := l1p.dtx_enabled,
1764 rxlev_f_u := ?,
1765 reserved1 := '00'B,
1766 rxlev_s_u := ?,
1767 reserved2 := '00'B,
1768 rxq_f_u := ?,
1769 rxq_s_u := ?,
1770 supp_meas_info := omit
1771 };
1772 if (l1p.toa256_enabled) {
1773 ul_meas.len := (3+8);
1774 ul_meas.supp_meas_info := {
1775 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1776 toa256_min := ?,
1777 toa256_max := ?,
1778 toa256_std_dev := ?
1779 }
1780 }
1781 var template RSL_IE_BS_Power bs_power := {
1782 reserved := 0,
1783 epc := false,
1784 fpc := false,
1785 power_level := l1p.bs_power_level
1786 };
1787
1788 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1789}
1790
Harald Welte70767382018-02-21 12:16:40 +01001791/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001792altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001793 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001794 var boolean chan_est := false;
1795
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001796 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001797
1798 /* Receive osmocom specific measurement reports. This is the normal
1799 * case. Here we verify that the measurement reports we sent are
1800 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001801 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1802 /* increment counter of next to-be-expected meas rep */
1803 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1804 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001805 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001806
1807 /* The following two cases may only happen in the beginning
1808 * of the channel establishment phase. Once we have received
1809 * the "our" measurement report the first time, the channel
1810 * is established and empty or hardcoded TRXCON reports must
1811 * not occur anymore. */
1812 chan_est := true;
1813
1814 repeat;
1815 }
1816
1817 /* When the BTS has established the channel, the MS might need slightly
1818 * more time to establish the channel and actually start sending. The
1819 * result is then a measurement report that just lacks the measurement
1820 * information of the MS. This is normal and we tolerate this behavior. */
1821 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1822 /* increment counter of next to-be-expected meas rep */
1823 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1824 /* Re-start the timer expecting the next MEAS RES */
1825 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001826 repeat;
1827 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001828
1829 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1830 * measurements if the TTCN3 side does not supply measurement input in
1831 * time. In those cases TRXCON will either use a cached measurement
1832 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1833 * report the templates above will not match. We tolerate this
1834 * behavior, but only once. */
1835 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001836 /* increment counter of next to-be-expected meas rep */
1837 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1838 if (g_first_meas_res) {
1839 g_first_meas_res := false;
1840 repeat;
1841 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001843 }
Harald Welte70767382018-02-21 12:16:40 +01001844 }
1845 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001847 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001848 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001850 }
1851}
1852
Harald Weltee613f962018-04-18 22:38:16 +02001853private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1854 select (rsl_alg_id) {
1855 case (RSL_ALG_ID_A5_0) { return 0; }
1856 case (RSL_ALG_ID_A5_1) { return 1; }
1857 case (RSL_ALG_ID_A5_2) { return 2; }
1858 case (RSL_ALG_ID_A5_3) { return 3; }
1859 case (RSL_ALG_ID_A5_4) { return 4; }
1860 case (RSL_ALG_ID_A5_5) { return 5; }
1861 case (RSL_ALG_ID_A5_6) { return 6; }
1862 case (RSL_ALG_ID_A5_7) { return 7; }
1863 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1865 /* Make compiler happy by calling mtc.stop here. It is already
1866 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001867 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001868 }
1869 }
1870}
1871
1872private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1873 select (rsl_alg_id) {
1874 case (RSL_ALG_ID_A5_1) { return '000'B; }
1875 case (RSL_ALG_ID_A5_2) { return '001'B; }
1876 case (RSL_ALG_ID_A5_3) { return '010'B; }
1877 case (RSL_ALG_ID_A5_4) { return '011'B; }
1878 case (RSL_ALG_ID_A5_5) { return '100'B; }
1879 case (RSL_ALG_ID_A5_6) { return '101'B; }
1880 case (RSL_ALG_ID_A5_7) { return '110'B; }
1881 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1883 /* Make compiler happy by calling mtc.stop here. It is already
1884 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001885 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001886 }
1887 }
1888}
1889
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001890/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1891private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1892 var GsmFrameNumber fn;
1893 timer T := 8.0;
1894
1895 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1896 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1897
1898 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1899 /* Send the actual RACH */
1900 fn := f_L1CTL_RACH(L1CTL, ra);
1901
1902 T.start;
1903 alt {
1904 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1905 [] T.timeout {
1906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1907 }
1908 }
1909 T.stop
1910 return fn;
1911}
Harald Weltee613f962018-04-18 22:38:16 +02001912
Harald Welte70767382018-02-21 12:16:40 +01001913/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001914private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001915 var GsmFrameNumber fn;
1916 var ImmediateAssignment imm_ass;
1917 var integer ra := 23;
1918
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001919 /* Send RACH request and wait for ChanReq */
1920 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001921
1922 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001923 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001924
1925 /* Send IMM.ASS via CCHAN */
1926 var ChannelDescription ch_desc := {
1927 chan_nr := g_pars.chan_nr,
1928 tsc := 7,
1929 h := false,
1930 arfcn := mp_trx0_arfcn,
1931 maio_hsn := omit
1932 };
1933 var MobileAllocation ma := {
1934 len := 0,
1935 ma := ''B
1936 };
1937 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1938 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1939
1940 /* receive IMM.ASS on MS side */
1941 var ImmediateAssignment ia_um;
1942 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1943 /* enable dedicated mode */
1944 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001945 /* enable encryption, if requested */
1946 if (encr_enable) {
1947 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1948 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1949 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001950
1951 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001952}
1953
1954/* establish DChan, verify existance + contents of measurement reports */
1955function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001956 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001957 RSL.clear;
1958
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001959 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001960 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001961 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001962 }
Harald Welte70767382018-02-21 12:16:40 +01001963
1964 f_est_dchan();
1965
1966 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1967 * RSL measurement reports on Abis side */
1968 timer T := 8.0;
1969 T.start;
1970 alt {
1971 [] as_l1_sacch();
1972 [] as_meas_res();
1973 [] as_l1_dcch();
1974 [] L1CTL.receive { repeat; }
1975 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001976 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001977 * of any earlier errors, so if we reach this timeout, we're good */
1978 setverdict(pass);
1979 }
1980 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001982 }
1983 }
1984 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001985 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001986}
Harald Welte0472ab42018-03-12 15:02:26 +01001987
Eric Wildae8f2622019-06-18 17:05:11 +02001988function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
1989 timer T := 8.0;
1990 T.start;
1991 var RSL_Message rsl;
1992 alt {
1993 [] as_l1_sacch();
1994 [] L1CTL.receive { repeat; }
1995 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
1996 if (rsl.ies[3].body.bs_power.power_level == level) {
1997 setverdict(pass)
1998 } else {
1999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2000 }
2001 }
2002 [] T.timeout {
2003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2004 }
2005 }
2006}
2007
2008/* see if the rsl meas res contains our expeced bs power level
2009bs power set during assignment */
2010function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2011 f_l1_tune(L1CTL);
2012 RSL.clear;
2013
2014 if (mp_bts_trxc_port != -1) {
2015 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2016 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2017 }
2018
2019 var uint5_t pwr_var := 1;
2020 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2021 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2022
2023 f_est_dchan(more_ies :={valueof(pwr)});
2024
2025 f_check_meas_bs_power_level(pwr_var);
2026
2027 f_rsl_chan_deact();
2028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2029}
2030
2031/* see if the rsl meas res contains our expeced bs power level
2032bs power set after assignment */
2033function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2034 f_l1_tune(L1CTL);
2035 RSL.clear;
2036
2037 if (mp_bts_trxc_port != -1) {
2038 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2039 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2040 }
2041
2042 var uint5_t pwr_var := 1;
2043 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2044
2045 f_est_dchan();
2046
2047 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2048
2049 f_check_meas_bs_power_level(pwr_var);
2050
2051 f_rsl_chan_deact();
2052 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2053}
2054
2055testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2056 var ConnHdlr vc_conn;
2057 var ConnHdlrPars pars;
2058 f_init();
2059 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2060 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2061 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2062 pcu_comp := false, trxc_comp := true);
2063 vc_conn.done;
2064 }
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066}
2067
2068testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2069 var ConnHdlr vc_conn;
2070 var ConnHdlrPars pars;
2071 f_init();
2072 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2073 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2074 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2075 pcu_comp := false, trxc_comp := true);
2076 vc_conn.done;
2077 }
2078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2079}
2080
Eric Wild61edb7e2019-06-03 12:38:31 +02002081/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2082second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2083These power levels are valid for all bands and require no special handling */
2084function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2085 var uint5_t pwr_var := 7;
2086 var L1ctlDlMessage l1_dl;
2087
2088 f_trxc_fake_rssi(rxlev2dbm(10));
2089 f_l1_tune(L1CTL);
2090 RSL.clear;
2091
2092 var RSL_IE_List addl_ies;
2093 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2094
2095 addl_ies := {
2096 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2097 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2098 };
2099
2100 /* establish with power parameters */
2101 f_est_dchan(more_ies := addl_ies);
2102
2103 /* set a high value to ensure L1 power control level increases */
2104 f_trxc_fake_rssi(rxlev2dbm(20));
2105
2106 timer T2 := 6.0;
2107 T2.start;
2108 alt {
2109 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002110 /* Update sent MS power to follow what BTS requests */
2111 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2112 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002113 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002114 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002115 T2.stop;
2116 }
2117 [] L1CTL.receive { repeat; }
2118 [] T2.timeout {
2119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2120 "Power Level in L1 header has not increased sufficiently");
2121 }
2122 }
2123
2124 /* set a low value to ensure L1 power control level decreases */
2125 f_trxc_fake_rssi(rxlev2dbm(0));
2126
2127 timer T4 := 6.0;
2128 T4.start;
2129 alt {
2130 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002131 /* Update sent MS power to follow what BTS requests */
2132 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2133 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002134 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002135 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002136 T4.stop;
2137 setverdict(pass, "Power level in L1 decreased/increased as expected");
2138 }
2139 [] L1CTL.receive { repeat; }
2140 [] T4.timeout {
2141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2142 "Power Level in L1 header has not decreased sufficiently");
2143 }
2144 }
2145
2146 f_rsl_chan_deact();
2147 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2148
2149}
2150
2151/* check that we do not exceed the max power */
2152function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2153 var uint5_t pwr_var := 7;
2154 var L1ctlDlMessage l1_dl;
2155
2156 /* set a low value to ensure power increases */
2157 f_trxc_fake_rssi(rxlev2dbm(10));
2158 f_l1_tune(L1CTL);
2159 RSL.clear;
2160
2161 var RSL_IE_List addl_ies;
2162 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2163
2164 addl_ies := {
2165 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2166 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2167 };
2168
2169 /* establish with power parameters */
2170 f_est_dchan(more_ies := addl_ies);
2171
2172 timer T1 := 10.0;
2173 T1.start;
2174 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002175 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2176 /* Update sent MS power to follow what BTS requests */
2177 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2178 repeat;
2179 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002180 [] L1CTL.receive { repeat; }
2181 [] T1.timeout {
2182 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2183 setverdict(fail, "Power level in L1 header should not have changed");
2184 }
2185 }
2186 }
2187
2188 f_rsl_chan_deact();
2189 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2190
2191}
2192
2193/* see if we reach the band max power */
2194function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2195 var L1ctlDlMessage l1_dl;
2196 var uint5_t pwr_var := 15;
2197 var uint5_t pwr_max_var := f_get_max_power_from_band();
2198
2199 /* set a low value to ensure power increases */
2200 f_trxc_fake_rssi(rxlev2dbm(10));
2201 f_l1_tune(L1CTL);
2202 RSL.clear;
2203
2204 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2205 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2206
2207 /* establish with fixed power level */
2208 f_est_dchan(more_ies :={valueof(pwr)});
2209
2210 /* check our initial power level */
2211 f_wait_for_l1_power_level(pwr_var);
2212
2213 /* update power param to enable power loop
2214 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2215 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2216
2217 /* wait, then check that our power level was reduced */
2218 timer T1 := 10.0;
2219 T1.start;
2220 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002221 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2222 /* Update sent MS power to follow what BTS requests */
2223 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2224 repeat;
2225 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002226 [] L1CTL.receive { repeat; }
2227 [] T1.timeout {
2228 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2229 if( f_power_level_is_highest_dbm(rcv) ){
2230 setverdict(pass, "Power level in L1 header reduced as expected");
2231 } else {
2232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2233 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2234 }
2235 }
2236 }
2237
2238 f_rsl_chan_deact();
2239 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2240
2241}
2242
2243/* see if we reach the band min power */
2244function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2245 var L1ctlDlMessage l1_dl;
2246
2247 /* set a high value to ensure power decreases */
2248 f_trxc_fake_rssi(rxlev2dbm(50));
2249 f_l1_tune(L1CTL);
2250 RSL.clear;
2251
2252 var uint5_t pwr_var := 5;
2253 var uint5_t pwr_target_val := 15;
2254
2255 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2256 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2257
2258 /* establish with fixed power level */
2259 f_est_dchan(more_ies :={valueof(pwr)});
2260
2261 /* check our initial power level */
2262 f_wait_for_l1_power_level(pwr_var);
2263
2264 /* update power param to enable power loop
2265 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002266 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002267
2268 /* wait, then check that our power level was increased */
2269 timer T1 := 10.0;
2270 T1.start;
2271 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002272 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2273 /* Update sent MS power to follow what BTS requests */
2274 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2275 repeat;
2276 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002277 [] L1CTL.receive { repeat; }
2278 [] T1.timeout {
2279 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2280 setverdict(pass, "Power level in L1 header increased to lowest power value");
2281 } else {
2282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2283 "Power level in L1 header NOT increased to lowest power value");
2284 }
2285 }
2286 }
2287
2288 f_rsl_chan_deact();
2289 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2290
2291}
2292
Eric Wild095024b2019-06-17 15:08:57 +02002293/* see if we change the power level without receiving power parameters, which should not happen
2294rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002295function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2296 var L1ctlDlMessage l1_dl;
2297
2298 /* set a high value to ensure power decreases */
2299 f_trxc_fake_rssi(rxlev2dbm(50));
2300 f_l1_tune(L1CTL);
2301 RSL.clear;
2302
2303 var uint5_t pwr_var := 5;
2304
2305 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2306 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2307
2308 /* establish with fixed power level */
2309 f_est_dchan(more_ies :={valueof(pwr)});
2310
2311 /* check our initial power level */
2312 f_wait_for_l1_power_level(pwr_var);
2313
2314 /* wait, then check that our power level did not change */
2315 timer T1 := 10.0;
2316 T1.start;
2317 alt {
2318 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2319 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2321 "BS power control should not be active unless we receive a power parameters IE!");
2322 }
2323 repeat;
2324 }
2325 [] L1CTL.receive { repeat; }
2326 [] T1.timeout { setverdict(pass); }
2327 }
2328
2329 f_rsl_chan_deact();
2330 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2331
2332}
2333
Eric Wild095024b2019-06-17 15:08:57 +02002334/* see if we change the power level without receiving power parameters, which should not happen
2335ms power control WITHOUT power parameters */
2336function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2337 var L1ctlDlMessage l1_dl;
2338
2339 /* set a high value to ensure power decreases */
2340 f_trxc_fake_rssi(rxlev2dbm(50));
2341 f_l1_tune(L1CTL);
2342 RSL.clear;
2343
2344 var uint5_t pwr_var := 5;
2345
2346 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2347 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2348
2349 /* establish with fixed power level */
2350 f_est_dchan(more_ies :={valueof(pwr)});
2351
2352 /* check our initial power level */
2353 f_wait_for_l1_power_level(pwr_var);
2354
2355 /* pwr control without power params IE, should NOT activate MS power control*/
2356 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2357
2358 /* wait, then check that our power level did not change */
2359 timer T1 := 10.0;
2360 T1.start;
2361 alt {
2362 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2363 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2365 "BS power control should not be active unless we receive a power parameters IE!");
2366 }
2367 repeat;
2368 }
2369 [] L1CTL.receive { repeat; }
2370 [] T1.timeout { setverdict(pass); }
2371 }
2372
2373 f_rsl_chan_deact();
2374 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2375
2376}
2377
Eric Wild61edb7e2019-06-03 12:38:31 +02002378function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2379 var L1ctlDlMessage l1_dl;
2380 timer T0 := 10.0;
2381 T0.start;
2382 alt {
2383 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2384 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2386 "Power level in L1 header != signaled (RSL) power level.");
2387 }
2388 }
2389 [] L1CTL.receive { repeat; }
2390 [] T0.timeout {
2391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2392 "Timeout waiting for initial power level");
2393 }
2394 }
2395 T0.stop;
2396}
2397
2398private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2399 var IntegerRecord min_dbm_level;
2400 var IntegerRecord max_dbm_level;
2401 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2402
2403 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2404 if (min_dbm_level[i] == level) {
2405 return true;
2406 }
2407 }
2408 return false;
2409}
2410
2411private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2412 var IntegerRecord min_dbm_level;
2413 var IntegerRecord max_dbm_level;
2414 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2415
2416 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2417 if (max_dbm_level[i] == level) {
2418 return true;
2419 }
2420 }
2421 return false;
2422}
2423
2424private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2425 var IntegerRecord min_dbm_level;
2426 var IntegerRecord max_dbm_level;
2427 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2428 return max_dbm_level[0];
2429}
2430
2431type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2432template charstring BtsBand_allGSM:= pattern "GSM???";
2433private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2434 // 45.005 4.1.1
2435 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2436 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2437 2, 1, 0};
2438 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2439 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2440 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2441 var IntegerRecord rv;
2442
2443 select(band){
2444 case (BtsBand_allGSM){
2445 rv := gsm_power;
2446 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2447 max_dbm_level := {2, 1, 0};
2448 }
2449 case("DCS1800"){
2450 rv := dcs_power;
2451 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2452 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2453 }
2454 case("PCS1900"){
2455 rv := pcs_power;
2456 min_dbm_level := {15};
2457 max_dbm_level := {30};
2458 }
2459 }
2460
2461 return rv;
2462}
2463
2464private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2465 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2466}
2467
2468testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2469 var ConnHdlr vc_conn;
2470 var ConnHdlrPars pars;
2471 f_init();
2472 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2473 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2474 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2475 pars.bts0_band := f_vty_get_bts0_band();
2476 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2477 vc_conn.done;
2478 }
2479 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2481}
2482
2483testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2484 var ConnHdlr vc_conn;
2485 var ConnHdlrPars pars;
2486 f_init();
2487 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2488 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2489 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2490 pars.bts0_band := f_vty_get_bts0_band();
2491 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2492 vc_conn.done;
2493 }
2494 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2496}
2497
2498testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2499 var ConnHdlr vc_conn;
2500 var ConnHdlrPars pars;
2501 f_init();
2502 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2503 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2504 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2505 pars.bts0_band := f_vty_get_bts0_band();
2506 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2507 vc_conn.done;
2508 }
2509 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2511}
2512
2513testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2514 var ConnHdlr vc_conn;
2515 var ConnHdlrPars pars;
2516 f_init();
2517 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2518 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2519 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2520 pars.bts0_band := f_vty_get_bts0_band();
2521 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2522 vc_conn.done;
2523 }
2524 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2526}
2527
Eric Wild280ccb82019-06-17 11:11:52 +02002528testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2529 var ConnHdlr vc_conn;
2530 var ConnHdlrPars pars;
2531 f_init();
2532 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2533 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2534 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2535 pars.bts0_band := f_vty_get_bts0_band();
2536 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2537 vc_conn.done;
2538 }
2539 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2541}
2542
Eric Wild095024b2019-06-17 15:08:57 +02002543testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2544 var ConnHdlr vc_conn;
2545 var ConnHdlrPars pars;
2546 f_init();
2547 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2548 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2549 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2550 pars.bts0_band := f_vty_get_bts0_band();
2551 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2552 vc_conn.done;
2553 }
2554 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2556}
2557
Harald Welte70767382018-02-21 12:16:40 +01002558testcase TC_meas_res_sign_tchf() runs on test_CT {
2559 var ConnHdlr vc_conn;
2560 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002561 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002562 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2563 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002564 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2565 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002566 vc_conn.done;
2567 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002569}
2570testcase TC_meas_res_sign_tchh() runs on test_CT {
2571 var ConnHdlr vc_conn;
2572 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002573 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002574 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2575 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002576 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2577 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002578 vc_conn.done;
2579 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002581}
2582testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2583 var ConnHdlr vc_conn;
2584 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002585 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002586 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2587 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002588 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2589 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002590 vc_conn.done;
2591 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002593}
2594testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2595 var ConnHdlr vc_conn;
2596 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002597 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002598 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2599 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002600 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2601 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002602 vc_conn.done;
2603 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002605}
Harald Welte685d5982018-02-27 20:42:05 +01002606testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2607 var ConnHdlr vc_conn;
2608 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002609 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002610 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2611 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2612 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2613 pars.l1_pars.toa256_enabled := true;
2614 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2615 vc_conn.done;
2616 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002618}
2619
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002620/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2621 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2622function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2623 var L1ctlDlMessage l1_dl;
2624 var RSL_IE_MS_Power ms_power;
2625 var RSL_Message rsl;
2626 var uint5_t power_level := 0;
2627
2628 f_l1_tune(L1CTL);
2629 RSL.clear;
2630
2631 f_est_dchan();
2632
2633 ms_power.reserved := 0;
2634 ms_power.fpc_epc := false;
2635
2636 /* Send the first power control command. This will disable any BTS/TRX
2637 * internal power control and switch the MS (which is not in scope of
2638 * this test) to a constant power level. We start with a power level
2639 * of 0 */
2640 ms_power.power_level := power_level;
2641 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2642 RSL.send(rsl);
2643
2644 alt {
2645
2646 /* Pick all SACCH blocks for checking */
2647 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2648
2649 /* The first byte of the L1 header contains the power level.
2650 * The reserved bits and the fpc bit is set to 0, so we may
2651 * compare directly. */
2652 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2653 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2654 }
2655
2656 /* Signal a new power level via RSL for the next turn. */
2657 if (power_level < 31) {
2658 power_level := power_level + 1;
2659 ms_power.power_level := power_level;
2660 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2661 RSL.send(rsl);
2662 repeat;
2663 }
2664
2665 }
2666
2667 /* Ignore all other blocks */
2668 [] L1CTL.receive { repeat; }
2669
2670 }
2671
2672 f_rsl_chan_deact();
2673 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2674
2675 setverdict(pass);
2676}
2677
2678testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2679 var ConnHdlr vc_conn;
2680 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002681 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002682
2683 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2684 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2685 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2686 vc_conn.done;
2687 }
2688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2689}
Harald Welte70767382018-02-21 12:16:40 +01002690
Eric Wild6833cc92019-05-23 19:34:44 +02002691/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2692TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2693function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2694 var L1ctlDlMessage l1_dl;
2695 var uint5_t ta_to_test := 16;
2696
2697
2698 f_l1_tune(L1CTL);
2699 RSL.clear;
2700
2701 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002702 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002703
2704 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2705
2706
2707 alt {
2708
2709 /* Pick all SACCH blocks for checking */
2710 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2711
2712 /* The second byte of the L1 header contains the TA. */
2713 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2714 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2715 }
2716
2717 }
2718
2719 /* Ignore all other blocks */
2720 [] L1CTL.receive { repeat; }
2721
2722 }
2723
2724 f_rsl_chan_deact();
2725 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2726
2727 setverdict(pass);
2728}
2729
2730testcase TC_rsl_chan_initial_ta() runs on test_CT {
2731 var ConnHdlr vc_conn;
2732 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002733 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002734 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002735 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2736 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002737 vc_conn.done;
2738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2739}
2740
Eric Wilde57e1a62019-05-28 13:30:55 +02002741/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2742function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2743 var L1ctlDlMessage l1_dl;
2744 var uint5_t ms_power_level := 7;
2745
2746 var RSL_IE_MS_Power ms_power;
2747 ms_power.reserved := 0;
2748 ms_power.fpc_epc := false;
2749 ms_power.power_level := ms_power_level;
2750
2751 f_l1_tune(L1CTL);
2752 RSL.clear;
2753
2754 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2755
2756 timer T := 1.0;
2757 T.start;
2758 alt {
2759 /* Pick all SACCH blocks for checking */
2760 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2761 /* The first byte of the L1 header contains the power level.. */
2762 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2763 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2764 }
2765 }
2766 /* Ignore all other blocks */
2767 [] L1CTL.receive { repeat; }
2768 [] T.timeout {
2769 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2770 }
2771 }
2772
2773 f_rsl_chan_deact();
2774 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2775 setverdict(pass);
2776}
2777
2778testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2779 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2780 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2781}
2782
Harald Welte0472ab42018-03-12 15:02:26 +01002783/* 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 +01002784private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002785 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002786 RSL.clear;
2787
2788 f_est_dchan();
2789 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002790 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002791
2792 timer T := 40.0;
2793 T.start;
2794 alt {
2795 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2796 setverdict(pass)
2797 }
2798 [] RSL.receive { repeat };
2799 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002801 }
2802 }
2803 f_rsl_chan_deact();
2804}
2805testcase TC_conn_fail_crit() runs on test_CT {
2806 var ConnHdlr vc_conn;
2807 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002808 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002809 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2810 pars.t_guard := 60.0;
2811 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2812 vc_conn.done;
2813}
2814
Harald Welte93640c62018-02-25 16:59:33 +01002815/***********************************************************************
2816 * Paging
2817 ***********************************************************************/
2818
Harald Welte68e495b2018-02-25 00:05:57 +01002819function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2820 if (tmsi == 'FFFFFFFF'O) {
2821 return true;
2822 } else {
2823 return false;
2824 }
2825}
Harald Welte70767382018-02-21 12:16:40 +01002826
Philipp Maier82cb0b12018-08-31 14:41:39 +02002827type record allowedFn { integer frame_nr }
2828template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2829template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2830template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2831template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2832template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2833template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2834template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2835template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2836function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2837{
2838 var integer frame_nr_51;
2839 frame_nr_51 := frame_nr mod 51
2840
2841 var allowedFn fn_check;
2842 fn_check.frame_nr := frame_nr_51;
2843
2844 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002846 return;
2847 }
2848
2849 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2850 return;
2851 }
2852 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2853 return;
2854 }
2855 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2856 return;
2857 }
2858 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2859 return;
2860 }
2861 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2862 return;
2863 }
2864 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2865 return;
2866 }
2867 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2868 return;
2869 }
2870 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2871 return;
2872 }
2873
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002875 return;
2876}
2877
2878altstep 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 +01002879runs on test_CT {
2880 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002881 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002882 repeat;
2883 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002884 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002885 var octetstring without_plen :=
2886 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2887 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002888
2889 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2890
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07002891 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
2892 /* Ignore empty RR Paging Request (PCH filling) messages.
2893 * TODO: does it make sense to count them? */
2894 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002895 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2896 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002897 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002898 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2899 }
2900 } else if (match(rr, tr_PAGING_REQ2)) {
2901 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2902 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2903 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2904 }
2905 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2906 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2907 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002908 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002909 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2910 }
2911 } else if (match(rr, tr_PAGING_REQ3)) {
2912 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2913 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2914 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2915 }
2916 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2917 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2918 }
2919 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2920 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2921 }
2922 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2923 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2924 }
2925 }
2926 repeat;
2927 }
2928}
2929
2930type record PagingTestCfg {
2931 boolean combined_ccch,
2932 integer bs_ag_blks_res,
2933 float load_factor,
2934 boolean exp_load_ind,
2935 boolean exp_overload,
2936 boolean use_tmsi
2937}
2938
2939type record PagingTestState {
2940 integer num_paging_sent,
2941 integer num_paging_rcv_msgs,
2942 integer num_paging_rcv_ids,
2943 integer num_overload
2944}
2945
2946/* receive + ignore RSL RF RES IND */
2947altstep as_rsl_res_ind() runs on test_CT {
2948 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2949 repeat;
2950 }
2951}
2952
2953/* Helper function for paging related testing */
2954private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002955 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002956 f_init_l1ctl();
2957 f_l1_tune(L1CTL);
2958
2959 var PagingTestState st := {
2960 num_paging_sent := 0,
2961 num_paging_rcv_msgs := 0,
2962 num_paging_rcv_ids := 0,
2963 num_overload := 0
2964 };
2965
2966 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2967 var float max_pch_imsi_per_sec;
2968 if (cfg.use_tmsi) {
2969 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2970 } else {
2971 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2972 }
2973 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2974 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002975 var float time_total := 20.0;
2976 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2977 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002978
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002979 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2980 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002981
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002982 timer T_itv := 0.0;
2983 T_itv.start;
2984 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002985 alt {
2986 /* check for presence of CCCH LOAD IND (paging load) */
2987 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2988 st.num_overload := st.num_overload + 1;
2989 repeat;
2990 }
2991 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002993 }
2994 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2995 log("Rx LOAD_IND");
2996 /* FIXME: analyze/verify interval + contents */
2997 repeat;
2998 }
2999 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003000 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003001 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003002 [] T_itv.timeout {
3003 /* Send paging cmds based on elapsed time */
3004 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3005 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003006 var MobileIdentityV mi;
3007
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003008 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003009 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003010 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003011 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003012 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003013 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003014
3015 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003016 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi, st.num_paging_sent mod 4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003017
3018 st.num_paging_sent := st.num_paging_sent + 1;
3019 }
3020 if (st.num_paging_sent < pkt_total) {
3021 /* Wait for interval to next PAGING COMMAND */
3022 var float time_now := T_total.read;
3023 var float next_sched := int2float(st.num_paging_sent)*interval;
3024 if (next_sched > time_now) {
3025 T_itv.start(next_sched - time_now);
3026 } else {
3027 T_itv.start(0.0);
3028 }
3029 } else {
3030 /* We are done, no need to keep counting */
3031 T_total.stop;
3032 }
3033 }
3034 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003035 [] as_rsl_res_ind();
3036 }
3037 }
3038
3039 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3040 timer T_wait := 18.0;
3041 T_wait.start;
3042 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003043 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003044 [] L1CTL.receive { repeat; }
3045 /* 65535 == empty paging queue, we can terminate*/
3046 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3047 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
3048 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003050 }
3051 [] as_rsl_res_ind();
3052 }
3053
3054 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3055 " rcvd_ids=", st.num_paging_rcv_ids);
3056 return st;
3057}
3058
3059/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3060 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3061 * - that CCCH LOAD IND (PCH) are being generated
3062 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3063testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003064 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003065 var PagingTestCfg cfg := {
3066 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003067 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003068 load_factor := 0.8,
3069 exp_load_ind := true,
3070 exp_overload := false,
3071 use_tmsi := false
3072 };
3073 var PagingTestState st := f_TC_paging(cfg);
3074 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003075 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3076 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003077 } else {
3078 setverdict(pass);
3079 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003081}
3082
3083/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3084 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3085 * - that CCCH LOAD IND (PCH) are being generated
3086 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3087testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003088 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003089 var PagingTestCfg cfg := {
3090 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003091 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003092 load_factor := 0.8,
3093 exp_load_ind := true,
3094 exp_overload := false,
3095 use_tmsi := true
3096 };
3097 var PagingTestState st := f_TC_paging(cfg);
3098 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3100 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003101 } else {
3102 setverdict(pass);
3103 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003105}
3106
3107/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3108 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3109 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3110 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3111testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003112 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003113 var PagingTestCfg cfg := {
3114 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003115 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003116 load_factor := 2.0,
3117 exp_load_ind := true,
3118 exp_overload := true,
3119 use_tmsi := false
3120 };
3121 var PagingTestState st := f_TC_paging(cfg);
3122 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3123 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003124 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003125 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003126 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 +01003127 } else {
3128 setverdict(pass);
3129 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003130 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003131}
3132
3133/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3134 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3135 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3136 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3137testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003138 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003139 var PagingTestCfg cfg := {
3140 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003141 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003142 load_factor := 2.0,
3143 exp_load_ind := true,
3144 exp_overload := true,
3145 use_tmsi := true
3146 };
3147 var PagingTestState st := f_TC_paging(cfg);
3148 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3149 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003150 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003151 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003152 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 +01003153 } else {
3154 setverdict(pass);
3155 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003157}
3158
3159
Harald Welte93640c62018-02-25 16:59:33 +01003160/***********************************************************************
3161 * Immediate Assignment / AGCH
3162 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02003163const MobileAllocation c_MA_null := {
3164 len := 0,
3165 ma := ''B
3166}
Harald Welte93640c62018-02-25 16:59:33 +01003167
Harald Weltee8d750e2018-06-10 21:41:35 +02003168template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3169 uint12_t arfcn := 871) := {
3170 chan_nr := chan_nr,
3171 tsc := tsc,
3172 h := false,
3173 arfcn := arfcn,
3174 maio_hsn := omit
3175}
3176
3177private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3178 return int2str(num_tx) & " sent, "
3179 & int2str(num_rx) & " received, "
3180 & int2str(num_del) & " deleted";
3181}
3182
3183private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3184 var L1ctlDlMessage l1_dl;
3185 timer T := 10.0;
3186 var integer num_tx := 0;
3187 var integer num_rx := 0;
3188 var integer num_del := 0;
3189 var charstring res_str;
3190 var float rx_ratio;
3191
Harald Welte10474062019-05-30 16:48:17 +02003192 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003193 f_init_l1ctl();
3194 f_l1_tune(L1CTL);
3195
3196 for (var integer i := 0; i < num_total; i := i+1) {
3197 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
3198 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3199 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01003200 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003201 num_tx := num_tx+1;
3202 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003203 }
3204 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003205 T.start;
3206 alt {
3207 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
3208 num_del := num_del+1;
3209 repeat;
3210 }
3211 [] RSL_CCHAN.receive {
3212 repeat;
3213 }
3214 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3215 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3216 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3217 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3218 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003219 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003220 } else {
3221 num_rx := num_rx+1;
3222 }
3223 repeat;
3224 }
3225 [] L1CTL.receive { repeat; }
3226 [] T.timeout { }
3227 }
3228 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3229 log("AGCH test: " & res_str);
3230 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003232 }
3233 rx_ratio := int2float(num_rx) / int2float(num_tx);
3234 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003235 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 +02003236 } else {
3237 setverdict(pass);
3238 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003240}
3241
Harald Weltee8d750e2018-06-10 21:41:35 +02003242/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3243testcase TC_imm_ass_1000_20ms() runs on test_CT {
3244 f_TC_imm_ass(1000, 0.02, 0.25);
3245}
3246
3247/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3248testcase TC_imm_ass_200_0ms() runs on test_CT {
3249 f_TC_imm_ass(200, 0.0, 0.05);
3250}
3251
3252/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3253testcase TC_imm_ass_200_76ms() runs on test_CT {
3254 f_TC_imm_ass(150, 0.076, 1.00);
3255}
3256
3257
3258
Harald Welte48494ca2018-02-25 16:59:50 +01003259/***********************************************************************
3260 * BCCH
3261 ***********************************************************************/
3262
3263/* tuple of Frame Number + decoded SI */
3264type record SystemInformationFn {
3265 GsmFrameNumber frame_number,
3266 SystemInformation si
3267}
3268
3269/* an arbitrary-length vector of decoded SI + gsmtap header */
3270type record of SystemInformationFn SystemInformationVector;
3271
3272/* an array of SI-vectors indexed by TC value */
3273type SystemInformationVector SystemInformationVectorPerTc[8];
3274
3275/* determine if a given SI vector contains given SI type at least once */
3276function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3277 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3278 var integer fn_mod51 := arr[i].frame_number mod 51;
3279 if (not bcch_ext and fn_mod51 == 2 or
3280 bcch_ext and fn_mod51 == 6) {
3281 if (arr[i].si.header.message_type == key) {
3282 return true;
3283 }
3284 }
3285 }
3286 return false;
3287}
3288
3289/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3290function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3291 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003293 }
3294}
3295
3296/* check if a given SI vector contains given SI type at least once on any TC */
3297function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3298 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3299 if (f_si_vecslot_contains(arr[tc], key) or
3300 f_si_vecslot_contains(arr[tc], key, true)) {
3301 return true;
3302 }
3303 }
3304 return false;
3305}
3306
3307/* determine if a given SI vector contains given SI type at least N of M times */
3308function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3309 var integer count := 0;
3310 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003312 }
3313 for (var integer i:= 0; i < m; i := i + 1) {
3314 var integer fn_mod51 := arr[i].frame_number mod 51;
3315 if (not bcch_ext and fn_mod51 == 2 or
3316 bcch_ext and fn_mod51 == 6) {
3317 if (arr[i].si.header.message_type == key) {
3318 count := count + 1;
3319 }
3320 }
3321 }
3322 if (count >= n) {
3323 return true;
3324 } else {
3325 return false;
3326 }
3327}
3328
3329/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3330function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3331 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003333 }
3334}
3335
3336/* determine if a given SI vector contains given SI type at least once */
3337function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3338 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3339 var integer fn_mod51 := arr[i].frame_number mod 51;
3340 if (not bcch_ext and fn_mod51 == 2 or
3341 bcch_ext and fn_mod51 == 6) {
3342 if (arr[i].si.header.message_type != key) {
3343 return false;
3344 }
3345 }
3346 }
3347 return true;
3348}
3349
3350/* ensure a given TC slot of the SI vector contains only given SI type */
3351function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3352 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003354 }
3355}
3356
3357/* SI configuration of cell, against which we validate actual SI messages */
3358type set SystemInformationConfig {
3359 boolean bcch_extended,
3360 boolean si1_present,
3361 boolean si2bis_present,
3362 boolean si2ter_present,
3363 boolean si2quater_present,
3364 boolean si7_present,
3365 boolean si8_present,
3366 boolean si9_present,
3367 boolean si13_present,
3368 boolean si13alt_present,
3369 boolean si15_present,
3370 boolean si16_present,
3371 boolean si17_present,
3372 boolean si2n_present,
3373 boolean si21_present,
3374 boolean si22_present
3375}
3376
3377/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3378function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3379 var integer i;
3380 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3381 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003383 }
3384 }
3385 if (cfg.si1_present) {
3386 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3387 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3388 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3389 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3390 /* make sure *ALL* contain SI1 */
3391 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3392 }
3393 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3394 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3395 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3396 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3397 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3398 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3399
3400 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3401 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3402 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3403 * consecutive occurrences of TC = 4. */
3404 if (cfg.si2bis_present and not cfg.si2ter_present) {
3405 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3406 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3407 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3408 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3409 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3410 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3411 }
3412
3413 if (cfg.si7_present or cfg.si8_present) {
3414 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3415 * if System Information type 4 does not contain all information needed for cell
3416 * selection and reselection. */
3417 if (not cfg.bcch_extended) {
3418 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3419 }
3420 if (cfg.si7_present) {
3421 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3422 }
3423 if (cfg.si8_present) {
3424 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3425 }
3426 }
3427
3428 if (cfg.si2quater_present) {
3429 /* iii) System information type 2 quater is sent if needed, as determined by the system
3430 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3431 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3432 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3433 * within any of 4 consecutive occurrences of TC = 5. */
3434 if (not (cfg.bcch_extended)) {
3435 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3436 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3437 } else {
3438 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3439 }
3440 } else {
3441 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3442 }
3443 }
3444 if (cfg.si9_present) {
3445 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3446 * in system information type 3 as defined in 3GPP TS 44.018. */
3447 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3448 }
3449 if (cfg.si13_present) {
3450 /* vii) System Information type 13 is only related to the GPRS service. System Information
3451 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3452 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3453 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3454 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3455 * within any of 4 consecutive occurrences of TC=4. */
3456 if (not cfg.bcch_extended) {
3457 log("not-bccch-extended");
3458 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3459 } else {
3460 log("bccch-extended");
3461 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3462 }
3463 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003465 }
3466 }
3467 if (cfg.si16_present or cfg.si17_present) {
3468 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3469 * should not be sent in a cell where network sharing is used (see rule xv). */
3470 if (cfg.si22_present) {
3471 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3472 }
3473 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003475 }
3476 if (not cfg.bcch_extended) {
3477 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3478 }
3479 if (cfg.si16_present) {
3480 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3481 }
3482 if (cfg.si17_present) {
3483 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3484 }
3485 }
3486
3487 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3488 * broadcast information. The frequency with which they are sent is determined by the
3489 * system operator. System Information type 9 identifies the scheduling of System
3490 * Information type 18 and 20 messages. */
3491
3492 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3493 * Information Type 19 is present, then its scheduling shall be indicated in System
3494 * Information Type 9. */
3495
3496 if (cfg.si15_present) {
3497 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3498 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3499 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3500 * 4 consecutive occurrences of TC = 1. */
3501 if (not cfg.bcch_extended) {
3502 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3503 } else {
3504 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3505 }
3506 }
3507 if (cfg.si13alt_present) {
3508 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3509 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3510 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3511 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3512 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3513 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3514 * of TC = 4. */
3515 if (cfg.si13_present) {
3516 testcase.stop("Error: Cannot have SI13alt and SI13");
3517 }
3518 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003520 }
3521 if (not cfg.bcch_extended) {
3522 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3523 } else {
3524 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3525 }
3526 }
3527 if (cfg.si2n_present) {
3528 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3529 * as determined by the system operator. In the case that the message is sent on the
3530 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3531 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3532 * consecutive occurrences of TC = 4. */
3533 if (not cfg.bcch_extended) {
3534 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3535 } else {
3536 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3537 }
3538 }
3539 if (cfg.si21_present) {
3540 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3541 * determined by the system operator. If Extended Access Barring is in use in the cell
3542 * then this message is sent at least once within any of 4 consecutive occurrences of
3543 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3544 * cell then this message shall only be sent on BCCH Ext. */
3545 if (not cfg.bcch_extended) {
3546 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3547 } else {
3548 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3549 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003551 }
3552 }
3553 }
3554 if (cfg.si22_present) {
3555 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3556 * should not be sent in a cell where SoLSA is used (see rule viii). System
3557 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3558 * =2 and TC=6. */
3559 if (cfg.si16_present or cfg.si17_present) {
3560 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3561 }
3562 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3563 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003565 }
3566 if (not cfg.bcch_extended) {
3567 testcase.stop("Error: SI22 requires BCCH Extd!");
3568 } else {
3569 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3570 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3571 }
3572 }
3573}
3574
3575/* sample Systme Information for specified duration via L1CTL */
3576function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3577 timer T := duration;
3578 var SystemInformationVectorPerTc si_per_tc;
3579 var L1ctlDlMessage l1_dl;
3580
3581 /* initialize all per-TC vectors empty */
3582 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3583 si_per_tc[i] := {};
3584 }
3585
3586 /* flush all previous L1 queued msgs */
3587 pt.clear;
3588
3589 T.start;
3590 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003591 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003592 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3593 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3594 log("Ignoring non-RR SI ", l1_dl);
3595 repeat;
3596 }
3597 var SystemInformationFn sig := {
3598 frame_number := l1_dl.dl_info.frame_nr,
3599 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3600 }
3601 var integer tc := f_gsm_compute_tc(sig.frame_number);
3602 log("SI received at TC=", tc, ": ", sig.si);
3603 /* append to the per-TC bucket */
3604 si_per_tc[tc] := si_per_tc[tc] & { sig };
3605 repeat;
3606 }
3607 [] pt.receive { repeat; }
3608 [] T.timeout { }
3609 }
3610
3611 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3612 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3613 }
3614 log("si_per_tc=", si_per_tc);
3615 return si_per_tc;
3616}
3617
3618/* helper function: Set given SI via RSL + validate scheduling.
3619 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3620function f_TC_si_sched() runs on test_CT {
3621 var SystemInformationVectorPerTc si_per_tc;
3622 f_init_l1ctl();
3623 f_l1_tune(L1CTL);
3624
3625 /* Sample + Validate Scheduling */
3626 si_per_tc := f_l1_sample_si(L1CTL);
3627 f_validate_si_scheduling(si_cfg, si_per_tc);
3628
3629 setverdict(pass);
3630}
3631
3632testcase TC_si_sched_default() runs on test_CT {
3633 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003634 /* 2+3+4 are mandatory and set in f_init() */
3635 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003637}
3638
3639testcase TC_si_sched_1() runs on test_CT {
3640 f_init();
3641 si_cfg.si1_present := true;
3642 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003643 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003645}
3646
3647testcase TC_si_sched_2bis() runs on test_CT {
3648 f_init();
3649 si_cfg.si2bis_present := true;
3650 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3651 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003653}
3654
3655testcase TC_si_sched_2ter() runs on test_CT {
3656 f_init();
3657 si_cfg.si2ter_present := true;
3658 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3659 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003661}
3662
3663testcase TC_si_sched_2ter_2bis() runs on test_CT {
3664 f_init();
3665 si_cfg.si2bis_present := true;
3666 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3667 si_cfg.si2ter_present := true;
3668 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3669 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003671}
3672
3673testcase TC_si_sched_2quater() runs on test_CT {
3674 f_init();
3675 si_cfg.si2quater_present := true;
3676 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3677 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003679}
3680
3681testcase TC_si_sched_13() runs on test_CT {
3682 f_init();
3683 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003684 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003685 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003687}
3688
3689testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3690 f_init();
3691 si_cfg.si2bis_present := true;
3692 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3693 si_cfg.si2ter_present := true;
3694 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3695 si_cfg.si2quater_present := true;
3696 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3697 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003698 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003699 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003701}
3702
3703
Harald Welte68e495b2018-02-25 00:05:57 +01003704testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003705 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003706 /* FIXME: enable / disable individual BCCH info */
3707 //ts_RSL_BCCH_INFO(si_type, info);
3708 /* expect no ERROR REPORT after either of them *
3709 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003711}
3712
Harald Welte93640c62018-02-25 16:59:33 +01003713/***********************************************************************
3714 * Low-Level Protocol Errors / ERROR REPORT
3715 ***********************************************************************/
3716
Harald Welte01d982c2018-02-25 01:31:40 +01003717private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3718 timer T := 5.0;
3719 T.start;
3720 alt {
3721 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3722 setverdict(pass);
3723 }
3724 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003726 }
3727 [] RSL_CCHAN.receive {
3728 repeat;
3729 }
3730 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003732 }
3733 }
3734}
3735
3736/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3737testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003738 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003739 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3740 rsl.ies := omit;
3741 RSL_CCHAN.send(ts_RSL_UD(rsl));
3742
3743 f_exp_err_rep(RSL_ERR_PROTO);
3744}
3745
3746/* Provoke a mandatory IE error and match on ERROR REPORT */
3747testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003748 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003749
3750 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3751 rsl.ies := { rsl.ies[0] };
3752 RSL_CCHAN.send(ts_RSL_UD(rsl));
3753
3754 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3755}
3756
3757/* Provoke an IE content error and match on ERROR REPORT */
3758testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003759 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003760 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3761 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3762 RSL_CCHAN.send(ts_RSL_UD(rsl));
3763
3764 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3765}
3766
Harald Welteee25aae2019-05-19 14:32:37 +02003767/* attempt to activate channel with wrong RSL Message Discriminator IE */
3768function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3769 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3770 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3771 RSL.send(rsl);
3772 f_rslem_unregister(0, g_chan_nr);
3773}
3774testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3775 var ConnHdlr vc_conn;
3776 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3777
Harald Welte10474062019-05-30 16:48:17 +02003778 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003779
3780 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3781 vc_conn.done;
3782 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3783
3784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3785}
3786
3787/* Send messages with wrong message type */
3788function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3789 var template (value) RSL_Message rsl_tx;
3790 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3791 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3792 RSL.send(rsl_tx);
3793 f_rslem_unregister(0, g_chan_nr);
3794}
3795function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3796 var template (value) RSL_Message rsl_tx;
3797 /* we first have to activate the dedicated channel */
3798 f_rsl_chan_act(g_pars.chan_mode);
3799 /* ... to then send an invalid RLL message */
3800 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3801 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3802 RSL.send(rsl_tx);
3803 f_rslem_unregister(0, g_chan_nr);
3804}
3805testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3806 var ConnHdlr vc_conn;
3807 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3808 var template (value) RSL_Message rsl_tx;
3809
Harald Welte10474062019-05-30 16:48:17 +02003810 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003811
3812 /* Common Channel with wrong message type */
3813 RSL_CCHAN.clear;
3814 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3815 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3816 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3817 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3818
3819 /* TRX Management */
3820 RSL_CCHAN.clear;
3821 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3822 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3823 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3824 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3825
3826 /* Dedicated Channel */
3827 RSL_CCHAN.clear;
3828 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3829 vc_conn.done;
3830 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3831
3832 /* RLL */
3833 RSL_CCHAN.clear;
3834 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3835 vc_conn.done;
3836 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3837}
3838
3839/* Send messages in wrong sequence (RLL to an inactive lchan) */
3840function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3841 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3842 f_rslem_unregister(0, g_chan_nr);
3843}
3844testcase TC_err_rep_wrong_sequence() runs on test_CT {
3845 var ConnHdlr vc_conn;
3846 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3847
Harald Welte10474062019-05-30 16:48:17 +02003848 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003849
3850 RSL_CCHAN.clear;
3851 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3852 vc_conn.done;
3853 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3854}
3855
Harald Welte93640c62018-02-25 16:59:33 +01003856/***********************************************************************
3857 * IPA CRCX/MDCX/DLCS media stream handling
3858 ***********************************************************************/
3859
Harald Weltea871a382018-02-25 02:03:14 +01003860/* Send IPA DLCX to inactive lchan */
3861function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003862 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3863 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003864}
3865testcase TC_ipa_dlcx_not_active() runs on test_CT {
3866 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003867 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003868 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3869 vc_conn.done;
3870}
Harald Welte68e495b2018-02-25 00:05:57 +01003871
Harald Weltea3f1df92018-02-25 12:49:55 +01003872/* Send IPA CRCX twice to inactive lchan */
3873function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3874 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3875 "IPA CRCX ACK");
3876 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3877 "IPA CRCX NACK");
3878}
3879testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3880 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003881 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003882 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3883 vc_conn.done;
3884}
3885
3886/* Regular sequence of CRCX/MDCX/DLCX */
3887function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3888 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3889 "IPA CRCX ACK");
3890 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3891 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3892 var uint7_t rtp_pt2 := f_rnd_int(127);
3893 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3894 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3895 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3896 "IPA MDCX ACK");
3897 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3898 "IPA DLCX ACK");
3899}
3900testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3901 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003902 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003903 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3904 vc_conn.done;
3905}
3906
Harald Welte3ae11da2018-02-25 13:36:06 +01003907/* Sequence of CRCX, 2x MDCX, DLCX */
3908function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3909 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3910 "IPA CRCX ACK");
3911 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3912 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3913 var uint7_t rtp_pt2 := f_rnd_int(127);
3914 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3915 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3916 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3917 "IPA MDCX ACK");
3918 /* Second MDCX */
3919 remote_ip := f_rnd_int(c_UINT32_MAX);
3920 remote_port := f_rnd_int(c_UINT16_MAX);
3921 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3922 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3923 "IPA MDCX ACK");
3924 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3925 "IPA DLCX ACK");
3926}
3927testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3928 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003929 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003930 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3931 vc_conn.done;
3932}
3933
Harald Welte9912eb52018-02-25 13:30:15 +01003934/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3935function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3936 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3937 "IPA CRCX NACK");
3938}
3939testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3940 var ConnHdlrPars pars;
3941 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003942 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003943
3944 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3945 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3946 vc_conn.done;
3947
3948 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3949 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3950 vc_conn.done;
3951}
3952
Harald Weltea3f1df92018-02-25 12:49:55 +01003953
Harald Welte883340c2018-02-28 18:59:29 +01003954/***********************************************************************
3955 * PCU Socket related tests
3956 ***********************************************************************/
3957
Harald Welte07bd2d22019-05-25 11:03:30 +02003958/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003959friend 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 +01003960runs on test_CT {
3961 timer T := 3.0;
3962
3963 /* we don't expect any RTS.req before PDCH are active */
3964 T.start;
3965 alt {
3966 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003968 }
3969 [] PCU.receive { repeat; }
3970 [] T.timeout { }
3971 }
3972
3973 /* Send PDCH activate request for known PDCH timeslot */
3974 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3975
3976 /* we now expect RTS.req for this timeslot (only) */
3977 T.start;
3978 alt {
3979 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3980 setverdict(pass);
3981 }
3982 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3983 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003985 }
3986 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003988 }
3989 [] PCU.receive { repeat; }
3990 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003992 }
3993 [not exp_success] T.timeout {
3994 setverdict(pass);
3995 }
3996 }
3997}
3998
Harald Welte07bd2d22019-05-25 11:03:30 +02003999/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004000friend 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 +01004001runs on test_CT {
4002 timer T := 3.0;
4003
4004 /* Send PDCH activate request for known PDCH timeslot */
4005 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4006
4007 PCU.clear;
4008 /* we now expect no RTS.req for this timeslot */
4009 T.start;
4010 alt {
4011 [] 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 +02004012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004013 }
4014 [] PCU.receive { repeat; }
4015 [] T.timeout {
4016 setverdict(pass);
4017 }
4018 }
4019}
4020
Harald Weltead033dc2019-05-25 17:28:16 +02004021friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004022 f_init();
4023 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4024}
4025
Harald Welte883340c2018-02-28 18:59:29 +01004026/* PDCH activation via PCU socket; check for presence of RTS.req */
4027testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004028 f_init_pcu_test();
4029
Harald Welte883340c2018-02-28 18:59:29 +01004030 f_TC_pcu_act_req(0, 0, 7, true);
4031}
4032
4033/* PDCH activation via PCU socket on non-PDCU timeslot */
4034testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004035 f_init_pcu_test();
4036
Harald Welte883340c2018-02-28 18:59:29 +01004037 f_TC_pcu_act_req(0, 0, 1, false);
4038}
4039
4040/* PDCH activation via PCU socket on wrong BTS */
4041testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004042 f_init_pcu_test();
4043
Harald Welte883340c2018-02-28 18:59:29 +01004044 f_TC_pcu_act_req(23, 0, 7, false);
4045}
4046
4047/* PDCH activation via PCU socket on wrong TRX */
4048testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004049 f_init_pcu_test();
4050
Harald Welte883340c2018-02-28 18:59:29 +01004051 f_TC_pcu_act_req(0, 23, 7, false);
4052}
4053
4054/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4055testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004056 f_init_pcu_test();
4057
Harald Welte883340c2018-02-28 18:59:29 +01004058 /* Activate PDCH */
4059 f_TC_pcu_act_req(0, 0, 7, true);
4060 f_sleep(1.0);
4061 /* and De-Activate again */
4062 f_TC_pcu_deact_req(0, 0, 7);
4063}
4064
4065/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4066testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004067 f_init_pcu_test();
4068
Harald Welte883340c2018-02-28 18:59:29 +01004069 f_TC_pcu_deact_req(0, 0, 1);
4070}
4071
4072/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4073testcase TC_pcu_ver_si13() runs on test_CT {
4074 const octetstring si13 := '00010203040506070909'O;
4075 var PCUIF_send_data sd;
4076 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004077 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004078
4079 /* Set SI13 via RSL */
4080 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004081
Harald Welte883340c2018-02-28 18:59:29 +01004082 T.start;
4083 alt {
4084 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4085 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4086 setverdict(pass);
4087 } else {
4088 repeat;
4089 }
4090 }
4091 [] PCU.receive { repeat; }
4092 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004094 }
4095 }
4096}
4097
4098private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4099
4100/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004101friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004102 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4103runs on test_CT
4104{
4105 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4106 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4107}
4108
4109/* 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 +02004110friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4111 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004112runs on test_CT
4113{
4114 var PCUIF_send_data sd;
4115
4116 timer T := 3.0;
4117 T.start;
4118 alt {
4119 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4120 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4121 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4122 sd.data.u.rts_req.fn, sapi, data);
4123 }
4124 [] PCU.receive { repeat; }
4125 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004127 }
4128 }
4129}
4130
4131/* Send DATA.req on invalid BTS */
4132testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004133 var TfiUsfArr tua := f_TfiUsfArrInit();
4134 var octetstring data := '0000'O & f_rnd_octstring(21);
4135
4136 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004137
Harald Welte883340c2018-02-28 18:59:29 +01004138 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004139 f_TfiUsfArrSet(tua, 7, 0);
4140 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4141 f_sleep(1.0);
4142
4143 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004144}
4145
4146/* Send DATA.req on invalid TRX */
4147testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004148 var TfiUsfArr tua := f_TfiUsfArrInit();
4149 var octetstring data := '0000'O & f_rnd_octstring(21);
4150
4151 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004152
Harald Welte883340c2018-02-28 18:59:29 +01004153 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004154 f_TfiUsfArrSet(tua, 7, 0);
4155 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4156 f_sleep(1.0);
4157
4158 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004159}
4160
4161/* Send DATA.req on invalid timeslot */
4162testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004163 var TfiUsfArr tua := f_TfiUsfArrInit();
4164 var octetstring data := '0000'O & f_rnd_octstring(21);
4165
4166 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004167
Harald Welte883340c2018-02-28 18:59:29 +01004168 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004169 f_TfiUsfArrSet(tua, 7, 0);
4170 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4171 f_sleep(1.0);
4172
4173 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004174}
4175
4176/* Send DATA.req on timeslot that hasn't been activated */
4177testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004178 var TfiUsfArr tua := f_TfiUsfArrInit();
4179 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004180
Harald Welte7162a612019-05-26 12:56:09 +02004181 f_virtphy_common();
4182
4183 f_TfiUsfArrSet(tua, 7, 0);
4184 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4185 f_sleep(1.0);
4186
4187 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004188}
4189
Harald Weltead033dc2019-05-25 17:28:16 +02004190private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004191 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4192 boolean wait_rts := true)
4193runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004194 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004195 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004196
4197 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004198 if (wait_rts) {
4199 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4200 } else {
4201 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4202 }
Harald Weltead033dc2019-05-25 17:28:16 +02004203
4204 T.start;
4205 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004206 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004207 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4208 setverdict(pass);
4209 }
Harald Welte7162a612019-05-26 12:56:09 +02004210 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4211 setverdict(fail, "Received unexpected ", rx_dl);
4212 }
Harald Weltead033dc2019-05-25 17:28:16 +02004213 [] L1CTL.receive {
4214 repeat;
4215 }
Harald Welte7162a612019-05-26 12:56:09 +02004216 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004217 setverdict(fail, "Timeout waiting for ", data);
4218 }
Harald Welte7162a612019-05-26 12:56:09 +02004219 [not expect_data] T.timeout {
4220 setverdict(pass);
4221 }
Harald Weltead033dc2019-05-25 17:28:16 +02004222 }
4223}
4224
4225private function f_disable_dynamic_ts() runs on test_CT
4226{
4227 f_init_vty_bsc();
4228 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4229 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4230 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4231 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004232 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004233}
4234
4235private function f_virtphy_common() runs on test_CT {
4236 f_disable_dynamic_ts();
4237 f_init_l1ctl();
4238 f_l1_tune(L1CTL);
4239}
4240
4241testcase TC_pcu_data_req_pdtch() runs on test_CT {
4242 var TfiUsfArr tua := f_TfiUsfArrInit();
4243 var octetstring data := '0000'O & f_rnd_octstring(21);
4244
4245 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004246
Harald Welte883340c2018-02-28 18:59:29 +01004247 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004248 f_TfiUsfArrSet(tua, 7, 0);
4249 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4250 f_sleep(1.0);
4251
4252 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004253}
4254
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004255/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004256testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004257 var TfiUsfArr tua := f_TfiUsfArrInit();
4258 var octetstring data := '0000'O & f_rnd_octstring(21);
4259
4260 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004261
Harald Welte883340c2018-02-28 18:59:29 +01004262 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004263 f_TfiUsfArrSet(tua, 7, 0);
4264 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4265 f_sleep(1.0);
4266
4267 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004268}
4269
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004270private function f_TC_pcu_ptcch_ul(uint16_t ra)
4271runs on test_CT {
4272 var template PCUIF_Message pcu_rach_ind;
4273 var PCUIF_send_data sd;
4274 var GsmFrameNumber fn;
4275 timer T;
4276
4277 /* Send an Access Burst on PTCCH/U over the Um-interface */
4278 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4279 chan_nr := ts_RslChanNr_PDCH(7),
4280 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4281
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004282 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4283 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004284
4285 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4286 T.start(52.0 * 4.615 / 1000.0);
4287 alt {
4288 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4289 log("Rx an Access Burst on the PCU interface: ", sd.data);
4290 setverdict(pass);
4291 T.stop;
4292 }
4293 [] PCU.receive { repeat; }
4294 [] T.timeout {
4295 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4296 /* Keep going, that's not the end of the world */
4297 }
4298 }
4299}
4300
4301testcase TC_pcu_ptcch() runs on test_CT {
4302 var L1ctlDlMessage dl;
4303 var octetstring data;
4304 timer T;
4305
4306 f_init_pcu_test();
4307 f_init_l1ctl();
4308 f_l1_tune(L1CTL);
4309
4310 /* Activate PDCH channel on TS7 */
4311 f_TC_pcu_act_req(0, 0, 7, true);
4312
4313 /* Tune trxcon to that PDCH channel */
4314 L1CTL.send(ts_L1CTL_DM_EST_REQ(arfcn := { false, mp_trx0_arfcn },
4315 chan_nr := valueof(ts_RslChanNr_PDCH(7)),
4316 tsc := 7));
4317
4318 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4319 for (var integer i := 0; i < 16; i := i + 1) {
4320 log("Sending an Access Burst towards the L1CTL interface");
4321 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4322 }
4323
4324 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4325 data := f_rnd_octstring(23);
4326
4327 /* Verify PTCCH/D: send a random data block, make sure it's received */
4328 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4329 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4330
4331 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4332 * let's give it more time in case if we miss the beginning. */
4333 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4334 alt {
4335 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4336 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4337 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4338 frame := data)) -> value dl {
4339 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4340 setverdict(pass);
4341 T.stop;
4342 }
4343 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4344 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4345 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4346 l2_data := data)) -> value dl {
4347 log("Rx PTCCH/D data block on L1CTL: ", dl);
4348 setverdict(pass);
4349 T.stop;
4350 }
4351 [] L1CTL.receive { repeat; }
4352 [] T.timeout {
4353 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4354 }
4355 }
4356}
4357
Harald Welte883340c2018-02-28 18:59:29 +01004358/* Send AGCH from PCU; check it appears on Um side */
4359testcase TC_pcu_data_req_agch() runs on test_CT {
4360 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004361 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004362 f_init_l1ctl();
4363 f_l1_tune(L1CTL);
4364
4365 f_TC_pcu_act_req(0, 0, 7, true);
4366 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4367
4368 T.start;
4369 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004370 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004371 setverdict(pass);
4372 }
4373 [] L1CTL.receive { repeat; }
4374 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004376 }
4377 }
4378}
4379
Harald Welte928622b2019-05-26 13:22:59 +02004380/* Send AGCH from PCU; check it appears on Um side */
4381testcase TC_pcu_data_req_pch() runs on test_CT {
4382 timer T := 3.0;
4383 f_init_pcu_test();
4384 f_init_l1ctl();
4385 f_l1_tune(L1CTL);
4386
4387 f_TC_pcu_act_req(0, 0, 7, true);
4388 /* three characters prefix: last 3 digits of IMSI as ASCII */
4389 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4390
4391 T.start;
4392 alt {
4393 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4394 setverdict(pass);
4395 }
4396 [] L1CTL.receive { repeat; }
4397 [] T.timeout {
4398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4399 }
4400 }
4401}
4402
Harald Welte883340c2018-02-28 18:59:29 +01004403/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4404testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4405 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004406 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004407 f_init_l1ctl();
4408 f_l1_tune(L1CTL);
4409
4410 /* append 3 last imsi digits so BTS can compute pagng group */
4411 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4412
4413 timer T := 0.5;
4414 T.start;
4415 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004416 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004417 /* TODO: verify paging group */
4418 setverdict(pass);
4419 }
4420 [] L1CTL.receive { repeat; }
4421 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004423 }
4424 }
4425}
4426
4427/* Send RACH from Um side, expect it to show up on PCU socket */
4428testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004429 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004430 f_init_l1ctl();
4431 f_l1_tune(L1CTL);
4432
4433 var GsmFrameNumber fn_last := 0;
4434 for (var integer i := 0; i < 1000; i := i+1) {
4435 var OCT1 ra := f_rnd_ra_ps();
4436 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4437 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004439 }
4440 fn_last := fn;
4441
4442 timer T := 2.0;
4443 T.start;
4444 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004445 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, 0, 0, oct2int(ra), 0, ?, fn))) {
Harald Welte883340c2018-02-28 18:59:29 +01004446 T.stop;
4447 }
4448 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004450 }
4451 [] PCU.receive { repeat; }
4452 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004454 }
4455 }
4456 }
4457 setverdict(pass);
4458}
4459
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004460/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4461 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4462testcase TC_pcu_ext_rach_content() runs on test_CT {
4463 var template PCUIF_Message pcu_rach_ind;
4464 var GsmFrameNumber fn_last := 0;
4465 var L1ctlRachSynchSeq synch_seq;
4466 var PCUIF_BurstType pcu_bt;
4467 var GsmFrameNumber fn;
4468 var BIT11 ra11;
4469
4470 f_init_pcu_test();
4471 f_init_l1ctl();
4472 f_l1_tune(L1CTL);
4473
4474 for (var integer i := 0; i < 1000; i := i+1) {
4475 /* We need to test both TS1 & TS2 */
4476 if (i rem 2 == 0) {
4477 synch_seq := RACH_SYNCH_SEQ_TS1;
4478 pcu_bt := BURST_TYPE_1;
4479 } else {
4480 synch_seq := RACH_SYNCH_SEQ_TS2;
4481 pcu_bt := BURST_TYPE_2;
4482 }
4483
4484 ra11 := f_rnd_ra11_ps();
4485 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4486 if (fn == fn_last) {
4487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4488 "Two RACH in same FN?!?");
4489 }
4490 fn_last := fn;
4491
4492 /* Compose the expected message */
4493 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004494 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004495 ra := bit2int(ra11),
4496 is_11bit := 1,
4497 burst_type := pcu_bt,
4498 fn := fn);
4499
4500 timer T := 2.0;
4501 T.start;
4502 alt {
4503 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4504 T.stop;
4505 }
4506 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4508 }
4509 [] PCU.receive { repeat; }
4510 [] T.timeout {
4511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4512 }
4513 }
4514 }
4515 setverdict(pass);
4516}
4517
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004518private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4519runs on test_CT {
4520 var template PCUIF_send_data sdt;
4521 var PCUIF_send_data sd;
4522 var int16_t lqual_cb;
4523 timer T := 1.0;
4524
4525 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4526 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4527
4528 /* Send a random PDTCH frame over Um */
4529 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4530 '0000'O & f_rnd_octstring(21)));
4531
4532 T.start;
4533 alt {
4534 /* If expected link quality is above the threshold */
4535 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4536 lqual_cb := sd.data.u.data_ind.lqual_cb;
4537 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4538
4539 /* Make sure the actual link quality matches the expected value */
4540 if (not match(lqual_cb, lqual_cb_exp)) {
4541 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4542 "expected value ", lqual_cb_exp));
4543 } else {
4544 setverdict(pass);
4545 }
4546 }
4547 /* If expected link quality is below the threshold */
4548 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4550 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4551 }
4552 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4553 [] PCU.receive { repeat; }
4554 [lqual_cb_exp < thresh] T.timeout {
4555 log("Rx nothing, as expected");
4556 setverdict(pass);
4557 }
4558 [lqual_cb_exp >= thresh] T.timeout {
4559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4560 "Timeout waiting for PCUIF_DATA.ind");
4561 }
4562 }
4563}
4564
4565/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4566testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4567 f_init_pcu_test();
4568 PCU.clear;
4569
4570 f_init_l1ctl();
4571 f_l1_tune(L1CTL);
4572
4573 /* Activate a PDCH channel on TS7 */
4574 f_TC_pcu_act_req(0, 0, 7, true);
4575
4576 /* Tune trxcon to that PDCH channel on TS7 */
4577 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn },
4578 valueof(ts_RslChanNr_PDCH(7)), 7);
4579
4580 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4581 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4582 var TrxcMessage ret;
4583
4584 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4585 valueof(ts_TRXC_FAKE_CI(i)));
4586
4587 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4588 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4589 }
4590}
4591
Harald Welte883340c2018-02-28 18:59:29 +01004592/* Send PAGING via RSL, expect it to shw up on PCU socket */
4593testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004594 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004595
4596 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004597 var MobileIdentityLV mi_lv;
4598 var octetstring mi_lv_enc;
4599 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004600 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004601
Harald Welte883340c2018-02-28 18:59:29 +01004602 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004603 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004604 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004605 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004606 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004607
4608 /* Fancy encoding for PCUIF */
4609 mi_lv := valueof(ts_MI_LV(mi));
4610 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4611 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004612
4613 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004614 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004615 T.start;
4616 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004617 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004618 }
4619 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004621 }
4622 [] PCU.receive { repeat; }
4623 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004625 }
4626 }
4627 }
4628 setverdict(pass);
4629}
4630
Harald Welted66c9b82019-05-25 09:03:15 +02004631/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4632testcase TC_pcu_time_ind() runs on test_CT {
4633 var PCUIF_send_data pcu_sd;
4634 var integer num_time_ind := 0;
4635 var integer first_fn, last_fn;
4636 var float test_duration := 5.0;
4637 timer T;
4638
4639 f_init_pcu_test();
4640 f_TC_pcu_act_req(0, 0, 7, true);
4641
4642 PCU.clear;
4643 T.start(test_duration);
4644 alt {
4645 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4646 num_time_ind := num_time_ind + 1;
4647 if (not isbound(first_fn)) {
4648 first_fn := pcu_sd.data.u.time_ind.fn;
4649 }
4650 last_fn := pcu_sd.data.u.time_ind.fn;
4651 repeat;
4652 }
4653 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4654 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4655 repeat;
4656 }
4657 [] PCU.receive {
4658 repeat;
4659 }
4660 [] T.timeout {}
4661 }
4662 var integer fn_expired := last_fn - first_fn;
4663 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4664
4665 /* verify the number of frames expired matches our expectation */
4666 const float c_GSM_FN_DURATION_MS := 4.61538;
4667 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004668 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004669 if (not match(fn_expired, t_fn_expected)) {
4670 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4671 }
4672
4673 /* There are three TIME.ind in every fn MOD 13 */
4674 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4675 /* Add some tolerance */
4676 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4677 if (not match(num_time_ind, t_time_ind_exp)) {
4678 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4679 }
4680
4681 setverdict(pass);
4682}
4683
Harald Welte4832c862019-05-25 14:57:18 +02004684/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4685testcase TC_pcu_rts_req() runs on test_CT {
4686 var PCUIF_send_data pcu_sd;
4687 var integer first_fn, last_fn;
4688 var integer num_rts_pdtch := 0;
4689 var integer num_rts_ptcch := 0;
4690 var float test_duration := 5.0;
4691 timer T;
4692
4693 f_init_pcu_test();
4694 f_TC_pcu_act_req(0, 0, 7, true);
4695
4696 PCU.clear;
4697 T.start(test_duration);
4698 alt {
4699 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4700 -> value pcu_sd {
4701 num_rts_pdtch := num_rts_pdtch + 1;
4702 if (not isbound(first_fn)) {
4703 first_fn := pcu_sd.data.u.rts_req.fn;
4704 }
4705 last_fn := pcu_sd.data.u.rts_req.fn;
4706 repeat;
4707 }
4708 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4709 -> value pcu_sd {
4710 num_rts_ptcch := num_rts_ptcch + 1;
4711 if (not isbound(first_fn)) {
4712 first_fn := pcu_sd.data.u.rts_req.fn;
4713 }
4714 last_fn := pcu_sd.data.u.rts_req.fn;
4715 repeat;
4716 }
4717 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4718 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4719 repeat;
4720 }
4721 [] PCU.receive {
4722 repeat;
4723 }
4724 [] T.timeout {}
4725 }
4726 var integer fn_expired := last_fn - first_fn;
4727 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4728 ", num_rts_ptcch=", num_rts_ptcch);
4729
4730 /* verify the number of frames expired matches our expectation */
4731 const float c_GSM_FN_DURATION_MS := 4.61538;
4732 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004733 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004734 if (not match(fn_expired, t_fn_expected)) {
4735 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4736 }
4737
4738 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4739 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4740 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4741 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4742 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4743 t_ptcch_exp);
4744 }
4745
4746 /* We have 12 PDTCH blocks every 52-multiframe */
4747 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4748 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4749 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4750 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4751 t_pdtch_exp);
4752 }
4753
4754 setverdict(pass);
4755}
4756
Harald Welte07bd2d22019-05-25 11:03:30 +02004757/* test for generating Abis side OML ALERT from the PCU */
4758testcase TC_pcu_oml_alert() runs on test_CT {
4759 var PCUIF_send_data pcu_sd;
4760 var integer num_time_ind := 0;
4761 var integer first_fn, last_fn;
4762 var float test_duration := 5.0;
4763 timer T;
4764
4765 f_init_pcu_test();
4766 f_TC_pcu_act_req(0, 0, 7, true);
4767
4768 /* re-connect CTRL port from BTS to BSC */
4769 f_ipa_ctrl_stop();
4770 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4771
4772 /* Send that OML Alert */
4773 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4774
4775 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4776 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4777 setverdict(pass);
4778}
4779
Harald Welteeaa9a862019-05-26 23:01:08 +02004780template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4781 template (value) RoutingAreaIdentificationV rai,
4782 template (value) OCT1 cause) := {
4783 discriminator := '0000'B, /* overwritten */
4784 tiOrSkip := {
4785 skipIndicator := '0000'B
4786 },
4787 msgs := {
4788 rrm := {
4789 gPRS_suspensionRequest := {
4790 messageType := '00110100'B,
4791 tLLI := tlli,
4792 routingAreaIdentification := rai,
4793 suspensionCause := cause,
4794 service_Support := omit
4795 }
4796 }
4797 }
4798}
4799
4800/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4801private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4802 var PCUIF_Message first_info;
4803 var integer pcu_conn_id := -1;
4804 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4805 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4806 var OCT4 tlli := '01020304'O;
4807 var OCT1 cause := '23'O;
4808 timer T := 5.0;
4809
4810 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4811
4812 f_l1_tune(L1CTL);
4813 RSL.clear;
4814
4815 f_est_dchan();
4816 L1CTL.clear;
4817
4818 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4819
4820 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4821 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4822 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4823
4824 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4825 T.start;
4826 alt {
4827 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4828 setverdict(pass);
4829 }
4830 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4831 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4832 }
4833 [] PCU.receive {
4834 repeat;
4835 }
4836 [] T.timeout {
4837 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4838 }
4839 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004840
4841 /* release the channel */
4842 f_rsl_chan_deact();
4843 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4844 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004845}
4846testcase TC_pcu_rr_suspend() runs on test_CT {
4847 var ConnHdlrPars pars;
4848 var ConnHdlr vc_conn;
4849
4850 f_init();
4851
4852 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4853 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4854 vc_conn.done;
4855}
Harald Welte07bd2d22019-05-25 11:03:30 +02004856
Harald Weltea2e0e942019-05-27 18:12:53 +02004857/* Ensure that PCUIF socket can accept only a single connection */
4858testcase TC_pcu_socket_connect_multi() runs on test_CT {
4859 timer T := 5.0;
4860
4861 /* this (among other things) establishes the first connection to the PCUIF socket */
4862 f_init();
4863
4864 /* try to establish a second connection, expect it to fail */
4865 PCU.send(UD_connect:{mp_pcu_socket, -1});
4866 T.start;
4867 alt {
4868 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4869 setverdict(pass);
4870 }
4871 [] PCU.receive(UD_connect_result:?) {
4872 setverdict(fail, "Unexpected unix domain connect result");
4873 }
4874 [] T.timeout {
4875 setverdict(pass);
4876 }
4877 }
4878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4879}
4880
Harald Weltec8effb72019-05-27 18:23:04 +02004881/* Ensure that PCUIF socket can disconnect + reconnect */
4882testcase TC_pcu_socket_reconnect() runs on test_CT {
4883 /* this (among other things) establishes the first connection to the PCUIF socket */
4884 f_init();
4885
4886 f_sleep(1.0);
4887
4888 f_pcuif_close(PCU, g_pcu_conn_id);
4889 g_pcu_conn_id := -1;
4890
4891 f_sleep(1.0);
4892
4893 /* re-connect */
4894 PCU.clear;
4895 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4896 setverdict(pass);
4897
4898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4899}
4900
Harald Weltebe030482019-05-27 22:29:35 +02004901/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4902private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4903 var L1ctlDlMessage l1_dl;
4904 var SystemInformation si;
4905 timer T := 5.0;
4906 T.start;
4907 alt {
4908 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4909 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4910 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4911 log("Ignoring non-RR SI ", l1_dl);
4912 repeat;
4913 }
4914 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4915 if (not ischosen(si.payload.si3)) {
4916 repeat;
4917 }
4918 }
4919 [] pt.receive {
4920 repeat;
4921 }
4922 [] T.timeout {
Vadim Yanitskiy4a07c122020-05-03 23:07:56 +07004923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI3");
Harald Weltebe030482019-05-27 22:29:35 +02004924 }
4925 }
4926 return si.payload.si3;
4927}
4928
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +07004929private function f_si3_has_gprs_indicator(RestOctets ro) return boolean {
4930 var SI3RestOctets rest := dec_SI3RestOctets(ro);
4931 return rest.gprs_ind.presence == '1'B;
Harald Weltebe030482019-05-27 22:29:35 +02004932}
4933
4934testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4935 var SystemInformationType3 si3;
4936 timer T := 5.0;
4937
4938 /* don't call f_init() as this would connect PCU socket */
4939 f_init_rsl(testcasename());
4940 T.start;
4941 alt {
4942 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4943 [] T.timeout {
4944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4945 }
4946 }
4947 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4948
4949 f_init_l1ctl();
4950 f_l1_tune(L1CTL);
4951
4952 f_sleep(2.0);
4953 L1CTL.clear;
4954 si3 := f_get_si3(L1CTL);
4955 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4956 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4957 } else {
4958 setverdict(pass);
4959 }
4960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4961}
4962
4963/* Ensure that GPRS capability is advertised after PCU socket connect */
4964testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4965 var SystemInformationType3 si3;
4966
4967 /* this (among other things) establishes the first connection to the PCUIF socket */
4968 f_init();
4969 f_init_l1ctl();
4970 f_l1_tune(L1CTL);
4971
4972 f_sleep(2.0);
4973 L1CTL.clear;
4974 si3 := f_get_si3(L1CTL);
4975 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4976 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4977 } else {
4978 setverdict(pass);
4979 }
4980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4981}
4982
4983/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4984testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4985 var SystemInformationType3 si3;
4986
4987 /* this (among other things) establishes the first connection to the PCUIF socket */
4988 f_init();
4989 f_init_l1ctl();
4990 f_l1_tune(L1CTL);
4991
4992 f_pcuif_close(PCU, g_pcu_conn_id);
4993 g_pcu_conn_id := -1;
4994
4995 f_sleep(1.0);
4996
4997 /* re-connect */
4998 PCU.clear;
4999 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5000
5001 f_sleep(2.0);
5002 L1CTL.clear;
5003 si3 := f_get_si3(L1CTL);
5004 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
5005 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
5006 } else {
5007 setverdict(pass);
5008 }
5009
5010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5011}
5012
Oliver Smithf5239c72019-08-28 10:01:25 +02005013/* Verify that the cell_id of SI3 (TS 04.08 9.1.35) and other values are passed properly to the PCU socket (OS#3854) */
5014testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5015 var SystemInformation si3 := valueof(ts_SI3_default);
5016
5017 f_init();
5018
5019 /* Verify cell_id */
5020 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5021 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5022 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005023 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5024 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5025 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005026 }
5027
5028 /* Verify LAC */
5029 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5030 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5031 if (lac_si3 != lac_pcu) {
5032 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5033 }
5034
5035 setverdict(pass);
5036}
Harald Welted66c9b82019-05-25 09:03:15 +02005037
Harald Welte3d04ae62018-04-04 20:29:05 +02005038/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005039 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005040 ***********************************************************************/
5041
5042private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5043runs on ConnHdlr {
5044 var PCUIF_send_data sd;
5045 /* Expect BTS to immediately acknowledge activation as PDCH */
5046 PCU.clear;
5047 f_rsl_chan_act(g_pars.chan_mode);
5048 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005049 timer T_wait := 2.0;
5050 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005051 alt {
5052 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5053 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005054 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5055 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5056 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005057 }
5058 }
5059 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005060 [] T_wait.timeout {
5061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5062 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5063 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005064 }
5065 /* try to activate this PDCH from the PCU point of view */
5066 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5067 /* FIXME: is there a response? */
5068}
5069
5070private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5071runs on ConnHdlr {
5072 var PCUIF_send_data sd;
5073 /* Send RSL CHAN REL (deactivate) */
5074 PCU.clear;
5075 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5076 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005077 timer T_wait := 2.0;
5078 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005079 alt {
5080 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5081 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005082 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5083 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5084 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005085 }
5086 }
5087 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005088 [] T_wait.timeout {
5089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5090 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5091 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005092 }
5093 /* Emulate PCU asking BTS to deactivate PDCH */
5094 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5095 alt {
5096 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5097 setverdict(pass);
5098 }
5099 [] RSL.receive { repeat; }
5100 }
5101}
5102
5103/* Activate Osmocom-style dynamic PDCH from BSC side */
5104function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5105 var PCUIF_Message first_info;
5106 var integer ts_nr := g_chan_nr.tn;
5107 var integer trx_nr := 0;
5108 var integer bts_nr := 0;
5109 var integer pcu_conn_id := -1;
5110
5111 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5112
5113 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5114 f_sleep(3.0);
5115 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5116 setverdict(pass);
5117}
5118testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5119 var ConnHdlrPars pars;
5120 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005121 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005122
5123 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5124 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5125 vc_conn.done;
5126}
5127
5128/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5129function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5130 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005131 var integer pcu_conn_id := -1;
5132
5133 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5134
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005135 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5136 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5137 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005138 setverdict(pass);
5139}
5140testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5141 var ConnHdlrPars pars;
5142 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005143 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005144
5145 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5146 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5147 vc_conn.done;
5148}
5149
5150/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5151function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5152 var PCUIF_Message first_info;
5153 var integer ts_nr := g_chan_nr.tn;
5154 var integer trx_nr := 0;
5155 var integer bts_nr := 0;
5156 var integer pcu_conn_id := -1;
5157
5158 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5159
5160 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005161 /* Send a second Chan Activ and expect it to be NACKed */
5162 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5163 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005164 setverdict(pass);
5165}
5166testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5167 var ConnHdlrPars pars;
5168 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005169 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005170
5171 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5172 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5173 vc_conn.done;
5174}
5175
5176/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5177function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5178 var PCUIF_Message first_info;
5179 var integer ts_nr := g_chan_nr.tn;
5180 var integer trx_nr := 0;
5181 var integer bts_nr := 0;
5182 var integer pcu_conn_id := -1;
5183 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5184
5185 /* register for the TCH/F channel number */
5186 f_rslem_register(0, chan_nr);
5187
5188 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5189
5190 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5191 "RSL CHAN ACT");
5192 setverdict(pass);
5193}
5194testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5195 var ConnHdlrPars pars;
5196 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005197 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005198
5199 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5200 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5201 vc_conn.done;
5202}
5203
5204/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5205function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5206 var PCUIF_Message first_info;
5207 var integer ts_nr := g_chan_nr.tn;
5208 var integer trx_nr := 0;
5209 var integer bts_nr := 0;
5210 var integer pcu_conn_id := -1;
5211 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5212 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5213
5214 /* register for the TCH/H channel numbers */
5215 f_rslem_register(0, chan_nr[0]);
5216 f_rslem_register(0, chan_nr[1]);
5217
5218 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5219
5220 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5221 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5222 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5223 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5224 setverdict(pass);
5225}
5226testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5227 var ConnHdlrPars pars;
5228 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005229 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005230
5231 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5232 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5233 vc_conn.done;
5234}
5235
Harald Welte9bbbfb52018-04-05 09:33:19 +02005236/***********************************************************************
5237 * IPA Style Dynamic Timeslot Support
5238 ***********************************************************************/
5239
5240private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5241runs on ConnHdlr {
5242 var PCUIF_send_data sd;
5243 /* Expect BTS to immediately acknowledge activation as PDCH */
5244 PCU.clear;
5245 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5246 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005247 timer T_wait := 2.0;
5248 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005249 alt {
5250 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5251 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 +01005252 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5253 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5254 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005255 }
5256 }
5257 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005258 [] T_wait.timeout {
5259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5260 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5261 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005262 }
5263 /* try to activate this PDCH from the PCU point of view */
5264 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5265 /* FIXME: is there a response? */
5266
5267 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5268}
5269
5270private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5271runs on ConnHdlr {
5272 var PCUIF_send_data sd;
5273 /* Send RSL CHAN REL (deactivate) */
5274 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5275 PCU.clear;
5276 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005277 timer T_wait := 2.0;
5278 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005279 alt {
5280 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5281 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 +01005282 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5283 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5284 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005285 }
5286 }
5287 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005288 [] T_wait.timeout {
5289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5290 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5291 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005292 }
5293 /* Emulate PCU asking BTS to deactivate PDCH */
5294 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5295 alt {
5296 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5297 setverdict(pass);
5298 }
5299 [] RSL.receive { repeat; }
5300 }
5301}
5302
5303/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5304function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5305 var PCUIF_Message first_info;
5306 var integer ts_nr := g_chan_nr.tn;
5307 var integer trx_nr := 0;
5308 var integer bts_nr := 0;
5309 var integer pcu_conn_id := -1;
5310
5311 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5312
5313 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5314 f_sleep(3.0);
5315 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5316
5317 setverdict(pass);
5318
5319}
5320testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5321 var ConnHdlrPars pars;
5322 var ConnHdlr vc_conn;
5323 f_init();
5324
5325 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5326 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5327 vc_conn.done;
5328}
5329
5330/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5331function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5332 var PCUIF_Message first_info;
5333 var integer ts_nr := g_chan_nr.tn;
5334 var integer trx_nr := 0;
5335 var integer bts_nr := 0;
5336 var integer pcu_conn_id := -1;
5337
5338 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5339
5340 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5341 "RSL CHAN ACT");
5342 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5343 "RF CHAN REL", true);
5344 setverdict(pass);
5345}
5346testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5347 var ConnHdlrPars pars;
5348 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005349 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005350
5351 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5352 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5353 vc_conn.done;
5354}
5355
5356/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5357function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5358 var PCUIF_Message first_info;
5359 var integer ts_nr := g_chan_nr.tn;
5360 var integer trx_nr := 0;
5361 var integer bts_nr := 0;
5362 var integer pcu_conn_id := -1;
5363
5364 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5365
5366 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5367 "RSL CHAN ACT");
5368
5369 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5370 alt {
5371 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5372 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005374 }
5375 [] RSL.receive { repeat; }
5376 }
5377
5378 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5379 "RF CHAN REL", true);
5380 setverdict(pass);
5381}
5382testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5383 var ConnHdlrPars pars;
5384 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005385 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005386
5387 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5388 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5389 vc_conn.done;
5390}
5391
5392/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5393function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5394 var PCUIF_Message first_info;
5395 var integer ts_nr := g_chan_nr.tn;
5396 var integer trx_nr := 0;
5397 var integer bts_nr := 0;
5398 var integer pcu_conn_id := -1;
5399
5400 /* register for the TCH/F channel number */
5401 f_rslem_register(0, g_chan_nr);
5402
5403 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5404
5405 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5406
5407 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5408 "RSL CHAN ACT");
5409
5410 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5411
5412 setverdict(pass);
5413}
5414testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5415 var ConnHdlrPars pars;
5416 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005417 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005418
5419 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5420 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5421 vc_conn.done;
5422}
5423
5424
Harald Welte0472ab42018-03-12 15:02:26 +01005425/***********************************************************************
5426 * LAPDm / RLL related
5427 ***********************************************************************/
5428
5429private function f_tx_lapdm(template (value) LapdmFrame l,
5430 template (value) RslLinkId link_id) runs on ConnHdlr {
5431 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005432 var template (value) SacchL1Header l1h;
5433
5434 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005435 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005436 /* Compose dummy L1 header */
5437 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5438 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 +02005439 } else {
5440 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005441 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 +01005442 }
Harald Welte0472ab42018-03-12 15:02:26 +01005443}
5444
5445type record RllTestCase {
5446 uint3_t sapi,
5447 RslLinkId link_id,
5448 octetstring l3,
5449 boolean exp
5450}
5451type record of RllTestCase RllTestCases;
5452template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5453 sapi := sapi,
5454 link_id := id,
5455 l3 := l3,
5456 exp := exp
5457}
5458
5459/* execute the same callback function with a set of different parameters (tcs) on a
5460 * variety of logical channels */
5461private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5462 var ConnHdlrPars pars;
5463 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005464 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005465
5466 /* test on each of the channels we have */
5467 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5468 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5469
5470 /* test each of the test cases on the current channel */
5471 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5472 pars.spec.rll := tcs[j];
5473 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5474 vc_conn := f_start_handler(fn, pars);
5475 vc_conn.done;
5476 }
5477 }
5478
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005480}
5481
5482/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5483private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5484 var RllTestCase tc := g_pars.spec.rll;
5485 timer T := 3.0;
5486
5487 f_l1_tune(L1CTL);
5488 RSL.clear;
5489
5490 /* activate the logical channel */
5491 f_est_dchan();
5492 L1CTL.clear;
5493
5494 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5495 T.start;
5496 alt {
5497 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5498 if (tc.exp) {
5499 setverdict(pass);
5500 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005502 }
5503 }
5504 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5505 if (tc.exp) {
5506 setverdict(pass);
5507 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005509 }
5510 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005511 /* We also expect to receive the measurements */
5512 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005513 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005515 }
5516 [not tc.exp] T.timeout {
5517 setverdict(pass);
5518 }
5519 }
5520
5521 f_rsl_chan_deact();
5522 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5523 f_rslem_unregister(0, g_chan_nr);
5524}
5525testcase TC_rll_est_ind() runs on test_CT {
5526 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005527 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005528 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005529 /* normal SAPI0 establishment */
5530 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005531 /* SAPI 3 doesn't support contention resolution */
5532 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5533 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5534 /* normal SAPI3 establishment on main DCCH */
5535 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5536 /* normal SAPI3 establishment on SACCH */
5537 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5538 };
5539 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5540}
5541
5542/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5543private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5544 var RllTestCase tc := g_pars.spec.rll;
5545 var L1ctlDlMessage dl;
5546 timer T := 3.0;
5547
5548 f_l1_tune(L1CTL);
5549 RSL.clear;
5550
5551 /* activate the logical channel */
5552 f_est_dchan();
5553 L1CTL.clear;
5554
5555 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5556 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5557 T.start;
5558 alt {
5559 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5560 var LapdmFrame lapdm;
5561 var octetstring l2 := dl.payload.data_ind.payload;
5562 if (dl.dl_info.link_id.c == SACCH) {
5563 /* remove L1 header */
5564 l2 := substr(l2, 2, lengthof(l2)-2);
5565 }
5566 lapdm.ab := dec_LapdmFrameAB(l2);
5567 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5568 setverdict(pass);
5569 } else {
5570 repeat;
5571 }
5572 }
5573 [] L1CTL.receive { repeat; }
5574 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005576 }
5577 }
5578
5579 f_rsl_chan_deact();
5580 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5581 f_rslem_unregister(0, g_chan_nr);
5582}
5583testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5584 var RllTestCases tcs := {
5585 /* normal SAPI3 establishment on main DCCH */
5586 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5587 };
5588 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5589}
5590testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5591 var RllTestCases tcs := {
5592 /* normal SAPI3 establishment on SACCH */
5593 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5594 }
5595 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5596}
5597
5598/* altstep to receive a LAPDm frame matching the given template */
5599private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5600 var L1ctlDlMessage dl;
5601 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5602 var LapdmFrame lapdm;
5603 var octetstring l2 := dl.payload.data_ind.payload;
5604 if (dl.dl_info.link_id.c == SACCH) {
5605 /* remove L1 header */
5606 l2 := substr(l2, 2, lengthof(l2)-2);
5607 }
5608 if (ischosen(exp.ab)) {
5609 lapdm.ab := dec_LapdmFrameAB(l2);
5610 } else if (ischosen(exp.b4)) {
5611 lapdm.b4 := dec_LapdmFrameB4(l2);
5612 } else if (ischosen(exp.bbis)) {
5613 lapdm.bbis := dec_LapdmFrameBbis(l2);
5614 }
5615 log("Rx LAPDm ", lapdm);
5616 if (match(lapdm, exp)) {
5617 setverdict(pass);
5618 } else {
5619 repeat;
5620 }
5621 }
5622 [] L1CTL.receive { repeat; }
5623}
5624private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5625 timer T := t;
5626 T.start;
5627 alt {
5628 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005630 }
5631 [] as_l1_exp_lapdm(exp);
5632 }
5633}
5634
5635/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5636private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5637 /* send SABM from MS -> BTS */
5638 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5639 /* expect RLL EST IND on Abis */
5640 alt {
5641 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5642 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5643 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005645 }
5646 [] RSL.receive { repeat; }
5647 }
5648 /* expect UA from BTS -> MS */
5649 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5650}
5651
5652/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5653private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5654 var RllTestCase tc := g_pars.spec.rll;
5655
5656 f_l1_tune(L1CTL);
5657 RSL.clear;
5658
5659 /* activate the logical channel */
5660 f_est_dchan();
5661 L1CTL.clear;
5662
5663 /* first establish the link-layer */
5664 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5665
5666 /* then send the DISC */
5667 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5668 /* ... and expect the REL IND on the RSL side */
5669 alt {
5670 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5671 setverdict(pass);
5672 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005673 /* We also expect to receive the measurements */
5674 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005675 }
5676
5677 /* release the channel */
5678 f_rsl_chan_deact();
5679 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5680 f_rslem_unregister(0, g_chan_nr);
5681}
5682testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5683 var RllTestCases tcs := {
5684 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5685 };
5686 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5687}
5688
5689testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5690 var RllTestCases tcs := {
5691 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5692 };
5693 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5694}
5695testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5696 var RllTestCases tcs := {
5697 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5698 };
5699 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5700}
5701testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5702 var RllTestCases tcs := {
5703 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5704 };
5705 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5706}
5707
5708/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5709private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5710 var RllTestCase tc := g_pars.spec.rll;
5711 f_l1_tune(L1CTL);
5712 RSL.clear;
5713
5714 /* activate the logical channel */
5715 f_est_dchan();
5716 L1CTL.clear;
5717
5718 /* first establish the link-layer */
5719 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5720
5721 /* then send the REL REQ via RSL */
5722 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5723 /* ... and expect the DISC on the Um side */
5724 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005725 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005726 /* FIXME: send a UA in resposne to the DISC */
5727 }
5728 }
5729
5730 /* release the channel */
5731 f_rsl_chan_deact();
5732 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5733 f_rslem_unregister(0, g_chan_nr);
5734}
5735testcase TC_rll_rel_req() runs on test_CT {
5736 var RllTestCases tcs := {
5737 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5738 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5739 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5740 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5741 };
5742 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5743}
5744
5745/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5746testcase TC_rll_data_req() runs on test_CT {
5747}
5748
5749/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5750testcase TC_rll_data_ind() runs on test_CT {
5751}
5752
5753/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5754private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5755 var RllTestCase tc := g_pars.spec.rll;
5756
5757 f_l1_tune(L1CTL);
5758 RSL.clear;
5759
5760 f_est_dchan();
5761 L1CTL.clear;
5762
5763 /* Send UNITDATA REQ on RSL side */
5764 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5765 /* Expect it to arrive on the other side */
5766 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005767 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005768 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005769 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005770 }
5771
5772 /* release the channel */
5773 f_rsl_chan_deact();
5774 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5775 f_rslem_unregister(0, g_chan_nr);
5776}
5777testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5778 var octetstring l3 := f_rnd_octstring(15);
5779 var RllTestCases tcs := {
5780 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5781 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5782 };
5783 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5784}
5785testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5786 var octetstring l3 := f_rnd_octstring(19);
5787 var RllTestCases tcs := {
5788 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5789 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5790 };
5791 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5792}
5793
5794/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5795private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5796 var RllTestCase tc := g_pars.spec.rll;
5797
5798 f_l1_tune(L1CTL);
5799 RSL.clear;
5800
5801 f_est_dchan();
5802 L1CTL.clear;
5803
5804 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005805 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005806 /* Expdct RLL UNITDATA IND on RSL side */
5807 alt {
5808 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5809 setverdict(pass);
5810 }
5811 [] RSL.receive { repeat; }
5812 }
5813
5814 /* release the channel */
5815 f_rsl_chan_deact();
5816 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5817 f_rslem_unregister(0, g_chan_nr);
5818}
5819testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005820 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005821 var RllTestCases tcs := {
5822 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5823 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5824 };
5825 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5826}
5827testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5828 var octetstring l3 := f_rnd_octstring(18);
5829 var RllTestCases tcs := {
5830 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5831 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5832 };
5833 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5834}
5835
Harald Weltee613f962018-04-18 22:38:16 +02005836/***********************************************************************
5837 * Encryption Related
5838 ***********************************************************************/
5839
5840/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5841function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5842 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5843 if (link_id.c == SACCH) {
5844 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5845 } else {
5846 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5847 }
5848}
5849
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005850/* Expect (or not expect) other kinds of messages */
5851private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5852 [exp_any] RSL.receive { repeat; }
5853 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005855 }
5856}
5857
Harald Weltee613f962018-04-18 22:38:16 +02005858/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005859private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005860 RslLinkId link_id,
5861 octetstring l3,
5862 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005863 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005864) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005865 timer T := 3.0;
5866 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5867 T.start;
5868 /* Expect RLL UNITDATA IND on RSL side */
5869 alt {
5870 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5871 setverdict(pass);
5872 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005873 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005874 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005875 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005877 }
Harald Weltee613f962018-04-18 22:38:16 +02005878 }
5879}
5880
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005881/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5882private function f_data_mo(
5883 RslLinkId link_id,
5884 boolean p, uint3_t nr, uint3_t ns,
5885 octetstring l3,
5886 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005887 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005888) runs on ConnHdlr {
5889 timer T := 3.0;
5890 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5891 T.start;
5892 /* Expect RLL DATA IND on RSL side */
5893 alt {
5894 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5895 setverdict(pass);
5896 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005897 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005898 [] as_rsl_any_ind(exp_any);
5899 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005901 }
5902 }
5903}
5904
Harald Weltee613f962018-04-18 22:38:16 +02005905/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5906function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5907 f_l1_tune(L1CTL);
5908 f_est_dchan(true);
5909
5910 /* now we actually need to transmit some data both ways to check if the encryption works */
5911 var L1ctlDlMessage dl;
5912
Stefan Sperling603d98e2018-07-25 16:47:28 +02005913 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005914 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5915
5916 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5917 f_unitdata_mt(link_id, l3);
5918
5919 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5920 f_unitdata_mo(link_id, l3);
5921
5922 /* release the channel */
5923 f_rsl_chan_deact();
5924 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5925 f_rslem_unregister(0, g_chan_nr);
5926}
5927testcase TC_chan_act_a51() runs on test_CT {
5928 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5929 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5930 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5931}
5932testcase TC_chan_act_a52() runs on test_CT {
5933 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5934 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5935 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5936}
5937testcase TC_chan_act_a53() runs on test_CT {
5938 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5939 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5940 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5941}
5942
Eric Wildf1827a72019-05-28 17:37:35 +02005943/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5944 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5945function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5946 f_l1_tune(L1CTL);
5947 f_est_dchan(true);
5948
5949 /* now we actually need to transmit some data both ways to check if the encryption works */
5950 var L1ctlDlMessage dl;
5951
5952 var octetstring l3 := f_rnd_octstring(20);
5953 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5954
5955 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5956 f_unitdata_mt(link_id, l3);
5957
5958 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5959 f_unitdata_mo(link_id, l3);
5960
5961 var RSL_Message rsl;
5962 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5963
5964 /* modify key to break proper encryption */
5965 g_pars.encr.key := f_rnd_octstring(8);
5966 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5967 rsl.ies := rsl.ies & { ei };
5968 RSL.send(rsl);
5969
5970 timer T0 := 1.0;
5971 T0.start;
5972 /* Expect RSL MODIFY ACK */
5973 alt {
5974 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5975 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5977 }
5978 [] T0.timeout {
5979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5980 }
5981 }
5982
5983 var octetstring l3msg := f_rnd_octstring(15);
5984 timer T1 := 3.0;
5985 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5986 due to broken encryption */
5987 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5988 T1.start;
5989 alt {
5990 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5992 }
5993 [] T1.timeout {
5994 setverdict(pass);
5995 }
5996 }
5997
5998 /* release the channel */
5999 f_rsl_chan_deact();
6000 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6001 f_rslem_unregister(0, g_chan_nr);
6002}
6003testcase TC_rsl_modify_encr() runs on test_CT {
6004 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6005 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6006 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6007}
Harald Weltee613f962018-04-18 22:38:16 +02006008
6009/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6010function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6011 /* L3 payload doesn't matter, as it is passed transparently */
6012 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6013 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6014 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6015
6016 f_l1_tune(L1CTL);
6017
6018 /* first establish a dedicated channel in the clear */
6019 f_est_dchan(false);
6020
6021 /* Establish ABM */
6022 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6023
6024 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6025 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6026 /* expect the L3 to arrive still unencrypted on the MS side */
6027 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6028
6029 /* configure L1 to apply ciphering */
6030 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6031 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6032
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006033 /* send first ciphered I-frame in response and expect it on RSL */
6034 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006035
6036 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6037 * and hence enable encryption also on the downlink */
6038
6039 /* expect bi-directional communication work in encrypted mode */
6040 f_unitdata_mo(link_id, f_rnd_octstring(15));
6041 f_unitdata_mt(link_id, f_rnd_octstring(15));
6042
6043 /* release the channel */
6044 f_rsl_chan_deact();
6045 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6046 f_rslem_unregister(0, g_chan_nr);
6047}
6048testcase TC_encr_cmd_a51() runs on test_CT {
6049 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6050 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6051 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6052}
6053testcase TC_encr_cmd_a52() runs on test_CT {
6054 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6055 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6056 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6057}
6058testcase TC_encr_cmd_a53() runs on test_CT {
6059 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6060 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6061 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6062}
6063
6064private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6065 var LapdmFrame lf;
6066 var octetstring reenc;
6067
6068 /* decode the LAPDm frame */
6069 if (ischosen(exp_match.ab)) {
6070 lf.ab := dec_LapdmFrameAB(enc);
6071 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006073 }
6074
6075 /* check if decoder result matches expectation */
6076 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006078 } else {
6079 log(name, ": matched");
6080 setverdict(pass);
6081 }
6082
6083 /* test if re-encoded frame equals original input */
6084 reenc := enc_LapdmFrame(lf);
6085 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006087 } else {
6088 setverdict(pass);
6089 }
6090}
6091
6092testcase TC_lapdm_selftest() runs on test_CT {
6093 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6094 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6095 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6096 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6097 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6098 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6099 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6100}
6101
Stefan Sperling4880be42018-08-07 18:12:59 +02006102/***********************************************************************
6103 * DTX Related (see GSM 05.08, section 8.3)
6104 ***********************************************************************/
6105
6106/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6107function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6108 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6109 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6110 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6111 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6112}
6113function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6114 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6115 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6116}
6117function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6118 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6119 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6120 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6121 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6122}
6123function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6124 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6125 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6126 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6127 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6128 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6129 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6130 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6131 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6132}
6133
6134function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6135 var L1ctlDlMessage dl;
6136 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6137 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6138 var GsmFrameNumber first_fn;
6139 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006140 var integer nfill_frames_sacch := 0;
6141 var integer nfill_frames_nonsacch := 0;
6142 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006143 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6144 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006145 const integer frame_dtx_tchf_mod := 104;
6146 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6147 * which operates in terms of blocks rather than frames. */
6148 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6149 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006150 timer T := 5.0;
6151
6152 f_l1_tune(L1CTL);
6153 RSL.clear;
6154 L1CTL.clear;
6155
6156 /* activate TCHF signalling channel */
6157 f_est_dchan(false);
6158
6159 T.start;
6160 alt {
6161 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6162 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6163 var octetstring l2 := dl.payload.data_ind.payload;
6164
6165 if (is_first_frame) {
6166 is_first_frame := false;
6167 first_fn := dl.dl_info.frame_nr;
6168 }
6169
6170 if (dl.dl_info.link_id.c == SACCH) {
6171 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6172 if (not match(l2_fill_frame_sacch, l2)) {
6173 repeat;
6174 }
6175 } else if (not match(l2_fill_frame, l2)) {
6176 repeat;
6177 }
6178
6179 if (dtxd) {
6180 if (not f_g_chan_is_tchf()) {
6181 T.stop;
6182 f_rsl_chan_deact();
6183 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006184 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 +02006185 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006186 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006187 T.stop;
6188 f_rsl_chan_deact();
6189 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006190
6191 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6192 * 2 SACCH, 1 TCH/F */
6193 expected_fill_frames := 3;
6194
6195 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6196 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6197 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006199 } else {
6200 setverdict(pass);
6201 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006202 } else {
6203 if (dl.dl_info.link_id.c == SACCH) {
6204 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006205 repeat;
6206 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006207 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6208 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6209 * we should only see the subset of frames numbers which correspond to a block boundary.
6210 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6211 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6212 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6213 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6214 repeat;
6215 }
6216 }
6217 log("Received DTX TCH fill frame with bad frame number: ", fn,
6218 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6219 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6220 f_rsl_chan_deact();
6221 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006223 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006224 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006225 if (dl.dl_info.link_id.c == SACCH) {
6226 nfill_frames_sacch := nfill_frames_sacch + 1;
6227 } else {
6228 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6229 }
6230 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006231 T.stop;
6232 if (f_g_chan_is_tchf()) {
6233 /* Without DTX we can expect 25 fill frames for every 104 frames.
6234 * (24 FACCH + 1 SACCH filling) */
6235 expected_fill_frames := 25;
6236 } else if (f_g_chan_is_tchh()) {
6237 /* We can expect 2 fill frames for every 104 frames. */
6238 expected_fill_frames := 2;
6239 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6240 /* We can expect 5 fill frames for every 104 frames. */
6241 expected_fill_frames := 5;
6242 } else {
6243 f_rsl_chan_deact();
6244 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006246 }
6247
6248 f_rsl_chan_deact();
6249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006250
6251 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006252 setverdict(pass);
6253 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006254 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6255 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006257 }
6258 } else {
6259 repeat;
6260 }
6261 }
6262 }
6263 [] L1CTL.receive { repeat; }
6264 [] T.timeout {
6265 f_rsl_chan_deact();
6266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006268 }
6269 }
6270}
6271
6272function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6273 f_test_l2_fill_frames(false);
6274}
6275
6276function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6277 f_test_l2_fill_frames(true);
6278}
6279
6280function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6281 var ConnHdlr vc_conn;
6282 var ConnHdlrPars pars;
6283 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006284 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006285 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6286 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6287 if (dtxd) {
6288 if (i >= 4) { /* DTX is only allowed on TCH/F */
6289 break;
6290 }
6291 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6292 } else {
6293 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6294 }
6295 vc_conn.done;
6296 }
6297}
6298
6299/* Verify that L2 fill frames are sent on TCH in signaling mode if
6300 * there is nothing to transmit while DTX is disabled on downlink. */
6301testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6302 f_tch_sign_l2_fill_frame(false);
6303}
6304
6305/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6306 * there is nothing to transmit while DTX is enabled on downlink. */
6307testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6308 f_tch_sign_l2_fill_frame(true);
6309}
Harald Welte0472ab42018-03-12 15:02:26 +01006310
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006311testcase TC_chopped_ipa_ping() runs on test_CT {
6312 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6313}
6314
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006315testcase TC_chopped_ipa_payload() runs on test_CT {
6316 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6317}
6318
Harald Welte0472ab42018-03-12 15:02:26 +01006319/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6320/* protocol error as per 44.006 */
6321/* link layer failure (repetition of I-frame N200 times without ACK */
6322/* repetition of SABM or DISC N200 times without ACK */
6323/* receptiom of SABM in multi-frame established state */
6324
6325
Harald Welte68e495b2018-02-25 00:05:57 +01006326/* TODO Areas:
6327
6328* channel activation
6329** with BS_Power / MS_Power, bypassing power control loop
6330** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006331** with timing advance from initial activation on
6332* mode modify
6333** encryption
6334** multirate
6335* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006336** unsupported algorithm
6337* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006338* BS Power Control
6339* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006340* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006341* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006342** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006343* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006344** DATA_IND from BTS->PCU
6345** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006346
6347*/
Harald Welte70767382018-02-21 12:16:40 +01006348
6349control {
6350 execute( TC_chan_act_stress() );
6351 execute( TC_chan_act_react() );
6352 execute( TC_chan_deact_not_active() );
6353 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006354 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006355 execute( TC_sacch_filling() );
6356 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006357 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006358 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006359 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006360 execute( TC_sacch_chan_act_ho_async() );
6361 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006362 execute( TC_rach_content() );
6363 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006364 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006365 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006366 execute( TC_rach_load_idle_thresh0() );
6367 execute( TC_rach_load_idle_below_thresh() );
6368 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006369 execute( TC_meas_res_sign_tchf() );
6370 execute( TC_meas_res_sign_tchh() );
6371 execute( TC_meas_res_sign_sdcch4() );
6372 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006373 execute( TC_meas_res_sign_tchh_toa256() );
Eric Wildae8f2622019-06-18 17:05:11 +02006374 execute( TC_rsl_bs_pwr_static_ass() );
6375 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006376 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006377 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006378 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006379 execute( TC_rsl_ms_pwr_dyn_up() );
6380 execute( TC_rsl_ms_pwr_dyn_down() );
6381 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6382 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006383 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006384 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006385 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006386 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006387 execute( TC_paging_imsi_80percent() );
6388 execute( TC_paging_tmsi_80percent() );
6389 execute( TC_paging_imsi_200percent() );
6390 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006391 execute( TC_rsl_protocol_error() );
6392 execute( TC_rsl_mand_ie_error() );
6393 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006394 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006395 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006396 execute( TC_si_sched_2bis() );
6397 execute( TC_si_sched_2ter() );
6398 execute( TC_si_sched_2ter_2bis() );
6399 execute( TC_si_sched_2quater() );
6400 execute( TC_si_sched_13() );
6401 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006402 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006403 execute( TC_ipa_crcx_twice_not_active() );
6404 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006405 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006406 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006407
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006408 if (mp_pcu_socket != "") {
6409 execute( TC_pcu_act_req() );
6410 execute( TC_pcu_act_req_wrong_ts() );
6411 execute( TC_pcu_act_req_wrong_bts() );
6412 execute( TC_pcu_act_req_wrong_trx() );
6413 execute( TC_pcu_deact_req() );
6414 execute( TC_pcu_deact_req_wrong_ts() );
6415 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006416 if (mp_l1_supports_gprs) {
6417 execute( TC_pcu_data_req_pdtch() );
6418 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006419 execute( TC_pcu_data_req_wrong_bts() );
6420 execute( TC_pcu_data_req_wrong_trx() );
6421 execute( TC_pcu_data_req_wrong_ts() );
6422 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006423 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006424 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006425 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006426 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006427 execute( TC_pcu_data_req_imm_ass_pch() );
6428 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006429 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006430 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006431 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006432 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006433 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006434 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006435 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006436 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006437 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006438 execute( TC_pcu_socket_noconnect_nosi3gprs() );
6439 execute( TC_pcu_socket_connect_si3gprs() );
6440 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006441 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006442 execute( TC_dyn_osmo_pdch_act_deact() );
6443 execute( TC_dyn_osmo_pdch_double_act() );
6444 execute( TC_dyn_ipa_pdch_act_deact() );
6445 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6446
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006447 } else {
6448 log("PCU socket path not available, skipping PCU tests");
6449 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006450
Harald Welte3d04ae62018-04-04 20:29:05 +02006451 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006452 execute( TC_dyn_osmo_pdch_tchf_act() );
6453 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006454 execute( TC_dyn_ipa_pdch_tchf_act() );
6455 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006456
6457 execute( TC_rll_est_ind() );
6458 execute( TC_rll_est_req_DCCH_3() );
6459 execute( TC_rll_est_req_ACCH_3() );
6460 execute( TC_rll_rel_ind_DCCH_0() );
6461 execute( TC_rll_rel_ind_DCCH_3() );
6462 execute( TC_rll_rel_ind_ACCH_0() );
6463 execute( TC_rll_rel_ind_ACCH_3() );
6464 execute( TC_rll_rel_req() );
6465 execute( TC_rll_unit_data_req_DCCH() );
6466 execute( TC_rll_unit_data_req_ACCH() );
6467 execute( TC_rll_unit_data_ind_DCCH() );
6468 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006469
6470 execute( TC_chan_act_a51() );
6471 execute( TC_chan_act_a52() );
6472 execute( TC_chan_act_a53() );
6473 execute( TC_encr_cmd_a51() );
6474 execute( TC_encr_cmd_a52() );
6475 execute( TC_encr_cmd_a53() );
6476
Harald Welteee25aae2019-05-19 14:32:37 +02006477 execute( TC_err_rep_wrong_mdisc() );
6478 execute( TC_err_rep_wrong_msg_type() );
6479 execute( TC_err_rep_wrong_sequence() );
6480
Harald Weltee613f962018-04-18 22:38:16 +02006481 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006482
6483 execute( TC_tch_sign_l2_fill_frame() );
6484 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006485
6486 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006487 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006488}
6489
6490
6491}