blob: 3ed3655969a32393be594e186ead881ba7a8c933 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010038import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020039import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010040
41import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010042import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010043import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020044import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010045import from RSL_Emulation all;
46
47import from IPL4asp_Types all;
48import from TRXC_Types all;
49import from TRXC_CodecPort all;
50import from TRXC_CodecPort_CtrlFunct all;
51
Harald Welte883340c2018-02-28 18:59:29 +010052import from PCUIF_Types all;
53import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020054import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010055
Harald Welte7484fc42018-02-24 14:09:45 +010056import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010057import from MobileL3_RRM_Types all;
58import from MobileL3_Types all;
59import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020060import from L3_Common all;
61import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010062
Harald Welte8da48242018-02-27 20:41:32 +010063import from Osmocom_VTY_Functions all;
64import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020065import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010066
Harald Welte505cf9b2018-09-15 17:47:23 +030067friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020068friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020069friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010070friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030071
Harald Welte70767382018-02-21 12:16:40 +010072/* The tests assume a BTS with the following timeslot configuration:
73 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020074 * TS1 : TCH/F
75 * TS2 : TCH/F
76 * TS3 : TCH/F_PDCH (IPA Style)
77 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010078 * TS5 : TCH/H
79 * TS6 : SDCCH/8
80 * TS7 : PDCH
81 */
82
83modulepar {
84 charstring mp_rsl_ip := "127.0.0.2";
85 integer mp_rsl_port := 3003;
86 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070087 charstring mp_bts_trxc_ip := "127.0.0.1";
88 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010089 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020090 charstring mp_ctrl_ip := "127.0.0.1";
91 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020092 charstring mp_bsc_ctrl_ip := "127.0.0.1";
93 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020094 integer mp_tolerance_rxqual := 1;
95 integer mp_tolerance_rxlev := 3;
96 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020097 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020098 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020099 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_ms_actual_ta_exp := 0;
101 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100102 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200103 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200104 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200105 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
106 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100107}
108
Harald Welte629cc6b2018-03-11 17:19:05 +0100109type record of RslChannelNr ChannelNrs;
110
Harald Welte70767382018-02-21 12:16:40 +0100111type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100113 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100114 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100115 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100116 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100117 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100118
119 /* L1CTL port (for classic tests) */
120 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100121
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700122 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700123 port TRXC_CODEC_PT BTS_TRXC;
124 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100125
Harald Weltef50e3ae2018-09-10 10:27:56 +0200126 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100127 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200128 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100129
Harald Welte883340c2018-02-28 18:59:29 +0100130 /* PCU Interface of BTS */
131 port PCUIF_CODEC_PT PCU;
132 var integer g_pcu_conn_id;
133 /* Last PCU INFO IND we received */
134 var PCUIF_Message g_pcu_last_info;
135
Harald Welte48494ca2018-02-25 16:59:50 +0100136 /* SI configuration */
137 var SystemInformationConfig si_cfg := {
138 bcch_extended := false,
139 si1_present := false,
140 si2bis_present := false,
141 si2ter_present := false,
142 si2quater_present := false,
143 si7_present := false,
144 si8_present := false,
145 si9_present := false,
146 si13_present := false,
147 si13alt_present := false,
148 si15_present := false,
149 si16_present := false,
150 si17_present := false,
151 si2n_present := false,
152 si21_present := false,
153 si22_present := false
154 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100155
156 /* all logical channels available on the BTS */
157 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100158 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100159}
160
161/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200162type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100163 port L1CTL_PT L1CTL;
164
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700165 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700166 port TRXC_CODEC_PT BTS_TRXC;
167 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100168
169 timer g_Tguard;
170 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
171
172 var ConnHdlrPars g_pars;
173 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100174 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200175
176 /* PCU Interface of BTS */
177 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100178}
179
180function f_init_rsl(charstring id) runs on test_CT {
181 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
182 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
183
184 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
185 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
186 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
187
188 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
189 vc_RSL.start(RSL_Emulation.main(false));
190}
191
192type record ConnHdlrPars {
193 RslChannelNr chan_nr,
194 RSL_IE_ChannelMode chan_mode,
195 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100196 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200197 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200198 RSL_IE_EncryptionInfo encr optional,
199 BtsBand bts0_band optional
Harald Welte0472ab42018-03-12 15:02:26 +0100200}
201
202/* Test-specific parameters */
203type union TestSpecUnion {
204 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100205}
206
Harald Welte82ccef72018-02-25 16:17:33 +0100207template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100208 max_retrans := RACH_MAX_RETRANS_7,
209 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100210 cell_barr_access := false,
211 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100212 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100213};
214
Harald Weltef10153f2018-02-25 16:34:05 +0100215template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100216 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200217 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100218 acs := '0'B,
219 neci := true,
220 rxlev_access_min := 0
221}
222
223template (value) LocationAreaIdentification ts_LAI_default := {
224 mcc_mnc := '262F42'H,
225 lac := 42
226}
227
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700228private template (value) GPRSIndicator ts_GPRSIndicator_def := {
229 ra_colour := 0,
230 si13_pos := '0'B
231}
232
233private template (value) SI3RestOctets ts_SI3RestOctets_def
234modifies ts_SI3RestOctets := {
235 gprs_ind := {
236 presence := CSN1_H,
237 ind := ts_GPRSIndicator_def
238 }
239}
240
241private template (value) SI4RestOctets ts_SI4RestOctets_def
242modifies ts_SI4RestOctets := {
243 gprs_ind := {
244 /* FIXME: GPRS Indicator shall be present here too */
245 presence := CSN1_L,
246 ind := omit
247 }
248}
249
Harald Welte7484fc42018-02-24 14:09:45 +0100250/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100251template (value) SystemInformation ts_SI3_default := {
252 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100253 payload := {
254 si3 := {
255 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100256 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100257 ctrl_chan_desc := {
258 msc_r99 := true,
259 att := true,
260 bs_ag_blks_res := 1,
261 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100262 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100263 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
264 spare := '00'B,
265 bs_pa_mfrms := 0, /* 2 multiframes */
266 t3212 := 1 /* 6 minutes */
267 },
Harald Welte82ccef72018-02-25 16:17:33 +0100268 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100269 dn_ind := false,
270 pwrc := false,
271 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100272 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100273 },
Harald Weltef10153f2018-02-25 16:34:05 +0100274 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100275 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700276 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100277 }
278 }
279}
Harald Welte70767382018-02-21 12:16:40 +0100280
Harald Weltef8df4cb2018-03-10 15:15:08 +0100281template (value) SystemInformation ts_SI2_default := {
282 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100283 payload := {
284 si2 := {
285 bcch_freq_list := '00000000000000000000000000000000'O,
286 ncc_permitted := '11111111'B,
287 rach_control := ts_RachCtrl_default
288 }
289 }
290}
291
Harald Weltef8df4cb2018-03-10 15:15:08 +0100292template (value) SystemInformation ts_SI4_default := {
293 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100294 payload := {
295 si4 := {
296 lai := ts_LAI_default,
297 cell_sel_par := ts_CellSelPar_default,
298 rach_control := ts_RachCtrl_default,
299 cbch_chan_desc := omit,
300 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700301 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100302 }
303 }
304}
305
306function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
307runs on test_CT {
308 log("Setting ", rsl_si_type, ": ", si_enc);
309 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
310}
311
312function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
313runs on test_CT {
314 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
315 log("Setting ", rsl_si_type, ": ", si_dec);
316 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
317}
318
Harald Welte505cf9b2018-09-15 17:47:23 +0300319friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100320 map(self:BTSVTY, system:BTSVTY);
321 f_vty_set_prompts(BTSVTY);
322 f_vty_transceive(BTSVTY, "enable");
323}
324
Harald Welte505cf9b2018-09-15 17:47:23 +0300325friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200326 map(self:BSCVTY, system:BSCVTY);
327 f_vty_set_prompts(BSCVTY, "OsmoBSC");
328 f_vty_transceive(BSCVTY, "enable");
329}
330
Harald Welte883340c2018-02-28 18:59:29 +0100331/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200332private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
333 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100334 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200335 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
336 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100337 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200338 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100340 }
341}
342
Harald Weltef26de0b2018-04-04 20:28:05 +0200343private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
344 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100345 timer T := 2.0;
346 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100347 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200348 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100349 return;
350 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200351 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100352
353 T.start;
354 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200355 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100356 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100358 }
359 }
360}
361
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700362private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
363 out integer trxc_conn_id) {
364 var Result res;
365
366 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
367 "", -1, -1, { udp := {} }, {});
368 if (not ispresent(res.connId)) {
369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
370 "Could not connect to the control (TRXC) interface " &
371 "of FakeTRX, check your configuration");
372 }
373 trxc_conn_id := res.connId;
374}
375
Harald Welte70767382018-02-21 12:16:40 +0100376/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200377function f_init() runs on test_CT {
378 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100379 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100380 g_AllChannels := {
381 /* TS 1..4: TCH/F */
382 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
383 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
384 /* TS 5: TCH/H */
385 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
386 /* TS 0: SDCCH/4 */
387 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
388 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
389 /* TS 6: SDCCH/8 */
390 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
391 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
392 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
393 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
394 };
395
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200396 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700397 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200398 g_AllChanTypes := {
399 /* TS 1..4: TCH/F */
400 valueof(ts_RslChanNr_Bm(1)),
401 /* TS 5: TCH/H */
402 valueof(ts_RslChanNr_Lm(5,1)),
403 /* TS 0: SDCCH/4 */
404 valueof(ts_RslChanNr_SDCCH4(0,2)),
405 /* TS 6: SDCCH/8 */
406 valueof(ts_RslChanNr_SDCCH8(6,4))
407 };
408 } else {
409 g_AllChanTypes := {
410 /* TS 1..4: TCH/F */
411 valueof(ts_RslChanNr_Bm(1)),
412 /* TS 0: SDCCH/4 */
413 valueof(ts_RslChanNr_SDCCH4(0,2)),
414 /* TS 6: SDCCH/8 */
415 valueof(ts_RslChanNr_SDCCH8(6,4))
416 };
417 }
Harald Welte70767382018-02-21 12:16:40 +0100418 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200419 T.start;
420 alt {
421 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
422 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200424 }
425 }
Harald Welte2d142592018-02-25 13:19:44 +0100426 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100427 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200428 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100429
430 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100431 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
432 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
433 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
434 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100435
Harald Weltef26de0b2018-04-04 20:28:05 +0200436 map(self:PCU, system:PCU);
437 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100438
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700439 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100440 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700441
442 /* Init TRXC interface to FakeTRX */
443 map(self:BTS_TRXC, system:BTS_TRXC);
444 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
445
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700446 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700447 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 +0700448 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700449 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
450 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100451 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200452
453 /* Wait some extra time to make sure the BTS emits a stable carrier.
454 * (this is only relevant when running the tests with a physical BTS.) */
455 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100456}
457
Harald Welte68e495b2018-02-25 00:05:57 +0100458/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
459function f_init_l1ctl() runs on test_CT {
460 map(self:L1CTL, system:L1CTL);
461 f_connect_reset(L1CTL);
462}
463
Harald Welte70767382018-02-21 12:16:40 +0100464type function void_fn(charstring id) runs on ConnHdlr;
465
466/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700467function f_start_handler(void_fn fn, ConnHdlrPars pars,
468 boolean pcu_comp := false,
469 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100470runs on test_CT return ConnHdlr {
471 var charstring id := testcasename();
472 var ConnHdlr vc_conn;
473
474 vc_conn := ConnHdlr.create(id);
475 /* connect to RSL Emulation main component */
476 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
477 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700478
479 /* The ConnHdlr component may want to talk to some ports directly,
480 * so we disconnect it from the test_CT and connect it to the component.
481 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200482 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200483 unmap(self:PCU, system:PCU);
484 map(vc_conn:PCU, system:PCU);
485 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700486 if (trxc_comp) {
487 unmap(self:BTS_TRXC, system:BTS_TRXC);
488 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
489 }
Harald Welte70767382018-02-21 12:16:40 +0100490
491 vc_conn.start(f_handler_init(fn, id, pars));
492 return vc_conn;
493}
494
Harald Welte7484fc42018-02-24 14:09:45 +0100495template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
496 streamId := sid,
497 rsl := rsl
498}
499
500template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
501 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
502 streamId := sid,
503 rsl := rsl
504}
505
Harald Welte70767382018-02-21 12:16:40 +0100506private altstep as_Tguard() runs on ConnHdlr {
507 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100509 }
510}
511
Harald Welte990a3612019-05-27 14:02:13 +0200512friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
513 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100514}
515
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700516private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100517 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700518 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100519}
520
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700521private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100522 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700523 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100524}
525
526/* first function started in ConnHdlr component */
527private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
528runs on ConnHdlr {
529 g_pars := pars;
530 g_chan_nr := pars.chan_nr;
531
532 map(self:L1CTL, system:L1CTL);
533 f_connect_reset(L1CTL);
534
Harald Welted48c0c72019-06-05 10:01:15 +0200535 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700536 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100537 }
Harald Welte70767382018-02-21 12:16:40 +0100538
539 g_Tguard.start(pars.t_guard);
540 activate(as_Tguard());
541
542 f_rslem_register(0, pars.chan_nr);
543
544 /* call the user-supplied test case function */
545 fn.apply(id);
546}
547
Harald Welteb1726c92018-03-30 11:56:38 +0200548function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
549 boolean ignore_other := false)
550runs on ConnHdlr return RSL_Message {
551 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100552 timer T := 3.0;
553 RSL.send(tx);
554 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100555 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200556 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100557 T.stop;
558 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100559 }
Harald Welte1eba3742018-02-25 12:48:14 +0100560 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100562 }
Harald Welte21240e62018-03-11 21:43:35 +0100563 [not ignore_other] as_l1_sacch();
564 [not ignore_other] as_meas_res();
565 [not ignore_other] as_l1_dcch();
566 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100568 }
Harald Welte21240e62018-03-11 21:43:35 +0100569 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100570 }
Harald Welteb1726c92018-03-30 11:56:38 +0200571 return rx;
572}
573
574function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
575 boolean ignore_other := false)
576runs on ConnHdlr {
577 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100578}
579
Harald Welte8b01c792019-05-19 22:51:25 +0200580function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
581 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
582 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200583 if (encr_enable) {
584 /* append encryption related IEs, if requested */
585 var RSL_IE_EncryptionInfo encr_info;
586 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
587 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
588encr_info})) };
589 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200590 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200591 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100592}
593
Harald Welte70767382018-02-21 12:16:40 +0100594function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100595 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 +0100596 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100597}
598
Harald Welte2f2b2b72019-05-31 22:24:57 +0200599friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100600 template RSL_IE_ChannelMode chan_mode,
601 float t_guard := 20.0) := {
602 chan_nr := valueof(chan_nr),
603 chan_mode := valueof(chan_mode),
604 t_guard := t_guard,
605 l1_pars := {
606 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100607 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100608 meas_ul := {
609 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200610 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100611 rxqual := 0
612 },
613 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200614 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100615 rxqual := 0
616 }
617 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200618 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100619 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200620 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200621 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100622 },
Harald Weltee613f962018-04-18 22:38:16 +0200623 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200624 encr := omit,
625 bts0_band := omit
Harald Welte70767382018-02-21 12:16:40 +0100626}
627
Harald Welte93640c62018-02-25 16:59:33 +0100628/***********************************************************************
629 * Channel Activation / Deactivation
630 ***********************************************************************/
631
Harald Welte70767382018-02-21 12:16:40 +0100632/* Stress test: Do 500 channel activations/deactivations in rapid succession */
633function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
634 for (var integer i := 0; i < 500; i := i+1) {
635 f_rsl_chan_act(g_pars.chan_mode);
636 f_rsl_chan_deact();
637 }
638 setverdict(pass);
639}
640testcase TC_chan_act_stress() runs on test_CT {
641 var ConnHdlr vc_conn;
642 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200643 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100644 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
645 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100647}
648
649/* Test if re-activation of an already active channel fails as expected */
650function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
651 f_rsl_chan_act(g_pars.chan_mode);
652 /* attempt to activate the same lchan again -> expect reject */
653 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
654 alt {
655 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100657 }
658 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
659 setverdict(pass);
660 }
661 }
662 f_rsl_chan_deact();
663}
664testcase TC_chan_act_react() runs on test_CT {
665 var ConnHdlr vc_conn;
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 vc_conn := f_start_handler(refers(f_TC_chan_act_react), 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 de-activate a channel that's not active */
674function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
675 timer T := 3.0;
676 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
677 T.start;
678 alt {
679 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
680 setverdict(pass);
681 }
682 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100684 }
685 }
686}
687testcase TC_chan_deact_not_active() runs on test_CT {
688 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100689 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100690 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
691 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100693}
694
695/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
696function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
697 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
698 alt {
699 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100701 }
702 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
703 setverdict(pass);
704 }
705 }
706}
707private type record WrongChanNrCase {
708 RslChannelNr chan_nr,
709 charstring description
710}
711private type record of WrongChanNrCase WrongChanNrCases;
712private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
713 chan_nr := chan_nr,
714 description := desc
715}
716
717testcase TC_chan_act_wrong_nr() runs on test_CT {
718 var ConnHdlr vc_conn;
719 var ConnHdlrPars pars;
720
Harald Welte294b0a22018-03-10 23:26:48 +0100721 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100722
723 var WrongChanNrCases wrong := {
724 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
725 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
726 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
727 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
728 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
729 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
730 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
731 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
732 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
733 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
734 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
735 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
736 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
737 };
738
739 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
740 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
741 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
742 vc_conn.done;
743 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100745}
746
Harald Weltee613f962018-04-18 22:38:16 +0200747/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200748friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200749 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200750 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200751
752 /* test on each of the channels we have */
753 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
754 pars.chan_nr := valueof(g_AllChanTypes[i]);
755
756 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
757 vc_conn := f_start_handler(fn, pars);
758 vc_conn.done;
759 }
760
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200762}
763
Harald Welte93640c62018-02-25 16:59:33 +0100764/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100765 * SACCH handling
766 ***********************************************************************/
767
768private function f_exp_sacch(boolean exp) runs on ConnHdlr {
769 timer T_sacch := 3.0;
770 T_sacch.start;
771 alt {
772 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100774 }
775 [not exp] T_sacch.timeout {
776 setverdict(pass);
777 }
778 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
779 setverdict(pass);
780 }
781 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100783 }
784 [] L1CTL.receive { repeat; }
785 [] RSL.receive { repeat; }
786 }
787}
788
789/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
790private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
791 f_l1_tune(L1CTL);
792 RSL.clear;
793
794 /* activate the logical channel */
795 f_est_dchan();
796 L1CTL.clear;
797
798 /* check that SACCH actually are received as expected */
799 f_exp_sacch(true);
800
801 /* deactivate SACCH on the logical channel */
802 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
803 f_sleep(1.0);
804 L1CTL.clear;
805
806 /* check that no SACCH are received anymore */
807 f_exp_sacch(false);
808
809 /* release the channel */
810 f_rsl_chan_deact();
811 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
812}
813testcase TC_deact_sacch() runs on test_CT {
814 var ConnHdlr vc_conn;
815 var ConnHdlrPars pars;
816 f_init();
817 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
818 //for (var integer i := 0; i < 1; i := i+1) {
819 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
820 log(testcasename(), ": Starting for ", g_AllChannels[i]);
821 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
822 vc_conn.done;
823 }
824 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100826}
827
Harald Welte55700662018-03-12 13:15:43 +0100828/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100829private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
830 var L1ctlDlMessage dl;
831 /* check that the specified SI5 value is actually sent */
832 timer T_sacch := 3.0;
833 L1CTL.clear;
834 T_sacch.start;
835 alt {
836 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
837 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
838 if (match(l3, l3_exp)) {
839 setverdict(pass);
840 } else {
841 repeat;
842 }
843 }
844 [] L1CTL.receive { repeat; }
845 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100847 }
848 }
849}
850
Harald Welte55700662018-03-12 13:15:43 +0100851/* verify that given SACCH payload is not present */
852private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
853 var L1ctlDlMessage dl;
854 /* check that the specified SI5 value is actually sent */
855 timer T_sacch := 3.0;
856 L1CTL.clear;
857 T_sacch.start;
858 alt {
859 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
860 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
861 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200862 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100863 } else {
864 repeat;
865 }
866 }
867 [] L1CTL.receive { repeat; }
868 [] T_sacch.timeout {
869 setverdict(pass);
870 }
871 }
872}
873
Harald Welte629cc6b2018-03-11 17:19:05 +0100874/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100875private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
876 /* Set a known default SACCH filling for SI5 */
877 var octetstring si5 := f_rnd_octstring(19);
878 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
879
880 f_l1_tune(L1CTL);
881 RSL.clear;
882
883 /* activate the logical channel */
884 f_est_dchan();
885
886 /* check that the specified SI5 value is actually sent */
887 f_sacch_present(si5);
888
889 /* release the channel */
890 RSL.clear;
891 f_rsl_chan_deact();
892 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
893}
894testcase TC_sacch_filling() runs on test_CT {
895 var ConnHdlr vc_conn;
896 var ConnHdlrPars pars;
897 f_init();
898 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
899 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
900 log(testcasename(), ": Starting for ", g_AllChannels[i]);
901 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
902 vc_conn.done;
903 }
904 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100906}
907
Harald Welte629cc6b2018-03-11 17:19:05 +0100908/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100909private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
910 /* Set a known default SACCH filling for SI5 */
911 var octetstring si5 := f_rnd_octstring(19);
912 var octetstring si5_diff := f_rnd_octstring(19);
913 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
914
915 f_l1_tune(L1CTL);
916 RSL.clear;
917
918 log("Activating channel, expecting standard SI5");
919 /* activate the logical channel */
920 f_est_dchan();
921 /* check that the specified SI5 value is actually sent */
922 f_sacch_present(si5);
923
924 /* set channel-specific different SI5 */
925 log("Setting channel specific SACCH INFO, expecting it");
926 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
927 /* check that the specified lchan-specific value is now used */
928 f_sacch_present(si5_diff);
929
930 /* deactivate the channel and re-activate it, this should result in default SI5 */
931 log("De-activating and re-activating channel, expecting standard SI5");
932 f_rsl_chan_deact();
933 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
934 /* Verify that the TRX-wide default SACCH filling is present again */
935 f_sacch_present(si5);
936
937 /* release the channel */
938 RSL.clear;
939 f_rsl_chan_deact();
940 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
941}
942testcase TC_sacch_info_mod() runs on test_CT {
943 var ConnHdlr vc_conn;
944 var ConnHdlrPars pars;
945 f_init();
946 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
947 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
948 log(testcasename(), ": Starting for ", g_AllChannels[i]);
949 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
950 vc_conn.done;
951 }
952 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100954}
955
Harald Welte075d84c2018-03-12 13:07:24 +0100956/* Test SACCH scheduling of multiple different SI message types */
957private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
958 var octetstring si5 := f_rnd_octstring(19);
959 var octetstring si5bis := f_rnd_octstring(19);
960 var octetstring si5ter := f_rnd_octstring(19);
961 var octetstring si6 := f_rnd_octstring(19);
962
963 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
964 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
965 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
966 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
967
968 f_l1_tune(L1CTL);
969 RSL.clear;
970
971 /* activate the logical channel */
972 f_est_dchan();
973 L1CTL.clear;
974
975 /* check that SACCH actually are received as expected */
976 f_sacch_present(si5);
977 f_sacch_present(si5bis);
978 f_sacch_present(si5ter);
979 f_sacch_present(si6);
980
981 /* release the channel */
982 f_rsl_chan_deact();
983 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
984}
985testcase TC_sacch_multi() runs on test_CT {
986 var ConnHdlr vc_conn;
987 var ConnHdlrPars pars;
988 f_init();
989 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
990 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
991 log(testcasename(), ": Starting for ", g_AllChannels[i]);
992 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
993 vc_conn.done;
994 }
995 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100997}
998
Harald Welte55700662018-03-12 13:15:43 +0100999/* Test if SACH information is modified as expected */
1000private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1001 var octetstring si5 := f_rnd_octstring(19);
1002 var octetstring si6 := f_rnd_octstring(19);
1003
1004 /* First, configure both SI5 and SI6 to be transmitted */
1005 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1006 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1007
1008 f_l1_tune(L1CTL);
1009 RSL.clear;
1010
1011 /* activate the logical channel */
1012 f_est_dchan();
1013 L1CTL.clear;
1014
1015 /* check that SACCH actually are received as expected */
1016 f_sacch_present(si5);
1017 f_sacch_present(si6);
1018
1019 /* disable SI6 */
1020 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1021
1022 /* check that SI5 is still transmitted */
1023 f_sacch_present(si5);
1024 /* check if SI6 is now gone */
1025 f_sacch_missing(si6);
1026
1027 /* release the channel */
1028 f_rsl_chan_deact();
1029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1030}
1031testcase TC_sacch_multi_chg() runs on test_CT {
1032 var ConnHdlr vc_conn;
1033 var ConnHdlrPars pars;
1034 f_init();
1035 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1036 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1037 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1038 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1039 vc_conn.done;
1040 }
1041 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001043}
1044
Harald Weltec8d363c2019-05-19 20:36:48 +02001045/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1046private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1047 var octetstring si5 := f_rnd_octstring(19);
1048 var octetstring si6 := f_rnd_octstring(19);
1049 var octetstring si5_specific := f_rnd_octstring(19);
1050 var octetstring si6_specific := f_rnd_octstring(19);
1051
1052 /* First, configure both SI5 and SI6 to be transmitted */
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1054 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1055
1056 f_l1_tune(L1CTL);
1057 RSL.clear;
1058
1059 /* activate channel with different SACCH filling */
1060 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1061 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1062 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1063 }));
1064 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1065 RSL_IE_Body:{sacch_info := sacch_info})) };
1066 f_est_dchan(more_ies := addl_ies);
1067
1068 /* check that SACCH actually are received as expected */
1069 f_sacch_present(si5_specific);
1070 f_sacch_present(si6_specific);
1071
1072 /* release the channel */
1073 f_rsl_chan_deact();
1074 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1075}
1076testcase TC_sacch_chan_act() runs on test_CT {
1077 var ConnHdlr vc_conn;
1078 var ConnHdlrPars pars;
1079 f_init();
1080
1081 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1082 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1083 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1084 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1085 vc_conn.done;
1086 }
1087 /* TODO: do the above in parallel, rather than sequentially? */
1088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1089}
1090
Harald Welte8b01c792019-05-19 22:51:25 +02001091/* verify that SACCH DL transmission is started only if MS power IE present
1092 * see section 4.1.3 of 3GPP TS 48.058 */
1093private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1094 var octetstring si5 := f_rnd_octstring(19);
1095
1096 f_l1_tune(L1CTL);
1097 RSL.clear;
1098
1099 /* Step 1: Activate ASYNC HO channel without MS power IE */
1100
1101 /* Activate channel on BTS side */
1102 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1103 /* don't perform immediate assignment here, as we're testing non-IA case */
1104 /* enable dedicated mode */
1105 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1106
1107 /* Verify that no DL SACCH is being received */
1108 f_sacch_missing(?);
1109
1110 f_rsl_chan_deact();
1111 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1112
1113
1114 /* Step 2: Activate ASYNC HO channel with MS power IE */
1115
1116 /* Activate channel on BTS side */
1117 var RSL_IE_List addl_ies := {
1118 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1119 };
1120 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1121 /* don't perform immediate assignment here, as we're testing non-IA case */
1122 /* enable dedicated mode */
1123 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1124
1125 /* Verify that DL SACCH is being received */
1126 f_sacch_present(si5);
1127
1128 f_rsl_chan_deact();
1129 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1130}
1131testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1132 var ConnHdlr vc_conn;
1133 var ConnHdlrPars pars;
1134 f_init();
1135
1136 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1137 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1138 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1139 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1140 vc_conn.done;
1141 }
1142 /* TODO: do the above in parallel, rather than sequentially? */
1143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1144}
1145
1146/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1147 * see section 4.1.4 of 3GPP TS 48.058 */
1148private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1149 var octetstring si5 := f_rnd_octstring(19);
1150 var RSL_IE_List addl_ies;
1151
1152 f_l1_tune(L1CTL);
1153 RSL.clear;
1154
1155 /* Step 1: Activate SYNC HO channel without MS power IE */
1156
1157 /* Activate channel on BTS side */
1158 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1159 /* don't perform immediate assignment here, as we're testing non-IA case */
1160 /* enable dedicated mode */
1161 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1162
1163 /* Verify that no DL SACCH is being received */
1164 f_sacch_missing(?);
1165
1166 f_rsl_chan_deact();
1167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1168
1169
1170 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1171
1172 /* Activate channel on BTS side */
1173 addl_ies := {
1174 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1175 };
1176 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1177 /* don't perform immediate assignment here, as we're testing non-IA case */
1178 /* enable dedicated mode */
1179 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1180
1181 /* Verify that no DL SACCH is being received */
1182 f_sacch_missing(?);
1183
1184 f_rsl_chan_deact();
1185 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1186
1187
1188 /* Step 2b: Activate SYNC HO channel with TA IE */
1189
1190 /* Activate channel on BTS side */
1191 addl_ies := {
1192 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1193 };
1194 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1195 /* don't perform immediate assignment here, as we're testing non-IA case */
1196 /* enable dedicated mode */
1197 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1198
1199 /* Verify that no DL SACCH is being received */
1200 f_sacch_missing(?);
1201
1202 f_rsl_chan_deact();
1203 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1204
1205
1206 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1207
1208 /* Activate channel on BTS side */
1209 addl_ies := {
1210 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1211 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1212 };
1213 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1214 /* don't perform immediate assignment here, as we're testing non-IA case */
1215 /* enable dedicated mode */
1216 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1217
1218 /* Verify that DL SACCH is being received */
1219 f_sacch_present(si5);
1220
1221 f_rsl_chan_deact();
1222 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1223}
1224testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1225 var ConnHdlr vc_conn;
1226 var ConnHdlrPars pars;
1227 f_init();
1228
1229 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1230 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1231 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1232 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1233 vc_conn.done;
1234 }
1235 /* TODO: do the above in parallel, rather than sequentially? */
1236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1237}
Harald Welte629cc6b2018-03-11 17:19:05 +01001238
1239
1240/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001241 * RACH Handling
1242 ***********************************************************************/
1243
Harald Welte8c24c2b2018-02-26 08:31:31 +01001244/* like L1SAP_IS_PACKET_RACH */
1245private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001246 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247 return true;
1248 }
1249 return false;
1250}
1251
1252/* generate a random RACH for circuit-switched */
1253private function f_rnd_ra_cs() return OCT1 {
1254 var OCT1 ra;
1255 do {
1256 ra := f_rnd_octstring(1);
1257 } while (ra_is_ps(ra));
1258 return ra;
1259}
1260
Harald Welte883340c2018-02-28 18:59:29 +01001261/* generate a random RACH for packet-switched */
1262private function f_rnd_ra_ps() return OCT1 {
1263 var OCT1 ra;
1264 do {
1265 ra := f_rnd_octstring(1);
1266 } while (not ra_is_ps(ra));
1267 return ra;
1268}
1269
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001270/* generate a random 11-bit RA (packet-switched only) */
1271private function f_rnd_ra11_ps() return BIT11 {
1272 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1273 return int2bit(ra11, 11);
1274}
1275
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1277testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001278 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001279 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001280 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001281
Harald Welte8c24c2b2018-02-26 08:31:31 +01001282 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001283 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001284 for (var integer i := 0; i < 1000; i := i+1) {
1285 var OCT1 ra := f_rnd_ra_cs();
1286 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1287 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001289 }
1290 fn_last := fn;
1291
1292 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001293 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001295 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001296 T.stop;
1297 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001298 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001300 }
1301 [] RSL_CCHAN.receive { repeat; }
1302 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001303 test_failed := true;
1304 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001305 }
1306 }
1307 }
Maxba06feb2019-03-05 10:52:46 +01001308 if (test_failed) {
1309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001310 }
Maxba06feb2019-03-05 10:52:46 +01001311 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001313}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001314
1315/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1316testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001317 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001318 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001319 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001320 f_l1_tune(L1CTL);
1321
1322 var GsmFrameNumber fn_last := 0;
1323 for (var integer i := 0; i < 1000; i := i+1) {
1324 var OCT1 ra := f_rnd_ra_cs();
1325 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1326 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001328 }
1329 fn_last := fn;
1330 }
1331 var integer rsl_chrqd := 0;
1332 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001333 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001334 alt {
1335 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1336 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001337 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001338 repeat;
1339 }
1340 [] RSL_CCHAN.receive { repeat; }
1341 [] T.timeout { }
1342 }
1343 if (rsl_chrqd == 1000) {
1344 setverdict(pass);
1345 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001347 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001349}
1350
Harald Welte3453ab42019-05-24 21:19:58 +02001351private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1352 var charstring bts_str := "bts " & int2str(bts_nr);
1353 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1354}
1355
1356/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1357private template integer tr_rach_slots_per_interval := (90 .. 130);
1358
1359/* Expect 0 RACH load on an idle BTS that has just started up */
1360testcase TC_rach_load_idle_thresh0() runs on test_CT {
1361 var ASP_RSL_Unitdata rx_ud;
1362
1363 f_init_vty_bsc();
1364 /* send load indications even at 0% load */
1365 f_vty_load_ind_thresh(0);
1366 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1367 f_sleep(2.0);
1368
1369 f_init();
1370
1371 timer T := 5.0;
1372 T.start;
1373 alt {
1374 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1375 setverdict(pass);
1376 repeat;
1377 }
1378 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1379 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1380 repeat;
1381 }
1382 [] RSL_CCHAN.receive {
1383 repeat;
1384 }
1385 [] T.timeout { }
1386 }
1387
1388 f_vty_load_ind_thresh(10);
1389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1390}
1391
1392/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1393testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1394 var ASP_RSL_Unitdata rx_ud;
1395
1396 f_init_vty_bsc();
1397 f_init();
1398
1399 timer T := 5.0;
1400 T.start;
1401 alt {
1402 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1403 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1404 repeat;
1405 }
1406 [] RSL_CCHAN.receive {
1407 repeat;
1408 }
1409 [] T.timeout {
1410 setverdict(pass);
1411 }
1412 }
1413
1414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1415}
1416
1417/* Expect 0 RACH load on an idle BTS that has just started up */
1418testcase TC_rach_load_count() runs on test_CT {
1419 var ASP_RSL_Unitdata rx_ud;
1420 var integer load_access_count := 0;
1421
1422 f_init_vty_bsc();
1423 /* send load indications even at 0% load */
1424 f_vty_load_ind_thresh(0);
1425 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1426 f_sleep(2.0);
1427 f_init();
1428
1429 f_init_l1ctl();
1430 f_sleep(1.0);
1431 f_l1_tune(L1CTL);
1432
1433 var GsmFrameNumber fn_last := 0;
1434 for (var integer i := 0; i < 1000; i := i+1) {
1435 var OCT1 ra := f_rnd_ra_cs();
1436 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1437 if (fn == fn_last) {
1438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1439 }
1440 fn_last := fn;
1441 }
1442
1443 timer T := 5.0;
1444 T.start;
1445 alt {
1446 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1447 -> value rx_ud {
1448 var RSL_IE_Body ie;
1449 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1450 load_access_count := load_access_count + ie.rach_load.access_count;
1451 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1452 setverdict(fail, "Access count cannot be < Busy count");
1453 }
1454 repeat;
1455 }
1456 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1457 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1458 repeat;
1459 }
1460 [] RSL_CCHAN.receive {
1461 repeat;
1462 }
1463 [] T.timeout { }
1464 }
1465 if (load_access_count == 1000) {
1466 setverdict(pass);
1467 } else {
1468 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1469 }
1470
1471 f_vty_load_ind_thresh(10);
1472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1473}
1474
Harald Welte54a2a2d2018-02-26 09:14:05 +01001475private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001476 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001477 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001478 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001479 f_sleep(0.5);
1480
1481 /* Transmit RACH request + wait for confirmation */
1482 var OCT1 ra := f_rnd_ra_cs();
1483 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1484
1485 /* Check for expected result */
1486 timer T := 1.5;
1487 T.start;
1488 alt {
1489 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1490 setverdict(pass);
1491 }
1492 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001494 }
1495 [] RSL_CCHAN.receive { repeat; }
1496 [not expect_pass] T.timeout {
1497 setverdict(pass);
1498 }
1499 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001501 }
1502 }
1503}
1504
1505/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1506testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001507 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001508 f_init_l1ctl();
1509 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001510 f_sleep(1.0);
1511
1512 /* default max-ta is 63 (full range of GSM timing advance */
1513
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001514 /* We allow early arrival up to 2 symbols */
1515 f_rach_toffs(-1*256, true);
1516 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001517 f_rach_toffs(-10*256, false);
1518
1519 /* 0 / 32 / 63 bits is legal / permitted */
1520 f_rach_toffs(0, true);
1521 f_rach_toffs(32*256, true);
1522 f_rach_toffs(63*256, true);
1523
1524 /* more than 63 bits is not legal / permitted */
1525 f_rach_toffs(64*256, false);
1526 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001528}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001529
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001530function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1531 var GsmFrameNumber fn;
1532 var RSL_Message rm;
1533
1534 f_l1_tune(L1CTL);
1535 RSL.clear;
1536
1537 /* Generate a random Handover Reference */
1538 var integer ho_ref := oct2int(f_rnd_octstring(1));
1539
1540 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1541 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1542 RSL_IE_Body:{ handover_ref := ho_ref }));
1543
1544 /* Activate a channel on the BTS side (no encryption) */
1545 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1546 act_type := t_RSL_IE_ActType_HO_SYNC);
1547
1548 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1549 * waiting for Immediate Assignment and sending Access Burst */
1550 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1551
1552 /* Send handover Access Burst */
1553 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1554
1555 /* TODO: test mismatching Handover Reference, and missing IE */
1556
1557 /* Wait for handover detection */
1558 timer T := 3.0;
1559 T.start;
1560 alt {
1561 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1562 log("Handover RACH has been detected: ", rm);
1563 setverdict(pass);
1564 }
1565 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1567 log2str("RSL_CHAN_RQD was not expected: ", rm));
1568 }
1569 [] RSL.receive { repeat; }
1570 [] T.timeout {
1571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1572 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1573 }
1574 }
1575
1576 /* Release the channel */
1577 f_rsl_chan_deact();
1578 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1579}
1580
1581/* Test handover RACH detection */
1582testcase TC_ho_rach() runs on test_CT {
1583 var ConnHdlrPars pars;
1584 var ConnHdlr vc_conn;
1585
1586 f_init();
1587
1588 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1589 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1590 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1591 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1592 vc_conn.done;
1593 }
1594
1595 /* TODO: do the above in parallel, rather than sequentially? */
1596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1597}
1598
Harald Welte93640c62018-02-25 16:59:33 +01001599/***********************************************************************
1600 * Measurement Processing / Reporting
1601 ***********************************************************************/
1602
Harald Welte70767382018-02-21 12:16:40 +01001603template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1604 spare := '0'B,
1605 lpd := 0,
1606 sapi := sapi,
1607 c_r := c_r,
1608 ea := true
1609}
1610
Harald Welted879bd92018-03-12 15:01:23 +01001611template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001612 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001613 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001614 len := 0, /* overwritten */
1615 m := false,
1616 el := 1,
1617 payload := pl
1618}
1619
1620/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1621altstep as_l1_sacch() runs on ConnHdlr {
1622 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001623 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001624 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001625 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 +01001626 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001627 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001628
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001629 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1630 g_pars.l1_pars.ms_power_level, false,
1631 g_pars.l1_pars.ms_actual_ta);
1632
1633 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1634 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1635
1636 log("Sending Measurement Report: ", l1h, l2);
1637 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001638 repeat;
1639 }
1640}
1641
1642altstep as_l1_dcch() runs on ConnHdlr {
1643 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001644 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001645 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1646 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001647 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1648 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001649 repeat;
1650 }
1651}
1652
1653type record MeasElem {
1654 uint6_t rxlev,
1655 uint3_t rxqual
1656}
1657
1658type record MeasElemFS {
1659 MeasElem full,
1660 MeasElem sub
1661}
1662
1663type record ConnL1Pars {
1664 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001665 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001666 MeasElemFS meas_ul,
1667 int16_t timing_offset_256syms,
1668 uint5_t bs_power_level,
1669 uint5_t ms_power_level,
1670 uint8_t ms_actual_ta
1671}
1672
1673/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1674private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1675 return 63 + (toffs256s/256);
1676}
1677
Harald Welted5684392018-03-10 18:22:04 +01001678private function f_max(integer a, integer b) return integer {
1679 if (a > b) {
1680 return a;
1681 } else {
1682 return b;
1683 }
1684}
1685
1686private function f_min(integer a, integer b) return integer {
1687 if (a < b) {
1688 return a;
1689 } else {
1690 return b;
1691 }
1692}
1693
1694/* compute negative tolerance val-tolerance, ensure >= min */
1695private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1696 val := val - tolerance;
1697 return f_max(val, min);
1698}
1699
1700/* compute positive tolerance val+tolerance, ensure <= max */
1701private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1702 val := val + tolerance;
1703 return f_min(val, max);
1704}
1705
1706/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1707private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1708return template integer {
1709 var template integer ret;
1710 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1711 return ret;
1712}
1713
1714
Harald Welte70767382018-02-21 12:16:40 +01001715/* build a template for matching measurement results against */
1716private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1717 var ConnL1Pars l1p := g_pars.l1_pars;
1718 var template RSL_IE_UplinkMeas ul_meas := {
1719 len := 3,
1720 rfu := '0'B,
1721 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001722 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001723 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001724 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001725 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001726 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1727 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001728 supp_meas_info := omit
1729 };
Harald Welte685d5982018-02-27 20:42:05 +01001730 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001731 ul_meas.len := (3+8);
1732 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001733 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001734 toa256_min := ?,
1735 toa256_max := ?,
1736 toa256_std_dev := ?
1737 }
Harald Welte685d5982018-02-27 20:42:05 +01001738 }
Harald Welte70767382018-02-21 12:16:40 +01001739 var template RSL_IE_BS_Power bs_power := {
1740 reserved := 0,
1741 epc := false,
1742 fpc := false,
1743 power_level := l1p.bs_power_level
1744 };
1745 var template RSL_IE_L1Info l1_info := {
1746 ms_power_lvl := l1p.ms_power_level,
1747 fpc := false,
1748 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001749 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001750 };
1751 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001752 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001753 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1754 ?, t_toffs);
1755}
1756
Philipp Maierdd841d32019-12-17 14:44:54 +01001757/* build a template for matching measurement results that do not contain any
1758 * MS related measurement (l1_info, l3_info and ms timing offset). */
1759private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1760 var ConnL1Pars l1p := g_pars.l1_pars;
1761 var template RSL_IE_UplinkMeas ul_meas := {
1762 len := 3,
1763 rfu := '0'B,
1764 dtx_d := l1p.dtx_enabled,
1765 rxlev_f_u := ?,
1766 reserved1 := '00'B,
1767 rxlev_s_u := ?,
1768 reserved2 := '00'B,
1769 rxq_f_u := ?,
1770 rxq_s_u := ?,
1771 supp_meas_info := omit
1772 };
1773 if (l1p.toa256_enabled) {
1774 ul_meas.len := (3+8);
1775 ul_meas.supp_meas_info := {
1776 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1777 toa256_min := ?,
1778 toa256_max := ?,
1779 toa256_std_dev := ?
1780 }
1781 }
1782 var template RSL_IE_BS_Power bs_power := {
1783 reserved := 0,
1784 epc := false,
1785 fpc := false,
1786 power_level := l1p.bs_power_level
1787 };
1788
1789 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1790}
1791
Harald Welte70767382018-02-21 12:16:40 +01001792/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001793altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001794 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001795 var boolean chan_est := false;
1796
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001797 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001798
1799 /* Receive osmocom specific measurement reports. This is the normal
1800 * case. Here we verify that the measurement reports we sent are
1801 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001802 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1803 /* increment counter of next to-be-expected meas rep */
1804 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1805 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001806 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001807
1808 /* The following two cases may only happen in the beginning
1809 * of the channel establishment phase. Once we have received
1810 * the "our" measurement report the first time, the channel
1811 * is established and empty or hardcoded TRXCON reports must
1812 * not occur anymore. */
1813 chan_est := true;
1814
1815 repeat;
1816 }
1817
1818 /* When the BTS has established the channel, the MS might need slightly
1819 * more time to establish the channel and actually start sending. The
1820 * result is then a measurement report that just lacks the measurement
1821 * information of the MS. This is normal and we tolerate this behavior. */
1822 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1823 /* increment counter of next to-be-expected meas rep */
1824 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1825 /* Re-start the timer expecting the next MEAS RES */
1826 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001827 repeat;
1828 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001829
1830 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1831 * measurements if the TTCN3 side does not supply measurement input in
1832 * time. In those cases TRXCON will either use a cached measurement
1833 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1834 * report the templates above will not match. We tolerate this
1835 * behavior, but only once. */
1836 [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 +01001837 /* increment counter of next to-be-expected meas rep */
1838 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1839 if (g_first_meas_res) {
1840 g_first_meas_res := false;
1841 repeat;
1842 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001844 }
Harald Welte70767382018-02-21 12:16:40 +01001845 }
1846 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001848 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001849 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001851 }
1852}
1853
Harald Weltee613f962018-04-18 22:38:16 +02001854private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1855 select (rsl_alg_id) {
1856 case (RSL_ALG_ID_A5_0) { return 0; }
1857 case (RSL_ALG_ID_A5_1) { return 1; }
1858 case (RSL_ALG_ID_A5_2) { return 2; }
1859 case (RSL_ALG_ID_A5_3) { return 3; }
1860 case (RSL_ALG_ID_A5_4) { return 4; }
1861 case (RSL_ALG_ID_A5_5) { return 5; }
1862 case (RSL_ALG_ID_A5_6) { return 6; }
1863 case (RSL_ALG_ID_A5_7) { return 7; }
1864 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1866 /* Make compiler happy by calling mtc.stop here. It is already
1867 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001868 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001869 }
1870 }
1871}
1872
1873private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1874 select (rsl_alg_id) {
1875 case (RSL_ALG_ID_A5_1) { return '000'B; }
1876 case (RSL_ALG_ID_A5_2) { return '001'B; }
1877 case (RSL_ALG_ID_A5_3) { return '010'B; }
1878 case (RSL_ALG_ID_A5_4) { return '011'B; }
1879 case (RSL_ALG_ID_A5_5) { return '100'B; }
1880 case (RSL_ALG_ID_A5_6) { return '101'B; }
1881 case (RSL_ALG_ID_A5_7) { return '110'B; }
1882 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1884 /* Make compiler happy by calling mtc.stop here. It is already
1885 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001886 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001887 }
1888 }
1889}
1890
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001891/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1892private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1893 var GsmFrameNumber fn;
1894 timer T := 8.0;
1895
1896 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1897 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1898
1899 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1900 /* Send the actual RACH */
1901 fn := f_L1CTL_RACH(L1CTL, ra);
1902
1903 T.start;
1904 alt {
1905 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1906 [] T.timeout {
1907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1908 }
1909 }
1910 T.stop
1911 return fn;
1912}
Harald Weltee613f962018-04-18 22:38:16 +02001913
Harald Welte70767382018-02-21 12:16:40 +01001914/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001915private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001916 var GsmFrameNumber fn;
1917 var ImmediateAssignment imm_ass;
1918 var integer ra := 23;
1919
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001920 /* Send RACH request and wait for ChanReq */
1921 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001922
1923 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001924 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001925
1926 /* Send IMM.ASS via CCHAN */
1927 var ChannelDescription ch_desc := {
1928 chan_nr := g_pars.chan_nr,
1929 tsc := 7,
1930 h := false,
1931 arfcn := mp_trx0_arfcn,
1932 maio_hsn := omit
1933 };
1934 var MobileAllocation ma := {
1935 len := 0,
1936 ma := ''B
1937 };
1938 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1939 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1940
1941 /* receive IMM.ASS on MS side */
1942 var ImmediateAssignment ia_um;
1943 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1944 /* enable dedicated mode */
1945 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001946 /* enable encryption, if requested */
1947 if (encr_enable) {
1948 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1949 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1950 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001951
1952 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001953}
1954
1955/* establish DChan, verify existance + contents of measurement reports */
1956function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001957 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001958 RSL.clear;
1959
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001960 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001961 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001962 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001963 }
Harald Welte70767382018-02-21 12:16:40 +01001964
1965 f_est_dchan();
1966
1967 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1968 * RSL measurement reports on Abis side */
1969 timer T := 8.0;
1970 T.start;
1971 alt {
1972 [] as_l1_sacch();
1973 [] as_meas_res();
1974 [] as_l1_dcch();
1975 [] L1CTL.receive { repeat; }
1976 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001977 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001978 * of any earlier errors, so if we reach this timeout, we're good */
1979 setverdict(pass);
1980 }
1981 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001983 }
1984 }
1985 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001986 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001987}
Harald Welte0472ab42018-03-12 15:02:26 +01001988
Eric Wildae8f2622019-06-18 17:05:11 +02001989function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
1990 timer T := 8.0;
1991 T.start;
1992 var RSL_Message rsl;
1993 alt {
1994 [] as_l1_sacch();
1995 [] L1CTL.receive { repeat; }
1996 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
1997 if (rsl.ies[3].body.bs_power.power_level == level) {
1998 setverdict(pass)
1999 } else {
2000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2001 }
2002 }
2003 [] T.timeout {
2004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2005 }
2006 }
2007}
2008
2009/* see if the rsl meas res contains our expeced bs power level
2010bs power set during assignment */
2011function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2012 f_l1_tune(L1CTL);
2013 RSL.clear;
2014
2015 if (mp_bts_trxc_port != -1) {
2016 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2017 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2018 }
2019
2020 var uint5_t pwr_var := 1;
2021 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2022 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2023
2024 f_est_dchan(more_ies :={valueof(pwr)});
2025
2026 f_check_meas_bs_power_level(pwr_var);
2027
2028 f_rsl_chan_deact();
2029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2030}
2031
2032/* see if the rsl meas res contains our expeced bs power level
2033bs power set after assignment */
2034function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2035 f_l1_tune(L1CTL);
2036 RSL.clear;
2037
2038 if (mp_bts_trxc_port != -1) {
2039 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2040 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2041 }
2042
2043 var uint5_t pwr_var := 1;
2044 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2045
2046 f_est_dchan();
2047
2048 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2049
2050 f_check_meas_bs_power_level(pwr_var);
2051
2052 f_rsl_chan_deact();
2053 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2054}
2055
2056testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2057 var ConnHdlr vc_conn;
2058 var ConnHdlrPars pars;
2059 f_init();
2060 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2061 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2062 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2063 pcu_comp := false, trxc_comp := true);
2064 vc_conn.done;
2065 }
2066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2067}
2068
2069testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2070 var ConnHdlr vc_conn;
2071 var ConnHdlrPars pars;
2072 f_init();
2073 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2074 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2075 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2076 pcu_comp := false, trxc_comp := true);
2077 vc_conn.done;
2078 }
2079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2080}
2081
Eric Wild61edb7e2019-06-03 12:38:31 +02002082/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2083second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2084These power levels are valid for all bands and require no special handling */
2085function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2086 var uint5_t pwr_var := 7;
2087 var L1ctlDlMessage l1_dl;
2088
2089 f_trxc_fake_rssi(rxlev2dbm(10));
2090 f_l1_tune(L1CTL);
2091 RSL.clear;
2092
2093 var RSL_IE_List addl_ies;
2094 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2095
2096 addl_ies := {
2097 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2098 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2099 };
2100
2101 /* establish with power parameters */
2102 f_est_dchan(more_ies := addl_ies);
2103
2104 /* set a high value to ensure L1 power control level increases */
2105 f_trxc_fake_rssi(rxlev2dbm(20));
2106
2107 timer T2 := 6.0;
2108 T2.start;
2109 alt {
2110 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002111 /* Update sent MS power to follow what BTS requests */
2112 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2113 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002114 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002115 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002116 T2.stop;
2117 }
2118 [] L1CTL.receive { repeat; }
2119 [] T2.timeout {
2120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2121 "Power Level in L1 header has not increased sufficiently");
2122 }
2123 }
2124
2125 /* set a low value to ensure L1 power control level decreases */
2126 f_trxc_fake_rssi(rxlev2dbm(0));
2127
2128 timer T4 := 6.0;
2129 T4.start;
2130 alt {
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002132 /* Update sent MS power to follow what BTS requests */
2133 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2134 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002135 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002136 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002137 T4.stop;
2138 setverdict(pass, "Power level in L1 decreased/increased as expected");
2139 }
2140 [] L1CTL.receive { repeat; }
2141 [] T4.timeout {
2142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2143 "Power Level in L1 header has not decreased sufficiently");
2144 }
2145 }
2146
2147 f_rsl_chan_deact();
2148 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2149
2150}
2151
2152/* check that we do not exceed the max power */
2153function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2154 var uint5_t pwr_var := 7;
2155 var L1ctlDlMessage l1_dl;
2156
2157 /* set a low value to ensure power increases */
2158 f_trxc_fake_rssi(rxlev2dbm(10));
2159 f_l1_tune(L1CTL);
2160 RSL.clear;
2161
2162 var RSL_IE_List addl_ies;
2163 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2164
2165 addl_ies := {
2166 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2167 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2168 };
2169
2170 /* establish with power parameters */
2171 f_est_dchan(more_ies := addl_ies);
2172
2173 timer T1 := 10.0;
2174 T1.start;
2175 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002176 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2177 /* Update sent MS power to follow what BTS requests */
2178 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2179 repeat;
2180 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002181 [] L1CTL.receive { repeat; }
2182 [] T1.timeout {
2183 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2184 setverdict(fail, "Power level in L1 header should not have changed");
2185 }
2186 }
2187 }
2188
2189 f_rsl_chan_deact();
2190 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2191
2192}
2193
2194/* see if we reach the band max power */
2195function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2196 var L1ctlDlMessage l1_dl;
2197 var uint5_t pwr_var := 15;
2198 var uint5_t pwr_max_var := f_get_max_power_from_band();
2199
2200 /* set a low value to ensure power increases */
2201 f_trxc_fake_rssi(rxlev2dbm(10));
2202 f_l1_tune(L1CTL);
2203 RSL.clear;
2204
2205 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2206 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2207
2208 /* establish with fixed power level */
2209 f_est_dchan(more_ies :={valueof(pwr)});
2210
2211 /* check our initial power level */
2212 f_wait_for_l1_power_level(pwr_var);
2213
2214 /* update power param to enable power loop
2215 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2216 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2217
2218 /* wait, then check that our power level was reduced */
2219 timer T1 := 10.0;
2220 T1.start;
2221 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002222 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2223 /* Update sent MS power to follow what BTS requests */
2224 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2225 repeat;
2226 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002227 [] L1CTL.receive { repeat; }
2228 [] T1.timeout {
2229 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2230 if( f_power_level_is_highest_dbm(rcv) ){
2231 setverdict(pass, "Power level in L1 header reduced as expected");
2232 } else {
2233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2234 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2235 }
2236 }
2237 }
2238
2239 f_rsl_chan_deact();
2240 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2241
2242}
2243
2244/* see if we reach the band min power */
2245function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2246 var L1ctlDlMessage l1_dl;
2247
2248 /* set a high value to ensure power decreases */
2249 f_trxc_fake_rssi(rxlev2dbm(50));
2250 f_l1_tune(L1CTL);
2251 RSL.clear;
2252
2253 var uint5_t pwr_var := 5;
2254 var uint5_t pwr_target_val := 15;
2255
2256 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2257 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2258
2259 /* establish with fixed power level */
2260 f_est_dchan(more_ies :={valueof(pwr)});
2261
2262 /* check our initial power level */
2263 f_wait_for_l1_power_level(pwr_var);
2264
2265 /* update power param to enable power loop
2266 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002267 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002268
2269 /* wait, then check that our power level was increased */
2270 timer T1 := 10.0;
2271 T1.start;
2272 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002273 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2274 /* Update sent MS power to follow what BTS requests */
2275 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2276 repeat;
2277 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002278 [] L1CTL.receive { repeat; }
2279 [] T1.timeout {
2280 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2281 setverdict(pass, "Power level in L1 header increased to lowest power value");
2282 } else {
2283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2284 "Power level in L1 header NOT increased to lowest power value");
2285 }
2286 }
2287 }
2288
2289 f_rsl_chan_deact();
2290 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2291
2292}
2293
Eric Wild095024b2019-06-17 15:08:57 +02002294/* see if we change the power level without receiving power parameters, which should not happen
2295rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002296function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2297 var L1ctlDlMessage l1_dl;
2298
2299 /* set a high value to ensure power decreases */
2300 f_trxc_fake_rssi(rxlev2dbm(50));
2301 f_l1_tune(L1CTL);
2302 RSL.clear;
2303
2304 var uint5_t pwr_var := 5;
2305
2306 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2307 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2308
2309 /* establish with fixed power level */
2310 f_est_dchan(more_ies :={valueof(pwr)});
2311
2312 /* check our initial power level */
2313 f_wait_for_l1_power_level(pwr_var);
2314
2315 /* wait, then check that our power level did not change */
2316 timer T1 := 10.0;
2317 T1.start;
2318 alt {
2319 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2320 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2322 "BS power control should not be active unless we receive a power parameters IE!");
2323 }
2324 repeat;
2325 }
2326 [] L1CTL.receive { repeat; }
2327 [] T1.timeout { setverdict(pass); }
2328 }
2329
2330 f_rsl_chan_deact();
2331 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2332
2333}
2334
Eric Wild095024b2019-06-17 15:08:57 +02002335/* see if we change the power level without receiving power parameters, which should not happen
2336ms power control WITHOUT power parameters */
2337function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2338 var L1ctlDlMessage l1_dl;
2339
2340 /* set a high value to ensure power decreases */
2341 f_trxc_fake_rssi(rxlev2dbm(50));
2342 f_l1_tune(L1CTL);
2343 RSL.clear;
2344
2345 var uint5_t pwr_var := 5;
2346
2347 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2348 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2349
2350 /* establish with fixed power level */
2351 f_est_dchan(more_ies :={valueof(pwr)});
2352
2353 /* check our initial power level */
2354 f_wait_for_l1_power_level(pwr_var);
2355
2356 /* pwr control without power params IE, should NOT activate MS power control*/
2357 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2358
2359 /* wait, then check that our power level did not change */
2360 timer T1 := 10.0;
2361 T1.start;
2362 alt {
2363 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2364 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2366 "BS power control should not be active unless we receive a power parameters IE!");
2367 }
2368 repeat;
2369 }
2370 [] L1CTL.receive { repeat; }
2371 [] T1.timeout { setverdict(pass); }
2372 }
2373
2374 f_rsl_chan_deact();
2375 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2376
2377}
2378
Eric Wild61edb7e2019-06-03 12:38:31 +02002379function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2380 var L1ctlDlMessage l1_dl;
2381 timer T0 := 10.0;
2382 T0.start;
2383 alt {
2384 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2385 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2387 "Power level in L1 header != signaled (RSL) power level.");
2388 }
2389 }
2390 [] L1CTL.receive { repeat; }
2391 [] T0.timeout {
2392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2393 "Timeout waiting for initial power level");
2394 }
2395 }
2396 T0.stop;
2397}
2398
2399private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2400 var IntegerRecord min_dbm_level;
2401 var IntegerRecord max_dbm_level;
2402 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2403
2404 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2405 if (min_dbm_level[i] == level) {
2406 return true;
2407 }
2408 }
2409 return false;
2410}
2411
2412private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2413 var IntegerRecord min_dbm_level;
2414 var IntegerRecord max_dbm_level;
2415 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2416
2417 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2418 if (max_dbm_level[i] == level) {
2419 return true;
2420 }
2421 }
2422 return false;
2423}
2424
2425private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2426 var IntegerRecord min_dbm_level;
2427 var IntegerRecord max_dbm_level;
2428 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2429 return max_dbm_level[0];
2430}
2431
2432type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2433template charstring BtsBand_allGSM:= pattern "GSM???";
2434private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2435 // 45.005 4.1.1
2436 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2437 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2438 2, 1, 0};
2439 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2440 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2441 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2442 var IntegerRecord rv;
2443
2444 select(band){
2445 case (BtsBand_allGSM){
2446 rv := gsm_power;
2447 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2448 max_dbm_level := {2, 1, 0};
2449 }
2450 case("DCS1800"){
2451 rv := dcs_power;
2452 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2453 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2454 }
2455 case("PCS1900"){
2456 rv := pcs_power;
2457 min_dbm_level := {15};
2458 max_dbm_level := {30};
2459 }
2460 }
2461
2462 return rv;
2463}
2464
2465private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2466 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2467}
2468
2469testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2470 var ConnHdlr vc_conn;
2471 var ConnHdlrPars pars;
2472 f_init();
2473 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2474 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2475 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2476 pars.bts0_band := f_vty_get_bts0_band();
2477 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2478 vc_conn.done;
2479 }
2480 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2482}
2483
2484testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2485 var ConnHdlr vc_conn;
2486 var ConnHdlrPars pars;
2487 f_init();
2488 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2489 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2490 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2491 pars.bts0_band := f_vty_get_bts0_band();
2492 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2493 vc_conn.done;
2494 }
2495 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2497}
2498
2499testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2500 var ConnHdlr vc_conn;
2501 var ConnHdlrPars pars;
2502 f_init();
2503 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2504 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2505 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2506 pars.bts0_band := f_vty_get_bts0_band();
2507 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2508 vc_conn.done;
2509 }
2510 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2512}
2513
2514testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2515 var ConnHdlr vc_conn;
2516 var ConnHdlrPars pars;
2517 f_init();
2518 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2519 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2520 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2521 pars.bts0_band := f_vty_get_bts0_band();
2522 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2523 vc_conn.done;
2524 }
2525 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2527}
2528
Eric Wild280ccb82019-06-17 11:11:52 +02002529testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2530 var ConnHdlr vc_conn;
2531 var ConnHdlrPars pars;
2532 f_init();
2533 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2534 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2535 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2536 pars.bts0_band := f_vty_get_bts0_band();
2537 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2538 vc_conn.done;
2539 }
2540 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2542}
2543
Eric Wild095024b2019-06-17 15:08:57 +02002544testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2545 var ConnHdlr vc_conn;
2546 var ConnHdlrPars pars;
2547 f_init();
2548 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2549 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2550 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2551 pars.bts0_band := f_vty_get_bts0_band();
2552 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2553 vc_conn.done;
2554 }
2555 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2557}
2558
Harald Welte70767382018-02-21 12:16:40 +01002559testcase TC_meas_res_sign_tchf() runs on test_CT {
2560 var ConnHdlr vc_conn;
2561 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002562 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002563 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2564 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002565 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2566 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002567 vc_conn.done;
2568 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002570}
2571testcase TC_meas_res_sign_tchh() runs on test_CT {
2572 var ConnHdlr vc_conn;
2573 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002574 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002575 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2576 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002577 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2578 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002579 vc_conn.done;
2580 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002582}
2583testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2584 var ConnHdlr vc_conn;
2585 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002586 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002587 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2588 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002589 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2590 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002591 vc_conn.done;
2592 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002594}
2595testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2596 var ConnHdlr vc_conn;
2597 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002598 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002599 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2600 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002601 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2602 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002603 vc_conn.done;
2604 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002606}
Harald Welte685d5982018-02-27 20:42:05 +01002607testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2608 var ConnHdlr vc_conn;
2609 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002610 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002611 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2612 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2613 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2614 pars.l1_pars.toa256_enabled := true;
2615 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2616 vc_conn.done;
2617 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002619}
2620
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002621/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2622 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2623function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2624 var L1ctlDlMessage l1_dl;
2625 var RSL_IE_MS_Power ms_power;
2626 var RSL_Message rsl;
2627 var uint5_t power_level := 0;
2628
2629 f_l1_tune(L1CTL);
2630 RSL.clear;
2631
2632 f_est_dchan();
2633
2634 ms_power.reserved := 0;
2635 ms_power.fpc_epc := false;
2636
2637 /* Send the first power control command. This will disable any BTS/TRX
2638 * internal power control and switch the MS (which is not in scope of
2639 * this test) to a constant power level. We start with a power level
2640 * of 0 */
2641 ms_power.power_level := power_level;
2642 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2643 RSL.send(rsl);
2644
2645 alt {
2646
2647 /* Pick all SACCH blocks for checking */
2648 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2649
2650 /* The first byte of the L1 header contains the power level.
2651 * The reserved bits and the fpc bit is set to 0, so we may
2652 * compare directly. */
2653 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2654 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2655 }
2656
2657 /* Signal a new power level via RSL for the next turn. */
2658 if (power_level < 31) {
2659 power_level := power_level + 1;
2660 ms_power.power_level := power_level;
2661 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2662 RSL.send(rsl);
2663 repeat;
2664 }
2665
2666 }
2667
2668 /* Ignore all other blocks */
2669 [] L1CTL.receive { repeat; }
2670
2671 }
2672
2673 f_rsl_chan_deact();
2674 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2675
2676 setverdict(pass);
2677}
2678
2679testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2680 var ConnHdlr vc_conn;
2681 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002682 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002683
2684 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2685 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2686 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2687 vc_conn.done;
2688 }
2689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2690}
Harald Welte70767382018-02-21 12:16:40 +01002691
Eric Wild6833cc92019-05-23 19:34:44 +02002692/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2693TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2694function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2695 var L1ctlDlMessage l1_dl;
2696 var uint5_t ta_to_test := 16;
2697
2698
2699 f_l1_tune(L1CTL);
2700 RSL.clear;
2701
2702 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002703 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002704
2705 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2706
2707
2708 alt {
2709
2710 /* Pick all SACCH blocks for checking */
2711 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2712
2713 /* The second byte of the L1 header contains the TA. */
2714 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2715 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2716 }
2717
2718 }
2719
2720 /* Ignore all other blocks */
2721 [] L1CTL.receive { repeat; }
2722
2723 }
2724
2725 f_rsl_chan_deact();
2726 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2727
2728 setverdict(pass);
2729}
2730
2731testcase TC_rsl_chan_initial_ta() runs on test_CT {
2732 var ConnHdlr vc_conn;
2733 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002734 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002735 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002736 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2737 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002738 vc_conn.done;
2739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2740}
2741
Eric Wilde57e1a62019-05-28 13:30:55 +02002742/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2743function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2744 var L1ctlDlMessage l1_dl;
2745 var uint5_t ms_power_level := 7;
2746
2747 var RSL_IE_MS_Power ms_power;
2748 ms_power.reserved := 0;
2749 ms_power.fpc_epc := false;
2750 ms_power.power_level := ms_power_level;
2751
2752 f_l1_tune(L1CTL);
2753 RSL.clear;
2754
2755 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2756
2757 timer T := 1.0;
2758 T.start;
2759 alt {
2760 /* Pick all SACCH blocks for checking */
2761 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2762 /* The first byte of the L1 header contains the power level.. */
2763 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2764 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2765 }
2766 }
2767 /* Ignore all other blocks */
2768 [] L1CTL.receive { repeat; }
2769 [] T.timeout {
2770 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2771 }
2772 }
2773
2774 f_rsl_chan_deact();
2775 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2776 setverdict(pass);
2777}
2778
2779testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2780 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2781 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2782}
2783
Harald Welte0472ab42018-03-12 15:02:26 +01002784/* 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 +01002785private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002786 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002787 RSL.clear;
2788
2789 f_est_dchan();
2790 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002791 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002792
2793 timer T := 40.0;
2794 T.start;
2795 alt {
2796 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2797 setverdict(pass)
2798 }
2799 [] RSL.receive { repeat };
2800 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002802 }
2803 }
2804 f_rsl_chan_deact();
2805}
2806testcase TC_conn_fail_crit() runs on test_CT {
2807 var ConnHdlr vc_conn;
2808 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002809 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002810 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2811 pars.t_guard := 60.0;
2812 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2813 vc_conn.done;
2814}
2815
Harald Welte93640c62018-02-25 16:59:33 +01002816/***********************************************************************
2817 * Paging
2818 ***********************************************************************/
2819
Harald Welte68e495b2018-02-25 00:05:57 +01002820function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2821 if (tmsi == 'FFFFFFFF'O) {
2822 return true;
2823 } else {
2824 return false;
2825 }
2826}
Harald Welte70767382018-02-21 12:16:40 +01002827
Philipp Maier82cb0b12018-08-31 14:41:39 +02002828type record allowedFn { integer frame_nr }
2829template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2830template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2831template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2832template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2833template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2834template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2835template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2836template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2837function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2838{
2839 var integer frame_nr_51;
2840 frame_nr_51 := frame_nr mod 51
2841
2842 var allowedFn fn_check;
2843 fn_check.frame_nr := frame_nr_51;
2844
2845 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002847 return;
2848 }
2849
2850 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2851 return;
2852 }
2853 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2854 return;
2855 }
2856 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2857 return;
2858 }
2859 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2860 return;
2861 }
2862 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2863 return;
2864 }
2865 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2866 return;
2867 }
2868 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2869 return;
2870 }
2871 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2872 return;
2873 }
2874
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002876 return;
2877}
2878
2879altstep 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 +01002880runs on test_CT {
2881 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002882 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002883 repeat;
2884 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002885 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002886 var octetstring without_plen :=
2887 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2888 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002889
2890 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2891
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07002892 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
2893 /* Ignore empty RR Paging Request (PCH filling) messages.
2894 * TODO: does it make sense to count them? */
2895 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002896 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2897 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002898 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002899 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2900 }
2901 } else if (match(rr, tr_PAGING_REQ2)) {
2902 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2903 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2904 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2905 }
2906 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2907 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2908 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07002909 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002910 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2911 }
2912 } else if (match(rr, tr_PAGING_REQ3)) {
2913 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2914 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2915 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2916 }
2917 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2918 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2919 }
2920 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2921 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2922 }
2923 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2924 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2925 }
2926 }
2927 repeat;
2928 }
2929}
2930
2931type record PagingTestCfg {
2932 boolean combined_ccch,
2933 integer bs_ag_blks_res,
2934 float load_factor,
2935 boolean exp_load_ind,
2936 boolean exp_overload,
2937 boolean use_tmsi
2938}
2939
2940type record PagingTestState {
2941 integer num_paging_sent,
2942 integer num_paging_rcv_msgs,
2943 integer num_paging_rcv_ids,
2944 integer num_overload
2945}
2946
2947/* receive + ignore RSL RF RES IND */
2948altstep as_rsl_res_ind() runs on test_CT {
2949 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2950 repeat;
2951 }
2952}
2953
2954/* Helper function for paging related testing */
2955private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002956 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002957 f_init_l1ctl();
2958 f_l1_tune(L1CTL);
2959
2960 var PagingTestState st := {
2961 num_paging_sent := 0,
2962 num_paging_rcv_msgs := 0,
2963 num_paging_rcv_ids := 0,
2964 num_overload := 0
2965 };
2966
2967 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2968 var float max_pch_imsi_per_sec;
2969 if (cfg.use_tmsi) {
2970 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2971 } else {
2972 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2973 }
2974 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2975 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002976 var float time_total := 20.0;
2977 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2978 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002979
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002980 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2981 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002982
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002983 timer T_itv := 0.0;
2984 T_itv.start;
2985 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002986 alt {
2987 /* check for presence of CCCH LOAD IND (paging load) */
2988 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2989 st.num_overload := st.num_overload + 1;
2990 repeat;
2991 }
2992 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002994 }
2995 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2996 log("Rx LOAD_IND");
2997 /* FIXME: analyze/verify interval + contents */
2998 repeat;
2999 }
3000 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003001 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003002 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003003 [] T_itv.timeout {
3004 /* Send paging cmds based on elapsed time */
3005 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3006 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003007 var MobileIdentityV mi;
3008
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003009 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003010 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003011 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003012 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003013 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003014 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003015
3016 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003017 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 +02003018
3019 st.num_paging_sent := st.num_paging_sent + 1;
3020 }
3021 if (st.num_paging_sent < pkt_total) {
3022 /* Wait for interval to next PAGING COMMAND */
3023 var float time_now := T_total.read;
3024 var float next_sched := int2float(st.num_paging_sent)*interval;
3025 if (next_sched > time_now) {
3026 T_itv.start(next_sched - time_now);
3027 } else {
3028 T_itv.start(0.0);
3029 }
3030 } else {
3031 /* We are done, no need to keep counting */
3032 T_total.stop;
3033 }
3034 }
3035 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003036 [] as_rsl_res_ind();
3037 }
3038 }
3039
3040 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3041 timer T_wait := 18.0;
3042 T_wait.start;
3043 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003044 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003045 [] L1CTL.receive { repeat; }
3046 /* 65535 == empty paging queue, we can terminate*/
3047 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3048 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
3049 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003051 }
3052 [] as_rsl_res_ind();
3053 }
3054
3055 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3056 " rcvd_ids=", st.num_paging_rcv_ids);
3057 return st;
3058}
3059
3060/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3061 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3062 * - that CCCH LOAD IND (PCH) are being generated
3063 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3064testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003065 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003066 var PagingTestCfg cfg := {
3067 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003068 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003069 load_factor := 0.8,
3070 exp_load_ind := true,
3071 exp_overload := false,
3072 use_tmsi := false
3073 };
3074 var PagingTestState st := f_TC_paging(cfg);
3075 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3077 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003078 } else {
3079 setverdict(pass);
3080 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003082}
3083
3084/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3085 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3086 * - that CCCH LOAD IND (PCH) are being generated
3087 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3088testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003089 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003090 var PagingTestCfg cfg := {
3091 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003092 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003093 load_factor := 0.8,
3094 exp_load_ind := true,
3095 exp_overload := false,
3096 use_tmsi := true
3097 };
3098 var PagingTestState st := f_TC_paging(cfg);
3099 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3101 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003102 } else {
3103 setverdict(pass);
3104 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003106}
3107
3108/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3109 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3110 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3111 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3112testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003113 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003114 var PagingTestCfg cfg := {
3115 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003116 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003117 load_factor := 2.0,
3118 exp_load_ind := true,
3119 exp_overload := true,
3120 use_tmsi := false
3121 };
3122 var PagingTestState st := f_TC_paging(cfg);
3123 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3124 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003125 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003126 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003128 } else {
3129 setverdict(pass);
3130 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003132}
3133
3134/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3135 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3136 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3137 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3138testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003139 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003140 var PagingTestCfg cfg := {
3141 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003142 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003143 load_factor := 2.0,
3144 exp_load_ind := true,
3145 exp_overload := true,
3146 use_tmsi := true
3147 };
3148 var PagingTestState st := f_TC_paging(cfg);
3149 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3150 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003151 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003152 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003153 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 +01003154 } else {
3155 setverdict(pass);
3156 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003158}
3159
3160
Harald Welte93640c62018-02-25 16:59:33 +01003161/***********************************************************************
3162 * Immediate Assignment / AGCH
3163 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02003164const MobileAllocation c_MA_null := {
3165 len := 0,
3166 ma := ''B
3167}
Harald Welte93640c62018-02-25 16:59:33 +01003168
Harald Weltee8d750e2018-06-10 21:41:35 +02003169template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3170 uint12_t arfcn := 871) := {
3171 chan_nr := chan_nr,
3172 tsc := tsc,
3173 h := false,
3174 arfcn := arfcn,
3175 maio_hsn := omit
3176}
3177
3178private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3179 return int2str(num_tx) & " sent, "
3180 & int2str(num_rx) & " received, "
3181 & int2str(num_del) & " deleted";
3182}
3183
3184private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3185 var L1ctlDlMessage l1_dl;
3186 timer T := 10.0;
3187 var integer num_tx := 0;
3188 var integer num_rx := 0;
3189 var integer num_del := 0;
3190 var charstring res_str;
3191 var float rx_ratio;
3192
Harald Welte10474062019-05-30 16:48:17 +02003193 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003194 f_init_l1ctl();
3195 f_l1_tune(L1CTL);
3196
3197 for (var integer i := 0; i < num_total; i := i+1) {
3198 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
3199 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3200 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01003201 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003202 num_tx := num_tx+1;
3203 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003204 }
3205 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003206 T.start;
3207 alt {
3208 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
3209 num_del := num_del+1;
3210 repeat;
3211 }
3212 [] RSL_CCHAN.receive {
3213 repeat;
3214 }
3215 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3216 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3217 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3218 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3219 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003220 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003221 } else {
3222 num_rx := num_rx+1;
3223 }
3224 repeat;
3225 }
3226 [] L1CTL.receive { repeat; }
3227 [] T.timeout { }
3228 }
3229 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3230 log("AGCH test: " & res_str);
3231 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003233 }
3234 rx_ratio := int2float(num_rx) / int2float(num_tx);
3235 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003236 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 +02003237 } else {
3238 setverdict(pass);
3239 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003241}
3242
Harald Weltee8d750e2018-06-10 21:41:35 +02003243/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3244testcase TC_imm_ass_1000_20ms() runs on test_CT {
3245 f_TC_imm_ass(1000, 0.02, 0.25);
3246}
3247
3248/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3249testcase TC_imm_ass_200_0ms() runs on test_CT {
3250 f_TC_imm_ass(200, 0.0, 0.05);
3251}
3252
3253/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3254testcase TC_imm_ass_200_76ms() runs on test_CT {
3255 f_TC_imm_ass(150, 0.076, 1.00);
3256}
3257
3258
3259
Harald Welte48494ca2018-02-25 16:59:50 +01003260/***********************************************************************
3261 * BCCH
3262 ***********************************************************************/
3263
3264/* tuple of Frame Number + decoded SI */
3265type record SystemInformationFn {
3266 GsmFrameNumber frame_number,
3267 SystemInformation si
3268}
3269
3270/* an arbitrary-length vector of decoded SI + gsmtap header */
3271type record of SystemInformationFn SystemInformationVector;
3272
3273/* an array of SI-vectors indexed by TC value */
3274type SystemInformationVector SystemInformationVectorPerTc[8];
3275
3276/* determine if a given SI vector contains given SI type at least once */
3277function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3278 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3279 var integer fn_mod51 := arr[i].frame_number mod 51;
3280 if (not bcch_ext and fn_mod51 == 2 or
3281 bcch_ext and fn_mod51 == 6) {
3282 if (arr[i].si.header.message_type == key) {
3283 return true;
3284 }
3285 }
3286 }
3287 return false;
3288}
3289
3290/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3291function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3292 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003294 }
3295}
3296
3297/* check if a given SI vector contains given SI type at least once on any TC */
3298function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3299 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3300 if (f_si_vecslot_contains(arr[tc], key) or
3301 f_si_vecslot_contains(arr[tc], key, true)) {
3302 return true;
3303 }
3304 }
3305 return false;
3306}
3307
3308/* determine if a given SI vector contains given SI type at least N of M times */
3309function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3310 var integer count := 0;
3311 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003313 }
3314 for (var integer i:= 0; i < m; i := i + 1) {
3315 var integer fn_mod51 := arr[i].frame_number mod 51;
3316 if (not bcch_ext and fn_mod51 == 2 or
3317 bcch_ext and fn_mod51 == 6) {
3318 if (arr[i].si.header.message_type == key) {
3319 count := count + 1;
3320 }
3321 }
3322 }
3323 if (count >= n) {
3324 return true;
3325 } else {
3326 return false;
3327 }
3328}
3329
3330/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3331function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3332 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003334 }
3335}
3336
3337/* determine if a given SI vector contains given SI type at least once */
3338function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3339 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3340 var integer fn_mod51 := arr[i].frame_number mod 51;
3341 if (not bcch_ext and fn_mod51 == 2 or
3342 bcch_ext and fn_mod51 == 6) {
3343 if (arr[i].si.header.message_type != key) {
3344 return false;
3345 }
3346 }
3347 }
3348 return true;
3349}
3350
3351/* ensure a given TC slot of the SI vector contains only given SI type */
3352function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3353 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003355 }
3356}
3357
3358/* SI configuration of cell, against which we validate actual SI messages */
3359type set SystemInformationConfig {
3360 boolean bcch_extended,
3361 boolean si1_present,
3362 boolean si2bis_present,
3363 boolean si2ter_present,
3364 boolean si2quater_present,
3365 boolean si7_present,
3366 boolean si8_present,
3367 boolean si9_present,
3368 boolean si13_present,
3369 boolean si13alt_present,
3370 boolean si15_present,
3371 boolean si16_present,
3372 boolean si17_present,
3373 boolean si2n_present,
3374 boolean si21_present,
3375 boolean si22_present
3376}
3377
3378/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3379function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3380 var integer i;
3381 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3382 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003384 }
3385 }
3386 if (cfg.si1_present) {
3387 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3388 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3389 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3390 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3391 /* make sure *ALL* contain SI1 */
3392 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3393 }
3394 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3395 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3396 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3397 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3398 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3399 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3400
3401 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3402 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3403 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3404 * consecutive occurrences of TC = 4. */
3405 if (cfg.si2bis_present and not cfg.si2ter_present) {
3406 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3407 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3408 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3409 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3410 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3411 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3412 }
3413
3414 if (cfg.si7_present or cfg.si8_present) {
3415 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3416 * if System Information type 4 does not contain all information needed for cell
3417 * selection and reselection. */
3418 if (not cfg.bcch_extended) {
3419 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3420 }
3421 if (cfg.si7_present) {
3422 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3423 }
3424 if (cfg.si8_present) {
3425 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3426 }
3427 }
3428
3429 if (cfg.si2quater_present) {
3430 /* iii) System information type 2 quater is sent if needed, as determined by the system
3431 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3432 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3433 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3434 * within any of 4 consecutive occurrences of TC = 5. */
3435 if (not (cfg.bcch_extended)) {
3436 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3437 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3438 } else {
3439 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3440 }
3441 } else {
3442 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3443 }
3444 }
3445 if (cfg.si9_present) {
3446 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3447 * in system information type 3 as defined in 3GPP TS 44.018. */
3448 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3449 }
3450 if (cfg.si13_present) {
3451 /* vii) System Information type 13 is only related to the GPRS service. System Information
3452 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3453 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3454 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3455 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3456 * within any of 4 consecutive occurrences of TC=4. */
3457 if (not cfg.bcch_extended) {
3458 log("not-bccch-extended");
3459 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3460 } else {
3461 log("bccch-extended");
3462 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3463 }
3464 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003466 }
3467 }
3468 if (cfg.si16_present or cfg.si17_present) {
3469 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3470 * should not be sent in a cell where network sharing is used (see rule xv). */
3471 if (cfg.si22_present) {
3472 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3473 }
3474 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003476 }
3477 if (not cfg.bcch_extended) {
3478 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3479 }
3480 if (cfg.si16_present) {
3481 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3482 }
3483 if (cfg.si17_present) {
3484 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3485 }
3486 }
3487
3488 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3489 * broadcast information. The frequency with which they are sent is determined by the
3490 * system operator. System Information type 9 identifies the scheduling of System
3491 * Information type 18 and 20 messages. */
3492
3493 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3494 * Information Type 19 is present, then its scheduling shall be indicated in System
3495 * Information Type 9. */
3496
3497 if (cfg.si15_present) {
3498 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3499 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3500 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3501 * 4 consecutive occurrences of TC = 1. */
3502 if (not cfg.bcch_extended) {
3503 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3504 } else {
3505 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3506 }
3507 }
3508 if (cfg.si13alt_present) {
3509 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3510 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3511 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3512 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3513 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3514 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3515 * of TC = 4. */
3516 if (cfg.si13_present) {
3517 testcase.stop("Error: Cannot have SI13alt and SI13");
3518 }
3519 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003521 }
3522 if (not cfg.bcch_extended) {
3523 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3524 } else {
3525 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3526 }
3527 }
3528 if (cfg.si2n_present) {
3529 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3530 * as determined by the system operator. In the case that the message is sent on the
3531 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3532 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3533 * consecutive occurrences of TC = 4. */
3534 if (not cfg.bcch_extended) {
3535 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3536 } else {
3537 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3538 }
3539 }
3540 if (cfg.si21_present) {
3541 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3542 * determined by the system operator. If Extended Access Barring is in use in the cell
3543 * then this message is sent at least once within any of 4 consecutive occurrences of
3544 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3545 * cell then this message shall only be sent on BCCH Ext. */
3546 if (not cfg.bcch_extended) {
3547 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3548 } else {
3549 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3550 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003552 }
3553 }
3554 }
3555 if (cfg.si22_present) {
3556 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3557 * should not be sent in a cell where SoLSA is used (see rule viii). System
3558 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3559 * =2 and TC=6. */
3560 if (cfg.si16_present or cfg.si17_present) {
3561 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3562 }
3563 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3564 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003566 }
3567 if (not cfg.bcch_extended) {
3568 testcase.stop("Error: SI22 requires BCCH Extd!");
3569 } else {
3570 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3571 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3572 }
3573 }
3574}
3575
3576/* sample Systme Information for specified duration via L1CTL */
3577function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3578 timer T := duration;
3579 var SystemInformationVectorPerTc si_per_tc;
3580 var L1ctlDlMessage l1_dl;
3581
3582 /* initialize all per-TC vectors empty */
3583 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3584 si_per_tc[i] := {};
3585 }
3586
3587 /* flush all previous L1 queued msgs */
3588 pt.clear;
3589
3590 T.start;
3591 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003592 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003593 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3594 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3595 log("Ignoring non-RR SI ", l1_dl);
3596 repeat;
3597 }
3598 var SystemInformationFn sig := {
3599 frame_number := l1_dl.dl_info.frame_nr,
3600 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3601 }
3602 var integer tc := f_gsm_compute_tc(sig.frame_number);
3603 log("SI received at TC=", tc, ": ", sig.si);
3604 /* append to the per-TC bucket */
3605 si_per_tc[tc] := si_per_tc[tc] & { sig };
3606 repeat;
3607 }
3608 [] pt.receive { repeat; }
3609 [] T.timeout { }
3610 }
3611
3612 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3613 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3614 }
3615 log("si_per_tc=", si_per_tc);
3616 return si_per_tc;
3617}
3618
3619/* helper function: Set given SI via RSL + validate scheduling.
3620 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3621function f_TC_si_sched() runs on test_CT {
3622 var SystemInformationVectorPerTc si_per_tc;
3623 f_init_l1ctl();
3624 f_l1_tune(L1CTL);
3625
3626 /* Sample + Validate Scheduling */
3627 si_per_tc := f_l1_sample_si(L1CTL);
3628 f_validate_si_scheduling(si_cfg, si_per_tc);
3629
3630 setverdict(pass);
3631}
3632
3633testcase TC_si_sched_default() runs on test_CT {
3634 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003635 /* 2+3+4 are mandatory and set in f_init() */
3636 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003638}
3639
3640testcase TC_si_sched_1() runs on test_CT {
3641 f_init();
3642 si_cfg.si1_present := true;
3643 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003644 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003646}
3647
3648testcase TC_si_sched_2bis() runs on test_CT {
3649 f_init();
3650 si_cfg.si2bis_present := true;
3651 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3652 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003654}
3655
3656testcase TC_si_sched_2ter() runs on test_CT {
3657 f_init();
3658 si_cfg.si2ter_present := true;
3659 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3660 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003662}
3663
3664testcase TC_si_sched_2ter_2bis() runs on test_CT {
3665 f_init();
3666 si_cfg.si2bis_present := true;
3667 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3668 si_cfg.si2ter_present := true;
3669 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3670 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003672}
3673
3674testcase TC_si_sched_2quater() runs on test_CT {
3675 f_init();
3676 si_cfg.si2quater_present := true;
3677 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3678 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
3682testcase TC_si_sched_13() runs on test_CT {
3683 f_init();
3684 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003685 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003686 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003688}
3689
3690testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3691 f_init();
3692 si_cfg.si2bis_present := true;
3693 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3694 si_cfg.si2ter_present := true;
3695 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3696 si_cfg.si2quater_present := true;
3697 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3698 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003699 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003700 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003702}
3703
3704
Harald Welte68e495b2018-02-25 00:05:57 +01003705testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003706 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003707 /* FIXME: enable / disable individual BCCH info */
3708 //ts_RSL_BCCH_INFO(si_type, info);
3709 /* expect no ERROR REPORT after either of them *
3710 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003712}
3713
Harald Welte93640c62018-02-25 16:59:33 +01003714/***********************************************************************
3715 * Low-Level Protocol Errors / ERROR REPORT
3716 ***********************************************************************/
3717
Harald Welte01d982c2018-02-25 01:31:40 +01003718private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3719 timer T := 5.0;
3720 T.start;
3721 alt {
3722 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3723 setverdict(pass);
3724 }
3725 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003727 }
3728 [] RSL_CCHAN.receive {
3729 repeat;
3730 }
3731 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003733 }
3734 }
3735}
3736
3737/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3738testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003739 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003740 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3741 rsl.ies := omit;
3742 RSL_CCHAN.send(ts_RSL_UD(rsl));
3743
3744 f_exp_err_rep(RSL_ERR_PROTO);
3745}
3746
3747/* Provoke a mandatory IE error and match on ERROR REPORT */
3748testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003749 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003750
3751 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3752 rsl.ies := { rsl.ies[0] };
3753 RSL_CCHAN.send(ts_RSL_UD(rsl));
3754
3755 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3756}
3757
3758/* Provoke an IE content error and match on ERROR REPORT */
3759testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003760 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003761 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3762 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3763 RSL_CCHAN.send(ts_RSL_UD(rsl));
3764
3765 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3766}
3767
Harald Welteee25aae2019-05-19 14:32:37 +02003768/* attempt to activate channel with wrong RSL Message Discriminator IE */
3769function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3770 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3771 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3772 RSL.send(rsl);
3773 f_rslem_unregister(0, g_chan_nr);
3774}
3775testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3776 var ConnHdlr vc_conn;
3777 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3778
Harald Welte10474062019-05-30 16:48:17 +02003779 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003780
3781 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3782 vc_conn.done;
3783 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3784
3785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3786}
3787
3788/* Send messages with wrong message type */
3789function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3790 var template (value) RSL_Message rsl_tx;
3791 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3792 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3793 RSL.send(rsl_tx);
3794 f_rslem_unregister(0, g_chan_nr);
3795}
3796function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3797 var template (value) RSL_Message rsl_tx;
3798 /* we first have to activate the dedicated channel */
3799 f_rsl_chan_act(g_pars.chan_mode);
3800 /* ... to then send an invalid RLL message */
3801 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3802 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3803 RSL.send(rsl_tx);
3804 f_rslem_unregister(0, g_chan_nr);
3805}
3806testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3807 var ConnHdlr vc_conn;
3808 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3809 var template (value) RSL_Message rsl_tx;
3810
Harald Welte10474062019-05-30 16:48:17 +02003811 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003812
3813 /* Common Channel with wrong message type */
3814 RSL_CCHAN.clear;
3815 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3816 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3817 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3818 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3819
3820 /* TRX Management */
3821 RSL_CCHAN.clear;
3822 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3823 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3824 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3825 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3826
3827 /* Dedicated Channel */
3828 RSL_CCHAN.clear;
3829 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3830 vc_conn.done;
3831 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3832
3833 /* RLL */
3834 RSL_CCHAN.clear;
3835 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3836 vc_conn.done;
3837 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3838}
3839
3840/* Send messages in wrong sequence (RLL to an inactive lchan) */
3841function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3842 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3843 f_rslem_unregister(0, g_chan_nr);
3844}
3845testcase TC_err_rep_wrong_sequence() runs on test_CT {
3846 var ConnHdlr vc_conn;
3847 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3848
Harald Welte10474062019-05-30 16:48:17 +02003849 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003850
3851 RSL_CCHAN.clear;
3852 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3853 vc_conn.done;
3854 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3855}
3856
Harald Welte93640c62018-02-25 16:59:33 +01003857/***********************************************************************
3858 * IPA CRCX/MDCX/DLCS media stream handling
3859 ***********************************************************************/
3860
Harald Weltea871a382018-02-25 02:03:14 +01003861/* Send IPA DLCX to inactive lchan */
3862function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003863 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3864 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003865}
3866testcase TC_ipa_dlcx_not_active() runs on test_CT {
3867 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003868 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003869 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3870 vc_conn.done;
3871}
Harald Welte68e495b2018-02-25 00:05:57 +01003872
Harald Weltea3f1df92018-02-25 12:49:55 +01003873/* Send IPA CRCX twice to inactive lchan */
3874function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3875 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3876 "IPA CRCX ACK");
3877 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3878 "IPA CRCX NACK");
3879}
3880testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3881 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003882 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003883 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3884 vc_conn.done;
3885}
3886
3887/* Regular sequence of CRCX/MDCX/DLCX */
3888function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3889 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3890 "IPA CRCX ACK");
3891 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3892 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3893 var uint7_t rtp_pt2 := f_rnd_int(127);
3894 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3895 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3896 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3897 "IPA MDCX ACK");
3898 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3899 "IPA DLCX ACK");
3900}
3901testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3902 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003903 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003904 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3905 vc_conn.done;
3906}
3907
Harald Welte3ae11da2018-02-25 13:36:06 +01003908/* Sequence of CRCX, 2x MDCX, DLCX */
3909function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3910 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3911 "IPA CRCX ACK");
3912 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3913 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3914 var uint7_t rtp_pt2 := f_rnd_int(127);
3915 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3916 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3917 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3918 "IPA MDCX ACK");
3919 /* Second MDCX */
3920 remote_ip := f_rnd_int(c_UINT32_MAX);
3921 remote_port := f_rnd_int(c_UINT16_MAX);
3922 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3923 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3924 "IPA MDCX ACK");
3925 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3926 "IPA DLCX ACK");
3927}
3928testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3929 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003930 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003931 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3932 vc_conn.done;
3933}
3934
Harald Welte9912eb52018-02-25 13:30:15 +01003935/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3936function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3937 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3938 "IPA CRCX NACK");
3939}
3940testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3941 var ConnHdlrPars pars;
3942 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003943 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003944
3945 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3946 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3947 vc_conn.done;
3948
3949 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3950 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3951 vc_conn.done;
3952}
3953
Harald Weltea3f1df92018-02-25 12:49:55 +01003954
Harald Welte883340c2018-02-28 18:59:29 +01003955/***********************************************************************
3956 * PCU Socket related tests
3957 ***********************************************************************/
3958
Harald Welte07bd2d22019-05-25 11:03:30 +02003959/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003960friend 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 +01003961runs on test_CT {
3962 timer T := 3.0;
3963
3964 /* we don't expect any RTS.req before PDCH are active */
3965 T.start;
3966 alt {
3967 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003968 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003969 }
3970 [] PCU.receive { repeat; }
3971 [] T.timeout { }
3972 }
3973
3974 /* Send PDCH activate request for known PDCH timeslot */
3975 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3976
3977 /* we now expect RTS.req for this timeslot (only) */
3978 T.start;
3979 alt {
3980 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3981 setverdict(pass);
3982 }
3983 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3984 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003986 }
3987 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003989 }
3990 [] PCU.receive { repeat; }
3991 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003993 }
3994 [not exp_success] T.timeout {
3995 setverdict(pass);
3996 }
3997 }
3998}
3999
Harald Welte07bd2d22019-05-25 11:03:30 +02004000/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004001friend 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 +01004002runs on test_CT {
4003 timer T := 3.0;
4004
4005 /* Send PDCH activate request for known PDCH timeslot */
4006 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4007
4008 PCU.clear;
4009 /* we now expect no RTS.req for this timeslot */
4010 T.start;
4011 alt {
4012 [] 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 +02004013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004014 }
4015 [] PCU.receive { repeat; }
4016 [] T.timeout {
4017 setverdict(pass);
4018 }
4019 }
4020}
4021
Harald Weltead033dc2019-05-25 17:28:16 +02004022friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004023 f_init();
4024 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4025}
4026
Harald Welte883340c2018-02-28 18:59:29 +01004027/* PDCH activation via PCU socket; check for presence of RTS.req */
4028testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004029 f_init_pcu_test();
4030
Harald Welte883340c2018-02-28 18:59:29 +01004031 f_TC_pcu_act_req(0, 0, 7, true);
4032}
4033
4034/* PDCH activation via PCU socket on non-PDCU timeslot */
4035testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004036 f_init_pcu_test();
4037
Harald Welte883340c2018-02-28 18:59:29 +01004038 f_TC_pcu_act_req(0, 0, 1, false);
4039}
4040
4041/* PDCH activation via PCU socket on wrong BTS */
4042testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004043 f_init_pcu_test();
4044
Harald Welte883340c2018-02-28 18:59:29 +01004045 f_TC_pcu_act_req(23, 0, 7, false);
4046}
4047
4048/* PDCH activation via PCU socket on wrong TRX */
4049testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004050 f_init_pcu_test();
4051
Harald Welte883340c2018-02-28 18:59:29 +01004052 f_TC_pcu_act_req(0, 23, 7, false);
4053}
4054
4055/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4056testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004057 f_init_pcu_test();
4058
Harald Welte883340c2018-02-28 18:59:29 +01004059 /* Activate PDCH */
4060 f_TC_pcu_act_req(0, 0, 7, true);
4061 f_sleep(1.0);
4062 /* and De-Activate again */
4063 f_TC_pcu_deact_req(0, 0, 7);
4064}
4065
4066/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4067testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004068 f_init_pcu_test();
4069
Harald Welte883340c2018-02-28 18:59:29 +01004070 f_TC_pcu_deact_req(0, 0, 1);
4071}
4072
4073/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4074testcase TC_pcu_ver_si13() runs on test_CT {
4075 const octetstring si13 := '00010203040506070909'O;
4076 var PCUIF_send_data sd;
4077 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004078 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004079
4080 /* Set SI13 via RSL */
4081 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004082
Harald Welte883340c2018-02-28 18:59:29 +01004083 T.start;
4084 alt {
4085 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4086 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4087 setverdict(pass);
4088 } else {
4089 repeat;
4090 }
4091 }
4092 [] PCU.receive { repeat; }
4093 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004095 }
4096 }
4097}
4098
4099private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4100
4101/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004102friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004103 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4104runs on test_CT
4105{
4106 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4107 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4108}
4109
4110/* 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 +02004111friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4112 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004113runs on test_CT
4114{
4115 var PCUIF_send_data sd;
4116
4117 timer T := 3.0;
4118 T.start;
4119 alt {
4120 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4121 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4122 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4123 sd.data.u.rts_req.fn, sapi, data);
4124 }
4125 [] PCU.receive { repeat; }
4126 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004128 }
4129 }
4130}
4131
4132/* Send DATA.req on invalid BTS */
4133testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004134 var TfiUsfArr tua := f_TfiUsfArrInit();
4135 var octetstring data := '0000'O & f_rnd_octstring(21);
4136
4137 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004138
Harald Welte883340c2018-02-28 18:59:29 +01004139 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004140 f_TfiUsfArrSet(tua, 7, 0);
4141 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4142 f_sleep(1.0);
4143
4144 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004145}
4146
4147/* Send DATA.req on invalid TRX */
4148testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004149 var TfiUsfArr tua := f_TfiUsfArrInit();
4150 var octetstring data := '0000'O & f_rnd_octstring(21);
4151
4152 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004153
Harald Welte883340c2018-02-28 18:59:29 +01004154 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004155 f_TfiUsfArrSet(tua, 7, 0);
4156 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4157 f_sleep(1.0);
4158
4159 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004160}
4161
4162/* Send DATA.req on invalid timeslot */
4163testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004164 var TfiUsfArr tua := f_TfiUsfArrInit();
4165 var octetstring data := '0000'O & f_rnd_octstring(21);
4166
4167 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004168
Harald Welte883340c2018-02-28 18:59:29 +01004169 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004170 f_TfiUsfArrSet(tua, 7, 0);
4171 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4172 f_sleep(1.0);
4173
4174 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004175}
4176
4177/* Send DATA.req on timeslot that hasn't been activated */
4178testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004179 var TfiUsfArr tua := f_TfiUsfArrInit();
4180 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004181
Harald Welte7162a612019-05-26 12:56:09 +02004182 f_virtphy_common();
4183
4184 f_TfiUsfArrSet(tua, 7, 0);
4185 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4186 f_sleep(1.0);
4187
4188 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004189}
4190
Harald Weltead033dc2019-05-25 17:28:16 +02004191private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004192 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4193 boolean wait_rts := true)
4194runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004195 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004196 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004197
4198 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004199 if (wait_rts) {
4200 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4201 } else {
4202 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4203 }
Harald Weltead033dc2019-05-25 17:28:16 +02004204
4205 T.start;
4206 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004207 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004208 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4209 setverdict(pass);
4210 }
Harald Welte7162a612019-05-26 12:56:09 +02004211 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4212 setverdict(fail, "Received unexpected ", rx_dl);
4213 }
Harald Weltead033dc2019-05-25 17:28:16 +02004214 [] L1CTL.receive {
4215 repeat;
4216 }
Harald Welte7162a612019-05-26 12:56:09 +02004217 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004218 setverdict(fail, "Timeout waiting for ", data);
4219 }
Harald Welte7162a612019-05-26 12:56:09 +02004220 [not expect_data] T.timeout {
4221 setverdict(pass);
4222 }
Harald Weltead033dc2019-05-25 17:28:16 +02004223 }
4224}
4225
4226private function f_disable_dynamic_ts() runs on test_CT
4227{
4228 f_init_vty_bsc();
4229 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4230 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4231 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4232 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004233 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004234}
4235
4236private function f_virtphy_common() runs on test_CT {
4237 f_disable_dynamic_ts();
4238 f_init_l1ctl();
4239 f_l1_tune(L1CTL);
4240}
4241
4242testcase TC_pcu_data_req_pdtch() runs on test_CT {
4243 var TfiUsfArr tua := f_TfiUsfArrInit();
4244 var octetstring data := '0000'O & f_rnd_octstring(21);
4245
4246 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004247
Harald Welte883340c2018-02-28 18:59:29 +01004248 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004249 f_TfiUsfArrSet(tua, 7, 0);
4250 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4251 f_sleep(1.0);
4252
4253 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004254}
4255
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004256/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004257testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004258 var TfiUsfArr tua := f_TfiUsfArrInit();
4259 var octetstring data := '0000'O & f_rnd_octstring(21);
4260
4261 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004262
Harald Welte883340c2018-02-28 18:59:29 +01004263 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004264 f_TfiUsfArrSet(tua, 7, 0);
4265 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4266 f_sleep(1.0);
4267
4268 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004269}
4270
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004271private function f_TC_pcu_ptcch_ul(uint16_t ra)
4272runs on test_CT {
4273 var template PCUIF_Message pcu_rach_ind;
4274 var PCUIF_send_data sd;
4275 var GsmFrameNumber fn;
4276 timer T;
4277
4278 /* Send an Access Burst on PTCCH/U over the Um-interface */
4279 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4280 chan_nr := ts_RslChanNr_PDCH(7),
4281 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4282
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004283 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4284 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004285
4286 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4287 T.start(52.0 * 4.615 / 1000.0);
4288 alt {
4289 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4290 log("Rx an Access Burst on the PCU interface: ", sd.data);
4291 setverdict(pass);
4292 T.stop;
4293 }
4294 [] PCU.receive { repeat; }
4295 [] T.timeout {
4296 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4297 /* Keep going, that's not the end of the world */
4298 }
4299 }
4300}
4301
4302testcase TC_pcu_ptcch() runs on test_CT {
4303 var L1ctlDlMessage dl;
4304 var octetstring data;
4305 timer T;
4306
4307 f_init_pcu_test();
4308 f_init_l1ctl();
4309 f_l1_tune(L1CTL);
4310
4311 /* Activate PDCH channel on TS7 */
4312 f_TC_pcu_act_req(0, 0, 7, true);
4313
4314 /* Tune trxcon to that PDCH channel */
4315 L1CTL.send(ts_L1CTL_DM_EST_REQ(arfcn := { false, mp_trx0_arfcn },
4316 chan_nr := valueof(ts_RslChanNr_PDCH(7)),
4317 tsc := 7));
4318
4319 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4320 for (var integer i := 0; i < 16; i := i + 1) {
4321 log("Sending an Access Burst towards the L1CTL interface");
4322 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4323 }
4324
4325 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4326 data := f_rnd_octstring(23);
4327
4328 /* Verify PTCCH/D: send a random data block, make sure it's received */
4329 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4330 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4331
4332 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4333 * let's give it more time in case if we miss the beginning. */
4334 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4335 alt {
4336 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4337 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4338 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4339 frame := data)) -> value dl {
4340 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4341 setverdict(pass);
4342 T.stop;
4343 }
4344 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4345 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4346 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4347 l2_data := data)) -> value dl {
4348 log("Rx PTCCH/D data block on L1CTL: ", dl);
4349 setverdict(pass);
4350 T.stop;
4351 }
4352 [] L1CTL.receive { repeat; }
4353 [] T.timeout {
4354 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4355 }
4356 }
4357}
4358
Harald Welte883340c2018-02-28 18:59:29 +01004359/* Send AGCH from PCU; check it appears on Um side */
4360testcase TC_pcu_data_req_agch() runs on test_CT {
4361 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004362 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004363 f_init_l1ctl();
4364 f_l1_tune(L1CTL);
4365
4366 f_TC_pcu_act_req(0, 0, 7, true);
4367 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4368
4369 T.start;
4370 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004371 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004372 setverdict(pass);
4373 }
4374 [] L1CTL.receive { repeat; }
4375 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004377 }
4378 }
4379}
4380
Harald Welte928622b2019-05-26 13:22:59 +02004381/* Send AGCH from PCU; check it appears on Um side */
4382testcase TC_pcu_data_req_pch() runs on test_CT {
4383 timer T := 3.0;
4384 f_init_pcu_test();
4385 f_init_l1ctl();
4386 f_l1_tune(L1CTL);
4387
4388 f_TC_pcu_act_req(0, 0, 7, true);
4389 /* three characters prefix: last 3 digits of IMSI as ASCII */
4390 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4391
4392 T.start;
4393 alt {
4394 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4395 setverdict(pass);
4396 }
4397 [] L1CTL.receive { repeat; }
4398 [] T.timeout {
4399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4400 }
4401 }
4402}
4403
Harald Welte883340c2018-02-28 18:59:29 +01004404/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4405testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4406 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004407 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004408 f_init_l1ctl();
4409 f_l1_tune(L1CTL);
4410
4411 /* append 3 last imsi digits so BTS can compute pagng group */
4412 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4413
4414 timer T := 0.5;
4415 T.start;
4416 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004417 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004418 /* TODO: verify paging group */
4419 setverdict(pass);
4420 }
4421 [] L1CTL.receive { repeat; }
4422 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004424 }
4425 }
4426}
4427
4428/* Send RACH from Um side, expect it to show up on PCU socket */
4429testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004430 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004431 f_init_l1ctl();
4432 f_l1_tune(L1CTL);
4433
4434 var GsmFrameNumber fn_last := 0;
4435 for (var integer i := 0; i < 1000; i := i+1) {
4436 var OCT1 ra := f_rnd_ra_ps();
4437 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4438 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004440 }
4441 fn_last := fn;
4442
4443 timer T := 2.0;
4444 T.start;
4445 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004446 [] 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 +01004447 T.stop;
4448 }
4449 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004451 }
4452 [] PCU.receive { repeat; }
4453 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004455 }
4456 }
4457 }
4458 setverdict(pass);
4459}
4460
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004461/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4462 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4463testcase TC_pcu_ext_rach_content() runs on test_CT {
4464 var template PCUIF_Message pcu_rach_ind;
4465 var GsmFrameNumber fn_last := 0;
4466 var L1ctlRachSynchSeq synch_seq;
4467 var PCUIF_BurstType pcu_bt;
4468 var GsmFrameNumber fn;
4469 var BIT11 ra11;
4470
4471 f_init_pcu_test();
4472 f_init_l1ctl();
4473 f_l1_tune(L1CTL);
4474
4475 for (var integer i := 0; i < 1000; i := i+1) {
4476 /* We need to test both TS1 & TS2 */
4477 if (i rem 2 == 0) {
4478 synch_seq := RACH_SYNCH_SEQ_TS1;
4479 pcu_bt := BURST_TYPE_1;
4480 } else {
4481 synch_seq := RACH_SYNCH_SEQ_TS2;
4482 pcu_bt := BURST_TYPE_2;
4483 }
4484
4485 ra11 := f_rnd_ra11_ps();
4486 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4487 if (fn == fn_last) {
4488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4489 "Two RACH in same FN?!?");
4490 }
4491 fn_last := fn;
4492
4493 /* Compose the expected message */
4494 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004495 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004496 ra := bit2int(ra11),
4497 is_11bit := 1,
4498 burst_type := pcu_bt,
4499 fn := fn);
4500
4501 timer T := 2.0;
4502 T.start;
4503 alt {
4504 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4505 T.stop;
4506 }
4507 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4509 }
4510 [] PCU.receive { repeat; }
4511 [] T.timeout {
4512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4513 }
4514 }
4515 }
4516 setverdict(pass);
4517}
4518
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004519private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4520runs on test_CT {
4521 var template PCUIF_send_data sdt;
4522 var PCUIF_send_data sd;
4523 var int16_t lqual_cb;
4524 timer T := 1.0;
4525
4526 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4527 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4528
4529 /* Send a random PDTCH frame over Um */
4530 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4531 '0000'O & f_rnd_octstring(21)));
4532
4533 T.start;
4534 alt {
4535 /* If expected link quality is above the threshold */
4536 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4537 lqual_cb := sd.data.u.data_ind.lqual_cb;
4538 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4539
4540 /* Make sure the actual link quality matches the expected value */
4541 if (not match(lqual_cb, lqual_cb_exp)) {
4542 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4543 "expected value ", lqual_cb_exp));
4544 } else {
4545 setverdict(pass);
4546 }
4547 }
4548 /* If expected link quality is below the threshold */
4549 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4551 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4552 }
4553 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4554 [] PCU.receive { repeat; }
4555 [lqual_cb_exp < thresh] T.timeout {
4556 log("Rx nothing, as expected");
4557 setverdict(pass);
4558 }
4559 [lqual_cb_exp >= thresh] T.timeout {
4560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4561 "Timeout waiting for PCUIF_DATA.ind");
4562 }
4563 }
4564}
4565
4566/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4567testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4568 f_init_pcu_test();
4569 PCU.clear;
4570
4571 f_init_l1ctl();
4572 f_l1_tune(L1CTL);
4573
4574 /* Activate a PDCH channel on TS7 */
4575 f_TC_pcu_act_req(0, 0, 7, true);
4576
4577 /* Tune trxcon to that PDCH channel on TS7 */
4578 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn },
4579 valueof(ts_RslChanNr_PDCH(7)), 7);
4580
4581 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4582 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4583 var TrxcMessage ret;
4584
4585 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4586 valueof(ts_TRXC_FAKE_CI(i)));
4587
4588 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4589 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4590 }
4591}
4592
Harald Welte883340c2018-02-28 18:59:29 +01004593/* Send PAGING via RSL, expect it to shw up on PCU socket */
4594testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004595 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004596
4597 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004598 var MobileIdentityLV mi_lv;
4599 var octetstring mi_lv_enc;
4600 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004601 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004602
Harald Welte883340c2018-02-28 18:59:29 +01004603 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004604 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004605 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004606 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004607 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004608
4609 /* Fancy encoding for PCUIF */
4610 mi_lv := valueof(ts_MI_LV(mi));
4611 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4612 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004613
4614 /* Send RSL PAGING COMMAND */
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004615 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004616 T.start;
4617 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004618 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004619 }
4620 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004622 }
4623 [] PCU.receive { repeat; }
4624 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004626 }
4627 }
4628 }
4629 setverdict(pass);
4630}
4631
Harald Welted66c9b82019-05-25 09:03:15 +02004632/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4633testcase TC_pcu_time_ind() runs on test_CT {
4634 var PCUIF_send_data pcu_sd;
4635 var integer num_time_ind := 0;
4636 var integer first_fn, last_fn;
4637 var float test_duration := 5.0;
4638 timer T;
4639
4640 f_init_pcu_test();
4641 f_TC_pcu_act_req(0, 0, 7, true);
4642
4643 PCU.clear;
4644 T.start(test_duration);
4645 alt {
4646 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4647 num_time_ind := num_time_ind + 1;
4648 if (not isbound(first_fn)) {
4649 first_fn := pcu_sd.data.u.time_ind.fn;
4650 }
4651 last_fn := pcu_sd.data.u.time_ind.fn;
4652 repeat;
4653 }
4654 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4655 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4656 repeat;
4657 }
4658 [] PCU.receive {
4659 repeat;
4660 }
4661 [] T.timeout {}
4662 }
4663 var integer fn_expired := last_fn - first_fn;
4664 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4665
4666 /* verify the number of frames expired matches our expectation */
4667 const float c_GSM_FN_DURATION_MS := 4.61538;
4668 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004669 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004670 if (not match(fn_expired, t_fn_expected)) {
4671 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4672 }
4673
4674 /* There are three TIME.ind in every fn MOD 13 */
4675 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4676 /* Add some tolerance */
4677 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4678 if (not match(num_time_ind, t_time_ind_exp)) {
4679 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4680 }
4681
4682 setverdict(pass);
4683}
4684
Harald Welte4832c862019-05-25 14:57:18 +02004685/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4686testcase TC_pcu_rts_req() runs on test_CT {
4687 var PCUIF_send_data pcu_sd;
4688 var integer first_fn, last_fn;
4689 var integer num_rts_pdtch := 0;
4690 var integer num_rts_ptcch := 0;
4691 var float test_duration := 5.0;
4692 timer T;
4693
4694 f_init_pcu_test();
4695 f_TC_pcu_act_req(0, 0, 7, true);
4696
4697 PCU.clear;
4698 T.start(test_duration);
4699 alt {
4700 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4701 -> value pcu_sd {
4702 num_rts_pdtch := num_rts_pdtch + 1;
4703 if (not isbound(first_fn)) {
4704 first_fn := pcu_sd.data.u.rts_req.fn;
4705 }
4706 last_fn := pcu_sd.data.u.rts_req.fn;
4707 repeat;
4708 }
4709 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4710 -> value pcu_sd {
4711 num_rts_ptcch := num_rts_ptcch + 1;
4712 if (not isbound(first_fn)) {
4713 first_fn := pcu_sd.data.u.rts_req.fn;
4714 }
4715 last_fn := pcu_sd.data.u.rts_req.fn;
4716 repeat;
4717 }
4718 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4719 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4720 repeat;
4721 }
4722 [] PCU.receive {
4723 repeat;
4724 }
4725 [] T.timeout {}
4726 }
4727 var integer fn_expired := last_fn - first_fn;
4728 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4729 ", num_rts_ptcch=", num_rts_ptcch);
4730
4731 /* verify the number of frames expired matches our expectation */
4732 const float c_GSM_FN_DURATION_MS := 4.61538;
4733 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004734 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004735 if (not match(fn_expired, t_fn_expected)) {
4736 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4737 }
4738
4739 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4740 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4741 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4742 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4743 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4744 t_ptcch_exp);
4745 }
4746
4747 /* We have 12 PDTCH blocks every 52-multiframe */
4748 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4749 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4750 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4751 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4752 t_pdtch_exp);
4753 }
4754
4755 setverdict(pass);
4756}
4757
Harald Welte07bd2d22019-05-25 11:03:30 +02004758/* test for generating Abis side OML ALERT from the PCU */
4759testcase TC_pcu_oml_alert() runs on test_CT {
4760 var PCUIF_send_data pcu_sd;
4761 var integer num_time_ind := 0;
4762 var integer first_fn, last_fn;
4763 var float test_duration := 5.0;
4764 timer T;
4765
4766 f_init_pcu_test();
4767 f_TC_pcu_act_req(0, 0, 7, true);
4768
4769 /* re-connect CTRL port from BTS to BSC */
4770 f_ipa_ctrl_stop();
4771 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4772
4773 /* Send that OML Alert */
4774 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4775
4776 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4777 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4778 setverdict(pass);
4779}
4780
Harald Welteeaa9a862019-05-26 23:01:08 +02004781template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4782 template (value) RoutingAreaIdentificationV rai,
4783 template (value) OCT1 cause) := {
4784 discriminator := '0000'B, /* overwritten */
4785 tiOrSkip := {
4786 skipIndicator := '0000'B
4787 },
4788 msgs := {
4789 rrm := {
4790 gPRS_suspensionRequest := {
4791 messageType := '00110100'B,
4792 tLLI := tlli,
4793 routingAreaIdentification := rai,
4794 suspensionCause := cause,
4795 service_Support := omit
4796 }
4797 }
4798 }
4799}
4800
4801/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4802private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4803 var PCUIF_Message first_info;
4804 var integer pcu_conn_id := -1;
4805 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4806 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4807 var OCT4 tlli := '01020304'O;
4808 var OCT1 cause := '23'O;
4809 timer T := 5.0;
4810
4811 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4812
4813 f_l1_tune(L1CTL);
4814 RSL.clear;
4815
4816 f_est_dchan();
4817 L1CTL.clear;
4818
4819 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4820
4821 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4822 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4823 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4824
4825 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4826 T.start;
4827 alt {
4828 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4829 setverdict(pass);
4830 }
4831 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4832 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4833 }
4834 [] PCU.receive {
4835 repeat;
4836 }
4837 [] T.timeout {
4838 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4839 }
4840 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004841
4842 /* release the channel */
4843 f_rsl_chan_deact();
4844 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4845 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004846}
4847testcase TC_pcu_rr_suspend() runs on test_CT {
4848 var ConnHdlrPars pars;
4849 var ConnHdlr vc_conn;
4850
4851 f_init();
4852
4853 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4854 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4855 vc_conn.done;
4856}
Harald Welte07bd2d22019-05-25 11:03:30 +02004857
Harald Weltea2e0e942019-05-27 18:12:53 +02004858/* Ensure that PCUIF socket can accept only a single connection */
4859testcase TC_pcu_socket_connect_multi() runs on test_CT {
4860 timer T := 5.0;
4861
4862 /* this (among other things) establishes the first connection to the PCUIF socket */
4863 f_init();
4864
4865 /* try to establish a second connection, expect it to fail */
4866 PCU.send(UD_connect:{mp_pcu_socket, -1});
4867 T.start;
4868 alt {
4869 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4870 setverdict(pass);
4871 }
4872 [] PCU.receive(UD_connect_result:?) {
4873 setverdict(fail, "Unexpected unix domain connect result");
4874 }
4875 [] T.timeout {
4876 setverdict(pass);
4877 }
4878 }
4879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4880}
4881
Harald Weltec8effb72019-05-27 18:23:04 +02004882/* Ensure that PCUIF socket can disconnect + reconnect */
4883testcase TC_pcu_socket_reconnect() runs on test_CT {
4884 /* this (among other things) establishes the first connection to the PCUIF socket */
4885 f_init();
4886
4887 f_sleep(1.0);
4888
4889 f_pcuif_close(PCU, g_pcu_conn_id);
4890 g_pcu_conn_id := -1;
4891
4892 f_sleep(1.0);
4893
4894 /* re-connect */
4895 PCU.clear;
4896 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4897 setverdict(pass);
4898
4899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4900}
4901
Harald Weltebe030482019-05-27 22:29:35 +02004902/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4903private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4904 var L1ctlDlMessage l1_dl;
4905 var SystemInformation si;
4906 timer T := 5.0;
4907 T.start;
4908 alt {
4909 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4910 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4911 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4912 log("Ignoring non-RR SI ", l1_dl);
4913 repeat;
4914 }
4915 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4916 if (not ischosen(si.payload.si3)) {
4917 repeat;
4918 }
4919 }
4920 [] pt.receive {
4921 repeat;
4922 }
4923 [] T.timeout {
Vadim Yanitskiy4a07c122020-05-03 23:07:56 +07004924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI3");
Harald Weltebe030482019-05-27 22:29:35 +02004925 }
4926 }
4927 return si.payload.si3;
4928}
4929
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +07004930private function f_si3_has_gprs_indicator(RestOctets ro) return boolean {
4931 var SI3RestOctets rest := dec_SI3RestOctets(ro);
4932 return rest.gprs_ind.presence == '1'B;
Harald Weltebe030482019-05-27 22:29:35 +02004933}
4934
4935testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4936 var SystemInformationType3 si3;
4937 timer T := 5.0;
4938
4939 /* don't call f_init() as this would connect PCU socket */
4940 f_init_rsl(testcasename());
4941 T.start;
4942 alt {
4943 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4944 [] T.timeout {
4945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4946 }
4947 }
4948 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4949
4950 f_init_l1ctl();
4951 f_l1_tune(L1CTL);
4952
4953 f_sleep(2.0);
4954 L1CTL.clear;
4955 si3 := f_get_si3(L1CTL);
4956 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4957 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4958 } else {
4959 setverdict(pass);
4960 }
4961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4962}
4963
4964/* Ensure that GPRS capability is advertised after PCU socket connect */
4965testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4966 var SystemInformationType3 si3;
4967
4968 /* this (among other things) establishes the first connection to the PCUIF socket */
4969 f_init();
4970 f_init_l1ctl();
4971 f_l1_tune(L1CTL);
4972
4973 f_sleep(2.0);
4974 L1CTL.clear;
4975 si3 := f_get_si3(L1CTL);
4976 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4977 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4978 } else {
4979 setverdict(pass);
4980 }
4981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4982}
4983
4984/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4985testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4986 var SystemInformationType3 si3;
4987
4988 /* this (among other things) establishes the first connection to the PCUIF socket */
4989 f_init();
4990 f_init_l1ctl();
4991 f_l1_tune(L1CTL);
4992
4993 f_pcuif_close(PCU, g_pcu_conn_id);
4994 g_pcu_conn_id := -1;
4995
4996 f_sleep(1.0);
4997
4998 /* re-connect */
4999 PCU.clear;
5000 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5001
5002 f_sleep(2.0);
5003 L1CTL.clear;
5004 si3 := f_get_si3(L1CTL);
5005 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
5006 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
5007 } else {
5008 setverdict(pass);
5009 }
5010
5011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5012}
5013
Oliver Smithf5239c72019-08-28 10:01:25 +02005014/* 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) */
5015testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5016 var SystemInformation si3 := valueof(ts_SI3_default);
5017
5018 f_init();
5019
5020 /* Verify cell_id */
5021 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5022 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5023 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005024 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5025 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5026 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005027 }
5028
5029 /* Verify LAC */
5030 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5031 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5032 if (lac_si3 != lac_pcu) {
5033 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5034 }
5035
5036 setverdict(pass);
5037}
Harald Welted66c9b82019-05-25 09:03:15 +02005038
Harald Welte3d04ae62018-04-04 20:29:05 +02005039/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005040 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005041 ***********************************************************************/
5042
5043private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5044runs on ConnHdlr {
5045 var PCUIF_send_data sd;
5046 /* Expect BTS to immediately acknowledge activation as PDCH */
5047 PCU.clear;
5048 f_rsl_chan_act(g_pars.chan_mode);
5049 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005050 timer T_wait := 2.0;
5051 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005052 alt {
5053 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5054 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 +02005055 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5056 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5057 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005058 }
5059 }
5060 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005061 [] T_wait.timeout {
5062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5063 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5064 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005065 }
5066 /* try to activate this PDCH from the PCU point of view */
5067 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5068 /* FIXME: is there a response? */
5069}
5070
5071private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5072runs on ConnHdlr {
5073 var PCUIF_send_data sd;
5074 /* Send RSL CHAN REL (deactivate) */
5075 PCU.clear;
5076 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5077 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005078 timer T_wait := 2.0;
5079 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005080 alt {
5081 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5082 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 +02005083 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5084 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5085 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005086 }
5087 }
5088 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005089 [] T_wait.timeout {
5090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5091 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5092 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005093 }
5094 /* Emulate PCU asking BTS to deactivate PDCH */
5095 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5096 alt {
5097 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5098 setverdict(pass);
5099 }
5100 [] RSL.receive { repeat; }
5101 }
5102}
5103
5104/* Activate Osmocom-style dynamic PDCH from BSC side */
5105function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5106 var PCUIF_Message first_info;
5107 var integer ts_nr := g_chan_nr.tn;
5108 var integer trx_nr := 0;
5109 var integer bts_nr := 0;
5110 var integer pcu_conn_id := -1;
5111
5112 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5113
5114 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5115 f_sleep(3.0);
5116 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5117 setverdict(pass);
5118}
5119testcase TC_dyn_osmo_pdch_act_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_act_deact), pars, true);
5126 vc_conn.done;
5127}
5128
5129/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5130function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5131 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005132 var integer pcu_conn_id := -1;
5133
5134 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5135
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005136 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5137 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5138 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005139 setverdict(pass);
5140}
5141testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5142 var ConnHdlrPars pars;
5143 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005144 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005145
5146 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5147 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5148 vc_conn.done;
5149}
5150
5151/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5152function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5153 var PCUIF_Message first_info;
5154 var integer ts_nr := g_chan_nr.tn;
5155 var integer trx_nr := 0;
5156 var integer bts_nr := 0;
5157 var integer pcu_conn_id := -1;
5158
5159 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5160
5161 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005162 /* Send a second Chan Activ and expect it to be NACKed */
5163 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5164 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005165 setverdict(pass);
5166}
5167testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5168 var ConnHdlrPars pars;
5169 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005170 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005171
5172 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5173 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5174 vc_conn.done;
5175}
5176
5177/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5178function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5179 var PCUIF_Message first_info;
5180 var integer ts_nr := g_chan_nr.tn;
5181 var integer trx_nr := 0;
5182 var integer bts_nr := 0;
5183 var integer pcu_conn_id := -1;
5184 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5185
5186 /* register for the TCH/F channel number */
5187 f_rslem_register(0, chan_nr);
5188
5189 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5190
5191 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5192 "RSL CHAN ACT");
5193 setverdict(pass);
5194}
5195testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5196 var ConnHdlrPars pars;
5197 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005198 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005199
5200 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5201 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5202 vc_conn.done;
5203}
5204
5205/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5206function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5207 var PCUIF_Message first_info;
5208 var integer ts_nr := g_chan_nr.tn;
5209 var integer trx_nr := 0;
5210 var integer bts_nr := 0;
5211 var integer pcu_conn_id := -1;
5212 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5213 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5214
5215 /* register for the TCH/H channel numbers */
5216 f_rslem_register(0, chan_nr[0]);
5217 f_rslem_register(0, chan_nr[1]);
5218
5219 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5220
5221 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5222 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5223 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5224 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5225 setverdict(pass);
5226}
5227testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5228 var ConnHdlrPars pars;
5229 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005230 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005231
5232 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5233 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5234 vc_conn.done;
5235}
5236
Harald Welte9bbbfb52018-04-05 09:33:19 +02005237/***********************************************************************
5238 * IPA Style Dynamic Timeslot Support
5239 ***********************************************************************/
5240
5241private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5242runs on ConnHdlr {
5243 var PCUIF_send_data sd;
5244 /* Expect BTS to immediately acknowledge activation as PDCH */
5245 PCU.clear;
5246 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5247 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005248 timer T_wait := 2.0;
5249 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005250 alt {
5251 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5252 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 +01005253 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5254 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5255 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005256 }
5257 }
5258 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005259 [] T_wait.timeout {
5260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5261 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5262 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005263 }
5264 /* try to activate this PDCH from the PCU point of view */
5265 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5266 /* FIXME: is there a response? */
5267
5268 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5269}
5270
5271private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5272runs on ConnHdlr {
5273 var PCUIF_send_data sd;
5274 /* Send RSL CHAN REL (deactivate) */
5275 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5276 PCU.clear;
5277 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005278 timer T_wait := 2.0;
5279 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005280 alt {
5281 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5282 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 +01005283 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5284 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5285 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005286 }
5287 }
5288 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005289 [] T_wait.timeout {
5290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5291 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5292 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005293 }
5294 /* Emulate PCU asking BTS to deactivate PDCH */
5295 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5296 alt {
5297 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5298 setverdict(pass);
5299 }
5300 [] RSL.receive { repeat; }
5301 }
5302}
5303
5304/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5305function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5306 var PCUIF_Message first_info;
5307 var integer ts_nr := g_chan_nr.tn;
5308 var integer trx_nr := 0;
5309 var integer bts_nr := 0;
5310 var integer pcu_conn_id := -1;
5311
5312 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5313
5314 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5315 f_sleep(3.0);
5316 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5317
5318 setverdict(pass);
5319
5320}
5321testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5322 var ConnHdlrPars pars;
5323 var ConnHdlr vc_conn;
5324 f_init();
5325
5326 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5327 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5328 vc_conn.done;
5329}
5330
5331/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5332function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5333 var PCUIF_Message first_info;
5334 var integer ts_nr := g_chan_nr.tn;
5335 var integer trx_nr := 0;
5336 var integer bts_nr := 0;
5337 var integer pcu_conn_id := -1;
5338
5339 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5340
5341 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5342 "RSL CHAN ACT");
5343 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5344 "RF CHAN REL", true);
5345 setverdict(pass);
5346}
5347testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5348 var ConnHdlrPars pars;
5349 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005350 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005351
5352 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5353 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5354 vc_conn.done;
5355}
5356
5357/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5358function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5359 var PCUIF_Message first_info;
5360 var integer ts_nr := g_chan_nr.tn;
5361 var integer trx_nr := 0;
5362 var integer bts_nr := 0;
5363 var integer pcu_conn_id := -1;
5364
5365 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5366
5367 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5368 "RSL CHAN ACT");
5369
5370 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5371 alt {
5372 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5373 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005375 }
5376 [] RSL.receive { repeat; }
5377 }
5378
5379 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5380 "RF CHAN REL", true);
5381 setverdict(pass);
5382}
5383testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5384 var ConnHdlrPars pars;
5385 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005386 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005387
5388 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5389 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5390 vc_conn.done;
5391}
5392
5393/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5394function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5395 var PCUIF_Message first_info;
5396 var integer ts_nr := g_chan_nr.tn;
5397 var integer trx_nr := 0;
5398 var integer bts_nr := 0;
5399 var integer pcu_conn_id := -1;
5400
5401 /* register for the TCH/F channel number */
5402 f_rslem_register(0, g_chan_nr);
5403
5404 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5405
5406 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5407
5408 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5409 "RSL CHAN ACT");
5410
5411 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5412
5413 setverdict(pass);
5414}
5415testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5416 var ConnHdlrPars pars;
5417 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005418 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005419
5420 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5421 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5422 vc_conn.done;
5423}
5424
5425
Harald Welte0472ab42018-03-12 15:02:26 +01005426/***********************************************************************
5427 * LAPDm / RLL related
5428 ***********************************************************************/
5429
5430private function f_tx_lapdm(template (value) LapdmFrame l,
5431 template (value) RslLinkId link_id) runs on ConnHdlr {
5432 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005433 var template (value) SacchL1Header l1h;
5434
5435 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005436 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005437 /* Compose dummy L1 header */
5438 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5439 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 +02005440 } else {
5441 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005442 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 +01005443 }
Harald Welte0472ab42018-03-12 15:02:26 +01005444}
5445
5446type record RllTestCase {
5447 uint3_t sapi,
5448 RslLinkId link_id,
5449 octetstring l3,
5450 boolean exp
5451}
5452type record of RllTestCase RllTestCases;
5453template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5454 sapi := sapi,
5455 link_id := id,
5456 l3 := l3,
5457 exp := exp
5458}
5459
5460/* execute the same callback function with a set of different parameters (tcs) on a
5461 * variety of logical channels */
5462private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5463 var ConnHdlrPars pars;
5464 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005465 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005466
5467 /* test on each of the channels we have */
5468 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5469 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5470
5471 /* test each of the test cases on the current channel */
5472 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5473 pars.spec.rll := tcs[j];
5474 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5475 vc_conn := f_start_handler(fn, pars);
5476 vc_conn.done;
5477 }
5478 }
5479
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005481}
5482
5483/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5484private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5485 var RllTestCase tc := g_pars.spec.rll;
5486 timer T := 3.0;
5487
5488 f_l1_tune(L1CTL);
5489 RSL.clear;
5490
5491 /* activate the logical channel */
5492 f_est_dchan();
5493 L1CTL.clear;
5494
5495 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5496 T.start;
5497 alt {
5498 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5499 if (tc.exp) {
5500 setverdict(pass);
5501 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005503 }
5504 }
5505 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5506 if (tc.exp) {
5507 setverdict(pass);
5508 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005510 }
5511 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005512 /* We also expect to receive the measurements */
5513 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005514 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005516 }
5517 [not tc.exp] T.timeout {
5518 setverdict(pass);
5519 }
5520 }
5521
5522 f_rsl_chan_deact();
5523 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5524 f_rslem_unregister(0, g_chan_nr);
5525}
5526testcase TC_rll_est_ind() runs on test_CT {
5527 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005528 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005529 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005530 /* normal SAPI0 establishment */
5531 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005532 /* SAPI 3 doesn't support contention resolution */
5533 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5534 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5535 /* normal SAPI3 establishment on main DCCH */
5536 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5537 /* normal SAPI3 establishment on SACCH */
5538 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5539 };
5540 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5541}
5542
5543/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5544private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5545 var RllTestCase tc := g_pars.spec.rll;
5546 var L1ctlDlMessage dl;
5547 timer T := 3.0;
5548
5549 f_l1_tune(L1CTL);
5550 RSL.clear;
5551
5552 /* activate the logical channel */
5553 f_est_dchan();
5554 L1CTL.clear;
5555
5556 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5557 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5558 T.start;
5559 alt {
5560 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5561 var LapdmFrame lapdm;
5562 var octetstring l2 := dl.payload.data_ind.payload;
5563 if (dl.dl_info.link_id.c == SACCH) {
5564 /* remove L1 header */
5565 l2 := substr(l2, 2, lengthof(l2)-2);
5566 }
5567 lapdm.ab := dec_LapdmFrameAB(l2);
5568 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5569 setverdict(pass);
5570 } else {
5571 repeat;
5572 }
5573 }
5574 [] L1CTL.receive { repeat; }
5575 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005576 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005577 }
5578 }
5579
5580 f_rsl_chan_deact();
5581 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5582 f_rslem_unregister(0, g_chan_nr);
5583}
5584testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5585 var RllTestCases tcs := {
5586 /* normal SAPI3 establishment on main DCCH */
5587 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5588 };
5589 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5590}
5591testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5592 var RllTestCases tcs := {
5593 /* normal SAPI3 establishment on SACCH */
5594 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5595 }
5596 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5597}
5598
5599/* altstep to receive a LAPDm frame matching the given template */
5600private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5601 var L1ctlDlMessage dl;
5602 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5603 var LapdmFrame lapdm;
5604 var octetstring l2 := dl.payload.data_ind.payload;
5605 if (dl.dl_info.link_id.c == SACCH) {
5606 /* remove L1 header */
5607 l2 := substr(l2, 2, lengthof(l2)-2);
5608 }
5609 if (ischosen(exp.ab)) {
5610 lapdm.ab := dec_LapdmFrameAB(l2);
5611 } else if (ischosen(exp.b4)) {
5612 lapdm.b4 := dec_LapdmFrameB4(l2);
5613 } else if (ischosen(exp.bbis)) {
5614 lapdm.bbis := dec_LapdmFrameBbis(l2);
5615 }
5616 log("Rx LAPDm ", lapdm);
5617 if (match(lapdm, exp)) {
5618 setverdict(pass);
5619 } else {
5620 repeat;
5621 }
5622 }
5623 [] L1CTL.receive { repeat; }
5624}
5625private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5626 timer T := t;
5627 T.start;
5628 alt {
5629 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005631 }
5632 [] as_l1_exp_lapdm(exp);
5633 }
5634}
5635
5636/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5637private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5638 /* send SABM from MS -> BTS */
5639 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5640 /* expect RLL EST IND on Abis */
5641 alt {
5642 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5643 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5644 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005646 }
5647 [] RSL.receive { repeat; }
5648 }
5649 /* expect UA from BTS -> MS */
5650 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5651}
5652
5653/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5654private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5655 var RllTestCase tc := g_pars.spec.rll;
5656
5657 f_l1_tune(L1CTL);
5658 RSL.clear;
5659
5660 /* activate the logical channel */
5661 f_est_dchan();
5662 L1CTL.clear;
5663
5664 /* first establish the link-layer */
5665 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5666
5667 /* then send the DISC */
5668 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5669 /* ... and expect the REL IND on the RSL side */
5670 alt {
5671 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5672 setverdict(pass);
5673 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005674 /* We also expect to receive the measurements */
5675 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005676 }
5677
5678 /* release the channel */
5679 f_rsl_chan_deact();
5680 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5681 f_rslem_unregister(0, g_chan_nr);
5682}
5683testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5684 var RllTestCases tcs := {
5685 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5686 };
5687 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5688}
5689
5690testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5691 var RllTestCases tcs := {
5692 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5693 };
5694 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5695}
5696testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5697 var RllTestCases tcs := {
5698 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5699 };
5700 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5701}
5702testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5703 var RllTestCases tcs := {
5704 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5705 };
5706 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5707}
5708
5709/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5710private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5711 var RllTestCase tc := g_pars.spec.rll;
5712 f_l1_tune(L1CTL);
5713 RSL.clear;
5714
5715 /* activate the logical channel */
5716 f_est_dchan();
5717 L1CTL.clear;
5718
5719 /* first establish the link-layer */
5720 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5721
5722 /* then send the REL REQ via RSL */
5723 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5724 /* ... and expect the DISC on the Um side */
5725 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005726 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005727 /* FIXME: send a UA in resposne to the DISC */
5728 }
5729 }
5730
5731 /* release the channel */
5732 f_rsl_chan_deact();
5733 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5734 f_rslem_unregister(0, g_chan_nr);
5735}
5736testcase TC_rll_rel_req() runs on test_CT {
5737 var RllTestCases tcs := {
5738 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5739 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5740 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5741 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5742 };
5743 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5744}
5745
5746/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5747testcase TC_rll_data_req() runs on test_CT {
5748}
5749
5750/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5751testcase TC_rll_data_ind() runs on test_CT {
5752}
5753
5754/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5755private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5756 var RllTestCase tc := g_pars.spec.rll;
5757
5758 f_l1_tune(L1CTL);
5759 RSL.clear;
5760
5761 f_est_dchan();
5762 L1CTL.clear;
5763
5764 /* Send UNITDATA REQ on RSL side */
5765 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5766 /* Expect it to arrive on the other side */
5767 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005768 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005769 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005770 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005771 }
5772
5773 /* release the channel */
5774 f_rsl_chan_deact();
5775 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5776 f_rslem_unregister(0, g_chan_nr);
5777}
5778testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5779 var octetstring l3 := f_rnd_octstring(15);
5780 var RllTestCases tcs := {
5781 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5782 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5783 };
5784 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5785}
5786testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5787 var octetstring l3 := f_rnd_octstring(19);
5788 var RllTestCases tcs := {
5789 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5790 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5791 };
5792 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5793}
5794
5795/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5796private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5797 var RllTestCase tc := g_pars.spec.rll;
5798
5799 f_l1_tune(L1CTL);
5800 RSL.clear;
5801
5802 f_est_dchan();
5803 L1CTL.clear;
5804
5805 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005806 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005807 /* Expdct RLL UNITDATA IND on RSL side */
5808 alt {
5809 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5810 setverdict(pass);
5811 }
5812 [] RSL.receive { repeat; }
5813 }
5814
5815 /* release the channel */
5816 f_rsl_chan_deact();
5817 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5818 f_rslem_unregister(0, g_chan_nr);
5819}
5820testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005821 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005822 var RllTestCases tcs := {
5823 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5824 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5825 };
5826 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5827}
5828testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5829 var octetstring l3 := f_rnd_octstring(18);
5830 var RllTestCases tcs := {
5831 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5832 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5833 };
5834 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5835}
5836
Harald Weltee613f962018-04-18 22:38:16 +02005837/***********************************************************************
5838 * Encryption Related
5839 ***********************************************************************/
5840
5841/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5842function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5843 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5844 if (link_id.c == SACCH) {
5845 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5846 } else {
5847 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5848 }
5849}
5850
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005851/* Expect (or not expect) other kinds of messages */
5852private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5853 [exp_any] RSL.receive { repeat; }
5854 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005856 }
5857}
5858
Harald Weltee613f962018-04-18 22:38:16 +02005859/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005860private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005861 RslLinkId link_id,
5862 octetstring l3,
5863 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005864 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005865) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005866 timer T := 3.0;
5867 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5868 T.start;
5869 /* Expect RLL UNITDATA IND on RSL side */
5870 alt {
5871 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5872 setverdict(pass);
5873 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005874 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005875 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005876 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005878 }
Harald Weltee613f962018-04-18 22:38:16 +02005879 }
5880}
5881
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005882/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5883private function f_data_mo(
5884 RslLinkId link_id,
5885 boolean p, uint3_t nr, uint3_t ns,
5886 octetstring l3,
5887 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005888 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005889) runs on ConnHdlr {
5890 timer T := 3.0;
5891 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5892 T.start;
5893 /* Expect RLL DATA IND on RSL side */
5894 alt {
5895 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5896 setverdict(pass);
5897 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005898 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005899 [] as_rsl_any_ind(exp_any);
5900 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005902 }
5903 }
5904}
5905
Harald Weltee613f962018-04-18 22:38:16 +02005906/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5907function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5908 f_l1_tune(L1CTL);
5909 f_est_dchan(true);
5910
5911 /* now we actually need to transmit some data both ways to check if the encryption works */
5912 var L1ctlDlMessage dl;
5913
Stefan Sperling603d98e2018-07-25 16:47:28 +02005914 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005915 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5916
5917 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5918 f_unitdata_mt(link_id, l3);
5919
5920 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5921 f_unitdata_mo(link_id, l3);
5922
5923 /* release the channel */
5924 f_rsl_chan_deact();
5925 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5926 f_rslem_unregister(0, g_chan_nr);
5927}
5928testcase TC_chan_act_a51() runs on test_CT {
5929 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5930 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5931 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5932}
5933testcase TC_chan_act_a52() runs on test_CT {
5934 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5935 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5936 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5937}
5938testcase TC_chan_act_a53() runs on test_CT {
5939 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5940 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5941 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5942}
5943
Eric Wildf1827a72019-05-28 17:37:35 +02005944/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5945 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5946function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5947 f_l1_tune(L1CTL);
5948 f_est_dchan(true);
5949
5950 /* now we actually need to transmit some data both ways to check if the encryption works */
5951 var L1ctlDlMessage dl;
5952
5953 var octetstring l3 := f_rnd_octstring(20);
5954 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5955
5956 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5957 f_unitdata_mt(link_id, l3);
5958
5959 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5960 f_unitdata_mo(link_id, l3);
5961
5962 var RSL_Message rsl;
5963 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5964
5965 /* modify key to break proper encryption */
5966 g_pars.encr.key := f_rnd_octstring(8);
5967 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5968 rsl.ies := rsl.ies & { ei };
5969 RSL.send(rsl);
5970
5971 timer T0 := 1.0;
5972 T0.start;
5973 /* Expect RSL MODIFY ACK */
5974 alt {
5975 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5976 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5978 }
5979 [] T0.timeout {
5980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5981 }
5982 }
5983
5984 var octetstring l3msg := f_rnd_octstring(15);
5985 timer T1 := 3.0;
5986 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5987 due to broken encryption */
5988 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5989 T1.start;
5990 alt {
5991 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5993 }
5994 [] T1.timeout {
5995 setverdict(pass);
5996 }
5997 }
5998
5999 /* release the channel */
6000 f_rsl_chan_deact();
6001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6002 f_rslem_unregister(0, g_chan_nr);
6003}
6004testcase TC_rsl_modify_encr() runs on test_CT {
6005 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6006 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6007 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6008}
Harald Weltee613f962018-04-18 22:38:16 +02006009
6010/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6011function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6012 /* L3 payload doesn't matter, as it is passed transparently */
6013 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6014 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6015 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6016
6017 f_l1_tune(L1CTL);
6018
6019 /* first establish a dedicated channel in the clear */
6020 f_est_dchan(false);
6021
6022 /* Establish ABM */
6023 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6024
6025 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6026 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6027 /* expect the L3 to arrive still unencrypted on the MS side */
6028 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6029
6030 /* configure L1 to apply ciphering */
6031 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6032 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6033
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006034 /* send first ciphered I-frame in response and expect it on RSL */
6035 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006036
6037 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6038 * and hence enable encryption also on the downlink */
6039
6040 /* expect bi-directional communication work in encrypted mode */
6041 f_unitdata_mo(link_id, f_rnd_octstring(15));
6042 f_unitdata_mt(link_id, f_rnd_octstring(15));
6043
6044 /* release the channel */
6045 f_rsl_chan_deact();
6046 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6047 f_rslem_unregister(0, g_chan_nr);
6048}
6049testcase TC_encr_cmd_a51() runs on test_CT {
6050 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6051 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6052 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6053}
6054testcase TC_encr_cmd_a52() runs on test_CT {
6055 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6056 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6057 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6058}
6059testcase TC_encr_cmd_a53() runs on test_CT {
6060 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6061 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6062 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6063}
6064
6065private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6066 var LapdmFrame lf;
6067 var octetstring reenc;
6068
6069 /* decode the LAPDm frame */
6070 if (ischosen(exp_match.ab)) {
6071 lf.ab := dec_LapdmFrameAB(enc);
6072 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006074 }
6075
6076 /* check if decoder result matches expectation */
6077 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006079 } else {
6080 log(name, ": matched");
6081 setverdict(pass);
6082 }
6083
6084 /* test if re-encoded frame equals original input */
6085 reenc := enc_LapdmFrame(lf);
6086 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006088 } else {
6089 setverdict(pass);
6090 }
6091}
6092
6093testcase TC_lapdm_selftest() runs on test_CT {
6094 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6095 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6096 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6097 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6098 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6099 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6100 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6101}
6102
Stefan Sperling4880be42018-08-07 18:12:59 +02006103/***********************************************************************
6104 * DTX Related (see GSM 05.08, section 8.3)
6105 ***********************************************************************/
6106
6107/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6108function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6109 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6110 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6111 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6112 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6113}
6114function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6115 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6116 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6117}
6118function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6119 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6120 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6121 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6122 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6123}
6124function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6125 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6126 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6127 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6128 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6129 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6130 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6131 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6132 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6133}
6134
6135function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6136 var L1ctlDlMessage dl;
6137 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6138 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6139 var GsmFrameNumber first_fn;
6140 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006141 var integer nfill_frames_sacch := 0;
6142 var integer nfill_frames_nonsacch := 0;
6143 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006144 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6145 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006146 const integer frame_dtx_tchf_mod := 104;
6147 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6148 * which operates in terms of blocks rather than frames. */
6149 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6150 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006151 timer T := 5.0;
6152
6153 f_l1_tune(L1CTL);
6154 RSL.clear;
6155 L1CTL.clear;
6156
6157 /* activate TCHF signalling channel */
6158 f_est_dchan(false);
6159
6160 T.start;
6161 alt {
6162 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6163 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6164 var octetstring l2 := dl.payload.data_ind.payload;
6165
6166 if (is_first_frame) {
6167 is_first_frame := false;
6168 first_fn := dl.dl_info.frame_nr;
6169 }
6170
6171 if (dl.dl_info.link_id.c == SACCH) {
6172 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6173 if (not match(l2_fill_frame_sacch, l2)) {
6174 repeat;
6175 }
6176 } else if (not match(l2_fill_frame, l2)) {
6177 repeat;
6178 }
6179
6180 if (dtxd) {
6181 if (not f_g_chan_is_tchf()) {
6182 T.stop;
6183 f_rsl_chan_deact();
6184 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006185 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 +02006186 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006187 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006188 T.stop;
6189 f_rsl_chan_deact();
6190 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006191
6192 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6193 * 2 SACCH, 1 TCH/F */
6194 expected_fill_frames := 3;
6195
6196 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6197 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6198 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006200 } else {
6201 setverdict(pass);
6202 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006203 } else {
6204 if (dl.dl_info.link_id.c == SACCH) {
6205 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006206 repeat;
6207 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006208 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6209 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6210 * we should only see the subset of frames numbers which correspond to a block boundary.
6211 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6212 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6213 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6214 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6215 repeat;
6216 }
6217 }
6218 log("Received DTX TCH fill frame with bad frame number: ", fn,
6219 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6220 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6221 f_rsl_chan_deact();
6222 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006224 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006225 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006226 if (dl.dl_info.link_id.c == SACCH) {
6227 nfill_frames_sacch := nfill_frames_sacch + 1;
6228 } else {
6229 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6230 }
6231 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006232 T.stop;
6233 if (f_g_chan_is_tchf()) {
6234 /* Without DTX we can expect 25 fill frames for every 104 frames.
6235 * (24 FACCH + 1 SACCH filling) */
6236 expected_fill_frames := 25;
6237 } else if (f_g_chan_is_tchh()) {
6238 /* We can expect 2 fill frames for every 104 frames. */
6239 expected_fill_frames := 2;
6240 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6241 /* We can expect 5 fill frames for every 104 frames. */
6242 expected_fill_frames := 5;
6243 } else {
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, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006247 }
6248
6249 f_rsl_chan_deact();
6250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006251
6252 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006253 setverdict(pass);
6254 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006255 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6256 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006258 }
6259 } else {
6260 repeat;
6261 }
6262 }
6263 }
6264 [] L1CTL.receive { repeat; }
6265 [] T.timeout {
6266 f_rsl_chan_deact();
6267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006269 }
6270 }
6271}
6272
6273function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6274 f_test_l2_fill_frames(false);
6275}
6276
6277function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6278 f_test_l2_fill_frames(true);
6279}
6280
6281function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6282 var ConnHdlr vc_conn;
6283 var ConnHdlrPars pars;
6284 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006285 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006286 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6287 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6288 if (dtxd) {
6289 if (i >= 4) { /* DTX is only allowed on TCH/F */
6290 break;
6291 }
6292 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6293 } else {
6294 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6295 }
6296 vc_conn.done;
6297 }
6298}
6299
6300/* Verify that L2 fill frames are sent on TCH in signaling mode if
6301 * there is nothing to transmit while DTX is disabled on downlink. */
6302testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6303 f_tch_sign_l2_fill_frame(false);
6304}
6305
6306/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6307 * there is nothing to transmit while DTX is enabled on downlink. */
6308testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6309 f_tch_sign_l2_fill_frame(true);
6310}
Harald Welte0472ab42018-03-12 15:02:26 +01006311
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006312testcase TC_chopped_ipa_ping() runs on test_CT {
6313 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6314}
6315
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006316testcase TC_chopped_ipa_payload() runs on test_CT {
6317 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6318}
6319
Harald Welte0472ab42018-03-12 15:02:26 +01006320/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6321/* protocol error as per 44.006 */
6322/* link layer failure (repetition of I-frame N200 times without ACK */
6323/* repetition of SABM or DISC N200 times without ACK */
6324/* receptiom of SABM in multi-frame established state */
6325
6326
Harald Welte68e495b2018-02-25 00:05:57 +01006327/* TODO Areas:
6328
6329* channel activation
6330** with BS_Power / MS_Power, bypassing power control loop
6331** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006332** with timing advance from initial activation on
6333* mode modify
6334** encryption
6335** multirate
6336* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006337** unsupported algorithm
6338* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006339* BS Power Control
6340* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006341* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006342* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006343** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006344* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006345** DATA_IND from BTS->PCU
6346** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006347
6348*/
Harald Welte70767382018-02-21 12:16:40 +01006349
6350control {
6351 execute( TC_chan_act_stress() );
6352 execute( TC_chan_act_react() );
6353 execute( TC_chan_deact_not_active() );
6354 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006355 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006356 execute( TC_sacch_filling() );
6357 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006358 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006359 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006360 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006361 execute( TC_sacch_chan_act_ho_async() );
6362 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006363 execute( TC_rach_content() );
6364 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006365 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006366 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006367 execute( TC_rach_load_idle_thresh0() );
6368 execute( TC_rach_load_idle_below_thresh() );
6369 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006370 execute( TC_meas_res_sign_tchf() );
6371 execute( TC_meas_res_sign_tchh() );
6372 execute( TC_meas_res_sign_sdcch4() );
6373 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006374 execute( TC_meas_res_sign_tchh_toa256() );
Eric Wildae8f2622019-06-18 17:05:11 +02006375 execute( TC_rsl_bs_pwr_static_ass() );
6376 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006377 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006378 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006379 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006380 execute( TC_rsl_ms_pwr_dyn_up() );
6381 execute( TC_rsl_ms_pwr_dyn_down() );
6382 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6383 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006384 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006385 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006386 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006387 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006388 execute( TC_paging_imsi_80percent() );
6389 execute( TC_paging_tmsi_80percent() );
6390 execute( TC_paging_imsi_200percent() );
6391 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006392 execute( TC_rsl_protocol_error() );
6393 execute( TC_rsl_mand_ie_error() );
6394 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006395 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006396 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006397 execute( TC_si_sched_2bis() );
6398 execute( TC_si_sched_2ter() );
6399 execute( TC_si_sched_2ter_2bis() );
6400 execute( TC_si_sched_2quater() );
6401 execute( TC_si_sched_13() );
6402 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006403 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006404 execute( TC_ipa_crcx_twice_not_active() );
6405 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006406 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006407 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006408
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006409 if (mp_pcu_socket != "") {
6410 execute( TC_pcu_act_req() );
6411 execute( TC_pcu_act_req_wrong_ts() );
6412 execute( TC_pcu_act_req_wrong_bts() );
6413 execute( TC_pcu_act_req_wrong_trx() );
6414 execute( TC_pcu_deact_req() );
6415 execute( TC_pcu_deact_req_wrong_ts() );
6416 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006417 if (mp_l1_supports_gprs) {
6418 execute( TC_pcu_data_req_pdtch() );
6419 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006420 execute( TC_pcu_data_req_wrong_bts() );
6421 execute( TC_pcu_data_req_wrong_trx() );
6422 execute( TC_pcu_data_req_wrong_ts() );
6423 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006424 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006425 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006426 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006427 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006428 execute( TC_pcu_data_req_imm_ass_pch() );
6429 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006430 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006431 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006432 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006433 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006434 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006435 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006436 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006437 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006438 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006439 execute( TC_pcu_socket_noconnect_nosi3gprs() );
6440 execute( TC_pcu_socket_connect_si3gprs() );
6441 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006442 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006443 execute( TC_dyn_osmo_pdch_act_deact() );
6444 execute( TC_dyn_osmo_pdch_double_act() );
6445 execute( TC_dyn_ipa_pdch_act_deact() );
6446 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6447
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006448 } else {
6449 log("PCU socket path not available, skipping PCU tests");
6450 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006451
Harald Welte3d04ae62018-04-04 20:29:05 +02006452 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006453 execute( TC_dyn_osmo_pdch_tchf_act() );
6454 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006455 execute( TC_dyn_ipa_pdch_tchf_act() );
6456 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006457
6458 execute( TC_rll_est_ind() );
6459 execute( TC_rll_est_req_DCCH_3() );
6460 execute( TC_rll_est_req_ACCH_3() );
6461 execute( TC_rll_rel_ind_DCCH_0() );
6462 execute( TC_rll_rel_ind_DCCH_3() );
6463 execute( TC_rll_rel_ind_ACCH_0() );
6464 execute( TC_rll_rel_ind_ACCH_3() );
6465 execute( TC_rll_rel_req() );
6466 execute( TC_rll_unit_data_req_DCCH() );
6467 execute( TC_rll_unit_data_req_ACCH() );
6468 execute( TC_rll_unit_data_ind_DCCH() );
6469 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006470
6471 execute( TC_chan_act_a51() );
6472 execute( TC_chan_act_a52() );
6473 execute( TC_chan_act_a53() );
6474 execute( TC_encr_cmd_a51() );
6475 execute( TC_encr_cmd_a52() );
6476 execute( TC_encr_cmd_a53() );
6477
Harald Welteee25aae2019-05-19 14:32:37 +02006478 execute( TC_err_rep_wrong_mdisc() );
6479 execute( TC_err_rep_wrong_msg_type() );
6480 execute( TC_err_rep_wrong_sequence() );
6481
Harald Weltee613f962018-04-18 22:38:16 +02006482 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006483
6484 execute( TC_tch_sign_l2_fill_frame() );
6485 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006486
6487 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006488 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006489}
6490
6491
6492}