blob: a60a50fb5535d9254c6babe20ccf1cc312f0422d [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;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Harald Welte70767382018-02-21 12:16:40 +0100114}
115
Harald Welte629cc6b2018-03-11 17:19:05 +0100116type record of RslChannelNr ChannelNrs;
117
Harald Welte70767382018-02-21 12:16:40 +0100118type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100119 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100120 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100121 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100122 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100123 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100124 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100125
126 /* L1CTL port (for classic tests) */
127 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100128
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700129 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700130 port TRXC_CODEC_PT BTS_TRXC;
131 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100132
Harald Weltef50e3ae2018-09-10 10:27:56 +0200133 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100134 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200135 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100136
Harald Welte883340c2018-02-28 18:59:29 +0100137 /* PCU Interface of BTS */
138 port PCUIF_CODEC_PT PCU;
139 var integer g_pcu_conn_id;
140 /* Last PCU INFO IND we received */
141 var PCUIF_Message g_pcu_last_info;
142
Harald Welte48494ca2018-02-25 16:59:50 +0100143 /* SI configuration */
144 var SystemInformationConfig si_cfg := {
145 bcch_extended := false,
146 si1_present := false,
147 si2bis_present := false,
148 si2ter_present := false,
149 si2quater_present := false,
150 si7_present := false,
151 si8_present := false,
152 si9_present := false,
153 si13_present := false,
154 si13alt_present := false,
155 si15_present := false,
156 si16_present := false,
157 si17_present := false,
158 si2n_present := false,
159 si21_present := false,
160 si22_present := false
161 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100162
163 /* all logical channels available on the BTS */
164 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100165 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100166}
167
168/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200169type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100170 port L1CTL_PT L1CTL;
171
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700172 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700173 port TRXC_CODEC_PT BTS_TRXC;
174 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100175
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200176 /* port to be initialized optionally to access BSC VTY */
177 port TELNETasp_PT BSCVTY;
178
Harald Welte70767382018-02-21 12:16:40 +0100179 timer g_Tguard;
180 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
181
182 var ConnHdlrPars g_pars;
183 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100184 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200185
186 /* PCU Interface of BTS */
187 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100188}
189
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700190function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700191 var bitstring trx_mask := '00000000'B;
192 var integer trx_count := 0;
193 var RSLEm_Event ev;
194 timer T;
195
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 Yanitskiy89db3e02020-06-22 17:49:39 +0700206 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700207 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700208 T.start(mp_ipa_up_timeout);
209 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700210 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700211 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
212 /* Make sure that all transceivers use unique stream ID */
213 if (trx_mask[enum2int(ev.sid)] == '1'B) {
214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
215 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
216 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 /* This message (RF RESource INDication) is sent by the IUT itself */
219 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
220 trx_mask[enum2int(ev.sid)] := '1'B;
221 trx_count := trx_count + 1;
222
223 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
224 if (trx_count < mp_transceiver_num) { repeat; }
225 }
226 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
227 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
228 [] T.timeout {
229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
230 "Timeout waiting for RSL bring up");
231 }
232 }
Harald Welte70767382018-02-21 12:16:40 +0100233}
234
235type record ConnHdlrPars {
236 RslChannelNr chan_nr,
237 RSL_IE_ChannelMode chan_mode,
238 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100239 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200240 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200241 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700242 BtsBand bts0_band optional,
243
244 /* Frequency hopping parameters (disabled if absent) */
245 MaioHsn maio_hsn optional,
246 /* MA bitmap to be indicated in RR Immediate Assignment */
247 MobileAllocation ma_map,
248 /* The actual Mobile Allocation (ARFCN list) to be used */
249 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100250}
251
252/* Test-specific parameters */
253type union TestSpecUnion {
254 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100255}
256
Harald Welte82ccef72018-02-25 16:17:33 +0100257template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100258 max_retrans := RACH_MAX_RETRANS_7,
259 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100260 cell_barr_access := false,
261 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100262 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100263};
264
Harald Weltef10153f2018-02-25 16:34:05 +0100265template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100266 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200267 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100268 acs := '0'B,
269 neci := true,
270 rxlev_access_min := 0
271}
272
273template (value) LocationAreaIdentification ts_LAI_default := {
274 mcc_mnc := '262F42'H,
275 lac := 42
276}
277
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700278private template (value) GPRSIndicator ts_GPRSIndicator_def := {
279 ra_colour := 0,
280 si13_pos := '0'B
281}
282
283private template (value) SI3RestOctets ts_SI3RestOctets_def
284modifies ts_SI3RestOctets := {
285 gprs_ind := {
286 presence := CSN1_H,
287 ind := ts_GPRSIndicator_def
288 }
289}
290
291private template (value) SI4RestOctets ts_SI4RestOctets_def
292modifies ts_SI4RestOctets := {
293 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700294 presence := CSN1_H,
295 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700296 }
297}
298
Harald Welte7484fc42018-02-24 14:09:45 +0100299/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100300template (value) SystemInformation ts_SI3_default := {
301 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100302 payload := {
303 si3 := {
304 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100305 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100306 ctrl_chan_desc := {
307 msc_r99 := true,
308 att := true,
309 bs_ag_blks_res := 1,
310 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100311 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100312 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
313 spare := '00'B,
314 bs_pa_mfrms := 0, /* 2 multiframes */
315 t3212 := 1 /* 6 minutes */
316 },
Harald Welte82ccef72018-02-25 16:17:33 +0100317 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100318 dn_ind := false,
319 pwrc := false,
320 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100321 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100322 },
Harald Weltef10153f2018-02-25 16:34:05 +0100323 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100324 rach_control := ts_RachCtrl_default,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700325 rest_octets := enc_SI3RestOctets(valueof(ts_SI3RestOctets_def))
Harald Welte7484fc42018-02-24 14:09:45 +0100326 }
327 }
328}
Harald Welte70767382018-02-21 12:16:40 +0100329
Harald Weltef8df4cb2018-03-10 15:15:08 +0100330template (value) SystemInformation ts_SI2_default := {
331 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100332 payload := {
333 si2 := {
334 bcch_freq_list := '00000000000000000000000000000000'O,
335 ncc_permitted := '11111111'B,
336 rach_control := ts_RachCtrl_default
337 }
338 }
339}
340
Harald Weltef8df4cb2018-03-10 15:15:08 +0100341template (value) SystemInformation ts_SI4_default := {
342 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100343 payload := {
344 si4 := {
345 lai := ts_LAI_default,
346 cell_sel_par := ts_CellSelPar_default,
347 rach_control := ts_RachCtrl_default,
348 cbch_chan_desc := omit,
349 cbch_mobile_alloc := omit,
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700350 rest_octets := enc_SI4RestOctets(valueof(ts_SI4RestOctets_def))
Harald Weltef10153f2018-02-25 16:34:05 +0100351 }
352 }
353}
354
355function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
356runs on test_CT {
357 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700358 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100359}
360
361function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
362runs on test_CT {
363 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
364 log("Setting ", rsl_si_type, ": ", si_dec);
365 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
366}
367
Harald Welte505cf9b2018-09-15 17:47:23 +0300368friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100369 map(self:BTSVTY, system:BTSVTY);
370 f_vty_set_prompts(BTSVTY);
371 f_vty_transceive(BTSVTY, "enable");
372}
373
Harald Welte505cf9b2018-09-15 17:47:23 +0300374friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200375 map(self:BSCVTY, system:BSCVTY);
376 f_vty_set_prompts(BSCVTY, "OsmoBSC");
377 f_vty_transceive(BSCVTY, "enable");
378}
379
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200380friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
381 map(self:BSCVTY, system:BSCVTY);
382 f_vty_set_prompts(BSCVTY, "OsmoBSC");
383 f_vty_transceive(BSCVTY, "enable");
384}
385
Harald Welte883340c2018-02-28 18:59:29 +0100386/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200387private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
388 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100389 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200390 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
391 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100392 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200393 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100395 }
396}
397
Harald Weltef26de0b2018-04-04 20:28:05 +0200398private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
399 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100400 timer T := 2.0;
401 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100402 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200403 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100404 return;
405 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200406 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100407
408 T.start;
409 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200410 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100411 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100413 }
414 }
415}
416
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700417private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
418 out integer trxc_conn_id) {
419 var Result res;
420
421 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
422 "", -1, -1, { udp := {} }, {});
423 if (not ispresent(res.connId)) {
424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
425 "Could not connect to the control (TRXC) interface " &
426 "of FakeTRX, check your configuration");
427 }
428 trxc_conn_id := res.connId;
429}
430
Harald Welte70767382018-02-21 12:16:40 +0100431/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200432function f_init() runs on test_CT {
433 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100434 g_AllChannels := {
435 /* TS 1..4: TCH/F */
436 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
437 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
438 /* TS 5: TCH/H */
439 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
440 /* TS 0: SDCCH/4 */
441 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
442 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
443 /* TS 6: SDCCH/8 */
444 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
445 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
446 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
447 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
448 };
449
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200450 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700451 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200452 g_AllChanTypes := {
453 /* TS 1..4: TCH/F */
454 valueof(ts_RslChanNr_Bm(1)),
455 /* TS 5: TCH/H */
456 valueof(ts_RslChanNr_Lm(5,1)),
457 /* TS 0: SDCCH/4 */
458 valueof(ts_RslChanNr_SDCCH4(0,2)),
459 /* TS 6: SDCCH/8 */
460 valueof(ts_RslChanNr_SDCCH8(6,4))
461 };
462 } else {
463 g_AllChanTypes := {
464 /* TS 1..4: TCH/F */
465 valueof(ts_RslChanNr_Bm(1)),
466 /* TS 0: SDCCH/4 */
467 valueof(ts_RslChanNr_SDCCH4(0,2)),
468 /* TS 6: SDCCH/8 */
469 valueof(ts_RslChanNr_SDCCH8(6,4))
470 };
471 }
Harald Welte70767382018-02-21 12:16:40 +0100472 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100473 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100474 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200475 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100476
477 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100478 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
479 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
480 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
481 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100482
Harald Weltef26de0b2018-04-04 20:28:05 +0200483 map(self:PCU, system:PCU);
484 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100485
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700486 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100487 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488
489 /* Init TRXC interface to FakeTRX */
490 map(self:BTS_TRXC, system:BTS_TRXC);
491 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
492
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700493 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700494 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 +0700495 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700496 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
497 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100498 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200499
500 /* Wait some extra time to make sure the BTS emits a stable carrier.
501 * (this is only relevant when running the tests with a physical BTS.) */
502 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100503}
504
Harald Welte68e495b2018-02-25 00:05:57 +0100505/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
506function f_init_l1ctl() runs on test_CT {
507 map(self:L1CTL, system:L1CTL);
508 f_connect_reset(L1CTL);
509}
510
Harald Welte70767382018-02-21 12:16:40 +0100511type function void_fn(charstring id) runs on ConnHdlr;
512
513/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700514function f_start_handler(void_fn fn, ConnHdlrPars pars,
515 boolean pcu_comp := false,
516 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100517runs on test_CT return ConnHdlr {
518 var charstring id := testcasename();
519 var ConnHdlr vc_conn;
520
521 vc_conn := ConnHdlr.create(id);
522 /* connect to RSL Emulation main component */
523 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
524 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700525
526 /* The ConnHdlr component may want to talk to some ports directly,
527 * so we disconnect it from the test_CT and connect it to the component.
528 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200529 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200530 unmap(self:PCU, system:PCU);
531 map(vc_conn:PCU, system:PCU);
532 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700533 if (trxc_comp) {
534 unmap(self:BTS_TRXC, system:BTS_TRXC);
535 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
536 }
Harald Welte70767382018-02-21 12:16:40 +0100537
538 vc_conn.start(f_handler_init(fn, id, pars));
539 return vc_conn;
540}
541
Harald Welte70767382018-02-21 12:16:40 +0100542private altstep as_Tguard() runs on ConnHdlr {
543 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100545 }
546}
547
Harald Welte990a3612019-05-27 14:02:13 +0200548friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
549 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100550}
551
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700552private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100553 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700554 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100555}
556
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700557private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100558 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700559 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100560}
561
562/* first function started in ConnHdlr component */
563private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
564runs on ConnHdlr {
565 g_pars := pars;
566 g_chan_nr := pars.chan_nr;
567
568 map(self:L1CTL, system:L1CTL);
569 f_connect_reset(L1CTL);
570
Harald Welted48c0c72019-06-05 10:01:15 +0200571 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700572 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100573 }
Harald Welte70767382018-02-21 12:16:40 +0100574
575 g_Tguard.start(pars.t_guard);
576 activate(as_Tguard());
577
578 f_rslem_register(0, pars.chan_nr);
579
580 /* call the user-supplied test case function */
581 fn.apply(id);
582}
583
Harald Welteb1726c92018-03-30 11:56:38 +0200584function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
585 boolean ignore_other := false)
586runs on ConnHdlr return RSL_Message {
587 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100588 timer T := 3.0;
589 RSL.send(tx);
590 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100591 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200592 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100593 T.stop;
594 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100595 }
Harald Welte1eba3742018-02-25 12:48:14 +0100596 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100598 }
Harald Welte21240e62018-03-11 21:43:35 +0100599 [not ignore_other] as_l1_sacch();
600 [not ignore_other] as_meas_res();
601 [not ignore_other] as_l1_dcch();
602 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100604 }
Harald Welte21240e62018-03-11 21:43:35 +0100605 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100606 }
Harald Welteb1726c92018-03-30 11:56:38 +0200607 return rx;
608}
609
610function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
611 boolean ignore_other := false)
612runs on ConnHdlr {
613 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100614}
615
Harald Welte8b01c792019-05-19 22:51:25 +0200616function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
617 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
618 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200619 if (encr_enable) {
620 /* append encryption related IEs, if requested */
621 var RSL_IE_EncryptionInfo encr_info;
622 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
623 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
624encr_info})) };
625 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200626 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200627 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100628}
629
Harald Welte70767382018-02-21 12:16:40 +0100630function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100631 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 +0100632 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100633}
634
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700635/* Default Mobile Allocation to be used for frequency hopping */
636private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
637 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
638
Harald Welte2f2b2b72019-05-31 22:24:57 +0200639friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100640 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700641 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100642 float t_guard := 20.0) := {
643 chan_nr := valueof(chan_nr),
644 chan_mode := valueof(chan_mode),
645 t_guard := t_guard,
646 l1_pars := {
647 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100648 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100649 meas_ul := {
650 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200651 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100652 rxqual := 0
653 },
654 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200655 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100656 rxqual := 0
657 }
658 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200659 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100660 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200661 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200662 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100663 },
Harald Weltee613f962018-04-18 22:38:16 +0200664 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200665 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700666 bts0_band := omit,
667 maio_hsn := maio_hsn,
668 ma_map := c_MA_null,
669 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100670}
671
Harald Welte93640c62018-02-25 16:59:33 +0100672/***********************************************************************
673 * Channel Activation / Deactivation
674 ***********************************************************************/
675
Harald Welte70767382018-02-21 12:16:40 +0100676/* Stress test: Do 500 channel activations/deactivations in rapid succession */
677function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
678 for (var integer i := 0; i < 500; i := i+1) {
679 f_rsl_chan_act(g_pars.chan_mode);
680 f_rsl_chan_deact();
681 }
682 setverdict(pass);
683}
684testcase TC_chan_act_stress() runs on test_CT {
685 var ConnHdlr vc_conn;
686 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200687 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100688 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
689 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100691}
692
693/* Test if re-activation of an already active channel fails as expected */
694function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
695 f_rsl_chan_act(g_pars.chan_mode);
696 /* attempt to activate the same lchan again -> expect reject */
697 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
698 alt {
699 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100701 }
702 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
703 setverdict(pass);
704 }
705 }
706 f_rsl_chan_deact();
707}
708testcase TC_chan_act_react() runs on test_CT {
709 var ConnHdlr vc_conn;
710 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100711 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100712 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
713 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100715}
716
717/* Attempt to de-activate a channel that's not active */
718function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
719 timer T := 3.0;
720 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
721 T.start;
722 alt {
723 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
724 setverdict(pass);
725 }
726 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100728 }
729 }
730}
731testcase TC_chan_deact_not_active() runs on test_CT {
732 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100733 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100734 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
735 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100737}
738
739/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
740function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
741 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
742 alt {
743 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100745 }
746 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
747 setverdict(pass);
748 }
749 }
750}
751private type record WrongChanNrCase {
752 RslChannelNr chan_nr,
753 charstring description
754}
755private type record of WrongChanNrCase WrongChanNrCases;
756private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
757 chan_nr := chan_nr,
758 description := desc
759}
760
761testcase TC_chan_act_wrong_nr() runs on test_CT {
762 var ConnHdlr vc_conn;
763 var ConnHdlrPars pars;
764
Harald Welte294b0a22018-03-10 23:26:48 +0100765 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100766
767 var WrongChanNrCases wrong := {
768 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
769 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
770 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
771 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
772 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
773 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
774 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
775 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
776 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
777 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
778 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
779 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
780 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
781 };
782
783 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
784 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
785 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
786 vc_conn.done;
787 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100789}
790
Harald Weltee613f962018-04-18 22:38:16 +0200791/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200792friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200793 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200794 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200795
796 /* test on each of the channels we have */
797 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
798 pars.chan_nr := valueof(g_AllChanTypes[i]);
799
800 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
801 vc_conn := f_start_handler(fn, pars);
802 vc_conn.done;
803 }
804
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200806}
807
Harald Welte93640c62018-02-25 16:59:33 +0100808/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100809 * SACCH handling
810 ***********************************************************************/
811
812private function f_exp_sacch(boolean exp) runs on ConnHdlr {
813 timer T_sacch := 3.0;
814 T_sacch.start;
815 alt {
816 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100818 }
819 [not exp] T_sacch.timeout {
820 setverdict(pass);
821 }
822 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
823 setverdict(pass);
824 }
825 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100827 }
828 [] L1CTL.receive { repeat; }
829 [] RSL.receive { repeat; }
830 }
831}
832
833/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
834private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
835 f_l1_tune(L1CTL);
836 RSL.clear;
837
838 /* activate the logical channel */
839 f_est_dchan();
840 L1CTL.clear;
841
842 /* check that SACCH actually are received as expected */
843 f_exp_sacch(true);
844
845 /* deactivate SACCH on the logical channel */
846 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
847 f_sleep(1.0);
848 L1CTL.clear;
849
850 /* check that no SACCH are received anymore */
851 f_exp_sacch(false);
852
853 /* release the channel */
854 f_rsl_chan_deact();
855 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
856}
857testcase TC_deact_sacch() runs on test_CT {
858 var ConnHdlr vc_conn;
859 var ConnHdlrPars pars;
860 f_init();
861 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
862 //for (var integer i := 0; i < 1; i := i+1) {
863 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
864 log(testcasename(), ": Starting for ", g_AllChannels[i]);
865 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
866 vc_conn.done;
867 }
868 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100870}
871
Harald Welte55700662018-03-12 13:15:43 +0100872/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100873private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
874 var L1ctlDlMessage dl;
875 /* check that the specified SI5 value is actually sent */
876 timer T_sacch := 3.0;
877 L1CTL.clear;
878 T_sacch.start;
879 alt {
880 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
881 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
882 if (match(l3, l3_exp)) {
883 setverdict(pass);
884 } else {
885 repeat;
886 }
887 }
888 [] L1CTL.receive { repeat; }
889 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100891 }
892 }
893}
894
Harald Welte55700662018-03-12 13:15:43 +0100895/* verify that given SACCH payload is not present */
896private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
897 var L1ctlDlMessage dl;
898 /* check that the specified SI5 value is actually sent */
899 timer T_sacch := 3.0;
900 L1CTL.clear;
901 T_sacch.start;
902 alt {
903 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
904 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
905 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100907 } else {
908 repeat;
909 }
910 }
911 [] L1CTL.receive { repeat; }
912 [] T_sacch.timeout {
913 setverdict(pass);
914 }
915 }
916}
917
Harald Welte629cc6b2018-03-11 17:19:05 +0100918/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100919private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
920 /* Set a known default SACCH filling for SI5 */
921 var octetstring si5 := f_rnd_octstring(19);
922 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
923
924 f_l1_tune(L1CTL);
925 RSL.clear;
926
927 /* activate the logical channel */
928 f_est_dchan();
929
930 /* check that the specified SI5 value is actually sent */
931 f_sacch_present(si5);
932
933 /* release the channel */
934 RSL.clear;
935 f_rsl_chan_deact();
936 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
937}
938testcase TC_sacch_filling() runs on test_CT {
939 var ConnHdlr vc_conn;
940 var ConnHdlrPars pars;
941 f_init();
942 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
943 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
944 log(testcasename(), ": Starting for ", g_AllChannels[i]);
945 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
946 vc_conn.done;
947 }
948 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100950}
951
Harald Welte629cc6b2018-03-11 17:19:05 +0100952/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100953private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
954 /* Set a known default SACCH filling for SI5 */
955 var octetstring si5 := f_rnd_octstring(19);
956 var octetstring si5_diff := f_rnd_octstring(19);
957 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
958
959 f_l1_tune(L1CTL);
960 RSL.clear;
961
962 log("Activating channel, expecting standard SI5");
963 /* activate the logical channel */
964 f_est_dchan();
965 /* check that the specified SI5 value is actually sent */
966 f_sacch_present(si5);
967
968 /* set channel-specific different SI5 */
969 log("Setting channel specific SACCH INFO, expecting it");
970 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
971 /* check that the specified lchan-specific value is now used */
972 f_sacch_present(si5_diff);
973
974 /* deactivate the channel and re-activate it, this should result in default SI5 */
975 log("De-activating and re-activating channel, expecting standard SI5");
976 f_rsl_chan_deact();
977 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
978 /* Verify that the TRX-wide default SACCH filling is present again */
979 f_sacch_present(si5);
980
981 /* release the channel */
982 RSL.clear;
983 f_rsl_chan_deact();
984 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
985}
986testcase TC_sacch_info_mod() runs on test_CT {
987 var ConnHdlr vc_conn;
988 var ConnHdlrPars pars;
989 f_init();
990 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
991 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
992 log(testcasename(), ": Starting for ", g_AllChannels[i]);
993 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
994 vc_conn.done;
995 }
996 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100998}
999
Harald Welte075d84c2018-03-12 13:07:24 +01001000/* Test SACCH scheduling of multiple different SI message types */
1001private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1002 var octetstring si5 := f_rnd_octstring(19);
1003 var octetstring si5bis := f_rnd_octstring(19);
1004 var octetstring si5ter := f_rnd_octstring(19);
1005 var octetstring si6 := f_rnd_octstring(19);
1006
1007 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1008 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1009 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1010 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1011
1012 f_l1_tune(L1CTL);
1013 RSL.clear;
1014
1015 /* activate the logical channel */
1016 f_est_dchan();
1017 L1CTL.clear;
1018
1019 /* check that SACCH actually are received as expected */
1020 f_sacch_present(si5);
1021 f_sacch_present(si5bis);
1022 f_sacch_present(si5ter);
1023 f_sacch_present(si6);
1024
1025 /* release the channel */
1026 f_rsl_chan_deact();
1027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1028}
1029testcase TC_sacch_multi() runs on test_CT {
1030 var ConnHdlr vc_conn;
1031 var ConnHdlrPars pars;
1032 f_init();
1033 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1034 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1035 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1036 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1037 vc_conn.done;
1038 }
1039 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001041}
1042
Harald Welte55700662018-03-12 13:15:43 +01001043/* Test if SACH information is modified as expected */
1044private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1045 var octetstring si5 := f_rnd_octstring(19);
1046 var octetstring si6 := f_rnd_octstring(19);
1047
1048 /* First, configure both SI5 and SI6 to be transmitted */
1049 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1050 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1051
1052 f_l1_tune(L1CTL);
1053 RSL.clear;
1054
1055 /* activate the logical channel */
1056 f_est_dchan();
1057 L1CTL.clear;
1058
1059 /* check that SACCH actually are received as expected */
1060 f_sacch_present(si5);
1061 f_sacch_present(si6);
1062
1063 /* disable SI6 */
1064 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1065
1066 /* check that SI5 is still transmitted */
1067 f_sacch_present(si5);
1068 /* check if SI6 is now gone */
1069 f_sacch_missing(si6);
1070
1071 /* release the channel */
1072 f_rsl_chan_deact();
1073 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1074}
1075testcase TC_sacch_multi_chg() runs on test_CT {
1076 var ConnHdlr vc_conn;
1077 var ConnHdlrPars pars;
1078 f_init();
1079 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1080 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1081 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1082 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1083 vc_conn.done;
1084 }
1085 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001087}
1088
Harald Weltec8d363c2019-05-19 20:36:48 +02001089/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1090private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1091 var octetstring si5 := f_rnd_octstring(19);
1092 var octetstring si6 := f_rnd_octstring(19);
1093 var octetstring si5_specific := f_rnd_octstring(19);
1094 var octetstring si6_specific := f_rnd_octstring(19);
1095
1096 /* First, configure both SI5 and SI6 to be transmitted */
1097 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1098 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1099
1100 f_l1_tune(L1CTL);
1101 RSL.clear;
1102
1103 /* activate channel with different SACCH filling */
1104 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1105 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1106 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1107 }));
1108 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1109 RSL_IE_Body:{sacch_info := sacch_info})) };
1110 f_est_dchan(more_ies := addl_ies);
1111
1112 /* check that SACCH actually are received as expected */
1113 f_sacch_present(si5_specific);
1114 f_sacch_present(si6_specific);
1115
1116 /* release the channel */
1117 f_rsl_chan_deact();
1118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1119}
1120testcase TC_sacch_chan_act() runs on test_CT {
1121 var ConnHdlr vc_conn;
1122 var ConnHdlrPars pars;
1123 f_init();
1124
1125 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1126 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1127 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1128 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1129 vc_conn.done;
1130 }
1131 /* TODO: do the above in parallel, rather than sequentially? */
1132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1133}
1134
Harald Welte8b01c792019-05-19 22:51:25 +02001135/* verify that SACCH DL transmission is started only if MS power IE present
1136 * see section 4.1.3 of 3GPP TS 48.058 */
1137private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1138 var octetstring si5 := f_rnd_octstring(19);
1139
1140 f_l1_tune(L1CTL);
1141 RSL.clear;
1142
1143 /* Step 1: Activate ASYNC HO channel without MS power IE */
1144
1145 /* Activate channel on BTS side */
1146 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1147 /* don't perform immediate assignment here, as we're testing non-IA case */
1148 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001149 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001150
1151 /* Verify that no DL SACCH is being received */
1152 f_sacch_missing(?);
1153
1154 f_rsl_chan_deact();
1155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1156
1157
1158 /* Step 2: Activate ASYNC HO channel with MS power IE */
1159
1160 /* Activate channel on BTS side */
1161 var RSL_IE_List addl_ies := {
1162 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1163 };
1164 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1165 /* don't perform immediate assignment here, as we're testing non-IA case */
1166 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001167 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001168
1169 /* Verify that DL SACCH is being received */
1170 f_sacch_present(si5);
1171
1172 f_rsl_chan_deact();
1173 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1174}
1175testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1176 var ConnHdlr vc_conn;
1177 var ConnHdlrPars pars;
1178 f_init();
1179
1180 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1181 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1182 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1183 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1184 vc_conn.done;
1185 }
1186 /* TODO: do the above in parallel, rather than sequentially? */
1187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1188}
1189
1190/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1191 * see section 4.1.4 of 3GPP TS 48.058 */
1192private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1193 var octetstring si5 := f_rnd_octstring(19);
1194 var RSL_IE_List addl_ies;
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* Step 1: Activate SYNC HO channel without MS power IE */
1200
1201 /* Activate channel on BTS side */
1202 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1203 /* don't perform immediate assignment here, as we're testing non-IA case */
1204 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001205 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001206
1207 /* Verify that no DL SACCH is being received */
1208 f_sacch_missing(?);
1209
1210 f_rsl_chan_deact();
1211 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1212
1213
1214 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1215
1216 /* Activate channel on BTS side */
1217 addl_ies := {
1218 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1219 };
1220 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1221 /* don't perform immediate assignment here, as we're testing non-IA case */
1222 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001223 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001224
1225 /* Verify that no DL SACCH is being received */
1226 f_sacch_missing(?);
1227
1228 f_rsl_chan_deact();
1229 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1230
1231
1232 /* Step 2b: Activate SYNC HO channel with TA IE */
1233
1234 /* Activate channel on BTS side */
1235 addl_ies := {
1236 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1237 };
1238 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1239 /* don't perform immediate assignment here, as we're testing non-IA case */
1240 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001241 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001242
1243 /* Verify that no DL SACCH is being received */
1244 f_sacch_missing(?);
1245
1246 f_rsl_chan_deact();
1247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1248
1249
1250 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1251
1252 /* Activate channel on BTS side */
1253 addl_ies := {
1254 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1255 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1256 };
1257 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1258 /* don't perform immediate assignment here, as we're testing non-IA case */
1259 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001260 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001261
1262 /* Verify that DL SACCH is being received */
1263 f_sacch_present(si5);
1264
1265 f_rsl_chan_deact();
1266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1267}
1268testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1269 var ConnHdlr vc_conn;
1270 var ConnHdlrPars pars;
1271 f_init();
1272
1273 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1274 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1275 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1276 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1277 vc_conn.done;
1278 }
1279 /* TODO: do the above in parallel, rather than sequentially? */
1280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1281}
Harald Welte629cc6b2018-03-11 17:19:05 +01001282
1283
1284/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001285 * RACH Handling
1286 ***********************************************************************/
1287
Harald Welte8c24c2b2018-02-26 08:31:31 +01001288/* like L1SAP_IS_PACKET_RACH */
1289private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001290 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291 return true;
1292 }
1293 return false;
1294}
1295
1296/* generate a random RACH for circuit-switched */
1297private function f_rnd_ra_cs() return OCT1 {
1298 var OCT1 ra;
1299 do {
1300 ra := f_rnd_octstring(1);
1301 } while (ra_is_ps(ra));
1302 return ra;
1303}
1304
Harald Welte883340c2018-02-28 18:59:29 +01001305/* generate a random RACH for packet-switched */
1306private function f_rnd_ra_ps() return OCT1 {
1307 var OCT1 ra;
1308 do {
1309 ra := f_rnd_octstring(1);
1310 } while (not ra_is_ps(ra));
1311 return ra;
1312}
1313
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001314/* generate a random 11-bit RA (packet-switched only) */
1315private function f_rnd_ra11_ps() return BIT11 {
1316 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1317 return int2bit(ra11, 11);
1318}
1319
Harald Welte8c24c2b2018-02-26 08:31:31 +01001320/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1321testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001322 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001323 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001324 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001325
Harald Welte8c24c2b2018-02-26 08:31:31 +01001326 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001327 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001328 for (var integer i := 0; i < 1000; i := i+1) {
1329 var OCT1 ra := f_rnd_ra_cs();
1330 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1331 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001333 }
1334 fn_last := fn;
1335
1336 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001337 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001338 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001339 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001340 T.stop;
1341 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001342 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001344 }
1345 [] RSL_CCHAN.receive { repeat; }
1346 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001347 test_failed := true;
1348 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001349 }
1350 }
1351 }
Maxba06feb2019-03-05 10:52:46 +01001352 if (test_failed) {
1353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001354 }
Maxba06feb2019-03-05 10:52:46 +01001355 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001357}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001358
1359/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1360testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001361 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001362 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001363 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001364 f_l1_tune(L1CTL);
1365
1366 var GsmFrameNumber fn_last := 0;
1367 for (var integer i := 0; i < 1000; i := i+1) {
1368 var OCT1 ra := f_rnd_ra_cs();
1369 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1370 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001372 }
1373 fn_last := fn;
1374 }
1375 var integer rsl_chrqd := 0;
1376 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001377 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001378 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001379 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001380 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001381 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001382 repeat;
1383 }
1384 [] RSL_CCHAN.receive { repeat; }
1385 [] T.timeout { }
1386 }
1387 if (rsl_chrqd == 1000) {
1388 setverdict(pass);
1389 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001391 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001393}
1394
Harald Welte3453ab42019-05-24 21:19:58 +02001395private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1396 var charstring bts_str := "bts " & int2str(bts_nr);
1397 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1398}
1399
1400/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1401private template integer tr_rach_slots_per_interval := (90 .. 130);
1402
1403/* Expect 0 RACH load on an idle BTS that has just started up */
1404testcase TC_rach_load_idle_thresh0() runs on test_CT {
1405 var ASP_RSL_Unitdata rx_ud;
1406
1407 f_init_vty_bsc();
1408 /* send load indications even at 0% load */
1409 f_vty_load_ind_thresh(0);
1410 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1411 f_sleep(2.0);
1412
1413 f_init();
1414
1415 timer T := 5.0;
1416 T.start;
1417 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001418 [] 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 +02001419 setverdict(pass);
1420 repeat;
1421 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001422 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001423 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1424 repeat;
1425 }
1426 [] RSL_CCHAN.receive {
1427 repeat;
1428 }
1429 [] T.timeout { }
1430 }
1431
1432 f_vty_load_ind_thresh(10);
1433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1434}
1435
1436/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1437testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1438 var ASP_RSL_Unitdata rx_ud;
1439
1440 f_init_vty_bsc();
1441 f_init();
1442
1443 timer T := 5.0;
1444 T.start;
1445 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001446 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001447 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1448 repeat;
1449 }
1450 [] RSL_CCHAN.receive {
1451 repeat;
1452 }
1453 [] T.timeout {
1454 setverdict(pass);
1455 }
1456 }
1457
1458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1459}
1460
1461/* Expect 0 RACH load on an idle BTS that has just started up */
1462testcase TC_rach_load_count() runs on test_CT {
1463 var ASP_RSL_Unitdata rx_ud;
1464 var integer load_access_count := 0;
1465
1466 f_init_vty_bsc();
1467 /* send load indications even at 0% load */
1468 f_vty_load_ind_thresh(0);
1469 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1470 f_sleep(2.0);
1471 f_init();
1472
1473 f_init_l1ctl();
1474 f_sleep(1.0);
1475 f_l1_tune(L1CTL);
1476
1477 var GsmFrameNumber fn_last := 0;
1478 for (var integer i := 0; i < 1000; i := i+1) {
1479 var OCT1 ra := f_rnd_ra_cs();
1480 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1481 if (fn == fn_last) {
1482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1483 }
1484 fn_last := fn;
1485 }
1486
1487 timer T := 5.0;
1488 T.start;
1489 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001490 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001491 -> value rx_ud {
1492 var RSL_IE_Body ie;
1493 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1494 load_access_count := load_access_count + ie.rach_load.access_count;
1495 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1496 setverdict(fail, "Access count cannot be < Busy count");
1497 }
1498 repeat;
1499 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001500 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001501 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1502 repeat;
1503 }
1504 [] RSL_CCHAN.receive {
1505 repeat;
1506 }
1507 [] T.timeout { }
1508 }
1509 if (load_access_count == 1000) {
1510 setverdict(pass);
1511 } else {
1512 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1513 }
1514
1515 f_vty_load_ind_thresh(10);
1516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1517}
1518
Harald Welte54a2a2d2018-02-26 09:14:05 +01001519private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001520 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001521 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001522 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001523 f_sleep(0.5);
1524
1525 /* Transmit RACH request + wait for confirmation */
1526 var OCT1 ra := f_rnd_ra_cs();
1527 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1528
1529 /* Check for expected result */
1530 timer T := 1.5;
1531 T.start;
1532 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001533 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001534 setverdict(pass);
1535 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001536 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001538 }
1539 [] RSL_CCHAN.receive { repeat; }
1540 [not expect_pass] T.timeout {
1541 setverdict(pass);
1542 }
1543 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001545 }
1546 }
1547}
1548
1549/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1550testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001551 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001552 f_init_l1ctl();
1553 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001554 f_sleep(1.0);
1555
1556 /* default max-ta is 63 (full range of GSM timing advance */
1557
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001558 /* We allow early arrival up to 2 symbols */
1559 f_rach_toffs(-1*256, true);
1560 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001561 f_rach_toffs(-10*256, false);
1562
1563 /* 0 / 32 / 63 bits is legal / permitted */
1564 f_rach_toffs(0, true);
1565 f_rach_toffs(32*256, true);
1566 f_rach_toffs(63*256, true);
1567
1568 /* more than 63 bits is not legal / permitted */
1569 f_rach_toffs(64*256, false);
1570 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001572}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001573
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001574function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1575 var GsmFrameNumber fn;
1576 var RSL_Message rm;
1577
1578 f_l1_tune(L1CTL);
1579 RSL.clear;
1580
1581 /* Generate a random Handover Reference */
1582 var integer ho_ref := oct2int(f_rnd_octstring(1));
1583
1584 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1585 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1586 RSL_IE_Body:{ handover_ref := ho_ref }));
1587
1588 /* Activate a channel on the BTS side (no encryption) */
1589 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1590 act_type := t_RSL_IE_ActType_HO_SYNC);
1591
1592 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1593 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001594 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001595
1596 /* Send handover Access Burst */
1597 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1598
1599 /* TODO: test mismatching Handover Reference, and missing IE */
1600
1601 /* Wait for handover detection */
1602 timer T := 3.0;
1603 T.start;
1604 alt {
1605 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1606 log("Handover RACH has been detected: ", rm);
1607 setverdict(pass);
1608 }
1609 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1611 log2str("RSL_CHAN_RQD was not expected: ", rm));
1612 }
1613 [] RSL.receive { repeat; }
1614 [] T.timeout {
1615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1616 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1617 }
1618 }
1619
1620 /* Release the channel */
1621 f_rsl_chan_deact();
1622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1623}
1624
1625/* Test handover RACH detection */
1626testcase TC_ho_rach() runs on test_CT {
1627 var ConnHdlrPars pars;
1628 var ConnHdlr vc_conn;
1629
1630 f_init();
1631
1632 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1633 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1634 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1635 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1636 vc_conn.done;
1637 }
1638
1639 /* TODO: do the above in parallel, rather than sequentially? */
1640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1641}
1642
Harald Welte93640c62018-02-25 16:59:33 +01001643/***********************************************************************
1644 * Measurement Processing / Reporting
1645 ***********************************************************************/
1646
Harald Welte70767382018-02-21 12:16:40 +01001647template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1648 spare := '0'B,
1649 lpd := 0,
1650 sapi := sapi,
1651 c_r := c_r,
1652 ea := true
1653}
1654
Harald Welted879bd92018-03-12 15:01:23 +01001655template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001656 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001657 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001658 len := 0, /* overwritten */
1659 m := false,
1660 el := 1,
1661 payload := pl
1662}
1663
1664/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1665altstep as_l1_sacch() runs on ConnHdlr {
1666 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001667 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001668 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001669 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 +01001670 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001671 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001672
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001673 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1674 g_pars.l1_pars.ms_power_level, false,
1675 g_pars.l1_pars.ms_actual_ta);
1676
1677 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1678 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1679
1680 log("Sending Measurement Report: ", l1h, l2);
1681 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001682 repeat;
1683 }
1684}
1685
1686altstep as_l1_dcch() runs on ConnHdlr {
1687 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001688 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001689 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1690 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001691 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1692 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001693 repeat;
1694 }
1695}
1696
1697type record MeasElem {
1698 uint6_t rxlev,
1699 uint3_t rxqual
1700}
1701
1702type record MeasElemFS {
1703 MeasElem full,
1704 MeasElem sub
1705}
1706
1707type record ConnL1Pars {
1708 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001709 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001710 MeasElemFS meas_ul,
1711 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001712 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001713 uint5_t ms_power_level,
1714 uint8_t ms_actual_ta
1715}
1716
1717/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1718private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1719 return 63 + (toffs256s/256);
1720}
1721
Harald Welted5684392018-03-10 18:22:04 +01001722private function f_max(integer a, integer b) return integer {
1723 if (a > b) {
1724 return a;
1725 } else {
1726 return b;
1727 }
1728}
1729
1730private function f_min(integer a, integer b) return integer {
1731 if (a < b) {
1732 return a;
1733 } else {
1734 return b;
1735 }
1736}
1737
1738/* compute negative tolerance val-tolerance, ensure >= min */
1739private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1740 val := val - tolerance;
1741 return f_max(val, min);
1742}
1743
1744/* compute positive tolerance val+tolerance, ensure <= max */
1745private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1746 val := val + tolerance;
1747 return f_min(val, max);
1748}
1749
1750/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1751private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1752return template integer {
1753 var template integer ret;
1754 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1755 return ret;
1756}
1757
1758
Harald Welte70767382018-02-21 12:16:40 +01001759/* build a template for matching measurement results against */
1760private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1761 var ConnL1Pars l1p := g_pars.l1_pars;
1762 var template RSL_IE_UplinkMeas ul_meas := {
1763 len := 3,
1764 rfu := '0'B,
1765 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001766 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001767 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001768 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001769 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001770 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1771 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001772 supp_meas_info := omit
1773 };
Harald Welte685d5982018-02-27 20:42:05 +01001774 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001775 ul_meas.len := (3+8);
1776 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001777 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001778 toa256_min := ?,
1779 toa256_max := ?,
1780 toa256_std_dev := ?
1781 }
Harald Welte685d5982018-02-27 20:42:05 +01001782 }
Harald Welte70767382018-02-21 12:16:40 +01001783 var template RSL_IE_BS_Power bs_power := {
1784 reserved := 0,
1785 epc := false,
1786 fpc := false,
1787 power_level := l1p.bs_power_level
1788 };
1789 var template RSL_IE_L1Info l1_info := {
1790 ms_power_lvl := l1p.ms_power_level,
1791 fpc := false,
1792 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001793 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001794 };
1795 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001796 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001797 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1798 ?, t_toffs);
1799}
1800
Philipp Maierdd841d32019-12-17 14:44:54 +01001801/* build a template for matching measurement results that do not contain any
1802 * MS related measurement (l1_info, l3_info and ms timing offset). */
1803private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1804 var ConnL1Pars l1p := g_pars.l1_pars;
1805 var template RSL_IE_UplinkMeas ul_meas := {
1806 len := 3,
1807 rfu := '0'B,
1808 dtx_d := l1p.dtx_enabled,
1809 rxlev_f_u := ?,
1810 reserved1 := '00'B,
1811 rxlev_s_u := ?,
1812 reserved2 := '00'B,
1813 rxq_f_u := ?,
1814 rxq_s_u := ?,
1815 supp_meas_info := omit
1816 };
1817 if (l1p.toa256_enabled) {
1818 ul_meas.len := (3+8);
1819 ul_meas.supp_meas_info := {
1820 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1821 toa256_min := ?,
1822 toa256_max := ?,
1823 toa256_std_dev := ?
1824 }
1825 }
1826 var template RSL_IE_BS_Power bs_power := {
1827 reserved := 0,
1828 epc := false,
1829 fpc := false,
1830 power_level := l1p.bs_power_level
1831 };
1832
1833 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1834}
1835
Harald Welte70767382018-02-21 12:16:40 +01001836/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001837altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001838 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001839 var boolean chan_est := false;
1840
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001841 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001842
1843 /* Receive osmocom specific measurement reports. This is the normal
1844 * case. Here we verify that the measurement reports we sent are
1845 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001846 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1847 /* increment counter of next to-be-expected meas rep */
1848 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1849 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001850 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001851
1852 /* The following two cases may only happen in the beginning
1853 * of the channel establishment phase. Once we have received
1854 * the "our" measurement report the first time, the channel
1855 * is established and empty or hardcoded TRXCON reports must
1856 * not occur anymore. */
1857 chan_est := true;
1858
1859 repeat;
1860 }
1861
1862 /* When the BTS has established the channel, the MS might need slightly
1863 * more time to establish the channel and actually start sending. The
1864 * result is then a measurement report that just lacks the measurement
1865 * information of the MS. This is normal and we tolerate this behavior. */
1866 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1867 /* increment counter of next to-be-expected meas rep */
1868 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1869 /* Re-start the timer expecting the next MEAS RES */
1870 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001871 repeat;
1872 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001873
1874 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1875 * measurements if the TTCN3 side does not supply measurement input in
1876 * time. In those cases TRXCON will either use a cached measurement
1877 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1878 * report the templates above will not match. We tolerate this
1879 * behavior, but only once. */
1880 [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 +01001881 /* increment counter of next to-be-expected meas rep */
1882 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1883 if (g_first_meas_res) {
1884 g_first_meas_res := false;
1885 repeat;
1886 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001888 }
Harald Welte70767382018-02-21 12:16:40 +01001889 }
1890 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001892 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001893 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001895 }
1896}
1897
Harald Weltee613f962018-04-18 22:38:16 +02001898private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1899 select (rsl_alg_id) {
1900 case (RSL_ALG_ID_A5_0) { return 0; }
1901 case (RSL_ALG_ID_A5_1) { return 1; }
1902 case (RSL_ALG_ID_A5_2) { return 2; }
1903 case (RSL_ALG_ID_A5_3) { return 3; }
1904 case (RSL_ALG_ID_A5_4) { return 4; }
1905 case (RSL_ALG_ID_A5_5) { return 5; }
1906 case (RSL_ALG_ID_A5_6) { return 6; }
1907 case (RSL_ALG_ID_A5_7) { return 7; }
1908 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1910 /* Make compiler happy by calling mtc.stop here. It is already
1911 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001912 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001913 }
1914 }
1915}
1916
1917private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1918 select (rsl_alg_id) {
1919 case (RSL_ALG_ID_A5_1) { return '000'B; }
1920 case (RSL_ALG_ID_A5_2) { return '001'B; }
1921 case (RSL_ALG_ID_A5_3) { return '010'B; }
1922 case (RSL_ALG_ID_A5_4) { return '011'B; }
1923 case (RSL_ALG_ID_A5_5) { return '100'B; }
1924 case (RSL_ALG_ID_A5_6) { return '101'B; }
1925 case (RSL_ALG_ID_A5_7) { return '110'B; }
1926 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1928 /* Make compiler happy by calling mtc.stop here. It is already
1929 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001930 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001931 }
1932 }
1933}
1934
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001935/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1936private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1937 var GsmFrameNumber fn;
1938 timer T := 8.0;
1939
1940 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1941 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1942
1943 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1944 /* Send the actual RACH */
1945 fn := f_L1CTL_RACH(L1CTL, ra);
1946
1947 T.start;
1948 alt {
1949 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1950 [] T.timeout {
1951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1952 }
1953 }
1954 T.stop
1955 return fn;
1956}
Harald Weltee613f962018-04-18 22:38:16 +02001957
Harald Welte70767382018-02-21 12:16:40 +01001958/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001959private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001960 var GsmFrameNumber fn;
1961 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001962 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001963 var integer ra := 23;
1964
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001965 /* Send RACH request and wait for ChanReq */
1966 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001967
1968 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001969 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001970
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001971 /* Craft channel description (with or without frequency hopping parameters) */
1972 if (ispresent(g_pars.maio_hsn)) {
1973 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1974 } else {
1975 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1976 }
1977
Harald Welte70767382018-02-21 12:16:40 +01001978 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001979 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001980 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1981
1982 /* receive IMM.ASS on MS side */
1983 var ImmediateAssignment ia_um;
1984 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001985
1986 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1987 if (ch_desc.h != ia_um.chan_desc.h) {
1988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1989 }
1990
Harald Welte70767382018-02-21 12:16:40 +01001991 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001992 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001993 /* enable encryption, if requested */
1994 if (encr_enable) {
1995 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1996 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1997 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001998
1999 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002000}
2001
2002/* establish DChan, verify existance + contents of measurement reports */
2003function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002004 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002005 RSL.clear;
2006
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002007 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002008 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002009 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002010 }
Harald Welte70767382018-02-21 12:16:40 +01002011
2012 f_est_dchan();
2013
2014 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2015 * RSL measurement reports on Abis side */
2016 timer T := 8.0;
2017 T.start;
2018 alt {
2019 [] as_l1_sacch();
2020 [] as_meas_res();
2021 [] as_l1_dcch();
2022 [] L1CTL.receive { repeat; }
2023 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002024 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002025 * of any earlier errors, so if we reach this timeout, we're good */
2026 setverdict(pass);
2027 }
2028 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002030 }
2031 }
2032 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002033 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002034}
Harald Welte0472ab42018-03-12 15:02:26 +01002035
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002036/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2037private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002038 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002039 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2040 timer Tup := 10.0;
2041 Tup.start;
2042 alt {
2043 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2044 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2045 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002046
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002047 if (rx_lvl != max_rx_lvl) {
2048 repeat;
2049 }
2050 Tup.stop;
2051 }
2052 [] L1CTL.receive { repeat; }
2053 [] Tup.timeout {
2054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2055 log2str("Didn't reach full power ", max_rx_lvl));
2056 }
2057 }
2058 return max_rx_lvl;
2059}
2060
2061/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2062private function f_verify_ramp_up() runs on ConnHdlr {
2063 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002064 var integer initial_rx_lvl := -1;
2065 var integer last_rx_lvl := -1;
2066 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2067
2068 timer T := 2.0;
2069 alt {
2070 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2071 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2072 log("Received rx_level=", rx_lvl);
2073 if (initial_rx_lvl == -1) {
2074 initial_rx_lvl := rx_lvl;
2075 last_rx_lvl := rx_lvl;
2076
2077 /* Expect a somehow low value during first received messages */
2078 if (initial_rx_lvl >= max_rx_lvl / 2) {
2079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2080 log2str("Detected high initial tx power during ramp up: ",
2081 initial_rx_lvl , ", full power is", max_rx_lvl));
2082 }
2083 }
2084
2085 /* received Rx level bigger than maximum allowed power by CN */
2086 if (rx_lvl > max_rx_lvl) {
2087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2088 log2str("Detected Tx power higher than full power: ",
2089 rx_lvl , " > ", max_rx_lvl));
2090 }
2091
2092 /* Make sure it never decreases, since we are rumping up */
2093 if (last_rx_lvl > rx_lvl) {
2094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2095 log2str("Detected Tx power decrease during ramp up: ",
2096 last_rx_lvl , " -> ", rx_lvl));
2097 }
2098
2099 if (rx_lvl == max_rx_lvl and not T.running) {
2100 /* We reached the maximum power, start timer and receive
2101 /* a few more to make sure we don't surpass it */
2102 log("Reached full power, wating a bit more until success");
2103 T.start;
2104 }
2105
2106 last_rx_lvl := rx_lvl;
2107 repeat;
2108 }
2109 [] L1CTL.receive { repeat; }
2110 [] T.timeout { }
2111 }
2112
2113 /* We didn't increase tx power during ramp up */
2114 if (initial_rx_lvl < last_rx_lvl) {
2115 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2116 } else {
2117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2118 log2str("No Tx power increase during whole ramp up: ",
2119 initial_rx_lvl , " -> ", last_rx_lvl));
2120 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002121}
2122
2123/* verify BTS ramps power down to rx_level 0 */
2124private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2125 var L1ctlDlMessage l1_dl;
2126 var integer last_rx_lvl := max_rx_lvl;
2127
2128 timer Tdown := 5.0;
2129 Tdown.start;
2130 alt {
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2132 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2133 log("Received rx_level=", rx_lvl);
2134
2135 /* received Rx level bigger than maximum allowed power by CN */
2136 if (rx_lvl > max_rx_lvl) {
2137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2138 log2str("Detected Tx power higher than full power: ",
2139 rx_lvl , " > ", max_rx_lvl));
2140 }
2141
2142 /* Make sure it never increases, since we are rumping down */
2143 if (last_rx_lvl < rx_lvl) {
2144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2145 log2str("Detected Tx power increase during ramp up: ",
2146 last_rx_lvl , " -> ", rx_lvl));
2147 }
2148
2149 last_rx_lvl := rx_lvl;
2150 if (last_rx_lvl != 0) {
2151 repeat;
2152 }
2153 /* we reached power level 0, we are done */
2154 Tdown.stop;
2155 }
2156 [] L1CTL.receive { repeat; }
2157 [] Tdown.timeout { }
2158 }
2159
2160 /* We didn't increase tx power during ramp down */
2161 if (max_rx_lvl > last_rx_lvl) {
2162 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2163 } else {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 log2str("No Tx power decrease during whole ramp down: ",
2166 max_rx_lvl , " -> ", last_rx_lvl));
2167 }
2168}
2169
2170/* Verify Tx power reduction and ramping up during BTS bring up */
2171function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
2172 f_l1_tune(L1CTL);
2173 RSL.clear;
2174
2175 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002176
2177 setverdict(pass);
2178}
2179testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2180 var ConnHdlr vc_conn;
2181 var ConnHdlrPars pars;
2182 f_init();
2183 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2184 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2185 pcu_comp := false, trxc_comp := true);
2186 vc_conn.done;
2187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2188}
2189
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002190/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
2191function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
2192 f_connhdlr_init_vty_bsc();
2193
2194 f_l1_tune(L1CTL);
2195 RSL.clear;
2196
2197 /* Wait until BTS is started and at full power */
2198 var integer max_rx_lvl := f_wait_ramp_up();
2199 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2200
2201 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2202 f_verify_ramp_down(max_rx_lvl);
2203
2204 setverdict(pass);
2205}
2206testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2207 var ConnHdlr vc_conn;
2208 var ConnHdlrPars pars;
2209 f_init();
2210 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2211 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2212 pcu_comp := false, trxc_comp := true);
2213 vc_conn.done;
2214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2215}
2216
Eric Wildae8f2622019-06-18 17:05:11 +02002217function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
2218 timer T := 8.0;
2219 T.start;
2220 var RSL_Message rsl;
2221 alt {
2222 [] as_l1_sacch();
2223 [] L1CTL.receive { repeat; }
2224 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2225 if (rsl.ies[3].body.bs_power.power_level == level) {
2226 setverdict(pass)
2227 } else {
2228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2229 }
2230 }
2231 [] T.timeout {
2232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2233 }
2234 }
2235}
2236
2237/* see if the rsl meas res contains our expeced bs power level
2238bs power set during assignment */
2239function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
2240 f_l1_tune(L1CTL);
2241 RSL.clear;
2242
2243 if (mp_bts_trxc_port != -1) {
2244 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2245 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2246 }
2247
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002248 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002249 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2250 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2251
2252 f_est_dchan(more_ies :={valueof(pwr)});
2253
2254 f_check_meas_bs_power_level(pwr_var);
2255
2256 f_rsl_chan_deact();
2257 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2258}
2259
2260/* see if the rsl meas res contains our expeced bs power level
2261bs power set after assignment */
2262function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
2263 f_l1_tune(L1CTL);
2264 RSL.clear;
2265
2266 if (mp_bts_trxc_port != -1) {
2267 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2268 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2269 }
2270
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002271 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002272 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2273
2274 f_est_dchan();
2275
2276 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2277
2278 f_check_meas_bs_power_level(pwr_var);
2279
2280 f_rsl_chan_deact();
2281 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2282}
2283
2284testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2285 var ConnHdlr vc_conn;
2286 var ConnHdlrPars pars;
2287 f_init();
2288 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2289 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2290 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2291 pcu_comp := false, trxc_comp := true);
2292 vc_conn.done;
2293 }
2294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2295}
2296
2297testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2298 var ConnHdlr vc_conn;
2299 var ConnHdlrPars pars;
2300 f_init();
2301 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2302 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2303 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2304 pcu_comp := false, trxc_comp := true);
2305 vc_conn.done;
2306 }
2307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2308}
2309
Eric Wild61edb7e2019-06-03 12:38:31 +02002310/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2311second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2312These power levels are valid for all bands and require no special handling */
2313function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
2314 var uint5_t pwr_var := 7;
2315 var L1ctlDlMessage l1_dl;
2316
2317 f_trxc_fake_rssi(rxlev2dbm(10));
2318 f_l1_tune(L1CTL);
2319 RSL.clear;
2320
2321 var RSL_IE_List addl_ies;
2322 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2323
2324 addl_ies := {
2325 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2326 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2327 };
2328
2329 /* establish with power parameters */
2330 f_est_dchan(more_ies := addl_ies);
2331
2332 /* set a high value to ensure L1 power control level increases */
2333 f_trxc_fake_rssi(rxlev2dbm(20));
2334
2335 timer T2 := 6.0;
2336 T2.start;
2337 alt {
2338 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002339 /* Update sent MS power to follow what BTS requests */
2340 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2341 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002342 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002343 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002344 T2.stop;
2345 }
2346 [] L1CTL.receive { repeat; }
2347 [] T2.timeout {
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2349 "Power Level in L1 header has not increased sufficiently");
2350 }
2351 }
2352
2353 /* set a low value to ensure L1 power control level decreases */
2354 f_trxc_fake_rssi(rxlev2dbm(0));
2355
2356 timer T4 := 6.0;
2357 T4.start;
2358 alt {
2359 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002360 /* Update sent MS power to follow what BTS requests */
2361 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2362 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002363 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002364 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002365 T4.stop;
2366 setverdict(pass, "Power level in L1 decreased/increased as expected");
2367 }
2368 [] L1CTL.receive { repeat; }
2369 [] T4.timeout {
2370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2371 "Power Level in L1 header has not decreased sufficiently");
2372 }
2373 }
2374
2375 f_rsl_chan_deact();
2376 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2377
2378}
2379
2380/* check that we do not exceed the max power */
2381function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
2382 var uint5_t pwr_var := 7;
2383 var L1ctlDlMessage l1_dl;
2384
2385 /* set a low value to ensure power increases */
2386 f_trxc_fake_rssi(rxlev2dbm(10));
2387 f_l1_tune(L1CTL);
2388 RSL.clear;
2389
2390 var RSL_IE_List addl_ies;
2391 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2392
2393 addl_ies := {
2394 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2395 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2396 };
2397
2398 /* establish with power parameters */
2399 f_est_dchan(more_ies := addl_ies);
2400
2401 timer T1 := 10.0;
2402 T1.start;
2403 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002404 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2405 /* Update sent MS power to follow what BTS requests */
2406 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2407 repeat;
2408 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002409 [] L1CTL.receive { repeat; }
2410 [] T1.timeout {
2411 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2412 setverdict(fail, "Power level in L1 header should not have changed");
2413 }
2414 }
2415 }
2416
2417 f_rsl_chan_deact();
2418 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2419
2420}
2421
2422/* see if we reach the band max power */
2423function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
2424 var L1ctlDlMessage l1_dl;
2425 var uint5_t pwr_var := 15;
2426 var uint5_t pwr_max_var := f_get_max_power_from_band();
2427
2428 /* set a low value to ensure power increases */
2429 f_trxc_fake_rssi(rxlev2dbm(10));
2430 f_l1_tune(L1CTL);
2431 RSL.clear;
2432
2433 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2434 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2435
2436 /* establish with fixed power level */
2437 f_est_dchan(more_ies :={valueof(pwr)});
2438
2439 /* check our initial power level */
2440 f_wait_for_l1_power_level(pwr_var);
2441
2442 /* update power param to enable power loop
2443 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2444 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2445
2446 /* wait, then check that our power level was reduced */
2447 timer T1 := 10.0;
2448 T1.start;
2449 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002450 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2451 /* Update sent MS power to follow what BTS requests */
2452 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2453 repeat;
2454 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002455 [] L1CTL.receive { repeat; }
2456 [] T1.timeout {
2457 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2458 if( f_power_level_is_highest_dbm(rcv) ){
2459 setverdict(pass, "Power level in L1 header reduced as expected");
2460 } else {
2461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2462 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2463 }
2464 }
2465 }
2466
2467 f_rsl_chan_deact();
2468 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2469
2470}
2471
2472/* see if we reach the band min power */
2473function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
2474 var L1ctlDlMessage l1_dl;
2475
2476 /* set a high value to ensure power decreases */
2477 f_trxc_fake_rssi(rxlev2dbm(50));
2478 f_l1_tune(L1CTL);
2479 RSL.clear;
2480
2481 var uint5_t pwr_var := 5;
2482 var uint5_t pwr_target_val := 15;
2483
2484 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2485 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2486
2487 /* establish with fixed power level */
2488 f_est_dchan(more_ies :={valueof(pwr)});
2489
2490 /* check our initial power level */
2491 f_wait_for_l1_power_level(pwr_var);
2492
2493 /* update power param to enable power loop
2494 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002495 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002496
2497 /* wait, then check that our power level was increased */
2498 timer T1 := 10.0;
2499 T1.start;
2500 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002501 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2502 /* Update sent MS power to follow what BTS requests */
2503 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2504 repeat;
2505 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002506 [] L1CTL.receive { repeat; }
2507 [] T1.timeout {
2508 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2509 setverdict(pass, "Power level in L1 header increased to lowest power value");
2510 } else {
2511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2512 "Power level in L1 header NOT increased to lowest power value");
2513 }
2514 }
2515 }
2516
2517 f_rsl_chan_deact();
2518 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2519
2520}
2521
Eric Wild095024b2019-06-17 15:08:57 +02002522/* see if we change the power level without receiving power parameters, which should not happen
2523rsl chan act WITHOUT power parameters */
Eric Wild280ccb82019-06-17 11:11:52 +02002524function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
2525 var L1ctlDlMessage l1_dl;
2526
2527 /* set a high value to ensure power decreases */
2528 f_trxc_fake_rssi(rxlev2dbm(50));
2529 f_l1_tune(L1CTL);
2530 RSL.clear;
2531
2532 var uint5_t pwr_var := 5;
2533
2534 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2535 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2536
2537 /* establish with fixed power level */
2538 f_est_dchan(more_ies :={valueof(pwr)});
2539
2540 /* check our initial power level */
2541 f_wait_for_l1_power_level(pwr_var);
2542
2543 /* wait, then check that our power level did not change */
2544 timer T1 := 10.0;
2545 T1.start;
2546 alt {
2547 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2548 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2550 "BS power control should not be active unless we receive a power parameters IE!");
2551 }
2552 repeat;
2553 }
2554 [] L1CTL.receive { repeat; }
2555 [] T1.timeout { setverdict(pass); }
2556 }
2557
2558 f_rsl_chan_deact();
2559 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2560
2561}
2562
Eric Wild095024b2019-06-17 15:08:57 +02002563/* see if we change the power level without receiving power parameters, which should not happen
2564ms power control WITHOUT power parameters */
2565function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
2566 var L1ctlDlMessage l1_dl;
2567
2568 /* set a high value to ensure power decreases */
2569 f_trxc_fake_rssi(rxlev2dbm(50));
2570 f_l1_tune(L1CTL);
2571 RSL.clear;
2572
2573 var uint5_t pwr_var := 5;
2574
2575 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2576 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2577
2578 /* establish with fixed power level */
2579 f_est_dchan(more_ies :={valueof(pwr)});
2580
2581 /* check our initial power level */
2582 f_wait_for_l1_power_level(pwr_var);
2583
2584 /* pwr control without power params IE, should NOT activate MS power control*/
2585 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2586
2587 /* wait, then check that our power level did not change */
2588 timer T1 := 10.0;
2589 T1.start;
2590 alt {
2591 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2592 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2594 "BS power control should not be active unless we receive a power parameters IE!");
2595 }
2596 repeat;
2597 }
2598 [] L1CTL.receive { repeat; }
2599 [] T1.timeout { setverdict(pass); }
2600 }
2601
2602 f_rsl_chan_deact();
2603 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2604
2605}
2606
Eric Wild61edb7e2019-06-03 12:38:31 +02002607function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
2608 var L1ctlDlMessage l1_dl;
2609 timer T0 := 10.0;
2610 T0.start;
2611 alt {
2612 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2613 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2615 "Power level in L1 header != signaled (RSL) power level.");
2616 }
2617 }
2618 [] L1CTL.receive { repeat; }
2619 [] T0.timeout {
2620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2621 "Timeout waiting for initial power level");
2622 }
2623 }
2624 T0.stop;
2625}
2626
2627private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2628 var IntegerRecord min_dbm_level;
2629 var IntegerRecord max_dbm_level;
2630 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2631
2632 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2633 if (min_dbm_level[i] == level) {
2634 return true;
2635 }
2636 }
2637 return false;
2638}
2639
2640private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2641 var IntegerRecord min_dbm_level;
2642 var IntegerRecord max_dbm_level;
2643 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2644
2645 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2646 if (max_dbm_level[i] == level) {
2647 return true;
2648 }
2649 }
2650 return false;
2651}
2652
2653private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2654 var IntegerRecord min_dbm_level;
2655 var IntegerRecord max_dbm_level;
2656 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2657 return max_dbm_level[0];
2658}
2659
2660type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
2661template charstring BtsBand_allGSM:= pattern "GSM???";
2662private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2663 // 45.005 4.1.1
2664 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2665 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2666 2, 1, 0};
2667 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2668 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2669 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2670 var IntegerRecord rv;
2671
2672 select(band){
2673 case (BtsBand_allGSM){
2674 rv := gsm_power;
2675 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2676 max_dbm_level := {2, 1, 0};
2677 }
2678 case("DCS1800"){
2679 rv := dcs_power;
2680 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2681 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2682 }
2683 case("PCS1900"){
2684 rv := pcs_power;
2685 min_dbm_level := {15};
2686 max_dbm_level := {30};
2687 }
2688 }
2689
2690 return rv;
2691}
2692
2693private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2694 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2695}
2696
2697testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2698 var ConnHdlr vc_conn;
2699 var ConnHdlrPars pars;
2700 f_init();
2701 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2702 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2703 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2704 pars.bts0_band := f_vty_get_bts0_band();
2705 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2706 vc_conn.done;
2707 }
2708 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2710}
2711
2712testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2713 var ConnHdlr vc_conn;
2714 var ConnHdlrPars pars;
2715 f_init();
2716 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2717 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2718 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2719 pars.bts0_band := f_vty_get_bts0_band();
2720 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2721 vc_conn.done;
2722 }
2723 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2725}
2726
2727testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2728 var ConnHdlr vc_conn;
2729 var ConnHdlrPars pars;
2730 f_init();
2731 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2732 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2733 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2734 pars.bts0_band := f_vty_get_bts0_band();
2735 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2736 vc_conn.done;
2737 }
2738 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2740}
2741
2742testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2743 var ConnHdlr vc_conn;
2744 var ConnHdlrPars pars;
2745 f_init();
2746 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2747 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2748 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2749 pars.bts0_band := f_vty_get_bts0_band();
2750 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2751 vc_conn.done;
2752 }
2753 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2755}
2756
Eric Wild280ccb82019-06-17 11:11:52 +02002757testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2758 var ConnHdlr vc_conn;
2759 var ConnHdlrPars pars;
2760 f_init();
2761 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2762 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2763 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2764 pars.bts0_band := f_vty_get_bts0_band();
2765 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2766 vc_conn.done;
2767 }
2768 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2770}
2771
Eric Wild095024b2019-06-17 15:08:57 +02002772testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2773 var ConnHdlr vc_conn;
2774 var ConnHdlrPars pars;
2775 f_init();
2776 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2777 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2778 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2779 pars.bts0_band := f_vty_get_bts0_band();
2780 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2781 vc_conn.done;
2782 }
2783 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2785}
2786
Harald Welte70767382018-02-21 12:16:40 +01002787testcase TC_meas_res_sign_tchf() runs on test_CT {
2788 var ConnHdlr vc_conn;
2789 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002790 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002791 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2792 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002793 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2794 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002795 vc_conn.done;
2796 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002798}
2799testcase TC_meas_res_sign_tchh() runs on test_CT {
2800 var ConnHdlr vc_conn;
2801 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002802 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002803 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2804 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002805 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2806 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002807 vc_conn.done;
2808 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002810}
2811testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2812 var ConnHdlr vc_conn;
2813 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002814 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002815 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2816 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002817 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2818 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002819 vc_conn.done;
2820 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002822}
2823testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2824 var ConnHdlr vc_conn;
2825 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002826 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002827 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2828 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002829 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2830 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002831 vc_conn.done;
2832 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002834}
Harald Welte685d5982018-02-27 20:42:05 +01002835testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2836 var ConnHdlr vc_conn;
2837 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002838 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002839 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2840 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2841 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2842 pars.l1_pars.toa256_enabled := true;
2843 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2844 vc_conn.done;
2845 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002847}
2848
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002849/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2850 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
2851function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
2852 var L1ctlDlMessage l1_dl;
2853 var RSL_IE_MS_Power ms_power;
2854 var RSL_Message rsl;
2855 var uint5_t power_level := 0;
2856
2857 f_l1_tune(L1CTL);
2858 RSL.clear;
2859
2860 f_est_dchan();
2861
2862 ms_power.reserved := 0;
2863 ms_power.fpc_epc := false;
2864
2865 /* Send the first power control command. This will disable any BTS/TRX
2866 * internal power control and switch the MS (which is not in scope of
2867 * this test) to a constant power level. We start with a power level
2868 * of 0 */
2869 ms_power.power_level := power_level;
2870 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2871 RSL.send(rsl);
2872
2873 alt {
2874
2875 /* Pick all SACCH blocks for checking */
2876 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2877
2878 /* The first byte of the L1 header contains the power level.
2879 * The reserved bits and the fpc bit is set to 0, so we may
2880 * compare directly. */
2881 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2882 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2883 }
2884
2885 /* Signal a new power level via RSL for the next turn. */
2886 if (power_level < 31) {
2887 power_level := power_level + 1;
2888 ms_power.power_level := power_level;
2889 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2890 RSL.send(rsl);
2891 repeat;
2892 }
2893
2894 }
2895
2896 /* Ignore all other blocks */
2897 [] L1CTL.receive { repeat; }
2898
2899 }
2900
2901 f_rsl_chan_deact();
2902 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2903
2904 setverdict(pass);
2905}
2906
2907testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2908 var ConnHdlr vc_conn;
2909 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002910 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002911
2912 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2913 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2914 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2915 vc_conn.done;
2916 }
2917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2918}
Harald Welte70767382018-02-21 12:16:40 +01002919
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002920/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002921TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2922function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2923 var L1ctlDlMessage l1_dl;
2924 var uint5_t ta_to_test := 16;
2925
2926
2927 f_l1_tune(L1CTL);
2928 RSL.clear;
2929
2930 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002931 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002932
2933 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2934
2935
2936 alt {
2937
2938 /* Pick all SACCH blocks for checking */
2939 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2940
2941 /* The second byte of the L1 header contains the TA. */
2942 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2943 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2944 }
2945
2946 }
2947
2948 /* Ignore all other blocks */
2949 [] L1CTL.receive { repeat; }
2950
2951 }
2952
2953 f_rsl_chan_deact();
2954 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2955
2956 setverdict(pass);
2957}
2958
2959testcase TC_rsl_chan_initial_ta() runs on test_CT {
2960 var ConnHdlr vc_conn;
2961 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002962 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002963 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002964 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2965 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002966 vc_conn.done;
2967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2968}
2969
Eric Wilde57e1a62019-05-28 13:30:55 +02002970/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2971function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2972 var L1ctlDlMessage l1_dl;
2973 var uint5_t ms_power_level := 7;
2974
2975 var RSL_IE_MS_Power ms_power;
2976 ms_power.reserved := 0;
2977 ms_power.fpc_epc := false;
2978 ms_power.power_level := ms_power_level;
2979
2980 f_l1_tune(L1CTL);
2981 RSL.clear;
2982
2983 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2984
2985 timer T := 1.0;
2986 T.start;
2987 alt {
2988 /* Pick all SACCH blocks for checking */
2989 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2990 /* The first byte of the L1 header contains the power level.. */
2991 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2992 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2993 }
2994 }
2995 /* Ignore all other blocks */
2996 [] L1CTL.receive { repeat; }
2997 [] T.timeout {
2998 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2999 }
3000 }
3001
3002 f_rsl_chan_deact();
3003 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3004 setverdict(pass);
3005}
3006
3007testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3008 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3009 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3010}
3011
Harald Welte0472ab42018-03-12 15:02:26 +01003012/* 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 +01003013private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003014 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003015 RSL.clear;
3016
3017 f_est_dchan();
3018 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003019 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003020
3021 timer T := 40.0;
3022 T.start;
3023 alt {
3024 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3025 setverdict(pass)
3026 }
3027 [] RSL.receive { repeat };
3028 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003030 }
3031 }
3032 f_rsl_chan_deact();
3033}
3034testcase TC_conn_fail_crit() runs on test_CT {
3035 var ConnHdlr vc_conn;
3036 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003037 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003038 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3039 pars.t_guard := 60.0;
3040 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3041 vc_conn.done;
3042}
3043
Harald Welte93640c62018-02-25 16:59:33 +01003044/***********************************************************************
3045 * Paging
3046 ***********************************************************************/
3047
Harald Welte68e495b2018-02-25 00:05:57 +01003048function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
3049 if (tmsi == 'FFFFFFFF'O) {
3050 return true;
3051 } else {
3052 return false;
3053 }
3054}
Harald Welte70767382018-02-21 12:16:40 +01003055
Philipp Maier82cb0b12018-08-31 14:41:39 +02003056type record allowedFn { integer frame_nr }
3057template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3058template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3059template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3060template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3061template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3062template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3063template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3064template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3065function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
3066{
3067 var integer frame_nr_51;
3068 frame_nr_51 := frame_nr mod 51
3069
3070 var allowedFn fn_check;
3071 fn_check.frame_nr := frame_nr_51;
3072
3073 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003075 return;
3076 }
3077
3078 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3079 return;
3080 }
3081 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3082 return;
3083 }
3084 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3085 return;
3086 }
3087 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3088 return;
3089 }
3090 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3091 return;
3092 }
3093 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3094 return;
3095 }
3096 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3097 return;
3098 }
3099 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3100 return;
3101 }
3102
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003104 return;
3105}
3106
3107altstep 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 +01003108runs on test_CT {
3109 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003110 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003111 repeat;
3112 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003113 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003114 var octetstring without_plen :=
3115 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3116 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003117
3118 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3119
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003120 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3121 /* Ignore empty RR Paging Request (PCH filling) messages.
3122 * TODO: does it make sense to count them? */
3123 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003124 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3125 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003126 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003127 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3128 }
3129 } else if (match(rr, tr_PAGING_REQ2)) {
3130 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3131 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3132 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3133 }
3134 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3135 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3136 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003137 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003138 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3139 }
3140 } else if (match(rr, tr_PAGING_REQ3)) {
3141 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3142 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3143 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3144 }
3145 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3146 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3147 }
3148 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3149 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3150 }
3151 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3152 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3153 }
3154 }
3155 repeat;
3156 }
3157}
3158
3159type record PagingTestCfg {
3160 boolean combined_ccch,
3161 integer bs_ag_blks_res,
3162 float load_factor,
3163 boolean exp_load_ind,
3164 boolean exp_overload,
3165 boolean use_tmsi
3166}
3167
3168type record PagingTestState {
3169 integer num_paging_sent,
3170 integer num_paging_rcv_msgs,
3171 integer num_paging_rcv_ids,
3172 integer num_overload
3173}
3174
Harald Welte68e495b2018-02-25 00:05:57 +01003175/* Helper function for paging related testing */
3176private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003177 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003178 f_init_l1ctl();
3179 f_l1_tune(L1CTL);
3180
3181 var PagingTestState st := {
3182 num_paging_sent := 0,
3183 num_paging_rcv_msgs := 0,
3184 num_paging_rcv_ids := 0,
3185 num_overload := 0
3186 };
3187
3188 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3189 var float max_pch_imsi_per_sec;
3190 if (cfg.use_tmsi) {
3191 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3192 } else {
3193 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3194 }
3195 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3196 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003197 var float time_total := 20.0;
3198 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3199 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003200
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003201 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3202 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003203
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003204 timer T_itv := 0.0;
3205 T_itv.start;
3206 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003207 alt {
3208 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003209 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003210 st.num_overload := st.num_overload + 1;
3211 repeat;
3212 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003213 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003215 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003216 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003217 log("Rx LOAD_IND");
3218 /* FIXME: analyze/verify interval + contents */
3219 repeat;
3220 }
3221 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003222 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003223 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003224 [] T_itv.timeout {
3225 /* Send paging cmds based on elapsed time */
3226 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3227 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003228 var MobileIdentityV mi;
3229
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003230 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003231 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003232 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003233 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003234 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003235 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003236
3237 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003238 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 +02003239
3240 st.num_paging_sent := st.num_paging_sent + 1;
3241 }
3242 if (st.num_paging_sent < pkt_total) {
3243 /* Wait for interval to next PAGING COMMAND */
3244 var float time_now := T_total.read;
3245 var float next_sched := int2float(st.num_paging_sent)*interval;
3246 if (next_sched > time_now) {
3247 T_itv.start(next_sched - time_now);
3248 } else {
3249 T_itv.start(0.0);
3250 }
3251 } else {
3252 /* We are done, no need to keep counting */
3253 T_total.stop;
3254 }
3255 }
3256 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003257 }
3258 }
3259
3260 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3261 timer T_wait := 18.0;
3262 T_wait.start;
3263 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003264 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003265 [] L1CTL.receive { repeat; }
3266 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003267 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3268 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003269 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003271 }
Harald Welte68e495b2018-02-25 00:05:57 +01003272 }
3273
3274 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3275 " rcvd_ids=", st.num_paging_rcv_ids);
3276 return st;
3277}
3278
3279/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3280 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3281 * - that CCCH LOAD IND (PCH) are being generated
3282 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3283testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003284 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003285 var PagingTestCfg cfg := {
3286 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003287 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003288 load_factor := 0.8,
3289 exp_load_ind := true,
3290 exp_overload := false,
3291 use_tmsi := false
3292 };
3293 var PagingTestState st := f_TC_paging(cfg);
3294 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3296 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003297 } else {
3298 setverdict(pass);
3299 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003301}
3302
3303/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3304 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3305 * - that CCCH LOAD IND (PCH) are being generated
3306 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3307testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003308 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003309 var PagingTestCfg cfg := {
3310 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003311 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003312 load_factor := 0.8,
3313 exp_load_ind := true,
3314 exp_overload := false,
3315 use_tmsi := true
3316 };
3317 var PagingTestState st := f_TC_paging(cfg);
3318 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3320 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003321 } else {
3322 setverdict(pass);
3323 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003325}
3326
3327/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3328 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3329 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3330 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3331testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003332 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003333 var PagingTestCfg cfg := {
3334 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003335 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003336 load_factor := 2.0,
3337 exp_load_ind := true,
3338 exp_overload := true,
3339 use_tmsi := false
3340 };
3341 var PagingTestState st := f_TC_paging(cfg);
3342 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3343 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003344 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003345 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003346 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 +01003347 } else {
3348 setverdict(pass);
3349 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003351}
3352
3353/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3354 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3355 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3356 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3357testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003358 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003359 var PagingTestCfg cfg := {
3360 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003361 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003362 load_factor := 2.0,
3363 exp_load_ind := true,
3364 exp_overload := true,
3365 use_tmsi := true
3366 };
3367 var PagingTestState st := f_TC_paging(cfg);
3368 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3369 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003370 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003371 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003372 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 +01003373 } else {
3374 setverdict(pass);
3375 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003377}
3378
3379
Harald Welte93640c62018-02-25 16:59:33 +01003380/***********************************************************************
3381 * Immediate Assignment / AGCH
3382 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003383private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003384 len := 0,
3385 ma := ''B
3386}
Harald Welte93640c62018-02-25 16:59:33 +01003387
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003388template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
Vadim Yanitskiye9f68be2020-05-27 02:08:35 +07003389 uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003390 chan_nr := chan_nr,
3391 tsc := tsc,
3392 h := false,
3393 arfcn := arfcn,
3394 maio_hsn := omit
3395}
3396
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003397template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
3398 template (value) MaioHsn maio_hsn) := {
3399 chan_nr := chan_nr,
3400 tsc := tsc,
3401 h := true,
3402 arfcn := omit,
3403 maio_hsn := maio_hsn
3404}
3405
Harald Weltee8d750e2018-06-10 21:41:35 +02003406private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3407 return int2str(num_tx) & " sent, "
3408 & int2str(num_rx) & " received, "
3409 & int2str(num_del) & " deleted";
3410}
3411
3412private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3413 var L1ctlDlMessage l1_dl;
3414 timer T := 10.0;
3415 var integer num_tx := 0;
3416 var integer num_rx := 0;
3417 var integer num_del := 0;
3418 var charstring res_str;
3419 var float rx_ratio;
3420
Harald Welte10474062019-05-30 16:48:17 +02003421 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003422 f_init_l1ctl();
3423 f_l1_tune(L1CTL);
3424
3425 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003426 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003427 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3428 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003429 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003430 num_tx := num_tx+1;
3431 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003432 }
3433 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003434 T.start;
3435 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003436 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003437 num_del := num_del+1;
3438 repeat;
3439 }
3440 [] RSL_CCHAN.receive {
3441 repeat;
3442 }
3443 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3444 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3445 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3446 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3447 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003448 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003449 } else {
3450 num_rx := num_rx+1;
3451 }
3452 repeat;
3453 }
3454 [] L1CTL.receive { repeat; }
3455 [] T.timeout { }
3456 }
3457 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3458 log("AGCH test: " & res_str);
3459 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003461 }
3462 rx_ratio := int2float(num_rx) / int2float(num_tx);
3463 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 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 +02003465 } else {
3466 setverdict(pass);
3467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003469}
3470
Harald Weltee8d750e2018-06-10 21:41:35 +02003471/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3472testcase TC_imm_ass_1000_20ms() runs on test_CT {
3473 f_TC_imm_ass(1000, 0.02, 0.25);
3474}
3475
3476/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3477testcase TC_imm_ass_200_0ms() runs on test_CT {
3478 f_TC_imm_ass(200, 0.0, 0.05);
3479}
3480
3481/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3482testcase TC_imm_ass_200_76ms() runs on test_CT {
3483 f_TC_imm_ass(150, 0.076, 1.00);
3484}
3485
3486
3487
Harald Welte48494ca2018-02-25 16:59:50 +01003488/***********************************************************************
3489 * BCCH
3490 ***********************************************************************/
3491
3492/* tuple of Frame Number + decoded SI */
3493type record SystemInformationFn {
3494 GsmFrameNumber frame_number,
3495 SystemInformation si
3496}
3497
3498/* an arbitrary-length vector of decoded SI + gsmtap header */
3499type record of SystemInformationFn SystemInformationVector;
3500
3501/* an array of SI-vectors indexed by TC value */
3502type SystemInformationVector SystemInformationVectorPerTc[8];
3503
3504/* determine if a given SI vector contains given SI type at least once */
3505function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3506 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3507 var integer fn_mod51 := arr[i].frame_number mod 51;
3508 if (not bcch_ext and fn_mod51 == 2 or
3509 bcch_ext and fn_mod51 == 6) {
3510 if (arr[i].si.header.message_type == key) {
3511 return true;
3512 }
3513 }
3514 }
3515 return false;
3516}
3517
3518/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
3519function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3520 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003522 }
3523}
3524
3525/* check if a given SI vector contains given SI type at least once on any TC */
3526function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
3527 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3528 if (f_si_vecslot_contains(arr[tc], key) or
3529 f_si_vecslot_contains(arr[tc], key, true)) {
3530 return true;
3531 }
3532 }
3533 return false;
3534}
3535
3536/* determine if a given SI vector contains given SI type at least N of M times */
3537function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
3538 var integer count := 0;
3539 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003541 }
3542 for (var integer i:= 0; i < m; i := i + 1) {
3543 var integer fn_mod51 := arr[i].frame_number mod 51;
3544 if (not bcch_ext and fn_mod51 == 2 or
3545 bcch_ext and fn_mod51 == 6) {
3546 if (arr[i].si.header.message_type == key) {
3547 count := count + 1;
3548 }
3549 }
3550 }
3551 if (count >= n) {
3552 return true;
3553 } else {
3554 return false;
3555 }
3556}
3557
3558/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
3559function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
3560 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003562 }
3563}
3564
3565/* determine if a given SI vector contains given SI type at least once */
3566function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
3567 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3568 var integer fn_mod51 := arr[i].frame_number mod 51;
3569 if (not bcch_ext and fn_mod51 == 2 or
3570 bcch_ext and fn_mod51 == 6) {
3571 if (arr[i].si.header.message_type != key) {
3572 return false;
3573 }
3574 }
3575 }
3576 return true;
3577}
3578
3579/* ensure a given TC slot of the SI vector contains only given SI type */
3580function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
3581 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003583 }
3584}
3585
3586/* SI configuration of cell, against which we validate actual SI messages */
3587type set SystemInformationConfig {
3588 boolean bcch_extended,
3589 boolean si1_present,
3590 boolean si2bis_present,
3591 boolean si2ter_present,
3592 boolean si2quater_present,
3593 boolean si7_present,
3594 boolean si8_present,
3595 boolean si9_present,
3596 boolean si13_present,
3597 boolean si13alt_present,
3598 boolean si15_present,
3599 boolean si16_present,
3600 boolean si17_present,
3601 boolean si2n_present,
3602 boolean si21_present,
3603 boolean si22_present
3604}
3605
3606/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
3607function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
3608 var integer i;
3609 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3610 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003612 }
3613 }
3614 if (cfg.si1_present) {
3615 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3616 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3617 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3618 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3619 /* make sure *ALL* contain SI1 */
3620 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3621 }
3622 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3623 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3624 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3625 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3626 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3627 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3628
3629 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3630 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3631 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3632 * consecutive occurrences of TC = 4. */
3633 if (cfg.si2bis_present and not cfg.si2ter_present) {
3634 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3635 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3636 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3637 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3638 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3639 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3640 }
3641
3642 if (cfg.si7_present or cfg.si8_present) {
3643 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3644 * if System Information type 4 does not contain all information needed for cell
3645 * selection and reselection. */
3646 if (not cfg.bcch_extended) {
3647 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3648 }
3649 if (cfg.si7_present) {
3650 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3651 }
3652 if (cfg.si8_present) {
3653 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3654 }
3655 }
3656
3657 if (cfg.si2quater_present) {
3658 /* iii) System information type 2 quater is sent if needed, as determined by the system
3659 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3660 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3661 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3662 * within any of 4 consecutive occurrences of TC = 5. */
3663 if (not (cfg.bcch_extended)) {
3664 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3665 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3666 } else {
3667 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3668 }
3669 } else {
3670 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3671 }
3672 }
3673 if (cfg.si9_present) {
3674 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3675 * in system information type 3 as defined in 3GPP TS 44.018. */
3676 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3677 }
3678 if (cfg.si13_present) {
3679 /* vii) System Information type 13 is only related to the GPRS service. System Information
3680 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3681 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3682 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3683 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3684 * within any of 4 consecutive occurrences of TC=4. */
3685 if (not cfg.bcch_extended) {
3686 log("not-bccch-extended");
3687 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3688 } else {
3689 log("bccch-extended");
3690 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3691 }
3692 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003694 }
3695 }
3696 if (cfg.si16_present or cfg.si17_present) {
3697 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3698 * should not be sent in a cell where network sharing is used (see rule xv). */
3699 if (cfg.si22_present) {
3700 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3701 }
3702 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003704 }
3705 if (not cfg.bcch_extended) {
3706 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3707 }
3708 if (cfg.si16_present) {
3709 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3710 }
3711 if (cfg.si17_present) {
3712 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3713 }
3714 }
3715
3716 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3717 * broadcast information. The frequency with which they are sent is determined by the
3718 * system operator. System Information type 9 identifies the scheduling of System
3719 * Information type 18 and 20 messages. */
3720
3721 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3722 * Information Type 19 is present, then its scheduling shall be indicated in System
3723 * Information Type 9. */
3724
3725 if (cfg.si15_present) {
3726 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3727 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3728 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3729 * 4 consecutive occurrences of TC = 1. */
3730 if (not cfg.bcch_extended) {
3731 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3732 } else {
3733 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3734 }
3735 }
3736 if (cfg.si13alt_present) {
3737 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3738 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3739 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3740 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3741 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3742 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3743 * of TC = 4. */
3744 if (cfg.si13_present) {
3745 testcase.stop("Error: Cannot have SI13alt and SI13");
3746 }
3747 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003749 }
3750 if (not cfg.bcch_extended) {
3751 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3752 } else {
3753 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3754 }
3755 }
3756 if (cfg.si2n_present) {
3757 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3758 * as determined by the system operator. In the case that the message is sent on the
3759 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3760 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3761 * consecutive occurrences of TC = 4. */
3762 if (not cfg.bcch_extended) {
3763 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3764 } else {
3765 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3766 }
3767 }
3768 if (cfg.si21_present) {
3769 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3770 * determined by the system operator. If Extended Access Barring is in use in the cell
3771 * then this message is sent at least once within any of 4 consecutive occurrences of
3772 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3773 * cell then this message shall only be sent on BCCH Ext. */
3774 if (not cfg.bcch_extended) {
3775 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3776 } else {
3777 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3778 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003780 }
3781 }
3782 }
3783 if (cfg.si22_present) {
3784 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3785 * should not be sent in a cell where SoLSA is used (see rule viii). System
3786 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3787 * =2 and TC=6. */
3788 if (cfg.si16_present or cfg.si17_present) {
3789 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3790 }
3791 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3792 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003794 }
3795 if (not cfg.bcch_extended) {
3796 testcase.stop("Error: SI22 requires BCCH Extd!");
3797 } else {
3798 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3799 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3800 }
3801 }
3802}
3803
3804/* sample Systme Information for specified duration via L1CTL */
3805function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
3806 timer T := duration;
3807 var SystemInformationVectorPerTc si_per_tc;
3808 var L1ctlDlMessage l1_dl;
3809
3810 /* initialize all per-TC vectors empty */
3811 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3812 si_per_tc[i] := {};
3813 }
3814
3815 /* flush all previous L1 queued msgs */
3816 pt.clear;
3817
3818 T.start;
3819 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003820 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003821 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3822 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3823 log("Ignoring non-RR SI ", l1_dl);
3824 repeat;
3825 }
3826 var SystemInformationFn sig := {
3827 frame_number := l1_dl.dl_info.frame_nr,
3828 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3829 }
3830 var integer tc := f_gsm_compute_tc(sig.frame_number);
3831 log("SI received at TC=", tc, ": ", sig.si);
3832 /* append to the per-TC bucket */
3833 si_per_tc[tc] := si_per_tc[tc] & { sig };
3834 repeat;
3835 }
3836 [] pt.receive { repeat; }
3837 [] T.timeout { }
3838 }
3839
3840 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3841 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3842 }
3843 log("si_per_tc=", si_per_tc);
3844 return si_per_tc;
3845}
3846
3847/* helper function: Set given SI via RSL + validate scheduling.
3848 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
3849function f_TC_si_sched() runs on test_CT {
3850 var SystemInformationVectorPerTc si_per_tc;
3851 f_init_l1ctl();
3852 f_l1_tune(L1CTL);
3853
3854 /* Sample + Validate Scheduling */
3855 si_per_tc := f_l1_sample_si(L1CTL);
3856 f_validate_si_scheduling(si_cfg, si_per_tc);
3857
3858 setverdict(pass);
3859}
3860
3861testcase TC_si_sched_default() runs on test_CT {
3862 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003863 /* 2+3+4 are mandatory and set in f_init() */
3864 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003866}
3867
3868testcase TC_si_sched_1() runs on test_CT {
3869 f_init();
3870 si_cfg.si1_present := true;
3871 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003872 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003874}
3875
3876testcase TC_si_sched_2bis() runs on test_CT {
3877 f_init();
3878 si_cfg.si2bis_present := true;
3879 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3880 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003882}
3883
3884testcase TC_si_sched_2ter() runs on test_CT {
3885 f_init();
3886 si_cfg.si2ter_present := true;
3887 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3888 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003890}
3891
3892testcase TC_si_sched_2ter_2bis() runs on test_CT {
3893 f_init();
3894 si_cfg.si2bis_present := true;
3895 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3896 si_cfg.si2ter_present := true;
3897 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3898 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003900}
3901
3902testcase TC_si_sched_2quater() runs on test_CT {
3903 f_init();
3904 si_cfg.si2quater_present := true;
3905 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3906 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003908}
3909
3910testcase TC_si_sched_13() runs on test_CT {
3911 f_init();
3912 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003913 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003914 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003916}
3917
3918testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3919 f_init();
3920 si_cfg.si2bis_present := true;
3921 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3922 si_cfg.si2ter_present := true;
3923 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3924 si_cfg.si2quater_present := true;
3925 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3926 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003927 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003928 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003930}
3931
3932
Harald Welte68e495b2018-02-25 00:05:57 +01003933testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003934 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003935 /* FIXME: enable / disable individual BCCH info */
3936 //ts_RSL_BCCH_INFO(si_type, info);
3937 /* expect no ERROR REPORT after either of them *
3938 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003940}
3941
Harald Welte93640c62018-02-25 16:59:33 +01003942/***********************************************************************
3943 * Low-Level Protocol Errors / ERROR REPORT
3944 ***********************************************************************/
3945
Harald Welte01d982c2018-02-25 01:31:40 +01003946private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3947 timer T := 5.0;
3948 T.start;
3949 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003950 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01003951 setverdict(pass);
3952 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003953 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003955 }
3956 [] RSL_CCHAN.receive {
3957 repeat;
3958 }
3959 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003961 }
3962 }
3963}
3964
3965/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3966testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003967 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003968 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3969 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003970 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003971
3972 f_exp_err_rep(RSL_ERR_PROTO);
3973}
3974
3975/* Provoke a mandatory IE error and match on ERROR REPORT */
3976testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003977 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003978
3979 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3980 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003981 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003982
3983 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3984}
3985
3986/* Provoke an IE content error and match on ERROR REPORT */
3987testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003988 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003989 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3990 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003991 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01003992
3993 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3994}
3995
Harald Welteee25aae2019-05-19 14:32:37 +02003996/* attempt to activate channel with wrong RSL Message Discriminator IE */
3997function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3998 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3999 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4000 RSL.send(rsl);
4001 f_rslem_unregister(0, g_chan_nr);
4002}
4003testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4004 var ConnHdlr vc_conn;
4005 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4006
Harald Welte10474062019-05-30 16:48:17 +02004007 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004008
4009 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4010 vc_conn.done;
4011 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4012
4013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4014}
4015
4016/* Send messages with wrong message type */
4017function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
4018 var template (value) RSL_Message rsl_tx;
4019 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4020 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4021 RSL.send(rsl_tx);
4022 f_rslem_unregister(0, g_chan_nr);
4023}
4024function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
4025 var template (value) RSL_Message rsl_tx;
4026 /* we first have to activate the dedicated channel */
4027 f_rsl_chan_act(g_pars.chan_mode);
4028 /* ... to then send an invalid RLL message */
4029 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4030 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4031 RSL.send(rsl_tx);
4032 f_rslem_unregister(0, g_chan_nr);
4033}
4034testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4035 var ConnHdlr vc_conn;
4036 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4037 var template (value) RSL_Message rsl_tx;
4038
Harald Welte10474062019-05-30 16:48:17 +02004039 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004040
4041 /* Common Channel with wrong message type */
4042 RSL_CCHAN.clear;
4043 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4044 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004045 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004046 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4047
4048 /* TRX Management */
4049 RSL_CCHAN.clear;
4050 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4051 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004052 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004053 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4054
4055 /* Dedicated Channel */
4056 RSL_CCHAN.clear;
4057 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4058 vc_conn.done;
4059 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4060
4061 /* RLL */
4062 RSL_CCHAN.clear;
4063 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4064 vc_conn.done;
4065 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4066}
4067
4068/* Send messages in wrong sequence (RLL to an inactive lchan) */
4069function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
4070 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4071 f_rslem_unregister(0, g_chan_nr);
4072}
4073testcase TC_err_rep_wrong_sequence() runs on test_CT {
4074 var ConnHdlr vc_conn;
4075 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4076
Harald Welte10474062019-05-30 16:48:17 +02004077 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004078
4079 RSL_CCHAN.clear;
4080 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4081 vc_conn.done;
4082 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4083}
4084
Harald Welte93640c62018-02-25 16:59:33 +01004085/***********************************************************************
4086 * IPA CRCX/MDCX/DLCS media stream handling
4087 ***********************************************************************/
4088
Harald Weltea871a382018-02-25 02:03:14 +01004089/* Send IPA DLCX to inactive lchan */
4090function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004091 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4092 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004093}
4094testcase TC_ipa_dlcx_not_active() runs on test_CT {
4095 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004096 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004097 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4098 vc_conn.done;
4099}
Harald Welte68e495b2018-02-25 00:05:57 +01004100
Harald Weltea3f1df92018-02-25 12:49:55 +01004101/* Send IPA CRCX twice to inactive lchan */
4102function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
4103 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4104 "IPA CRCX ACK");
4105 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4106 "IPA CRCX NACK");
4107}
4108testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4109 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004110 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004111 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4112 vc_conn.done;
4113}
4114
4115/* Regular sequence of CRCX/MDCX/DLCX */
4116function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4117 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4118 "IPA CRCX ACK");
4119 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4120 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4121 var uint7_t rtp_pt2 := f_rnd_int(127);
4122 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4123 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4124 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4125 "IPA MDCX ACK");
4126 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4127 "IPA DLCX ACK");
4128}
4129testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4130 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004131 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004132 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4133 vc_conn.done;
4134}
4135
Harald Welte3ae11da2018-02-25 13:36:06 +01004136/* Sequence of CRCX, 2x MDCX, DLCX */
4137function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
4138 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4139 "IPA CRCX ACK");
4140 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4141 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4142 var uint7_t rtp_pt2 := f_rnd_int(127);
4143 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4144 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4145 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4146 "IPA MDCX ACK");
4147 /* Second MDCX */
4148 remote_ip := f_rnd_int(c_UINT32_MAX);
4149 remote_port := f_rnd_int(c_UINT16_MAX);
4150 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4151 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4152 "IPA MDCX ACK");
4153 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4154 "IPA DLCX ACK");
4155}
4156testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4157 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004158 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004159 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4160 vc_conn.done;
4161}
4162
Harald Welte9912eb52018-02-25 13:30:15 +01004163/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
4164function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
4165 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4166 "IPA CRCX NACK");
4167}
4168testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4169 var ConnHdlrPars pars;
4170 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004171 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004172
4173 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4174 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4175 vc_conn.done;
4176
4177 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4178 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4179 vc_conn.done;
4180}
4181
Harald Weltea3f1df92018-02-25 12:49:55 +01004182
Harald Welte883340c2018-02-28 18:59:29 +01004183/***********************************************************************
4184 * PCU Socket related tests
4185 ***********************************************************************/
4186
Harald Welte07bd2d22019-05-25 11:03:30 +02004187/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004188friend 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 +01004189runs on test_CT {
4190 timer T := 3.0;
4191
4192 /* we don't expect any RTS.req before PDCH are active */
4193 T.start;
4194 alt {
4195 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004197 }
4198 [] PCU.receive { repeat; }
4199 [] T.timeout { }
4200 }
4201
4202 /* Send PDCH activate request for known PDCH timeslot */
4203 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4204
4205 /* we now expect RTS.req for this timeslot (only) */
4206 T.start;
4207 alt {
4208 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4209 setverdict(pass);
4210 }
4211 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4212 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004214 }
4215 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004217 }
4218 [] PCU.receive { repeat; }
4219 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004221 }
4222 [not exp_success] T.timeout {
4223 setverdict(pass);
4224 }
4225 }
4226}
4227
Harald Welte07bd2d22019-05-25 11:03:30 +02004228/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004229friend 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 +01004230runs on test_CT {
4231 timer T := 3.0;
4232
4233 /* Send PDCH activate request for known PDCH timeslot */
4234 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4235
4236 PCU.clear;
4237 /* we now expect no RTS.req for this timeslot */
4238 T.start;
4239 alt {
4240 [] 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 +02004241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004242 }
4243 [] PCU.receive { repeat; }
4244 [] T.timeout {
4245 setverdict(pass);
4246 }
4247 }
4248}
4249
Harald Weltead033dc2019-05-25 17:28:16 +02004250friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004251 f_init();
4252 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4253}
4254
Harald Welte883340c2018-02-28 18:59:29 +01004255/* PDCH activation via PCU socket; check for presence of RTS.req */
4256testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004257 f_init_pcu_test();
4258
Harald Welte883340c2018-02-28 18:59:29 +01004259 f_TC_pcu_act_req(0, 0, 7, true);
4260}
4261
4262/* PDCH activation via PCU socket on non-PDCU timeslot */
4263testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004264 f_init_pcu_test();
4265
Harald Welte883340c2018-02-28 18:59:29 +01004266 f_TC_pcu_act_req(0, 0, 1, false);
4267}
4268
4269/* PDCH activation via PCU socket on wrong BTS */
4270testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004271 f_init_pcu_test();
4272
Harald Welte883340c2018-02-28 18:59:29 +01004273 f_TC_pcu_act_req(23, 0, 7, false);
4274}
4275
4276/* PDCH activation via PCU socket on wrong TRX */
4277testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004278 f_init_pcu_test();
4279
Harald Welte883340c2018-02-28 18:59:29 +01004280 f_TC_pcu_act_req(0, 23, 7, false);
4281}
4282
4283/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4284testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004285 f_init_pcu_test();
4286
Harald Welte883340c2018-02-28 18:59:29 +01004287 /* Activate PDCH */
4288 f_TC_pcu_act_req(0, 0, 7, true);
4289 f_sleep(1.0);
4290 /* and De-Activate again */
4291 f_TC_pcu_deact_req(0, 0, 7);
4292}
4293
4294/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4295testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004296 f_init_pcu_test();
4297
Harald Welte883340c2018-02-28 18:59:29 +01004298 f_TC_pcu_deact_req(0, 0, 1);
4299}
4300
4301/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4302testcase TC_pcu_ver_si13() runs on test_CT {
4303 const octetstring si13 := '00010203040506070909'O;
4304 var PCUIF_send_data sd;
4305 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004306 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004307
4308 /* Set SI13 via RSL */
4309 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004310
Harald Welte883340c2018-02-28 18:59:29 +01004311 T.start;
4312 alt {
4313 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4314 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4315 setverdict(pass);
4316 } else {
4317 repeat;
4318 }
4319 }
4320 [] PCU.receive { repeat; }
4321 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004323 }
4324 }
4325}
4326
4327private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4328
4329/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004330friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004331 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4332runs on test_CT
4333{
4334 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4335 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4336}
4337
4338/* 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 +02004339friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4340 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004341runs on test_CT
4342{
4343 var PCUIF_send_data sd;
4344
4345 timer T := 3.0;
4346 T.start;
4347 alt {
4348 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4349 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4350 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4351 sd.data.u.rts_req.fn, sapi, data);
4352 }
4353 [] PCU.receive { repeat; }
4354 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004356 }
4357 }
4358}
4359
4360/* Send DATA.req on invalid BTS */
4361testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004362 var TfiUsfArr tua := f_TfiUsfArrInit();
4363 var octetstring data := '0000'O & f_rnd_octstring(21);
4364
4365 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004366
Harald Welte883340c2018-02-28 18:59:29 +01004367 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004368 f_TfiUsfArrSet(tua, 7, 0);
4369 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4370 f_sleep(1.0);
4371
4372 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004373}
4374
4375/* Send DATA.req on invalid TRX */
4376testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004377 var TfiUsfArr tua := f_TfiUsfArrInit();
4378 var octetstring data := '0000'O & f_rnd_octstring(21);
4379
4380 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004381
Harald Welte883340c2018-02-28 18:59:29 +01004382 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004383 f_TfiUsfArrSet(tua, 7, 0);
4384 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4385 f_sleep(1.0);
4386
4387 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004388}
4389
4390/* Send DATA.req on invalid timeslot */
4391testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004392 var TfiUsfArr tua := f_TfiUsfArrInit();
4393 var octetstring data := '0000'O & f_rnd_octstring(21);
4394
4395 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004396
Harald Welte883340c2018-02-28 18:59:29 +01004397 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004398 f_TfiUsfArrSet(tua, 7, 0);
4399 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4400 f_sleep(1.0);
4401
4402 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004403}
4404
4405/* Send DATA.req on timeslot that hasn't been activated */
4406testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004407 var TfiUsfArr tua := f_TfiUsfArrInit();
4408 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004409
Harald Welte7162a612019-05-26 12:56:09 +02004410 f_virtphy_common();
4411
4412 f_TfiUsfArrSet(tua, 7, 0);
4413 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4414 f_sleep(1.0);
4415
4416 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004417}
4418
Harald Weltead033dc2019-05-25 17:28:16 +02004419private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004420 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4421 boolean wait_rts := true)
4422runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004423 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004424 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004425
4426 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004427 if (wait_rts) {
4428 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4429 } else {
4430 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4431 }
Harald Weltead033dc2019-05-25 17:28:16 +02004432
4433 T.start;
4434 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004435 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004436 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4437 setverdict(pass);
4438 }
Harald Welte7162a612019-05-26 12:56:09 +02004439 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4440 setverdict(fail, "Received unexpected ", rx_dl);
4441 }
Harald Weltead033dc2019-05-25 17:28:16 +02004442 [] L1CTL.receive {
4443 repeat;
4444 }
Harald Welte7162a612019-05-26 12:56:09 +02004445 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004446 setverdict(fail, "Timeout waiting for ", data);
4447 }
Harald Welte7162a612019-05-26 12:56:09 +02004448 [not expect_data] T.timeout {
4449 setverdict(pass);
4450 }
Harald Weltead033dc2019-05-25 17:28:16 +02004451 }
4452}
4453
4454private function f_disable_dynamic_ts() runs on test_CT
4455{
4456 f_init_vty_bsc();
4457 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4458 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4459 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4460 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004461 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004462}
4463
4464private function f_virtphy_common() runs on test_CT {
4465 f_disable_dynamic_ts();
4466 f_init_l1ctl();
4467 f_l1_tune(L1CTL);
4468}
4469
4470testcase TC_pcu_data_req_pdtch() runs on test_CT {
4471 var TfiUsfArr tua := f_TfiUsfArrInit();
4472 var octetstring data := '0000'O & f_rnd_octstring(21);
4473
4474 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004475
Harald Welte883340c2018-02-28 18:59:29 +01004476 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004477 f_TfiUsfArrSet(tua, 7, 0);
4478 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4479 f_sleep(1.0);
4480
4481 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004482}
4483
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004484/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004485testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004486 var TfiUsfArr tua := f_TfiUsfArrInit();
4487 var octetstring data := '0000'O & f_rnd_octstring(21);
4488
4489 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004490
Harald Welte883340c2018-02-28 18:59:29 +01004491 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004492 f_TfiUsfArrSet(tua, 7, 0);
4493 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4494 f_sleep(1.0);
4495
4496 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004497}
4498
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004499private function f_TC_pcu_ptcch_ul(uint16_t ra)
4500runs on test_CT {
4501 var template PCUIF_Message pcu_rach_ind;
4502 var PCUIF_send_data sd;
4503 var GsmFrameNumber fn;
4504 timer T;
4505
4506 /* Send an Access Burst on PTCCH/U over the Um-interface */
4507 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4508 chan_nr := ts_RslChanNr_PDCH(7),
4509 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4510
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004511 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4512 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004513
4514 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4515 T.start(52.0 * 4.615 / 1000.0);
4516 alt {
4517 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4518 log("Rx an Access Burst on the PCU interface: ", sd.data);
4519 setverdict(pass);
4520 T.stop;
4521 }
4522 [] PCU.receive { repeat; }
4523 [] T.timeout {
4524 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4525 /* Keep going, that's not the end of the world */
4526 }
4527 }
4528}
4529
4530testcase TC_pcu_ptcch() runs on test_CT {
4531 var L1ctlDlMessage dl;
4532 var octetstring data;
4533 timer T;
4534
4535 f_init_pcu_test();
4536 f_init_l1ctl();
4537 f_l1_tune(L1CTL);
4538
4539 /* Activate PDCH channel on TS7 */
4540 f_TC_pcu_act_req(0, 0, 7, true);
4541
4542 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004543 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004544
4545 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4546 for (var integer i := 0; i < 16; i := i + 1) {
4547 log("Sending an Access Burst towards the L1CTL interface");
4548 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4549 }
4550
4551 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4552 data := f_rnd_octstring(23);
4553
4554 /* Verify PTCCH/D: send a random data block, make sure it's received */
4555 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4556 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4557
4558 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4559 * let's give it more time in case if we miss the beginning. */
4560 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4561 alt {
4562 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4563 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4564 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4565 frame := data)) -> value dl {
4566 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4567 setverdict(pass);
4568 T.stop;
4569 }
4570 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4571 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4572 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4573 l2_data := data)) -> value dl {
4574 log("Rx PTCCH/D data block on L1CTL: ", dl);
4575 setverdict(pass);
4576 T.stop;
4577 }
4578 [] L1CTL.receive { repeat; }
4579 [] T.timeout {
4580 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4581 }
4582 }
4583}
4584
Harald Welte883340c2018-02-28 18:59:29 +01004585/* Send AGCH from PCU; check it appears on Um side */
4586testcase TC_pcu_data_req_agch() runs on test_CT {
4587 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004588 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004589 f_init_l1ctl();
4590 f_l1_tune(L1CTL);
4591
4592 f_TC_pcu_act_req(0, 0, 7, true);
4593 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4594
4595 T.start;
4596 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004597 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004598 setverdict(pass);
4599 }
4600 [] L1CTL.receive { repeat; }
4601 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004603 }
4604 }
4605}
4606
Harald Welte928622b2019-05-26 13:22:59 +02004607/* Send AGCH from PCU; check it appears on Um side */
4608testcase TC_pcu_data_req_pch() runs on test_CT {
4609 timer T := 3.0;
4610 f_init_pcu_test();
4611 f_init_l1ctl();
4612 f_l1_tune(L1CTL);
4613
4614 f_TC_pcu_act_req(0, 0, 7, true);
4615 /* three characters prefix: last 3 digits of IMSI as ASCII */
4616 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4617
4618 T.start;
4619 alt {
4620 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4621 setverdict(pass);
4622 }
4623 [] L1CTL.receive { repeat; }
4624 [] T.timeout {
4625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4626 }
4627 }
4628}
4629
Harald Welte883340c2018-02-28 18:59:29 +01004630/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4631testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4632 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004633 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004634 f_init_l1ctl();
4635 f_l1_tune(L1CTL);
4636
4637 /* append 3 last imsi digits so BTS can compute pagng group */
4638 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4639
4640 timer T := 0.5;
4641 T.start;
4642 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004643 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004644 /* TODO: verify paging group */
4645 setverdict(pass);
4646 }
4647 [] L1CTL.receive { repeat; }
4648 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004650 }
4651 }
4652}
4653
4654/* Send RACH from Um side, expect it to show up on PCU socket */
4655testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004656 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004657 f_init_l1ctl();
4658 f_l1_tune(L1CTL);
4659
4660 var GsmFrameNumber fn_last := 0;
4661 for (var integer i := 0; i < 1000; i := i+1) {
4662 var OCT1 ra := f_rnd_ra_ps();
4663 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4664 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004666 }
4667 fn_last := fn;
4668
4669 timer T := 2.0;
4670 T.start;
4671 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004672 [] 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 +01004673 T.stop;
4674 }
4675 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004677 }
4678 [] PCU.receive { repeat; }
4679 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004681 }
4682 }
4683 }
4684 setverdict(pass);
4685}
4686
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004687/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4688 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4689testcase TC_pcu_ext_rach_content() runs on test_CT {
4690 var template PCUIF_Message pcu_rach_ind;
4691 var GsmFrameNumber fn_last := 0;
4692 var L1ctlRachSynchSeq synch_seq;
4693 var PCUIF_BurstType pcu_bt;
4694 var GsmFrameNumber fn;
4695 var BIT11 ra11;
4696
4697 f_init_pcu_test();
4698 f_init_l1ctl();
4699 f_l1_tune(L1CTL);
4700
4701 for (var integer i := 0; i < 1000; i := i+1) {
4702 /* We need to test both TS1 & TS2 */
4703 if (i rem 2 == 0) {
4704 synch_seq := RACH_SYNCH_SEQ_TS1;
4705 pcu_bt := BURST_TYPE_1;
4706 } else {
4707 synch_seq := RACH_SYNCH_SEQ_TS2;
4708 pcu_bt := BURST_TYPE_2;
4709 }
4710
4711 ra11 := f_rnd_ra11_ps();
4712 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4713 if (fn == fn_last) {
4714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4715 "Two RACH in same FN?!?");
4716 }
4717 fn_last := fn;
4718
4719 /* Compose the expected message */
4720 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004721 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004722 ra := bit2int(ra11),
4723 is_11bit := 1,
4724 burst_type := pcu_bt,
4725 fn := fn);
4726
4727 timer T := 2.0;
4728 T.start;
4729 alt {
4730 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4731 T.stop;
4732 }
4733 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4735 }
4736 [] PCU.receive { repeat; }
4737 [] T.timeout {
4738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4739 }
4740 }
4741 }
4742 setverdict(pass);
4743}
4744
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004745private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4746runs on test_CT {
4747 var template PCUIF_send_data sdt;
4748 var PCUIF_send_data sd;
4749 var int16_t lqual_cb;
4750 timer T := 1.0;
4751
4752 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4753 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4754
4755 /* Send a random PDTCH frame over Um */
4756 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4757 '0000'O & f_rnd_octstring(21)));
4758
4759 T.start;
4760 alt {
4761 /* If expected link quality is above the threshold */
4762 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4763 lqual_cb := sd.data.u.data_ind.lqual_cb;
4764 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4765
4766 /* Make sure the actual link quality matches the expected value */
4767 if (not match(lqual_cb, lqual_cb_exp)) {
4768 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4769 "expected value ", lqual_cb_exp));
4770 } else {
4771 setverdict(pass);
4772 }
4773 }
4774 /* If expected link quality is below the threshold */
4775 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4777 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4778 }
4779 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4780 [] PCU.receive { repeat; }
4781 [lqual_cb_exp < thresh] T.timeout {
4782 log("Rx nothing, as expected");
4783 setverdict(pass);
4784 }
4785 [lqual_cb_exp >= thresh] T.timeout {
4786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4787 "Timeout waiting for PCUIF_DATA.ind");
4788 }
4789 }
4790}
4791
4792/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4793testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4794 f_init_pcu_test();
4795 PCU.clear;
4796
4797 f_init_l1ctl();
4798 f_l1_tune(L1CTL);
4799
4800 /* Activate a PDCH channel on TS7 */
4801 f_TC_pcu_act_req(0, 0, 7, true);
4802
4803 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004804 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004805
4806 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4807 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4808 var TrxcMessage ret;
4809
4810 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4811 valueof(ts_TRXC_FAKE_CI(i)));
4812
4813 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4814 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4815 }
4816}
4817
Harald Welte883340c2018-02-28 18:59:29 +01004818/* Send PAGING via RSL, expect it to shw up on PCU socket */
4819testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004820 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004821
4822 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004823 var MobileIdentityLV mi_lv;
4824 var octetstring mi_lv_enc;
4825 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004826 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004827
Harald Welte883340c2018-02-28 18:59:29 +01004828 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004829 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004830 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004831 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004832 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004833
4834 /* Fancy encoding for PCUIF */
4835 mi_lv := valueof(ts_MI_LV(mi));
4836 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4837 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004838
4839 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004840 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004841 T.start;
4842 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004843 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004844 }
4845 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004847 }
4848 [] PCU.receive { repeat; }
4849 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004851 }
4852 }
4853 }
4854 setverdict(pass);
4855}
4856
Harald Welted66c9b82019-05-25 09:03:15 +02004857/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4858testcase TC_pcu_time_ind() runs on test_CT {
4859 var PCUIF_send_data pcu_sd;
4860 var integer num_time_ind := 0;
4861 var integer first_fn, last_fn;
4862 var float test_duration := 5.0;
4863 timer T;
4864
4865 f_init_pcu_test();
4866 f_TC_pcu_act_req(0, 0, 7, true);
4867
4868 PCU.clear;
4869 T.start(test_duration);
4870 alt {
4871 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4872 num_time_ind := num_time_ind + 1;
4873 if (not isbound(first_fn)) {
4874 first_fn := pcu_sd.data.u.time_ind.fn;
4875 }
4876 last_fn := pcu_sd.data.u.time_ind.fn;
4877 repeat;
4878 }
4879 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4880 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4881 repeat;
4882 }
4883 [] PCU.receive {
4884 repeat;
4885 }
4886 [] T.timeout {}
4887 }
4888 var integer fn_expired := last_fn - first_fn;
4889 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4890
4891 /* verify the number of frames expired matches our expectation */
4892 const float c_GSM_FN_DURATION_MS := 4.61538;
4893 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004894 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004895 if (not match(fn_expired, t_fn_expected)) {
4896 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4897 }
4898
4899 /* There are three TIME.ind in every fn MOD 13 */
4900 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4901 /* Add some tolerance */
4902 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4903 if (not match(num_time_ind, t_time_ind_exp)) {
4904 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4905 }
4906
4907 setverdict(pass);
4908}
4909
Harald Welte4832c862019-05-25 14:57:18 +02004910/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4911testcase TC_pcu_rts_req() runs on test_CT {
4912 var PCUIF_send_data pcu_sd;
4913 var integer first_fn, last_fn;
4914 var integer num_rts_pdtch := 0;
4915 var integer num_rts_ptcch := 0;
4916 var float test_duration := 5.0;
4917 timer T;
4918
4919 f_init_pcu_test();
4920 f_TC_pcu_act_req(0, 0, 7, true);
4921
4922 PCU.clear;
4923 T.start(test_duration);
4924 alt {
4925 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
4926 -> value pcu_sd {
4927 num_rts_pdtch := num_rts_pdtch + 1;
4928 if (not isbound(first_fn)) {
4929 first_fn := pcu_sd.data.u.rts_req.fn;
4930 }
4931 last_fn := pcu_sd.data.u.rts_req.fn;
4932 repeat;
4933 }
4934 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
4935 -> value pcu_sd {
4936 num_rts_ptcch := num_rts_ptcch + 1;
4937 if (not isbound(first_fn)) {
4938 first_fn := pcu_sd.data.u.rts_req.fn;
4939 }
4940 last_fn := pcu_sd.data.u.rts_req.fn;
4941 repeat;
4942 }
4943 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
4944 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
4945 repeat;
4946 }
4947 [] PCU.receive {
4948 repeat;
4949 }
4950 [] T.timeout {}
4951 }
4952 var integer fn_expired := last_fn - first_fn;
4953 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
4954 ", num_rts_ptcch=", num_rts_ptcch);
4955
4956 /* verify the number of frames expired matches our expectation */
4957 const float c_GSM_FN_DURATION_MS := 4.61538;
4958 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004959 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02004960 if (not match(fn_expired, t_fn_expected)) {
4961 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4962 }
4963
4964 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
4965 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
4966 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
4967 if (not match(num_rts_ptcch, t_ptcch_exp)) {
4968 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
4969 t_ptcch_exp);
4970 }
4971
4972 /* We have 12 PDTCH blocks every 52-multiframe */
4973 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
4974 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
4975 if (not match(num_rts_pdtch, t_pdtch_exp)) {
4976 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
4977 t_pdtch_exp);
4978 }
4979
4980 setverdict(pass);
4981}
4982
Harald Welte07bd2d22019-05-25 11:03:30 +02004983/* test for generating Abis side OML ALERT from the PCU */
4984testcase TC_pcu_oml_alert() runs on test_CT {
4985 var PCUIF_send_data pcu_sd;
4986 var integer num_time_ind := 0;
4987 var integer first_fn, last_fn;
4988 var float test_duration := 5.0;
4989 timer T;
4990
4991 f_init_pcu_test();
4992 f_TC_pcu_act_req(0, 0, 7, true);
4993
4994 /* re-connect CTRL port from BTS to BSC */
4995 f_ipa_ctrl_stop();
4996 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
4997
4998 /* Send that OML Alert */
4999 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5000
5001 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5002 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5003 setverdict(pass);
5004}
5005
Harald Welteeaa9a862019-05-26 23:01:08 +02005006template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
5007 template (value) RoutingAreaIdentificationV rai,
5008 template (value) OCT1 cause) := {
5009 discriminator := '0000'B, /* overwritten */
5010 tiOrSkip := {
5011 skipIndicator := '0000'B
5012 },
5013 msgs := {
5014 rrm := {
5015 gPRS_suspensionRequest := {
5016 messageType := '00110100'B,
5017 tLLI := tlli,
5018 routingAreaIdentification := rai,
5019 suspensionCause := cause,
5020 service_Support := omit
5021 }
5022 }
5023 }
5024}
5025
5026/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5027private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5028 var PCUIF_Message first_info;
5029 var integer pcu_conn_id := -1;
5030 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5031 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5032 var OCT4 tlli := '01020304'O;
5033 var OCT1 cause := '23'O;
5034 timer T := 5.0;
5035
5036 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5037
5038 f_l1_tune(L1CTL);
5039 RSL.clear;
5040
5041 f_est_dchan();
5042 L1CTL.clear;
5043
5044 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5045
5046 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5047 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5048 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5049
5050 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5051 T.start;
5052 alt {
5053 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5054 setverdict(pass);
5055 }
5056 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5057 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5058 }
5059 [] PCU.receive {
5060 repeat;
5061 }
5062 [] T.timeout {
5063 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5064 }
5065 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005066
5067 /* release the channel */
5068 f_rsl_chan_deact();
5069 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5070 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005071}
5072testcase TC_pcu_rr_suspend() runs on test_CT {
5073 var ConnHdlrPars pars;
5074 var ConnHdlr vc_conn;
5075
5076 f_init();
5077
5078 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5079 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5080 vc_conn.done;
5081}
Harald Welte07bd2d22019-05-25 11:03:30 +02005082
Harald Weltea2e0e942019-05-27 18:12:53 +02005083/* Ensure that PCUIF socket can accept only a single connection */
5084testcase TC_pcu_socket_connect_multi() runs on test_CT {
5085 timer T := 5.0;
5086
5087 /* this (among other things) establishes the first connection to the PCUIF socket */
5088 f_init();
5089
5090 /* try to establish a second connection, expect it to fail */
5091 PCU.send(UD_connect:{mp_pcu_socket, -1});
5092 T.start;
5093 alt {
5094 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5095 setverdict(pass);
5096 }
5097 [] PCU.receive(UD_connect_result:?) {
5098 setverdict(fail, "Unexpected unix domain connect result");
5099 }
5100 [] T.timeout {
5101 setverdict(pass);
5102 }
5103 }
5104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5105}
5106
Harald Weltec8effb72019-05-27 18:23:04 +02005107/* Ensure that PCUIF socket can disconnect + reconnect */
5108testcase TC_pcu_socket_reconnect() runs on test_CT {
5109 /* this (among other things) establishes the first connection to the PCUIF socket */
5110 f_init();
5111
5112 f_sleep(1.0);
5113
5114 f_pcuif_close(PCU, g_pcu_conn_id);
5115 g_pcu_conn_id := -1;
5116
5117 f_sleep(1.0);
5118
5119 /* re-connect */
5120 PCU.clear;
5121 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5122 setverdict(pass);
5123
5124 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5125}
5126
Harald Weltebe030482019-05-27 22:29:35 +02005127/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005128private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5129runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005130 var L1ctlDlMessage l1_dl;
5131 var SystemInformation si;
5132 timer T := 5.0;
5133 T.start;
5134 alt {
5135 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
5136 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
5137 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
5138 log("Ignoring non-RR SI ", l1_dl);
5139 repeat;
5140 }
5141 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005142 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005143 repeat;
5144 }
5145 }
5146 [] pt.receive {
5147 repeat;
5148 }
5149 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5151 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005152 }
5153 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005154 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005155}
5156
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005157/* Check if GPRS Indicator is present in RR System Information of a given type */
5158private function f_si_has_gprs_indicator(RrMessageType si_type)
5159runs on test_CT return boolean {
5160 var SystemInformation si := f_get_si(L1CTL, si_type);
5161
5162 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
5163 var RestOctets ro := si.payload.si3.rest_octets;
5164 var SI3RestOctets rest := dec_SI3RestOctets(ro);
5165 return rest.gprs_ind.presence == '1'B;
5166 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
5167 var RestOctets ro := si.payload.si4.rest_octets;
5168 var SI4RestOctets rest := dec_SI4RestOctets(ro);
5169 return rest.gprs_ind.presence == '1'B;
5170 }
5171
5172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5173 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005174}
5175
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005176/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5177private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5178runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005179 /* don't call f_init() as this would connect PCU socket */
5180 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005181
5182 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005183 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005184 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005185
5186 f_init_l1ctl();
5187 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005188 f_sleep(2.0);
5189 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005190
5191 if (f_si_has_gprs_indicator(si_type)) {
5192 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005193 } else {
5194 setverdict(pass);
5195 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005196
Harald Weltebe030482019-05-27 22:29:35 +02005197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5198}
5199
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005200testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5201 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5202}
Harald Weltebe030482019-05-27 22:29:35 +02005203
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005204testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5205 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5206}
5207
5208/* Ensure that GPRS capability is advertised after PCU socket connect */
5209private function f_TC_pcu_socket_connect(RrMessageType si_type)
5210runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005211 /* this (among other things) establishes the first connection to the PCUIF socket */
5212 f_init();
5213 f_init_l1ctl();
5214 f_l1_tune(L1CTL);
5215
5216 f_sleep(2.0);
5217 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005218
5219 if (not f_si_has_gprs_indicator(si_type)) {
5220 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005221 } else {
5222 setverdict(pass);
5223 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005224
Harald Weltebe030482019-05-27 22:29:35 +02005225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5226}
5227
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005228testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5229 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5230}
Harald Weltebe030482019-05-27 22:29:35 +02005231
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005232testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5233 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5234}
5235
5236/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5237private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5238runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005239 /* this (among other things) establishes the first connection to the PCUIF socket */
5240 f_init();
5241 f_init_l1ctl();
5242 f_l1_tune(L1CTL);
5243
5244 f_pcuif_close(PCU, g_pcu_conn_id);
5245 g_pcu_conn_id := -1;
5246
5247 f_sleep(1.0);
5248
5249 /* re-connect */
5250 PCU.clear;
5251 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5252
5253 f_sleep(2.0);
5254 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005255
5256 if (f_si_has_gprs_indicator(si_type)) {
5257 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005258 } else {
5259 setverdict(pass);
5260 }
5261
5262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5263}
5264
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005265testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5266 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5267}
5268
5269testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5270 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5271}
5272
Oliver Smithf5239c72019-08-28 10:01:25 +02005273/* 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) */
5274testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5275 var SystemInformation si3 := valueof(ts_SI3_default);
5276
5277 f_init();
5278
5279 /* Verify cell_id */
5280 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5281 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5282 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005283 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5284 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5285 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005286 }
5287
5288 /* Verify LAC */
5289 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5290 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5291 if (lac_si3 != lac_pcu) {
5292 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5293 }
5294
5295 setverdict(pass);
5296}
Harald Welted66c9b82019-05-25 09:03:15 +02005297
Harald Welte3d04ae62018-04-04 20:29:05 +02005298/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005299 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005300 ***********************************************************************/
5301
5302private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5303runs on ConnHdlr {
5304 var PCUIF_send_data sd;
5305 /* Expect BTS to immediately acknowledge activation as PDCH */
5306 PCU.clear;
5307 f_rsl_chan_act(g_pars.chan_mode);
5308 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005309 timer T_wait := 2.0;
5310 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005311 alt {
5312 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5313 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 +02005314 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5315 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5316 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005317 }
5318 }
5319 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005320 [] T_wait.timeout {
5321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5322 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5323 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005324 }
5325 /* try to activate this PDCH from the PCU point of view */
5326 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5327 /* FIXME: is there a response? */
5328}
5329
5330private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5331runs on ConnHdlr {
5332 var PCUIF_send_data sd;
5333 /* Send RSL CHAN REL (deactivate) */
5334 PCU.clear;
5335 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5336 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005337 timer T_wait := 2.0;
5338 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005339 alt {
5340 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5341 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 +02005342 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5343 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5344 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005345 }
5346 }
5347 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005348 [] T_wait.timeout {
5349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5350 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5351 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005352 }
5353 /* Emulate PCU asking BTS to deactivate PDCH */
5354 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5355 alt {
5356 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5357 setverdict(pass);
5358 }
5359 [] RSL.receive { repeat; }
5360 }
5361}
5362
5363/* Activate Osmocom-style dynamic PDCH from BSC side */
5364function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
5365 var PCUIF_Message first_info;
5366 var integer ts_nr := g_chan_nr.tn;
5367 var integer trx_nr := 0;
5368 var integer bts_nr := 0;
5369 var integer pcu_conn_id := -1;
5370
5371 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5372
5373 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5374 f_sleep(3.0);
5375 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5376 setverdict(pass);
5377}
5378testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5379 var ConnHdlrPars pars;
5380 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005381 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005382
5383 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5384 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5385 vc_conn.done;
5386}
5387
5388/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
5389function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
5390 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005391 var integer pcu_conn_id := -1;
5392
5393 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5394
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005395 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5396 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5397 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005398 setverdict(pass);
5399}
5400testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5401 var ConnHdlrPars pars;
5402 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005403 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005404
5405 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5406 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5407 vc_conn.done;
5408}
5409
5410/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
5411function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
5412 var PCUIF_Message first_info;
5413 var integer ts_nr := g_chan_nr.tn;
5414 var integer trx_nr := 0;
5415 var integer bts_nr := 0;
5416 var integer pcu_conn_id := -1;
5417
5418 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5419
5420 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005421 /* Send a second Chan Activ and expect it to be NACKed */
5422 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5423 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005424 setverdict(pass);
5425}
5426testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5427 var ConnHdlrPars pars;
5428 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005429 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005430
5431 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5432 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5433 vc_conn.done;
5434}
5435
5436/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
5437function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
5438 var PCUIF_Message first_info;
5439 var integer ts_nr := g_chan_nr.tn;
5440 var integer trx_nr := 0;
5441 var integer bts_nr := 0;
5442 var integer pcu_conn_id := -1;
5443 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5444
5445 /* register for the TCH/F channel number */
5446 f_rslem_register(0, chan_nr);
5447
5448 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5449
5450 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5451 "RSL CHAN ACT");
5452 setverdict(pass);
5453}
5454testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5455 var ConnHdlrPars pars;
5456 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005457 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005458
5459 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5460 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5461 vc_conn.done;
5462}
5463
5464/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
5465function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
5466 var PCUIF_Message first_info;
5467 var integer ts_nr := g_chan_nr.tn;
5468 var integer trx_nr := 0;
5469 var integer bts_nr := 0;
5470 var integer pcu_conn_id := -1;
5471 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5472 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5473
5474 /* register for the TCH/H channel numbers */
5475 f_rslem_register(0, chan_nr[0]);
5476 f_rslem_register(0, chan_nr[1]);
5477
5478 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5479
5480 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5481 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5482 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5483 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5484 setverdict(pass);
5485}
5486testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5487 var ConnHdlrPars pars;
5488 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005489 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005490
5491 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5492 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5493 vc_conn.done;
5494}
5495
Harald Welte9bbbfb52018-04-05 09:33:19 +02005496/***********************************************************************
5497 * IPA Style Dynamic Timeslot Support
5498 ***********************************************************************/
5499
5500private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5501runs on ConnHdlr {
5502 var PCUIF_send_data sd;
5503 /* Expect BTS to immediately acknowledge activation as PDCH */
5504 PCU.clear;
5505 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5506 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005507 timer T_wait := 2.0;
5508 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005509 alt {
5510 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5511 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 +01005512 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5513 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5514 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005515 }
5516 }
5517 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005518 [] T_wait.timeout {
5519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5520 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5521 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005522 }
5523 /* try to activate this PDCH from the PCU point of view */
5524 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5525 /* FIXME: is there a response? */
5526
5527 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5528}
5529
5530private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5531runs on ConnHdlr {
5532 var PCUIF_send_data sd;
5533 /* Send RSL CHAN REL (deactivate) */
5534 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5535 PCU.clear;
5536 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005537 timer T_wait := 2.0;
5538 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005539 alt {
5540 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5541 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 +01005542 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5543 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5544 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005545 }
5546 }
5547 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005548 [] T_wait.timeout {
5549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5550 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5551 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005552 }
5553 /* Emulate PCU asking BTS to deactivate PDCH */
5554 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5555 alt {
5556 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5557 setverdict(pass);
5558 }
5559 [] RSL.receive { repeat; }
5560 }
5561}
5562
5563/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
5564function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
5565 var PCUIF_Message first_info;
5566 var integer ts_nr := g_chan_nr.tn;
5567 var integer trx_nr := 0;
5568 var integer bts_nr := 0;
5569 var integer pcu_conn_id := -1;
5570
5571 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5572
5573 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5574 f_sleep(3.0);
5575 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5576
5577 setverdict(pass);
5578
5579}
5580testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5581 var ConnHdlrPars pars;
5582 var ConnHdlr vc_conn;
5583 f_init();
5584
5585 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5586 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5587 vc_conn.done;
5588}
5589
5590/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
5591function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
5592 var PCUIF_Message first_info;
5593 var integer ts_nr := g_chan_nr.tn;
5594 var integer trx_nr := 0;
5595 var integer bts_nr := 0;
5596 var integer pcu_conn_id := -1;
5597
5598 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5599
5600 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5601 "RSL CHAN ACT");
5602 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5603 "RF CHAN REL", true);
5604 setverdict(pass);
5605}
5606testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5607 var ConnHdlrPars pars;
5608 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005609 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005610
5611 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5612 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5613 vc_conn.done;
5614}
5615
5616/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
5617function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
5618 var PCUIF_Message first_info;
5619 var integer ts_nr := g_chan_nr.tn;
5620 var integer trx_nr := 0;
5621 var integer bts_nr := 0;
5622 var integer pcu_conn_id := -1;
5623
5624 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5625
5626 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5627 "RSL CHAN ACT");
5628
5629 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5630 alt {
5631 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5632 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005634 }
5635 [] RSL.receive { repeat; }
5636 }
5637
5638 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5639 "RF CHAN REL", true);
5640 setverdict(pass);
5641}
5642testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5643 var ConnHdlrPars pars;
5644 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005645 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005646
5647 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5648 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5649 vc_conn.done;
5650}
5651
5652/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
5653function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
5654 var PCUIF_Message first_info;
5655 var integer ts_nr := g_chan_nr.tn;
5656 var integer trx_nr := 0;
5657 var integer bts_nr := 0;
5658 var integer pcu_conn_id := -1;
5659
5660 /* register for the TCH/F channel number */
5661 f_rslem_register(0, g_chan_nr);
5662
5663 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5664
5665 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5666
5667 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5668 "RSL CHAN ACT");
5669
5670 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5671
5672 setverdict(pass);
5673}
5674testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5675 var ConnHdlrPars pars;
5676 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005677 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005678
5679 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5680 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5681 vc_conn.done;
5682}
5683
5684
Harald Welte0472ab42018-03-12 15:02:26 +01005685/***********************************************************************
5686 * LAPDm / RLL related
5687 ***********************************************************************/
5688
5689private function f_tx_lapdm(template (value) LapdmFrame l,
5690 template (value) RslLinkId link_id) runs on ConnHdlr {
5691 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005692 var template (value) SacchL1Header l1h;
5693
5694 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005695 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005696 /* Compose dummy L1 header */
5697 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5698 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 +02005699 } else {
5700 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005701 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 +01005702 }
Harald Welte0472ab42018-03-12 15:02:26 +01005703}
5704
5705type record RllTestCase {
5706 uint3_t sapi,
5707 RslLinkId link_id,
5708 octetstring l3,
5709 boolean exp
5710}
5711type record of RllTestCase RllTestCases;
5712template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
5713 sapi := sapi,
5714 link_id := id,
5715 l3 := l3,
5716 exp := exp
5717}
5718
5719/* execute the same callback function with a set of different parameters (tcs) on a
5720 * variety of logical channels */
5721private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5722 var ConnHdlrPars pars;
5723 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005724 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005725
5726 /* test on each of the channels we have */
5727 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5728 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5729
5730 /* test each of the test cases on the current channel */
5731 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5732 pars.spec.rll := tcs[j];
5733 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5734 vc_conn := f_start_handler(fn, pars);
5735 vc_conn.done;
5736 }
5737 }
5738
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005740}
5741
5742/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5743private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5744 var RllTestCase tc := g_pars.spec.rll;
5745 timer T := 3.0;
5746
5747 f_l1_tune(L1CTL);
5748 RSL.clear;
5749
5750 /* activate the logical channel */
5751 f_est_dchan();
5752 L1CTL.clear;
5753
5754 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5755 T.start;
5756 alt {
5757 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5758 if (tc.exp) {
5759 setverdict(pass);
5760 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005762 }
5763 }
5764 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5765 if (tc.exp) {
5766 setverdict(pass);
5767 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005769 }
5770 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005771 /* We also expect to receive the measurements */
5772 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005773 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005775 }
5776 [not tc.exp] T.timeout {
5777 setverdict(pass);
5778 }
5779 }
5780
5781 f_rsl_chan_deact();
5782 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5783 f_rslem_unregister(0, g_chan_nr);
5784}
5785testcase TC_rll_est_ind() runs on test_CT {
5786 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005787 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005788 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005789 /* normal SAPI0 establishment */
5790 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005791 /* SAPI 3 doesn't support contention resolution */
5792 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5793 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5794 /* normal SAPI3 establishment on main DCCH */
5795 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5796 /* normal SAPI3 establishment on SACCH */
5797 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5798 };
5799 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5800}
5801
5802/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5803private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5804 var RllTestCase tc := g_pars.spec.rll;
5805 var L1ctlDlMessage dl;
5806 timer T := 3.0;
5807
5808 f_l1_tune(L1CTL);
5809 RSL.clear;
5810
5811 /* activate the logical channel */
5812 f_est_dchan();
5813 L1CTL.clear;
5814
5815 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5816 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5817 T.start;
5818 alt {
5819 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5820 var LapdmFrame lapdm;
5821 var octetstring l2 := dl.payload.data_ind.payload;
5822 if (dl.dl_info.link_id.c == SACCH) {
5823 /* remove L1 header */
5824 l2 := substr(l2, 2, lengthof(l2)-2);
5825 }
5826 lapdm.ab := dec_LapdmFrameAB(l2);
5827 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5828 setverdict(pass);
5829 } else {
5830 repeat;
5831 }
5832 }
5833 [] L1CTL.receive { repeat; }
5834 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005836 }
5837 }
5838
5839 f_rsl_chan_deact();
5840 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5841 f_rslem_unregister(0, g_chan_nr);
5842}
5843testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5844 var RllTestCases tcs := {
5845 /* normal SAPI3 establishment on main DCCH */
5846 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5847 };
5848 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5849}
5850testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5851 var RllTestCases tcs := {
5852 /* normal SAPI3 establishment on SACCH */
5853 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5854 }
5855 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5856}
5857
5858/* altstep to receive a LAPDm frame matching the given template */
5859private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5860 var L1ctlDlMessage dl;
5861 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5862 var LapdmFrame lapdm;
5863 var octetstring l2 := dl.payload.data_ind.payload;
5864 if (dl.dl_info.link_id.c == SACCH) {
5865 /* remove L1 header */
5866 l2 := substr(l2, 2, lengthof(l2)-2);
5867 }
5868 if (ischosen(exp.ab)) {
5869 lapdm.ab := dec_LapdmFrameAB(l2);
5870 } else if (ischosen(exp.b4)) {
5871 lapdm.b4 := dec_LapdmFrameB4(l2);
5872 } else if (ischosen(exp.bbis)) {
5873 lapdm.bbis := dec_LapdmFrameBbis(l2);
5874 }
5875 log("Rx LAPDm ", lapdm);
5876 if (match(lapdm, exp)) {
5877 setverdict(pass);
5878 } else {
5879 repeat;
5880 }
5881 }
5882 [] L1CTL.receive { repeat; }
5883}
5884private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5885 timer T := t;
5886 T.start;
5887 alt {
5888 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005890 }
5891 [] as_l1_exp_lapdm(exp);
5892 }
5893}
5894
5895/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5896private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5897 /* send SABM from MS -> BTS */
5898 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5899 /* expect RLL EST IND on Abis */
5900 alt {
5901 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5902 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5903 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005905 }
5906 [] RSL.receive { repeat; }
5907 }
5908 /* expect UA from BTS -> MS */
5909 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5910}
5911
5912/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5913private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5914 var RllTestCase tc := g_pars.spec.rll;
5915
5916 f_l1_tune(L1CTL);
5917 RSL.clear;
5918
5919 /* activate the logical channel */
5920 f_est_dchan();
5921 L1CTL.clear;
5922
5923 /* first establish the link-layer */
5924 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5925
5926 /* then send the DISC */
5927 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
5928 /* ... and expect the REL IND on the RSL side */
5929 alt {
5930 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
5931 setverdict(pass);
5932 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005933 /* We also expect to receive the measurements */
5934 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005935 }
5936
5937 /* release the channel */
5938 f_rsl_chan_deact();
5939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5940 f_rslem_unregister(0, g_chan_nr);
5941}
5942testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
5943 var RllTestCases tcs := {
5944 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
5945 };
5946 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5947}
5948
5949testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
5950 var RllTestCases tcs := {
5951 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
5952 };
5953 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5954}
5955testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
5956 var RllTestCases tcs := {
5957 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
5958 };
5959 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5960}
5961testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
5962 var RllTestCases tcs := {
5963 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5964 };
5965 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
5966}
5967
5968/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
5969private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
5970 var RllTestCase tc := g_pars.spec.rll;
5971 f_l1_tune(L1CTL);
5972 RSL.clear;
5973
5974 /* activate the logical channel */
5975 f_est_dchan();
5976 L1CTL.clear;
5977
5978 /* first establish the link-layer */
5979 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
5980
5981 /* then send the REL REQ via RSL */
5982 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
5983 /* ... and expect the DISC on the Um side */
5984 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02005985 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01005986 /* FIXME: send a UA in resposne to the DISC */
5987 }
5988 }
5989
5990 /* release the channel */
5991 f_rsl_chan_deact();
5992 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5993 f_rslem_unregister(0, g_chan_nr);
5994}
5995testcase TC_rll_rel_req() runs on test_CT {
5996 var RllTestCases tcs := {
5997 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
5998 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
5999 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6000 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6001 };
6002 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6003}
6004
6005/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
6006testcase TC_rll_data_req() runs on test_CT {
6007}
6008
6009/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
6010testcase TC_rll_data_ind() runs on test_CT {
6011}
6012
6013/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6014private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6015 var RllTestCase tc := g_pars.spec.rll;
6016
6017 f_l1_tune(L1CTL);
6018 RSL.clear;
6019
6020 f_est_dchan();
6021 L1CTL.clear;
6022
6023 /* Send UNITDATA REQ on RSL side */
6024 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6025 /* Expect it to arrive on the other side */
6026 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006027 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006028 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006029 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006030 }
6031
6032 /* release the channel */
6033 f_rsl_chan_deact();
6034 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6035 f_rslem_unregister(0, g_chan_nr);
6036}
6037testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6038 var octetstring l3 := f_rnd_octstring(15);
6039 var RllTestCases tcs := {
6040 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6041 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6042 };
6043 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6044}
6045testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6046 var octetstring l3 := f_rnd_octstring(19);
6047 var RllTestCases tcs := {
6048 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6049 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6050 };
6051 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6052}
6053
6054/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6055private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6056 var RllTestCase tc := g_pars.spec.rll;
6057
6058 f_l1_tune(L1CTL);
6059 RSL.clear;
6060
6061 f_est_dchan();
6062 L1CTL.clear;
6063
6064 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006065 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006066 /* Expdct RLL UNITDATA IND on RSL side */
6067 alt {
6068 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6069 setverdict(pass);
6070 }
6071 [] RSL.receive { repeat; }
6072 }
6073
6074 /* release the channel */
6075 f_rsl_chan_deact();
6076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6077 f_rslem_unregister(0, g_chan_nr);
6078}
6079testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006080 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006081 var RllTestCases tcs := {
6082 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6083 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6084 };
6085 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6086}
6087testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6088 var octetstring l3 := f_rnd_octstring(18);
6089 var RllTestCases tcs := {
6090 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6091 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6092 };
6093 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6094}
6095
Harald Weltee613f962018-04-18 22:38:16 +02006096/***********************************************************************
6097 * Encryption Related
6098 ***********************************************************************/
6099
6100/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6101function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6102 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6103 if (link_id.c == SACCH) {
6104 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6105 } else {
6106 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6107 }
6108}
6109
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006110/* Expect (or not expect) other kinds of messages */
6111private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6112 [exp_any] RSL.receive { repeat; }
6113 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006115 }
6116}
6117
Harald Weltee613f962018-04-18 22:38:16 +02006118/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006119private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006120 RslLinkId link_id,
6121 octetstring l3,
6122 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006123 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006124) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006125 timer T := 3.0;
6126 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6127 T.start;
6128 /* Expect RLL UNITDATA IND on RSL side */
6129 alt {
6130 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6131 setverdict(pass);
6132 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006133 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006134 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006135 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006137 }
Harald Weltee613f962018-04-18 22:38:16 +02006138 }
6139}
6140
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006141/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6142private function f_data_mo(
6143 RslLinkId link_id,
6144 boolean p, uint3_t nr, uint3_t ns,
6145 octetstring l3,
6146 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006147 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006148) runs on ConnHdlr {
6149 timer T := 3.0;
6150 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6151 T.start;
6152 /* Expect RLL DATA IND on RSL side */
6153 alt {
6154 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6155 setverdict(pass);
6156 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006157 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006158 [] as_rsl_any_ind(exp_any);
6159 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006161 }
6162 }
6163}
6164
Harald Weltee613f962018-04-18 22:38:16 +02006165/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
6166function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
6167 f_l1_tune(L1CTL);
6168 f_est_dchan(true);
6169
6170 /* now we actually need to transmit some data both ways to check if the encryption works */
6171 var L1ctlDlMessage dl;
6172
Stefan Sperling603d98e2018-07-25 16:47:28 +02006173 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006174 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6175
6176 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6177 f_unitdata_mt(link_id, l3);
6178
6179 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6180 f_unitdata_mo(link_id, l3);
6181
6182 /* release the channel */
6183 f_rsl_chan_deact();
6184 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6185 f_rslem_unregister(0, g_chan_nr);
6186}
6187testcase TC_chan_act_a51() runs on test_CT {
6188 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6189 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6190 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6191}
6192testcase TC_chan_act_a52() 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_2, f_rnd_octstring(8)));
6195 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6196}
6197testcase TC_chan_act_a53() 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_3, f_rnd_octstring(8)));
6200 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6201}
6202
Eric Wildf1827a72019-05-28 17:37:35 +02006203/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6204 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
6205function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
6206 f_l1_tune(L1CTL);
6207 f_est_dchan(true);
6208
6209 /* now we actually need to transmit some data both ways to check if the encryption works */
6210 var L1ctlDlMessage dl;
6211
6212 var octetstring l3 := f_rnd_octstring(20);
6213 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6214
6215 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6216 f_unitdata_mt(link_id, l3);
6217
6218 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6219 f_unitdata_mo(link_id, l3);
6220
6221 var RSL_Message rsl;
6222 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6223
6224 /* modify key to break proper encryption */
6225 g_pars.encr.key := f_rnd_octstring(8);
6226 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6227 rsl.ies := rsl.ies & { ei };
6228 RSL.send(rsl);
6229
6230 timer T0 := 1.0;
6231 T0.start;
6232 /* Expect RSL MODIFY ACK */
6233 alt {
6234 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6235 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6237 }
6238 [] T0.timeout {
6239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6240 }
6241 }
6242
6243 var octetstring l3msg := f_rnd_octstring(15);
6244 timer T1 := 3.0;
6245 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6246 due to broken encryption */
6247 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6248 T1.start;
6249 alt {
6250 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6252 }
6253 [] T1.timeout {
6254 setverdict(pass);
6255 }
6256 }
6257
6258 /* release the channel */
6259 f_rsl_chan_deact();
6260 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6261 f_rslem_unregister(0, g_chan_nr);
6262}
6263testcase TC_rsl_modify_encr() runs on test_CT {
6264 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6265 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6266 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6267}
Harald Weltee613f962018-04-18 22:38:16 +02006268
6269/* Test unencrypted channel activation followed by explicit ENCR CMD later */
6270function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
6271 /* L3 payload doesn't matter, as it is passed transparently */
6272 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6273 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6274 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6275
6276 f_l1_tune(L1CTL);
6277
6278 /* first establish a dedicated channel in the clear */
6279 f_est_dchan(false);
6280
6281 /* Establish ABM */
6282 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6283
6284 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6285 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6286 /* expect the L3 to arrive still unencrypted on the MS side */
6287 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6288
6289 /* configure L1 to apply ciphering */
6290 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6291 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6292
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006293 /* send first ciphered I-frame in response and expect it on RSL */
6294 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006295
6296 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6297 * and hence enable encryption also on the downlink */
6298
6299 /* expect bi-directional communication work in encrypted mode */
6300 f_unitdata_mo(link_id, f_rnd_octstring(15));
6301 f_unitdata_mt(link_id, f_rnd_octstring(15));
6302
6303 /* release the channel */
6304 f_rsl_chan_deact();
6305 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6306 f_rslem_unregister(0, g_chan_nr);
6307}
6308testcase TC_encr_cmd_a51() runs on test_CT {
6309 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6310 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6311 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6312}
6313testcase TC_encr_cmd_a52() runs on test_CT {
6314 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6315 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6316 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6317}
6318testcase TC_encr_cmd_a53() runs on test_CT {
6319 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6320 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6321 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6322}
6323
6324private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6325 var LapdmFrame lf;
6326 var octetstring reenc;
6327
6328 /* decode the LAPDm frame */
6329 if (ischosen(exp_match.ab)) {
6330 lf.ab := dec_LapdmFrameAB(enc);
6331 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006333 }
6334
6335 /* check if decoder result matches expectation */
6336 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006338 } else {
6339 log(name, ": matched");
6340 setverdict(pass);
6341 }
6342
6343 /* test if re-encoded frame equals original input */
6344 reenc := enc_LapdmFrame(lf);
6345 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006347 } else {
6348 setverdict(pass);
6349 }
6350}
6351
6352testcase TC_lapdm_selftest() runs on test_CT {
6353 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6354 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6355 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6356 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6357 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6358 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6359 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6360}
6361
Stefan Sperling4880be42018-08-07 18:12:59 +02006362/***********************************************************************
6363 * DTX Related (see GSM 05.08, section 8.3)
6364 ***********************************************************************/
6365
6366/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
6367function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
6368 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6369 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6370 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6371 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6372}
6373function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
6374 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6375 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6376}
6377function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
6378 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6379 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6380 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6381 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6382}
6383function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
6384 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6385 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6386 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6387 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6388 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6389 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6390 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6391 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6392}
6393
6394function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
6395 var L1ctlDlMessage dl;
6396 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6397 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6398 var GsmFrameNumber first_fn;
6399 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006400 var integer nfill_frames_sacch := 0;
6401 var integer nfill_frames_nonsacch := 0;
6402 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006403 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6404 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006405 const integer frame_dtx_tchf_mod := 104;
6406 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6407 * which operates in terms of blocks rather than frames. */
6408 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6409 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006410 timer T := 5.0;
6411
6412 f_l1_tune(L1CTL);
6413 RSL.clear;
6414 L1CTL.clear;
6415
6416 /* activate TCHF signalling channel */
6417 f_est_dchan(false);
6418
6419 T.start;
6420 alt {
6421 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6422 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6423 var octetstring l2 := dl.payload.data_ind.payload;
6424
6425 if (is_first_frame) {
6426 is_first_frame := false;
6427 first_fn := dl.dl_info.frame_nr;
6428 }
6429
6430 if (dl.dl_info.link_id.c == SACCH) {
6431 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6432 if (not match(l2_fill_frame_sacch, l2)) {
6433 repeat;
6434 }
6435 } else if (not match(l2_fill_frame, l2)) {
6436 repeat;
6437 }
6438
6439 if (dtxd) {
6440 if (not f_g_chan_is_tchf()) {
6441 T.stop;
6442 f_rsl_chan_deact();
6443 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006444 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 +02006445 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006446 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006447 T.stop;
6448 f_rsl_chan_deact();
6449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006450
6451 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6452 * 2 SACCH, 1 TCH/F */
6453 expected_fill_frames := 3;
6454
6455 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6456 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6457 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006459 } else {
6460 setverdict(pass);
6461 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006462 } else {
6463 if (dl.dl_info.link_id.c == SACCH) {
6464 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006465 repeat;
6466 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006467 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6468 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6469 * we should only see the subset of frames numbers which correspond to a block boundary.
6470 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6471 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6472 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6473 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6474 repeat;
6475 }
6476 }
6477 log("Received DTX TCH fill frame with bad frame number: ", fn,
6478 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6479 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6480 f_rsl_chan_deact();
6481 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006483 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006484 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006485 if (dl.dl_info.link_id.c == SACCH) {
6486 nfill_frames_sacch := nfill_frames_sacch + 1;
6487 } else {
6488 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6489 }
6490 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006491 T.stop;
6492 if (f_g_chan_is_tchf()) {
6493 /* Without DTX we can expect 25 fill frames for every 104 frames.
6494 * (24 FACCH + 1 SACCH filling) */
6495 expected_fill_frames := 25;
6496 } else if (f_g_chan_is_tchh()) {
6497 /* We can expect 2 fill frames for every 104 frames. */
6498 expected_fill_frames := 2;
6499 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6500 /* We can expect 5 fill frames for every 104 frames. */
6501 expected_fill_frames := 5;
6502 } else {
6503 f_rsl_chan_deact();
6504 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006506 }
6507
6508 f_rsl_chan_deact();
6509 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006510
6511 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006512 setverdict(pass);
6513 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006514 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6515 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006517 }
6518 } else {
6519 repeat;
6520 }
6521 }
6522 }
6523 [] L1CTL.receive { repeat; }
6524 [] T.timeout {
6525 f_rsl_chan_deact();
6526 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006528 }
6529 }
6530}
6531
6532function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
6533 f_test_l2_fill_frames(false);
6534}
6535
6536function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
6537 f_test_l2_fill_frames(true);
6538}
6539
6540function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
6541 var ConnHdlr vc_conn;
6542 var ConnHdlrPars pars;
6543 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006544 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006545 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6546 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6547 if (dtxd) {
6548 if (i >= 4) { /* DTX is only allowed on TCH/F */
6549 break;
6550 }
6551 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6552 } else {
6553 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6554 }
6555 vc_conn.done;
6556 }
6557}
6558
6559/* Verify that L2 fill frames are sent on TCH in signaling mode if
6560 * there is nothing to transmit while DTX is disabled on downlink. */
6561testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6562 f_tch_sign_l2_fill_frame(false);
6563}
6564
6565/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6566 * there is nothing to transmit while DTX is enabled on downlink. */
6567testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6568 f_tch_sign_l2_fill_frame(true);
6569}
Harald Welte0472ab42018-03-12 15:02:26 +01006570
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006571testcase TC_chopped_ipa_ping() runs on test_CT {
6572 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6573}
6574
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006575testcase TC_chopped_ipa_payload() runs on test_CT {
6576 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6577}
6578
Harald Welte0472ab42018-03-12 15:02:26 +01006579/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6580/* protocol error as per 44.006 */
6581/* link layer failure (repetition of I-frame N200 times without ACK */
6582/* repetition of SABM or DISC N200 times without ACK */
6583/* receptiom of SABM in multi-frame established state */
6584
6585
Harald Welte68e495b2018-02-25 00:05:57 +01006586/* TODO Areas:
6587
6588* channel activation
6589** with BS_Power / MS_Power, bypassing power control loop
6590** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006591** with timing advance from initial activation on
6592* mode modify
6593** encryption
6594** multirate
6595* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006596** unsupported algorithm
6597* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006598* BS Power Control
6599* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006600* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006601* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006602** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006603* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006604** DATA_IND from BTS->PCU
6605** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006606
6607*/
Harald Welte70767382018-02-21 12:16:40 +01006608
6609control {
6610 execute( TC_chan_act_stress() );
6611 execute( TC_chan_act_react() );
6612 execute( TC_chan_deact_not_active() );
6613 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006614 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006615 execute( TC_sacch_filling() );
6616 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006617 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006618 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006619 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006620 execute( TC_sacch_chan_act_ho_async() );
6621 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006622 execute( TC_rach_content() );
6623 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006624 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006625 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006626 execute( TC_rach_load_idle_thresh0() );
6627 execute( TC_rach_load_idle_below_thresh() );
6628 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006629 execute( TC_meas_res_sign_tchf() );
6630 execute( TC_meas_res_sign_tchh() );
6631 execute( TC_meas_res_sign_sdcch4() );
6632 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006633 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006634 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006635 execute( TC_tx_power_start_ramp_down_bcch() );
Eric Wildae8f2622019-06-18 17:05:11 +02006636 execute( TC_rsl_bs_pwr_static_ass() );
6637 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006638 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006639 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006640 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006641 execute( TC_rsl_ms_pwr_dyn_up() );
6642 execute( TC_rsl_ms_pwr_dyn_down() );
6643 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6644 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006645 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006646 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006647 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006648 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006649 execute( TC_paging_imsi_80percent() );
6650 execute( TC_paging_tmsi_80percent() );
6651 execute( TC_paging_imsi_200percent() );
6652 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006653 execute( TC_rsl_protocol_error() );
6654 execute( TC_rsl_mand_ie_error() );
6655 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006656 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006657 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006658 execute( TC_si_sched_2bis() );
6659 execute( TC_si_sched_2ter() );
6660 execute( TC_si_sched_2ter_2bis() );
6661 execute( TC_si_sched_2quater() );
6662 execute( TC_si_sched_13() );
6663 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006664 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006665 execute( TC_ipa_crcx_twice_not_active() );
6666 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006667 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006668 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006669
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006670 if (mp_pcu_socket != "") {
6671 execute( TC_pcu_act_req() );
6672 execute( TC_pcu_act_req_wrong_ts() );
6673 execute( TC_pcu_act_req_wrong_bts() );
6674 execute( TC_pcu_act_req_wrong_trx() );
6675 execute( TC_pcu_deact_req() );
6676 execute( TC_pcu_deact_req_wrong_ts() );
6677 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006678 if (mp_l1_supports_gprs) {
6679 execute( TC_pcu_data_req_pdtch() );
6680 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006681 execute( TC_pcu_data_req_wrong_bts() );
6682 execute( TC_pcu_data_req_wrong_trx() );
6683 execute( TC_pcu_data_req_wrong_ts() );
6684 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006685 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006686 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006687 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006688 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006689 execute( TC_pcu_data_req_imm_ass_pch() );
6690 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006691 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006692 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006693 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006694 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006695 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006696 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006697 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006698 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006699 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006700 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006701 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006702 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006703 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006704 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006705 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006706 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006707 execute( TC_dyn_osmo_pdch_act_deact() );
6708 execute( TC_dyn_osmo_pdch_double_act() );
6709 execute( TC_dyn_ipa_pdch_act_deact() );
6710 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6711
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006712 } else {
6713 log("PCU socket path not available, skipping PCU tests");
6714 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006715
Harald Welte3d04ae62018-04-04 20:29:05 +02006716 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006717 execute( TC_dyn_osmo_pdch_tchf_act() );
6718 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006719 execute( TC_dyn_ipa_pdch_tchf_act() );
6720 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006721
6722 execute( TC_rll_est_ind() );
6723 execute( TC_rll_est_req_DCCH_3() );
6724 execute( TC_rll_est_req_ACCH_3() );
6725 execute( TC_rll_rel_ind_DCCH_0() );
6726 execute( TC_rll_rel_ind_DCCH_3() );
6727 execute( TC_rll_rel_ind_ACCH_0() );
6728 execute( TC_rll_rel_ind_ACCH_3() );
6729 execute( TC_rll_rel_req() );
6730 execute( TC_rll_unit_data_req_DCCH() );
6731 execute( TC_rll_unit_data_req_ACCH() );
6732 execute( TC_rll_unit_data_ind_DCCH() );
6733 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006734
6735 execute( TC_chan_act_a51() );
6736 execute( TC_chan_act_a52() );
6737 execute( TC_chan_act_a53() );
6738 execute( TC_encr_cmd_a51() );
6739 execute( TC_encr_cmd_a52() );
6740 execute( TC_encr_cmd_a53() );
6741
Harald Welteee25aae2019-05-19 14:32:37 +02006742 execute( TC_err_rep_wrong_mdisc() );
6743 execute( TC_err_rep_wrong_msg_type() );
6744 execute( TC_err_rep_wrong_sequence() );
6745
Harald Weltee613f962018-04-18 22:38:16 +02006746 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006747
6748 execute( TC_tch_sign_l2_fill_frame() );
6749 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006750
6751 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006752 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006753}
6754
6755
6756}