blob: f98419d9f1962a6c1a2ca0a13af5618fdfdf5c0d [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 Yanitskiy28cabc42020-05-27 19:44:44 +070087 integer mp_trx1_arfcn := 873;
88 integer mp_trx2_arfcn := 875;
89 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070090 charstring mp_bts_trxc_ip := "127.0.0.1";
91 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010092 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020093 charstring mp_ctrl_ip := "127.0.0.1";
94 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020095 charstring mp_bsc_ctrl_ip := "127.0.0.1";
96 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020097 integer mp_tolerance_rxqual := 1;
98 integer mp_tolerance_rxlev := 3;
99 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200100 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200101 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200102 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200103 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
104 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200105 integer mp_ms_actual_ta_exp := 0;
106 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100112}
113
Harald Welte629cc6b2018-03-11 17:19:05 +0100114type record of RslChannelNr ChannelNrs;
115
Harald Welte70767382018-02-21 12:16:40 +0100116type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100117 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100118 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100119 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100120 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100121 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100122 port RSL_CCHAN_PT RSL_CCHAN;
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700123 timer g_rslem_up_timer;
Harald Welte68e495b2018-02-25 00:05:57 +0100124
125 /* L1CTL port (for classic tests) */
126 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100127
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700128 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700129 port TRXC_CODEC_PT BTS_TRXC;
130 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100131
Harald Weltef50e3ae2018-09-10 10:27:56 +0200132 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100133 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200134 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100135
Harald Welte883340c2018-02-28 18:59:29 +0100136 /* PCU Interface of BTS */
137 port PCUIF_CODEC_PT PCU;
138 var integer g_pcu_conn_id;
139 /* Last PCU INFO IND we received */
140 var PCUIF_Message g_pcu_last_info;
141
Harald Welte48494ca2018-02-25 16:59:50 +0100142 /* SI configuration */
143 var SystemInformationConfig si_cfg := {
144 bcch_extended := false,
145 si1_present := false,
146 si2bis_present := false,
147 si2ter_present := false,
148 si2quater_present := false,
149 si7_present := false,
150 si8_present := false,
151 si9_present := false,
152 si13_present := false,
153 si13alt_present := false,
154 si15_present := false,
155 si16_present := false,
156 si17_present := false,
157 si2n_present := false,
158 si21_present := false,
159 si22_present := false
160 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100161
162 /* all logical channels available on the BTS */
163 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100164 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100165}
166
167/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200168type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100169 port L1CTL_PT L1CTL;
170
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700171 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700172 port TRXC_CODEC_PT BTS_TRXC;
173 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100174
175 timer g_Tguard;
176 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
177
178 var ConnHdlrPars g_pars;
179 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100180 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200181
182 /* PCU Interface of BTS */
183 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100184}
185
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700186private altstep as_rsl_init_guard() runs on test_CT {
187 [] g_rslem_up_timer.timeout {
188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
189 "Timeout waiting for RSL bring up");
190 }
Vadim Yanitskiy96e8c802020-06-10 14:14:12 +0700191 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
192 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700193}
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700194
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700195function f_init_rsl(charstring id) runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100196 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
197 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
198
199 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
200 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
201 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
202
203 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
204 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700205
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700206 /* TTCN-3 offers no way to guard 'interleave' statements */
207 g_rslem_up_timer.start(mp_ipa_up_timeout);
208 var default d := activate(as_rsl_init_guard());
209
210 /* We expect all 4 transceivers to connect here (separate IPA/RSL connections).
211 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
212 interleave {
213 /* These events are sent by the RSL_Emulation_CT */
214 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX0));
215 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX1));
216 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX2));
217 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, IPAC_PROTO_RSL_TRX3));
218 /* These messages (RF RESource INDication) are sent by the IUT itself */
219 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX0));
220 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX1));
221 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX2));
222 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, IPAC_PROTO_RSL_TRX3));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700223 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700224
225 g_rslem_up_timer.stop;
226 deactivate(d);
Harald Welte70767382018-02-21 12:16:40 +0100227}
228
229type record ConnHdlrPars {
230 RslChannelNr chan_nr,
231 RSL_IE_ChannelMode chan_mode,
232 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100233 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200234 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200235 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700236 BtsBand bts0_band optional,
237
238 /* Frequency hopping parameters (disabled if absent) */
239 MaioHsn maio_hsn optional,
240 /* MA bitmap to be indicated in RR Immediate Assignment */
241 MobileAllocation ma_map,
242 /* The actual Mobile Allocation (ARFCN list) to be used */
243 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100244}
245
246/* Test-specific parameters */
247type union TestSpecUnion {
248 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100249}
250
Harald Welte82ccef72018-02-25 16:17:33 +0100251template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100252 max_retrans := RACH_MAX_RETRANS_7,
253 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100254 cell_barr_access := false,
255 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100256 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100257};
258
Harald Weltef10153f2018-02-25 16:34:05 +0100259template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100260 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200261 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100262 acs := '0'B,
263 neci := true,
264 rxlev_access_min := 0
265}
266
267template (value) LocationAreaIdentification ts_LAI_default := {
268 mcc_mnc := '262F42'H,
269 lac := 42
270}
271
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700272private template (value) GPRSIndicator ts_GPRSIndicator_def := {
273 ra_colour := 0,
274 si13_pos := '0'B
275}
276
277private template (value) SI3RestOctets ts_SI3RestOctets_def
278modifies ts_SI3RestOctets := {
279 gprs_ind := {
280 presence := CSN1_H,
281 ind := ts_GPRSIndicator_def
282 }
283}
284
285private template (value) SI4RestOctets ts_SI4RestOctets_def
286modifies ts_SI4RestOctets := {
287 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700288 presence := CSN1_H,
289 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700290 }
291}
292
Harald Welte7484fc42018-02-24 14:09:45 +0100293/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100294template (value) SystemInformation ts_SI3_default := {
295 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100296 payload := {
297 si3 := {
298 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100299 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100300 ctrl_chan_desc := {
301 msc_r99 := true,
302 att := true,
303 bs_ag_blks_res := 1,
304 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100305 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100306 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
307 spare := '00'B,
308 bs_pa_mfrms := 0, /* 2 multiframes */
309 t3212 := 1 /* 6 minutes */
310 },
Harald Welte82ccef72018-02-25 16:17:33 +0100311 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100312 dn_ind := false,
313 pwrc := false,
314 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100315 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100316 },
Harald Weltef10153f2018-02-25 16:34:05 +0100317 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100318 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700319 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100320 }
321 }
322}
Harald Welte70767382018-02-21 12:16:40 +0100323
Harald Weltef8df4cb2018-03-10 15:15:08 +0100324template (value) SystemInformation ts_SI2_default := {
325 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100326 payload := {
327 si2 := {
328 bcch_freq_list := '00000000000000000000000000000000'O,
329 ncc_permitted := '11111111'B,
330 rach_control := ts_RachCtrl_default
331 }
332 }
333}
334
Harald Weltef8df4cb2018-03-10 15:15:08 +0100335template (value) SystemInformation ts_SI4_default := {
336 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100337 payload := {
338 si4 := {
339 lai := ts_LAI_default,
340 cell_sel_par := ts_CellSelPar_default,
341 rach_control := ts_RachCtrl_default,
342 cbch_chan_desc := omit,
343 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700344 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100345 }
346 }
347}
348
349function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
350runs on test_CT {
351 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700352 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100353}
354
355function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
356runs on test_CT {
357 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
358 log("Setting ", rsl_si_type, ": ", si_dec);
359 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
360}
361
Harald Welte505cf9b2018-09-15 17:47:23 +0300362friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100363 map(self:BTSVTY, system:BTSVTY);
364 f_vty_set_prompts(BTSVTY);
365 f_vty_transceive(BTSVTY, "enable");
366}
367
Harald Welte505cf9b2018-09-15 17:47:23 +0300368friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200369 map(self:BSCVTY, system:BSCVTY);
370 f_vty_set_prompts(BSCVTY, "OsmoBSC");
371 f_vty_transceive(BSCVTY, "enable");
372}
373
Harald Welte883340c2018-02-28 18:59:29 +0100374/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200375private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
376 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100377 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200378 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
379 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100380 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200381 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100383 }
384}
385
Harald Weltef26de0b2018-04-04 20:28:05 +0200386private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
387 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100388 timer T := 2.0;
389 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100390 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200391 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100392 return;
393 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200394 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100395
396 T.start;
397 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200398 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100399 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100401 }
402 }
403}
404
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700405private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
406 out integer trxc_conn_id) {
407 var Result res;
408
409 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
410 "", -1, -1, { udp := {} }, {});
411 if (not ispresent(res.connId)) {
412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
413 "Could not connect to the control (TRXC) interface " &
414 "of FakeTRX, check your configuration");
415 }
416 trxc_conn_id := res.connId;
417}
418
Harald Welte70767382018-02-21 12:16:40 +0100419/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200420function f_init() runs on test_CT {
421 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100422 g_AllChannels := {
423 /* TS 1..4: TCH/F */
424 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
425 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
426 /* TS 5: TCH/H */
427 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
428 /* TS 0: SDCCH/4 */
429 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
430 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
431 /* TS 6: SDCCH/8 */
432 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
433 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
434 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
435 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
436 };
437
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200438 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700439 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200440 g_AllChanTypes := {
441 /* TS 1..4: TCH/F */
442 valueof(ts_RslChanNr_Bm(1)),
443 /* TS 5: TCH/H */
444 valueof(ts_RslChanNr_Lm(5,1)),
445 /* TS 0: SDCCH/4 */
446 valueof(ts_RslChanNr_SDCCH4(0,2)),
447 /* TS 6: SDCCH/8 */
448 valueof(ts_RslChanNr_SDCCH8(6,4))
449 };
450 } else {
451 g_AllChanTypes := {
452 /* TS 1..4: TCH/F */
453 valueof(ts_RslChanNr_Bm(1)),
454 /* TS 0: SDCCH/4 */
455 valueof(ts_RslChanNr_SDCCH4(0,2)),
456 /* TS 6: SDCCH/8 */
457 valueof(ts_RslChanNr_SDCCH8(6,4))
458 };
459 }
Harald Welte70767382018-02-21 12:16:40 +0100460 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100461 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100462 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200463 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100464
465 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100466 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
467 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
468 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
469 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100470
Harald Weltef26de0b2018-04-04 20:28:05 +0200471 map(self:PCU, system:PCU);
472 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100473
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700474 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100475 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700476
477 /* Init TRXC interface to FakeTRX */
478 map(self:BTS_TRXC, system:BTS_TRXC);
479 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
480
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700481 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700482 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 +0700483 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700484 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
485 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100486 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200487
488 /* Wait some extra time to make sure the BTS emits a stable carrier.
489 * (this is only relevant when running the tests with a physical BTS.) */
490 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100491}
492
Harald Welte68e495b2018-02-25 00:05:57 +0100493/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
494function f_init_l1ctl() runs on test_CT {
495 map(self:L1CTL, system:L1CTL);
496 f_connect_reset(L1CTL);
497}
498
Harald Welte70767382018-02-21 12:16:40 +0100499type function void_fn(charstring id) runs on ConnHdlr;
500
501/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700502function f_start_handler(void_fn fn, ConnHdlrPars pars,
503 boolean pcu_comp := false,
504 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100505runs on test_CT return ConnHdlr {
506 var charstring id := testcasename();
507 var ConnHdlr vc_conn;
508
509 vc_conn := ConnHdlr.create(id);
510 /* connect to RSL Emulation main component */
511 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
512 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700513
514 /* The ConnHdlr component may want to talk to some ports directly,
515 * so we disconnect it from the test_CT and connect it to the component.
516 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200517 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200518 unmap(self:PCU, system:PCU);
519 map(vc_conn:PCU, system:PCU);
520 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700521 if (trxc_comp) {
522 unmap(self:BTS_TRXC, system:BTS_TRXC);
523 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
524 }
Harald Welte70767382018-02-21 12:16:40 +0100525
526 vc_conn.start(f_handler_init(fn, id, pars));
527 return vc_conn;
528}
529
Harald Welte70767382018-02-21 12:16:40 +0100530private altstep as_Tguard() runs on ConnHdlr {
531 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100533 }
534}
535
Harald Welte990a3612019-05-27 14:02:13 +0200536friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
537 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100538}
539
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700540private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100541 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700542 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100543}
544
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700545private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100546 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700547 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100548}
549
550/* first function started in ConnHdlr component */
551private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
552runs on ConnHdlr {
553 g_pars := pars;
554 g_chan_nr := pars.chan_nr;
555
556 map(self:L1CTL, system:L1CTL);
557 f_connect_reset(L1CTL);
558
Harald Welted48c0c72019-06-05 10:01:15 +0200559 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700560 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100561 }
Harald Welte70767382018-02-21 12:16:40 +0100562
563 g_Tguard.start(pars.t_guard);
564 activate(as_Tguard());
565
566 f_rslem_register(0, pars.chan_nr);
567
568 /* call the user-supplied test case function */
569 fn.apply(id);
570}
571
Harald Welteb1726c92018-03-30 11:56:38 +0200572function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
573 boolean ignore_other := false)
574runs on ConnHdlr return RSL_Message {
575 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100576 timer T := 3.0;
577 RSL.send(tx);
578 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100579 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200580 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100581 T.stop;
582 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100583 }
Harald Welte1eba3742018-02-25 12:48:14 +0100584 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100586 }
Harald Welte21240e62018-03-11 21:43:35 +0100587 [not ignore_other] as_l1_sacch();
588 [not ignore_other] as_meas_res();
589 [not ignore_other] as_l1_dcch();
590 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100592 }
Harald Welte21240e62018-03-11 21:43:35 +0100593 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100594 }
Harald Welteb1726c92018-03-30 11:56:38 +0200595 return rx;
596}
597
598function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
599 boolean ignore_other := false)
600runs on ConnHdlr {
601 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Harald Welte8b01c792019-05-19 22:51:25 +0200604function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
605 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
606 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200607 if (encr_enable) {
608 /* append encryption related IEs, if requested */
609 var RSL_IE_EncryptionInfo encr_info;
610 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
611 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
612encr_info})) };
613 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200614 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200615 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100616}
617
Harald Welte70767382018-02-21 12:16:40 +0100618function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100619 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 +0100620 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100621}
622
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700623/* Default Mobile Allocation to be used for frequency hopping */
624private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
625 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
626
Harald Welte2f2b2b72019-05-31 22:24:57 +0200627friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100628 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700629 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100630 float t_guard := 20.0) := {
631 chan_nr := valueof(chan_nr),
632 chan_mode := valueof(chan_mode),
633 t_guard := t_guard,
634 l1_pars := {
635 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100636 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100637 meas_ul := {
638 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200639 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100640 rxqual := 0
641 },
642 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200643 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100644 rxqual := 0
645 }
646 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200647 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100648 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200649 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200650 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100651 },
Harald Weltee613f962018-04-18 22:38:16 +0200652 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200653 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700654 bts0_band := omit,
655 maio_hsn := maio_hsn,
656 ma_map := c_MA_null,
657 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100658}
659
Harald Welte93640c62018-02-25 16:59:33 +0100660/***********************************************************************
661 * Channel Activation / Deactivation
662 ***********************************************************************/
663
Harald Welte70767382018-02-21 12:16:40 +0100664/* Stress test: Do 500 channel activations/deactivations in rapid succession */
665function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
666 for (var integer i := 0; i < 500; i := i+1) {
667 f_rsl_chan_act(g_pars.chan_mode);
668 f_rsl_chan_deact();
669 }
670 setverdict(pass);
671}
672testcase TC_chan_act_stress() runs on test_CT {
673 var ConnHdlr vc_conn;
674 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200675 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100676 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
677 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100679}
680
681/* Test if re-activation of an already active channel fails as expected */
682function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
683 f_rsl_chan_act(g_pars.chan_mode);
684 /* attempt to activate the same lchan again -> expect reject */
685 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
686 alt {
687 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100689 }
690 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
691 setverdict(pass);
692 }
693 }
694 f_rsl_chan_deact();
695}
696testcase TC_chan_act_react() runs on test_CT {
697 var ConnHdlr vc_conn;
698 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100699 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100700 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
701 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100703}
704
705/* Attempt to de-activate a channel that's not active */
706function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
707 timer T := 3.0;
708 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
709 T.start;
710 alt {
711 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
712 setverdict(pass);
713 }
714 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100716 }
717 }
718}
719testcase TC_chan_deact_not_active() runs on test_CT {
720 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100721 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100722 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
723 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100725}
726
727/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
728function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
729 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
730 alt {
731 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100733 }
734 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
735 setverdict(pass);
736 }
737 }
738}
739private type record WrongChanNrCase {
740 RslChannelNr chan_nr,
741 charstring description
742}
743private type record of WrongChanNrCase WrongChanNrCases;
744private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
745 chan_nr := chan_nr,
746 description := desc
747}
748
749testcase TC_chan_act_wrong_nr() runs on test_CT {
750 var ConnHdlr vc_conn;
751 var ConnHdlrPars pars;
752
Harald Welte294b0a22018-03-10 23:26:48 +0100753 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100754
755 var WrongChanNrCases wrong := {
756 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
757 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
758 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
759 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
760 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
761 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
762 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
763 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
764 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
765 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
766 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
767 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
768 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
769 };
770
771 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
772 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
773 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
774 vc_conn.done;
775 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100777}
778
Harald Weltee613f962018-04-18 22:38:16 +0200779/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200780friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200781 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200782 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200783
784 /* test on each of the channels we have */
785 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
786 pars.chan_nr := valueof(g_AllChanTypes[i]);
787
788 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
789 vc_conn := f_start_handler(fn, pars);
790 vc_conn.done;
791 }
792
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200794}
795
Harald Welte93640c62018-02-25 16:59:33 +0100796/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100797 * SACCH handling
798 ***********************************************************************/
799
800private function f_exp_sacch(boolean exp) runs on ConnHdlr {
801 timer T_sacch := 3.0;
802 T_sacch.start;
803 alt {
804 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100806 }
807 [not exp] T_sacch.timeout {
808 setverdict(pass);
809 }
810 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
811 setverdict(pass);
812 }
813 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100815 }
816 [] L1CTL.receive { repeat; }
817 [] RSL.receive { repeat; }
818 }
819}
820
821/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
822private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
823 f_l1_tune(L1CTL);
824 RSL.clear;
825
826 /* activate the logical channel */
827 f_est_dchan();
828 L1CTL.clear;
829
830 /* check that SACCH actually are received as expected */
831 f_exp_sacch(true);
832
833 /* deactivate SACCH on the logical channel */
834 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
835 f_sleep(1.0);
836 L1CTL.clear;
837
838 /* check that no SACCH are received anymore */
839 f_exp_sacch(false);
840
841 /* release the channel */
842 f_rsl_chan_deact();
843 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
844}
845testcase TC_deact_sacch() runs on test_CT {
846 var ConnHdlr vc_conn;
847 var ConnHdlrPars pars;
848 f_init();
849 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
850 //for (var integer i := 0; i < 1; i := i+1) {
851 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
852 log(testcasename(), ": Starting for ", g_AllChannels[i]);
853 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
854 vc_conn.done;
855 }
856 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100858}
859
Harald Welte55700662018-03-12 13:15:43 +0100860/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100861private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
862 var L1ctlDlMessage dl;
863 /* check that the specified SI5 value is actually sent */
864 timer T_sacch := 3.0;
865 L1CTL.clear;
866 T_sacch.start;
867 alt {
868 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
869 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
870 if (match(l3, l3_exp)) {
871 setverdict(pass);
872 } else {
873 repeat;
874 }
875 }
876 [] L1CTL.receive { repeat; }
877 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100879 }
880 }
881}
882
Harald Welte55700662018-03-12 13:15:43 +0100883/* verify that given SACCH payload is not present */
884private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
885 var L1ctlDlMessage dl;
886 /* check that the specified SI5 value is actually sent */
887 timer T_sacch := 3.0;
888 L1CTL.clear;
889 T_sacch.start;
890 alt {
891 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
892 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
893 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100895 } else {
896 repeat;
897 }
898 }
899 [] L1CTL.receive { repeat; }
900 [] T_sacch.timeout {
901 setverdict(pass);
902 }
903 }
904}
905
Harald Welte629cc6b2018-03-11 17:19:05 +0100906/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100907private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
908 /* Set a known default SACCH filling for SI5 */
909 var octetstring si5 := f_rnd_octstring(19);
910 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
911
912 f_l1_tune(L1CTL);
913 RSL.clear;
914
915 /* activate the logical channel */
916 f_est_dchan();
917
918 /* check that the specified SI5 value is actually sent */
919 f_sacch_present(si5);
920
921 /* release the channel */
922 RSL.clear;
923 f_rsl_chan_deact();
924 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
925}
926testcase TC_sacch_filling() runs on test_CT {
927 var ConnHdlr vc_conn;
928 var ConnHdlrPars pars;
929 f_init();
930 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
931 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
932 log(testcasename(), ": Starting for ", g_AllChannels[i]);
933 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
934 vc_conn.done;
935 }
936 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100938}
939
Harald Welte629cc6b2018-03-11 17:19:05 +0100940/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100941private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
942 /* Set a known default SACCH filling for SI5 */
943 var octetstring si5 := f_rnd_octstring(19);
944 var octetstring si5_diff := f_rnd_octstring(19);
945 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
946
947 f_l1_tune(L1CTL);
948 RSL.clear;
949
950 log("Activating channel, expecting standard SI5");
951 /* activate the logical channel */
952 f_est_dchan();
953 /* check that the specified SI5 value is actually sent */
954 f_sacch_present(si5);
955
956 /* set channel-specific different SI5 */
957 log("Setting channel specific SACCH INFO, expecting it");
958 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
959 /* check that the specified lchan-specific value is now used */
960 f_sacch_present(si5_diff);
961
962 /* deactivate the channel and re-activate it, this should result in default SI5 */
963 log("De-activating and re-activating channel, expecting standard SI5");
964 f_rsl_chan_deact();
965 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
966 /* Verify that the TRX-wide default SACCH filling is present again */
967 f_sacch_present(si5);
968
969 /* release the channel */
970 RSL.clear;
971 f_rsl_chan_deact();
972 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
973}
974testcase TC_sacch_info_mod() runs on test_CT {
975 var ConnHdlr vc_conn;
976 var ConnHdlrPars pars;
977 f_init();
978 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
979 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
980 log(testcasename(), ": Starting for ", g_AllChannels[i]);
981 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
982 vc_conn.done;
983 }
984 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100986}
987
Harald Welte075d84c2018-03-12 13:07:24 +0100988/* Test SACCH scheduling of multiple different SI message types */
989private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
990 var octetstring si5 := f_rnd_octstring(19);
991 var octetstring si5bis := f_rnd_octstring(19);
992 var octetstring si5ter := f_rnd_octstring(19);
993 var octetstring si6 := f_rnd_octstring(19);
994
995 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
996 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
997 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
998 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
999
1000 f_l1_tune(L1CTL);
1001 RSL.clear;
1002
1003 /* activate the logical channel */
1004 f_est_dchan();
1005 L1CTL.clear;
1006
1007 /* check that SACCH actually are received as expected */
1008 f_sacch_present(si5);
1009 f_sacch_present(si5bis);
1010 f_sacch_present(si5ter);
1011 f_sacch_present(si6);
1012
1013 /* release the channel */
1014 f_rsl_chan_deact();
1015 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1016}
1017testcase TC_sacch_multi() runs on test_CT {
1018 var ConnHdlr vc_conn;
1019 var ConnHdlrPars pars;
1020 f_init();
1021 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1022 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1023 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1024 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1025 vc_conn.done;
1026 }
1027 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001029}
1030
Harald Welte55700662018-03-12 13:15:43 +01001031/* Test if SACH information is modified as expected */
1032private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1033 var octetstring si5 := f_rnd_octstring(19);
1034 var octetstring si6 := f_rnd_octstring(19);
1035
1036 /* First, configure both SI5 and SI6 to be transmitted */
1037 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1038 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1039
1040 f_l1_tune(L1CTL);
1041 RSL.clear;
1042
1043 /* activate the logical channel */
1044 f_est_dchan();
1045 L1CTL.clear;
1046
1047 /* check that SACCH actually are received as expected */
1048 f_sacch_present(si5);
1049 f_sacch_present(si6);
1050
1051 /* disable SI6 */
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1053
1054 /* check that SI5 is still transmitted */
1055 f_sacch_present(si5);
1056 /* check if SI6 is now gone */
1057 f_sacch_missing(si6);
1058
1059 /* release the channel */
1060 f_rsl_chan_deact();
1061 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1062}
1063testcase TC_sacch_multi_chg() runs on test_CT {
1064 var ConnHdlr vc_conn;
1065 var ConnHdlrPars pars;
1066 f_init();
1067 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1068 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1069 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1070 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1071 vc_conn.done;
1072 }
1073 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001075}
1076
Harald Weltec8d363c2019-05-19 20:36:48 +02001077/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1078private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1079 var octetstring si5 := f_rnd_octstring(19);
1080 var octetstring si6 := f_rnd_octstring(19);
1081 var octetstring si5_specific := f_rnd_octstring(19);
1082 var octetstring si6_specific := f_rnd_octstring(19);
1083
1084 /* First, configure both SI5 and SI6 to be transmitted */
1085 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1086 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1087
1088 f_l1_tune(L1CTL);
1089 RSL.clear;
1090
1091 /* activate channel with different SACCH filling */
1092 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1093 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1094 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1095 }));
1096 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1097 RSL_IE_Body:{sacch_info := sacch_info})) };
1098 f_est_dchan(more_ies := addl_ies);
1099
1100 /* check that SACCH actually are received as expected */
1101 f_sacch_present(si5_specific);
1102 f_sacch_present(si6_specific);
1103
1104 /* release the channel */
1105 f_rsl_chan_deact();
1106 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1107}
1108testcase TC_sacch_chan_act() runs on test_CT {
1109 var ConnHdlr vc_conn;
1110 var ConnHdlrPars pars;
1111 f_init();
1112
1113 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1114 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1115 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1116 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1117 vc_conn.done;
1118 }
1119 /* TODO: do the above in parallel, rather than sequentially? */
1120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1121}
1122
Harald Welte8b01c792019-05-19 22:51:25 +02001123/* verify that SACCH DL transmission is started only if MS power IE present
1124 * see section 4.1.3 of 3GPP TS 48.058 */
1125private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1126 var octetstring si5 := f_rnd_octstring(19);
1127
1128 f_l1_tune(L1CTL);
1129 RSL.clear;
1130
1131 /* Step 1: Activate ASYNC HO channel without MS power IE */
1132
1133 /* Activate channel on BTS side */
1134 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1135 /* don't perform immediate assignment here, as we're testing non-IA case */
1136 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001137 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001138
1139 /* Verify that no DL SACCH is being received */
1140 f_sacch_missing(?);
1141
1142 f_rsl_chan_deact();
1143 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1144
1145
1146 /* Step 2: Activate ASYNC HO channel with MS power IE */
1147
1148 /* Activate channel on BTS side */
1149 var RSL_IE_List addl_ies := {
1150 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1151 };
1152 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1153 /* don't perform immediate assignment here, as we're testing non-IA case */
1154 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001155 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001156
1157 /* Verify that DL SACCH is being received */
1158 f_sacch_present(si5);
1159
1160 f_rsl_chan_deact();
1161 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1162}
1163testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1164 var ConnHdlr vc_conn;
1165 var ConnHdlrPars pars;
1166 f_init();
1167
1168 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1169 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1170 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1171 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1172 vc_conn.done;
1173 }
1174 /* TODO: do the above in parallel, rather than sequentially? */
1175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1176}
1177
1178/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1179 * see section 4.1.4 of 3GPP TS 48.058 */
1180private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1181 var octetstring si5 := f_rnd_octstring(19);
1182 var RSL_IE_List addl_ies;
1183
1184 f_l1_tune(L1CTL);
1185 RSL.clear;
1186
1187 /* Step 1: Activate SYNC HO channel without MS power IE */
1188
1189 /* Activate channel on BTS side */
1190 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1191 /* don't perform immediate assignment here, as we're testing non-IA case */
1192 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001193 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001194
1195 /* Verify that no DL SACCH is being received */
1196 f_sacch_missing(?);
1197
1198 f_rsl_chan_deact();
1199 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1200
1201
1202 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1203
1204 /* Activate channel on BTS side */
1205 addl_ies := {
1206 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1207 };
1208 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1209 /* don't perform immediate assignment here, as we're testing non-IA case */
1210 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001211 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001212
1213 /* Verify that no DL SACCH is being received */
1214 f_sacch_missing(?);
1215
1216 f_rsl_chan_deact();
1217 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1218
1219
1220 /* Step 2b: Activate SYNC HO channel with TA IE */
1221
1222 /* Activate channel on BTS side */
1223 addl_ies := {
1224 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1225 };
1226 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1227 /* don't perform immediate assignment here, as we're testing non-IA case */
1228 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001229 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001230
1231 /* Verify that no DL SACCH is being received */
1232 f_sacch_missing(?);
1233
1234 f_rsl_chan_deact();
1235 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1236
1237
1238 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1239
1240 /* Activate channel on BTS side */
1241 addl_ies := {
1242 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1243 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1244 };
1245 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1246 /* don't perform immediate assignment here, as we're testing non-IA case */
1247 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001248 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001249
1250 /* Verify that DL SACCH is being received */
1251 f_sacch_present(si5);
1252
1253 f_rsl_chan_deact();
1254 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1255}
1256testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1257 var ConnHdlr vc_conn;
1258 var ConnHdlrPars pars;
1259 f_init();
1260
1261 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1262 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1263 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1264 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1265 vc_conn.done;
1266 }
1267 /* TODO: do the above in parallel, rather than sequentially? */
1268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1269}
Harald Welte629cc6b2018-03-11 17:19:05 +01001270
1271
1272/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001273 * RACH Handling
1274 ***********************************************************************/
1275
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276/* like L1SAP_IS_PACKET_RACH */
1277private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001278 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001279 return true;
1280 }
1281 return false;
1282}
1283
1284/* generate a random RACH for circuit-switched */
1285private function f_rnd_ra_cs() return OCT1 {
1286 var OCT1 ra;
1287 do {
1288 ra := f_rnd_octstring(1);
1289 } while (ra_is_ps(ra));
1290 return ra;
1291}
1292
Harald Welte883340c2018-02-28 18:59:29 +01001293/* generate a random RACH for packet-switched */
1294private function f_rnd_ra_ps() return OCT1 {
1295 var OCT1 ra;
1296 do {
1297 ra := f_rnd_octstring(1);
1298 } while (not ra_is_ps(ra));
1299 return ra;
1300}
1301
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001302/* generate a random 11-bit RA (packet-switched only) */
1303private function f_rnd_ra11_ps() return BIT11 {
1304 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1305 return int2bit(ra11, 11);
1306}
1307
Harald Welte8c24c2b2018-02-26 08:31:31 +01001308/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1309testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001310 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001311 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001312 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001313
Harald Welte8c24c2b2018-02-26 08:31:31 +01001314 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001315 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001316 for (var integer i := 0; i < 1000; i := i+1) {
1317 var OCT1 ra := f_rnd_ra_cs();
1318 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1319 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001321 }
1322 fn_last := fn;
1323
1324 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001325 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001326 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001327 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001328 T.stop;
1329 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001330 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001332 }
1333 [] RSL_CCHAN.receive { repeat; }
1334 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001335 test_failed := true;
1336 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001337 }
1338 }
1339 }
Maxba06feb2019-03-05 10:52:46 +01001340 if (test_failed) {
1341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001342 }
Maxba06feb2019-03-05 10:52:46 +01001343 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001345}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001346
1347/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1348testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001349 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001350 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001351 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001352 f_l1_tune(L1CTL);
1353
1354 var GsmFrameNumber fn_last := 0;
1355 for (var integer i := 0; i < 1000; i := i+1) {
1356 var OCT1 ra := f_rnd_ra_cs();
1357 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1358 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001360 }
1361 fn_last := fn;
1362 }
1363 var integer rsl_chrqd := 0;
1364 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001365 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001366 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001367 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001368 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001369 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001370 repeat;
1371 }
1372 [] RSL_CCHAN.receive { repeat; }
1373 [] T.timeout { }
1374 }
1375 if (rsl_chrqd == 1000) {
1376 setverdict(pass);
1377 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001379 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001381}
1382
Harald Welte3453ab42019-05-24 21:19:58 +02001383private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1384 var charstring bts_str := "bts " & int2str(bts_nr);
1385 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1386}
1387
1388/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1389private template integer tr_rach_slots_per_interval := (90 .. 130);
1390
1391/* Expect 0 RACH load on an idle BTS that has just started up */
1392testcase TC_rach_load_idle_thresh0() runs on test_CT {
1393 var ASP_RSL_Unitdata rx_ud;
1394
1395 f_init_vty_bsc();
1396 /* send load indications even at 0% load */
1397 f_vty_load_ind_thresh(0);
1398 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1399 f_sleep(2.0);
1400
1401 f_init();
1402
1403 timer T := 5.0;
1404 T.start;
1405 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001406 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001407 setverdict(pass);
1408 repeat;
1409 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001410 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001411 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1412 repeat;
1413 }
1414 [] RSL_CCHAN.receive {
1415 repeat;
1416 }
1417 [] T.timeout { }
1418 }
1419
1420 f_vty_load_ind_thresh(10);
1421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1422}
1423
1424/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1425testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1426 var ASP_RSL_Unitdata rx_ud;
1427
1428 f_init_vty_bsc();
1429 f_init();
1430
1431 timer T := 5.0;
1432 T.start;
1433 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001434 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001435 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1436 repeat;
1437 }
1438 [] RSL_CCHAN.receive {
1439 repeat;
1440 }
1441 [] T.timeout {
1442 setverdict(pass);
1443 }
1444 }
1445
1446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1447}
1448
1449/* Expect 0 RACH load on an idle BTS that has just started up */
1450testcase TC_rach_load_count() runs on test_CT {
1451 var ASP_RSL_Unitdata rx_ud;
1452 var integer load_access_count := 0;
1453
1454 f_init_vty_bsc();
1455 /* send load indications even at 0% load */
1456 f_vty_load_ind_thresh(0);
1457 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1458 f_sleep(2.0);
1459 f_init();
1460
1461 f_init_l1ctl();
1462 f_sleep(1.0);
1463 f_l1_tune(L1CTL);
1464
1465 var GsmFrameNumber fn_last := 0;
1466 for (var integer i := 0; i < 1000; i := i+1) {
1467 var OCT1 ra := f_rnd_ra_cs();
1468 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1469 if (fn == fn_last) {
1470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1471 }
1472 fn_last := fn;
1473 }
1474
1475 timer T := 5.0;
1476 T.start;
1477 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001478 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001479 -> value rx_ud {
1480 var RSL_IE_Body ie;
1481 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1482 load_access_count := load_access_count + ie.rach_load.access_count;
1483 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1484 setverdict(fail, "Access count cannot be < Busy count");
1485 }
1486 repeat;
1487 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001488 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001489 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1490 repeat;
1491 }
1492 [] RSL_CCHAN.receive {
1493 repeat;
1494 }
1495 [] T.timeout { }
1496 }
1497 if (load_access_count == 1000) {
1498 setverdict(pass);
1499 } else {
1500 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1501 }
1502
1503 f_vty_load_ind_thresh(10);
1504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1505}
1506
Harald Welte54a2a2d2018-02-26 09:14:05 +01001507private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001508 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001509 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001510 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001511 f_sleep(0.5);
1512
1513 /* Transmit RACH request + wait for confirmation */
1514 var OCT1 ra := f_rnd_ra_cs();
1515 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1516
1517 /* Check for expected result */
1518 timer T := 1.5;
1519 T.start;
1520 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001521 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001522 setverdict(pass);
1523 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001524 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001526 }
1527 [] RSL_CCHAN.receive { repeat; }
1528 [not expect_pass] T.timeout {
1529 setverdict(pass);
1530 }
1531 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001533 }
1534 }
1535}
1536
1537/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1538testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001539 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001540 f_init_l1ctl();
1541 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001542 f_sleep(1.0);
1543
1544 /* default max-ta is 63 (full range of GSM timing advance */
1545
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001546 /* We allow early arrival up to 2 symbols */
1547 f_rach_toffs(-1*256, true);
1548 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001549 f_rach_toffs(-10*256, false);
1550
1551 /* 0 / 32 / 63 bits is legal / permitted */
1552 f_rach_toffs(0, true);
1553 f_rach_toffs(32*256, true);
1554 f_rach_toffs(63*256, true);
1555
1556 /* more than 63 bits is not legal / permitted */
1557 f_rach_toffs(64*256, false);
1558 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001560}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001561
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001562function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1563 var GsmFrameNumber fn;
1564 var RSL_Message rm;
1565
1566 f_l1_tune(L1CTL);
1567 RSL.clear;
1568
1569 /* Generate a random Handover Reference */
1570 var integer ho_ref := oct2int(f_rnd_octstring(1));
1571
1572 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1573 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1574 RSL_IE_Body:{ handover_ref := ho_ref }));
1575
1576 /* Activate a channel on the BTS side (no encryption) */
1577 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1578 act_type := t_RSL_IE_ActType_HO_SYNC);
1579
1580 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1581 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001582 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001583
1584 /* Send handover Access Burst */
1585 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1586
1587 /* TODO: test mismatching Handover Reference, and missing IE */
1588
1589 /* Wait for handover detection */
1590 timer T := 3.0;
1591 T.start;
1592 alt {
1593 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1594 log("Handover RACH has been detected: ", rm);
1595 setverdict(pass);
1596 }
1597 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1599 log2str("RSL_CHAN_RQD was not expected: ", rm));
1600 }
1601 [] RSL.receive { repeat; }
1602 [] T.timeout {
1603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1604 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1605 }
1606 }
1607
1608 /* Release the channel */
1609 f_rsl_chan_deact();
1610 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1611}
1612
1613/* Test handover RACH detection */
1614testcase TC_ho_rach() runs on test_CT {
1615 var ConnHdlrPars pars;
1616 var ConnHdlr vc_conn;
1617
1618 f_init();
1619
1620 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1621 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1622 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1623 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1624 vc_conn.done;
1625 }
1626
1627 /* TODO: do the above in parallel, rather than sequentially? */
1628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1629}
1630
Harald Welte93640c62018-02-25 16:59:33 +01001631/***********************************************************************
1632 * Measurement Processing / Reporting
1633 ***********************************************************************/
1634
Harald Welte70767382018-02-21 12:16:40 +01001635template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1636 spare := '0'B,
1637 lpd := 0,
1638 sapi := sapi,
1639 c_r := c_r,
1640 ea := true
1641}
1642
Harald Welted879bd92018-03-12 15:01:23 +01001643template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001644 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001645 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001646 len := 0, /* overwritten */
1647 m := false,
1648 el := 1,
1649 payload := pl
1650}
1651
1652/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1653altstep as_l1_sacch() runs on ConnHdlr {
1654 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001655 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001656 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001657 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 +01001658 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001659 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001660
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001661 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1662 g_pars.l1_pars.ms_power_level, false,
1663 g_pars.l1_pars.ms_actual_ta);
1664
1665 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1666 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1667
1668 log("Sending Measurement Report: ", l1h, l2);
1669 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001670 repeat;
1671 }
1672}
1673
1674altstep as_l1_dcch() runs on ConnHdlr {
1675 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001676 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001677 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1678 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001679 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1680 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001681 repeat;
1682 }
1683}
1684
1685type record MeasElem {
1686 uint6_t rxlev,
1687 uint3_t rxqual
1688}
1689
1690type record MeasElemFS {
1691 MeasElem full,
1692 MeasElem sub
1693}
1694
1695type record ConnL1Pars {
1696 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001697 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001698 MeasElemFS meas_ul,
1699 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001700 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001701 uint5_t ms_power_level,
1702 uint8_t ms_actual_ta
1703}
1704
1705/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1706private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1707 return 63 + (toffs256s/256);
1708}
1709
Harald Welted5684392018-03-10 18:22:04 +01001710private function f_max(integer a, integer b) return integer {
1711 if (a > b) {
1712 return a;
1713 } else {
1714 return b;
1715 }
1716}
1717
1718private function f_min(integer a, integer b) return integer {
1719 if (a < b) {
1720 return a;
1721 } else {
1722 return b;
1723 }
1724}
1725
1726/* compute negative tolerance val-tolerance, ensure >= min */
1727private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1728 val := val - tolerance;
1729 return f_max(val, min);
1730}
1731
1732/* compute positive tolerance val+tolerance, ensure <= max */
1733private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1734 val := val + tolerance;
1735 return f_min(val, max);
1736}
1737
1738/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1739private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1740return template integer {
1741 var template integer ret;
1742 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1743 return ret;
1744}
1745
1746
Harald Welte70767382018-02-21 12:16:40 +01001747/* build a template for matching measurement results against */
1748private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1749 var ConnL1Pars l1p := g_pars.l1_pars;
1750 var template RSL_IE_UplinkMeas ul_meas := {
1751 len := 3,
1752 rfu := '0'B,
1753 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001754 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001755 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001756 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001757 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001758 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1759 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001760 supp_meas_info := omit
1761 };
Harald Welte685d5982018-02-27 20:42:05 +01001762 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001763 ul_meas.len := (3+8);
1764 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001765 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001766 toa256_min := ?,
1767 toa256_max := ?,
1768 toa256_std_dev := ?
1769 }
Harald Welte685d5982018-02-27 20:42:05 +01001770 }
Harald Welte70767382018-02-21 12:16:40 +01001771 var template RSL_IE_BS_Power bs_power := {
1772 reserved := 0,
1773 epc := false,
1774 fpc := false,
1775 power_level := l1p.bs_power_level
1776 };
1777 var template RSL_IE_L1Info l1_info := {
1778 ms_power_lvl := l1p.ms_power_level,
1779 fpc := false,
1780 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001781 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001782 };
1783 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001784 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001785 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1786 ?, t_toffs);
1787}
1788
Philipp Maierdd841d32019-12-17 14:44:54 +01001789/* build a template for matching measurement results that do not contain any
1790 * MS related measurement (l1_info, l3_info and ms timing offset). */
1791private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1792 var ConnL1Pars l1p := g_pars.l1_pars;
1793 var template RSL_IE_UplinkMeas ul_meas := {
1794 len := 3,
1795 rfu := '0'B,
1796 dtx_d := l1p.dtx_enabled,
1797 rxlev_f_u := ?,
1798 reserved1 := '00'B,
1799 rxlev_s_u := ?,
1800 reserved2 := '00'B,
1801 rxq_f_u := ?,
1802 rxq_s_u := ?,
1803 supp_meas_info := omit
1804 };
1805 if (l1p.toa256_enabled) {
1806 ul_meas.len := (3+8);
1807 ul_meas.supp_meas_info := {
1808 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1809 toa256_min := ?,
1810 toa256_max := ?,
1811 toa256_std_dev := ?
1812 }
1813 }
1814 var template RSL_IE_BS_Power bs_power := {
1815 reserved := 0,
1816 epc := false,
1817 fpc := false,
1818 power_level := l1p.bs_power_level
1819 };
1820
1821 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1822}
1823
Harald Welte70767382018-02-21 12:16:40 +01001824/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001825altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001826 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001827 var boolean chan_est := false;
1828
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001829 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001830
1831 /* Receive osmocom specific measurement reports. This is the normal
1832 * case. Here we verify that the measurement reports we sent are
1833 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001834 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1835 /* increment counter of next to-be-expected meas rep */
1836 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1837 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001838 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001839
1840 /* The following two cases may only happen in the beginning
1841 * of the channel establishment phase. Once we have received
1842 * the "our" measurement report the first time, the channel
1843 * is established and empty or hardcoded TRXCON reports must
1844 * not occur anymore. */
1845 chan_est := true;
1846
1847 repeat;
1848 }
1849
1850 /* When the BTS has established the channel, the MS might need slightly
1851 * more time to establish the channel and actually start sending. The
1852 * result is then a measurement report that just lacks the measurement
1853 * information of the MS. This is normal and we tolerate this behavior. */
1854 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1855 /* increment counter of next to-be-expected meas rep */
1856 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1857 /* Re-start the timer expecting the next MEAS RES */
1858 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001859 repeat;
1860 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001861
1862 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1863 * measurements if the TTCN3 side does not supply measurement input in
1864 * time. In those cases TRXCON will either use a cached measurement
1865 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1866 * report the templates above will not match. We tolerate this
1867 * behavior, but only once. */
1868 [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 +01001869 /* increment counter of next to-be-expected meas rep */
1870 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1871 if (g_first_meas_res) {
1872 g_first_meas_res := false;
1873 repeat;
1874 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001876 }
Harald Welte70767382018-02-21 12:16:40 +01001877 }
1878 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001880 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001881 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001883 }
1884}
1885
Harald Weltee613f962018-04-18 22:38:16 +02001886private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1887 select (rsl_alg_id) {
1888 case (RSL_ALG_ID_A5_0) { return 0; }
1889 case (RSL_ALG_ID_A5_1) { return 1; }
1890 case (RSL_ALG_ID_A5_2) { return 2; }
1891 case (RSL_ALG_ID_A5_3) { return 3; }
1892 case (RSL_ALG_ID_A5_4) { return 4; }
1893 case (RSL_ALG_ID_A5_5) { return 5; }
1894 case (RSL_ALG_ID_A5_6) { return 6; }
1895 case (RSL_ALG_ID_A5_7) { return 7; }
1896 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1898 /* Make compiler happy by calling mtc.stop here. It is already
1899 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001900 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001901 }
1902 }
1903}
1904
1905private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1906 select (rsl_alg_id) {
1907 case (RSL_ALG_ID_A5_1) { return '000'B; }
1908 case (RSL_ALG_ID_A5_2) { return '001'B; }
1909 case (RSL_ALG_ID_A5_3) { return '010'B; }
1910 case (RSL_ALG_ID_A5_4) { return '011'B; }
1911 case (RSL_ALG_ID_A5_5) { return '100'B; }
1912 case (RSL_ALG_ID_A5_6) { return '101'B; }
1913 case (RSL_ALG_ID_A5_7) { return '110'B; }
1914 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1916 /* Make compiler happy by calling mtc.stop here. It is already
1917 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001918 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001919 }
1920 }
1921}
1922
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001923/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1924private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1925 var GsmFrameNumber fn;
1926 timer T := 8.0;
1927
1928 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1929 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1930
1931 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1932 /* Send the actual RACH */
1933 fn := f_L1CTL_RACH(L1CTL, ra);
1934
1935 T.start;
1936 alt {
1937 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1938 [] T.timeout {
1939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1940 }
1941 }
1942 T.stop
1943 return fn;
1944}
Harald Weltee613f962018-04-18 22:38:16 +02001945
Harald Welte70767382018-02-21 12:16:40 +01001946/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001947private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001948 var GsmFrameNumber fn;
1949 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001950 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001951 var integer ra := 23;
1952
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001953 /* Send RACH request and wait for ChanReq */
1954 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001955
1956 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001957 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001958
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001959 /* Craft channel description (with or without frequency hopping parameters) */
1960 if (ispresent(g_pars.maio_hsn)) {
1961 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1962 } else {
1963 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1964 }
1965
Harald Welte70767382018-02-21 12:16:40 +01001966 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001967 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001968 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1969
1970 /* receive IMM.ASS on MS side */
1971 var ImmediateAssignment ia_um;
1972 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001973
1974 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1975 if (ch_desc.h != ia_um.chan_desc.h) {
1976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1977 }
1978
Harald Welte70767382018-02-21 12:16:40 +01001979 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001980 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001981 /* enable encryption, if requested */
1982 if (encr_enable) {
1983 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1984 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1985 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001986
1987 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001988}
1989
1990/* establish DChan, verify existance + contents of measurement reports */
1991function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001992 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001993 RSL.clear;
1994
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001995 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001996 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07001997 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001998 }
Harald Welte70767382018-02-21 12:16:40 +01001999
2000 f_est_dchan();
2001
2002 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2003 * RSL measurement reports on Abis side */
2004 timer T := 8.0;
2005 T.start;
2006 alt {
2007 [] as_l1_sacch();
2008 [] as_meas_res();
2009 [] as_l1_dcch();
2010 [] L1CTL.receive { repeat; }
2011 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002012 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002013 * of any earlier errors, so if we reach this timeout, we're good */
2014 setverdict(pass);
2015 }
2016 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002018 }
2019 }
2020 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002021 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002022}
Harald Welte0472ab42018-03-12 15:02:26 +01002023
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002024/* Verify Tx power reduction and ramping up during BTS bring up */
2025function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
2026 var L1ctlDlMessage l1_dl;
2027 f_l1_tune(L1CTL);
2028 RSL.clear;
2029
2030 var integer initial_rx_lvl := -1;
2031 var integer last_rx_lvl := -1;
2032 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2033
2034 timer T := 2.0;
2035 alt {
2036 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2037 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2038 log("Received rx_level=", rx_lvl);
2039 if (initial_rx_lvl == -1) {
2040 initial_rx_lvl := rx_lvl;
2041 last_rx_lvl := rx_lvl;
2042
2043 /* Expect a somehow low value during first received messages */
2044 if (initial_rx_lvl >= max_rx_lvl / 2) {
2045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2046 log2str("Detected high initial tx power during ramp up: ",
2047 initial_rx_lvl , ", full power is", max_rx_lvl));
2048 }
2049 }
2050
2051 /* received Rx level bigger than maximum allowed power by CN */
2052 if (rx_lvl > max_rx_lvl) {
2053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2054 log2str("Detected Tx power higher than full power: ",
2055 rx_lvl , " > ", max_rx_lvl));
2056 }
2057
2058 /* Make sure it never decreases, since we are rumping up */
2059 if (last_rx_lvl > rx_lvl) {
2060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2061 log2str("Detected Tx power decrease during ramp up: ",
2062 last_rx_lvl , " -> ", rx_lvl));
2063 }
2064
2065 if (rx_lvl == max_rx_lvl and not T.running) {
2066 /* We reached the maximum power, start timer and receive
2067 /* a few more to make sure we don't surpass it */
2068 log("Reached full power, wating a bit more until success");
2069 T.start;
2070 }
2071
2072 last_rx_lvl := rx_lvl;
2073 repeat;
2074 }
2075 [] L1CTL.receive { repeat; }
2076 [] T.timeout { }
2077 }
2078
2079 /* We didn't increase tx power during ramp up */
2080 if (initial_rx_lvl < last_rx_lvl) {
2081 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2082 } else {
2083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2084 log2str("No Tx power increase during whole ramp up: ",
2085 initial_rx_lvl , " -> ", last_rx_lvl));
2086 }
2087
2088 setverdict(pass);
2089}
2090testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2091 var ConnHdlr vc_conn;
2092 var ConnHdlrPars pars;
2093 f_init();
2094 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2095 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2096 pcu_comp := false, trxc_comp := true);
2097 vc_conn.done;
2098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2099}
2100
Eric Wildae8f2622019-06-18 17:05:11 +02002101function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
2102 timer T := 8.0;
2103 T.start;
2104 var RSL_Message rsl;
2105 alt {
2106 [] as_l1_sacch();
2107 [] L1CTL.receive { repeat; }
2108 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2109 if (rsl.ies[3].body.bs_power.power_level == level) {
2110 setverdict(pass)
2111 } else {
2112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2113 }
2114 }
2115 [] T.timeout {
2116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2117 }
2118 }
2119}
2120
2121/* see if the rsl meas res contains our expeced bs power level
2122bs power set during assignment */
2123function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2124 f_l1_tune(L1CTL);
2125 RSL.clear;
2126
2127 if (mp_bts_trxc_port != -1) {
2128 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2129 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2130 }
2131
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002132 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002133 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2134 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2135
2136 f_est_dchan(more_ies :={valueof(pwr)});
2137
2138 f_check_meas_bs_power_level(pwr_var);
2139
2140 f_rsl_chan_deact();
2141 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2142}
2143
2144/* see if the rsl meas res contains our expeced bs power level
2145bs power set after assignment */
2146function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2147 f_l1_tune(L1CTL);
2148 RSL.clear;
2149
2150 if (mp_bts_trxc_port != -1) {
2151 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2152 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2153 }
2154
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002155 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002156 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2157
2158 f_est_dchan();
2159
2160 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2161
2162 f_check_meas_bs_power_level(pwr_var);
2163
2164 f_rsl_chan_deact();
2165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2166}
2167
2168testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2169 var ConnHdlr vc_conn;
2170 var ConnHdlrPars pars;
2171 f_init();
2172 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2173 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2174 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2175 pcu_comp := false, trxc_comp := true);
2176 vc_conn.done;
2177 }
2178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2179}
2180
2181testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2182 var ConnHdlr vc_conn;
2183 var ConnHdlrPars pars;
2184 f_init();
2185 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2186 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2187 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2188 pcu_comp := false, trxc_comp := true);
2189 vc_conn.done;
2190 }
2191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2192}
2193
Eric Wild61edb7e2019-06-03 12:38:31 +02002194/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2195second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2196These power levels are valid for all bands and require no special handling */
2197function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2198 var uint5_t pwr_var := 7;
2199 var L1ctlDlMessage l1_dl;
2200
2201 f_trxc_fake_rssi(rxlev2dbm(10));
2202 f_l1_tune(L1CTL);
2203 RSL.clear;
2204
2205 var RSL_IE_List addl_ies;
2206 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2207
2208 addl_ies := {
2209 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2210 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2211 };
2212
2213 /* establish with power parameters */
2214 f_est_dchan(more_ies := addl_ies);
2215
2216 /* set a high value to ensure L1 power control level increases */
2217 f_trxc_fake_rssi(rxlev2dbm(20));
2218
2219 timer T2 := 6.0;
2220 T2.start;
2221 alt {
2222 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002223 /* 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 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002226 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002227 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002228 T2.stop;
2229 }
2230 [] L1CTL.receive { repeat; }
2231 [] T2.timeout {
2232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2233 "Power Level in L1 header has not increased sufficiently");
2234 }
2235 }
2236
2237 /* set a low value to ensure L1 power control level decreases */
2238 f_trxc_fake_rssi(rxlev2dbm(0));
2239
2240 timer T4 := 6.0;
2241 T4.start;
2242 alt {
2243 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002244 /* Update sent MS power to follow what BTS requests */
2245 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2246 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002247 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002248 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002249 T4.stop;
2250 setverdict(pass, "Power level in L1 decreased/increased as expected");
2251 }
2252 [] L1CTL.receive { repeat; }
2253 [] T4.timeout {
2254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2255 "Power Level in L1 header has not decreased sufficiently");
2256 }
2257 }
2258
2259 f_rsl_chan_deact();
2260 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2261
2262}
2263
2264/* check that we do not exceed the max power */
2265function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2266 var uint5_t pwr_var := 7;
2267 var L1ctlDlMessage l1_dl;
2268
2269 /* set a low value to ensure power increases */
2270 f_trxc_fake_rssi(rxlev2dbm(10));
2271 f_l1_tune(L1CTL);
2272 RSL.clear;
2273
2274 var RSL_IE_List addl_ies;
2275 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2276
2277 addl_ies := {
2278 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2279 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2280 };
2281
2282 /* establish with power parameters */
2283 f_est_dchan(more_ies := addl_ies);
2284
2285 timer T1 := 10.0;
2286 T1.start;
2287 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002288 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2289 /* Update sent MS power to follow what BTS requests */
2290 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2291 repeat;
2292 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002293 [] L1CTL.receive { repeat; }
2294 [] T1.timeout {
2295 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2296 setverdict(fail, "Power level in L1 header should not have changed");
2297 }
2298 }
2299 }
2300
2301 f_rsl_chan_deact();
2302 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2303
2304}
2305
2306/* see if we reach the band max power */
2307function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2308 var L1ctlDlMessage l1_dl;
2309 var uint5_t pwr_var := 15;
2310 var uint5_t pwr_max_var := f_get_max_power_from_band();
2311
2312 /* set a low value to ensure power increases */
2313 f_trxc_fake_rssi(rxlev2dbm(10));
2314 f_l1_tune(L1CTL);
2315 RSL.clear;
2316
2317 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2318 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2319
2320 /* establish with fixed power level */
2321 f_est_dchan(more_ies :={valueof(pwr)});
2322
2323 /* check our initial power level */
2324 f_wait_for_l1_power_level(pwr_var);
2325
2326 /* update power param to enable power loop
2327 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2328 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2329
2330 /* wait, then check that our power level was reduced */
2331 timer T1 := 10.0;
2332 T1.start;
2333 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002334 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2335 /* Update sent MS power to follow what BTS requests */
2336 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2337 repeat;
2338 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002339 [] L1CTL.receive { repeat; }
2340 [] T1.timeout {
2341 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2342 if( f_power_level_is_highest_dbm(rcv) ){
2343 setverdict(pass, "Power level in L1 header reduced as expected");
2344 } else {
2345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2346 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2347 }
2348 }
2349 }
2350
2351 f_rsl_chan_deact();
2352 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2353
2354}
2355
2356/* see if we reach the band min power */
2357function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2358 var L1ctlDlMessage l1_dl;
2359
2360 /* set a high value to ensure power decreases */
2361 f_trxc_fake_rssi(rxlev2dbm(50));
2362 f_l1_tune(L1CTL);
2363 RSL.clear;
2364
2365 var uint5_t pwr_var := 5;
2366 var uint5_t pwr_target_val := 15;
2367
2368 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2369 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2370
2371 /* establish with fixed power level */
2372 f_est_dchan(more_ies :={valueof(pwr)});
2373
2374 /* check our initial power level */
2375 f_wait_for_l1_power_level(pwr_var);
2376
2377 /* update power param to enable power loop
2378 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002379 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002380
2381 /* wait, then check that our power level was increased */
2382 timer T1 := 10.0;
2383 T1.start;
2384 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002385 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2386 /* Update sent MS power to follow what BTS requests */
2387 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2388 repeat;
2389 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002390 [] L1CTL.receive { repeat; }
2391 [] T1.timeout {
2392 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2393 setverdict(pass, "Power level in L1 header increased to lowest power value");
2394 } else {
2395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2396 "Power level in L1 header NOT increased to lowest power value");
2397 }
2398 }
2399 }
2400
2401 f_rsl_chan_deact();
2402 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2403
2404}
2405
Eric Wild095024b2019-06-17 15:08:57 +02002406/* see if we change the power level without receiving power parameters, which should not happen
2407rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002408function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2409 var L1ctlDlMessage l1_dl;
2410
2411 /* set a high value to ensure power decreases */
2412 f_trxc_fake_rssi(rxlev2dbm(50));
2413 f_l1_tune(L1CTL);
2414 RSL.clear;
2415
2416 var uint5_t pwr_var := 5;
2417
2418 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2419 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2420
2421 /* establish with fixed power level */
2422 f_est_dchan(more_ies :={valueof(pwr)});
2423
2424 /* check our initial power level */
2425 f_wait_for_l1_power_level(pwr_var);
2426
2427 /* wait, then check that our power level did not change */
2428 timer T1 := 10.0;
2429 T1.start;
2430 alt {
2431 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2432 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2434 "BS power control should not be active unless we receive a power parameters IE!");
2435 }
2436 repeat;
2437 }
2438 [] L1CTL.receive { repeat; }
2439 [] T1.timeout { setverdict(pass); }
2440 }
2441
2442 f_rsl_chan_deact();
2443 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2444
2445}
2446
Eric Wild095024b2019-06-17 15:08:57 +02002447/* see if we change the power level without receiving power parameters, which should not happen
2448ms power control WITHOUT power parameters */
2449function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2450 var L1ctlDlMessage l1_dl;
2451
2452 /* set a high value to ensure power decreases */
2453 f_trxc_fake_rssi(rxlev2dbm(50));
2454 f_l1_tune(L1CTL);
2455 RSL.clear;
2456
2457 var uint5_t pwr_var := 5;
2458
2459 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2460 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2461
2462 /* establish with fixed power level */
2463 f_est_dchan(more_ies :={valueof(pwr)});
2464
2465 /* check our initial power level */
2466 f_wait_for_l1_power_level(pwr_var);
2467
2468 /* pwr control without power params IE, should NOT activate MS power control*/
2469 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2470
2471 /* wait, then check that our power level did not change */
2472 timer T1 := 10.0;
2473 T1.start;
2474 alt {
2475 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2476 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2478 "BS power control should not be active unless we receive a power parameters IE!");
2479 }
2480 repeat;
2481 }
2482 [] L1CTL.receive { repeat; }
2483 [] T1.timeout { setverdict(pass); }
2484 }
2485
2486 f_rsl_chan_deact();
2487 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2488
2489}
2490
Eric Wild61edb7e2019-06-03 12:38:31 +02002491function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2492 var L1ctlDlMessage l1_dl;
2493 timer T0 := 10.0;
2494 T0.start;
2495 alt {
2496 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2497 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2499 "Power level in L1 header != signaled (RSL) power level.");
2500 }
2501 }
2502 [] L1CTL.receive { repeat; }
2503 [] T0.timeout {
2504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2505 "Timeout waiting for initial power level");
2506 }
2507 }
2508 T0.stop;
2509}
2510
2511private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2512 var IntegerRecord min_dbm_level;
2513 var IntegerRecord max_dbm_level;
2514 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2515
2516 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2517 if (min_dbm_level[i] == level) {
2518 return true;
2519 }
2520 }
2521 return false;
2522}
2523
2524private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2525 var IntegerRecord min_dbm_level;
2526 var IntegerRecord max_dbm_level;
2527 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2528
2529 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2530 if (max_dbm_level[i] == level) {
2531 return true;
2532 }
2533 }
2534 return false;
2535}
2536
2537private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2538 var IntegerRecord min_dbm_level;
2539 var IntegerRecord max_dbm_level;
2540 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2541 return max_dbm_level[0];
2542}
2543
2544type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2545template charstring BtsBand_allGSM:= pattern "GSM???";
2546private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2547 // 45.005 4.1.1
2548 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2549 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2550 2, 1, 0};
2551 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2552 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2553 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2554 var IntegerRecord rv;
2555
2556 select(band){
2557 case (BtsBand_allGSM){
2558 rv := gsm_power;
2559 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2560 max_dbm_level := {2, 1, 0};
2561 }
2562 case("DCS1800"){
2563 rv := dcs_power;
2564 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2565 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2566 }
2567 case("PCS1900"){
2568 rv := pcs_power;
2569 min_dbm_level := {15};
2570 max_dbm_level := {30};
2571 }
2572 }
2573
2574 return rv;
2575}
2576
2577private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2578 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2579}
2580
2581testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2582 var ConnHdlr vc_conn;
2583 var ConnHdlrPars pars;
2584 f_init();
2585 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2586 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2587 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2588 pars.bts0_band := f_vty_get_bts0_band();
2589 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2590 vc_conn.done;
2591 }
2592 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2594}
2595
2596testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2597 var ConnHdlr vc_conn;
2598 var ConnHdlrPars pars;
2599 f_init();
2600 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2601 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2602 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2603 pars.bts0_band := f_vty_get_bts0_band();
2604 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2605 vc_conn.done;
2606 }
2607 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2609}
2610
2611testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2612 var ConnHdlr vc_conn;
2613 var ConnHdlrPars pars;
2614 f_init();
2615 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2616 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2617 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2618 pars.bts0_band := f_vty_get_bts0_band();
2619 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2620 vc_conn.done;
2621 }
2622 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2624}
2625
2626testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2627 var ConnHdlr vc_conn;
2628 var ConnHdlrPars pars;
2629 f_init();
2630 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2631 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2632 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2633 pars.bts0_band := f_vty_get_bts0_band();
2634 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2635 vc_conn.done;
2636 }
2637 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2639}
2640
Eric Wild280ccb82019-06-17 11:11:52 +02002641testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2642 var ConnHdlr vc_conn;
2643 var ConnHdlrPars pars;
2644 f_init();
2645 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2646 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2647 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2648 pars.bts0_band := f_vty_get_bts0_band();
2649 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2650 vc_conn.done;
2651 }
2652 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2654}
2655
Eric Wild095024b2019-06-17 15:08:57 +02002656testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2657 var ConnHdlr vc_conn;
2658 var ConnHdlrPars pars;
2659 f_init();
2660 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2661 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2662 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2663 pars.bts0_band := f_vty_get_bts0_band();
2664 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2665 vc_conn.done;
2666 }
2667 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2669}
2670
Harald Welte70767382018-02-21 12:16:40 +01002671testcase TC_meas_res_sign_tchf() runs on test_CT {
2672 var ConnHdlr vc_conn;
2673 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002674 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002675 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2676 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002677 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2678 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002679 vc_conn.done;
2680 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002682}
2683testcase TC_meas_res_sign_tchh() runs on test_CT {
2684 var ConnHdlr vc_conn;
2685 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002686 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002687 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2688 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002689 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2690 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002691 vc_conn.done;
2692 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002694}
2695testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2696 var ConnHdlr vc_conn;
2697 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002698 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002699 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2700 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002701 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2702 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002703 vc_conn.done;
2704 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002706}
2707testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2708 var ConnHdlr vc_conn;
2709 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002710 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002711 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2712 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002713 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2714 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002715 vc_conn.done;
2716 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002718}
Harald Welte685d5982018-02-27 20:42:05 +01002719testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2720 var ConnHdlr vc_conn;
2721 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002722 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002723 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2724 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2725 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2726 pars.l1_pars.toa256_enabled := true;
2727 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2728 vc_conn.done;
2729 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002731}
2732
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002733/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2734 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2735function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2736 var L1ctlDlMessage l1_dl;
2737 var RSL_IE_MS_Power ms_power;
2738 var RSL_Message rsl;
2739 var uint5_t power_level := 0;
2740
2741 f_l1_tune(L1CTL);
2742 RSL.clear;
2743
2744 f_est_dchan();
2745
2746 ms_power.reserved := 0;
2747 ms_power.fpc_epc := false;
2748
2749 /* Send the first power control command. This will disable any BTS/TRX
2750 * internal power control and switch the MS (which is not in scope of
2751 * this test) to a constant power level. We start with a power level
2752 * of 0 */
2753 ms_power.power_level := power_level;
2754 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2755 RSL.send(rsl);
2756
2757 alt {
2758
2759 /* Pick all SACCH blocks for checking */
2760 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2761
2762 /* The first byte of the L1 header contains the power level.
2763 * The reserved bits and the fpc bit is set to 0, so we may
2764 * compare directly. */
2765 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2766 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2767 }
2768
2769 /* Signal a new power level via RSL for the next turn. */
2770 if (power_level < 31) {
2771 power_level := power_level + 1;
2772 ms_power.power_level := power_level;
2773 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2774 RSL.send(rsl);
2775 repeat;
2776 }
2777
2778 }
2779
2780 /* Ignore all other blocks */
2781 [] L1CTL.receive { repeat; }
2782
2783 }
2784
2785 f_rsl_chan_deact();
2786 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2787
2788 setverdict(pass);
2789}
2790
2791testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2792 var ConnHdlr vc_conn;
2793 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002794 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002795
2796 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2797 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2798 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2799 vc_conn.done;
2800 }
2801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2802}
Harald Welte70767382018-02-21 12:16:40 +01002803
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002804/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002805TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2806function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2807 var L1ctlDlMessage l1_dl;
2808 var uint5_t ta_to_test := 16;
2809
2810
2811 f_l1_tune(L1CTL);
2812 RSL.clear;
2813
2814 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002815 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002816
2817 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2818
2819
2820 alt {
2821
2822 /* Pick all SACCH blocks for checking */
2823 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2824
2825 /* The second byte of the L1 header contains the TA. */
2826 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2827 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2828 }
2829
2830 }
2831
2832 /* Ignore all other blocks */
2833 [] L1CTL.receive { repeat; }
2834
2835 }
2836
2837 f_rsl_chan_deact();
2838 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2839
2840 setverdict(pass);
2841}
2842
2843testcase TC_rsl_chan_initial_ta() runs on test_CT {
2844 var ConnHdlr vc_conn;
2845 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002846 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002847 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002848 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2849 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002850 vc_conn.done;
2851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2852}
2853
Eric Wilde57e1a62019-05-28 13:30:55 +02002854/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2855function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2856 var L1ctlDlMessage l1_dl;
2857 var uint5_t ms_power_level := 7;
2858
2859 var RSL_IE_MS_Power ms_power;
2860 ms_power.reserved := 0;
2861 ms_power.fpc_epc := false;
2862 ms_power.power_level := ms_power_level;
2863
2864 f_l1_tune(L1CTL);
2865 RSL.clear;
2866
2867 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2868
2869 timer T := 1.0;
2870 T.start;
2871 alt {
2872 /* Pick all SACCH blocks for checking */
2873 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2874 /* The first byte of the L1 header contains the power level.. */
2875 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2876 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2877 }
2878 }
2879 /* Ignore all other blocks */
2880 [] L1CTL.receive { repeat; }
2881 [] T.timeout {
2882 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2883 }
2884 }
2885
2886 f_rsl_chan_deact();
2887 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2888 setverdict(pass);
2889}
2890
2891testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2892 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2893 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2894}
2895
Harald Welte0472ab42018-03-12 15:02:26 +01002896/* 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 +01002897private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002898 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002899 RSL.clear;
2900
2901 f_est_dchan();
2902 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002903 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002904
2905 timer T := 40.0;
2906 T.start;
2907 alt {
2908 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2909 setverdict(pass)
2910 }
2911 [] RSL.receive { repeat };
2912 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002914 }
2915 }
2916 f_rsl_chan_deact();
2917}
2918testcase TC_conn_fail_crit() runs on test_CT {
2919 var ConnHdlr vc_conn;
2920 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002921 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002922 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2923 pars.t_guard := 60.0;
2924 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2925 vc_conn.done;
2926}
2927
Harald Welte93640c62018-02-25 16:59:33 +01002928/***********************************************************************
2929 * Paging
2930 ***********************************************************************/
2931
Harald Welte68e495b2018-02-25 00:05:57 +01002932function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2933 if (tmsi == 'FFFFFFFF'O) {
2934 return true;
2935 } else {
2936 return false;
2937 }
2938}
Harald Welte70767382018-02-21 12:16:40 +01002939
Philipp Maier82cb0b12018-08-31 14:41:39 +02002940type record allowedFn { integer frame_nr }
2941template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2942template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2943template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2944template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2945template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2946template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2947template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2948template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2949function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2950{
2951 var integer frame_nr_51;
2952 frame_nr_51 := frame_nr mod 51
2953
2954 var allowedFn fn_check;
2955 fn_check.frame_nr := frame_nr_51;
2956
2957 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002959 return;
2960 }
2961
2962 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2963 return;
2964 }
2965 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2966 return;
2967 }
2968 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2969 return;
2970 }
2971 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2972 return;
2973 }
2974 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2975 return;
2976 }
2977 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2978 return;
2979 }
2980 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2981 return;
2982 }
2983 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2984 return;
2985 }
2986
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002988 return;
2989}
2990
2991altstep 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 +01002992runs on test_CT {
2993 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002994 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002995 repeat;
2996 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002997 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002998 var octetstring without_plen :=
2999 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3000 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003001
3002 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3003
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003004 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3005 /* Ignore empty RR Paging Request (PCH filling) messages.
3006 * TODO: does it make sense to count them? */
3007 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003008 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3009 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003010 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003011 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3012 }
3013 } else if (match(rr, tr_PAGING_REQ2)) {
3014 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3015 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3016 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3017 }
3018 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3019 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3020 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003021 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003022 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3023 }
3024 } else if (match(rr, tr_PAGING_REQ3)) {
3025 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3026 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3027 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3028 }
3029 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3030 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3031 }
3032 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3033 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3034 }
3035 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3036 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3037 }
3038 }
3039 repeat;
3040 }
3041}
3042
3043type record PagingTestCfg {
3044 boolean combined_ccch,
3045 integer bs_ag_blks_res,
3046 float load_factor,
3047 boolean exp_load_ind,
3048 boolean exp_overload,
3049 boolean use_tmsi
3050}
3051
3052type record PagingTestState {
3053 integer num_paging_sent,
3054 integer num_paging_rcv_msgs,
3055 integer num_paging_rcv_ids,
3056 integer num_overload
3057}
3058
Harald Welte68e495b2018-02-25 00:05:57 +01003059/* Helper function for paging related testing */
3060private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003061 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003062 f_init_l1ctl();
3063 f_l1_tune(L1CTL);
3064
3065 var PagingTestState st := {
3066 num_paging_sent := 0,
3067 num_paging_rcv_msgs := 0,
3068 num_paging_rcv_ids := 0,
3069 num_overload := 0
3070 };
3071
3072 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3073 var float max_pch_imsi_per_sec;
3074 if (cfg.use_tmsi) {
3075 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3076 } else {
3077 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3078 }
3079 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3080 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003081 var float time_total := 20.0;
3082 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3083 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003084
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003085 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3086 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003087
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003088 timer T_itv := 0.0;
3089 T_itv.start;
3090 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003091 alt {
3092 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003093 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003094 st.num_overload := st.num_overload + 1;
3095 repeat;
3096 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003097 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003099 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003100 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003101 log("Rx LOAD_IND");
3102 /* FIXME: analyze/verify interval + contents */
3103 repeat;
3104 }
3105 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003106 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003107 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003108 [] T_itv.timeout {
3109 /* Send paging cmds based on elapsed time */
3110 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3111 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003112 var MobileIdentityV mi;
3113
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003114 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003115 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003116 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003117 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003118 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003119 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003120
3121 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003122 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, st.num_paging_sent mod 4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003123
3124 st.num_paging_sent := st.num_paging_sent + 1;
3125 }
3126 if (st.num_paging_sent < pkt_total) {
3127 /* Wait for interval to next PAGING COMMAND */
3128 var float time_now := T_total.read;
3129 var float next_sched := int2float(st.num_paging_sent)*interval;
3130 if (next_sched > time_now) {
3131 T_itv.start(next_sched - time_now);
3132 } else {
3133 T_itv.start(0.0);
3134 }
3135 } else {
3136 /* We are done, no need to keep counting */
3137 T_total.stop;
3138 }
3139 }
3140 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003141 }
3142 }
3143
3144 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3145 timer T_wait := 18.0;
3146 T_wait.start;
3147 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003148 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003149 [] L1CTL.receive { repeat; }
3150 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003151 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3152 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003153 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003155 }
Harald Welte68e495b2018-02-25 00:05:57 +01003156 }
3157
3158 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3159 " rcvd_ids=", st.num_paging_rcv_ids);
3160 return st;
3161}
3162
3163/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3164 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3165 * - that CCCH LOAD IND (PCH) are being generated
3166 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3167testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003168 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003169 var PagingTestCfg cfg := {
3170 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003171 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003172 load_factor := 0.8,
3173 exp_load_ind := true,
3174 exp_overload := false,
3175 use_tmsi := false
3176 };
3177 var PagingTestState st := f_TC_paging(cfg);
3178 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3180 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003181 } else {
3182 setverdict(pass);
3183 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003185}
3186
3187/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3188 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3189 * - that CCCH LOAD IND (PCH) are being generated
3190 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3191testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003192 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003193 var PagingTestCfg cfg := {
3194 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003195 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003196 load_factor := 0.8,
3197 exp_load_ind := true,
3198 exp_overload := false,
3199 use_tmsi := true
3200 };
3201 var PagingTestState st := f_TC_paging(cfg);
3202 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003203 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3204 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003205 } else {
3206 setverdict(pass);
3207 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003209}
3210
3211/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3212 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3213 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3214 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3215testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003216 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003217 var PagingTestCfg cfg := {
3218 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003219 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003220 load_factor := 2.0,
3221 exp_load_ind := true,
3222 exp_overload := true,
3223 use_tmsi := false
3224 };
3225 var PagingTestState st := f_TC_paging(cfg);
3226 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3227 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003228 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003229 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003230 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 +01003231 } else {
3232 setverdict(pass);
3233 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003235}
3236
3237/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3238 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3239 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3240 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3241testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003242 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003243 var PagingTestCfg cfg := {
3244 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003245 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003246 load_factor := 2.0,
3247 exp_load_ind := true,
3248 exp_overload := true,
3249 use_tmsi := true
3250 };
3251 var PagingTestState st := f_TC_paging(cfg);
3252 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3253 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003254 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003255 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003256 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 +01003257 } else {
3258 setverdict(pass);
3259 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003261}
3262
3263
Harald Welte93640c62018-02-25 16:59:33 +01003264/***********************************************************************
3265 * Immediate Assignment / AGCH
3266 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003267private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003268 len := 0,
3269 ma := ''B
3270}
Harald Welte93640c62018-02-25 16:59:33 +01003271
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003272template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
Vadim Yanitskiye9f68be2020-05-27 02:08:35 +07003273 uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003274 chan_nr := chan_nr,
3275 tsc := tsc,
3276 h := false,
3277 arfcn := arfcn,
3278 maio_hsn := omit
3279}
3280
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003281template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3282 template (value) MaioHsn maio_hsn) := {
3283 chan_nr := chan_nr,
3284 tsc := tsc,
3285 h := true,
3286 arfcn := omit,
3287 maio_hsn := maio_hsn
3288}
3289
Harald Weltee8d750e2018-06-10 21:41:35 +02003290private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3291 return int2str(num_tx) & " sent, "
3292 & int2str(num_rx) & " received, "
3293 & int2str(num_del) & " deleted";
3294}
3295
3296private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3297 var L1ctlDlMessage l1_dl;
3298 timer T := 10.0;
3299 var integer num_tx := 0;
3300 var integer num_rx := 0;
3301 var integer num_del := 0;
3302 var charstring res_str;
3303 var float rx_ratio;
3304
Harald Welte10474062019-05-30 16:48:17 +02003305 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003306 f_init_l1ctl();
3307 f_l1_tune(L1CTL);
3308
3309 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003310 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003311 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3312 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003313 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003314 num_tx := num_tx+1;
3315 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003316 }
3317 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003318 T.start;
3319 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003320 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003321 num_del := num_del+1;
3322 repeat;
3323 }
3324 [] RSL_CCHAN.receive {
3325 repeat;
3326 }
3327 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3328 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3329 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3330 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3331 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003332 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003333 } else {
3334 num_rx := num_rx+1;
3335 }
3336 repeat;
3337 }
3338 [] L1CTL.receive { repeat; }
3339 [] T.timeout { }
3340 }
3341 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3342 log("AGCH test: " & res_str);
3343 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003345 }
3346 rx_ratio := int2float(num_rx) / int2float(num_tx);
3347 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003348 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 +02003349 } else {
3350 setverdict(pass);
3351 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003353}
3354
Harald Weltee8d750e2018-06-10 21:41:35 +02003355/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3356testcase TC_imm_ass_1000_20ms() runs on test_CT {
3357 f_TC_imm_ass(1000, 0.02, 0.25);
3358}
3359
3360/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3361testcase TC_imm_ass_200_0ms() runs on test_CT {
3362 f_TC_imm_ass(200, 0.0, 0.05);
3363}
3364
3365/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3366testcase TC_imm_ass_200_76ms() runs on test_CT {
3367 f_TC_imm_ass(150, 0.076, 1.00);
3368}
3369
3370
3371
Harald Welte48494ca2018-02-25 16:59:50 +01003372/***********************************************************************
3373 * BCCH
3374 ***********************************************************************/
3375
3376/* tuple of Frame Number + decoded SI */
3377type record SystemInformationFn {
3378 GsmFrameNumber frame_number,
3379 SystemInformation si
3380}
3381
3382/* an arbitrary-length vector of decoded SI + gsmtap header */
3383type record of SystemInformationFn SystemInformationVector;
3384
3385/* an array of SI-vectors indexed by TC value */
3386type SystemInformationVector SystemInformationVectorPerTc[8];
3387
3388/* determine if a given SI vector contains given SI type at least once */
3389function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3390 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3391 var integer fn_mod51 := arr[i].frame_number mod 51;
3392 if (not bcch_ext and fn_mod51 == 2 or
3393 bcch_ext and fn_mod51 == 6) {
3394 if (arr[i].si.header.message_type == key) {
3395 return true;
3396 }
3397 }
3398 }
3399 return false;
3400}
3401
3402/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3403function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3404 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003406 }
3407}
3408
3409/* check if a given SI vector contains given SI type at least once on any TC */
3410function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3411 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3412 if (f_si_vecslot_contains(arr[tc], key) or
3413 f_si_vecslot_contains(arr[tc], key, true)) {
3414 return true;
3415 }
3416 }
3417 return false;
3418}
3419
3420/* determine if a given SI vector contains given SI type at least N of M times */
3421function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3422 var integer count := 0;
3423 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003425 }
3426 for (var integer i:= 0; i < m; i := i + 1) {
3427 var integer fn_mod51 := arr[i].frame_number mod 51;
3428 if (not bcch_ext and fn_mod51 == 2 or
3429 bcch_ext and fn_mod51 == 6) {
3430 if (arr[i].si.header.message_type == key) {
3431 count := count + 1;
3432 }
3433 }
3434 }
3435 if (count >= n) {
3436 return true;
3437 } else {
3438 return false;
3439 }
3440}
3441
3442/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3443function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3444 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003446 }
3447}
3448
3449/* determine if a given SI vector contains given SI type at least once */
3450function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3451 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3452 var integer fn_mod51 := arr[i].frame_number mod 51;
3453 if (not bcch_ext and fn_mod51 == 2 or
3454 bcch_ext and fn_mod51 == 6) {
3455 if (arr[i].si.header.message_type != key) {
3456 return false;
3457 }
3458 }
3459 }
3460 return true;
3461}
3462
3463/* ensure a given TC slot of the SI vector contains only given SI type */
3464function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3465 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003467 }
3468}
3469
3470/* SI configuration of cell, against which we validate actual SI messages */
3471type set SystemInformationConfig {
3472 boolean bcch_extended,
3473 boolean si1_present,
3474 boolean si2bis_present,
3475 boolean si2ter_present,
3476 boolean si2quater_present,
3477 boolean si7_present,
3478 boolean si8_present,
3479 boolean si9_present,
3480 boolean si13_present,
3481 boolean si13alt_present,
3482 boolean si15_present,
3483 boolean si16_present,
3484 boolean si17_present,
3485 boolean si2n_present,
3486 boolean si21_present,
3487 boolean si22_present
3488}
3489
3490/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3491function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3492 var integer i;
3493 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3494 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003496 }
3497 }
3498 if (cfg.si1_present) {
3499 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3500 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3501 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3502 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3503 /* make sure *ALL* contain SI1 */
3504 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3505 }
3506 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3507 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3508 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3509 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3510 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3511 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3512
3513 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3514 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3515 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3516 * consecutive occurrences of TC = 4. */
3517 if (cfg.si2bis_present and not cfg.si2ter_present) {
3518 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3519 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3520 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3521 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3522 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3523 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3524 }
3525
3526 if (cfg.si7_present or cfg.si8_present) {
3527 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3528 * if System Information type 4 does not contain all information needed for cell
3529 * selection and reselection. */
3530 if (not cfg.bcch_extended) {
3531 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3532 }
3533 if (cfg.si7_present) {
3534 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3535 }
3536 if (cfg.si8_present) {
3537 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3538 }
3539 }
3540
3541 if (cfg.si2quater_present) {
3542 /* iii) System information type 2 quater is sent if needed, as determined by the system
3543 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3544 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3545 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3546 * within any of 4 consecutive occurrences of TC = 5. */
3547 if (not (cfg.bcch_extended)) {
3548 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3549 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3550 } else {
3551 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3552 }
3553 } else {
3554 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3555 }
3556 }
3557 if (cfg.si9_present) {
3558 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3559 * in system information type 3 as defined in 3GPP TS 44.018. */
3560 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3561 }
3562 if (cfg.si13_present) {
3563 /* vii) System Information type 13 is only related to the GPRS service. System Information
3564 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3565 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3566 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3567 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3568 * within any of 4 consecutive occurrences of TC=4. */
3569 if (not cfg.bcch_extended) {
3570 log("not-bccch-extended");
3571 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3572 } else {
3573 log("bccch-extended");
3574 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3575 }
3576 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003578 }
3579 }
3580 if (cfg.si16_present or cfg.si17_present) {
3581 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3582 * should not be sent in a cell where network sharing is used (see rule xv). */
3583 if (cfg.si22_present) {
3584 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3585 }
3586 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003588 }
3589 if (not cfg.bcch_extended) {
3590 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3591 }
3592 if (cfg.si16_present) {
3593 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3594 }
3595 if (cfg.si17_present) {
3596 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3597 }
3598 }
3599
3600 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3601 * broadcast information. The frequency with which they are sent is determined by the
3602 * system operator. System Information type 9 identifies the scheduling of System
3603 * Information type 18 and 20 messages. */
3604
3605 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3606 * Information Type 19 is present, then its scheduling shall be indicated in System
3607 * Information Type 9. */
3608
3609 if (cfg.si15_present) {
3610 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3611 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3612 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3613 * 4 consecutive occurrences of TC = 1. */
3614 if (not cfg.bcch_extended) {
3615 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3616 } else {
3617 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3618 }
3619 }
3620 if (cfg.si13alt_present) {
3621 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3622 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3623 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3624 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3625 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3626 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3627 * of TC = 4. */
3628 if (cfg.si13_present) {
3629 testcase.stop("Error: Cannot have SI13alt and SI13");
3630 }
3631 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003633 }
3634 if (not cfg.bcch_extended) {
3635 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3636 } else {
3637 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3638 }
3639 }
3640 if (cfg.si2n_present) {
3641 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3642 * as determined by the system operator. In the case that the message is sent on the
3643 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3644 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3645 * consecutive occurrences of TC = 4. */
3646 if (not cfg.bcch_extended) {
3647 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3648 } else {
3649 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3650 }
3651 }
3652 if (cfg.si21_present) {
3653 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3654 * determined by the system operator. If Extended Access Barring is in use in the cell
3655 * then this message is sent at least once within any of 4 consecutive occurrences of
3656 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3657 * cell then this message shall only be sent on BCCH Ext. */
3658 if (not cfg.bcch_extended) {
3659 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3660 } else {
3661 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3662 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003664 }
3665 }
3666 }
3667 if (cfg.si22_present) {
3668 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3669 * should not be sent in a cell where SoLSA is used (see rule viii). System
3670 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3671 * =2 and TC=6. */
3672 if (cfg.si16_present or cfg.si17_present) {
3673 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3674 }
3675 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3676 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003678 }
3679 if (not cfg.bcch_extended) {
3680 testcase.stop("Error: SI22 requires BCCH Extd!");
3681 } else {
3682 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3683 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3684 }
3685 }
3686}
3687
3688/* sample Systme Information for specified duration via L1CTL */
3689function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3690 timer T := duration;
3691 var SystemInformationVectorPerTc si_per_tc;
3692 var L1ctlDlMessage l1_dl;
3693
3694 /* initialize all per-TC vectors empty */
3695 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3696 si_per_tc[i] := {};
3697 }
3698
3699 /* flush all previous L1 queued msgs */
3700 pt.clear;
3701
3702 T.start;
3703 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003704 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003705 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3706 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3707 log("Ignoring non-RR SI ", l1_dl);
3708 repeat;
3709 }
3710 var SystemInformationFn sig := {
3711 frame_number := l1_dl.dl_info.frame_nr,
3712 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3713 }
3714 var integer tc := f_gsm_compute_tc(sig.frame_number);
3715 log("SI received at TC=", tc, ": ", sig.si);
3716 /* append to the per-TC bucket */
3717 si_per_tc[tc] := si_per_tc[tc] & { sig };
3718 repeat;
3719 }
3720 [] pt.receive { repeat; }
3721 [] T.timeout { }
3722 }
3723
3724 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3725 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3726 }
3727 log("si_per_tc=", si_per_tc);
3728 return si_per_tc;
3729}
3730
3731/* helper function: Set given SI via RSL + validate scheduling.
3732 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3733function f_TC_si_sched() runs on test_CT {
3734 var SystemInformationVectorPerTc si_per_tc;
3735 f_init_l1ctl();
3736 f_l1_tune(L1CTL);
3737
3738 /* Sample + Validate Scheduling */
3739 si_per_tc := f_l1_sample_si(L1CTL);
3740 f_validate_si_scheduling(si_cfg, si_per_tc);
3741
3742 setverdict(pass);
3743}
3744
3745testcase TC_si_sched_default() runs on test_CT {
3746 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003747 /* 2+3+4 are mandatory and set in f_init() */
3748 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003750}
3751
3752testcase TC_si_sched_1() runs on test_CT {
3753 f_init();
3754 si_cfg.si1_present := true;
3755 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003756 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003758}
3759
3760testcase TC_si_sched_2bis() runs on test_CT {
3761 f_init();
3762 si_cfg.si2bis_present := true;
3763 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3764 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003766}
3767
3768testcase TC_si_sched_2ter() runs on test_CT {
3769 f_init();
3770 si_cfg.si2ter_present := true;
3771 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3772 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003774}
3775
3776testcase TC_si_sched_2ter_2bis() runs on test_CT {
3777 f_init();
3778 si_cfg.si2bis_present := true;
3779 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3780 si_cfg.si2ter_present := true;
3781 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3782 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003784}
3785
3786testcase TC_si_sched_2quater() runs on test_CT {
3787 f_init();
3788 si_cfg.si2quater_present := true;
3789 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3790 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003792}
3793
3794testcase TC_si_sched_13() runs on test_CT {
3795 f_init();
3796 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003797 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003798 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003800}
3801
3802testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3803 f_init();
3804 si_cfg.si2bis_present := true;
3805 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3806 si_cfg.si2ter_present := true;
3807 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3808 si_cfg.si2quater_present := true;
3809 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3810 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003811 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003812 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003814}
3815
3816
Harald Welte68e495b2018-02-25 00:05:57 +01003817testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003818 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003819 /* FIXME: enable / disable individual BCCH info */
3820 //ts_RSL_BCCH_INFO(si_type, info);
3821 /* expect no ERROR REPORT after either of them *
3822 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003824}
3825
Harald Welte93640c62018-02-25 16:59:33 +01003826/***********************************************************************
3827 * Low-Level Protocol Errors / ERROR REPORT
3828 ***********************************************************************/
3829
Harald Welte01d982c2018-02-25 01:31:40 +01003830private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3831 timer T := 5.0;
3832 T.start;
3833 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003834 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01003835 setverdict(pass);
3836 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003837 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003839 }
3840 [] RSL_CCHAN.receive {
3841 repeat;
3842 }
3843 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003845 }
3846 }
3847}
3848
3849/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3850testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003851 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003852 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3853 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003854 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003855
3856 f_exp_err_rep(RSL_ERR_PROTO);
3857}
3858
3859/* Provoke a mandatory IE error and match on ERROR REPORT */
3860testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003861 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003862
3863 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3864 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003865 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003866
3867 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3868}
3869
3870/* Provoke an IE content error and match on ERROR REPORT */
3871testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003872 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003873 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3874 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003875 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003876
3877 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3878}
3879
Harald Welteee25aae2019-05-19 14:32:37 +02003880/* attempt to activate channel with wrong RSL Message Discriminator IE */
3881function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3882 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3883 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3884 RSL.send(rsl);
3885 f_rslem_unregister(0, g_chan_nr);
3886}
3887testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3888 var ConnHdlr vc_conn;
3889 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3890
Harald Welte10474062019-05-30 16:48:17 +02003891 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003892
3893 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3894 vc_conn.done;
3895 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3896
3897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3898}
3899
3900/* Send messages with wrong message type */
3901function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3902 var template (value) RSL_Message rsl_tx;
3903 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3904 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3905 RSL.send(rsl_tx);
3906 f_rslem_unregister(0, g_chan_nr);
3907}
3908function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3909 var template (value) RSL_Message rsl_tx;
3910 /* we first have to activate the dedicated channel */
3911 f_rsl_chan_act(g_pars.chan_mode);
3912 /* ... to then send an invalid RLL message */
3913 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3914 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3915 RSL.send(rsl_tx);
3916 f_rslem_unregister(0, g_chan_nr);
3917}
3918testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3919 var ConnHdlr vc_conn;
3920 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3921 var template (value) RSL_Message rsl_tx;
3922
Harald Welte10474062019-05-30 16:48:17 +02003923 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003924
3925 /* Common Channel with wrong message type */
3926 RSL_CCHAN.clear;
3927 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3928 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003929 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003930 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3931
3932 /* TRX Management */
3933 RSL_CCHAN.clear;
3934 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3935 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003936 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02003937 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3938
3939 /* Dedicated Channel */
3940 RSL_CCHAN.clear;
3941 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3942 vc_conn.done;
3943 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3944
3945 /* RLL */
3946 RSL_CCHAN.clear;
3947 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3948 vc_conn.done;
3949 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3950}
3951
3952/* Send messages in wrong sequence (RLL to an inactive lchan) */
3953function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3954 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3955 f_rslem_unregister(0, g_chan_nr);
3956}
3957testcase TC_err_rep_wrong_sequence() runs on test_CT {
3958 var ConnHdlr vc_conn;
3959 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3960
Harald Welte10474062019-05-30 16:48:17 +02003961 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003962
3963 RSL_CCHAN.clear;
3964 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3965 vc_conn.done;
3966 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3967}
3968
Harald Welte93640c62018-02-25 16:59:33 +01003969/***********************************************************************
3970 * IPA CRCX/MDCX/DLCS media stream handling
3971 ***********************************************************************/
3972
Harald Weltea871a382018-02-25 02:03:14 +01003973/* Send IPA DLCX to inactive lchan */
3974function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003975 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3976 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003977}
3978testcase TC_ipa_dlcx_not_active() runs on test_CT {
3979 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003980 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003981 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3982 vc_conn.done;
3983}
Harald Welte68e495b2018-02-25 00:05:57 +01003984
Harald Weltea3f1df92018-02-25 12:49:55 +01003985/* Send IPA CRCX twice to inactive lchan */
3986function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3987 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3988 "IPA CRCX ACK");
3989 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3990 "IPA CRCX NACK");
3991}
3992testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3993 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003994 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003995 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3996 vc_conn.done;
3997}
3998
3999/* Regular sequence of CRCX/MDCX/DLCX */
4000function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4001 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4002 "IPA CRCX ACK");
4003 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4004 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4005 var uint7_t rtp_pt2 := f_rnd_int(127);
4006 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4007 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4008 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4009 "IPA MDCX ACK");
4010 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4011 "IPA DLCX ACK");
4012}
4013testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4014 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004015 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004016 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4017 vc_conn.done;
4018}
4019
Harald Welte3ae11da2018-02-25 13:36:06 +01004020/* Sequence of CRCX, 2x MDCX, DLCX */
4021function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4022 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4023 "IPA CRCX ACK");
4024 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4025 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4026 var uint7_t rtp_pt2 := f_rnd_int(127);
4027 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4028 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4029 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4030 "IPA MDCX ACK");
4031 /* Second MDCX */
4032 remote_ip := f_rnd_int(c_UINT32_MAX);
4033 remote_port := f_rnd_int(c_UINT16_MAX);
4034 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4035 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4036 "IPA MDCX ACK");
4037 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4038 "IPA DLCX ACK");
4039}
4040testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4041 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004042 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004043 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4044 vc_conn.done;
4045}
4046
Harald Welte9912eb52018-02-25 13:30:15 +01004047/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
4048function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
4049 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4050 "IPA CRCX NACK");
4051}
4052testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4053 var ConnHdlrPars pars;
4054 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004055 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004056
4057 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4058 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4059 vc_conn.done;
4060
4061 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4062 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4063 vc_conn.done;
4064}
4065
Harald Weltea3f1df92018-02-25 12:49:55 +01004066
Harald Welte883340c2018-02-28 18:59:29 +01004067/***********************************************************************
4068 * PCU Socket related tests
4069 ***********************************************************************/
4070
Harald Welte07bd2d22019-05-25 11:03:30 +02004071/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004072friend 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 +01004073runs on test_CT {
4074 timer T := 3.0;
4075
4076 /* we don't expect any RTS.req before PDCH are active */
4077 T.start;
4078 alt {
4079 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004081 }
4082 [] PCU.receive { repeat; }
4083 [] T.timeout { }
4084 }
4085
4086 /* Send PDCH activate request for known PDCH timeslot */
4087 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4088
4089 /* we now expect RTS.req for this timeslot (only) */
4090 T.start;
4091 alt {
4092 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4093 setverdict(pass);
4094 }
4095 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4096 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004098 }
4099 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004101 }
4102 [] PCU.receive { repeat; }
4103 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004105 }
4106 [not exp_success] T.timeout {
4107 setverdict(pass);
4108 }
4109 }
4110}
4111
Harald Welte07bd2d22019-05-25 11:03:30 +02004112/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004113friend 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 +01004114runs on test_CT {
4115 timer T := 3.0;
4116
4117 /* Send PDCH activate request for known PDCH timeslot */
4118 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4119
4120 PCU.clear;
4121 /* we now expect no RTS.req for this timeslot */
4122 T.start;
4123 alt {
4124 [] 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 +02004125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004126 }
4127 [] PCU.receive { repeat; }
4128 [] T.timeout {
4129 setverdict(pass);
4130 }
4131 }
4132}
4133
Harald Weltead033dc2019-05-25 17:28:16 +02004134friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004135 f_init();
4136 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4137}
4138
Harald Welte883340c2018-02-28 18:59:29 +01004139/* PDCH activation via PCU socket; check for presence of RTS.req */
4140testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004141 f_init_pcu_test();
4142
Harald Welte883340c2018-02-28 18:59:29 +01004143 f_TC_pcu_act_req(0, 0, 7, true);
4144}
4145
4146/* PDCH activation via PCU socket on non-PDCU timeslot */
4147testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004148 f_init_pcu_test();
4149
Harald Welte883340c2018-02-28 18:59:29 +01004150 f_TC_pcu_act_req(0, 0, 1, false);
4151}
4152
4153/* PDCH activation via PCU socket on wrong BTS */
4154testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004155 f_init_pcu_test();
4156
Harald Welte883340c2018-02-28 18:59:29 +01004157 f_TC_pcu_act_req(23, 0, 7, false);
4158}
4159
4160/* PDCH activation via PCU socket on wrong TRX */
4161testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004162 f_init_pcu_test();
4163
Harald Welte883340c2018-02-28 18:59:29 +01004164 f_TC_pcu_act_req(0, 23, 7, false);
4165}
4166
4167/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4168testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004169 f_init_pcu_test();
4170
Harald Welte883340c2018-02-28 18:59:29 +01004171 /* Activate PDCH */
4172 f_TC_pcu_act_req(0, 0, 7, true);
4173 f_sleep(1.0);
4174 /* and De-Activate again */
4175 f_TC_pcu_deact_req(0, 0, 7);
4176}
4177
4178/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4179testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004180 f_init_pcu_test();
4181
Harald Welte883340c2018-02-28 18:59:29 +01004182 f_TC_pcu_deact_req(0, 0, 1);
4183}
4184
4185/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4186testcase TC_pcu_ver_si13() runs on test_CT {
4187 const octetstring si13 := '00010203040506070909'O;
4188 var PCUIF_send_data sd;
4189 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004190 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004191
4192 /* Set SI13 via RSL */
4193 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004194
Harald Welte883340c2018-02-28 18:59:29 +01004195 T.start;
4196 alt {
4197 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4198 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4199 setverdict(pass);
4200 } else {
4201 repeat;
4202 }
4203 }
4204 [] PCU.receive { repeat; }
4205 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004207 }
4208 }
4209}
4210
4211private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4212
4213/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004214friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004215 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4216runs on test_CT
4217{
4218 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4219 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4220}
4221
4222/* 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 +02004223friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4224 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004225runs on test_CT
4226{
4227 var PCUIF_send_data sd;
4228
4229 timer T := 3.0;
4230 T.start;
4231 alt {
4232 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4233 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4234 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4235 sd.data.u.rts_req.fn, sapi, data);
4236 }
4237 [] PCU.receive { repeat; }
4238 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004240 }
4241 }
4242}
4243
4244/* Send DATA.req on invalid BTS */
4245testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004246 var TfiUsfArr tua := f_TfiUsfArrInit();
4247 var octetstring data := '0000'O & f_rnd_octstring(21);
4248
4249 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004250
Harald Welte883340c2018-02-28 18:59:29 +01004251 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004252 f_TfiUsfArrSet(tua, 7, 0);
4253 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4254 f_sleep(1.0);
4255
4256 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004257}
4258
4259/* Send DATA.req on invalid TRX */
4260testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004261 var TfiUsfArr tua := f_TfiUsfArrInit();
4262 var octetstring data := '0000'O & f_rnd_octstring(21);
4263
4264 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004265
Harald Welte883340c2018-02-28 18:59:29 +01004266 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004267 f_TfiUsfArrSet(tua, 7, 0);
4268 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4269 f_sleep(1.0);
4270
4271 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004272}
4273
4274/* Send DATA.req on invalid timeslot */
4275testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004276 var TfiUsfArr tua := f_TfiUsfArrInit();
4277 var octetstring data := '0000'O & f_rnd_octstring(21);
4278
4279 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004280
Harald Welte883340c2018-02-28 18:59:29 +01004281 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004282 f_TfiUsfArrSet(tua, 7, 0);
4283 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4284 f_sleep(1.0);
4285
4286 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004287}
4288
4289/* Send DATA.req on timeslot that hasn't been activated */
4290testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004291 var TfiUsfArr tua := f_TfiUsfArrInit();
4292 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004293
Harald Welte7162a612019-05-26 12:56:09 +02004294 f_virtphy_common();
4295
4296 f_TfiUsfArrSet(tua, 7, 0);
4297 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4298 f_sleep(1.0);
4299
4300 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004301}
4302
Harald Weltead033dc2019-05-25 17:28:16 +02004303private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004304 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4305 boolean wait_rts := true)
4306runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004307 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004308 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004309
4310 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004311 if (wait_rts) {
4312 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4313 } else {
4314 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4315 }
Harald Weltead033dc2019-05-25 17:28:16 +02004316
4317 T.start;
4318 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004319 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004320 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4321 setverdict(pass);
4322 }
Harald Welte7162a612019-05-26 12:56:09 +02004323 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4324 setverdict(fail, "Received unexpected ", rx_dl);
4325 }
Harald Weltead033dc2019-05-25 17:28:16 +02004326 [] L1CTL.receive {
4327 repeat;
4328 }
Harald Welte7162a612019-05-26 12:56:09 +02004329 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004330 setverdict(fail, "Timeout waiting for ", data);
4331 }
Harald Welte7162a612019-05-26 12:56:09 +02004332 [not expect_data] T.timeout {
4333 setverdict(pass);
4334 }
Harald Weltead033dc2019-05-25 17:28:16 +02004335 }
4336}
4337
4338private function f_disable_dynamic_ts() runs on test_CT
4339{
4340 f_init_vty_bsc();
4341 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4342 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4343 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4344 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004345 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004346}
4347
4348private function f_virtphy_common() runs on test_CT {
4349 f_disable_dynamic_ts();
4350 f_init_l1ctl();
4351 f_l1_tune(L1CTL);
4352}
4353
4354testcase TC_pcu_data_req_pdtch() runs on test_CT {
4355 var TfiUsfArr tua := f_TfiUsfArrInit();
4356 var octetstring data := '0000'O & f_rnd_octstring(21);
4357
4358 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004359
Harald Welte883340c2018-02-28 18:59:29 +01004360 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004361 f_TfiUsfArrSet(tua, 7, 0);
4362 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4363 f_sleep(1.0);
4364
4365 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004366}
4367
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004368/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004369testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004370 var TfiUsfArr tua := f_TfiUsfArrInit();
4371 var octetstring data := '0000'O & f_rnd_octstring(21);
4372
4373 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004374
Harald Welte883340c2018-02-28 18:59:29 +01004375 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004376 f_TfiUsfArrSet(tua, 7, 0);
4377 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4378 f_sleep(1.0);
4379
4380 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004381}
4382
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004383private function f_TC_pcu_ptcch_ul(uint16_t ra)
4384runs on test_CT {
4385 var template PCUIF_Message pcu_rach_ind;
4386 var PCUIF_send_data sd;
4387 var GsmFrameNumber fn;
4388 timer T;
4389
4390 /* Send an Access Burst on PTCCH/U over the Um-interface */
4391 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4392 chan_nr := ts_RslChanNr_PDCH(7),
4393 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4394
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004395 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4396 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004397
4398 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4399 T.start(52.0 * 4.615 / 1000.0);
4400 alt {
4401 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4402 log("Rx an Access Burst on the PCU interface: ", sd.data);
4403 setverdict(pass);
4404 T.stop;
4405 }
4406 [] PCU.receive { repeat; }
4407 [] T.timeout {
4408 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4409 /* Keep going, that's not the end of the world */
4410 }
4411 }
4412}
4413
4414testcase TC_pcu_ptcch() runs on test_CT {
4415 var L1ctlDlMessage dl;
4416 var octetstring data;
4417 timer T;
4418
4419 f_init_pcu_test();
4420 f_init_l1ctl();
4421 f_l1_tune(L1CTL);
4422
4423 /* Activate PDCH channel on TS7 */
4424 f_TC_pcu_act_req(0, 0, 7, true);
4425
4426 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004427 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004428
4429 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4430 for (var integer i := 0; i < 16; i := i + 1) {
4431 log("Sending an Access Burst towards the L1CTL interface");
4432 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4433 }
4434
4435 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4436 data := f_rnd_octstring(23);
4437
4438 /* Verify PTCCH/D: send a random data block, make sure it's received */
4439 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4440 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4441
4442 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4443 * let's give it more time in case if we miss the beginning. */
4444 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4445 alt {
4446 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4447 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4448 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4449 frame := data)) -> value dl {
4450 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4451 setverdict(pass);
4452 T.stop;
4453 }
4454 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4455 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4456 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4457 l2_data := data)) -> value dl {
4458 log("Rx PTCCH/D data block on L1CTL: ", dl);
4459 setverdict(pass);
4460 T.stop;
4461 }
4462 [] L1CTL.receive { repeat; }
4463 [] T.timeout {
4464 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4465 }
4466 }
4467}
4468
Harald Welte883340c2018-02-28 18:59:29 +01004469/* Send AGCH from PCU; check it appears on Um side */
4470testcase TC_pcu_data_req_agch() runs on test_CT {
4471 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004472 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004473 f_init_l1ctl();
4474 f_l1_tune(L1CTL);
4475
4476 f_TC_pcu_act_req(0, 0, 7, true);
4477 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4478
4479 T.start;
4480 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004481 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004482 setverdict(pass);
4483 }
4484 [] L1CTL.receive { repeat; }
4485 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004487 }
4488 }
4489}
4490
Harald Welte928622b2019-05-26 13:22:59 +02004491/* Send AGCH from PCU; check it appears on Um side */
4492testcase TC_pcu_data_req_pch() runs on test_CT {
4493 timer T := 3.0;
4494 f_init_pcu_test();
4495 f_init_l1ctl();
4496 f_l1_tune(L1CTL);
4497
4498 f_TC_pcu_act_req(0, 0, 7, true);
4499 /* three characters prefix: last 3 digits of IMSI as ASCII */
4500 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4501
4502 T.start;
4503 alt {
4504 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4505 setverdict(pass);
4506 }
4507 [] L1CTL.receive { repeat; }
4508 [] T.timeout {
4509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4510 }
4511 }
4512}
4513
Harald Welte883340c2018-02-28 18:59:29 +01004514/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4515testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4516 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004517 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004518 f_init_l1ctl();
4519 f_l1_tune(L1CTL);
4520
4521 /* append 3 last imsi digits so BTS can compute pagng group */
4522 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4523
4524 timer T := 0.5;
4525 T.start;
4526 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004527 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004528 /* TODO: verify paging group */
4529 setverdict(pass);
4530 }
4531 [] L1CTL.receive { repeat; }
4532 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004534 }
4535 }
4536}
4537
4538/* Send RACH from Um side, expect it to show up on PCU socket */
4539testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004540 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004541 f_init_l1ctl();
4542 f_l1_tune(L1CTL);
4543
4544 var GsmFrameNumber fn_last := 0;
4545 for (var integer i := 0; i < 1000; i := i+1) {
4546 var OCT1 ra := f_rnd_ra_ps();
4547 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4548 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004550 }
4551 fn_last := fn;
4552
4553 timer T := 2.0;
4554 T.start;
4555 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004556 [] 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 +01004557 T.stop;
4558 }
4559 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004561 }
4562 [] PCU.receive { repeat; }
4563 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004565 }
4566 }
4567 }
4568 setverdict(pass);
4569}
4570
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004571/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4572 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4573testcase TC_pcu_ext_rach_content() runs on test_CT {
4574 var template PCUIF_Message pcu_rach_ind;
4575 var GsmFrameNumber fn_last := 0;
4576 var L1ctlRachSynchSeq synch_seq;
4577 var PCUIF_BurstType pcu_bt;
4578 var GsmFrameNumber fn;
4579 var BIT11 ra11;
4580
4581 f_init_pcu_test();
4582 f_init_l1ctl();
4583 f_l1_tune(L1CTL);
4584
4585 for (var integer i := 0; i < 1000; i := i+1) {
4586 /* We need to test both TS1 & TS2 */
4587 if (i rem 2 == 0) {
4588 synch_seq := RACH_SYNCH_SEQ_TS1;
4589 pcu_bt := BURST_TYPE_1;
4590 } else {
4591 synch_seq := RACH_SYNCH_SEQ_TS2;
4592 pcu_bt := BURST_TYPE_2;
4593 }
4594
4595 ra11 := f_rnd_ra11_ps();
4596 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4597 if (fn == fn_last) {
4598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4599 "Two RACH in same FN?!?");
4600 }
4601 fn_last := fn;
4602
4603 /* Compose the expected message */
4604 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004605 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004606 ra := bit2int(ra11),
4607 is_11bit := 1,
4608 burst_type := pcu_bt,
4609 fn := fn);
4610
4611 timer T := 2.0;
4612 T.start;
4613 alt {
4614 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4615 T.stop;
4616 }
4617 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4619 }
4620 [] PCU.receive { repeat; }
4621 [] T.timeout {
4622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4623 }
4624 }
4625 }
4626 setverdict(pass);
4627}
4628
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004629private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4630runs on test_CT {
4631 var template PCUIF_send_data sdt;
4632 var PCUIF_send_data sd;
4633 var int16_t lqual_cb;
4634 timer T := 1.0;
4635
4636 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4637 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4638
4639 /* Send a random PDTCH frame over Um */
4640 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4641 '0000'O & f_rnd_octstring(21)));
4642
4643 T.start;
4644 alt {
4645 /* If expected link quality is above the threshold */
4646 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4647 lqual_cb := sd.data.u.data_ind.lqual_cb;
4648 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4649
4650 /* Make sure the actual link quality matches the expected value */
4651 if (not match(lqual_cb, lqual_cb_exp)) {
4652 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4653 "expected value ", lqual_cb_exp));
4654 } else {
4655 setverdict(pass);
4656 }
4657 }
4658 /* If expected link quality is below the threshold */
4659 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4661 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4662 }
4663 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4664 [] PCU.receive { repeat; }
4665 [lqual_cb_exp < thresh] T.timeout {
4666 log("Rx nothing, as expected");
4667 setverdict(pass);
4668 }
4669 [lqual_cb_exp >= thresh] T.timeout {
4670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4671 "Timeout waiting for PCUIF_DATA.ind");
4672 }
4673 }
4674}
4675
4676/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4677testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4678 f_init_pcu_test();
4679 PCU.clear;
4680
4681 f_init_l1ctl();
4682 f_l1_tune(L1CTL);
4683
4684 /* Activate a PDCH channel on TS7 */
4685 f_TC_pcu_act_req(0, 0, 7, true);
4686
4687 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004688 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004689
4690 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4691 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4692 var TrxcMessage ret;
4693
4694 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4695 valueof(ts_TRXC_FAKE_CI(i)));
4696
4697 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4698 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4699 }
4700}
4701
Harald Welte883340c2018-02-28 18:59:29 +01004702/* Send PAGING via RSL, expect it to shw up on PCU socket */
4703testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004704 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004705
4706 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004707 var MobileIdentityLV mi_lv;
4708 var octetstring mi_lv_enc;
4709 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004710 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004711
Harald Welte883340c2018-02-28 18:59:29 +01004712 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004713 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004714 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004715 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004716 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004717
4718 /* Fancy encoding for PCUIF */
4719 mi_lv := valueof(ts_MI_LV(mi));
4720 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4721 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004722
4723 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004724 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004725 T.start;
4726 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004727 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004728 }
4729 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004731 }
4732 [] PCU.receive { repeat; }
4733 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004735 }
4736 }
4737 }
4738 setverdict(pass);
4739}
4740
Harald Welted66c9b82019-05-25 09:03:15 +02004741/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4742testcase TC_pcu_time_ind() runs on test_CT {
4743 var PCUIF_send_data pcu_sd;
4744 var integer num_time_ind := 0;
4745 var integer first_fn, last_fn;
4746 var float test_duration := 5.0;
4747 timer T;
4748
4749 f_init_pcu_test();
4750 f_TC_pcu_act_req(0, 0, 7, true);
4751
4752 PCU.clear;
4753 T.start(test_duration);
4754 alt {
4755 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4756 num_time_ind := num_time_ind + 1;
4757 if (not isbound(first_fn)) {
4758 first_fn := pcu_sd.data.u.time_ind.fn;
4759 }
4760 last_fn := pcu_sd.data.u.time_ind.fn;
4761 repeat;
4762 }
4763 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4764 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4765 repeat;
4766 }
4767 [] PCU.receive {
4768 repeat;
4769 }
4770 [] T.timeout {}
4771 }
4772 var integer fn_expired := last_fn - first_fn;
4773 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4774
4775 /* verify the number of frames expired matches our expectation */
4776 const float c_GSM_FN_DURATION_MS := 4.61538;
4777 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004778 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004779 if (not match(fn_expired, t_fn_expected)) {
4780 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4781 }
4782
4783 /* There are three TIME.ind in every fn MOD 13 */
4784 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4785 /* Add some tolerance */
4786 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4787 if (not match(num_time_ind, t_time_ind_exp)) {
4788 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4789 }
4790
4791 setverdict(pass);
4792}
4793
Harald Welte4832c862019-05-25 14:57:18 +02004794/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4795testcase TC_pcu_rts_req() runs on test_CT {
4796 var PCUIF_send_data pcu_sd;
4797 var integer first_fn, last_fn;
4798 var integer num_rts_pdtch := 0;
4799 var integer num_rts_ptcch := 0;
4800 var float test_duration := 5.0;
4801 timer T;
4802
4803 f_init_pcu_test();
4804 f_TC_pcu_act_req(0, 0, 7, true);
4805
4806 PCU.clear;
4807 T.start(test_duration);
4808 alt {
4809 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4810 -> value pcu_sd {
4811 num_rts_pdtch := num_rts_pdtch + 1;
4812 if (not isbound(first_fn)) {
4813 first_fn := pcu_sd.data.u.rts_req.fn;
4814 }
4815 last_fn := pcu_sd.data.u.rts_req.fn;
4816 repeat;
4817 }
4818 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4819 -> value pcu_sd {
4820 num_rts_ptcch := num_rts_ptcch + 1;
4821 if (not isbound(first_fn)) {
4822 first_fn := pcu_sd.data.u.rts_req.fn;
4823 }
4824 last_fn := pcu_sd.data.u.rts_req.fn;
4825 repeat;
4826 }
4827 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4828 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4829 repeat;
4830 }
4831 [] PCU.receive {
4832 repeat;
4833 }
4834 [] T.timeout {}
4835 }
4836 var integer fn_expired := last_fn - first_fn;
4837 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4838 ", num_rts_ptcch=", num_rts_ptcch);
4839
4840 /* verify the number of frames expired matches our expectation */
4841 const float c_GSM_FN_DURATION_MS := 4.61538;
4842 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004843 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004844 if (not match(fn_expired, t_fn_expected)) {
4845 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4846 }
4847
4848 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4849 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4850 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4851 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4852 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4853 t_ptcch_exp);
4854 }
4855
4856 /* We have 12 PDTCH blocks every 52-multiframe */
4857 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4858 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4859 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4860 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4861 t_pdtch_exp);
4862 }
4863
4864 setverdict(pass);
4865}
4866
Harald Welte07bd2d22019-05-25 11:03:30 +02004867/* test for generating Abis side OML ALERT from the PCU */
4868testcase TC_pcu_oml_alert() runs on test_CT {
4869 var PCUIF_send_data pcu_sd;
4870 var integer num_time_ind := 0;
4871 var integer first_fn, last_fn;
4872 var float test_duration := 5.0;
4873 timer T;
4874
4875 f_init_pcu_test();
4876 f_TC_pcu_act_req(0, 0, 7, true);
4877
4878 /* re-connect CTRL port from BTS to BSC */
4879 f_ipa_ctrl_stop();
4880 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4881
4882 /* Send that OML Alert */
4883 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
4884
4885 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
4886 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
4887 setverdict(pass);
4888}
4889
Harald Welteeaa9a862019-05-26 23:01:08 +02004890template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
4891 template (value) RoutingAreaIdentificationV rai,
4892 template (value) OCT1 cause) := {
4893 discriminator := '0000'B, /* overwritten */
4894 tiOrSkip := {
4895 skipIndicator := '0000'B
4896 },
4897 msgs := {
4898 rrm := {
4899 gPRS_suspensionRequest := {
4900 messageType := '00110100'B,
4901 tLLI := tlli,
4902 routingAreaIdentification := rai,
4903 suspensionCause := cause,
4904 service_Support := omit
4905 }
4906 }
4907 }
4908}
4909
4910/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
4911private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
4912 var PCUIF_Message first_info;
4913 var integer pcu_conn_id := -1;
4914 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4915 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
4916 var OCT4 tlli := '01020304'O;
4917 var OCT1 cause := '23'O;
4918 timer T := 5.0;
4919
4920 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4921
4922 f_l1_tune(L1CTL);
4923 RSL.clear;
4924
4925 f_est_dchan();
4926 L1CTL.clear;
4927
4928 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4929
4930 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
4931 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
4932 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
4933
4934 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
4935 T.start;
4936 alt {
4937 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
4938 setverdict(pass);
4939 }
4940 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
4941 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
4942 }
4943 [] PCU.receive {
4944 repeat;
4945 }
4946 [] T.timeout {
4947 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
4948 }
4949 }
Alexander Couzensa0634832019-06-07 00:28:56 +02004950
4951 /* release the channel */
4952 f_rsl_chan_deact();
4953 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4954 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02004955}
4956testcase TC_pcu_rr_suspend() runs on test_CT {
4957 var ConnHdlrPars pars;
4958 var ConnHdlr vc_conn;
4959
4960 f_init();
4961
4962 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4963 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4964 vc_conn.done;
4965}
Harald Welte07bd2d22019-05-25 11:03:30 +02004966
Harald Weltea2e0e942019-05-27 18:12:53 +02004967/* Ensure that PCUIF socket can accept only a single connection */
4968testcase TC_pcu_socket_connect_multi() runs on test_CT {
4969 timer T := 5.0;
4970
4971 /* this (among other things) establishes the first connection to the PCUIF socket */
4972 f_init();
4973
4974 /* try to establish a second connection, expect it to fail */
4975 PCU.send(UD_connect:{mp_pcu_socket, -1});
4976 T.start;
4977 alt {
4978 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4979 setverdict(pass);
4980 }
4981 [] PCU.receive(UD_connect_result:?) {
4982 setverdict(fail, "Unexpected unix domain connect result");
4983 }
4984 [] T.timeout {
4985 setverdict(pass);
4986 }
4987 }
4988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4989}
4990
Harald Weltec8effb72019-05-27 18:23:04 +02004991/* Ensure that PCUIF socket can disconnect + reconnect */
4992testcase TC_pcu_socket_reconnect() runs on test_CT {
4993 /* this (among other things) establishes the first connection to the PCUIF socket */
4994 f_init();
4995
4996 f_sleep(1.0);
4997
4998 f_pcuif_close(PCU, g_pcu_conn_id);
4999 g_pcu_conn_id := -1;
5000
5001 f_sleep(1.0);
5002
5003 /* re-connect */
5004 PCU.clear;
5005 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5006 setverdict(pass);
5007
5008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5009}
5010
Harald Weltebe030482019-05-27 22:29:35 +02005011/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005012private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5013runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005014 var L1ctlDlMessage l1_dl;
5015 var SystemInformation si;
5016 timer T := 5.0;
5017 T.start;
5018 alt {
5019 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
5020 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
5021 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
5022 log("Ignoring non-RR SI ", l1_dl);
5023 repeat;
5024 }
5025 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005026 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005027 repeat;
5028 }
5029 }
5030 [] pt.receive {
5031 repeat;
5032 }
5033 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5035 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005036 }
5037 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005038 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005039}
5040
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005041/* Check if GPRS Indicator is present in RR System Information of a given type */
5042private function f_si_has_gprs_indicator(RrMessageType si_type)
5043runs on test_CT return boolean {
5044 var SystemInformation si := f_get_si(L1CTL, si_type);
5045
5046 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
5047 var RestOctets ro := si.payload.si3.rest_octets;
5048 var SI3RestOctets rest := dec_SI3RestOctets(ro);
5049 return rest.gprs_ind.presence == '1'B;
5050 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
5051 var RestOctets ro := si.payload.si4.rest_octets;
5052 var SI4RestOctets rest := dec_SI4RestOctets(ro);
5053 return rest.gprs_ind.presence == '1'B;
5054 }
5055
5056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5057 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005058}
5059
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005060/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5061private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5062runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005063 /* don't call f_init() as this would connect PCU socket */
5064 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005065
5066 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005067 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005068 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005069
5070 f_init_l1ctl();
5071 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005072 f_sleep(2.0);
5073 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005074
5075 if (f_si_has_gprs_indicator(si_type)) {
5076 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005077 } else {
5078 setverdict(pass);
5079 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005080
Harald Weltebe030482019-05-27 22:29:35 +02005081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5082}
5083
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005084testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5085 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5086}
Harald Weltebe030482019-05-27 22:29:35 +02005087
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005088testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5089 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5090}
5091
5092/* Ensure that GPRS capability is advertised after PCU socket connect */
5093private function f_TC_pcu_socket_connect(RrMessageType si_type)
5094runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005095 /* this (among other things) establishes the first connection to the PCUIF socket */
5096 f_init();
5097 f_init_l1ctl();
5098 f_l1_tune(L1CTL);
5099
5100 f_sleep(2.0);
5101 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005102
5103 if (not f_si_has_gprs_indicator(si_type)) {
5104 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005105 } else {
5106 setverdict(pass);
5107 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005108
Harald Weltebe030482019-05-27 22:29:35 +02005109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5110}
5111
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005112testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5113 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5114}
Harald Weltebe030482019-05-27 22:29:35 +02005115
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005116testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5117 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5118}
5119
5120/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5121private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5122runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005123 /* this (among other things) establishes the first connection to the PCUIF socket */
5124 f_init();
5125 f_init_l1ctl();
5126 f_l1_tune(L1CTL);
5127
5128 f_pcuif_close(PCU, g_pcu_conn_id);
5129 g_pcu_conn_id := -1;
5130
5131 f_sleep(1.0);
5132
5133 /* re-connect */
5134 PCU.clear;
5135 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5136
5137 f_sleep(2.0);
5138 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005139
5140 if (f_si_has_gprs_indicator(si_type)) {
5141 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005142 } else {
5143 setverdict(pass);
5144 }
5145
5146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5147}
5148
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005149testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5150 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5151}
5152
5153testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5154 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5155}
5156
Oliver Smithf5239c72019-08-28 10:01:25 +02005157/* 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) */
5158testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5159 var SystemInformation si3 := valueof(ts_SI3_default);
5160
5161 f_init();
5162
5163 /* Verify cell_id */
5164 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5165 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5166 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005167 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5168 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5169 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005170 }
5171
5172 /* Verify LAC */
5173 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5174 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5175 if (lac_si3 != lac_pcu) {
5176 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5177 }
5178
5179 setverdict(pass);
5180}
Harald Welted66c9b82019-05-25 09:03:15 +02005181
Harald Welte3d04ae62018-04-04 20:29:05 +02005182/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005183 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005184 ***********************************************************************/
5185
5186private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5187runs on ConnHdlr {
5188 var PCUIF_send_data sd;
5189 /* Expect BTS to immediately acknowledge activation as PDCH */
5190 PCU.clear;
5191 f_rsl_chan_act(g_pars.chan_mode);
5192 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005193 timer T_wait := 2.0;
5194 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005195 alt {
5196 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5197 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 +02005198 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5199 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5200 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005201 }
5202 }
5203 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005204 [] T_wait.timeout {
5205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5206 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5207 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005208 }
5209 /* try to activate this PDCH from the PCU point of view */
5210 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5211 /* FIXME: is there a response? */
5212}
5213
5214private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5215runs on ConnHdlr {
5216 var PCUIF_send_data sd;
5217 /* Send RSL CHAN REL (deactivate) */
5218 PCU.clear;
5219 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5220 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005221 timer T_wait := 2.0;
5222 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005223 alt {
5224 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5225 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 +02005226 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5227 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5228 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005229 }
5230 }
5231 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005232 [] T_wait.timeout {
5233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5234 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5235 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005236 }
5237 /* Emulate PCU asking BTS to deactivate PDCH */
5238 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5239 alt {
5240 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5241 setverdict(pass);
5242 }
5243 [] RSL.receive { repeat; }
5244 }
5245}
5246
5247/* Activate Osmocom-style dynamic PDCH from BSC side */
5248function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5249 var PCUIF_Message first_info;
5250 var integer ts_nr := g_chan_nr.tn;
5251 var integer trx_nr := 0;
5252 var integer bts_nr := 0;
5253 var integer pcu_conn_id := -1;
5254
5255 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5256
5257 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5258 f_sleep(3.0);
5259 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5260 setverdict(pass);
5261}
5262testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5263 var ConnHdlrPars pars;
5264 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005265 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005266
5267 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5268 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5269 vc_conn.done;
5270}
5271
5272/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5273function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5274 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005275 var integer pcu_conn_id := -1;
5276
5277 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5278
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005279 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5280 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5281 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005282 setverdict(pass);
5283}
5284testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5285 var ConnHdlrPars pars;
5286 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005287 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005288
5289 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5290 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5291 vc_conn.done;
5292}
5293
5294/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5295function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5296 var PCUIF_Message first_info;
5297 var integer ts_nr := g_chan_nr.tn;
5298 var integer trx_nr := 0;
5299 var integer bts_nr := 0;
5300 var integer pcu_conn_id := -1;
5301
5302 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5303
5304 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005305 /* Send a second Chan Activ and expect it to be NACKed */
5306 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5307 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005308 setverdict(pass);
5309}
5310testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5311 var ConnHdlrPars pars;
5312 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005313 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005314
5315 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5316 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5317 vc_conn.done;
5318}
5319
5320/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5321function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5322 var PCUIF_Message first_info;
5323 var integer ts_nr := g_chan_nr.tn;
5324 var integer trx_nr := 0;
5325 var integer bts_nr := 0;
5326 var integer pcu_conn_id := -1;
5327 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5328
5329 /* register for the TCH/F channel number */
5330 f_rslem_register(0, chan_nr);
5331
5332 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5333
5334 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5335 "RSL CHAN ACT");
5336 setverdict(pass);
5337}
5338testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5339 var ConnHdlrPars pars;
5340 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005341 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005342
5343 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5344 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5345 vc_conn.done;
5346}
5347
5348/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5349function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5350 var PCUIF_Message first_info;
5351 var integer ts_nr := g_chan_nr.tn;
5352 var integer trx_nr := 0;
5353 var integer bts_nr := 0;
5354 var integer pcu_conn_id := -1;
5355 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5356 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5357
5358 /* register for the TCH/H channel numbers */
5359 f_rslem_register(0, chan_nr[0]);
5360 f_rslem_register(0, chan_nr[1]);
5361
5362 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5363
5364 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5365 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5366 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5367 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5368 setverdict(pass);
5369}
5370testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5371 var ConnHdlrPars pars;
5372 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005373 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005374
5375 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5376 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5377 vc_conn.done;
5378}
5379
Harald Welte9bbbfb52018-04-05 09:33:19 +02005380/***********************************************************************
5381 * IPA Style Dynamic Timeslot Support
5382 ***********************************************************************/
5383
5384private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5385runs on ConnHdlr {
5386 var PCUIF_send_data sd;
5387 /* Expect BTS to immediately acknowledge activation as PDCH */
5388 PCU.clear;
5389 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5390 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005391 timer T_wait := 2.0;
5392 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005393 alt {
5394 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5395 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 +01005396 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5397 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5398 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005399 }
5400 }
5401 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005402 [] T_wait.timeout {
5403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5404 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5405 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005406 }
5407 /* try to activate this PDCH from the PCU point of view */
5408 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5409 /* FIXME: is there a response? */
5410
5411 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5412}
5413
5414private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5415runs on ConnHdlr {
5416 var PCUIF_send_data sd;
5417 /* Send RSL CHAN REL (deactivate) */
5418 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5419 PCU.clear;
5420 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005421 timer T_wait := 2.0;
5422 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005423 alt {
5424 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5425 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 +01005426 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5427 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5428 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005429 }
5430 }
5431 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005432 [] T_wait.timeout {
5433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5434 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5435 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005436 }
5437 /* Emulate PCU asking BTS to deactivate PDCH */
5438 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5439 alt {
5440 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5441 setverdict(pass);
5442 }
5443 [] RSL.receive { repeat; }
5444 }
5445}
5446
5447/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5448function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5449 var PCUIF_Message first_info;
5450 var integer ts_nr := g_chan_nr.tn;
5451 var integer trx_nr := 0;
5452 var integer bts_nr := 0;
5453 var integer pcu_conn_id := -1;
5454
5455 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5456
5457 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5458 f_sleep(3.0);
5459 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5460
5461 setverdict(pass);
5462
5463}
5464testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5465 var ConnHdlrPars pars;
5466 var ConnHdlr vc_conn;
5467 f_init();
5468
5469 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5470 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5471 vc_conn.done;
5472}
5473
5474/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5475function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5476 var PCUIF_Message first_info;
5477 var integer ts_nr := g_chan_nr.tn;
5478 var integer trx_nr := 0;
5479 var integer bts_nr := 0;
5480 var integer pcu_conn_id := -1;
5481
5482 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5483
5484 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5485 "RSL CHAN ACT");
5486 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5487 "RF CHAN REL", true);
5488 setverdict(pass);
5489}
5490testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5491 var ConnHdlrPars pars;
5492 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005493 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005494
5495 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5496 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5497 vc_conn.done;
5498}
5499
5500/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5501function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5502 var PCUIF_Message first_info;
5503 var integer ts_nr := g_chan_nr.tn;
5504 var integer trx_nr := 0;
5505 var integer bts_nr := 0;
5506 var integer pcu_conn_id := -1;
5507
5508 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5509
5510 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5511 "RSL CHAN ACT");
5512
5513 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5514 alt {
5515 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5516 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005518 }
5519 [] RSL.receive { repeat; }
5520 }
5521
5522 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5523 "RF CHAN REL", true);
5524 setverdict(pass);
5525}
5526testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5527 var ConnHdlrPars pars;
5528 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005529 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005530
5531 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5532 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5533 vc_conn.done;
5534}
5535
5536/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5537function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5538 var PCUIF_Message first_info;
5539 var integer ts_nr := g_chan_nr.tn;
5540 var integer trx_nr := 0;
5541 var integer bts_nr := 0;
5542 var integer pcu_conn_id := -1;
5543
5544 /* register for the TCH/F channel number */
5545 f_rslem_register(0, g_chan_nr);
5546
5547 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5548
5549 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5550
5551 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5552 "RSL CHAN ACT");
5553
5554 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5555
5556 setverdict(pass);
5557}
5558testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5559 var ConnHdlrPars pars;
5560 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005561 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005562
5563 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5564 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5565 vc_conn.done;
5566}
5567
5568
Harald Welte0472ab42018-03-12 15:02:26 +01005569/***********************************************************************
5570 * LAPDm / RLL related
5571 ***********************************************************************/
5572
5573private function f_tx_lapdm(template (value) LapdmFrame l,
5574 template (value) RslLinkId link_id) runs on ConnHdlr {
5575 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005576 var template (value) SacchL1Header l1h;
5577
5578 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005579 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005580 /* Compose dummy L1 header */
5581 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5582 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 +02005583 } else {
5584 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005585 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 +01005586 }
Harald Welte0472ab42018-03-12 15:02:26 +01005587}
5588
5589type record RllTestCase {
5590 uint3_t sapi,
5591 RslLinkId link_id,
5592 octetstring l3,
5593 boolean exp
5594}
5595type record of RllTestCase RllTestCases;
5596template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5597 sapi := sapi,
5598 link_id := id,
5599 l3 := l3,
5600 exp := exp
5601}
5602
5603/* execute the same callback function with a set of different parameters (tcs) on a
5604 * variety of logical channels */
5605private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5606 var ConnHdlrPars pars;
5607 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005608 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005609
5610 /* test on each of the channels we have */
5611 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5612 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5613
5614 /* test each of the test cases on the current channel */
5615 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5616 pars.spec.rll := tcs[j];
5617 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5618 vc_conn := f_start_handler(fn, pars);
5619 vc_conn.done;
5620 }
5621 }
5622
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005624}
5625
5626/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5627private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5628 var RllTestCase tc := g_pars.spec.rll;
5629 timer T := 3.0;
5630
5631 f_l1_tune(L1CTL);
5632 RSL.clear;
5633
5634 /* activate the logical channel */
5635 f_est_dchan();
5636 L1CTL.clear;
5637
5638 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5639 T.start;
5640 alt {
5641 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5642 if (tc.exp) {
5643 setverdict(pass);
5644 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005646 }
5647 }
5648 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5649 if (tc.exp) {
5650 setverdict(pass);
5651 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005653 }
5654 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005655 /* We also expect to receive the measurements */
5656 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005657 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005659 }
5660 [not tc.exp] T.timeout {
5661 setverdict(pass);
5662 }
5663 }
5664
5665 f_rsl_chan_deact();
5666 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5667 f_rslem_unregister(0, g_chan_nr);
5668}
5669testcase TC_rll_est_ind() runs on test_CT {
5670 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005671 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005672 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005673 /* normal SAPI0 establishment */
5674 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005675 /* SAPI 3 doesn't support contention resolution */
5676 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5677 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5678 /* normal SAPI3 establishment on main DCCH */
5679 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5680 /* normal SAPI3 establishment on SACCH */
5681 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5682 };
5683 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5684}
5685
5686/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5687private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5688 var RllTestCase tc := g_pars.spec.rll;
5689 var L1ctlDlMessage dl;
5690 timer T := 3.0;
5691
5692 f_l1_tune(L1CTL);
5693 RSL.clear;
5694
5695 /* activate the logical channel */
5696 f_est_dchan();
5697 L1CTL.clear;
5698
5699 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5700 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5701 T.start;
5702 alt {
5703 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5704 var LapdmFrame lapdm;
5705 var octetstring l2 := dl.payload.data_ind.payload;
5706 if (dl.dl_info.link_id.c == SACCH) {
5707 /* remove L1 header */
5708 l2 := substr(l2, 2, lengthof(l2)-2);
5709 }
5710 lapdm.ab := dec_LapdmFrameAB(l2);
5711 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5712 setverdict(pass);
5713 } else {
5714 repeat;
5715 }
5716 }
5717 [] L1CTL.receive { repeat; }
5718 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005720 }
5721 }
5722
5723 f_rsl_chan_deact();
5724 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5725 f_rslem_unregister(0, g_chan_nr);
5726}
5727testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5728 var RllTestCases tcs := {
5729 /* normal SAPI3 establishment on main DCCH */
5730 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5731 };
5732 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5733}
5734testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5735 var RllTestCases tcs := {
5736 /* normal SAPI3 establishment on SACCH */
5737 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5738 }
5739 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5740}
5741
5742/* altstep to receive a LAPDm frame matching the given template */
5743private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5744 var L1ctlDlMessage dl;
5745 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5746 var LapdmFrame lapdm;
5747 var octetstring l2 := dl.payload.data_ind.payload;
5748 if (dl.dl_info.link_id.c == SACCH) {
5749 /* remove L1 header */
5750 l2 := substr(l2, 2, lengthof(l2)-2);
5751 }
5752 if (ischosen(exp.ab)) {
5753 lapdm.ab := dec_LapdmFrameAB(l2);
5754 } else if (ischosen(exp.b4)) {
5755 lapdm.b4 := dec_LapdmFrameB4(l2);
5756 } else if (ischosen(exp.bbis)) {
5757 lapdm.bbis := dec_LapdmFrameBbis(l2);
5758 }
5759 log("Rx LAPDm ", lapdm);
5760 if (match(lapdm, exp)) {
5761 setverdict(pass);
5762 } else {
5763 repeat;
5764 }
5765 }
5766 [] L1CTL.receive { repeat; }
5767}
5768private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5769 timer T := t;
5770 T.start;
5771 alt {
5772 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005774 }
5775 [] as_l1_exp_lapdm(exp);
5776 }
5777}
5778
5779/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5780private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5781 /* send SABM from MS -> BTS */
5782 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5783 /* expect RLL EST IND on Abis */
5784 alt {
5785 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5786 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5787 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005789 }
5790 [] RSL.receive { repeat; }
5791 }
5792 /* expect UA from BTS -> MS */
5793 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5794}
5795
5796/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5797private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5798 var RllTestCase tc := g_pars.spec.rll;
5799
5800 f_l1_tune(L1CTL);
5801 RSL.clear;
5802
5803 /* activate the logical channel */
5804 f_est_dchan();
5805 L1CTL.clear;
5806
5807 /* first establish the link-layer */
5808 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5809
5810 /* then send the DISC */
5811 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5812 /* ... and expect the REL IND on the RSL side */
5813 alt {
5814 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5815 setverdict(pass);
5816 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005817 /* We also expect to receive the measurements */
5818 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005819 }
5820
5821 /* release the channel */
5822 f_rsl_chan_deact();
5823 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5824 f_rslem_unregister(0, g_chan_nr);
5825}
5826testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5827 var RllTestCases tcs := {
5828 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5829 };
5830 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5831}
5832
5833testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5834 var RllTestCases tcs := {
5835 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5836 };
5837 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5838}
5839testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5840 var RllTestCases tcs := {
5841 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5842 };
5843 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5844}
5845testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5846 var RllTestCases tcs := {
5847 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5848 };
5849 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5850}
5851
5852/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5853private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5854 var RllTestCase tc := g_pars.spec.rll;
5855 f_l1_tune(L1CTL);
5856 RSL.clear;
5857
5858 /* activate the logical channel */
5859 f_est_dchan();
5860 L1CTL.clear;
5861
5862 /* first establish the link-layer */
5863 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5864
5865 /* then send the REL REQ via RSL */
5866 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5867 /* ... and expect the DISC on the Um side */
5868 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005869 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005870 /* FIXME: send a UA in resposne to the DISC */
5871 }
5872 }
5873
5874 /* release the channel */
5875 f_rsl_chan_deact();
5876 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5877 f_rslem_unregister(0, g_chan_nr);
5878}
5879testcase TC_rll_rel_req() runs on test_CT {
5880 var RllTestCases tcs := {
5881 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5882 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5883 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5884 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5885 };
5886 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
5887}
5888
5889/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
5890testcase TC_rll_data_req() runs on test_CT {
5891}
5892
5893/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
5894testcase TC_rll_data_ind() runs on test_CT {
5895}
5896
5897/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
5898private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
5899 var RllTestCase tc := g_pars.spec.rll;
5900
5901 f_l1_tune(L1CTL);
5902 RSL.clear;
5903
5904 f_est_dchan();
5905 L1CTL.clear;
5906
5907 /* Send UNITDATA REQ on RSL side */
5908 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
5909 /* Expect it to arrive on the other side */
5910 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02005911 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005912 } else {
Harald Weltee613f962018-04-18 22:38:16 +02005913 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01005914 }
5915
5916 /* release the channel */
5917 f_rsl_chan_deact();
5918 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5919 f_rslem_unregister(0, g_chan_nr);
5920}
5921testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
5922 var octetstring l3 := f_rnd_octstring(15);
5923 var RllTestCases tcs := {
5924 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5925 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5926 };
5927 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5928}
5929testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
5930 var octetstring l3 := f_rnd_octstring(19);
5931 var RllTestCases tcs := {
5932 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5933 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5934 };
5935 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
5936}
5937
5938/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
5939private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
5940 var RllTestCase tc := g_pars.spec.rll;
5941
5942 f_l1_tune(L1CTL);
5943 RSL.clear;
5944
5945 f_est_dchan();
5946 L1CTL.clear;
5947
5948 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02005949 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01005950 /* Expdct RLL UNITDATA IND on RSL side */
5951 alt {
5952 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
5953 setverdict(pass);
5954 }
5955 [] RSL.receive { repeat; }
5956 }
5957
5958 /* release the channel */
5959 f_rsl_chan_deact();
5960 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5961 f_rslem_unregister(0, g_chan_nr);
5962}
5963testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02005964 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01005965 var RllTestCases tcs := {
5966 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
5967 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
5968 };
5969 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5970}
5971testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5972 var octetstring l3 := f_rnd_octstring(18);
5973 var RllTestCases tcs := {
5974 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5975 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5976 };
5977 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5978}
5979
Harald Weltee613f962018-04-18 22:38:16 +02005980/***********************************************************************
5981 * Encryption Related
5982 ***********************************************************************/
5983
5984/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5985function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5986 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5987 if (link_id.c == SACCH) {
5988 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5989 } else {
5990 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5991 }
5992}
5993
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005994/* Expect (or not expect) other kinds of messages */
5995private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5996 [exp_any] RSL.receive { repeat; }
5997 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005999 }
6000}
6001
Harald Weltee613f962018-04-18 22:38:16 +02006002/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006003private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006004 RslLinkId link_id,
6005 octetstring l3,
6006 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006007 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006008) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006009 timer T := 3.0;
6010 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6011 T.start;
6012 /* Expect RLL UNITDATA IND on RSL side */
6013 alt {
6014 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6015 setverdict(pass);
6016 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006017 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006018 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006019 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006021 }
Harald Weltee613f962018-04-18 22:38:16 +02006022 }
6023}
6024
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006025/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6026private function f_data_mo(
6027 RslLinkId link_id,
6028 boolean p, uint3_t nr, uint3_t ns,
6029 octetstring l3,
6030 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006031 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006032) runs on ConnHdlr {
6033 timer T := 3.0;
6034 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6035 T.start;
6036 /* Expect RLL DATA IND on RSL side */
6037 alt {
6038 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6039 setverdict(pass);
6040 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006041 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006042 [] as_rsl_any_ind(exp_any);
6043 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006045 }
6046 }
6047}
6048
Harald Weltee613f962018-04-18 22:38:16 +02006049/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
6050function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
6051 f_l1_tune(L1CTL);
6052 f_est_dchan(true);
6053
6054 /* now we actually need to transmit some data both ways to check if the encryption works */
6055 var L1ctlDlMessage dl;
6056
Stefan Sperling603d98e2018-07-25 16:47:28 +02006057 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006058 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6059
6060 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6061 f_unitdata_mt(link_id, l3);
6062
6063 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6064 f_unitdata_mo(link_id, l3);
6065
6066 /* release the channel */
6067 f_rsl_chan_deact();
6068 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6069 f_rslem_unregister(0, g_chan_nr);
6070}
6071testcase TC_chan_act_a51() runs on test_CT {
6072 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6073 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6074 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6075}
6076testcase TC_chan_act_a52() runs on test_CT {
6077 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6078 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6079 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6080}
6081testcase TC_chan_act_a53() runs on test_CT {
6082 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6083 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6084 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6085}
6086
Eric Wildf1827a72019-05-28 17:37:35 +02006087/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6088 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
6089function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
6090 f_l1_tune(L1CTL);
6091 f_est_dchan(true);
6092
6093 /* now we actually need to transmit some data both ways to check if the encryption works */
6094 var L1ctlDlMessage dl;
6095
6096 var octetstring l3 := f_rnd_octstring(20);
6097 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6098
6099 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6100 f_unitdata_mt(link_id, l3);
6101
6102 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6103 f_unitdata_mo(link_id, l3);
6104
6105 var RSL_Message rsl;
6106 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6107
6108 /* modify key to break proper encryption */
6109 g_pars.encr.key := f_rnd_octstring(8);
6110 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6111 rsl.ies := rsl.ies & { ei };
6112 RSL.send(rsl);
6113
6114 timer T0 := 1.0;
6115 T0.start;
6116 /* Expect RSL MODIFY ACK */
6117 alt {
6118 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6119 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6121 }
6122 [] T0.timeout {
6123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6124 }
6125 }
6126
6127 var octetstring l3msg := f_rnd_octstring(15);
6128 timer T1 := 3.0;
6129 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6130 due to broken encryption */
6131 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6132 T1.start;
6133 alt {
6134 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6136 }
6137 [] T1.timeout {
6138 setverdict(pass);
6139 }
6140 }
6141
6142 /* release the channel */
6143 f_rsl_chan_deact();
6144 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6145 f_rslem_unregister(0, g_chan_nr);
6146}
6147testcase TC_rsl_modify_encr() runs on test_CT {
6148 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6149 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6150 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6151}
Harald Weltee613f962018-04-18 22:38:16 +02006152
6153/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6154function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6155 /* L3 payload doesn't matter, as it is passed transparently */
6156 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6157 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6158 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6159
6160 f_l1_tune(L1CTL);
6161
6162 /* first establish a dedicated channel in the clear */
6163 f_est_dchan(false);
6164
6165 /* Establish ABM */
6166 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6167
6168 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6169 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6170 /* expect the L3 to arrive still unencrypted on the MS side */
6171 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6172
6173 /* configure L1 to apply ciphering */
6174 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6175 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6176
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006177 /* send first ciphered I-frame in response and expect it on RSL */
6178 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006179
6180 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6181 * and hence enable encryption also on the downlink */
6182
6183 /* expect bi-directional communication work in encrypted mode */
6184 f_unitdata_mo(link_id, f_rnd_octstring(15));
6185 f_unitdata_mt(link_id, f_rnd_octstring(15));
6186
6187 /* release the channel */
6188 f_rsl_chan_deact();
6189 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6190 f_rslem_unregister(0, g_chan_nr);
6191}
6192testcase TC_encr_cmd_a51() runs on test_CT {
6193 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6194 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6195 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6196}
6197testcase TC_encr_cmd_a52() runs on test_CT {
6198 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6199 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6200 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6201}
6202testcase TC_encr_cmd_a53() runs on test_CT {
6203 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6204 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6205 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6206}
6207
6208private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6209 var LapdmFrame lf;
6210 var octetstring reenc;
6211
6212 /* decode the LAPDm frame */
6213 if (ischosen(exp_match.ab)) {
6214 lf.ab := dec_LapdmFrameAB(enc);
6215 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006217 }
6218
6219 /* check if decoder result matches expectation */
6220 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006222 } else {
6223 log(name, ": matched");
6224 setverdict(pass);
6225 }
6226
6227 /* test if re-encoded frame equals original input */
6228 reenc := enc_LapdmFrame(lf);
6229 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006231 } else {
6232 setverdict(pass);
6233 }
6234}
6235
6236testcase TC_lapdm_selftest() runs on test_CT {
6237 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6238 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6239 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6240 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6241 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6242 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6243 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6244}
6245
Stefan Sperling4880be42018-08-07 18:12:59 +02006246/***********************************************************************
6247 * DTX Related (see GSM 05.08, section 8.3)
6248 ***********************************************************************/
6249
6250/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6251function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6252 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6253 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6254 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6255 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6256}
6257function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6258 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6259 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6260}
6261function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6262 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6263 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6264 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6265 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6266}
6267function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6268 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6269 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6270 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6271 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6272 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6273 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6274 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6275 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6276}
6277
6278function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6279 var L1ctlDlMessage dl;
6280 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6281 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6282 var GsmFrameNumber first_fn;
6283 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006284 var integer nfill_frames_sacch := 0;
6285 var integer nfill_frames_nonsacch := 0;
6286 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006287 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6288 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006289 const integer frame_dtx_tchf_mod := 104;
6290 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6291 * which operates in terms of blocks rather than frames. */
6292 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6293 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006294 timer T := 5.0;
6295
6296 f_l1_tune(L1CTL);
6297 RSL.clear;
6298 L1CTL.clear;
6299
6300 /* activate TCHF signalling channel */
6301 f_est_dchan(false);
6302
6303 T.start;
6304 alt {
6305 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6306 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6307 var octetstring l2 := dl.payload.data_ind.payload;
6308
6309 if (is_first_frame) {
6310 is_first_frame := false;
6311 first_fn := dl.dl_info.frame_nr;
6312 }
6313
6314 if (dl.dl_info.link_id.c == SACCH) {
6315 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6316 if (not match(l2_fill_frame_sacch, l2)) {
6317 repeat;
6318 }
6319 } else if (not match(l2_fill_frame, l2)) {
6320 repeat;
6321 }
6322
6323 if (dtxd) {
6324 if (not f_g_chan_is_tchf()) {
6325 T.stop;
6326 f_rsl_chan_deact();
6327 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006328 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 +02006329 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006330 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006331 T.stop;
6332 f_rsl_chan_deact();
6333 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006334
6335 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6336 * 2 SACCH, 1 TCH/F */
6337 expected_fill_frames := 3;
6338
6339 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6340 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6341 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006343 } else {
6344 setverdict(pass);
6345 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006346 } else {
6347 if (dl.dl_info.link_id.c == SACCH) {
6348 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006349 repeat;
6350 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006351 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6352 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6353 * we should only see the subset of frames numbers which correspond to a block boundary.
6354 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6355 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6356 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6357 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6358 repeat;
6359 }
6360 }
6361 log("Received DTX TCH fill frame with bad frame number: ", fn,
6362 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6363 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6364 f_rsl_chan_deact();
6365 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006367 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006368 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006369 if (dl.dl_info.link_id.c == SACCH) {
6370 nfill_frames_sacch := nfill_frames_sacch + 1;
6371 } else {
6372 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6373 }
6374 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006375 T.stop;
6376 if (f_g_chan_is_tchf()) {
6377 /* Without DTX we can expect 25 fill frames for every 104 frames.
6378 * (24 FACCH + 1 SACCH filling) */
6379 expected_fill_frames := 25;
6380 } else if (f_g_chan_is_tchh()) {
6381 /* We can expect 2 fill frames for every 104 frames. */
6382 expected_fill_frames := 2;
6383 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6384 /* We can expect 5 fill frames for every 104 frames. */
6385 expected_fill_frames := 5;
6386 } else {
6387 f_rsl_chan_deact();
6388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006390 }
6391
6392 f_rsl_chan_deact();
6393 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006394
6395 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006396 setverdict(pass);
6397 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006398 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6399 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006401 }
6402 } else {
6403 repeat;
6404 }
6405 }
6406 }
6407 [] L1CTL.receive { repeat; }
6408 [] T.timeout {
6409 f_rsl_chan_deact();
6410 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006412 }
6413 }
6414}
6415
6416function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6417 f_test_l2_fill_frames(false);
6418}
6419
6420function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6421 f_test_l2_fill_frames(true);
6422}
6423
6424function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6425 var ConnHdlr vc_conn;
6426 var ConnHdlrPars pars;
6427 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006428 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006429 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6430 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6431 if (dtxd) {
6432 if (i >= 4) { /* DTX is only allowed on TCH/F */
6433 break;
6434 }
6435 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6436 } else {
6437 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6438 }
6439 vc_conn.done;
6440 }
6441}
6442
6443/* Verify that L2 fill frames are sent on TCH in signaling mode if
6444 * there is nothing to transmit while DTX is disabled on downlink. */
6445testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6446 f_tch_sign_l2_fill_frame(false);
6447}
6448
6449/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6450 * there is nothing to transmit while DTX is enabled on downlink. */
6451testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6452 f_tch_sign_l2_fill_frame(true);
6453}
Harald Welte0472ab42018-03-12 15:02:26 +01006454
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006455testcase TC_chopped_ipa_ping() runs on test_CT {
6456 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6457}
6458
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006459testcase TC_chopped_ipa_payload() runs on test_CT {
6460 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6461}
6462
Harald Welte0472ab42018-03-12 15:02:26 +01006463/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6464/* protocol error as per 44.006 */
6465/* link layer failure (repetition of I-frame N200 times without ACK */
6466/* repetition of SABM or DISC N200 times without ACK */
6467/* receptiom of SABM in multi-frame established state */
6468
6469
Harald Welte68e495b2018-02-25 00:05:57 +01006470/* TODO Areas:
6471
6472* channel activation
6473** with BS_Power / MS_Power, bypassing power control loop
6474** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006475** with timing advance from initial activation on
6476* mode modify
6477** encryption
6478** multirate
6479* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006480** unsupported algorithm
6481* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006482* BS Power Control
6483* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006484* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006485* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006486** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006487* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006488** DATA_IND from BTS->PCU
6489** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006490
6491*/
Harald Welte70767382018-02-21 12:16:40 +01006492
6493control {
6494 execute( TC_chan_act_stress() );
6495 execute( TC_chan_act_react() );
6496 execute( TC_chan_deact_not_active() );
6497 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006498 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006499 execute( TC_sacch_filling() );
6500 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006501 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006502 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006503 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006504 execute( TC_sacch_chan_act_ho_async() );
6505 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006506 execute( TC_rach_content() );
6507 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006508 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006509 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006510 execute( TC_rach_load_idle_thresh0() );
6511 execute( TC_rach_load_idle_below_thresh() );
6512 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006513 execute( TC_meas_res_sign_tchf() );
6514 execute( TC_meas_res_sign_tchh() );
6515 execute( TC_meas_res_sign_sdcch4() );
6516 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006517 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006518 execute( TC_tx_power_start_ramp_up_bcch() );
Eric Wildae8f2622019-06-18 17:05:11 +02006519 execute( TC_rsl_bs_pwr_static_ass() );
6520 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006521 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006522 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006523 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006524 execute( TC_rsl_ms_pwr_dyn_up() );
6525 execute( TC_rsl_ms_pwr_dyn_down() );
6526 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6527 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006528 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006529 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006530 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006531 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006532 execute( TC_paging_imsi_80percent() );
6533 execute( TC_paging_tmsi_80percent() );
6534 execute( TC_paging_imsi_200percent() );
6535 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006536 execute( TC_rsl_protocol_error() );
6537 execute( TC_rsl_mand_ie_error() );
6538 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006539 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006540 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006541 execute( TC_si_sched_2bis() );
6542 execute( TC_si_sched_2ter() );
6543 execute( TC_si_sched_2ter_2bis() );
6544 execute( TC_si_sched_2quater() );
6545 execute( TC_si_sched_13() );
6546 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006547 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006548 execute( TC_ipa_crcx_twice_not_active() );
6549 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006550 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006551 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006552
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006553 if (mp_pcu_socket != "") {
6554 execute( TC_pcu_act_req() );
6555 execute( TC_pcu_act_req_wrong_ts() );
6556 execute( TC_pcu_act_req_wrong_bts() );
6557 execute( TC_pcu_act_req_wrong_trx() );
6558 execute( TC_pcu_deact_req() );
6559 execute( TC_pcu_deact_req_wrong_ts() );
6560 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006561 if (mp_l1_supports_gprs) {
6562 execute( TC_pcu_data_req_pdtch() );
6563 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006564 execute( TC_pcu_data_req_wrong_bts() );
6565 execute( TC_pcu_data_req_wrong_trx() );
6566 execute( TC_pcu_data_req_wrong_ts() );
6567 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006568 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006569 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006570 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006571 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006572 execute( TC_pcu_data_req_imm_ass_pch() );
6573 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006574 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006575 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006576 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006577 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006578 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006579 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006580 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006581 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006582 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006583 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006584 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006585 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006586 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006587 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006588 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006589 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006590 execute( TC_dyn_osmo_pdch_act_deact() );
6591 execute( TC_dyn_osmo_pdch_double_act() );
6592 execute( TC_dyn_ipa_pdch_act_deact() );
6593 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6594
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006595 } else {
6596 log("PCU socket path not available, skipping PCU tests");
6597 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006598
Harald Welte3d04ae62018-04-04 20:29:05 +02006599 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006600 execute( TC_dyn_osmo_pdch_tchf_act() );
6601 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006602 execute( TC_dyn_ipa_pdch_tchf_act() );
6603 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006604
6605 execute( TC_rll_est_ind() );
6606 execute( TC_rll_est_req_DCCH_3() );
6607 execute( TC_rll_est_req_ACCH_3() );
6608 execute( TC_rll_rel_ind_DCCH_0() );
6609 execute( TC_rll_rel_ind_DCCH_3() );
6610 execute( TC_rll_rel_ind_ACCH_0() );
6611 execute( TC_rll_rel_ind_ACCH_3() );
6612 execute( TC_rll_rel_req() );
6613 execute( TC_rll_unit_data_req_DCCH() );
6614 execute( TC_rll_unit_data_req_ACCH() );
6615 execute( TC_rll_unit_data_ind_DCCH() );
6616 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006617
6618 execute( TC_chan_act_a51() );
6619 execute( TC_chan_act_a52() );
6620 execute( TC_chan_act_a53() );
6621 execute( TC_encr_cmd_a51() );
6622 execute( TC_encr_cmd_a52() );
6623 execute( TC_encr_cmd_a53() );
6624
Harald Welteee25aae2019-05-19 14:32:37 +02006625 execute( TC_err_rep_wrong_mdisc() );
6626 execute( TC_err_rep_wrong_msg_type() );
6627 execute( TC_err_rep_wrong_sequence() );
6628
Harald Weltee613f962018-04-18 22:38:16 +02006629 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006630
6631 execute( TC_tch_sign_l2_fill_frame() );
6632 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006633
6634 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006635 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006636}
6637
6638
6639}