blob: 7191a7d84a809912b6683434d6cb600b1eade8fc [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
Harald Welte7484fc42018-02-24 14:09:45 +0100228/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100229template (value) SystemInformation ts_SI3_default := {
230 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100231 payload := {
232 si3 := {
233 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100234 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100235 ctrl_chan_desc := {
236 msc_r99 := true,
237 att := true,
238 bs_ag_blks_res := 1,
239 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100240 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100241 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
242 spare := '00'B,
243 bs_pa_mfrms := 0, /* 2 multiframes */
244 t3212 := 1 /* 6 minutes */
245 },
Harald Welte82ccef72018-02-25 16:17:33 +0100246 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100247 dn_ind := false,
248 pwrc := false,
249 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100250 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100251 },
Harald Weltef10153f2018-02-25 16:34:05 +0100252 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100253 rach_control := ts_RachCtrl_default,
Harald Weltebe030482019-05-27 22:29:35 +0200254 rest_octets := '2C2B2B2B'O /* GPRS present */
Harald Welte7484fc42018-02-24 14:09:45 +0100255 }
256 }
257}
Harald Welte70767382018-02-21 12:16:40 +0100258
Harald Weltef8df4cb2018-03-10 15:15:08 +0100259template (value) SystemInformation ts_SI2_default := {
260 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100261 payload := {
262 si2 := {
263 bcch_freq_list := '00000000000000000000000000000000'O,
264 ncc_permitted := '11111111'B,
265 rach_control := ts_RachCtrl_default
266 }
267 }
268}
269
Harald Weltef8df4cb2018-03-10 15:15:08 +0100270template (value) SystemInformation ts_SI4_default := {
271 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100272 payload := {
273 si4 := {
274 lai := ts_LAI_default,
275 cell_sel_par := ts_CellSelPar_default,
276 rach_control := ts_RachCtrl_default,
277 cbch_chan_desc := omit,
278 cbch_mobile_alloc := omit,
279 rest_octets := ''O
280 }
281 }
282}
283
284function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
285runs on test_CT {
286 log("Setting ", rsl_si_type, ": ", si_enc);
287 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
288}
289
290function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
291runs on test_CT {
292 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
293 log("Setting ", rsl_si_type, ": ", si_dec);
294 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
295}
296
Harald Welte505cf9b2018-09-15 17:47:23 +0300297friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100298 map(self:BTSVTY, system:BTSVTY);
299 f_vty_set_prompts(BTSVTY);
300 f_vty_transceive(BTSVTY, "enable");
301}
302
Harald Welte505cf9b2018-09-15 17:47:23 +0300303friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200304 map(self:BSCVTY, system:BSCVTY);
305 f_vty_set_prompts(BSCVTY, "OsmoBSC");
306 f_vty_transceive(BSCVTY, "enable");
307}
308
Harald Welte883340c2018-02-28 18:59:29 +0100309/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200310private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
311 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100312 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200313 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
314 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100315 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200316 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100318 }
319}
320
Harald Weltef26de0b2018-04-04 20:28:05 +0200321private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
322 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100323 timer T := 2.0;
324 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100325 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200326 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100327 return;
328 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200329 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100330
331 T.start;
332 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200333 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100334 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100336 }
337 }
338}
339
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700340private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
341 out integer trxc_conn_id) {
342 var Result res;
343
344 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
345 "", -1, -1, { udp := {} }, {});
346 if (not ispresent(res.connId)) {
347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
348 "Could not connect to the control (TRXC) interface " &
349 "of FakeTRX, check your configuration");
350 }
351 trxc_conn_id := res.connId;
352}
353
Harald Welte70767382018-02-21 12:16:40 +0100354/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200355function f_init() runs on test_CT {
356 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100357 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100358 g_AllChannels := {
359 /* TS 1..4: TCH/F */
360 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
361 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
362 /* TS 5: TCH/H */
363 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
364 /* TS 0: SDCCH/4 */
365 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
366 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
367 /* TS 6: SDCCH/8 */
368 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
369 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
370 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
371 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
372 };
373
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200374 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700375 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200376 g_AllChanTypes := {
377 /* TS 1..4: TCH/F */
378 valueof(ts_RslChanNr_Bm(1)),
379 /* TS 5: TCH/H */
380 valueof(ts_RslChanNr_Lm(5,1)),
381 /* TS 0: SDCCH/4 */
382 valueof(ts_RslChanNr_SDCCH4(0,2)),
383 /* TS 6: SDCCH/8 */
384 valueof(ts_RslChanNr_SDCCH8(6,4))
385 };
386 } else {
387 g_AllChanTypes := {
388 /* TS 1..4: TCH/F */
389 valueof(ts_RslChanNr_Bm(1)),
390 /* TS 0: SDCCH/4 */
391 valueof(ts_RslChanNr_SDCCH4(0,2)),
392 /* TS 6: SDCCH/8 */
393 valueof(ts_RslChanNr_SDCCH8(6,4))
394 };
395 }
Harald Welte70767382018-02-21 12:16:40 +0100396 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200397 T.start;
398 alt {
399 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
400 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200402 }
403 }
Harald Welte2d142592018-02-25 13:19:44 +0100404 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100405 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200406 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100407
408 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100409 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
410 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
411 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
412 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100413
Harald Weltef26de0b2018-04-04 20:28:05 +0200414 map(self:PCU, system:PCU);
415 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100416
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700417 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100418 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700419
420 /* Init TRXC interface to FakeTRX */
421 map(self:BTS_TRXC, system:BTS_TRXC);
422 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
423
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700424 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700425 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 +0700426 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700427 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
428 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100429 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200430
431 /* Wait some extra time to make sure the BTS emits a stable carrier.
432 * (this is only relevant when running the tests with a physical BTS.) */
433 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100434}
435
Harald Welte68e495b2018-02-25 00:05:57 +0100436/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
437function f_init_l1ctl() runs on test_CT {
438 map(self:L1CTL, system:L1CTL);
439 f_connect_reset(L1CTL);
440}
441
Harald Welte70767382018-02-21 12:16:40 +0100442type function void_fn(charstring id) runs on ConnHdlr;
443
444/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700445function f_start_handler(void_fn fn, ConnHdlrPars pars,
446 boolean pcu_comp := false,
447 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100448runs on test_CT return ConnHdlr {
449 var charstring id := testcasename();
450 var ConnHdlr vc_conn;
451
452 vc_conn := ConnHdlr.create(id);
453 /* connect to RSL Emulation main component */
454 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
455 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700456
457 /* The ConnHdlr component may want to talk to some ports directly,
458 * so we disconnect it from the test_CT and connect it to the component.
459 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200461 unmap(self:PCU, system:PCU);
462 map(vc_conn:PCU, system:PCU);
463 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700464 if (trxc_comp) {
465 unmap(self:BTS_TRXC, system:BTS_TRXC);
466 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
467 }
Harald Welte70767382018-02-21 12:16:40 +0100468
469 vc_conn.start(f_handler_init(fn, id, pars));
470 return vc_conn;
471}
472
Harald Welte7484fc42018-02-24 14:09:45 +0100473template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
474 streamId := sid,
475 rsl := rsl
476}
477
478template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
479 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
480 streamId := sid,
481 rsl := rsl
482}
483
Harald Welte70767382018-02-21 12:16:40 +0100484private altstep as_Tguard() runs on ConnHdlr {
485 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100487 }
488}
489
Harald Welte990a3612019-05-27 14:02:13 +0200490friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
491 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100492}
493
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700494private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100495 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700496 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100497}
498
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700499private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100500 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700501 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100502}
503
504/* first function started in ConnHdlr component */
505private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
506runs on ConnHdlr {
507 g_pars := pars;
508 g_chan_nr := pars.chan_nr;
509
510 map(self:L1CTL, system:L1CTL);
511 f_connect_reset(L1CTL);
512
Harald Welted48c0c72019-06-05 10:01:15 +0200513 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700514 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100515 }
Harald Welte70767382018-02-21 12:16:40 +0100516
517 g_Tguard.start(pars.t_guard);
518 activate(as_Tguard());
519
520 f_rslem_register(0, pars.chan_nr);
521
522 /* call the user-supplied test case function */
523 fn.apply(id);
524}
525
Harald Welteb1726c92018-03-30 11:56:38 +0200526function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
527 boolean ignore_other := false)
528runs on ConnHdlr return RSL_Message {
529 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100530 timer T := 3.0;
531 RSL.send(tx);
532 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100533 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200534 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100535 T.stop;
536 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100537 }
Harald Welte1eba3742018-02-25 12:48:14 +0100538 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100540 }
Harald Welte21240e62018-03-11 21:43:35 +0100541 [not ignore_other] as_l1_sacch();
542 [not ignore_other] as_meas_res();
543 [not ignore_other] as_l1_dcch();
544 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100546 }
Harald Welte21240e62018-03-11 21:43:35 +0100547 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100548 }
Harald Welteb1726c92018-03-30 11:56:38 +0200549 return rx;
550}
551
552function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
553 boolean ignore_other := false)
554runs on ConnHdlr {
555 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100556}
557
Harald Welte8b01c792019-05-19 22:51:25 +0200558function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
559 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
560 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200561 if (encr_enable) {
562 /* append encryption related IEs, if requested */
563 var RSL_IE_EncryptionInfo encr_info;
564 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
565 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
566encr_info})) };
567 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200568 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200569 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100570}
571
Harald Welte70767382018-02-21 12:16:40 +0100572function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100573 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 +0100574 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100575}
576
Harald Welte2f2b2b72019-05-31 22:24:57 +0200577friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100578 template RSL_IE_ChannelMode chan_mode,
579 float t_guard := 20.0) := {
580 chan_nr := valueof(chan_nr),
581 chan_mode := valueof(chan_mode),
582 t_guard := t_guard,
583 l1_pars := {
584 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100585 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100586 meas_ul := {
587 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200588 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100589 rxqual := 0
590 },
591 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200592 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100593 rxqual := 0
594 }
595 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200596 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100597 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200598 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200599 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100600 },
Harald Weltee613f962018-04-18 22:38:16 +0200601 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200602 encr := omit,
603 bts0_band := omit
Harald Welte70767382018-02-21 12:16:40 +0100604}
605
Harald Welte93640c62018-02-25 16:59:33 +0100606/***********************************************************************
607 * Channel Activation / Deactivation
608 ***********************************************************************/
609
Harald Welte70767382018-02-21 12:16:40 +0100610/* Stress test: Do 500 channel activations/deactivations in rapid succession */
611function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
612 for (var integer i := 0; i < 500; i := i+1) {
613 f_rsl_chan_act(g_pars.chan_mode);
614 f_rsl_chan_deact();
615 }
616 setverdict(pass);
617}
618testcase TC_chan_act_stress() runs on test_CT {
619 var ConnHdlr vc_conn;
620 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200621 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100622 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
623 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100625}
626
627/* Test if re-activation of an already active channel fails as expected */
628function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
629 f_rsl_chan_act(g_pars.chan_mode);
630 /* attempt to activate the same lchan again -> expect reject */
631 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
632 alt {
633 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100635 }
636 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
637 setverdict(pass);
638 }
639 }
640 f_rsl_chan_deact();
641}
642testcase TC_chan_act_react() runs on test_CT {
643 var ConnHdlr vc_conn;
644 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100645 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100646 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
647 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* Attempt to de-activate a channel that's not active */
652function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
653 timer T := 3.0;
654 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
655 T.start;
656 alt {
657 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
658 setverdict(pass);
659 }
660 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100662 }
663 }
664}
665testcase TC_chan_deact_not_active() runs on test_CT {
666 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100667 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100668 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
669 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100671}
672
673/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
674function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
675 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
676 alt {
677 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100679 }
680 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
681 setverdict(pass);
682 }
683 }
684}
685private type record WrongChanNrCase {
686 RslChannelNr chan_nr,
687 charstring description
688}
689private type record of WrongChanNrCase WrongChanNrCases;
690private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
691 chan_nr := chan_nr,
692 description := desc
693}
694
695testcase TC_chan_act_wrong_nr() runs on test_CT {
696 var ConnHdlr vc_conn;
697 var ConnHdlrPars pars;
698
Harald Welte294b0a22018-03-10 23:26:48 +0100699 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100700
701 var WrongChanNrCases wrong := {
702 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
703 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
704 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
705 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
706 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
707 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
708 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
709 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
710 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
711 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
712 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
713 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
714 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
715 };
716
717 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
718 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
719 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
720 vc_conn.done;
721 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100723}
724
Harald Weltee613f962018-04-18 22:38:16 +0200725/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200726friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200727 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200728 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200729
730 /* test on each of the channels we have */
731 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
732 pars.chan_nr := valueof(g_AllChanTypes[i]);
733
734 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
735 vc_conn := f_start_handler(fn, pars);
736 vc_conn.done;
737 }
738
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200740}
741
Harald Welte93640c62018-02-25 16:59:33 +0100742/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100743 * SACCH handling
744 ***********************************************************************/
745
746private function f_exp_sacch(boolean exp) runs on ConnHdlr {
747 timer T_sacch := 3.0;
748 T_sacch.start;
749 alt {
750 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100752 }
753 [not exp] T_sacch.timeout {
754 setverdict(pass);
755 }
756 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
757 setverdict(pass);
758 }
759 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100761 }
762 [] L1CTL.receive { repeat; }
763 [] RSL.receive { repeat; }
764 }
765}
766
767/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
768private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
769 f_l1_tune(L1CTL);
770 RSL.clear;
771
772 /* activate the logical channel */
773 f_est_dchan();
774 L1CTL.clear;
775
776 /* check that SACCH actually are received as expected */
777 f_exp_sacch(true);
778
779 /* deactivate SACCH on the logical channel */
780 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
781 f_sleep(1.0);
782 L1CTL.clear;
783
784 /* check that no SACCH are received anymore */
785 f_exp_sacch(false);
786
787 /* release the channel */
788 f_rsl_chan_deact();
789 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
790}
791testcase TC_deact_sacch() runs on test_CT {
792 var ConnHdlr vc_conn;
793 var ConnHdlrPars pars;
794 f_init();
795 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
796 //for (var integer i := 0; i < 1; i := i+1) {
797 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
798 log(testcasename(), ": Starting for ", g_AllChannels[i]);
799 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
800 vc_conn.done;
801 }
802 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100804}
805
Harald Welte55700662018-03-12 13:15:43 +0100806/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100807private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
808 var L1ctlDlMessage dl;
809 /* check that the specified SI5 value is actually sent */
810 timer T_sacch := 3.0;
811 L1CTL.clear;
812 T_sacch.start;
813 alt {
814 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
815 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
816 if (match(l3, l3_exp)) {
817 setverdict(pass);
818 } else {
819 repeat;
820 }
821 }
822 [] L1CTL.receive { repeat; }
823 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100825 }
826 }
827}
828
Harald Welte55700662018-03-12 13:15:43 +0100829/* verify that given SACCH payload is not present */
830private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
831 var L1ctlDlMessage dl;
832 /* check that the specified SI5 value is actually sent */
833 timer T_sacch := 3.0;
834 L1CTL.clear;
835 T_sacch.start;
836 alt {
837 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
838 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
839 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100841 } else {
842 repeat;
843 }
844 }
845 [] L1CTL.receive { repeat; }
846 [] T_sacch.timeout {
847 setverdict(pass);
848 }
849 }
850}
851
Harald Welte629cc6b2018-03-11 17:19:05 +0100852/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100853private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
854 /* Set a known default SACCH filling for SI5 */
855 var octetstring si5 := f_rnd_octstring(19);
856 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
857
858 f_l1_tune(L1CTL);
859 RSL.clear;
860
861 /* activate the logical channel */
862 f_est_dchan();
863
864 /* check that the specified SI5 value is actually sent */
865 f_sacch_present(si5);
866
867 /* release the channel */
868 RSL.clear;
869 f_rsl_chan_deact();
870 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
871}
872testcase TC_sacch_filling() runs on test_CT {
873 var ConnHdlr vc_conn;
874 var ConnHdlrPars pars;
875 f_init();
876 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
877 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
878 log(testcasename(), ": Starting for ", g_AllChannels[i]);
879 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
880 vc_conn.done;
881 }
882 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100884}
885
Harald Welte629cc6b2018-03-11 17:19:05 +0100886/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100887private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
888 /* Set a known default SACCH filling for SI5 */
889 var octetstring si5 := f_rnd_octstring(19);
890 var octetstring si5_diff := f_rnd_octstring(19);
891 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
892
893 f_l1_tune(L1CTL);
894 RSL.clear;
895
896 log("Activating channel, expecting standard SI5");
897 /* activate the logical channel */
898 f_est_dchan();
899 /* check that the specified SI5 value is actually sent */
900 f_sacch_present(si5);
901
902 /* set channel-specific different SI5 */
903 log("Setting channel specific SACCH INFO, expecting it");
904 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
905 /* check that the specified lchan-specific value is now used */
906 f_sacch_present(si5_diff);
907
908 /* deactivate the channel and re-activate it, this should result in default SI5 */
909 log("De-activating and re-activating channel, expecting standard SI5");
910 f_rsl_chan_deact();
911 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
912 /* Verify that the TRX-wide default SACCH filling is present again */
913 f_sacch_present(si5);
914
915 /* release the channel */
916 RSL.clear;
917 f_rsl_chan_deact();
918 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
919}
920testcase TC_sacch_info_mod() runs on test_CT {
921 var ConnHdlr vc_conn;
922 var ConnHdlrPars pars;
923 f_init();
924 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
925 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
926 log(testcasename(), ": Starting for ", g_AllChannels[i]);
927 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
928 vc_conn.done;
929 }
930 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100932}
933
Harald Welte075d84c2018-03-12 13:07:24 +0100934/* Test SACCH scheduling of multiple different SI message types */
935private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
936 var octetstring si5 := f_rnd_octstring(19);
937 var octetstring si5bis := f_rnd_octstring(19);
938 var octetstring si5ter := f_rnd_octstring(19);
939 var octetstring si6 := f_rnd_octstring(19);
940
941 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
942 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
943 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
944 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
945
946 f_l1_tune(L1CTL);
947 RSL.clear;
948
949 /* activate the logical channel */
950 f_est_dchan();
951 L1CTL.clear;
952
953 /* check that SACCH actually are received as expected */
954 f_sacch_present(si5);
955 f_sacch_present(si5bis);
956 f_sacch_present(si5ter);
957 f_sacch_present(si6);
958
959 /* release the channel */
960 f_rsl_chan_deact();
961 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
962}
963testcase TC_sacch_multi() runs on test_CT {
964 var ConnHdlr vc_conn;
965 var ConnHdlrPars pars;
966 f_init();
967 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
968 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
969 log(testcasename(), ": Starting for ", g_AllChannels[i]);
970 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
971 vc_conn.done;
972 }
973 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100975}
976
Harald Welte55700662018-03-12 13:15:43 +0100977/* Test if SACH information is modified as expected */
978private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
979 var octetstring si5 := f_rnd_octstring(19);
980 var octetstring si6 := f_rnd_octstring(19);
981
982 /* First, configure both SI5 and SI6 to be transmitted */
983 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
984 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
985
986 f_l1_tune(L1CTL);
987 RSL.clear;
988
989 /* activate the logical channel */
990 f_est_dchan();
991 L1CTL.clear;
992
993 /* check that SACCH actually are received as expected */
994 f_sacch_present(si5);
995 f_sacch_present(si6);
996
997 /* disable SI6 */
998 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
999
1000 /* check that SI5 is still transmitted */
1001 f_sacch_present(si5);
1002 /* check if SI6 is now gone */
1003 f_sacch_missing(si6);
1004
1005 /* release the channel */
1006 f_rsl_chan_deact();
1007 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1008}
1009testcase TC_sacch_multi_chg() runs on test_CT {
1010 var ConnHdlr vc_conn;
1011 var ConnHdlrPars pars;
1012 f_init();
1013 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1014 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1015 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1016 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1017 vc_conn.done;
1018 }
1019 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001021}
1022
Harald Weltec8d363c2019-05-19 20:36:48 +02001023/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1024private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1025 var octetstring si5 := f_rnd_octstring(19);
1026 var octetstring si6 := f_rnd_octstring(19);
1027 var octetstring si5_specific := f_rnd_octstring(19);
1028 var octetstring si6_specific := f_rnd_octstring(19);
1029
1030 /* First, configure both SI5 and SI6 to be transmitted */
1031 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1032 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1033
1034 f_l1_tune(L1CTL);
1035 RSL.clear;
1036
1037 /* activate channel with different SACCH filling */
1038 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1039 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1040 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1041 }));
1042 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1043 RSL_IE_Body:{sacch_info := sacch_info})) };
1044 f_est_dchan(more_ies := addl_ies);
1045
1046 /* check that SACCH actually are received as expected */
1047 f_sacch_present(si5_specific);
1048 f_sacch_present(si6_specific);
1049
1050 /* release the channel */
1051 f_rsl_chan_deact();
1052 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1053}
1054testcase TC_sacch_chan_act() runs on test_CT {
1055 var ConnHdlr vc_conn;
1056 var ConnHdlrPars pars;
1057 f_init();
1058
1059 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1060 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1061 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1062 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1063 vc_conn.done;
1064 }
1065 /* TODO: do the above in parallel, rather than sequentially? */
1066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1067}
1068
Harald Welte8b01c792019-05-19 22:51:25 +02001069/* verify that SACCH DL transmission is started only if MS power IE present
1070 * see section 4.1.3 of 3GPP TS 48.058 */
1071private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1072 var octetstring si5 := f_rnd_octstring(19);
1073
1074 f_l1_tune(L1CTL);
1075 RSL.clear;
1076
1077 /* Step 1: Activate ASYNC HO channel without MS power IE */
1078
1079 /* Activate channel on BTS side */
1080 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1081 /* don't perform immediate assignment here, as we're testing non-IA case */
1082 /* enable dedicated mode */
1083 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1084
1085 /* Verify that no DL SACCH is being received */
1086 f_sacch_missing(?);
1087
1088 f_rsl_chan_deact();
1089 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1090
1091
1092 /* Step 2: Activate ASYNC HO channel with MS power IE */
1093
1094 /* Activate channel on BTS side */
1095 var RSL_IE_List addl_ies := {
1096 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1097 };
1098 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1099 /* don't perform immediate assignment here, as we're testing non-IA case */
1100 /* enable dedicated mode */
1101 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1102
1103 /* Verify that DL SACCH is being received */
1104 f_sacch_present(si5);
1105
1106 f_rsl_chan_deact();
1107 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1108}
1109testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1110 var ConnHdlr vc_conn;
1111 var ConnHdlrPars pars;
1112 f_init();
1113
1114 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1115 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1116 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1117 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1118 vc_conn.done;
1119 }
1120 /* TODO: do the above in parallel, rather than sequentially? */
1121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1122}
1123
1124/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1125 * see section 4.1.4 of 3GPP TS 48.058 */
1126private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1127 var octetstring si5 := f_rnd_octstring(19);
1128 var RSL_IE_List addl_ies;
1129
1130 f_l1_tune(L1CTL);
1131 RSL.clear;
1132
1133 /* Step 1: Activate SYNC HO channel without MS power IE */
1134
1135 /* Activate channel on BTS side */
1136 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1137 /* don't perform immediate assignment here, as we're testing non-IA case */
1138 /* enable dedicated mode */
1139 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1140
1141 /* Verify that no DL SACCH is being received */
1142 f_sacch_missing(?);
1143
1144 f_rsl_chan_deact();
1145 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1146
1147
1148 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1149
1150 /* Activate channel on BTS side */
1151 addl_ies := {
1152 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1153 };
1154 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1155 /* don't perform immediate assignment here, as we're testing non-IA case */
1156 /* enable dedicated mode */
1157 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1158
1159 /* Verify that no DL SACCH is being received */
1160 f_sacch_missing(?);
1161
1162 f_rsl_chan_deact();
1163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1164
1165
1166 /* Step 2b: Activate SYNC HO channel with TA IE */
1167
1168 /* Activate channel on BTS side */
1169 addl_ies := {
1170 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1171 };
1172 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1173 /* don't perform immediate assignment here, as we're testing non-IA case */
1174 /* enable dedicated mode */
1175 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1176
1177 /* Verify that no DL SACCH is being received */
1178 f_sacch_missing(?);
1179
1180 f_rsl_chan_deact();
1181 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1182
1183
1184 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1185
1186 /* Activate channel on BTS side */
1187 addl_ies := {
1188 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1189 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1190 };
1191 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1192 /* don't perform immediate assignment here, as we're testing non-IA case */
1193 /* enable dedicated mode */
1194 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1195
1196 /* Verify that DL SACCH is being received */
1197 f_sacch_present(si5);
1198
1199 f_rsl_chan_deact();
1200 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1201}
1202testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1203 var ConnHdlr vc_conn;
1204 var ConnHdlrPars pars;
1205 f_init();
1206
1207 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1208 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1209 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1210 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1211 vc_conn.done;
1212 }
1213 /* TODO: do the above in parallel, rather than sequentially? */
1214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1215}
Harald Welte629cc6b2018-03-11 17:19:05 +01001216
1217
1218/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001219 * RACH Handling
1220 ***********************************************************************/
1221
Harald Welte8c24c2b2018-02-26 08:31:31 +01001222/* like L1SAP_IS_PACKET_RACH */
1223private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001224 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001225 return true;
1226 }
1227 return false;
1228}
1229
1230/* generate a random RACH for circuit-switched */
1231private function f_rnd_ra_cs() return OCT1 {
1232 var OCT1 ra;
1233 do {
1234 ra := f_rnd_octstring(1);
1235 } while (ra_is_ps(ra));
1236 return ra;
1237}
1238
Harald Welte883340c2018-02-28 18:59:29 +01001239/* generate a random RACH for packet-switched */
1240private function f_rnd_ra_ps() return OCT1 {
1241 var OCT1 ra;
1242 do {
1243 ra := f_rnd_octstring(1);
1244 } while (not ra_is_ps(ra));
1245 return ra;
1246}
1247
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001248/* generate a random 11-bit RA (packet-switched only) */
1249private function f_rnd_ra11_ps() return BIT11 {
1250 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1251 return int2bit(ra11, 11);
1252}
1253
Harald Welte8c24c2b2018-02-26 08:31:31 +01001254/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1255testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001256 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001257 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001258 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001259
Harald Welte8c24c2b2018-02-26 08:31:31 +01001260 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001261 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001262 for (var integer i := 0; i < 1000; i := i+1) {
1263 var OCT1 ra := f_rnd_ra_cs();
1264 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1265 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001267 }
1268 fn_last := fn;
1269
1270 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001271 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001272 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001273 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001274 T.stop;
1275 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001276 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001278 }
1279 [] RSL_CCHAN.receive { repeat; }
1280 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001281 test_failed := true;
1282 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001283 }
1284 }
1285 }
Maxba06feb2019-03-05 10:52:46 +01001286 if (test_failed) {
1287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001288 }
Maxba06feb2019-03-05 10:52:46 +01001289 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001291}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001292
1293/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1294testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001295 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001296 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001297 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001298 f_l1_tune(L1CTL);
1299
1300 var GsmFrameNumber fn_last := 0;
1301 for (var integer i := 0; i < 1000; i := i+1) {
1302 var OCT1 ra := f_rnd_ra_cs();
1303 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1304 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001306 }
1307 fn_last := fn;
1308 }
1309 var integer rsl_chrqd := 0;
1310 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001311 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001312 alt {
1313 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1314 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001315 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001316 repeat;
1317 }
1318 [] RSL_CCHAN.receive { repeat; }
1319 [] T.timeout { }
1320 }
1321 if (rsl_chrqd == 1000) {
1322 setverdict(pass);
1323 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001325 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001327}
1328
Harald Welte3453ab42019-05-24 21:19:58 +02001329private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1330 var charstring bts_str := "bts " & int2str(bts_nr);
1331 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1332}
1333
1334/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1335private template integer tr_rach_slots_per_interval := (90 .. 130);
1336
1337/* Expect 0 RACH load on an idle BTS that has just started up */
1338testcase TC_rach_load_idle_thresh0() runs on test_CT {
1339 var ASP_RSL_Unitdata rx_ud;
1340
1341 f_init_vty_bsc();
1342 /* send load indications even at 0% load */
1343 f_vty_load_ind_thresh(0);
1344 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1345 f_sleep(2.0);
1346
1347 f_init();
1348
1349 timer T := 5.0;
1350 T.start;
1351 alt {
1352 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1353 setverdict(pass);
1354 repeat;
1355 }
1356 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1357 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1358 repeat;
1359 }
1360 [] RSL_CCHAN.receive {
1361 repeat;
1362 }
1363 [] T.timeout { }
1364 }
1365
1366 f_vty_load_ind_thresh(10);
1367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1368}
1369
1370/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1371testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1372 var ASP_RSL_Unitdata rx_ud;
1373
1374 f_init_vty_bsc();
1375 f_init();
1376
1377 timer T := 5.0;
1378 T.start;
1379 alt {
1380 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1381 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1382 repeat;
1383 }
1384 [] RSL_CCHAN.receive {
1385 repeat;
1386 }
1387 [] T.timeout {
1388 setverdict(pass);
1389 }
1390 }
1391
1392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1393}
1394
1395/* Expect 0 RACH load on an idle BTS that has just started up */
1396testcase TC_rach_load_count() runs on test_CT {
1397 var ASP_RSL_Unitdata rx_ud;
1398 var integer load_access_count := 0;
1399
1400 f_init_vty_bsc();
1401 /* send load indications even at 0% load */
1402 f_vty_load_ind_thresh(0);
1403 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1404 f_sleep(2.0);
1405 f_init();
1406
1407 f_init_l1ctl();
1408 f_sleep(1.0);
1409 f_l1_tune(L1CTL);
1410
1411 var GsmFrameNumber fn_last := 0;
1412 for (var integer i := 0; i < 1000; i := i+1) {
1413 var OCT1 ra := f_rnd_ra_cs();
1414 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1415 if (fn == fn_last) {
1416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1417 }
1418 fn_last := fn;
1419 }
1420
1421 timer T := 5.0;
1422 T.start;
1423 alt {
1424 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1425 -> value rx_ud {
1426 var RSL_IE_Body ie;
1427 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1428 load_access_count := load_access_count + ie.rach_load.access_count;
1429 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1430 setverdict(fail, "Access count cannot be < Busy count");
1431 }
1432 repeat;
1433 }
1434 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1435 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1436 repeat;
1437 }
1438 [] RSL_CCHAN.receive {
1439 repeat;
1440 }
1441 [] T.timeout { }
1442 }
1443 if (load_access_count == 1000) {
1444 setverdict(pass);
1445 } else {
1446 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1447 }
1448
1449 f_vty_load_ind_thresh(10);
1450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1451}
1452
Harald Welte54a2a2d2018-02-26 09:14:05 +01001453private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001454 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001455 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001456 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001457 f_sleep(0.5);
1458
1459 /* Transmit RACH request + wait for confirmation */
1460 var OCT1 ra := f_rnd_ra_cs();
1461 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1462
1463 /* Check for expected result */
1464 timer T := 1.5;
1465 T.start;
1466 alt {
1467 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1468 setverdict(pass);
1469 }
1470 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001472 }
1473 [] RSL_CCHAN.receive { repeat; }
1474 [not expect_pass] T.timeout {
1475 setverdict(pass);
1476 }
1477 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001479 }
1480 }
1481}
1482
1483/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1484testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001485 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001486 f_init_l1ctl();
1487 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001488 f_sleep(1.0);
1489
1490 /* default max-ta is 63 (full range of GSM timing advance */
1491
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001492 /* We allow early arrival up to 2 symbols */
1493 f_rach_toffs(-1*256, true);
1494 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001495 f_rach_toffs(-10*256, false);
1496
1497 /* 0 / 32 / 63 bits is legal / permitted */
1498 f_rach_toffs(0, true);
1499 f_rach_toffs(32*256, true);
1500 f_rach_toffs(63*256, true);
1501
1502 /* more than 63 bits is not legal / permitted */
1503 f_rach_toffs(64*256, false);
1504 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001506}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001507
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001508function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1509 var GsmFrameNumber fn;
1510 var RSL_Message rm;
1511
1512 f_l1_tune(L1CTL);
1513 RSL.clear;
1514
1515 /* Generate a random Handover Reference */
1516 var integer ho_ref := oct2int(f_rnd_octstring(1));
1517
1518 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1519 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1520 RSL_IE_Body:{ handover_ref := ho_ref }));
1521
1522 /* Activate a channel on the BTS side (no encryption) */
1523 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1524 act_type := t_RSL_IE_ActType_HO_SYNC);
1525
1526 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1527 * waiting for Immediate Assignment and sending Access Burst */
1528 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1529
1530 /* Send handover Access Burst */
1531 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1532
1533 /* TODO: test mismatching Handover Reference, and missing IE */
1534
1535 /* Wait for handover detection */
1536 timer T := 3.0;
1537 T.start;
1538 alt {
1539 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1540 log("Handover RACH has been detected: ", rm);
1541 setverdict(pass);
1542 }
1543 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1545 log2str("RSL_CHAN_RQD was not expected: ", rm));
1546 }
1547 [] RSL.receive { repeat; }
1548 [] T.timeout {
1549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1550 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1551 }
1552 }
1553
1554 /* Release the channel */
1555 f_rsl_chan_deact();
1556 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1557}
1558
1559/* Test handover RACH detection */
1560testcase TC_ho_rach() runs on test_CT {
1561 var ConnHdlrPars pars;
1562 var ConnHdlr vc_conn;
1563
1564 f_init();
1565
1566 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1567 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1568 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1569 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1570 vc_conn.done;
1571 }
1572
1573 /* TODO: do the above in parallel, rather than sequentially? */
1574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1575}
1576
Harald Welte93640c62018-02-25 16:59:33 +01001577/***********************************************************************
1578 * Measurement Processing / Reporting
1579 ***********************************************************************/
1580
Harald Welte70767382018-02-21 12:16:40 +01001581template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1582 spare := '0'B,
1583 lpd := 0,
1584 sapi := sapi,
1585 c_r := c_r,
1586 ea := true
1587}
1588
Harald Welted879bd92018-03-12 15:01:23 +01001589template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001590 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001591 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001592 len := 0, /* overwritten */
1593 m := false,
1594 el := 1,
1595 payload := pl
1596}
1597
1598/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1599altstep as_l1_sacch() runs on ConnHdlr {
1600 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001601 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001602 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001603 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 +01001604 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001605 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001606
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001607 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1608 g_pars.l1_pars.ms_power_level, false,
1609 g_pars.l1_pars.ms_actual_ta);
1610
1611 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1612 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1613
1614 log("Sending Measurement Report: ", l1h, l2);
1615 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001616 repeat;
1617 }
1618}
1619
1620altstep as_l1_dcch() 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_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001623 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1624 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001625 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1626 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001627 repeat;
1628 }
1629}
1630
1631type record MeasElem {
1632 uint6_t rxlev,
1633 uint3_t rxqual
1634}
1635
1636type record MeasElemFS {
1637 MeasElem full,
1638 MeasElem sub
1639}
1640
1641type record ConnL1Pars {
1642 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001643 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001644 MeasElemFS meas_ul,
1645 int16_t timing_offset_256syms,
1646 uint5_t bs_power_level,
1647 uint5_t ms_power_level,
1648 uint8_t ms_actual_ta
1649}
1650
1651/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1652private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1653 return 63 + (toffs256s/256);
1654}
1655
Harald Welted5684392018-03-10 18:22:04 +01001656private function f_max(integer a, integer b) return integer {
1657 if (a > b) {
1658 return a;
1659 } else {
1660 return b;
1661 }
1662}
1663
1664private function f_min(integer a, integer b) return integer {
1665 if (a < b) {
1666 return a;
1667 } else {
1668 return b;
1669 }
1670}
1671
1672/* compute negative tolerance val-tolerance, ensure >= min */
1673private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1674 val := val - tolerance;
1675 return f_max(val, min);
1676}
1677
1678/* compute positive tolerance val+tolerance, ensure <= max */
1679private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1680 val := val + tolerance;
1681 return f_min(val, max);
1682}
1683
1684/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1685private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1686return template integer {
1687 var template integer ret;
1688 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1689 return ret;
1690}
1691
1692
Harald Welte70767382018-02-21 12:16:40 +01001693/* build a template for matching measurement results against */
1694private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1695 var ConnL1Pars l1p := g_pars.l1_pars;
1696 var template RSL_IE_UplinkMeas ul_meas := {
1697 len := 3,
1698 rfu := '0'B,
1699 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001700 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001701 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001702 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001703 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001704 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1705 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001706 supp_meas_info := omit
1707 };
Harald Welte685d5982018-02-27 20:42:05 +01001708 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001709 ul_meas.len := (3+8);
1710 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001711 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001712 toa256_min := ?,
1713 toa256_max := ?,
1714 toa256_std_dev := ?
1715 }
Harald Welte685d5982018-02-27 20:42:05 +01001716 }
Harald Welte70767382018-02-21 12:16:40 +01001717 var template RSL_IE_BS_Power bs_power := {
1718 reserved := 0,
1719 epc := false,
1720 fpc := false,
1721 power_level := l1p.bs_power_level
1722 };
1723 var template RSL_IE_L1Info l1_info := {
1724 ms_power_lvl := l1p.ms_power_level,
1725 fpc := false,
1726 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001727 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001728 };
1729 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001730 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001731 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1732 ?, t_toffs);
1733}
1734
Philipp Maierdd841d32019-12-17 14:44:54 +01001735/* build a template for matching measurement results that do not contain any
1736 * MS related measurement (l1_info, l3_info and ms timing offset). */
1737private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1738 var ConnL1Pars l1p := g_pars.l1_pars;
1739 var template RSL_IE_UplinkMeas ul_meas := {
1740 len := 3,
1741 rfu := '0'B,
1742 dtx_d := l1p.dtx_enabled,
1743 rxlev_f_u := ?,
1744 reserved1 := '00'B,
1745 rxlev_s_u := ?,
1746 reserved2 := '00'B,
1747 rxq_f_u := ?,
1748 rxq_s_u := ?,
1749 supp_meas_info := omit
1750 };
1751 if (l1p.toa256_enabled) {
1752 ul_meas.len := (3+8);
1753 ul_meas.supp_meas_info := {
1754 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1755 toa256_min := ?,
1756 toa256_max := ?,
1757 toa256_std_dev := ?
1758 }
1759 }
1760 var template RSL_IE_BS_Power bs_power := {
1761 reserved := 0,
1762 epc := false,
1763 fpc := false,
1764 power_level := l1p.bs_power_level
1765 };
1766
1767 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1768}
1769
Harald Welte70767382018-02-21 12:16:40 +01001770/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001771altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001772 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001773 var boolean chan_est := false;
1774
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001775 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001776
1777 /* Receive osmocom specific measurement reports. This is the normal
1778 * case. Here we verify that the measurement reports we sent are
1779 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001780 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1781 /* increment counter of next to-be-expected meas rep */
1782 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1783 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001784 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001785
1786 /* The following two cases may only happen in the beginning
1787 * of the channel establishment phase. Once we have received
1788 * the "our" measurement report the first time, the channel
1789 * is established and empty or hardcoded TRXCON reports must
1790 * not occur anymore. */
1791 chan_est := true;
1792
1793 repeat;
1794 }
1795
1796 /* When the BTS has established the channel, the MS might need slightly
1797 * more time to establish the channel and actually start sending. The
1798 * result is then a measurement report that just lacks the measurement
1799 * information of the MS. This is normal and we tolerate this behavior. */
1800 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1801 /* increment counter of next to-be-expected meas rep */
1802 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1803 /* Re-start the timer expecting the next MEAS RES */
1804 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001805 repeat;
1806 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001807
1808 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1809 * measurements if the TTCN3 side does not supply measurement input in
1810 * time. In those cases TRXCON will either use a cached measurement
1811 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1812 * report the templates above will not match. We tolerate this
1813 * behavior, but only once. */
1814 [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 +01001815 /* increment counter of next to-be-expected meas rep */
1816 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1817 if (g_first_meas_res) {
1818 g_first_meas_res := false;
1819 repeat;
1820 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001822 }
Harald Welte70767382018-02-21 12:16:40 +01001823 }
1824 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001826 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001827 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001829 }
1830}
1831
Harald Weltee613f962018-04-18 22:38:16 +02001832private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1833 select (rsl_alg_id) {
1834 case (RSL_ALG_ID_A5_0) { return 0; }
1835 case (RSL_ALG_ID_A5_1) { return 1; }
1836 case (RSL_ALG_ID_A5_2) { return 2; }
1837 case (RSL_ALG_ID_A5_3) { return 3; }
1838 case (RSL_ALG_ID_A5_4) { return 4; }
1839 case (RSL_ALG_ID_A5_5) { return 5; }
1840 case (RSL_ALG_ID_A5_6) { return 6; }
1841 case (RSL_ALG_ID_A5_7) { return 7; }
1842 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1844 /* Make compiler happy by calling mtc.stop here. It is already
1845 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001846 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001847 }
1848 }
1849}
1850
1851private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1852 select (rsl_alg_id) {
1853 case (RSL_ALG_ID_A5_1) { return '000'B; }
1854 case (RSL_ALG_ID_A5_2) { return '001'B; }
1855 case (RSL_ALG_ID_A5_3) { return '010'B; }
1856 case (RSL_ALG_ID_A5_4) { return '011'B; }
1857 case (RSL_ALG_ID_A5_5) { return '100'B; }
1858 case (RSL_ALG_ID_A5_6) { return '101'B; }
1859 case (RSL_ALG_ID_A5_7) { return '110'B; }
1860 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1862 /* Make compiler happy by calling mtc.stop here. It is already
1863 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001864 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001865 }
1866 }
1867}
1868
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001869/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1870private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1871 var GsmFrameNumber fn;
1872 timer T := 8.0;
1873
1874 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1875 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1876
1877 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1878 /* Send the actual RACH */
1879 fn := f_L1CTL_RACH(L1CTL, ra);
1880
1881 T.start;
1882 alt {
1883 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1884 [] T.timeout {
1885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1886 }
1887 }
1888 T.stop
1889 return fn;
1890}
Harald Weltee613f962018-04-18 22:38:16 +02001891
Harald Welte70767382018-02-21 12:16:40 +01001892/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001893private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001894 var GsmFrameNumber fn;
1895 var ImmediateAssignment imm_ass;
1896 var integer ra := 23;
1897
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001898 /* Send RACH request and wait for ChanReq */
1899 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001900
1901 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001902 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001903
1904 /* Send IMM.ASS via CCHAN */
1905 var ChannelDescription ch_desc := {
1906 chan_nr := g_pars.chan_nr,
1907 tsc := 7,
1908 h := false,
1909 arfcn := mp_trx0_arfcn,
1910 maio_hsn := omit
1911 };
1912 var MobileAllocation ma := {
1913 len := 0,
1914 ma := ''B
1915 };
1916 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1917 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1918
1919 /* receive IMM.ASS on MS side */
1920 var ImmediateAssignment ia_um;
1921 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1922 /* enable dedicated mode */
1923 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001924 /* enable encryption, if requested */
1925 if (encr_enable) {
1926 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1927 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1928 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001929
1930 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001931}
1932
1933/* establish DChan, verify existance + contents of measurement reports */
1934function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001935 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001936 RSL.clear;
1937
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001938 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001939 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001940 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001941 }
Harald Welte70767382018-02-21 12:16:40 +01001942
1943 f_est_dchan();
1944
1945 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1946 * RSL measurement reports on Abis side */
1947 timer T := 8.0;
1948 T.start;
1949 alt {
1950 [] as_l1_sacch();
1951 [] as_meas_res();
1952 [] as_l1_dcch();
1953 [] L1CTL.receive { repeat; }
1954 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001955 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001956 * of any earlier errors, so if we reach this timeout, we're good */
1957 setverdict(pass);
1958 }
1959 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001961 }
1962 }
1963 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001964 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001965}
Harald Welte0472ab42018-03-12 15:02:26 +01001966
Eric Wildae8f2622019-06-18 17:05:11 +02001967function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
1968 timer T := 8.0;
1969 T.start;
1970 var RSL_Message rsl;
1971 alt {
1972 [] as_l1_sacch();
1973 [] L1CTL.receive { repeat; }
1974 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
1975 if (rsl.ies[3].body.bs_power.power_level == level) {
1976 setverdict(pass)
1977 } else {
1978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
1979 }
1980 }
1981 [] T.timeout {
1982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
1983 }
1984 }
1985}
1986
1987/* see if the rsl meas res contains our expeced bs power level
1988bs power set during assignment */
1989function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
1990 f_l1_tune(L1CTL);
1991 RSL.clear;
1992
1993 if (mp_bts_trxc_port != -1) {
1994 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
1995 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1996 }
1997
1998 var uint5_t pwr_var := 1;
1999 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2000 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2001
2002 f_est_dchan(more_ies :={valueof(pwr)});
2003
2004 f_check_meas_bs_power_level(pwr_var);
2005
2006 f_rsl_chan_deact();
2007 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2008}
2009
2010/* see if the rsl meas res contains our expeced bs power level
2011bs power set after assignment */
2012function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2013 f_l1_tune(L1CTL);
2014 RSL.clear;
2015
2016 if (mp_bts_trxc_port != -1) {
2017 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2018 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2019 }
2020
2021 var uint5_t pwr_var := 1;
2022 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2023
2024 f_est_dchan();
2025
2026 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2027
2028 f_check_meas_bs_power_level(pwr_var);
2029
2030 f_rsl_chan_deact();
2031 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2032}
2033
2034testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2035 var ConnHdlr vc_conn;
2036 var ConnHdlrPars pars;
2037 f_init();
2038 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2039 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2040 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2041 pcu_comp := false, trxc_comp := true);
2042 vc_conn.done;
2043 }
2044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2045}
2046
2047testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2048 var ConnHdlr vc_conn;
2049 var ConnHdlrPars pars;
2050 f_init();
2051 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2052 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2053 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2054 pcu_comp := false, trxc_comp := true);
2055 vc_conn.done;
2056 }
2057 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2058}
2059
Eric Wild61edb7e2019-06-03 12:38:31 +02002060/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2061second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2062These power levels are valid for all bands and require no special handling */
2063function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2064 var uint5_t pwr_var := 7;
2065 var L1ctlDlMessage l1_dl;
2066
2067 f_trxc_fake_rssi(rxlev2dbm(10));
2068 f_l1_tune(L1CTL);
2069 RSL.clear;
2070
2071 var RSL_IE_List addl_ies;
2072 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2073
2074 addl_ies := {
2075 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2076 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2077 };
2078
2079 /* establish with power parameters */
2080 f_est_dchan(more_ies := addl_ies);
2081
2082 /* set a high value to ensure L1 power control level increases */
2083 f_trxc_fake_rssi(rxlev2dbm(20));
2084
2085 timer T2 := 6.0;
2086 T2.start;
2087 alt {
2088 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002089 /* Update sent MS power to follow what BTS requests */
2090 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2091 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002092 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002093 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002094 T2.stop;
2095 }
2096 [] L1CTL.receive { repeat; }
2097 [] T2.timeout {
2098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2099 "Power Level in L1 header has not increased sufficiently");
2100 }
2101 }
2102
2103 /* set a low value to ensure L1 power control level decreases */
2104 f_trxc_fake_rssi(rxlev2dbm(0));
2105
2106 timer T4 := 6.0;
2107 T4.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) {
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 T4.stop;
2116 setverdict(pass, "Power level in L1 decreased/increased as expected");
2117 }
2118 [] L1CTL.receive { repeat; }
2119 [] T4.timeout {
2120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2121 "Power Level in L1 header has not decreased sufficiently");
2122 }
2123 }
2124
2125 f_rsl_chan_deact();
2126 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2127
2128}
2129
2130/* check that we do not exceed the max power */
2131function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2132 var uint5_t pwr_var := 7;
2133 var L1ctlDlMessage l1_dl;
2134
2135 /* set a low value to ensure power increases */
2136 f_trxc_fake_rssi(rxlev2dbm(10));
2137 f_l1_tune(L1CTL);
2138 RSL.clear;
2139
2140 var RSL_IE_List addl_ies;
2141 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2142
2143 addl_ies := {
2144 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2145 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2146 };
2147
2148 /* establish with power parameters */
2149 f_est_dchan(more_ies := addl_ies);
2150
2151 timer T1 := 10.0;
2152 T1.start;
2153 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002154 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2155 /* Update sent MS power to follow what BTS requests */
2156 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2157 repeat;
2158 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002159 [] L1CTL.receive { repeat; }
2160 [] T1.timeout {
2161 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2162 setverdict(fail, "Power level in L1 header should not have changed");
2163 }
2164 }
2165 }
2166
2167 f_rsl_chan_deact();
2168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2169
2170}
2171
2172/* see if we reach the band max power */
2173function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2174 var L1ctlDlMessage l1_dl;
2175 var uint5_t pwr_var := 15;
2176 var uint5_t pwr_max_var := f_get_max_power_from_band();
2177
2178 /* set a low value to ensure power increases */
2179 f_trxc_fake_rssi(rxlev2dbm(10));
2180 f_l1_tune(L1CTL);
2181 RSL.clear;
2182
2183 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2184 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2185
2186 /* establish with fixed power level */
2187 f_est_dchan(more_ies :={valueof(pwr)});
2188
2189 /* check our initial power level */
2190 f_wait_for_l1_power_level(pwr_var);
2191
2192 /* update power param to enable power loop
2193 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2194 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2195
2196 /* wait, then check that our power level was reduced */
2197 timer T1 := 10.0;
2198 T1.start;
2199 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002200 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2201 /* Update sent MS power to follow what BTS requests */
2202 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2203 repeat;
2204 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002205 [] L1CTL.receive { repeat; }
2206 [] T1.timeout {
2207 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2208 if( f_power_level_is_highest_dbm(rcv) ){
2209 setverdict(pass, "Power level in L1 header reduced as expected");
2210 } else {
2211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2212 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2213 }
2214 }
2215 }
2216
2217 f_rsl_chan_deact();
2218 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2219
2220}
2221
2222/* see if we reach the band min power */
2223function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2224 var L1ctlDlMessage l1_dl;
2225
2226 /* set a high value to ensure power decreases */
2227 f_trxc_fake_rssi(rxlev2dbm(50));
2228 f_l1_tune(L1CTL);
2229 RSL.clear;
2230
2231 var uint5_t pwr_var := 5;
2232 var uint5_t pwr_target_val := 15;
2233
2234 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2235 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2236
2237 /* establish with fixed power level */
2238 f_est_dchan(more_ies :={valueof(pwr)});
2239
2240 /* check our initial power level */
2241 f_wait_for_l1_power_level(pwr_var);
2242
2243 /* update power param to enable power loop
2244 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002245 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002246
2247 /* wait, then check that our power level was increased */
2248 timer T1 := 10.0;
2249 T1.start;
2250 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002251 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2252 /* Update sent MS power to follow what BTS requests */
2253 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2254 repeat;
2255 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002256 [] L1CTL.receive { repeat; }
2257 [] T1.timeout {
2258 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2259 setverdict(pass, "Power level in L1 header increased to lowest power value");
2260 } else {
2261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2262 "Power level in L1 header NOT increased to lowest power value");
2263 }
2264 }
2265 }
2266
2267 f_rsl_chan_deact();
2268 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2269
2270}
2271
Eric Wild095024b2019-06-17 15:08:57 +02002272/* see if we change the power level without receiving power parameters, which should not happen
2273rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002274function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2275 var L1ctlDlMessage l1_dl;
2276
2277 /* set a high value to ensure power decreases */
2278 f_trxc_fake_rssi(rxlev2dbm(50));
2279 f_l1_tune(L1CTL);
2280 RSL.clear;
2281
2282 var uint5_t pwr_var := 5;
2283
2284 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2285 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2286
2287 /* establish with fixed power level */
2288 f_est_dchan(more_ies :={valueof(pwr)});
2289
2290 /* check our initial power level */
2291 f_wait_for_l1_power_level(pwr_var);
2292
2293 /* wait, then check that our power level did not change */
2294 timer T1 := 10.0;
2295 T1.start;
2296 alt {
2297 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2298 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2300 "BS power control should not be active unless we receive a power parameters IE!");
2301 }
2302 repeat;
2303 }
2304 [] L1CTL.receive { repeat; }
2305 [] T1.timeout { setverdict(pass); }
2306 }
2307
2308 f_rsl_chan_deact();
2309 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2310
2311}
2312
Eric Wild095024b2019-06-17 15:08:57 +02002313/* see if we change the power level without receiving power parameters, which should not happen
2314ms power control WITHOUT power parameters */
2315function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2316 var L1ctlDlMessage l1_dl;
2317
2318 /* set a high value to ensure power decreases */
2319 f_trxc_fake_rssi(rxlev2dbm(50));
2320 f_l1_tune(L1CTL);
2321 RSL.clear;
2322
2323 var uint5_t pwr_var := 5;
2324
2325 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2326 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2327
2328 /* establish with fixed power level */
2329 f_est_dchan(more_ies :={valueof(pwr)});
2330
2331 /* check our initial power level */
2332 f_wait_for_l1_power_level(pwr_var);
2333
2334 /* pwr control without power params IE, should NOT activate MS power control*/
2335 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2336
2337 /* wait, then check that our power level did not change */
2338 timer T1 := 10.0;
2339 T1.start;
2340 alt {
2341 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2342 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2344 "BS power control should not be active unless we receive a power parameters IE!");
2345 }
2346 repeat;
2347 }
2348 [] L1CTL.receive { repeat; }
2349 [] T1.timeout { setverdict(pass); }
2350 }
2351
2352 f_rsl_chan_deact();
2353 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2354
2355}
2356
Eric Wild61edb7e2019-06-03 12:38:31 +02002357function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2358 var L1ctlDlMessage l1_dl;
2359 timer T0 := 10.0;
2360 T0.start;
2361 alt {
2362 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2363 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2365 "Power level in L1 header != signaled (RSL) power level.");
2366 }
2367 }
2368 [] L1CTL.receive { repeat; }
2369 [] T0.timeout {
2370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2371 "Timeout waiting for initial power level");
2372 }
2373 }
2374 T0.stop;
2375}
2376
2377private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2378 var IntegerRecord min_dbm_level;
2379 var IntegerRecord max_dbm_level;
2380 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2381
2382 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2383 if (min_dbm_level[i] == level) {
2384 return true;
2385 }
2386 }
2387 return false;
2388}
2389
2390private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2391 var IntegerRecord min_dbm_level;
2392 var IntegerRecord max_dbm_level;
2393 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2394
2395 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2396 if (max_dbm_level[i] == level) {
2397 return true;
2398 }
2399 }
2400 return false;
2401}
2402
2403private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2404 var IntegerRecord min_dbm_level;
2405 var IntegerRecord max_dbm_level;
2406 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2407 return max_dbm_level[0];
2408}
2409
2410type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2411template charstring BtsBand_allGSM:= pattern "GSM???";
2412private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2413 // 45.005 4.1.1
2414 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2415 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2416 2, 1, 0};
2417 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2418 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2419 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2420 var IntegerRecord rv;
2421
2422 select(band){
2423 case (BtsBand_allGSM){
2424 rv := gsm_power;
2425 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2426 max_dbm_level := {2, 1, 0};
2427 }
2428 case("DCS1800"){
2429 rv := dcs_power;
2430 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2431 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2432 }
2433 case("PCS1900"){
2434 rv := pcs_power;
2435 min_dbm_level := {15};
2436 max_dbm_level := {30};
2437 }
2438 }
2439
2440 return rv;
2441}
2442
2443private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2444 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2445}
2446
2447testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2448 var ConnHdlr vc_conn;
2449 var ConnHdlrPars pars;
2450 f_init();
2451 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2452 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2453 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2454 pars.bts0_band := f_vty_get_bts0_band();
2455 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2456 vc_conn.done;
2457 }
2458 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2460}
2461
2462testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2463 var ConnHdlr vc_conn;
2464 var ConnHdlrPars pars;
2465 f_init();
2466 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2467 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2468 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2469 pars.bts0_band := f_vty_get_bts0_band();
2470 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2471 vc_conn.done;
2472 }
2473 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2475}
2476
2477testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2478 var ConnHdlr vc_conn;
2479 var ConnHdlrPars pars;
2480 f_init();
2481 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2482 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2483 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2484 pars.bts0_band := f_vty_get_bts0_band();
2485 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2486 vc_conn.done;
2487 }
2488 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2490}
2491
2492testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2493 var ConnHdlr vc_conn;
2494 var ConnHdlrPars pars;
2495 f_init();
2496 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2497 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2498 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2499 pars.bts0_band := f_vty_get_bts0_band();
2500 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2501 vc_conn.done;
2502 }
2503 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2505}
2506
Eric Wild280ccb82019-06-17 11:11:52 +02002507testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2508 var ConnHdlr vc_conn;
2509 var ConnHdlrPars pars;
2510 f_init();
2511 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2512 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2513 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2514 pars.bts0_band := f_vty_get_bts0_band();
2515 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2516 vc_conn.done;
2517 }
2518 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2520}
2521
Eric Wild095024b2019-06-17 15:08:57 +02002522testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2523 var ConnHdlr vc_conn;
2524 var ConnHdlrPars pars;
2525 f_init();
2526 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2527 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2528 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2529 pars.bts0_band := f_vty_get_bts0_band();
2530 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2531 vc_conn.done;
2532 }
2533 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2535}
2536
Harald Welte70767382018-02-21 12:16:40 +01002537testcase TC_meas_res_sign_tchf() runs on test_CT {
2538 var ConnHdlr vc_conn;
2539 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002540 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002541 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2542 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002543 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2544 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002545 vc_conn.done;
2546 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002548}
2549testcase TC_meas_res_sign_tchh() runs on test_CT {
2550 var ConnHdlr vc_conn;
2551 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002552 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002553 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2554 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002555 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2556 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002557 vc_conn.done;
2558 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002560}
2561testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2562 var ConnHdlr vc_conn;
2563 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002564 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002565 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2566 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002567 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2568 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002569 vc_conn.done;
2570 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002572}
2573testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2574 var ConnHdlr vc_conn;
2575 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002576 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002577 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2578 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002579 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2580 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002581 vc_conn.done;
2582 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002584}
Harald Welte685d5982018-02-27 20:42:05 +01002585testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2586 var ConnHdlr vc_conn;
2587 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002588 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002589 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2590 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2591 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2592 pars.l1_pars.toa256_enabled := true;
2593 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2594 vc_conn.done;
2595 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002597}
2598
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002599/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2600 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2601function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2602 var L1ctlDlMessage l1_dl;
2603 var RSL_IE_MS_Power ms_power;
2604 var RSL_Message rsl;
2605 var uint5_t power_level := 0;
2606
2607 f_l1_tune(L1CTL);
2608 RSL.clear;
2609
2610 f_est_dchan();
2611
2612 ms_power.reserved := 0;
2613 ms_power.fpc_epc := false;
2614
2615 /* Send the first power control command. This will disable any BTS/TRX
2616 * internal power control and switch the MS (which is not in scope of
2617 * this test) to a constant power level. We start with a power level
2618 * of 0 */
2619 ms_power.power_level := power_level;
2620 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2621 RSL.send(rsl);
2622
2623 alt {
2624
2625 /* Pick all SACCH blocks for checking */
2626 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2627
2628 /* The first byte of the L1 header contains the power level.
2629 * The reserved bits and the fpc bit is set to 0, so we may
2630 * compare directly. */
2631 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2632 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2633 }
2634
2635 /* Signal a new power level via RSL for the next turn. */
2636 if (power_level < 31) {
2637 power_level := power_level + 1;
2638 ms_power.power_level := power_level;
2639 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2640 RSL.send(rsl);
2641 repeat;
2642 }
2643
2644 }
2645
2646 /* Ignore all other blocks */
2647 [] L1CTL.receive { repeat; }
2648
2649 }
2650
2651 f_rsl_chan_deact();
2652 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2653
2654 setverdict(pass);
2655}
2656
2657testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2658 var ConnHdlr vc_conn;
2659 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002660 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002661
2662 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2663 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2664 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2665 vc_conn.done;
2666 }
2667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2668}
Harald Welte70767382018-02-21 12:16:40 +01002669
Eric Wild6833cc92019-05-23 19:34:44 +02002670/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2671TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2672function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2673 var L1ctlDlMessage l1_dl;
2674 var uint5_t ta_to_test := 16;
2675
2676
2677 f_l1_tune(L1CTL);
2678 RSL.clear;
2679
2680 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002681 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002682
2683 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2684
2685
2686 alt {
2687
2688 /* Pick all SACCH blocks for checking */
2689 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2690
2691 /* The second byte of the L1 header contains the TA. */
2692 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2693 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2694 }
2695
2696 }
2697
2698 /* Ignore all other blocks */
2699 [] L1CTL.receive { repeat; }
2700
2701 }
2702
2703 f_rsl_chan_deact();
2704 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2705
2706 setverdict(pass);
2707}
2708
2709testcase TC_rsl_chan_initial_ta() runs on test_CT {
2710 var ConnHdlr vc_conn;
2711 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002712 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002713 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002714 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2715 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002716 vc_conn.done;
2717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2718}
2719
Eric Wilde57e1a62019-05-28 13:30:55 +02002720/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2721function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2722 var L1ctlDlMessage l1_dl;
2723 var uint5_t ms_power_level := 7;
2724
2725 var RSL_IE_MS_Power ms_power;
2726 ms_power.reserved := 0;
2727 ms_power.fpc_epc := false;
2728 ms_power.power_level := ms_power_level;
2729
2730 f_l1_tune(L1CTL);
2731 RSL.clear;
2732
2733 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2734
2735 timer T := 1.0;
2736 T.start;
2737 alt {
2738 /* Pick all SACCH blocks for checking */
2739 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2740 /* The first byte of the L1 header contains the power level.. */
2741 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2742 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2743 }
2744 }
2745 /* Ignore all other blocks */
2746 [] L1CTL.receive { repeat; }
2747 [] T.timeout {
2748 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2749 }
2750 }
2751
2752 f_rsl_chan_deact();
2753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2754 setverdict(pass);
2755}
2756
2757testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2758 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2759 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2760}
2761
Harald Welte0472ab42018-03-12 15:02:26 +01002762/* 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 +01002763private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002764 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002765 RSL.clear;
2766
2767 f_est_dchan();
2768 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002769 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002770
2771 timer T := 40.0;
2772 T.start;
2773 alt {
2774 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2775 setverdict(pass)
2776 }
2777 [] RSL.receive { repeat };
2778 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002780 }
2781 }
2782 f_rsl_chan_deact();
2783}
2784testcase TC_conn_fail_crit() runs on test_CT {
2785 var ConnHdlr vc_conn;
2786 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002787 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002788 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2789 pars.t_guard := 60.0;
2790 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2791 vc_conn.done;
2792}
2793
Harald Welte93640c62018-02-25 16:59:33 +01002794/***********************************************************************
2795 * Paging
2796 ***********************************************************************/
2797
Harald Welte68e495b2018-02-25 00:05:57 +01002798function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2799 if (tmsi == 'FFFFFFFF'O) {
2800 return true;
2801 } else {
2802 return false;
2803 }
2804}
Harald Welte70767382018-02-21 12:16:40 +01002805
Philipp Maier82cb0b12018-08-31 14:41:39 +02002806type record allowedFn { integer frame_nr }
2807template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2808template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2809template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2810template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2811template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2812template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2813template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2814template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2815function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2816{
2817 var integer frame_nr_51;
2818 frame_nr_51 := frame_nr mod 51
2819
2820 var allowedFn fn_check;
2821 fn_check.frame_nr := frame_nr_51;
2822
2823 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002825 return;
2826 }
2827
2828 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2829 return;
2830 }
2831 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2832 return;
2833 }
2834 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2835 return;
2836 }
2837 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2838 return;
2839 }
2840 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2841 return;
2842 }
2843 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2844 return;
2845 }
2846 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2847 return;
2848 }
2849 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2850 return;
2851 }
2852
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002854 return;
2855}
2856
2857altstep 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 +01002858runs on test_CT {
2859 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002860 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002861 repeat;
2862 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002863 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002864 var octetstring without_plen :=
2865 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2866 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002867
2868 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2869
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07002870 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
2871 /* Ignore empty RR Paging Request (PCH filling) messages.
2872 * TODO: does it make sense to count them? */
2873 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002874 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2875 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002876 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002877 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2878 }
2879 } else if (match(rr, tr_PAGING_REQ2)) {
2880 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2881 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2882 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2883 }
2884 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2885 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2886 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002887 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2889 }
2890 } else if (match(rr, tr_PAGING_REQ3)) {
2891 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2892 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2893 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2894 }
2895 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2896 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2897 }
2898 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2899 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2900 }
2901 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2902 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2903 }
2904 }
2905 repeat;
2906 }
2907}
2908
2909type record PagingTestCfg {
2910 boolean combined_ccch,
2911 integer bs_ag_blks_res,
2912 float load_factor,
2913 boolean exp_load_ind,
2914 boolean exp_overload,
2915 boolean use_tmsi
2916}
2917
2918type record PagingTestState {
2919 integer num_paging_sent,
2920 integer num_paging_rcv_msgs,
2921 integer num_paging_rcv_ids,
2922 integer num_overload
2923}
2924
2925/* receive + ignore RSL RF RES IND */
2926altstep as_rsl_res_ind() runs on test_CT {
2927 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2928 repeat;
2929 }
2930}
2931
2932/* Helper function for paging related testing */
2933private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002934 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002935 f_init_l1ctl();
2936 f_l1_tune(L1CTL);
2937
2938 var PagingTestState st := {
2939 num_paging_sent := 0,
2940 num_paging_rcv_msgs := 0,
2941 num_paging_rcv_ids := 0,
2942 num_overload := 0
2943 };
2944
2945 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2946 var float max_pch_imsi_per_sec;
2947 if (cfg.use_tmsi) {
2948 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2949 } else {
2950 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2951 }
2952 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2953 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002954 var float time_total := 20.0;
2955 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2956 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002957
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002958 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2959 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002960
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002961 timer T_itv := 0.0;
2962 T_itv.start;
2963 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002964 alt {
2965 /* check for presence of CCCH LOAD IND (paging load) */
2966 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2967 st.num_overload := st.num_overload + 1;
2968 repeat;
2969 }
2970 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002972 }
2973 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2974 log("Rx LOAD_IND");
2975 /* FIXME: analyze/verify interval + contents */
2976 repeat;
2977 }
2978 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002979 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002980 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002981 [] T_itv.timeout {
2982 /* Send paging cmds based on elapsed time */
2983 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2984 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002985 var MobileIdentityV mi;
2986
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002987 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002988 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002989 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002990 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002991 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002992 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002993
2994 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002995 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 +02002996
2997 st.num_paging_sent := st.num_paging_sent + 1;
2998 }
2999 if (st.num_paging_sent < pkt_total) {
3000 /* Wait for interval to next PAGING COMMAND */
3001 var float time_now := T_total.read;
3002 var float next_sched := int2float(st.num_paging_sent)*interval;
3003 if (next_sched > time_now) {
3004 T_itv.start(next_sched - time_now);
3005 } else {
3006 T_itv.start(0.0);
3007 }
3008 } else {
3009 /* We are done, no need to keep counting */
3010 T_total.stop;
3011 }
3012 }
3013 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003014 [] as_rsl_res_ind();
3015 }
3016 }
3017
3018 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3019 timer T_wait := 18.0;
3020 T_wait.start;
3021 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003022 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003023 [] L1CTL.receive { repeat; }
3024 /* 65535 == empty paging queue, we can terminate*/
3025 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3026 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
3027 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003029 }
3030 [] as_rsl_res_ind();
3031 }
3032
3033 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3034 " rcvd_ids=", st.num_paging_rcv_ids);
3035 return st;
3036}
3037
3038/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3039 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3040 * - that CCCH LOAD IND (PCH) are being generated
3041 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3042testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003043 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003044 var PagingTestCfg cfg := {
3045 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003046 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003047 load_factor := 0.8,
3048 exp_load_ind := true,
3049 exp_overload := false,
3050 use_tmsi := false
3051 };
3052 var PagingTestState st := f_TC_paging(cfg);
3053 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3055 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003056 } else {
3057 setverdict(pass);
3058 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003060}
3061
3062/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3063 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3064 * - that CCCH LOAD IND (PCH) are being generated
3065 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3066testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003067 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003068 var PagingTestCfg cfg := {
3069 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003070 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003071 load_factor := 0.8,
3072 exp_load_ind := true,
3073 exp_overload := false,
3074 use_tmsi := true
3075 };
3076 var PagingTestState st := f_TC_paging(cfg);
3077 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3079 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003080 } else {
3081 setverdict(pass);
3082 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003084}
3085
3086/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3087 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3088 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3089 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3090testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003091 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003092 var PagingTestCfg cfg := {
3093 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003094 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003095 load_factor := 2.0,
3096 exp_load_ind := true,
3097 exp_overload := true,
3098 use_tmsi := false
3099 };
3100 var PagingTestState st := f_TC_paging(cfg);
3101 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3102 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003103 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003104 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003105 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 +01003106 } else {
3107 setverdict(pass);
3108 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003110}
3111
3112/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3113 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3114 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3115 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3116testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003117 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003118 var PagingTestCfg cfg := {
3119 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003120 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003121 load_factor := 2.0,
3122 exp_load_ind := true,
3123 exp_overload := true,
3124 use_tmsi := true
3125 };
3126 var PagingTestState st := f_TC_paging(cfg);
3127 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3128 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003129 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003130 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003131 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 +01003132 } else {
3133 setverdict(pass);
3134 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003136}
3137
3138
Harald Welte93640c62018-02-25 16:59:33 +01003139/***********************************************************************
3140 * Immediate Assignment / AGCH
3141 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02003142const MobileAllocation c_MA_null := {
3143 len := 0,
3144 ma := ''B
3145}
Harald Welte93640c62018-02-25 16:59:33 +01003146
Harald Weltee8d750e2018-06-10 21:41:35 +02003147template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3148 uint12_t arfcn := 871) := {
3149 chan_nr := chan_nr,
3150 tsc := tsc,
3151 h := false,
3152 arfcn := arfcn,
3153 maio_hsn := omit
3154}
3155
3156private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3157 return int2str(num_tx) & " sent, "
3158 & int2str(num_rx) & " received, "
3159 & int2str(num_del) & " deleted";
3160}
3161
3162private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3163 var L1ctlDlMessage l1_dl;
3164 timer T := 10.0;
3165 var integer num_tx := 0;
3166 var integer num_rx := 0;
3167 var integer num_del := 0;
3168 var charstring res_str;
3169 var float rx_ratio;
3170
Harald Welte10474062019-05-30 16:48:17 +02003171 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003172 f_init_l1ctl();
3173 f_l1_tune(L1CTL);
3174
3175 for (var integer i := 0; i < num_total; i := i+1) {
3176 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
3177 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3178 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01003179 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003180 num_tx := num_tx+1;
3181 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003182 }
3183 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003184 T.start;
3185 alt {
3186 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
3187 num_del := num_del+1;
3188 repeat;
3189 }
3190 [] RSL_CCHAN.receive {
3191 repeat;
3192 }
3193 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3194 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3195 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3196 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3197 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003198 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003199 } else {
3200 num_rx := num_rx+1;
3201 }
3202 repeat;
3203 }
3204 [] L1CTL.receive { repeat; }
3205 [] T.timeout { }
3206 }
3207 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3208 log("AGCH test: " & res_str);
3209 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003211 }
3212 rx_ratio := int2float(num_rx) / int2float(num_tx);
3213 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003214 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 +02003215 } else {
3216 setverdict(pass);
3217 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003219}
3220
Harald Weltee8d750e2018-06-10 21:41:35 +02003221/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3222testcase TC_imm_ass_1000_20ms() runs on test_CT {
3223 f_TC_imm_ass(1000, 0.02, 0.25);
3224}
3225
3226/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3227testcase TC_imm_ass_200_0ms() runs on test_CT {
3228 f_TC_imm_ass(200, 0.0, 0.05);
3229}
3230
3231/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3232testcase TC_imm_ass_200_76ms() runs on test_CT {
3233 f_TC_imm_ass(150, 0.076, 1.00);
3234}
3235
3236
3237
Harald Welte48494ca2018-02-25 16:59:50 +01003238/***********************************************************************
3239 * BCCH
3240 ***********************************************************************/
3241
3242/* tuple of Frame Number + decoded SI */
3243type record SystemInformationFn {
3244 GsmFrameNumber frame_number,
3245 SystemInformation si
3246}
3247
3248/* an arbitrary-length vector of decoded SI + gsmtap header */
3249type record of SystemInformationFn SystemInformationVector;
3250
3251/* an array of SI-vectors indexed by TC value */
3252type SystemInformationVector SystemInformationVectorPerTc[8];
3253
3254/* determine if a given SI vector contains given SI type at least once */
3255function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3256 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3257 var integer fn_mod51 := arr[i].frame_number mod 51;
3258 if (not bcch_ext and fn_mod51 == 2 or
3259 bcch_ext and fn_mod51 == 6) {
3260 if (arr[i].si.header.message_type == key) {
3261 return true;
3262 }
3263 }
3264 }
3265 return false;
3266}
3267
3268/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3269function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3270 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003272 }
3273}
3274
3275/* check if a given SI vector contains given SI type at least once on any TC */
3276function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3277 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3278 if (f_si_vecslot_contains(arr[tc], key) or
3279 f_si_vecslot_contains(arr[tc], key, true)) {
3280 return true;
3281 }
3282 }
3283 return false;
3284}
3285
3286/* determine if a given SI vector contains given SI type at least N of M times */
3287function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3288 var integer count := 0;
3289 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003291 }
3292 for (var integer i:= 0; i < m; i := i + 1) {
3293 var integer fn_mod51 := arr[i].frame_number mod 51;
3294 if (not bcch_ext and fn_mod51 == 2 or
3295 bcch_ext and fn_mod51 == 6) {
3296 if (arr[i].si.header.message_type == key) {
3297 count := count + 1;
3298 }
3299 }
3300 }
3301 if (count >= n) {
3302 return true;
3303 } else {
3304 return false;
3305 }
3306}
3307
3308/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3309function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3310 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003312 }
3313}
3314
3315/* determine if a given SI vector contains given SI type at least once */
3316function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3317 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3318 var integer fn_mod51 := arr[i].frame_number mod 51;
3319 if (not bcch_ext and fn_mod51 == 2 or
3320 bcch_ext and fn_mod51 == 6) {
3321 if (arr[i].si.header.message_type != key) {
3322 return false;
3323 }
3324 }
3325 }
3326 return true;
3327}
3328
3329/* ensure a given TC slot of the SI vector contains only given SI type */
3330function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3331 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003333 }
3334}
3335
3336/* SI configuration of cell, against which we validate actual SI messages */
3337type set SystemInformationConfig {
3338 boolean bcch_extended,
3339 boolean si1_present,
3340 boolean si2bis_present,
3341 boolean si2ter_present,
3342 boolean si2quater_present,
3343 boolean si7_present,
3344 boolean si8_present,
3345 boolean si9_present,
3346 boolean si13_present,
3347 boolean si13alt_present,
3348 boolean si15_present,
3349 boolean si16_present,
3350 boolean si17_present,
3351 boolean si2n_present,
3352 boolean si21_present,
3353 boolean si22_present
3354}
3355
3356/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3357function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3358 var integer i;
3359 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3360 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003362 }
3363 }
3364 if (cfg.si1_present) {
3365 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3366 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3367 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3368 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3369 /* make sure *ALL* contain SI1 */
3370 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3371 }
3372 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3373 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3374 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3375 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3376 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3377 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3378
3379 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3380 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3381 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3382 * consecutive occurrences of TC = 4. */
3383 if (cfg.si2bis_present and not cfg.si2ter_present) {
3384 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3385 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3386 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3387 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3388 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3389 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3390 }
3391
3392 if (cfg.si7_present or cfg.si8_present) {
3393 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3394 * if System Information type 4 does not contain all information needed for cell
3395 * selection and reselection. */
3396 if (not cfg.bcch_extended) {
3397 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3398 }
3399 if (cfg.si7_present) {
3400 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3401 }
3402 if (cfg.si8_present) {
3403 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3404 }
3405 }
3406
3407 if (cfg.si2quater_present) {
3408 /* iii) System information type 2 quater is sent if needed, as determined by the system
3409 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3410 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3411 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3412 * within any of 4 consecutive occurrences of TC = 5. */
3413 if (not (cfg.bcch_extended)) {
3414 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3415 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3416 } else {
3417 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3418 }
3419 } else {
3420 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3421 }
3422 }
3423 if (cfg.si9_present) {
3424 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3425 * in system information type 3 as defined in 3GPP TS 44.018. */
3426 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3427 }
3428 if (cfg.si13_present) {
3429 /* vii) System Information type 13 is only related to the GPRS service. System Information
3430 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3431 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3432 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3433 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3434 * within any of 4 consecutive occurrences of TC=4. */
3435 if (not cfg.bcch_extended) {
3436 log("not-bccch-extended");
3437 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3438 } else {
3439 log("bccch-extended");
3440 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3441 }
3442 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003444 }
3445 }
3446 if (cfg.si16_present or cfg.si17_present) {
3447 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3448 * should not be sent in a cell where network sharing is used (see rule xv). */
3449 if (cfg.si22_present) {
3450 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3451 }
3452 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003454 }
3455 if (not cfg.bcch_extended) {
3456 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3457 }
3458 if (cfg.si16_present) {
3459 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3460 }
3461 if (cfg.si17_present) {
3462 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3463 }
3464 }
3465
3466 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3467 * broadcast information. The frequency with which they are sent is determined by the
3468 * system operator. System Information type 9 identifies the scheduling of System
3469 * Information type 18 and 20 messages. */
3470
3471 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3472 * Information Type 19 is present, then its scheduling shall be indicated in System
3473 * Information Type 9. */
3474
3475 if (cfg.si15_present) {
3476 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3477 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3478 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3479 * 4 consecutive occurrences of TC = 1. */
3480 if (not cfg.bcch_extended) {
3481 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3482 } else {
3483 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3484 }
3485 }
3486 if (cfg.si13alt_present) {
3487 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3488 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3489 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3490 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3491 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3492 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3493 * of TC = 4. */
3494 if (cfg.si13_present) {
3495 testcase.stop("Error: Cannot have SI13alt and SI13");
3496 }
3497 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003499 }
3500 if (not cfg.bcch_extended) {
3501 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3502 } else {
3503 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3504 }
3505 }
3506 if (cfg.si2n_present) {
3507 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3508 * as determined by the system operator. In the case that the message is sent on the
3509 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3510 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3511 * consecutive occurrences of TC = 4. */
3512 if (not cfg.bcch_extended) {
3513 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3514 } else {
3515 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3516 }
3517 }
3518 if (cfg.si21_present) {
3519 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3520 * determined by the system operator. If Extended Access Barring is in use in the cell
3521 * then this message is sent at least once within any of 4 consecutive occurrences of
3522 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3523 * cell then this message shall only be sent on BCCH Ext. */
3524 if (not cfg.bcch_extended) {
3525 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3526 } else {
3527 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3528 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003530 }
3531 }
3532 }
3533 if (cfg.si22_present) {
3534 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3535 * should not be sent in a cell where SoLSA is used (see rule viii). System
3536 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3537 * =2 and TC=6. */
3538 if (cfg.si16_present or cfg.si17_present) {
3539 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3540 }
3541 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3542 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003544 }
3545 if (not cfg.bcch_extended) {
3546 testcase.stop("Error: SI22 requires BCCH Extd!");
3547 } else {
3548 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3549 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3550 }
3551 }
3552}
3553
3554/* sample Systme Information for specified duration via L1CTL */
3555function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3556 timer T := duration;
3557 var SystemInformationVectorPerTc si_per_tc;
3558 var L1ctlDlMessage l1_dl;
3559
3560 /* initialize all per-TC vectors empty */
3561 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3562 si_per_tc[i] := {};
3563 }
3564
3565 /* flush all previous L1 queued msgs */
3566 pt.clear;
3567
3568 T.start;
3569 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003570 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003571 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3572 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3573 log("Ignoring non-RR SI ", l1_dl);
3574 repeat;
3575 }
3576 var SystemInformationFn sig := {
3577 frame_number := l1_dl.dl_info.frame_nr,
3578 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3579 }
3580 var integer tc := f_gsm_compute_tc(sig.frame_number);
3581 log("SI received at TC=", tc, ": ", sig.si);
3582 /* append to the per-TC bucket */
3583 si_per_tc[tc] := si_per_tc[tc] & { sig };
3584 repeat;
3585 }
3586 [] pt.receive { repeat; }
3587 [] T.timeout { }
3588 }
3589
3590 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3591 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3592 }
3593 log("si_per_tc=", si_per_tc);
3594 return si_per_tc;
3595}
3596
3597/* helper function: Set given SI via RSL + validate scheduling.
3598 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3599function f_TC_si_sched() runs on test_CT {
3600 var SystemInformationVectorPerTc si_per_tc;
3601 f_init_l1ctl();
3602 f_l1_tune(L1CTL);
3603
3604 /* Sample + Validate Scheduling */
3605 si_per_tc := f_l1_sample_si(L1CTL);
3606 f_validate_si_scheduling(si_cfg, si_per_tc);
3607
3608 setverdict(pass);
3609}
3610
3611testcase TC_si_sched_default() runs on test_CT {
3612 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003613 /* 2+3+4 are mandatory and set in f_init() */
3614 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003616}
3617
3618testcase TC_si_sched_1() runs on test_CT {
3619 f_init();
3620 si_cfg.si1_present := true;
3621 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003622 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003624}
3625
3626testcase TC_si_sched_2bis() runs on test_CT {
3627 f_init();
3628 si_cfg.si2bis_present := true;
3629 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3630 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003632}
3633
3634testcase TC_si_sched_2ter() runs on test_CT {
3635 f_init();
3636 si_cfg.si2ter_present := true;
3637 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3638 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003640}
3641
3642testcase TC_si_sched_2ter_2bis() runs on test_CT {
3643 f_init();
3644 si_cfg.si2bis_present := true;
3645 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3646 si_cfg.si2ter_present := true;
3647 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3648 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003650}
3651
3652testcase TC_si_sched_2quater() runs on test_CT {
3653 f_init();
3654 si_cfg.si2quater_present := true;
3655 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3656 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003658}
3659
3660testcase TC_si_sched_13() runs on test_CT {
3661 f_init();
3662 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003663 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003664 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003666}
3667
3668testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3669 f_init();
3670 si_cfg.si2bis_present := true;
3671 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3672 si_cfg.si2ter_present := true;
3673 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3674 si_cfg.si2quater_present := true;
3675 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3676 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003677 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003678 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003680}
3681
3682
Harald Welte68e495b2018-02-25 00:05:57 +01003683testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003684 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003685 /* FIXME: enable / disable individual BCCH info */
3686 //ts_RSL_BCCH_INFO(si_type, info);
3687 /* expect no ERROR REPORT after either of them *
3688 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003690}
3691
Harald Welte93640c62018-02-25 16:59:33 +01003692/***********************************************************************
3693 * Low-Level Protocol Errors / ERROR REPORT
3694 ***********************************************************************/
3695
Harald Welte01d982c2018-02-25 01:31:40 +01003696private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3697 timer T := 5.0;
3698 T.start;
3699 alt {
3700 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3701 setverdict(pass);
3702 }
3703 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003705 }
3706 [] RSL_CCHAN.receive {
3707 repeat;
3708 }
3709 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003711 }
3712 }
3713}
3714
3715/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3716testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003717 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003718 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3719 rsl.ies := omit;
3720 RSL_CCHAN.send(ts_RSL_UD(rsl));
3721
3722 f_exp_err_rep(RSL_ERR_PROTO);
3723}
3724
3725/* Provoke a mandatory IE error and match on ERROR REPORT */
3726testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003727 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003728
3729 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3730 rsl.ies := { rsl.ies[0] };
3731 RSL_CCHAN.send(ts_RSL_UD(rsl));
3732
3733 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3734}
3735
3736/* Provoke an IE content error and match on ERROR REPORT */
3737testcase TC_rsl_ie_content_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[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3741 RSL_CCHAN.send(ts_RSL_UD(rsl));
3742
3743 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3744}
3745
Harald Welteee25aae2019-05-19 14:32:37 +02003746/* attempt to activate channel with wrong RSL Message Discriminator IE */
3747function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3748 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3749 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3750 RSL.send(rsl);
3751 f_rslem_unregister(0, g_chan_nr);
3752}
3753testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3754 var ConnHdlr vc_conn;
3755 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3756
Harald Welte10474062019-05-30 16:48:17 +02003757 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003758
3759 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3760 vc_conn.done;
3761 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3762
3763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3764}
3765
3766/* Send messages with wrong message type */
3767function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3768 var template (value) RSL_Message rsl_tx;
3769 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3770 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3771 RSL.send(rsl_tx);
3772 f_rslem_unregister(0, g_chan_nr);
3773}
3774function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3775 var template (value) RSL_Message rsl_tx;
3776 /* we first have to activate the dedicated channel */
3777 f_rsl_chan_act(g_pars.chan_mode);
3778 /* ... to then send an invalid RLL message */
3779 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3780 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3781 RSL.send(rsl_tx);
3782 f_rslem_unregister(0, g_chan_nr);
3783}
3784testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3785 var ConnHdlr vc_conn;
3786 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3787 var template (value) RSL_Message rsl_tx;
3788
Harald Welte10474062019-05-30 16:48:17 +02003789 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003790
3791 /* Common Channel with wrong message type */
3792 RSL_CCHAN.clear;
3793 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3794 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3795 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3796 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3797
3798 /* TRX Management */
3799 RSL_CCHAN.clear;
3800 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3801 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3802 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3803 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3804
3805 /* Dedicated Channel */
3806 RSL_CCHAN.clear;
3807 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3808 vc_conn.done;
3809 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3810
3811 /* RLL */
3812 RSL_CCHAN.clear;
3813 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3814 vc_conn.done;
3815 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3816}
3817
3818/* Send messages in wrong sequence (RLL to an inactive lchan) */
3819function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3820 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3821 f_rslem_unregister(0, g_chan_nr);
3822}
3823testcase TC_err_rep_wrong_sequence() runs on test_CT {
3824 var ConnHdlr vc_conn;
3825 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3826
Harald Welte10474062019-05-30 16:48:17 +02003827 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003828
3829 RSL_CCHAN.clear;
3830 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3831 vc_conn.done;
3832 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3833}
3834
Harald Welte93640c62018-02-25 16:59:33 +01003835/***********************************************************************
3836 * IPA CRCX/MDCX/DLCS media stream handling
3837 ***********************************************************************/
3838
Harald Weltea871a382018-02-25 02:03:14 +01003839/* Send IPA DLCX to inactive lchan */
3840function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003841 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3842 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003843}
3844testcase TC_ipa_dlcx_not_active() runs on test_CT {
3845 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003846 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003847 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3848 vc_conn.done;
3849}
Harald Welte68e495b2018-02-25 00:05:57 +01003850
Harald Weltea3f1df92018-02-25 12:49:55 +01003851/* Send IPA CRCX twice to inactive lchan */
3852function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3853 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3854 "IPA CRCX ACK");
3855 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3856 "IPA CRCX NACK");
3857}
3858testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3859 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003860 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003861 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3862 vc_conn.done;
3863}
3864
3865/* Regular sequence of CRCX/MDCX/DLCX */
3866function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3867 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3868 "IPA CRCX ACK");
3869 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3870 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3871 var uint7_t rtp_pt2 := f_rnd_int(127);
3872 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3873 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3874 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3875 "IPA MDCX ACK");
3876 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3877 "IPA DLCX ACK");
3878}
3879testcase TC_ipa_crcx_mdcx_dlcx_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_mdcx_dlcx_not_active), pars);
3883 vc_conn.done;
3884}
3885
Harald Welte3ae11da2018-02-25 13:36:06 +01003886/* Sequence of CRCX, 2x MDCX, DLCX */
3887function f_TC_ipa_crcx_mdcx_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 /* Second MDCX */
3898 remote_ip := f_rnd_int(c_UINT32_MAX);
3899 remote_port := f_rnd_int(c_UINT16_MAX);
3900 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3901 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3902 "IPA MDCX ACK");
3903 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3904 "IPA DLCX ACK");
3905}
3906testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3907 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003908 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003909 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3910 vc_conn.done;
3911}
3912
Harald Welte9912eb52018-02-25 13:30:15 +01003913/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3914function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3915 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3916 "IPA CRCX NACK");
3917}
3918testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3919 var ConnHdlrPars pars;
3920 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003921 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003922
3923 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3924 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3925 vc_conn.done;
3926
3927 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3928 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3929 vc_conn.done;
3930}
3931
Harald Weltea3f1df92018-02-25 12:49:55 +01003932
Harald Welte883340c2018-02-28 18:59:29 +01003933/***********************************************************************
3934 * PCU Socket related tests
3935 ***********************************************************************/
3936
Harald Welte07bd2d22019-05-25 11:03:30 +02003937/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003938friend 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 +01003939runs on test_CT {
3940 timer T := 3.0;
3941
3942 /* we don't expect any RTS.req before PDCH are active */
3943 T.start;
3944 alt {
3945 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003947 }
3948 [] PCU.receive { repeat; }
3949 [] T.timeout { }
3950 }
3951
3952 /* Send PDCH activate request for known PDCH timeslot */
3953 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3954
3955 /* we now expect RTS.req for this timeslot (only) */
3956 T.start;
3957 alt {
3958 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3959 setverdict(pass);
3960 }
3961 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3962 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003964 }
3965 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003967 }
3968 [] PCU.receive { repeat; }
3969 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003971 }
3972 [not exp_success] T.timeout {
3973 setverdict(pass);
3974 }
3975 }
3976}
3977
Harald Welte07bd2d22019-05-25 11:03:30 +02003978/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003979friend 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 +01003980runs on test_CT {
3981 timer T := 3.0;
3982
3983 /* Send PDCH activate request for known PDCH timeslot */
3984 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3985
3986 PCU.clear;
3987 /* we now expect no RTS.req for this timeslot */
3988 T.start;
3989 alt {
3990 [] 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 +02003991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003992 }
3993 [] PCU.receive { repeat; }
3994 [] T.timeout {
3995 setverdict(pass);
3996 }
3997 }
3998}
3999
Harald Weltead033dc2019-05-25 17:28:16 +02004000friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004001 f_init();
4002 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4003}
4004
Harald Welte883340c2018-02-28 18:59:29 +01004005/* PDCH activation via PCU socket; check for presence of RTS.req */
4006testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004007 f_init_pcu_test();
4008
Harald Welte883340c2018-02-28 18:59:29 +01004009 f_TC_pcu_act_req(0, 0, 7, true);
4010}
4011
4012/* PDCH activation via PCU socket on non-PDCU timeslot */
4013testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004014 f_init_pcu_test();
4015
Harald Welte883340c2018-02-28 18:59:29 +01004016 f_TC_pcu_act_req(0, 0, 1, false);
4017}
4018
4019/* PDCH activation via PCU socket on wrong BTS */
4020testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004021 f_init_pcu_test();
4022
Harald Welte883340c2018-02-28 18:59:29 +01004023 f_TC_pcu_act_req(23, 0, 7, false);
4024}
4025
4026/* PDCH activation via PCU socket on wrong TRX */
4027testcase TC_pcu_act_req_wrong_trx() 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, 23, 7, false);
4031}
4032
4033/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4034testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004035 f_init_pcu_test();
4036
Harald Welte883340c2018-02-28 18:59:29 +01004037 /* Activate PDCH */
4038 f_TC_pcu_act_req(0, 0, 7, true);
4039 f_sleep(1.0);
4040 /* and De-Activate again */
4041 f_TC_pcu_deact_req(0, 0, 7);
4042}
4043
4044/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4045testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004046 f_init_pcu_test();
4047
Harald Welte883340c2018-02-28 18:59:29 +01004048 f_TC_pcu_deact_req(0, 0, 1);
4049}
4050
4051/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4052testcase TC_pcu_ver_si13() runs on test_CT {
4053 const octetstring si13 := '00010203040506070909'O;
4054 var PCUIF_send_data sd;
4055 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004056 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004057
4058 /* Set SI13 via RSL */
4059 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004060
Harald Welte883340c2018-02-28 18:59:29 +01004061 T.start;
4062 alt {
4063 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4064 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4065 setverdict(pass);
4066 } else {
4067 repeat;
4068 }
4069 }
4070 [] PCU.receive { repeat; }
4071 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004073 }
4074 }
4075}
4076
4077private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4078
4079/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004080friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004081 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4082runs on test_CT
4083{
4084 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4085 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4086}
4087
4088/* 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 +02004089friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4090 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004091runs on test_CT
4092{
4093 var PCUIF_send_data sd;
4094
4095 timer T := 3.0;
4096 T.start;
4097 alt {
4098 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4099 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4100 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4101 sd.data.u.rts_req.fn, sapi, data);
4102 }
4103 [] PCU.receive { repeat; }
4104 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004106 }
4107 }
4108}
4109
4110/* Send DATA.req on invalid BTS */
4111testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004112 var TfiUsfArr tua := f_TfiUsfArrInit();
4113 var octetstring data := '0000'O & f_rnd_octstring(21);
4114
4115 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004116
Harald Welte883340c2018-02-28 18:59:29 +01004117 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004118 f_TfiUsfArrSet(tua, 7, 0);
4119 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4120 f_sleep(1.0);
4121
4122 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004123}
4124
4125/* Send DATA.req on invalid TRX */
4126testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004127 var TfiUsfArr tua := f_TfiUsfArrInit();
4128 var octetstring data := '0000'O & f_rnd_octstring(21);
4129
4130 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004131
Harald Welte883340c2018-02-28 18:59:29 +01004132 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004133 f_TfiUsfArrSet(tua, 7, 0);
4134 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4135 f_sleep(1.0);
4136
4137 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004138}
4139
4140/* Send DATA.req on invalid timeslot */
4141testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004142 var TfiUsfArr tua := f_TfiUsfArrInit();
4143 var octetstring data := '0000'O & f_rnd_octstring(21);
4144
4145 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004146
Harald Welte883340c2018-02-28 18:59:29 +01004147 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004148 f_TfiUsfArrSet(tua, 7, 0);
4149 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4150 f_sleep(1.0);
4151
4152 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004153}
4154
4155/* Send DATA.req on timeslot that hasn't been activated */
4156testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004157 var TfiUsfArr tua := f_TfiUsfArrInit();
4158 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004159
Harald Welte7162a612019-05-26 12:56:09 +02004160 f_virtphy_common();
4161
4162 f_TfiUsfArrSet(tua, 7, 0);
4163 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4164 f_sleep(1.0);
4165
4166 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004167}
4168
Harald Weltead033dc2019-05-25 17:28:16 +02004169private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004170 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4171 boolean wait_rts := true)
4172runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004173 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004174 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004175
4176 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004177 if (wait_rts) {
4178 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4179 } else {
4180 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4181 }
Harald Weltead033dc2019-05-25 17:28:16 +02004182
4183 T.start;
4184 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004185 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004186 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4187 setverdict(pass);
4188 }
Harald Welte7162a612019-05-26 12:56:09 +02004189 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4190 setverdict(fail, "Received unexpected ", rx_dl);
4191 }
Harald Weltead033dc2019-05-25 17:28:16 +02004192 [] L1CTL.receive {
4193 repeat;
4194 }
Harald Welte7162a612019-05-26 12:56:09 +02004195 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004196 setverdict(fail, "Timeout waiting for ", data);
4197 }
Harald Welte7162a612019-05-26 12:56:09 +02004198 [not expect_data] T.timeout {
4199 setverdict(pass);
4200 }
Harald Weltead033dc2019-05-25 17:28:16 +02004201 }
4202}
4203
4204private function f_disable_dynamic_ts() runs on test_CT
4205{
4206 f_init_vty_bsc();
4207 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4208 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4209 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4210 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004211 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004212}
4213
4214private function f_virtphy_common() runs on test_CT {
4215 f_disable_dynamic_ts();
4216 f_init_l1ctl();
4217 f_l1_tune(L1CTL);
4218}
4219
4220testcase TC_pcu_data_req_pdtch() runs on test_CT {
4221 var TfiUsfArr tua := f_TfiUsfArrInit();
4222 var octetstring data := '0000'O & f_rnd_octstring(21);
4223
4224 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004225
Harald Welte883340c2018-02-28 18:59:29 +01004226 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004227 f_TfiUsfArrSet(tua, 7, 0);
4228 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4229 f_sleep(1.0);
4230
4231 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004232}
4233
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004234/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004235testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004236 var TfiUsfArr tua := f_TfiUsfArrInit();
4237 var octetstring data := '0000'O & f_rnd_octstring(21);
4238
4239 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004240
Harald Welte883340c2018-02-28 18:59:29 +01004241 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004242 f_TfiUsfArrSet(tua, 7, 0);
4243 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4244 f_sleep(1.0);
4245
4246 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004247}
4248
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004249private function f_TC_pcu_ptcch_ul(uint16_t ra)
4250runs on test_CT {
4251 var template PCUIF_Message pcu_rach_ind;
4252 var PCUIF_send_data sd;
4253 var GsmFrameNumber fn;
4254 timer T;
4255
4256 /* Send an Access Burst on PTCCH/U over the Um-interface */
4257 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4258 chan_nr := ts_RslChanNr_PDCH(7),
4259 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4260
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004261 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4262 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004263
4264 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4265 T.start(52.0 * 4.615 / 1000.0);
4266 alt {
4267 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4268 log("Rx an Access Burst on the PCU interface: ", sd.data);
4269 setverdict(pass);
4270 T.stop;
4271 }
4272 [] PCU.receive { repeat; }
4273 [] T.timeout {
4274 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4275 /* Keep going, that's not the end of the world */
4276 }
4277 }
4278}
4279
4280testcase TC_pcu_ptcch() runs on test_CT {
4281 var L1ctlDlMessage dl;
4282 var octetstring data;
4283 timer T;
4284
4285 f_init_pcu_test();
4286 f_init_l1ctl();
4287 f_l1_tune(L1CTL);
4288
4289 /* Activate PDCH channel on TS7 */
4290 f_TC_pcu_act_req(0, 0, 7, true);
4291
4292 /* Tune trxcon to that PDCH channel */
4293 L1CTL.send(ts_L1CTL_DM_EST_REQ(arfcn := { false, mp_trx0_arfcn },
4294 chan_nr := valueof(ts_RslChanNr_PDCH(7)),
4295 tsc := 7));
4296
4297 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4298 for (var integer i := 0; i < 16; i := i + 1) {
4299 log("Sending an Access Burst towards the L1CTL interface");
4300 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4301 }
4302
4303 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4304 data := f_rnd_octstring(23);
4305
4306 /* Verify PTCCH/D: send a random data block, make sure it's received */
4307 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4308 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4309
4310 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4311 * let's give it more time in case if we miss the beginning. */
4312 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4313 alt {
4314 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4315 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4316 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4317 frame := data)) -> value dl {
4318 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4319 setverdict(pass);
4320 T.stop;
4321 }
4322 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4323 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4324 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4325 l2_data := data)) -> value dl {
4326 log("Rx PTCCH/D data block on L1CTL: ", dl);
4327 setverdict(pass);
4328 T.stop;
4329 }
4330 [] L1CTL.receive { repeat; }
4331 [] T.timeout {
4332 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4333 }
4334 }
4335}
4336
Harald Welte883340c2018-02-28 18:59:29 +01004337/* Send AGCH from PCU; check it appears on Um side */
4338testcase TC_pcu_data_req_agch() runs on test_CT {
4339 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004340 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004341 f_init_l1ctl();
4342 f_l1_tune(L1CTL);
4343
4344 f_TC_pcu_act_req(0, 0, 7, true);
4345 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4346
4347 T.start;
4348 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004349 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004350 setverdict(pass);
4351 }
4352 [] L1CTL.receive { repeat; }
4353 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004355 }
4356 }
4357}
4358
Harald Welte928622b2019-05-26 13:22:59 +02004359/* Send AGCH from PCU; check it appears on Um side */
4360testcase TC_pcu_data_req_pch() runs on test_CT {
4361 timer T := 3.0;
4362 f_init_pcu_test();
4363 f_init_l1ctl();
4364 f_l1_tune(L1CTL);
4365
4366 f_TC_pcu_act_req(0, 0, 7, true);
4367 /* three characters prefix: last 3 digits of IMSI as ASCII */
4368 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4369
4370 T.start;
4371 alt {
4372 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4373 setverdict(pass);
4374 }
4375 [] L1CTL.receive { repeat; }
4376 [] T.timeout {
4377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4378 }
4379 }
4380}
4381
Harald Welte883340c2018-02-28 18:59:29 +01004382/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4383testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4384 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004385 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004386 f_init_l1ctl();
4387 f_l1_tune(L1CTL);
4388
4389 /* append 3 last imsi digits so BTS can compute pagng group */
4390 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4391
4392 timer T := 0.5;
4393 T.start;
4394 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004395 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004396 /* TODO: verify paging group */
4397 setverdict(pass);
4398 }
4399 [] L1CTL.receive { repeat; }
4400 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004402 }
4403 }
4404}
4405
4406/* Send RACH from Um side, expect it to show up on PCU socket */
4407testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004408 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004409 f_init_l1ctl();
4410 f_l1_tune(L1CTL);
4411
4412 var GsmFrameNumber fn_last := 0;
4413 for (var integer i := 0; i < 1000; i := i+1) {
4414 var OCT1 ra := f_rnd_ra_ps();
4415 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4416 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004418 }
4419 fn_last := fn;
4420
4421 timer T := 2.0;
4422 T.start;
4423 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004424 [] 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 +01004425 T.stop;
4426 }
4427 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004429 }
4430 [] PCU.receive { repeat; }
4431 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004433 }
4434 }
4435 }
4436 setverdict(pass);
4437}
4438
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004439/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4440 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4441testcase TC_pcu_ext_rach_content() runs on test_CT {
4442 var template PCUIF_Message pcu_rach_ind;
4443 var GsmFrameNumber fn_last := 0;
4444 var L1ctlRachSynchSeq synch_seq;
4445 var PCUIF_BurstType pcu_bt;
4446 var GsmFrameNumber fn;
4447 var BIT11 ra11;
4448
4449 f_init_pcu_test();
4450 f_init_l1ctl();
4451 f_l1_tune(L1CTL);
4452
4453 for (var integer i := 0; i < 1000; i := i+1) {
4454 /* We need to test both TS1 & TS2 */
4455 if (i rem 2 == 0) {
4456 synch_seq := RACH_SYNCH_SEQ_TS1;
4457 pcu_bt := BURST_TYPE_1;
4458 } else {
4459 synch_seq := RACH_SYNCH_SEQ_TS2;
4460 pcu_bt := BURST_TYPE_2;
4461 }
4462
4463 ra11 := f_rnd_ra11_ps();
4464 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4465 if (fn == fn_last) {
4466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4467 "Two RACH in same FN?!?");
4468 }
4469 fn_last := fn;
4470
4471 /* Compose the expected message */
4472 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004473 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004474 ra := bit2int(ra11),
4475 is_11bit := 1,
4476 burst_type := pcu_bt,
4477 fn := fn);
4478
4479 timer T := 2.0;
4480 T.start;
4481 alt {
4482 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4483 T.stop;
4484 }
4485 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4487 }
4488 [] PCU.receive { repeat; }
4489 [] T.timeout {
4490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4491 }
4492 }
4493 }
4494 setverdict(pass);
4495}
4496
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004497private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4498runs on test_CT {
4499 var template PCUIF_send_data sdt;
4500 var PCUIF_send_data sd;
4501 var int16_t lqual_cb;
4502 timer T := 1.0;
4503
4504 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4505 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4506
4507 /* Send a random PDTCH frame over Um */
4508 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4509 '0000'O & f_rnd_octstring(21)));
4510
4511 T.start;
4512 alt {
4513 /* If expected link quality is above the threshold */
4514 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4515 lqual_cb := sd.data.u.data_ind.lqual_cb;
4516 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4517
4518 /* Make sure the actual link quality matches the expected value */
4519 if (not match(lqual_cb, lqual_cb_exp)) {
4520 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4521 "expected value ", lqual_cb_exp));
4522 } else {
4523 setverdict(pass);
4524 }
4525 }
4526 /* If expected link quality is below the threshold */
4527 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4529 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4530 }
4531 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4532 [] PCU.receive { repeat; }
4533 [lqual_cb_exp < thresh] T.timeout {
4534 log("Rx nothing, as expected");
4535 setverdict(pass);
4536 }
4537 [lqual_cb_exp >= thresh] T.timeout {
4538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4539 "Timeout waiting for PCUIF_DATA.ind");
4540 }
4541 }
4542}
4543
4544/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4545testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4546 f_init_pcu_test();
4547 PCU.clear;
4548
4549 f_init_l1ctl();
4550 f_l1_tune(L1CTL);
4551
4552 /* Activate a PDCH channel on TS7 */
4553 f_TC_pcu_act_req(0, 0, 7, true);
4554
4555 /* Tune trxcon to that PDCH channel on TS7 */
4556 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn },
4557 valueof(ts_RslChanNr_PDCH(7)), 7);
4558
4559 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4560 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4561 var TrxcMessage ret;
4562
4563 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4564 valueof(ts_TRXC_FAKE_CI(i)));
4565
4566 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4567 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4568 }
4569}
4570
Harald Welte883340c2018-02-28 18:59:29 +01004571/* Send PAGING via RSL, expect it to shw up on PCU socket */
4572testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004573 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004574
4575 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004576 var MobileIdentityLV mi_lv;
4577 var octetstring mi_lv_enc;
4578 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004579 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004580
Harald Welte883340c2018-02-28 18:59:29 +01004581 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004582 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004583 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004584 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004585 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004586
4587 /* Fancy encoding for PCUIF */
4588 mi_lv := valueof(ts_MI_LV(mi));
4589 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4590 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004591
4592 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004593 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004594 T.start;
4595 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004596 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004597 }
4598 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004600 }
4601 [] PCU.receive { repeat; }
4602 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004604 }
4605 }
4606 }
4607 setverdict(pass);
4608}
4609
Harald Welted66c9b82019-05-25 09:03:15 +02004610/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4611testcase TC_pcu_time_ind() runs on test_CT {
4612 var PCUIF_send_data pcu_sd;
4613 var integer num_time_ind := 0;
4614 var integer first_fn, last_fn;
4615 var float test_duration := 5.0;
4616 timer T;
4617
4618 f_init_pcu_test();
4619 f_TC_pcu_act_req(0, 0, 7, true);
4620
4621 PCU.clear;
4622 T.start(test_duration);
4623 alt {
4624 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4625 num_time_ind := num_time_ind + 1;
4626 if (not isbound(first_fn)) {
4627 first_fn := pcu_sd.data.u.time_ind.fn;
4628 }
4629 last_fn := pcu_sd.data.u.time_ind.fn;
4630 repeat;
4631 }
4632 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4633 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4634 repeat;
4635 }
4636 [] PCU.receive {
4637 repeat;
4638 }
4639 [] T.timeout {}
4640 }
4641 var integer fn_expired := last_fn - first_fn;
4642 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4643
4644 /* verify the number of frames expired matches our expectation */
4645 const float c_GSM_FN_DURATION_MS := 4.61538;
4646 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004647 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004648 if (not match(fn_expired, t_fn_expected)) {
4649 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4650 }
4651
4652 /* There are three TIME.ind in every fn MOD 13 */
4653 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4654 /* Add some tolerance */
4655 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4656 if (not match(num_time_ind, t_time_ind_exp)) {
4657 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4658 }
4659
4660 setverdict(pass);
4661}
4662
Harald Welte4832c862019-05-25 14:57:18 +02004663/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4664testcase TC_pcu_rts_req() runs on test_CT {
4665 var PCUIF_send_data pcu_sd;
4666 var integer first_fn, last_fn;
4667 var integer num_rts_pdtch := 0;
4668 var integer num_rts_ptcch := 0;
4669 var float test_duration := 5.0;
4670 timer T;
4671
4672 f_init_pcu_test();
4673 f_TC_pcu_act_req(0, 0, 7, true);
4674
4675 PCU.clear;
4676 T.start(test_duration);
4677 alt {
4678 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4679 -> value pcu_sd {
4680 num_rts_pdtch := num_rts_pdtch + 1;
4681 if (not isbound(first_fn)) {
4682 first_fn := pcu_sd.data.u.rts_req.fn;
4683 }
4684 last_fn := pcu_sd.data.u.rts_req.fn;
4685 repeat;
4686 }
4687 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4688 -> value pcu_sd {
4689 num_rts_ptcch := num_rts_ptcch + 1;
4690 if (not isbound(first_fn)) {
4691 first_fn := pcu_sd.data.u.rts_req.fn;
4692 }
4693 last_fn := pcu_sd.data.u.rts_req.fn;
4694 repeat;
4695 }
4696 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4697 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4698 repeat;
4699 }
4700 [] PCU.receive {
4701 repeat;
4702 }
4703 [] T.timeout {}
4704 }
4705 var integer fn_expired := last_fn - first_fn;
4706 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4707 ", num_rts_ptcch=", num_rts_ptcch);
4708
4709 /* verify the number of frames expired matches our expectation */
4710 const float c_GSM_FN_DURATION_MS := 4.61538;
4711 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004712 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004713 if (not match(fn_expired, t_fn_expected)) {
4714 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4715 }
4716
4717 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4718 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4719 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4720 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4721 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4722 t_ptcch_exp);
4723 }
4724
4725 /* We have 12 PDTCH blocks every 52-multiframe */
4726 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4727 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4728 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4729 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4730 t_pdtch_exp);
4731 }
4732
4733 setverdict(pass);
4734}
4735
Harald Welte07bd2d22019-05-25 11:03:30 +02004736/* test for generating Abis side OML ALERT from the PCU */
4737testcase TC_pcu_oml_alert() runs on test_CT {
4738 var PCUIF_send_data pcu_sd;
4739 var integer num_time_ind := 0;
4740 var integer first_fn, last_fn;
4741 var float test_duration := 5.0;
4742 timer T;
4743
4744 f_init_pcu_test();
4745 f_TC_pcu_act_req(0, 0, 7, true);
4746
4747 /* re-connect CTRL port from BTS to BSC */
4748 f_ipa_ctrl_stop();
4749 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4750
4751 /* Send that OML Alert */
4752 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4753
4754 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4755 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4756 setverdict(pass);
4757}
4758
Harald Welteeaa9a862019-05-26 23:01:08 +02004759template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4760 template (value) RoutingAreaIdentificationV rai,
4761 template (value) OCT1 cause) := {
4762 discriminator := '0000'B, /* overwritten */
4763 tiOrSkip := {
4764 skipIndicator := '0000'B
4765 },
4766 msgs := {
4767 rrm := {
4768 gPRS_suspensionRequest := {
4769 messageType := '00110100'B,
4770 tLLI := tlli,
4771 routingAreaIdentification := rai,
4772 suspensionCause := cause,
4773 service_Support := omit
4774 }
4775 }
4776 }
4777}
4778
4779/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4780private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4781 var PCUIF_Message first_info;
4782 var integer pcu_conn_id := -1;
4783 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4784 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4785 var OCT4 tlli := '01020304'O;
4786 var OCT1 cause := '23'O;
4787 timer T := 5.0;
4788
4789 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4790
4791 f_l1_tune(L1CTL);
4792 RSL.clear;
4793
4794 f_est_dchan();
4795 L1CTL.clear;
4796
4797 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4798
4799 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4800 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4801 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4802
4803 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4804 T.start;
4805 alt {
4806 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4807 setverdict(pass);
4808 }
4809 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4810 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4811 }
4812 [] PCU.receive {
4813 repeat;
4814 }
4815 [] T.timeout {
4816 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4817 }
4818 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004819
4820 /* release the channel */
4821 f_rsl_chan_deact();
4822 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4823 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004824}
4825testcase TC_pcu_rr_suspend() runs on test_CT {
4826 var ConnHdlrPars pars;
4827 var ConnHdlr vc_conn;
4828
4829 f_init();
4830
4831 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4832 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4833 vc_conn.done;
4834}
Harald Welte07bd2d22019-05-25 11:03:30 +02004835
Harald Weltea2e0e942019-05-27 18:12:53 +02004836/* Ensure that PCUIF socket can accept only a single connection */
4837testcase TC_pcu_socket_connect_multi() runs on test_CT {
4838 timer T := 5.0;
4839
4840 /* this (among other things) establishes the first connection to the PCUIF socket */
4841 f_init();
4842
4843 /* try to establish a second connection, expect it to fail */
4844 PCU.send(UD_connect:{mp_pcu_socket, -1});
4845 T.start;
4846 alt {
4847 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4848 setverdict(pass);
4849 }
4850 [] PCU.receive(UD_connect_result:?) {
4851 setverdict(fail, "Unexpected unix domain connect result");
4852 }
4853 [] T.timeout {
4854 setverdict(pass);
4855 }
4856 }
4857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4858}
4859
Harald Weltec8effb72019-05-27 18:23:04 +02004860/* Ensure that PCUIF socket can disconnect + reconnect */
4861testcase TC_pcu_socket_reconnect() runs on test_CT {
4862 /* this (among other things) establishes the first connection to the PCUIF socket */
4863 f_init();
4864
4865 f_sleep(1.0);
4866
4867 f_pcuif_close(PCU, g_pcu_conn_id);
4868 g_pcu_conn_id := -1;
4869
4870 f_sleep(1.0);
4871
4872 /* re-connect */
4873 PCU.clear;
4874 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4875 setverdict(pass);
4876
4877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4878}
4879
Harald Weltebe030482019-05-27 22:29:35 +02004880/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4881private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4882 var L1ctlDlMessage l1_dl;
4883 var SystemInformation si;
4884 timer T := 5.0;
4885 T.start;
4886 alt {
4887 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4888 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4889 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4890 log("Ignoring non-RR SI ", l1_dl);
4891 repeat;
4892 }
4893 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4894 if (not ischosen(si.payload.si3)) {
4895 repeat;
4896 }
4897 }
4898 [] pt.receive {
4899 repeat;
4900 }
4901 [] T.timeout {
4902 setverdict(fail, "Timeout waiting for SI3");
4903 }
4904 }
4905 return si.payload.si3;
4906}
4907
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +07004908private function f_si3_has_gprs_indicator(RestOctets ro) return boolean {
4909 var SI3RestOctets rest := dec_SI3RestOctets(ro);
4910 return rest.gprs_ind.presence == '1'B;
Harald Weltebe030482019-05-27 22:29:35 +02004911}
4912
4913testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4914 var SystemInformationType3 si3;
4915 timer T := 5.0;
4916
4917 /* don't call f_init() as this would connect PCU socket */
4918 f_init_rsl(testcasename());
4919 T.start;
4920 alt {
4921 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4922 [] T.timeout {
4923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4924 }
4925 }
4926 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4927
4928 f_init_l1ctl();
4929 f_l1_tune(L1CTL);
4930
4931 f_sleep(2.0);
4932 L1CTL.clear;
4933 si3 := f_get_si3(L1CTL);
4934 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4935 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4936 } else {
4937 setverdict(pass);
4938 }
4939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4940}
4941
4942/* Ensure that GPRS capability is advertised after PCU socket connect */
4943testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4944 var SystemInformationType3 si3;
4945
4946 /* this (among other things) establishes the first connection to the PCUIF socket */
4947 f_init();
4948 f_init_l1ctl();
4949 f_l1_tune(L1CTL);
4950
4951 f_sleep(2.0);
4952 L1CTL.clear;
4953 si3 := f_get_si3(L1CTL);
4954 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4955 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4956 } else {
4957 setverdict(pass);
4958 }
4959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4960}
4961
4962/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4963testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4964 var SystemInformationType3 si3;
4965
4966 /* this (among other things) establishes the first connection to the PCUIF socket */
4967 f_init();
4968 f_init_l1ctl();
4969 f_l1_tune(L1CTL);
4970
4971 f_pcuif_close(PCU, g_pcu_conn_id);
4972 g_pcu_conn_id := -1;
4973
4974 f_sleep(1.0);
4975
4976 /* re-connect */
4977 PCU.clear;
4978 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4979
4980 f_sleep(2.0);
4981 L1CTL.clear;
4982 si3 := f_get_si3(L1CTL);
4983 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4984 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4985 } else {
4986 setverdict(pass);
4987 }
4988
4989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4990}
4991
Oliver Smithf5239c72019-08-28 10:01:25 +02004992/* 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) */
4993testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
4994 var SystemInformation si3 := valueof(ts_SI3_default);
4995
4996 f_init();
4997
4998 /* Verify cell_id */
4999 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5000 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5001 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005002 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5003 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5004 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005005 }
5006
5007 /* Verify LAC */
5008 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5009 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5010 if (lac_si3 != lac_pcu) {
5011 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5012 }
5013
5014 setverdict(pass);
5015}
Harald Welted66c9b82019-05-25 09:03:15 +02005016
Harald Welte3d04ae62018-04-04 20:29:05 +02005017/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005018 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005019 ***********************************************************************/
5020
5021private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5022runs on ConnHdlr {
5023 var PCUIF_send_data sd;
5024 /* Expect BTS to immediately acknowledge activation as PDCH */
5025 PCU.clear;
5026 f_rsl_chan_act(g_pars.chan_mode);
5027 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005028 timer T_wait := 2.0;
5029 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005030 alt {
5031 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5032 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 +02005033 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5034 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5035 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005036 }
5037 }
5038 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005039 [] T_wait.timeout {
5040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5041 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5042 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005043 }
5044 /* try to activate this PDCH from the PCU point of view */
5045 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5046 /* FIXME: is there a response? */
5047}
5048
5049private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5050runs on ConnHdlr {
5051 var PCUIF_send_data sd;
5052 /* Send RSL CHAN REL (deactivate) */
5053 PCU.clear;
5054 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5055 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005056 timer T_wait := 2.0;
5057 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005058 alt {
5059 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5060 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 +02005061 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5062 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5063 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005064 }
5065 }
5066 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005067 [] T_wait.timeout {
5068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5069 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5070 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005071 }
5072 /* Emulate PCU asking BTS to deactivate PDCH */
5073 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5074 alt {
5075 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5076 setverdict(pass);
5077 }
5078 [] RSL.receive { repeat; }
5079 }
5080}
5081
5082/* Activate Osmocom-style dynamic PDCH from BSC side */
5083function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5084 var PCUIF_Message first_info;
5085 var integer ts_nr := g_chan_nr.tn;
5086 var integer trx_nr := 0;
5087 var integer bts_nr := 0;
5088 var integer pcu_conn_id := -1;
5089
5090 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5091
5092 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5093 f_sleep(3.0);
5094 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5095 setverdict(pass);
5096}
5097testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5098 var ConnHdlrPars pars;
5099 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005100 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005101
5102 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5103 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5104 vc_conn.done;
5105}
5106
5107/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5108function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5109 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005110 var integer pcu_conn_id := -1;
5111
5112 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5113
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005114 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5115 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5116 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005117 setverdict(pass);
5118}
5119testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5120 var ConnHdlrPars pars;
5121 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005122 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005123
5124 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5125 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5126 vc_conn.done;
5127}
5128
5129/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5130function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5131 var PCUIF_Message first_info;
5132 var integer ts_nr := g_chan_nr.tn;
5133 var integer trx_nr := 0;
5134 var integer bts_nr := 0;
5135 var integer pcu_conn_id := -1;
5136
5137 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5138
5139 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005140 /* Send a second Chan Activ and expect it to be NACKed */
5141 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5142 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005143 setverdict(pass);
5144}
5145testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5146 var ConnHdlrPars pars;
5147 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005148 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005149
5150 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5151 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5152 vc_conn.done;
5153}
5154
5155/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5156function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5157 var PCUIF_Message first_info;
5158 var integer ts_nr := g_chan_nr.tn;
5159 var integer trx_nr := 0;
5160 var integer bts_nr := 0;
5161 var integer pcu_conn_id := -1;
5162 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5163
5164 /* register for the TCH/F channel number */
5165 f_rslem_register(0, chan_nr);
5166
5167 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5168
5169 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5170 "RSL CHAN ACT");
5171 setverdict(pass);
5172}
5173testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5174 var ConnHdlrPars pars;
5175 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005176 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005177
5178 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5179 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5180 vc_conn.done;
5181}
5182
5183/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5184function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5185 var PCUIF_Message first_info;
5186 var integer ts_nr := g_chan_nr.tn;
5187 var integer trx_nr := 0;
5188 var integer bts_nr := 0;
5189 var integer pcu_conn_id := -1;
5190 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5191 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5192
5193 /* register for the TCH/H channel numbers */
5194 f_rslem_register(0, chan_nr[0]);
5195 f_rslem_register(0, chan_nr[1]);
5196
5197 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5198
5199 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5200 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5201 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5202 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5203 setverdict(pass);
5204}
5205testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5206 var ConnHdlrPars pars;
5207 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005208 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005209
5210 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5211 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5212 vc_conn.done;
5213}
5214
Harald Welte9bbbfb52018-04-05 09:33:19 +02005215/***********************************************************************
5216 * IPA Style Dynamic Timeslot Support
5217 ***********************************************************************/
5218
5219private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5220runs on ConnHdlr {
5221 var PCUIF_send_data sd;
5222 /* Expect BTS to immediately acknowledge activation as PDCH */
5223 PCU.clear;
5224 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5225 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005226 timer T_wait := 2.0;
5227 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005228 alt {
5229 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5230 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 +01005231 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5232 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5233 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005234 }
5235 }
5236 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005237 [] T_wait.timeout {
5238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5239 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5240 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005241 }
5242 /* try to activate this PDCH from the PCU point of view */
5243 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5244 /* FIXME: is there a response? */
5245
5246 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5247}
5248
5249private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5250runs on ConnHdlr {
5251 var PCUIF_send_data sd;
5252 /* Send RSL CHAN REL (deactivate) */
5253 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5254 PCU.clear;
5255 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005256 timer T_wait := 2.0;
5257 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005258 alt {
5259 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5260 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 +01005261 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5262 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5263 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005264 }
5265 }
5266 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005267 [] T_wait.timeout {
5268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5269 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5270 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005271 }
5272 /* Emulate PCU asking BTS to deactivate PDCH */
5273 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5274 alt {
5275 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5276 setverdict(pass);
5277 }
5278 [] RSL.receive { repeat; }
5279 }
5280}
5281
5282/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5283function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5284 var PCUIF_Message first_info;
5285 var integer ts_nr := g_chan_nr.tn;
5286 var integer trx_nr := 0;
5287 var integer bts_nr := 0;
5288 var integer pcu_conn_id := -1;
5289
5290 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5291
5292 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5293 f_sleep(3.0);
5294 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5295
5296 setverdict(pass);
5297
5298}
5299testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5300 var ConnHdlrPars pars;
5301 var ConnHdlr vc_conn;
5302 f_init();
5303
5304 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5305 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5306 vc_conn.done;
5307}
5308
5309/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5310function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5311 var PCUIF_Message first_info;
5312 var integer ts_nr := g_chan_nr.tn;
5313 var integer trx_nr := 0;
5314 var integer bts_nr := 0;
5315 var integer pcu_conn_id := -1;
5316
5317 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5318
5319 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5320 "RSL CHAN ACT");
5321 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5322 "RF CHAN REL", true);
5323 setverdict(pass);
5324}
5325testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5326 var ConnHdlrPars pars;
5327 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005328 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005329
5330 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5331 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5332 vc_conn.done;
5333}
5334
5335/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5336function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5337 var PCUIF_Message first_info;
5338 var integer ts_nr := g_chan_nr.tn;
5339 var integer trx_nr := 0;
5340 var integer bts_nr := 0;
5341 var integer pcu_conn_id := -1;
5342
5343 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5344
5345 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5346 "RSL CHAN ACT");
5347
5348 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5349 alt {
5350 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5351 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005353 }
5354 [] RSL.receive { repeat; }
5355 }
5356
5357 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5358 "RF CHAN REL", true);
5359 setverdict(pass);
5360}
5361testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5362 var ConnHdlrPars pars;
5363 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005364 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005365
5366 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5367 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5368 vc_conn.done;
5369}
5370
5371/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5372function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5373 var PCUIF_Message first_info;
5374 var integer ts_nr := g_chan_nr.tn;
5375 var integer trx_nr := 0;
5376 var integer bts_nr := 0;
5377 var integer pcu_conn_id := -1;
5378
5379 /* register for the TCH/F channel number */
5380 f_rslem_register(0, g_chan_nr);
5381
5382 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5383
5384 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5385
5386 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5387 "RSL CHAN ACT");
5388
5389 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5390
5391 setverdict(pass);
5392}
5393testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5394 var ConnHdlrPars pars;
5395 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005396 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005397
5398 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5399 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5400 vc_conn.done;
5401}
5402
5403
Harald Welte0472ab42018-03-12 15:02:26 +01005404/***********************************************************************
5405 * LAPDm / RLL related
5406 ***********************************************************************/
5407
5408private function f_tx_lapdm(template (value) LapdmFrame l,
5409 template (value) RslLinkId link_id) runs on ConnHdlr {
5410 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005411 var template (value) SacchL1Header l1h;
5412
5413 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005414 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005415 /* Compose dummy L1 header */
5416 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5417 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 +02005418 } else {
5419 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005420 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 +01005421 }
Harald Welte0472ab42018-03-12 15:02:26 +01005422}
5423
5424type record RllTestCase {
5425 uint3_t sapi,
5426 RslLinkId link_id,
5427 octetstring l3,
5428 boolean exp
5429}
5430type record of RllTestCase RllTestCases;
5431template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5432 sapi := sapi,
5433 link_id := id,
5434 l3 := l3,
5435 exp := exp
5436}
5437
5438/* execute the same callback function with a set of different parameters (tcs) on a
5439 * variety of logical channels */
5440private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5441 var ConnHdlrPars pars;
5442 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005443 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005444
5445 /* test on each of the channels we have */
5446 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5447 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5448
5449 /* test each of the test cases on the current channel */
5450 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5451 pars.spec.rll := tcs[j];
5452 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5453 vc_conn := f_start_handler(fn, pars);
5454 vc_conn.done;
5455 }
5456 }
5457
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005459}
5460
5461/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5462private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5463 var RllTestCase tc := g_pars.spec.rll;
5464 timer T := 3.0;
5465
5466 f_l1_tune(L1CTL);
5467 RSL.clear;
5468
5469 /* activate the logical channel */
5470 f_est_dchan();
5471 L1CTL.clear;
5472
5473 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5474 T.start;
5475 alt {
5476 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5477 if (tc.exp) {
5478 setverdict(pass);
5479 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005481 }
5482 }
5483 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5484 if (tc.exp) {
5485 setverdict(pass);
5486 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005488 }
5489 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005490 /* We also expect to receive the measurements */
5491 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005492 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005494 }
5495 [not tc.exp] T.timeout {
5496 setverdict(pass);
5497 }
5498 }
5499
5500 f_rsl_chan_deact();
5501 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5502 f_rslem_unregister(0, g_chan_nr);
5503}
5504testcase TC_rll_est_ind() runs on test_CT {
5505 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005506 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005507 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005508 /* normal SAPI0 establishment */
5509 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005510 /* SAPI 3 doesn't support contention resolution */
5511 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5512 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5513 /* normal SAPI3 establishment on main DCCH */
5514 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5515 /* normal SAPI3 establishment on SACCH */
5516 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5517 };
5518 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5519}
5520
5521/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5522private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5523 var RllTestCase tc := g_pars.spec.rll;
5524 var L1ctlDlMessage dl;
5525 timer T := 3.0;
5526
5527 f_l1_tune(L1CTL);
5528 RSL.clear;
5529
5530 /* activate the logical channel */
5531 f_est_dchan();
5532 L1CTL.clear;
5533
5534 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5535 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5536 T.start;
5537 alt {
5538 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5539 var LapdmFrame lapdm;
5540 var octetstring l2 := dl.payload.data_ind.payload;
5541 if (dl.dl_info.link_id.c == SACCH) {
5542 /* remove L1 header */
5543 l2 := substr(l2, 2, lengthof(l2)-2);
5544 }
5545 lapdm.ab := dec_LapdmFrameAB(l2);
5546 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5547 setverdict(pass);
5548 } else {
5549 repeat;
5550 }
5551 }
5552 [] L1CTL.receive { repeat; }
5553 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005555 }
5556 }
5557
5558 f_rsl_chan_deact();
5559 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5560 f_rslem_unregister(0, g_chan_nr);
5561}
5562testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5563 var RllTestCases tcs := {
5564 /* normal SAPI3 establishment on main DCCH */
5565 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5566 };
5567 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5568}
5569testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5570 var RllTestCases tcs := {
5571 /* normal SAPI3 establishment on SACCH */
5572 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5573 }
5574 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5575}
5576
5577/* altstep to receive a LAPDm frame matching the given template */
5578private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5579 var L1ctlDlMessage dl;
5580 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5581 var LapdmFrame lapdm;
5582 var octetstring l2 := dl.payload.data_ind.payload;
5583 if (dl.dl_info.link_id.c == SACCH) {
5584 /* remove L1 header */
5585 l2 := substr(l2, 2, lengthof(l2)-2);
5586 }
5587 if (ischosen(exp.ab)) {
5588 lapdm.ab := dec_LapdmFrameAB(l2);
5589 } else if (ischosen(exp.b4)) {
5590 lapdm.b4 := dec_LapdmFrameB4(l2);
5591 } else if (ischosen(exp.bbis)) {
5592 lapdm.bbis := dec_LapdmFrameBbis(l2);
5593 }
5594 log("Rx LAPDm ", lapdm);
5595 if (match(lapdm, exp)) {
5596 setverdict(pass);
5597 } else {
5598 repeat;
5599 }
5600 }
5601 [] L1CTL.receive { repeat; }
5602}
5603private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5604 timer T := t;
5605 T.start;
5606 alt {
5607 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005609 }
5610 [] as_l1_exp_lapdm(exp);
5611 }
5612}
5613
5614/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5615private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5616 /* send SABM from MS -> BTS */
5617 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5618 /* expect RLL EST IND on Abis */
5619 alt {
5620 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5621 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5622 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005624 }
5625 [] RSL.receive { repeat; }
5626 }
5627 /* expect UA from BTS -> MS */
5628 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5629}
5630
5631/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5632private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5633 var RllTestCase tc := g_pars.spec.rll;
5634
5635 f_l1_tune(L1CTL);
5636 RSL.clear;
5637
5638 /* activate the logical channel */
5639 f_est_dchan();
5640 L1CTL.clear;
5641
5642 /* first establish the link-layer */
5643 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5644
5645 /* then send the DISC */
5646 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5647 /* ... and expect the REL IND on the RSL side */
5648 alt {
5649 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5650 setverdict(pass);
5651 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005652 /* We also expect to receive the measurements */
5653 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005654 }
5655
5656 /* release the channel */
5657 f_rsl_chan_deact();
5658 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5659 f_rslem_unregister(0, g_chan_nr);
5660}
5661testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5662 var RllTestCases tcs := {
5663 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5664 };
5665 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5666}
5667
5668testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5669 var RllTestCases tcs := {
5670 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5671 };
5672 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5673}
5674testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5675 var RllTestCases tcs := {
5676 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5677 };
5678 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5679}
5680testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5681 var RllTestCases tcs := {
5682 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5683 };
5684 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5685}
5686
5687/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5688private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5689 var RllTestCase tc := g_pars.spec.rll;
5690 f_l1_tune(L1CTL);
5691 RSL.clear;
5692
5693 /* activate the logical channel */
5694 f_est_dchan();
5695 L1CTL.clear;
5696
5697 /* first establish the link-layer */
5698 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5699
5700 /* then send the REL REQ via RSL */
5701 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5702 /* ... and expect the DISC on the Um side */
5703 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005704 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005705 /* FIXME: send a UA in resposne to the DISC */
5706 }
5707 }
5708
5709 /* release the channel */
5710 f_rsl_chan_deact();
5711 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5712 f_rslem_unregister(0, g_chan_nr);
5713}
5714testcase TC_rll_rel_req() runs on test_CT {
5715 var RllTestCases tcs := {
5716 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5717 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5718 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5719 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5720 };
5721 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5722}
5723
5724/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5725testcase TC_rll_data_req() runs on test_CT {
5726}
5727
5728/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5729testcase TC_rll_data_ind() runs on test_CT {
5730}
5731
5732/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5733private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5734 var RllTestCase tc := g_pars.spec.rll;
5735
5736 f_l1_tune(L1CTL);
5737 RSL.clear;
5738
5739 f_est_dchan();
5740 L1CTL.clear;
5741
5742 /* Send UNITDATA REQ on RSL side */
5743 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5744 /* Expect it to arrive on the other side */
5745 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005746 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005747 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005748 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005749 }
5750
5751 /* release the channel */
5752 f_rsl_chan_deact();
5753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5754 f_rslem_unregister(0, g_chan_nr);
5755}
5756testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5757 var octetstring l3 := f_rnd_octstring(15);
5758 var RllTestCases tcs := {
5759 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5760 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5761 };
5762 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5763}
5764testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5765 var octetstring l3 := f_rnd_octstring(19);
5766 var RllTestCases tcs := {
5767 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5768 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5769 };
5770 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5771}
5772
5773/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5774private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5775 var RllTestCase tc := g_pars.spec.rll;
5776
5777 f_l1_tune(L1CTL);
5778 RSL.clear;
5779
5780 f_est_dchan();
5781 L1CTL.clear;
5782
5783 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005784 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005785 /* Expdct RLL UNITDATA IND on RSL side */
5786 alt {
5787 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5788 setverdict(pass);
5789 }
5790 [] RSL.receive { repeat; }
5791 }
5792
5793 /* release the channel */
5794 f_rsl_chan_deact();
5795 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5796 f_rslem_unregister(0, g_chan_nr);
5797}
5798testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005799 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005800 var RllTestCases tcs := {
5801 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5802 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5803 };
5804 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5805}
5806testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5807 var octetstring l3 := f_rnd_octstring(18);
5808 var RllTestCases tcs := {
5809 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5810 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5811 };
5812 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5813}
5814
Harald Weltee613f962018-04-18 22:38:16 +02005815/***********************************************************************
5816 * Encryption Related
5817 ***********************************************************************/
5818
5819/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5820function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5821 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5822 if (link_id.c == SACCH) {
5823 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5824 } else {
5825 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5826 }
5827}
5828
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005829/* Expect (or not expect) other kinds of messages */
5830private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5831 [exp_any] RSL.receive { repeat; }
5832 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005834 }
5835}
5836
Harald Weltee613f962018-04-18 22:38:16 +02005837/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005838private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005839 RslLinkId link_id,
5840 octetstring l3,
5841 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005842 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005843) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005844 timer T := 3.0;
5845 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5846 T.start;
5847 /* Expect RLL UNITDATA IND on RSL side */
5848 alt {
5849 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5850 setverdict(pass);
5851 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005852 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005853 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005854 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005856 }
Harald Weltee613f962018-04-18 22:38:16 +02005857 }
5858}
5859
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005860/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5861private function f_data_mo(
5862 RslLinkId link_id,
5863 boolean p, uint3_t nr, uint3_t ns,
5864 octetstring l3,
5865 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005866 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005867) runs on ConnHdlr {
5868 timer T := 3.0;
5869 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5870 T.start;
5871 /* Expect RLL DATA IND on RSL side */
5872 alt {
5873 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5874 setverdict(pass);
5875 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005876 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005877 [] as_rsl_any_ind(exp_any);
5878 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005880 }
5881 }
5882}
5883
Harald Weltee613f962018-04-18 22:38:16 +02005884/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5885function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5886 f_l1_tune(L1CTL);
5887 f_est_dchan(true);
5888
5889 /* now we actually need to transmit some data both ways to check if the encryption works */
5890 var L1ctlDlMessage dl;
5891
Stefan Sperling603d98e2018-07-25 16:47:28 +02005892 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005893 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5894
5895 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5896 f_unitdata_mt(link_id, l3);
5897
5898 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5899 f_unitdata_mo(link_id, l3);
5900
5901 /* release the channel */
5902 f_rsl_chan_deact();
5903 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5904 f_rslem_unregister(0, g_chan_nr);
5905}
5906testcase TC_chan_act_a51() runs on test_CT {
5907 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5908 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5909 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5910}
5911testcase TC_chan_act_a52() runs on test_CT {
5912 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5913 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5914 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5915}
5916testcase TC_chan_act_a53() runs on test_CT {
5917 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5918 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5919 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5920}
5921
Eric Wildf1827a72019-05-28 17:37:35 +02005922/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5923 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5924function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5925 f_l1_tune(L1CTL);
5926 f_est_dchan(true);
5927
5928 /* now we actually need to transmit some data both ways to check if the encryption works */
5929 var L1ctlDlMessage dl;
5930
5931 var octetstring l3 := f_rnd_octstring(20);
5932 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5933
5934 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5935 f_unitdata_mt(link_id, l3);
5936
5937 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5938 f_unitdata_mo(link_id, l3);
5939
5940 var RSL_Message rsl;
5941 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5942
5943 /* modify key to break proper encryption */
5944 g_pars.encr.key := f_rnd_octstring(8);
5945 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5946 rsl.ies := rsl.ies & { ei };
5947 RSL.send(rsl);
5948
5949 timer T0 := 1.0;
5950 T0.start;
5951 /* Expect RSL MODIFY ACK */
5952 alt {
5953 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5954 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5956 }
5957 [] T0.timeout {
5958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5959 }
5960 }
5961
5962 var octetstring l3msg := f_rnd_octstring(15);
5963 timer T1 := 3.0;
5964 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5965 due to broken encryption */
5966 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5967 T1.start;
5968 alt {
5969 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5971 }
5972 [] T1.timeout {
5973 setverdict(pass);
5974 }
5975 }
5976
5977 /* release the channel */
5978 f_rsl_chan_deact();
5979 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5980 f_rslem_unregister(0, g_chan_nr);
5981}
5982testcase TC_rsl_modify_encr() runs on test_CT {
5983 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5984 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5985 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5986}
Harald Weltee613f962018-04-18 22:38:16 +02005987
5988/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5989function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5990 /* L3 payload doesn't matter, as it is passed transparently */
5991 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5992 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5993 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5994
5995 f_l1_tune(L1CTL);
5996
5997 /* first establish a dedicated channel in the clear */
5998 f_est_dchan(false);
5999
6000 /* Establish ABM */
6001 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6002
6003 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6004 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6005 /* expect the L3 to arrive still unencrypted on the MS side */
6006 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6007
6008 /* configure L1 to apply ciphering */
6009 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6010 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6011
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006012 /* send first ciphered I-frame in response and expect it on RSL */
6013 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006014
6015 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6016 * and hence enable encryption also on the downlink */
6017
6018 /* expect bi-directional communication work in encrypted mode */
6019 f_unitdata_mo(link_id, f_rnd_octstring(15));
6020 f_unitdata_mt(link_id, f_rnd_octstring(15));
6021
6022 /* release the channel */
6023 f_rsl_chan_deact();
6024 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6025 f_rslem_unregister(0, g_chan_nr);
6026}
6027testcase TC_encr_cmd_a51() runs on test_CT {
6028 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6029 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6030 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6031}
6032testcase TC_encr_cmd_a52() runs on test_CT {
6033 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6034 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6035 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6036}
6037testcase TC_encr_cmd_a53() runs on test_CT {
6038 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6039 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6040 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6041}
6042
6043private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6044 var LapdmFrame lf;
6045 var octetstring reenc;
6046
6047 /* decode the LAPDm frame */
6048 if (ischosen(exp_match.ab)) {
6049 lf.ab := dec_LapdmFrameAB(enc);
6050 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006052 }
6053
6054 /* check if decoder result matches expectation */
6055 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006057 } else {
6058 log(name, ": matched");
6059 setverdict(pass);
6060 }
6061
6062 /* test if re-encoded frame equals original input */
6063 reenc := enc_LapdmFrame(lf);
6064 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006066 } else {
6067 setverdict(pass);
6068 }
6069}
6070
6071testcase TC_lapdm_selftest() runs on test_CT {
6072 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6073 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6074 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6075 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6076 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6077 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6078 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6079}
6080
Stefan Sperling4880be42018-08-07 18:12:59 +02006081/***********************************************************************
6082 * DTX Related (see GSM 05.08, section 8.3)
6083 ***********************************************************************/
6084
6085/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6086function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6087 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6088 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6089 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6090 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6091}
6092function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6093 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6094 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6095}
6096function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6097 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6098 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6099 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6100 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6101}
6102function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6103 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6104 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6105 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6106 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6107 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6108 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6109 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6110 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6111}
6112
6113function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6114 var L1ctlDlMessage dl;
6115 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6116 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6117 var GsmFrameNumber first_fn;
6118 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006119 var integer nfill_frames_sacch := 0;
6120 var integer nfill_frames_nonsacch := 0;
6121 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006122 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6123 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006124 const integer frame_dtx_tchf_mod := 104;
6125 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6126 * which operates in terms of blocks rather than frames. */
6127 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6128 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006129 timer T := 5.0;
6130
6131 f_l1_tune(L1CTL);
6132 RSL.clear;
6133 L1CTL.clear;
6134
6135 /* activate TCHF signalling channel */
6136 f_est_dchan(false);
6137
6138 T.start;
6139 alt {
6140 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6141 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6142 var octetstring l2 := dl.payload.data_ind.payload;
6143
6144 if (is_first_frame) {
6145 is_first_frame := false;
6146 first_fn := dl.dl_info.frame_nr;
6147 }
6148
6149 if (dl.dl_info.link_id.c == SACCH) {
6150 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6151 if (not match(l2_fill_frame_sacch, l2)) {
6152 repeat;
6153 }
6154 } else if (not match(l2_fill_frame, l2)) {
6155 repeat;
6156 }
6157
6158 if (dtxd) {
6159 if (not f_g_chan_is_tchf()) {
6160 T.stop;
6161 f_rsl_chan_deact();
6162 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006163 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 +02006164 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006165 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006166 T.stop;
6167 f_rsl_chan_deact();
6168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006169
6170 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6171 * 2 SACCH, 1 TCH/F */
6172 expected_fill_frames := 3;
6173
6174 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6175 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6176 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006178 } else {
6179 setverdict(pass);
6180 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006181 } else {
6182 if (dl.dl_info.link_id.c == SACCH) {
6183 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006184 repeat;
6185 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006186 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6187 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6188 * we should only see the subset of frames numbers which correspond to a block boundary.
6189 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6190 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6191 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6192 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6193 repeat;
6194 }
6195 }
6196 log("Received DTX TCH fill frame with bad frame number: ", fn,
6197 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6198 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6199 f_rsl_chan_deact();
6200 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006202 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006203 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006204 if (dl.dl_info.link_id.c == SACCH) {
6205 nfill_frames_sacch := nfill_frames_sacch + 1;
6206 } else {
6207 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6208 }
6209 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006210 T.stop;
6211 if (f_g_chan_is_tchf()) {
6212 /* Without DTX we can expect 25 fill frames for every 104 frames.
6213 * (24 FACCH + 1 SACCH filling) */
6214 expected_fill_frames := 25;
6215 } else if (f_g_chan_is_tchh()) {
6216 /* We can expect 2 fill frames for every 104 frames. */
6217 expected_fill_frames := 2;
6218 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6219 /* We can expect 5 fill frames for every 104 frames. */
6220 expected_fill_frames := 5;
6221 } else {
6222 f_rsl_chan_deact();
6223 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006225 }
6226
6227 f_rsl_chan_deact();
6228 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006229
6230 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006231 setverdict(pass);
6232 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006233 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6234 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006236 }
6237 } else {
6238 repeat;
6239 }
6240 }
6241 }
6242 [] L1CTL.receive { repeat; }
6243 [] T.timeout {
6244 f_rsl_chan_deact();
6245 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006247 }
6248 }
6249}
6250
6251function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6252 f_test_l2_fill_frames(false);
6253}
6254
6255function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6256 f_test_l2_fill_frames(true);
6257}
6258
6259function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6260 var ConnHdlr vc_conn;
6261 var ConnHdlrPars pars;
6262 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006263 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006264 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6265 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6266 if (dtxd) {
6267 if (i >= 4) { /* DTX is only allowed on TCH/F */
6268 break;
6269 }
6270 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6271 } else {
6272 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6273 }
6274 vc_conn.done;
6275 }
6276}
6277
6278/* Verify that L2 fill frames are sent on TCH in signaling mode if
6279 * there is nothing to transmit while DTX is disabled on downlink. */
6280testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6281 f_tch_sign_l2_fill_frame(false);
6282}
6283
6284/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6285 * there is nothing to transmit while DTX is enabled on downlink. */
6286testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6287 f_tch_sign_l2_fill_frame(true);
6288}
Harald Welte0472ab42018-03-12 15:02:26 +01006289
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006290testcase TC_chopped_ipa_ping() runs on test_CT {
6291 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6292}
6293
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006294testcase TC_chopped_ipa_payload() runs on test_CT {
6295 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6296}
6297
Harald Welte0472ab42018-03-12 15:02:26 +01006298/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6299/* protocol error as per 44.006 */
6300/* link layer failure (repetition of I-frame N200 times without ACK */
6301/* repetition of SABM or DISC N200 times without ACK */
6302/* receptiom of SABM in multi-frame established state */
6303
6304
Harald Welte68e495b2018-02-25 00:05:57 +01006305/* TODO Areas:
6306
6307* channel activation
6308** with BS_Power / MS_Power, bypassing power control loop
6309** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006310** with timing advance from initial activation on
6311* mode modify
6312** encryption
6313** multirate
6314* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006315** unsupported algorithm
6316* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006317* BS Power Control
6318* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006319* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006320* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006321** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006322* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006323** DATA_IND from BTS->PCU
6324** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006325
6326*/
Harald Welte70767382018-02-21 12:16:40 +01006327
6328control {
6329 execute( TC_chan_act_stress() );
6330 execute( TC_chan_act_react() );
6331 execute( TC_chan_deact_not_active() );
6332 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006333 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006334 execute( TC_sacch_filling() );
6335 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006336 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006337 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006338 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006339 execute( TC_sacch_chan_act_ho_async() );
6340 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006341 execute( TC_rach_content() );
6342 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006343 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006344 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006345 execute( TC_rach_load_idle_thresh0() );
6346 execute( TC_rach_load_idle_below_thresh() );
6347 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006348 execute( TC_meas_res_sign_tchf() );
6349 execute( TC_meas_res_sign_tchh() );
6350 execute( TC_meas_res_sign_sdcch4() );
6351 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006352 execute( TC_meas_res_sign_tchh_toa256() );
Eric Wildae8f2622019-06-18 17:05:11 +02006353 execute( TC_rsl_bs_pwr_static_ass() );
6354 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006355 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006356 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006357 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006358 execute( TC_rsl_ms_pwr_dyn_up() );
6359 execute( TC_rsl_ms_pwr_dyn_down() );
6360 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6361 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006362 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006363 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006364 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006365 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006366 execute( TC_paging_imsi_80percent() );
6367 execute( TC_paging_tmsi_80percent() );
6368 execute( TC_paging_imsi_200percent() );
6369 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006370 execute( TC_rsl_protocol_error() );
6371 execute( TC_rsl_mand_ie_error() );
6372 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006373 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006374 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006375 execute( TC_si_sched_2bis() );
6376 execute( TC_si_sched_2ter() );
6377 execute( TC_si_sched_2ter_2bis() );
6378 execute( TC_si_sched_2quater() );
6379 execute( TC_si_sched_13() );
6380 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006381 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006382 execute( TC_ipa_crcx_twice_not_active() );
6383 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006384 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006385 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006386
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006387 if (mp_pcu_socket != "") {
6388 execute( TC_pcu_act_req() );
6389 execute( TC_pcu_act_req_wrong_ts() );
6390 execute( TC_pcu_act_req_wrong_bts() );
6391 execute( TC_pcu_act_req_wrong_trx() );
6392 execute( TC_pcu_deact_req() );
6393 execute( TC_pcu_deact_req_wrong_ts() );
6394 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006395 if (mp_l1_supports_gprs) {
6396 execute( TC_pcu_data_req_pdtch() );
6397 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006398 execute( TC_pcu_data_req_wrong_bts() );
6399 execute( TC_pcu_data_req_wrong_trx() );
6400 execute( TC_pcu_data_req_wrong_ts() );
6401 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006402 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006403 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006404 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006405 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006406 execute( TC_pcu_data_req_imm_ass_pch() );
6407 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006408 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006409 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006410 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006411 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006412 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006413 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006414 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006415 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006416 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006417 execute( TC_pcu_socket_noconnect_nosi3gprs() );
6418 execute( TC_pcu_socket_connect_si3gprs() );
6419 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006420 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006421 execute( TC_dyn_osmo_pdch_act_deact() );
6422 execute( TC_dyn_osmo_pdch_double_act() );
6423 execute( TC_dyn_ipa_pdch_act_deact() );
6424 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6425
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006426 } else {
6427 log("PCU socket path not available, skipping PCU tests");
6428 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006429
Harald Welte3d04ae62018-04-04 20:29:05 +02006430 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006431 execute( TC_dyn_osmo_pdch_tchf_act() );
6432 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006433 execute( TC_dyn_ipa_pdch_tchf_act() );
6434 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006435
6436 execute( TC_rll_est_ind() );
6437 execute( TC_rll_est_req_DCCH_3() );
6438 execute( TC_rll_est_req_ACCH_3() );
6439 execute( TC_rll_rel_ind_DCCH_0() );
6440 execute( TC_rll_rel_ind_DCCH_3() );
6441 execute( TC_rll_rel_ind_ACCH_0() );
6442 execute( TC_rll_rel_ind_ACCH_3() );
6443 execute( TC_rll_rel_req() );
6444 execute( TC_rll_unit_data_req_DCCH() );
6445 execute( TC_rll_unit_data_req_ACCH() );
6446 execute( TC_rll_unit_data_ind_DCCH() );
6447 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006448
6449 execute( TC_chan_act_a51() );
6450 execute( TC_chan_act_a52() );
6451 execute( TC_chan_act_a53() );
6452 execute( TC_encr_cmd_a51() );
6453 execute( TC_encr_cmd_a52() );
6454 execute( TC_encr_cmd_a53() );
6455
Harald Welteee25aae2019-05-19 14:32:37 +02006456 execute( TC_err_rep_wrong_mdisc() );
6457 execute( TC_err_rep_wrong_msg_type() );
6458 execute( TC_err_rep_wrong_sequence() );
6459
Harald Weltee613f962018-04-18 22:38:16 +02006460 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006461
6462 execute( TC_tch_sign_l2_fill_frame() );
6463 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006464
6465 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006466 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006467}
6468
6469
6470}