blob: 15b07309cdcc2f7d81d4d72eb49b8dd7f2dac0d1 [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 Yanitskiy8239dd92020-07-04 20:31:35 +0700190private function 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 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700253private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100254 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100255}
256
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700257private template (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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700265private template (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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700273private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100274 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 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700300private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100301 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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700330private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100331 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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700341private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100342 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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700355private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100356runs 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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100362runs 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 */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700432friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200433 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) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700506friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100507 map(self:L1CTL, system:L1CTL);
508 f_connect_reset(L1CTL);
509}
510
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700511private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100512
513/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700514friend function 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
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700584private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
585 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200586runs 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
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700610friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
611 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200612runs 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
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700616friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
617 boolean encr_enable := false,
618 RSL_IE_List more_ies := {},
619 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
620runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200621 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200622 if (encr_enable) {
623 /* append encryption related IEs, if requested */
624 var RSL_IE_EncryptionInfo encr_info;
625 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
626 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
627encr_info})) };
628 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200629 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200630 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100631}
632
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700633friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100634 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 +0100635 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100636}
637
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700638/* Default Mobile Allocation to be used for frequency hopping */
639private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
640 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
641
Harald Welte2f2b2b72019-05-31 22:24:57 +0200642friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100643 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700644 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100645 float t_guard := 20.0) := {
646 chan_nr := valueof(chan_nr),
647 chan_mode := valueof(chan_mode),
648 t_guard := t_guard,
649 l1_pars := {
650 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100651 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100652 meas_ul := {
653 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200654 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100655 rxqual := 0
656 },
657 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200658 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100659 rxqual := 0
660 }
661 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200662 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100663 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200664 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200665 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100666 },
Harald Weltee613f962018-04-18 22:38:16 +0200667 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200668 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700669 bts0_band := omit,
670 maio_hsn := maio_hsn,
671 ma_map := c_MA_null,
672 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100673}
674
Harald Welte93640c62018-02-25 16:59:33 +0100675/***********************************************************************
676 * Channel Activation / Deactivation
677 ***********************************************************************/
678
Harald Welte70767382018-02-21 12:16:40 +0100679/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700680private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100681 for (var integer i := 0; i < 500; i := i+1) {
682 f_rsl_chan_act(g_pars.chan_mode);
683 f_rsl_chan_deact();
684 }
685 setverdict(pass);
686}
687testcase TC_chan_act_stress() runs on test_CT {
688 var ConnHdlr vc_conn;
689 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200690 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100691 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
692 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100694}
695
696/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700697private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100698 f_rsl_chan_act(g_pars.chan_mode);
699 /* attempt to activate the same lchan again -> expect reject */
700 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
701 alt {
702 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100704 }
705 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
706 setverdict(pass);
707 }
708 }
709 f_rsl_chan_deact();
710}
711testcase TC_chan_act_react() runs on test_CT {
712 var ConnHdlr vc_conn;
713 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100714 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100715 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
716 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
720/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700721private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100722 timer T := 3.0;
723 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
724 T.start;
725 alt {
726 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
727 setverdict(pass);
728 }
729 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100731 }
732 }
733}
734testcase TC_chan_deact_not_active() runs on test_CT {
735 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100736 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100737 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
738 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100740}
741
742/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700743private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100744 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
745 alt {
746 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100748 }
749 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
750 setverdict(pass);
751 }
752 }
753}
754private type record WrongChanNrCase {
755 RslChannelNr chan_nr,
756 charstring description
757}
758private type record of WrongChanNrCase WrongChanNrCases;
759private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
760 chan_nr := chan_nr,
761 description := desc
762}
763
764testcase TC_chan_act_wrong_nr() runs on test_CT {
765 var ConnHdlr vc_conn;
766 var ConnHdlrPars pars;
767
Harald Welte294b0a22018-03-10 23:26:48 +0100768 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100769
770 var WrongChanNrCases wrong := {
771 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
772 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
773 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
774 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
775 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
776 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
777 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
778 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
779 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
780 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
781 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
782 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
783 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
784 };
785
786 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
787 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
788 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
789 vc_conn.done;
790 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100792}
793
Harald Weltee613f962018-04-18 22:38:16 +0200794/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200795friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200796 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200797 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200798
799 /* test on each of the channels we have */
800 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
801 pars.chan_nr := valueof(g_AllChanTypes[i]);
802
803 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
804 vc_conn := f_start_handler(fn, pars);
805 vc_conn.done;
806 }
807
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200809}
810
Harald Welte93640c62018-02-25 16:59:33 +0100811/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100812 * SACCH handling
813 ***********************************************************************/
814
815private function f_exp_sacch(boolean exp) runs on ConnHdlr {
816 timer T_sacch := 3.0;
817 T_sacch.start;
818 alt {
819 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100821 }
822 [not exp] T_sacch.timeout {
823 setverdict(pass);
824 }
825 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
826 setverdict(pass);
827 }
828 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100830 }
831 [] L1CTL.receive { repeat; }
832 [] RSL.receive { repeat; }
833 }
834}
835
836/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
837private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
838 f_l1_tune(L1CTL);
839 RSL.clear;
840
841 /* activate the logical channel */
842 f_est_dchan();
843 L1CTL.clear;
844
845 /* check that SACCH actually are received as expected */
846 f_exp_sacch(true);
847
848 /* deactivate SACCH on the logical channel */
849 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
850 f_sleep(1.0);
851 L1CTL.clear;
852
853 /* check that no SACCH are received anymore */
854 f_exp_sacch(false);
855
856 /* release the channel */
857 f_rsl_chan_deact();
858 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
859}
860testcase TC_deact_sacch() runs on test_CT {
861 var ConnHdlr vc_conn;
862 var ConnHdlrPars pars;
863 f_init();
864 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
865 //for (var integer i := 0; i < 1; i := i+1) {
866 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
867 log(testcasename(), ": Starting for ", g_AllChannels[i]);
868 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
869 vc_conn.done;
870 }
871 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100873}
874
Harald Welte55700662018-03-12 13:15:43 +0100875/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100876private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
877 var L1ctlDlMessage dl;
878 /* check that the specified SI5 value is actually sent */
879 timer T_sacch := 3.0;
880 L1CTL.clear;
881 T_sacch.start;
882 alt {
883 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
884 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
885 if (match(l3, l3_exp)) {
886 setverdict(pass);
887 } else {
888 repeat;
889 }
890 }
891 [] L1CTL.receive { repeat; }
892 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100894 }
895 }
896}
897
Harald Welte55700662018-03-12 13:15:43 +0100898/* verify that given SACCH payload is not present */
899private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
900 var L1ctlDlMessage dl;
901 /* check that the specified SI5 value is actually sent */
902 timer T_sacch := 3.0;
903 L1CTL.clear;
904 T_sacch.start;
905 alt {
906 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
907 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
908 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100910 } else {
911 repeat;
912 }
913 }
914 [] L1CTL.receive { repeat; }
915 [] T_sacch.timeout {
916 setverdict(pass);
917 }
918 }
919}
920
Harald Welte629cc6b2018-03-11 17:19:05 +0100921/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100922private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
923 /* Set a known default SACCH filling for SI5 */
924 var octetstring si5 := f_rnd_octstring(19);
925 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
926
927 f_l1_tune(L1CTL);
928 RSL.clear;
929
930 /* activate the logical channel */
931 f_est_dchan();
932
933 /* check that the specified SI5 value is actually sent */
934 f_sacch_present(si5);
935
936 /* release the channel */
937 RSL.clear;
938 f_rsl_chan_deact();
939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
940}
941testcase TC_sacch_filling() runs on test_CT {
942 var ConnHdlr vc_conn;
943 var ConnHdlrPars pars;
944 f_init();
945 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
946 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
947 log(testcasename(), ": Starting for ", g_AllChannels[i]);
948 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
949 vc_conn.done;
950 }
951 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100953}
954
Harald Welte629cc6b2018-03-11 17:19:05 +0100955/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100956private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
957 /* Set a known default SACCH filling for SI5 */
958 var octetstring si5 := f_rnd_octstring(19);
959 var octetstring si5_diff := f_rnd_octstring(19);
960 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
961
962 f_l1_tune(L1CTL);
963 RSL.clear;
964
965 log("Activating channel, expecting standard SI5");
966 /* activate the logical channel */
967 f_est_dchan();
968 /* check that the specified SI5 value is actually sent */
969 f_sacch_present(si5);
970
971 /* set channel-specific different SI5 */
972 log("Setting channel specific SACCH INFO, expecting it");
973 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
974 /* check that the specified lchan-specific value is now used */
975 f_sacch_present(si5_diff);
976
977 /* deactivate the channel and re-activate it, this should result in default SI5 */
978 log("De-activating and re-activating channel, expecting standard SI5");
979 f_rsl_chan_deact();
980 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
981 /* Verify that the TRX-wide default SACCH filling is present again */
982 f_sacch_present(si5);
983
984 /* release the channel */
985 RSL.clear;
986 f_rsl_chan_deact();
987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
988}
989testcase TC_sacch_info_mod() runs on test_CT {
990 var ConnHdlr vc_conn;
991 var ConnHdlrPars pars;
992 f_init();
993 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
994 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
995 log(testcasename(), ": Starting for ", g_AllChannels[i]);
996 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
997 vc_conn.done;
998 }
999 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001001}
1002
Harald Welte075d84c2018-03-12 13:07:24 +01001003/* Test SACCH scheduling of multiple different SI message types */
1004private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1005 var octetstring si5 := f_rnd_octstring(19);
1006 var octetstring si5bis := f_rnd_octstring(19);
1007 var octetstring si5ter := f_rnd_octstring(19);
1008 var octetstring si6 := f_rnd_octstring(19);
1009
1010 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1011 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1012 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1013 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1014
1015 f_l1_tune(L1CTL);
1016 RSL.clear;
1017
1018 /* activate the logical channel */
1019 f_est_dchan();
1020 L1CTL.clear;
1021
1022 /* check that SACCH actually are received as expected */
1023 f_sacch_present(si5);
1024 f_sacch_present(si5bis);
1025 f_sacch_present(si5ter);
1026 f_sacch_present(si6);
1027
1028 /* release the channel */
1029 f_rsl_chan_deact();
1030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1031}
1032testcase TC_sacch_multi() runs on test_CT {
1033 var ConnHdlr vc_conn;
1034 var ConnHdlrPars pars;
1035 f_init();
1036 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1037 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1038 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1039 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1040 vc_conn.done;
1041 }
1042 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001044}
1045
Harald Welte55700662018-03-12 13:15:43 +01001046/* Test if SACH information is modified as expected */
1047private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1048 var octetstring si5 := f_rnd_octstring(19);
1049 var octetstring si6 := f_rnd_octstring(19);
1050
1051 /* First, configure both SI5 and SI6 to be transmitted */
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 /* activate the logical channel */
1059 f_est_dchan();
1060 L1CTL.clear;
1061
1062 /* check that SACCH actually are received as expected */
1063 f_sacch_present(si5);
1064 f_sacch_present(si6);
1065
1066 /* disable SI6 */
1067 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1068
1069 /* check that SI5 is still transmitted */
1070 f_sacch_present(si5);
1071 /* check if SI6 is now gone */
1072 f_sacch_missing(si6);
1073
1074 /* release the channel */
1075 f_rsl_chan_deact();
1076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1077}
1078testcase TC_sacch_multi_chg() runs on test_CT {
1079 var ConnHdlr vc_conn;
1080 var ConnHdlrPars pars;
1081 f_init();
1082 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1083 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1084 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1085 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1086 vc_conn.done;
1087 }
1088 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001090}
1091
Harald Weltec8d363c2019-05-19 20:36:48 +02001092/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1093private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1094 var octetstring si5 := f_rnd_octstring(19);
1095 var octetstring si6 := f_rnd_octstring(19);
1096 var octetstring si5_specific := f_rnd_octstring(19);
1097 var octetstring si6_specific := f_rnd_octstring(19);
1098
1099 /* First, configure both SI5 and SI6 to be transmitted */
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1102
1103 f_l1_tune(L1CTL);
1104 RSL.clear;
1105
1106 /* activate channel with different SACCH filling */
1107 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1108 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1109 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1110 }));
1111 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1112 RSL_IE_Body:{sacch_info := sacch_info})) };
1113 f_est_dchan(more_ies := addl_ies);
1114
1115 /* check that SACCH actually are received as expected */
1116 f_sacch_present(si5_specific);
1117 f_sacch_present(si6_specific);
1118
1119 /* release the channel */
1120 f_rsl_chan_deact();
1121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1122}
1123testcase TC_sacch_chan_act() runs on test_CT {
1124 var ConnHdlr vc_conn;
1125 var ConnHdlrPars pars;
1126 f_init();
1127
1128 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1129 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1130 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1131 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1132 vc_conn.done;
1133 }
1134 /* TODO: do the above in parallel, rather than sequentially? */
1135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1136}
1137
Harald Welte8b01c792019-05-19 22:51:25 +02001138/* verify that SACCH DL transmission is started only if MS power IE present
1139 * see section 4.1.3 of 3GPP TS 48.058 */
1140private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1141 var octetstring si5 := f_rnd_octstring(19);
1142
1143 f_l1_tune(L1CTL);
1144 RSL.clear;
1145
1146 /* Step 1: Activate ASYNC HO channel without MS power IE */
1147
1148 /* Activate channel on BTS side */
1149 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1150 /* don't perform immediate assignment here, as we're testing non-IA case */
1151 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001152 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001153
1154 /* Verify that no DL SACCH is being received */
1155 f_sacch_missing(?);
1156
1157 f_rsl_chan_deact();
1158 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1159
1160
1161 /* Step 2: Activate ASYNC HO channel with MS power IE */
1162
1163 /* Activate channel on BTS side */
1164 var RSL_IE_List addl_ies := {
1165 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1166 };
1167 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1168 /* don't perform immediate assignment here, as we're testing non-IA case */
1169 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001170 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001171
1172 /* Verify that DL SACCH is being received */
1173 f_sacch_present(si5);
1174
1175 f_rsl_chan_deact();
1176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1177}
1178testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1179 var ConnHdlr vc_conn;
1180 var ConnHdlrPars pars;
1181 f_init();
1182
1183 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1184 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1185 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1186 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1187 vc_conn.done;
1188 }
1189 /* TODO: do the above in parallel, rather than sequentially? */
1190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1191}
1192
1193/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1194 * see section 4.1.4 of 3GPP TS 48.058 */
1195private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1196 var octetstring si5 := f_rnd_octstring(19);
1197 var RSL_IE_List addl_ies;
1198
1199 f_l1_tune(L1CTL);
1200 RSL.clear;
1201
1202 /* Step 1: Activate SYNC HO channel without MS power IE */
1203
1204 /* Activate channel on BTS side */
1205 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1206 /* don't perform immediate assignment here, as we're testing non-IA case */
1207 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001208 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001209
1210 /* Verify that no DL SACCH is being received */
1211 f_sacch_missing(?);
1212
1213 f_rsl_chan_deact();
1214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1215
1216
1217 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1218
1219 /* Activate channel on BTS side */
1220 addl_ies := {
1221 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1222 };
1223 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1224 /* don't perform immediate assignment here, as we're testing non-IA case */
1225 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001226 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001227
1228 /* Verify that no DL SACCH is being received */
1229 f_sacch_missing(?);
1230
1231 f_rsl_chan_deact();
1232 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1233
1234
1235 /* Step 2b: Activate SYNC HO channel with TA IE */
1236
1237 /* Activate channel on BTS side */
1238 addl_ies := {
1239 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1240 };
1241 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1242 /* don't perform immediate assignment here, as we're testing non-IA case */
1243 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001244 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001245
1246 /* Verify that no DL SACCH is being received */
1247 f_sacch_missing(?);
1248
1249 f_rsl_chan_deact();
1250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1251
1252
1253 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1254
1255 /* Activate channel on BTS side */
1256 addl_ies := {
1257 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1258 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1259 };
1260 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1261 /* don't perform immediate assignment here, as we're testing non-IA case */
1262 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001263 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001264
1265 /* Verify that DL SACCH is being received */
1266 f_sacch_present(si5);
1267
1268 f_rsl_chan_deact();
1269 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1270}
1271testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1272 var ConnHdlr vc_conn;
1273 var ConnHdlrPars pars;
1274 f_init();
1275
1276 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1277 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1278 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1279 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1280 vc_conn.done;
1281 }
1282 /* TODO: do the above in parallel, rather than sequentially? */
1283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1284}
Harald Welte629cc6b2018-03-11 17:19:05 +01001285
1286
1287/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001288 * RACH Handling
1289 ***********************************************************************/
1290
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291/* like L1SAP_IS_PACKET_RACH */
1292private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001293 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 return true;
1295 }
1296 return false;
1297}
1298
1299/* generate a random RACH for circuit-switched */
1300private function f_rnd_ra_cs() return OCT1 {
1301 var OCT1 ra;
1302 do {
1303 ra := f_rnd_octstring(1);
1304 } while (ra_is_ps(ra));
1305 return ra;
1306}
1307
Harald Welte883340c2018-02-28 18:59:29 +01001308/* generate a random RACH for packet-switched */
1309private function f_rnd_ra_ps() return OCT1 {
1310 var OCT1 ra;
1311 do {
1312 ra := f_rnd_octstring(1);
1313 } while (not ra_is_ps(ra));
1314 return ra;
1315}
1316
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001317/* generate a random 11-bit RA (packet-switched only) */
1318private function f_rnd_ra11_ps() return BIT11 {
1319 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1320 return int2bit(ra11, 11);
1321}
1322
Harald Welte8c24c2b2018-02-26 08:31:31 +01001323/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1324testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001325 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001326 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001327 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001328
Harald Welte8c24c2b2018-02-26 08:31:31 +01001329 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001330 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001331 for (var integer i := 0; i < 1000; i := i+1) {
1332 var OCT1 ra := f_rnd_ra_cs();
1333 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1334 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001336 }
1337 fn_last := fn;
1338
1339 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001340 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001341 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001342 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001343 T.stop;
1344 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001345 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001347 }
1348 [] RSL_CCHAN.receive { repeat; }
1349 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001350 test_failed := true;
1351 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001352 }
1353 }
1354 }
Maxba06feb2019-03-05 10:52:46 +01001355 if (test_failed) {
1356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001357 }
Maxba06feb2019-03-05 10:52:46 +01001358 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001360}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001361
1362/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1363testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001364 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001365 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001366 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001367 f_l1_tune(L1CTL);
1368
1369 var GsmFrameNumber fn_last := 0;
1370 for (var integer i := 0; i < 1000; i := i+1) {
1371 var OCT1 ra := f_rnd_ra_cs();
1372 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1373 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001375 }
1376 fn_last := fn;
1377 }
1378 var integer rsl_chrqd := 0;
1379 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001380 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001382 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001383 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001384 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001385 repeat;
1386 }
1387 [] RSL_CCHAN.receive { repeat; }
1388 [] T.timeout { }
1389 }
1390 if (rsl_chrqd == 1000) {
1391 setverdict(pass);
1392 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001394 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001396}
1397
Harald Welte3453ab42019-05-24 21:19:58 +02001398private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1399 var charstring bts_str := "bts " & int2str(bts_nr);
1400 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1401}
1402
1403/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1404private template integer tr_rach_slots_per_interval := (90 .. 130);
1405
1406/* Expect 0 RACH load on an idle BTS that has just started up */
1407testcase TC_rach_load_idle_thresh0() runs on test_CT {
1408 var ASP_RSL_Unitdata rx_ud;
1409
1410 f_init_vty_bsc();
1411 /* send load indications even at 0% load */
1412 f_vty_load_ind_thresh(0);
1413 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1414 f_sleep(2.0);
1415
1416 f_init();
1417
1418 timer T := 5.0;
1419 T.start;
1420 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001421 [] 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 +02001422 setverdict(pass);
1423 repeat;
1424 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001425 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001426 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1427 repeat;
1428 }
1429 [] RSL_CCHAN.receive {
1430 repeat;
1431 }
1432 [] T.timeout { }
1433 }
1434
1435 f_vty_load_ind_thresh(10);
1436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1437}
1438
1439/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1440testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1441 var ASP_RSL_Unitdata rx_ud;
1442
1443 f_init_vty_bsc();
1444 f_init();
1445
1446 timer T := 5.0;
1447 T.start;
1448 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001449 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001450 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1451 repeat;
1452 }
1453 [] RSL_CCHAN.receive {
1454 repeat;
1455 }
1456 [] T.timeout {
1457 setverdict(pass);
1458 }
1459 }
1460
1461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1462}
1463
1464/* Expect 0 RACH load on an idle BTS that has just started up */
1465testcase TC_rach_load_count() runs on test_CT {
1466 var ASP_RSL_Unitdata rx_ud;
1467 var integer load_access_count := 0;
1468
1469 f_init_vty_bsc();
1470 /* send load indications even at 0% load */
1471 f_vty_load_ind_thresh(0);
1472 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1473 f_sleep(2.0);
1474 f_init();
1475
1476 f_init_l1ctl();
1477 f_sleep(1.0);
1478 f_l1_tune(L1CTL);
1479
1480 var GsmFrameNumber fn_last := 0;
1481 for (var integer i := 0; i < 1000; i := i+1) {
1482 var OCT1 ra := f_rnd_ra_cs();
1483 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1484 if (fn == fn_last) {
1485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1486 }
1487 fn_last := fn;
1488 }
1489
1490 timer T := 5.0;
1491 T.start;
1492 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001493 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001494 -> value rx_ud {
1495 var RSL_IE_Body ie;
1496 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1497 load_access_count := load_access_count + ie.rach_load.access_count;
1498 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1499 setverdict(fail, "Access count cannot be < Busy count");
1500 }
1501 repeat;
1502 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001503 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001504 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1505 repeat;
1506 }
1507 [] RSL_CCHAN.receive {
1508 repeat;
1509 }
1510 [] T.timeout { }
1511 }
1512 if (load_access_count == 1000) {
1513 setverdict(pass);
1514 } else {
1515 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1516 }
1517
1518 f_vty_load_ind_thresh(10);
1519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1520}
1521
Harald Welte54a2a2d2018-02-26 09:14:05 +01001522private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001523 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001524 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001526 f_sleep(0.5);
1527
1528 /* Transmit RACH request + wait for confirmation */
1529 var OCT1 ra := f_rnd_ra_cs();
1530 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1531
1532 /* Check for expected result */
1533 timer T := 1.5;
1534 T.start;
1535 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001536 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001537 setverdict(pass);
1538 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001539 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001541 }
1542 [] RSL_CCHAN.receive { repeat; }
1543 [not expect_pass] T.timeout {
1544 setverdict(pass);
1545 }
1546 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001548 }
1549 }
1550}
1551
1552/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1553testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001554 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001555 f_init_l1ctl();
1556 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001557 f_sleep(1.0);
1558
1559 /* default max-ta is 63 (full range of GSM timing advance */
1560
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001561 /* We allow early arrival up to 2 symbols */
1562 f_rach_toffs(-1*256, true);
1563 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001564 f_rach_toffs(-10*256, false);
1565
1566 /* 0 / 32 / 63 bits is legal / permitted */
1567 f_rach_toffs(0, true);
1568 f_rach_toffs(32*256, true);
1569 f_rach_toffs(63*256, true);
1570
1571 /* more than 63 bits is not legal / permitted */
1572 f_rach_toffs(64*256, false);
1573 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001575}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001576
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001577private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001578 var GsmFrameNumber fn;
1579 var RSL_Message rm;
1580
1581 f_l1_tune(L1CTL);
1582 RSL.clear;
1583
1584 /* Generate a random Handover Reference */
1585 var integer ho_ref := oct2int(f_rnd_octstring(1));
1586
1587 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1588 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1589 RSL_IE_Body:{ handover_ref := ho_ref }));
1590
1591 /* Activate a channel on the BTS side (no encryption) */
1592 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1593 act_type := t_RSL_IE_ActType_HO_SYNC);
1594
1595 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1596 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001597 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001598
1599 /* Send handover Access Burst */
1600 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1601
1602 /* TODO: test mismatching Handover Reference, and missing IE */
1603
1604 /* Wait for handover detection */
1605 timer T := 3.0;
1606 T.start;
1607 alt {
1608 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1609 log("Handover RACH has been detected: ", rm);
1610 setverdict(pass);
1611 }
1612 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1614 log2str("RSL_CHAN_RQD was not expected: ", rm));
1615 }
1616 [] RSL.receive { repeat; }
1617 [] T.timeout {
1618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1619 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1620 }
1621 }
1622
1623 /* Release the channel */
1624 f_rsl_chan_deact();
1625 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1626}
1627
1628/* Test handover RACH detection */
1629testcase TC_ho_rach() runs on test_CT {
1630 var ConnHdlrPars pars;
1631 var ConnHdlr vc_conn;
1632
1633 f_init();
1634
1635 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1636 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1637 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1638 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1639 vc_conn.done;
1640 }
1641
1642 /* TODO: do the above in parallel, rather than sequentially? */
1643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1644}
1645
Harald Welte93640c62018-02-25 16:59:33 +01001646/***********************************************************************
1647 * Measurement Processing / Reporting
1648 ***********************************************************************/
1649
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001650private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001651 spare := '0'B,
1652 lpd := 0,
1653 sapi := sapi,
1654 c_r := c_r,
1655 ea := true
1656}
1657
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001658private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001659 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001660 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001661 len := 0, /* overwritten */
1662 m := false,
1663 el := 1,
1664 payload := pl
1665}
1666
1667/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001668private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001669 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001670 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001671 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001672 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 +01001673 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001674 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001675
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001676 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1677 g_pars.l1_pars.ms_power_level, false,
1678 g_pars.l1_pars.ms_actual_ta);
1679
1680 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1681 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1682
1683 log("Sending Measurement Report: ", l1h, l2);
1684 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001685 repeat;
1686 }
1687}
1688
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001689private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001690 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001691 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001692 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1693 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001694 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1695 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001696 repeat;
1697 }
1698}
1699
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001700private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001701 uint6_t rxlev,
1702 uint3_t rxqual
1703}
1704
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001705private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001706 MeasElem full,
1707 MeasElem sub
1708}
1709
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001710private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001711 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001712 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001713 MeasElemFS meas_ul,
1714 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001715 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001716 uint5_t ms_power_level,
1717 uint8_t ms_actual_ta
1718}
1719
1720/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1721private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1722 return 63 + (toffs256s/256);
1723}
1724
Harald Welted5684392018-03-10 18:22:04 +01001725private function f_max(integer a, integer b) return integer {
1726 if (a > b) {
1727 return a;
1728 } else {
1729 return b;
1730 }
1731}
1732
1733private function f_min(integer a, integer b) return integer {
1734 if (a < b) {
1735 return a;
1736 } else {
1737 return b;
1738 }
1739}
1740
1741/* compute negative tolerance val-tolerance, ensure >= min */
1742private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1743 val := val - tolerance;
1744 return f_max(val, min);
1745}
1746
1747/* compute positive tolerance val+tolerance, ensure <= max */
1748private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1749 val := val + tolerance;
1750 return f_min(val, max);
1751}
1752
1753/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1754private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1755return template integer {
1756 var template integer ret;
1757 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1758 return ret;
1759}
1760
1761
Harald Welte70767382018-02-21 12:16:40 +01001762/* build a template for matching measurement results against */
1763private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1764 var ConnL1Pars l1p := g_pars.l1_pars;
1765 var template RSL_IE_UplinkMeas ul_meas := {
1766 len := 3,
1767 rfu := '0'B,
1768 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001769 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001770 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001771 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001772 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001773 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1774 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001775 supp_meas_info := omit
1776 };
Harald Welte685d5982018-02-27 20:42:05 +01001777 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001778 ul_meas.len := (3+8);
1779 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001780 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001781 toa256_min := ?,
1782 toa256_max := ?,
1783 toa256_std_dev := ?
1784 }
Harald Welte685d5982018-02-27 20:42:05 +01001785 }
Harald Welte70767382018-02-21 12:16:40 +01001786 var template RSL_IE_BS_Power bs_power := {
1787 reserved := 0,
1788 epc := false,
1789 fpc := false,
1790 power_level := l1p.bs_power_level
1791 };
1792 var template RSL_IE_L1Info l1_info := {
1793 ms_power_lvl := l1p.ms_power_level,
1794 fpc := false,
1795 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001796 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001797 };
1798 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001799 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001800 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1801 ?, t_toffs);
1802}
1803
Philipp Maierdd841d32019-12-17 14:44:54 +01001804/* build a template for matching measurement results that do not contain any
1805 * MS related measurement (l1_info, l3_info and ms timing offset). */
1806private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1807 var ConnL1Pars l1p := g_pars.l1_pars;
1808 var template RSL_IE_UplinkMeas ul_meas := {
1809 len := 3,
1810 rfu := '0'B,
1811 dtx_d := l1p.dtx_enabled,
1812 rxlev_f_u := ?,
1813 reserved1 := '00'B,
1814 rxlev_s_u := ?,
1815 reserved2 := '00'B,
1816 rxq_f_u := ?,
1817 rxq_s_u := ?,
1818 supp_meas_info := omit
1819 };
1820 if (l1p.toa256_enabled) {
1821 ul_meas.len := (3+8);
1822 ul_meas.supp_meas_info := {
1823 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1824 toa256_min := ?,
1825 toa256_max := ?,
1826 toa256_std_dev := ?
1827 }
1828 }
1829 var template RSL_IE_BS_Power bs_power := {
1830 reserved := 0,
1831 epc := false,
1832 fpc := false,
1833 power_level := l1p.bs_power_level
1834 };
1835
1836 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1837}
1838
Harald Welte70767382018-02-21 12:16:40 +01001839/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001840private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001841 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001842 var boolean chan_est := false;
1843
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001844 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001845
1846 /* Receive osmocom specific measurement reports. This is the normal
1847 * case. Here we verify that the measurement reports we sent are
1848 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001849 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1850 /* increment counter of next to-be-expected meas rep */
1851 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1852 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001853 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001854
1855 /* The following two cases may only happen in the beginning
1856 * of the channel establishment phase. Once we have received
1857 * the "our" measurement report the first time, the channel
1858 * is established and empty or hardcoded TRXCON reports must
1859 * not occur anymore. */
1860 chan_est := true;
1861
1862 repeat;
1863 }
1864
1865 /* When the BTS has established the channel, the MS might need slightly
1866 * more time to establish the channel and actually start sending. The
1867 * result is then a measurement report that just lacks the measurement
1868 * information of the MS. This is normal and we tolerate this behavior. */
1869 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1870 /* increment counter of next to-be-expected meas rep */
1871 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1872 /* Re-start the timer expecting the next MEAS RES */
1873 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001874 repeat;
1875 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001876
1877 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1878 * measurements if the TTCN3 side does not supply measurement input in
1879 * time. In those cases TRXCON will either use a cached measurement
1880 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1881 * report the templates above will not match. We tolerate this
1882 * behavior, but only once. */
1883 [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 +01001884 /* increment counter of next to-be-expected meas rep */
1885 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1886 if (g_first_meas_res) {
1887 g_first_meas_res := false;
1888 repeat;
1889 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001891 }
Harald Welte70767382018-02-21 12:16:40 +01001892 }
1893 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001895 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001896 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001898 }
1899}
1900
Harald Weltee613f962018-04-18 22:38:16 +02001901private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1902 select (rsl_alg_id) {
1903 case (RSL_ALG_ID_A5_0) { return 0; }
1904 case (RSL_ALG_ID_A5_1) { return 1; }
1905 case (RSL_ALG_ID_A5_2) { return 2; }
1906 case (RSL_ALG_ID_A5_3) { return 3; }
1907 case (RSL_ALG_ID_A5_4) { return 4; }
1908 case (RSL_ALG_ID_A5_5) { return 5; }
1909 case (RSL_ALG_ID_A5_6) { return 6; }
1910 case (RSL_ALG_ID_A5_7) { return 7; }
1911 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1913 /* Make compiler happy by calling mtc.stop here. It is already
1914 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001915 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001916 }
1917 }
1918}
1919
1920private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1921 select (rsl_alg_id) {
1922 case (RSL_ALG_ID_A5_1) { return '000'B; }
1923 case (RSL_ALG_ID_A5_2) { return '001'B; }
1924 case (RSL_ALG_ID_A5_3) { return '010'B; }
1925 case (RSL_ALG_ID_A5_4) { return '011'B; }
1926 case (RSL_ALG_ID_A5_5) { return '100'B; }
1927 case (RSL_ALG_ID_A5_6) { return '101'B; }
1928 case (RSL_ALG_ID_A5_7) { return '110'B; }
1929 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1931 /* Make compiler happy by calling mtc.stop here. It is already
1932 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001933 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001934 }
1935 }
1936}
1937
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001938/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1939private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1940 var GsmFrameNumber fn;
1941 timer T := 8.0;
1942
1943 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1944 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1945
1946 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1947 /* Send the actual RACH */
1948 fn := f_L1CTL_RACH(L1CTL, ra);
1949
1950 T.start;
1951 alt {
1952 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1953 [] T.timeout {
1954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1955 }
1956 }
1957 T.stop
1958 return fn;
1959}
Harald Weltee613f962018-04-18 22:38:16 +02001960
Harald Welte70767382018-02-21 12:16:40 +01001961/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001962private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001963 var GsmFrameNumber fn;
1964 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001965 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001966 var integer ra := 23;
1967
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001968 /* Send RACH request and wait for ChanReq */
1969 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001970
1971 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001972 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001973
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001974 /* Craft channel description (with or without frequency hopping parameters) */
1975 if (ispresent(g_pars.maio_hsn)) {
1976 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1977 } else {
1978 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1979 }
1980
Harald Welte70767382018-02-21 12:16:40 +01001981 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001982 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001983 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1984
1985 /* receive IMM.ASS on MS side */
1986 var ImmediateAssignment ia_um;
1987 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001988
1989 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1990 if (ch_desc.h != ia_um.chan_desc.h) {
1991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1992 }
1993
Harald Welte70767382018-02-21 12:16:40 +01001994 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001995 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001996 /* enable encryption, if requested */
1997 if (encr_enable) {
1998 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1999 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2000 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002001
2002 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002003}
2004
2005/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002006private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002007 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002008 RSL.clear;
2009
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002010 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002011 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002012 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002013 }
Harald Welte70767382018-02-21 12:16:40 +01002014
2015 f_est_dchan();
2016
2017 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2018 * RSL measurement reports on Abis side */
2019 timer T := 8.0;
2020 T.start;
2021 alt {
2022 [] as_l1_sacch();
2023 [] as_meas_res();
2024 [] as_l1_dcch();
2025 [] L1CTL.receive { repeat; }
2026 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002027 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002028 * of any earlier errors, so if we reach this timeout, we're good */
2029 setverdict(pass);
2030 }
2031 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002033 }
2034 }
2035 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002036 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002037}
Harald Welte0472ab42018-03-12 15:02:26 +01002038
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002039/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2040private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002041 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002042 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2043 timer Tup := 10.0;
2044 Tup.start;
2045 alt {
2046 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2047 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2048 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002049
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002050 if (rx_lvl != max_rx_lvl) {
2051 repeat;
2052 }
2053 Tup.stop;
2054 }
2055 [] L1CTL.receive { repeat; }
2056 [] Tup.timeout {
2057 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2058 log2str("Didn't reach full power ", max_rx_lvl));
2059 }
2060 }
2061 return max_rx_lvl;
2062}
2063
2064/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2065private function f_verify_ramp_up() runs on ConnHdlr {
2066 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002067 var integer initial_rx_lvl := -1;
2068 var integer last_rx_lvl := -1;
2069 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2070
2071 timer T := 2.0;
2072 alt {
2073 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2074 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2075 log("Received rx_level=", rx_lvl);
2076 if (initial_rx_lvl == -1) {
2077 initial_rx_lvl := rx_lvl;
2078 last_rx_lvl := rx_lvl;
2079
2080 /* Expect a somehow low value during first received messages */
2081 if (initial_rx_lvl >= max_rx_lvl / 2) {
2082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2083 log2str("Detected high initial tx power during ramp up: ",
2084 initial_rx_lvl , ", full power is", max_rx_lvl));
2085 }
2086 }
2087
2088 /* received Rx level bigger than maximum allowed power by CN */
2089 if (rx_lvl > max_rx_lvl) {
2090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2091 log2str("Detected Tx power higher than full power: ",
2092 rx_lvl , " > ", max_rx_lvl));
2093 }
2094
2095 /* Make sure it never decreases, since we are rumping up */
2096 if (last_rx_lvl > rx_lvl) {
2097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2098 log2str("Detected Tx power decrease during ramp up: ",
2099 last_rx_lvl , " -> ", rx_lvl));
2100 }
2101
2102 if (rx_lvl == max_rx_lvl and not T.running) {
2103 /* We reached the maximum power, start timer and receive
2104 /* a few more to make sure we don't surpass it */
2105 log("Reached full power, wating a bit more until success");
2106 T.start;
2107 }
2108
2109 last_rx_lvl := rx_lvl;
2110 repeat;
2111 }
2112 [] L1CTL.receive { repeat; }
2113 [] T.timeout { }
2114 }
2115
2116 /* We didn't increase tx power during ramp up */
2117 if (initial_rx_lvl < last_rx_lvl) {
2118 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2119 } else {
2120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2121 log2str("No Tx power increase during whole ramp up: ",
2122 initial_rx_lvl , " -> ", last_rx_lvl));
2123 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002124}
2125
2126/* verify BTS ramps power down to rx_level 0 */
2127private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2128 var L1ctlDlMessage l1_dl;
2129 var integer last_rx_lvl := max_rx_lvl;
2130
2131 timer Tdown := 5.0;
2132 Tdown.start;
2133 alt {
2134 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2135 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2136 log("Received rx_level=", rx_lvl);
2137
2138 /* received Rx level bigger than maximum allowed power by CN */
2139 if (rx_lvl > max_rx_lvl) {
2140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2141 log2str("Detected Tx power higher than full power: ",
2142 rx_lvl , " > ", max_rx_lvl));
2143 }
2144
2145 /* Make sure it never increases, since we are rumping down */
2146 if (last_rx_lvl < rx_lvl) {
2147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2148 log2str("Detected Tx power increase during ramp up: ",
2149 last_rx_lvl , " -> ", rx_lvl));
2150 }
2151
2152 last_rx_lvl := rx_lvl;
2153 if (last_rx_lvl != 0) {
2154 repeat;
2155 }
2156 /* we reached power level 0, we are done */
2157 Tdown.stop;
2158 }
2159 [] L1CTL.receive { repeat; }
2160 [] Tdown.timeout { }
2161 }
2162
2163 /* We didn't increase tx power during ramp down */
2164 if (max_rx_lvl > last_rx_lvl) {
2165 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2166 } else {
2167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2168 log2str("No Tx power decrease during whole ramp down: ",
2169 max_rx_lvl , " -> ", last_rx_lvl));
2170 }
2171}
2172
2173/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002174private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002175 f_l1_tune(L1CTL);
2176 RSL.clear;
2177
2178 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002179
2180 setverdict(pass);
2181}
2182testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2183 var ConnHdlr vc_conn;
2184 var ConnHdlrPars pars;
2185 f_init();
2186 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2187 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2188 pcu_comp := false, trxc_comp := true);
2189 vc_conn.done;
2190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2191}
2192
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002193/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002194private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002195 f_connhdlr_init_vty_bsc();
2196
2197 f_l1_tune(L1CTL);
2198 RSL.clear;
2199
2200 /* Wait until BTS is started and at full power */
2201 var integer max_rx_lvl := f_wait_ramp_up();
2202 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2203
2204 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2205 f_verify_ramp_down(max_rx_lvl);
2206
2207 setverdict(pass);
2208}
2209testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2210 var ConnHdlr vc_conn;
2211 var ConnHdlrPars pars;
2212 f_init();
2213 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2214 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2215 pcu_comp := false, trxc_comp := true);
2216 vc_conn.done;
2217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2218}
2219
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002220/* Verify Tx power:
2221 * + ramping down during ADM state UNLOCKED->LOCKED
2222 * + ramping up during ADM state LOCKED->UNLOCKED
2223 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002224private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002225 var L1ctlDlMessage l1_dl;
2226 var integer last_rx_lvl;
2227
2228 f_connhdlr_init_vty_bsc();
2229
2230 f_l1_tune(L1CTL);
2231 RSL.clear;
2232
2233 /* Wait until BTS is started and at full power */
2234 var integer max_rx_lvl := f_wait_ramp_up();
2235 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2236
2237 log("ADM STATE UNLOCKED->LOCKED");
2238 f_vty_enter_cfg_trx(BSCVTY);
2239 f_vty_transceive(BSCVTY, "rf_locked 1");
2240 last_rx_lvl := max_rx_lvl;
2241 f_verify_ramp_down(max_rx_lvl);
2242
2243 /* Let some time after we received 0dBm, then check we don't receive BCCH
2244 * anymore because scheduler has stopped after ramping down */
2245 f_sleep(2.0);
2246 L1CTL.clear;
2247 timer Tlocked := 2.0;
2248 Tlocked.start;
2249 alt {
2250 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2252 log2str("Received data_ind during rf_locked: ", l1_dl));
2253 }
2254 [] L1CTL.receive { repeat; }
2255 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2256 }
2257
2258 log("ADM STATE LOCKED->UNLOCKED");
2259 f_vty_transceive(BSCVTY, "rf_locked 0");
2260 f_verify_ramp_up();
2261 setverdict(pass);
2262}
2263testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2264 var ConnHdlr vc_conn;
2265 var ConnHdlrPars pars;
2266 f_init();
2267 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2268 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2269 pcu_comp := false, trxc_comp := true);
2270 vc_conn.done;
2271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2272}
2273
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002274private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002275 timer T := 8.0;
2276 T.start;
2277 var RSL_Message rsl;
2278 alt {
2279 [] as_l1_sacch();
2280 [] L1CTL.receive { repeat; }
2281 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2282 if (rsl.ies[3].body.bs_power.power_level == level) {
2283 setverdict(pass)
2284 } else {
2285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2286 }
2287 }
2288 [] T.timeout {
2289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2290 }
2291 }
2292}
2293
2294/* see if the rsl meas res contains our expeced bs power level
2295bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002296private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002297 f_l1_tune(L1CTL);
2298 RSL.clear;
2299
2300 if (mp_bts_trxc_port != -1) {
2301 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2302 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2303 }
2304
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002305 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002306 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2307 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2308
2309 f_est_dchan(more_ies :={valueof(pwr)});
2310
2311 f_check_meas_bs_power_level(pwr_var);
2312
2313 f_rsl_chan_deact();
2314 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2315}
2316
2317/* see if the rsl meas res contains our expeced bs power level
2318bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002319private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002320 f_l1_tune(L1CTL);
2321 RSL.clear;
2322
2323 if (mp_bts_trxc_port != -1) {
2324 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2325 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2326 }
2327
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002328 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002329 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2330
2331 f_est_dchan();
2332
2333 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2334
2335 f_check_meas_bs_power_level(pwr_var);
2336
2337 f_rsl_chan_deact();
2338 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2339}
2340
2341testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2342 var ConnHdlr vc_conn;
2343 var ConnHdlrPars pars;
2344 f_init();
2345 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2346 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2347 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2348 pcu_comp := false, trxc_comp := true);
2349 vc_conn.done;
2350 }
2351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2352}
2353
2354testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2355 var ConnHdlr vc_conn;
2356 var ConnHdlrPars pars;
2357 f_init();
2358 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2359 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2360 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2361 pcu_comp := false, trxc_comp := true);
2362 vc_conn.done;
2363 }
2364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2365}
2366
Eric Wild61edb7e2019-06-03 12:38:31 +02002367/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2368second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2369These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002370private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002371 var uint5_t pwr_var := 7;
2372 var L1ctlDlMessage l1_dl;
2373
2374 f_trxc_fake_rssi(rxlev2dbm(10));
2375 f_l1_tune(L1CTL);
2376 RSL.clear;
2377
2378 var RSL_IE_List addl_ies;
2379 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2380
2381 addl_ies := {
2382 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2383 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2384 };
2385
2386 /* establish with power parameters */
2387 f_est_dchan(more_ies := addl_ies);
2388
2389 /* set a high value to ensure L1 power control level increases */
2390 f_trxc_fake_rssi(rxlev2dbm(20));
2391
2392 timer T2 := 6.0;
2393 T2.start;
2394 alt {
2395 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002396 /* Update sent MS power to follow what BTS requests */
2397 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2398 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002399 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002400 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002401 T2.stop;
2402 }
2403 [] L1CTL.receive { repeat; }
2404 [] T2.timeout {
2405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2406 "Power Level in L1 header has not increased sufficiently");
2407 }
2408 }
2409
2410 /* set a low value to ensure L1 power control level decreases */
2411 f_trxc_fake_rssi(rxlev2dbm(0));
2412
2413 timer T4 := 6.0;
2414 T4.start;
2415 alt {
2416 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002417 /* Update sent MS power to follow what BTS requests */
2418 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2419 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002420 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002421 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002422 T4.stop;
2423 setverdict(pass, "Power level in L1 decreased/increased as expected");
2424 }
2425 [] L1CTL.receive { repeat; }
2426 [] T4.timeout {
2427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2428 "Power Level in L1 header has not decreased sufficiently");
2429 }
2430 }
2431
2432 f_rsl_chan_deact();
2433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2434
2435}
2436
2437/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002438private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002439 var uint5_t pwr_var := 7;
2440 var L1ctlDlMessage l1_dl;
2441
2442 /* set a low value to ensure power increases */
2443 f_trxc_fake_rssi(rxlev2dbm(10));
2444 f_l1_tune(L1CTL);
2445 RSL.clear;
2446
2447 var RSL_IE_List addl_ies;
2448 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2449
2450 addl_ies := {
2451 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2452 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2453 };
2454
2455 /* establish with power parameters */
2456 f_est_dchan(more_ies := addl_ies);
2457
2458 timer T1 := 10.0;
2459 T1.start;
2460 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002461 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2462 /* Update sent MS power to follow what BTS requests */
2463 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2464 repeat;
2465 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002466 [] L1CTL.receive { repeat; }
2467 [] T1.timeout {
2468 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2469 setverdict(fail, "Power level in L1 header should not have changed");
2470 }
2471 }
2472 }
2473
2474 f_rsl_chan_deact();
2475 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2476
2477}
2478
2479/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002480private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002481 var L1ctlDlMessage l1_dl;
2482 var uint5_t pwr_var := 15;
2483 var uint5_t pwr_max_var := f_get_max_power_from_band();
2484
2485 /* set a low value to ensure power increases */
2486 f_trxc_fake_rssi(rxlev2dbm(10));
2487 f_l1_tune(L1CTL);
2488 RSL.clear;
2489
2490 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2491 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2492
2493 /* establish with fixed power level */
2494 f_est_dchan(more_ies :={valueof(pwr)});
2495
2496 /* check our initial power level */
2497 f_wait_for_l1_power_level(pwr_var);
2498
2499 /* update power param to enable power loop
2500 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2501 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2502
2503 /* wait, then check that our power level was reduced */
2504 timer T1 := 10.0;
2505 T1.start;
2506 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002507 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2508 /* Update sent MS power to follow what BTS requests */
2509 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2510 repeat;
2511 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002512 [] L1CTL.receive { repeat; }
2513 [] T1.timeout {
2514 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2515 if( f_power_level_is_highest_dbm(rcv) ){
2516 setverdict(pass, "Power level in L1 header reduced as expected");
2517 } else {
2518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2519 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2520 }
2521 }
2522 }
2523
2524 f_rsl_chan_deact();
2525 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2526
2527}
2528
2529/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002530private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002531 var L1ctlDlMessage l1_dl;
2532
2533 /* set a high value to ensure power decreases */
2534 f_trxc_fake_rssi(rxlev2dbm(50));
2535 f_l1_tune(L1CTL);
2536 RSL.clear;
2537
2538 var uint5_t pwr_var := 5;
2539 var uint5_t pwr_target_val := 15;
2540
2541 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2542 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2543
2544 /* establish with fixed power level */
2545 f_est_dchan(more_ies :={valueof(pwr)});
2546
2547 /* check our initial power level */
2548 f_wait_for_l1_power_level(pwr_var);
2549
2550 /* update power param to enable power loop
2551 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002552 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002553
2554 /* wait, then check that our power level was increased */
2555 timer T1 := 10.0;
2556 T1.start;
2557 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002558 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2559 /* Update sent MS power to follow what BTS requests */
2560 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2561 repeat;
2562 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 [] L1CTL.receive { repeat; }
2564 [] T1.timeout {
2565 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2566 setverdict(pass, "Power level in L1 header increased to lowest power value");
2567 } else {
2568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2569 "Power level in L1 header NOT increased to lowest power value");
2570 }
2571 }
2572 }
2573
2574 f_rsl_chan_deact();
2575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2576
2577}
2578
Eric Wild095024b2019-06-17 15:08:57 +02002579/* see if we change the power level without receiving power parameters, which should not happen
2580rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002581private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002582 var L1ctlDlMessage l1_dl;
2583
2584 /* set a high value to ensure power decreases */
2585 f_trxc_fake_rssi(rxlev2dbm(50));
2586 f_l1_tune(L1CTL);
2587 RSL.clear;
2588
2589 var uint5_t pwr_var := 5;
2590
2591 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2592 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2593
2594 /* establish with fixed power level */
2595 f_est_dchan(more_ies :={valueof(pwr)});
2596
2597 /* check our initial power level */
2598 f_wait_for_l1_power_level(pwr_var);
2599
2600 /* wait, then check that our power level did not change */
2601 timer T1 := 10.0;
2602 T1.start;
2603 alt {
2604 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2605 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2607 "BS power control should not be active unless we receive a power parameters IE!");
2608 }
2609 repeat;
2610 }
2611 [] L1CTL.receive { repeat; }
2612 [] T1.timeout { setverdict(pass); }
2613 }
2614
2615 f_rsl_chan_deact();
2616 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2617
2618}
2619
Eric Wild095024b2019-06-17 15:08:57 +02002620/* see if we change the power level without receiving power parameters, which should not happen
2621ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002622private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002623 var L1ctlDlMessage l1_dl;
2624
2625 /* set a high value to ensure power decreases */
2626 f_trxc_fake_rssi(rxlev2dbm(50));
2627 f_l1_tune(L1CTL);
2628 RSL.clear;
2629
2630 var uint5_t pwr_var := 5;
2631
2632 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2633 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2634
2635 /* establish with fixed power level */
2636 f_est_dchan(more_ies :={valueof(pwr)});
2637
2638 /* check our initial power level */
2639 f_wait_for_l1_power_level(pwr_var);
2640
2641 /* pwr control without power params IE, should NOT activate MS power control*/
2642 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2643
2644 /* wait, then check that our power level did not change */
2645 timer T1 := 10.0;
2646 T1.start;
2647 alt {
2648 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2649 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 "BS power control should not be active unless we receive a power parameters IE!");
2652 }
2653 repeat;
2654 }
2655 [] L1CTL.receive { repeat; }
2656 [] T1.timeout { setverdict(pass); }
2657 }
2658
2659 f_rsl_chan_deact();
2660 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2661
2662}
2663
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002664private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002665 var L1ctlDlMessage l1_dl;
2666 timer T0 := 10.0;
2667 T0.start;
2668 alt {
2669 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2670 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2672 "Power level in L1 header != signaled (RSL) power level.");
2673 }
2674 }
2675 [] L1CTL.receive { repeat; }
2676 [] T0.timeout {
2677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2678 "Timeout waiting for initial power level");
2679 }
2680 }
2681 T0.stop;
2682}
2683
2684private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2685 var IntegerRecord min_dbm_level;
2686 var IntegerRecord max_dbm_level;
2687 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2688
2689 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2690 if (min_dbm_level[i] == level) {
2691 return true;
2692 }
2693 }
2694 return false;
2695}
2696
2697private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2698 var IntegerRecord min_dbm_level;
2699 var IntegerRecord max_dbm_level;
2700 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2701
2702 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2703 if (max_dbm_level[i] == level) {
2704 return true;
2705 }
2706 }
2707 return false;
2708}
2709
2710private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2711 var IntegerRecord min_dbm_level;
2712 var IntegerRecord max_dbm_level;
2713 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2714 return max_dbm_level[0];
2715}
2716
2717type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002718private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002719private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2720 // 45.005 4.1.1
2721 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2722 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2723 2, 1, 0};
2724 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2725 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2726 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2727 var IntegerRecord rv;
2728
2729 select(band){
2730 case (BtsBand_allGSM){
2731 rv := gsm_power;
2732 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2733 max_dbm_level := {2, 1, 0};
2734 }
2735 case("DCS1800"){
2736 rv := dcs_power;
2737 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2738 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2739 }
2740 case("PCS1900"){
2741 rv := pcs_power;
2742 min_dbm_level := {15};
2743 max_dbm_level := {30};
2744 }
2745 }
2746
2747 return rv;
2748}
2749
2750private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2751 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2752}
2753
2754testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2755 var ConnHdlr vc_conn;
2756 var ConnHdlrPars pars;
2757 f_init();
2758 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2759 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2760 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2761 pars.bts0_band := f_vty_get_bts0_band();
2762 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2763 vc_conn.done;
2764 }
2765 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2767}
2768
2769testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2770 var ConnHdlr vc_conn;
2771 var ConnHdlrPars pars;
2772 f_init();
2773 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2774 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2775 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2776 pars.bts0_band := f_vty_get_bts0_band();
2777 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2778 vc_conn.done;
2779 }
2780 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2782}
2783
2784testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2785 var ConnHdlr vc_conn;
2786 var ConnHdlrPars pars;
2787 f_init();
2788 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2789 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2790 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2791 pars.bts0_band := f_vty_get_bts0_band();
2792 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2793 vc_conn.done;
2794 }
2795 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2797}
2798
2799testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2800 var ConnHdlr vc_conn;
2801 var ConnHdlrPars pars;
2802 f_init();
2803 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2804 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2805 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2806 pars.bts0_band := f_vty_get_bts0_band();
2807 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2808 vc_conn.done;
2809 }
2810 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2812}
2813
Eric Wild280ccb82019-06-17 11:11:52 +02002814testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2815 var ConnHdlr vc_conn;
2816 var ConnHdlrPars pars;
2817 f_init();
2818 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2819 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2820 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2821 pars.bts0_band := f_vty_get_bts0_band();
2822 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2823 vc_conn.done;
2824 }
2825 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2827}
2828
Eric Wild095024b2019-06-17 15:08:57 +02002829testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2830 var ConnHdlr vc_conn;
2831 var ConnHdlrPars pars;
2832 f_init();
2833 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2834 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2835 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2836 pars.bts0_band := f_vty_get_bts0_band();
2837 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2838 vc_conn.done;
2839 }
2840 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2842}
2843
Harald Welte70767382018-02-21 12:16:40 +01002844testcase TC_meas_res_sign_tchf() runs on test_CT {
2845 var ConnHdlr vc_conn;
2846 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002847 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002848 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2849 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002850 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2851 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002852 vc_conn.done;
2853 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002855}
2856testcase TC_meas_res_sign_tchh() runs on test_CT {
2857 var ConnHdlr vc_conn;
2858 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002859 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002860 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2861 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002862 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2863 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002864 vc_conn.done;
2865 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002867}
2868testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2869 var ConnHdlr vc_conn;
2870 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002871 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002872 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2873 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002874 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2875 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002876 vc_conn.done;
2877 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002879}
2880testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2881 var ConnHdlr vc_conn;
2882 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002883 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002884 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2885 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002886 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2887 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002888 vc_conn.done;
2889 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002891}
Harald Welte685d5982018-02-27 20:42:05 +01002892testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2893 var ConnHdlr vc_conn;
2894 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002895 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002896 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2897 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2898 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2899 pars.l1_pars.toa256_enabled := true;
2900 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2901 vc_conn.done;
2902 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002904}
2905
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002906/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2907 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002908private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002909 var L1ctlDlMessage l1_dl;
2910 var RSL_IE_MS_Power ms_power;
2911 var RSL_Message rsl;
2912 var uint5_t power_level := 0;
2913
2914 f_l1_tune(L1CTL);
2915 RSL.clear;
2916
2917 f_est_dchan();
2918
2919 ms_power.reserved := 0;
2920 ms_power.fpc_epc := false;
2921
2922 /* Send the first power control command. This will disable any BTS/TRX
2923 * internal power control and switch the MS (which is not in scope of
2924 * this test) to a constant power level. We start with a power level
2925 * of 0 */
2926 ms_power.power_level := power_level;
2927 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2928 RSL.send(rsl);
2929
2930 alt {
2931
2932 /* Pick all SACCH blocks for checking */
2933 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2934
2935 /* The first byte of the L1 header contains the power level.
2936 * The reserved bits and the fpc bit is set to 0, so we may
2937 * compare directly. */
2938 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2939 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2940 }
2941
2942 /* Signal a new power level via RSL for the next turn. */
2943 if (power_level < 31) {
2944 power_level := power_level + 1;
2945 ms_power.power_level := power_level;
2946 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2947 RSL.send(rsl);
2948 repeat;
2949 }
2950
2951 }
2952
2953 /* Ignore all other blocks */
2954 [] L1CTL.receive { repeat; }
2955
2956 }
2957
2958 f_rsl_chan_deact();
2959 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2960
2961 setverdict(pass);
2962}
2963
2964testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2965 var ConnHdlr vc_conn;
2966 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002967 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002968
2969 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2970 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2971 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2972 vc_conn.done;
2973 }
2974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2975}
Harald Welte70767382018-02-21 12:16:40 +01002976
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002977/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002978TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002979private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02002980 var L1ctlDlMessage l1_dl;
2981 var uint5_t ta_to_test := 16;
2982
2983
2984 f_l1_tune(L1CTL);
2985 RSL.clear;
2986
2987 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002988 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002989
2990 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2991
2992
2993 alt {
2994
2995 /* Pick all SACCH blocks for checking */
2996 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2997
2998 /* The second byte of the L1 header contains the TA. */
2999 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3000 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3001 }
3002
3003 }
3004
3005 /* Ignore all other blocks */
3006 [] L1CTL.receive { repeat; }
3007
3008 }
3009
3010 f_rsl_chan_deact();
3011 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3012
3013 setverdict(pass);
3014}
3015
3016testcase TC_rsl_chan_initial_ta() runs on test_CT {
3017 var ConnHdlr vc_conn;
3018 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003019 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003020 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003021 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3022 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003023 vc_conn.done;
3024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3025}
3026
Eric Wilde57e1a62019-05-28 13:30:55 +02003027/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003028private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003029 var L1ctlDlMessage l1_dl;
3030 var uint5_t ms_power_level := 7;
3031
3032 var RSL_IE_MS_Power ms_power;
3033 ms_power.reserved := 0;
3034 ms_power.fpc_epc := false;
3035 ms_power.power_level := ms_power_level;
3036
3037 f_l1_tune(L1CTL);
3038 RSL.clear;
3039
3040 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3041
3042 timer T := 1.0;
3043 T.start;
3044 alt {
3045 /* Pick all SACCH blocks for checking */
3046 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3047 /* The first byte of the L1 header contains the power level.. */
3048 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3049 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3050 }
3051 }
3052 /* Ignore all other blocks */
3053 [] L1CTL.receive { repeat; }
3054 [] T.timeout {
3055 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3056 }
3057 }
3058
3059 f_rsl_chan_deact();
3060 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3061 setverdict(pass);
3062}
3063
3064testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3065 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3066 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3067}
3068
Harald Welte0472ab42018-03-12 15:02:26 +01003069/* 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 +01003070private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003071 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003072 RSL.clear;
3073
3074 f_est_dchan();
3075 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003076 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003077
3078 timer T := 40.0;
3079 T.start;
3080 alt {
3081 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3082 setverdict(pass)
3083 }
3084 [] RSL.receive { repeat };
3085 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003087 }
3088 }
3089 f_rsl_chan_deact();
3090}
3091testcase TC_conn_fail_crit() runs on test_CT {
3092 var ConnHdlr vc_conn;
3093 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003094 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003095 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3096 pars.t_guard := 60.0;
3097 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3098 vc_conn.done;
3099}
3100
Harald Welte93640c62018-02-25 16:59:33 +01003101/***********************************************************************
3102 * Paging
3103 ***********************************************************************/
3104
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003105private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003106 if (tmsi == 'FFFFFFFF'O) {
3107 return true;
3108 } else {
3109 return false;
3110 }
3111}
Harald Welte70767382018-02-21 12:16:40 +01003112
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003113private type record allowedFn { integer frame_nr }
3114private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3115private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3116private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3117private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3118private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3119private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3120private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3121private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3122private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003123{
3124 var integer frame_nr_51;
3125 frame_nr_51 := frame_nr mod 51
3126
3127 var allowedFn fn_check;
3128 fn_check.frame_nr := frame_nr_51;
3129
3130 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003132 return;
3133 }
3134
3135 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3136 return;
3137 }
3138 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3139 return;
3140 }
3141 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3142 return;
3143 }
3144 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3145 return;
3146 }
3147 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3148 return;
3149 }
3150 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3151 return;
3152 }
3153 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3154 return;
3155 }
3156 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3157 return;
3158 }
3159
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003161 return;
3162}
3163
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003164private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3165 inout integer num_paging_rcv_ids,
3166 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003167runs on test_CT {
3168 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003169 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003170 repeat;
3171 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003172 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003173 var octetstring without_plen :=
3174 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3175 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003176
3177 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3178
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003179 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3180 /* Ignore empty RR Paging Request (PCH filling) messages.
3181 * TODO: does it make sense to count them? */
3182 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003183 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3184 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003185 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003186 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3187 }
3188 } else if (match(rr, tr_PAGING_REQ2)) {
3189 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3190 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3191 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3192 }
3193 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3194 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3195 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003196 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003197 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3198 }
3199 } else if (match(rr, tr_PAGING_REQ3)) {
3200 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3201 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3202 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3203 }
3204 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3205 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3206 }
3207 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3208 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3209 }
3210 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3211 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3212 }
3213 }
3214 repeat;
3215 }
3216}
3217
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003218private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003219 boolean combined_ccch,
3220 integer bs_ag_blks_res,
3221 float load_factor,
3222 boolean exp_load_ind,
3223 boolean exp_overload,
3224 boolean use_tmsi
3225}
3226
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003227private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003228 integer num_paging_sent,
3229 integer num_paging_rcv_msgs,
3230 integer num_paging_rcv_ids,
3231 integer num_overload
3232}
3233
Harald Welte68e495b2018-02-25 00:05:57 +01003234/* Helper function for paging related testing */
3235private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003236 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003237 f_init_l1ctl();
3238 f_l1_tune(L1CTL);
3239
3240 var PagingTestState st := {
3241 num_paging_sent := 0,
3242 num_paging_rcv_msgs := 0,
3243 num_paging_rcv_ids := 0,
3244 num_overload := 0
3245 };
3246
3247 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3248 var float max_pch_imsi_per_sec;
3249 if (cfg.use_tmsi) {
3250 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3251 } else {
3252 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3253 }
3254 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3255 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003256 var float time_total := 20.0;
3257 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3258 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003259
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003260 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3261 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003262
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003263 timer T_itv := 0.0;
3264 T_itv.start;
3265 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003266 alt {
3267 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003268 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003269 st.num_overload := st.num_overload + 1;
3270 repeat;
3271 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003272 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003274 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003275 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003276 log("Rx LOAD_IND");
3277 /* FIXME: analyze/verify interval + contents */
3278 repeat;
3279 }
3280 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003281 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003282 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003283 [] T_itv.timeout {
3284 /* Send paging cmds based on elapsed time */
3285 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3286 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003287 var MobileIdentityV mi;
3288
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003289 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003290 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003291 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003292 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003293 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003294 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003295
3296 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003297 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 +02003298
3299 st.num_paging_sent := st.num_paging_sent + 1;
3300 }
3301 if (st.num_paging_sent < pkt_total) {
3302 /* Wait for interval to next PAGING COMMAND */
3303 var float time_now := T_total.read;
3304 var float next_sched := int2float(st.num_paging_sent)*interval;
3305 if (next_sched > time_now) {
3306 T_itv.start(next_sched - time_now);
3307 } else {
3308 T_itv.start(0.0);
3309 }
3310 } else {
3311 /* We are done, no need to keep counting */
3312 T_total.stop;
3313 }
3314 }
3315 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003316 }
3317 }
3318
3319 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3320 timer T_wait := 18.0;
3321 T_wait.start;
3322 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003323 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003324 [] L1CTL.receive { repeat; }
3325 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003326 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3327 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003328 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003330 }
Harald Welte68e495b2018-02-25 00:05:57 +01003331 }
3332
3333 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3334 " rcvd_ids=", st.num_paging_rcv_ids);
3335 return st;
3336}
3337
3338/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3339 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3340 * - that CCCH LOAD IND (PCH) are being generated
3341 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3342testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003343 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003344 var PagingTestCfg cfg := {
3345 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003346 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003347 load_factor := 0.8,
3348 exp_load_ind := true,
3349 exp_overload := false,
3350 use_tmsi := false
3351 };
3352 var PagingTestState st := f_TC_paging(cfg);
3353 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3355 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003356 } else {
3357 setverdict(pass);
3358 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003360}
3361
3362/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3363 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3364 * - that CCCH LOAD IND (PCH) are being generated
3365 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3366testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003367 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003368 var PagingTestCfg cfg := {
3369 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003370 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003371 load_factor := 0.8,
3372 exp_load_ind := true,
3373 exp_overload := false,
3374 use_tmsi := true
3375 };
3376 var PagingTestState st := f_TC_paging(cfg);
3377 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3379 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003380 } else {
3381 setverdict(pass);
3382 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003384}
3385
3386/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3387 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3388 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3389 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3390testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003391 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003392 var PagingTestCfg cfg := {
3393 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003394 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003395 load_factor := 2.0,
3396 exp_load_ind := true,
3397 exp_overload := true,
3398 use_tmsi := false
3399 };
3400 var PagingTestState st := f_TC_paging(cfg);
3401 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3402 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003403 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003404 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003405 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 +01003406 } else {
3407 setverdict(pass);
3408 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003410}
3411
3412/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3413 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3414 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3415 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3416testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003417 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003418 var PagingTestCfg cfg := {
3419 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003420 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003421 load_factor := 2.0,
3422 exp_load_ind := true,
3423 exp_overload := true,
3424 use_tmsi := true
3425 };
3426 var PagingTestState st := f_TC_paging(cfg);
3427 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3428 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003429 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003430 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003431 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 +01003432 } else {
3433 setverdict(pass);
3434 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003436}
3437
3438
Harald Welte93640c62018-02-25 16:59:33 +01003439/***********************************************************************
3440 * Immediate Assignment / AGCH
3441 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003442private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003443 len := 0,
3444 ma := ''B
3445}
Harald Welte93640c62018-02-25 16:59:33 +01003446
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003447private template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr,
3448 template (value) uint3_t tsc := 7,
3449 template (value) uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003450 chan_nr := chan_nr,
3451 tsc := tsc,
3452 h := false,
3453 arfcn := arfcn,
3454 maio_hsn := omit
3455}
3456
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003457private template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr,
3458 template (value) uint3_t tsc := 7,
3459 template (value) MaioHsn maio_hsn) := {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003460 chan_nr := chan_nr,
3461 tsc := tsc,
3462 h := true,
3463 arfcn := omit,
3464 maio_hsn := maio_hsn
3465}
3466
Harald Weltee8d750e2018-06-10 21:41:35 +02003467private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3468 return int2str(num_tx) & " sent, "
3469 & int2str(num_rx) & " received, "
3470 & int2str(num_del) & " deleted";
3471}
3472
3473private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3474 var L1ctlDlMessage l1_dl;
3475 timer T := 10.0;
3476 var integer num_tx := 0;
3477 var integer num_rx := 0;
3478 var integer num_del := 0;
3479 var charstring res_str;
3480 var float rx_ratio;
3481
Harald Welte10474062019-05-30 16:48:17 +02003482 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003483 f_init_l1ctl();
3484 f_l1_tune(L1CTL);
3485
3486 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003487 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003488 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3489 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003490 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003491 num_tx := num_tx+1;
3492 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003493 }
3494 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003495 T.start;
3496 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003497 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003498 num_del := num_del+1;
3499 repeat;
3500 }
3501 [] RSL_CCHAN.receive {
3502 repeat;
3503 }
3504 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3505 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3506 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3507 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3508 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003509 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003510 } else {
3511 num_rx := num_rx+1;
3512 }
3513 repeat;
3514 }
3515 [] L1CTL.receive { repeat; }
3516 [] T.timeout { }
3517 }
3518 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3519 log("AGCH test: " & res_str);
3520 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003522 }
3523 rx_ratio := int2float(num_rx) / int2float(num_tx);
3524 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003525 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 +02003526 } else {
3527 setverdict(pass);
3528 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003530}
3531
Harald Weltee8d750e2018-06-10 21:41:35 +02003532/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3533testcase TC_imm_ass_1000_20ms() runs on test_CT {
3534 f_TC_imm_ass(1000, 0.02, 0.25);
3535}
3536
3537/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3538testcase TC_imm_ass_200_0ms() runs on test_CT {
3539 f_TC_imm_ass(200, 0.0, 0.05);
3540}
3541
3542/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3543testcase TC_imm_ass_200_76ms() runs on test_CT {
3544 f_TC_imm_ass(150, 0.076, 1.00);
3545}
3546
3547
3548
Harald Welte48494ca2018-02-25 16:59:50 +01003549/***********************************************************************
3550 * BCCH
3551 ***********************************************************************/
3552
3553/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003554private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003555 GsmFrameNumber frame_number,
3556 SystemInformation si
3557}
3558
3559/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003560private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003561
3562/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003563private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003564
3565/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003566private function f_si_vecslot_contains(SystemInformationVector arr,
3567 RrMessageType key,
3568 boolean bcch_ext := false)
3569return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003570 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3571 var integer fn_mod51 := arr[i].frame_number mod 51;
3572 if (not bcch_ext and fn_mod51 == 2 or
3573 bcch_ext and fn_mod51 == 6) {
3574 if (arr[i].si.header.message_type == key) {
3575 return true;
3576 }
3577 }
3578 }
3579 return false;
3580}
3581
3582/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003583private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3584 integer tc, RrMessageType key,
3585 boolean ext_bcch := false)
3586{
Harald Welte48494ca2018-02-25 16:59:50 +01003587 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003589 }
3590}
3591
3592/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003593private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3594 RrMessageType key)
3595return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003596 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3597 if (f_si_vecslot_contains(arr[tc], key) or
3598 f_si_vecslot_contains(arr[tc], key, true)) {
3599 return true;
3600 }
3601 }
3602 return false;
3603}
3604
3605/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003606private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3607 RrMessageType key,
3608 boolean bcch_ext := false,
3609 integer n := 1, integer m := 4)
3610return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003611 var integer count := 0;
3612 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003614 }
3615 for (var integer i:= 0; i < m; i := i + 1) {
3616 var integer fn_mod51 := arr[i].frame_number mod 51;
3617 if (not bcch_ext and fn_mod51 == 2 or
3618 bcch_ext and fn_mod51 == 6) {
3619 if (arr[i].si.header.message_type == key) {
3620 count := count + 1;
3621 }
3622 }
3623 }
3624 if (count >= n) {
3625 return true;
3626 } else {
3627 return false;
3628 }
3629}
3630
3631/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003632private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3633 integer tc, RrMessageType key,
3634 boolean ext_bcch := false,
3635 integer n, integer m)
3636{
Harald Welte48494ca2018-02-25 16:59:50 +01003637 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003639 }
3640}
3641
3642/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003643private function f_si_vecslot_contains_only(SystemInformationVector arr,
3644 RrMessageType key,
3645 boolean bcch_ext := false)
3646return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003647 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3648 var integer fn_mod51 := arr[i].frame_number mod 51;
3649 if (not bcch_ext and fn_mod51 == 2 or
3650 bcch_ext and fn_mod51 == 6) {
3651 if (arr[i].si.header.message_type != key) {
3652 return false;
3653 }
3654 }
3655 }
3656 return true;
3657}
3658
3659/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003660private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3661 integer tc, RrMessageType key,
3662 boolean ext_bcch := false)
3663{
Harald Welte48494ca2018-02-25 16:59:50 +01003664 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003666 }
3667}
3668
3669/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003670private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003671 boolean bcch_extended,
3672 boolean si1_present,
3673 boolean si2bis_present,
3674 boolean si2ter_present,
3675 boolean si2quater_present,
3676 boolean si7_present,
3677 boolean si8_present,
3678 boolean si9_present,
3679 boolean si13_present,
3680 boolean si13alt_present,
3681 boolean si15_present,
3682 boolean si16_present,
3683 boolean si17_present,
3684 boolean si2n_present,
3685 boolean si21_present,
3686 boolean si22_present
3687}
3688
3689/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003690private function f_validate_si_scheduling(SystemInformationConfig cfg,
3691 SystemInformationVectorPerTc si_per_tc)
3692{
Harald Welte48494ca2018-02-25 16:59:50 +01003693 var integer i;
3694 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3695 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003697 }
3698 }
3699 if (cfg.si1_present) {
3700 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3701 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3702 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3703 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3704 /* make sure *ALL* contain SI1 */
3705 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3706 }
3707 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3708 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3709 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3710 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3711 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3712 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3713
3714 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3715 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3716 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3717 * consecutive occurrences of TC = 4. */
3718 if (cfg.si2bis_present and not cfg.si2ter_present) {
3719 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3720 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3721 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3722 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3723 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3724 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3725 }
3726
3727 if (cfg.si7_present or cfg.si8_present) {
3728 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3729 * if System Information type 4 does not contain all information needed for cell
3730 * selection and reselection. */
3731 if (not cfg.bcch_extended) {
3732 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3733 }
3734 if (cfg.si7_present) {
3735 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3736 }
3737 if (cfg.si8_present) {
3738 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3739 }
3740 }
3741
3742 if (cfg.si2quater_present) {
3743 /* iii) System information type 2 quater is sent if needed, as determined by the system
3744 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3745 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3746 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3747 * within any of 4 consecutive occurrences of TC = 5. */
3748 if (not (cfg.bcch_extended)) {
3749 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3750 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3751 } else {
3752 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3753 }
3754 } else {
3755 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3756 }
3757 }
3758 if (cfg.si9_present) {
3759 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3760 * in system information type 3 as defined in 3GPP TS 44.018. */
3761 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3762 }
3763 if (cfg.si13_present) {
3764 /* vii) System Information type 13 is only related to the GPRS service. System Information
3765 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3766 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3767 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3768 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3769 * within any of 4 consecutive occurrences of TC=4. */
3770 if (not cfg.bcch_extended) {
3771 log("not-bccch-extended");
3772 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3773 } else {
3774 log("bccch-extended");
3775 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3776 }
3777 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003779 }
3780 }
3781 if (cfg.si16_present or cfg.si17_present) {
3782 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3783 * should not be sent in a cell where network sharing is used (see rule xv). */
3784 if (cfg.si22_present) {
3785 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3786 }
3787 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003789 }
3790 if (not cfg.bcch_extended) {
3791 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3792 }
3793 if (cfg.si16_present) {
3794 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3795 }
3796 if (cfg.si17_present) {
3797 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3798 }
3799 }
3800
3801 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3802 * broadcast information. The frequency with which they are sent is determined by the
3803 * system operator. System Information type 9 identifies the scheduling of System
3804 * Information type 18 and 20 messages. */
3805
3806 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3807 * Information Type 19 is present, then its scheduling shall be indicated in System
3808 * Information Type 9. */
3809
3810 if (cfg.si15_present) {
3811 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3812 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3813 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3814 * 4 consecutive occurrences of TC = 1. */
3815 if (not cfg.bcch_extended) {
3816 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3817 } else {
3818 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3819 }
3820 }
3821 if (cfg.si13alt_present) {
3822 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3823 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3824 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3825 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3826 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3827 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3828 * of TC = 4. */
3829 if (cfg.si13_present) {
3830 testcase.stop("Error: Cannot have SI13alt and SI13");
3831 }
3832 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003834 }
3835 if (not cfg.bcch_extended) {
3836 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3837 } else {
3838 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3839 }
3840 }
3841 if (cfg.si2n_present) {
3842 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3843 * as determined by the system operator. In the case that the message is sent on the
3844 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3845 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3846 * consecutive occurrences of TC = 4. */
3847 if (not cfg.bcch_extended) {
3848 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3849 } else {
3850 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3851 }
3852 }
3853 if (cfg.si21_present) {
3854 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3855 * determined by the system operator. If Extended Access Barring is in use in the cell
3856 * then this message is sent at least once within any of 4 consecutive occurrences of
3857 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3858 * cell then this message shall only be sent on BCCH Ext. */
3859 if (not cfg.bcch_extended) {
3860 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3861 } else {
3862 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3863 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003865 }
3866 }
3867 }
3868 if (cfg.si22_present) {
3869 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3870 * should not be sent in a cell where SoLSA is used (see rule viii). System
3871 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3872 * =2 and TC=6. */
3873 if (cfg.si16_present or cfg.si17_present) {
3874 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3875 }
3876 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3877 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003879 }
3880 if (not cfg.bcch_extended) {
3881 testcase.stop("Error: SI22 requires BCCH Extd!");
3882 } else {
3883 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3884 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3885 }
3886 }
3887}
3888
3889/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003890private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3891return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003892 timer T := duration;
3893 var SystemInformationVectorPerTc si_per_tc;
3894 var L1ctlDlMessage l1_dl;
3895
3896 /* initialize all per-TC vectors empty */
3897 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3898 si_per_tc[i] := {};
3899 }
3900
3901 /* flush all previous L1 queued msgs */
3902 pt.clear;
3903
3904 T.start;
3905 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003906 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003907 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3908 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3909 log("Ignoring non-RR SI ", l1_dl);
3910 repeat;
3911 }
3912 var SystemInformationFn sig := {
3913 frame_number := l1_dl.dl_info.frame_nr,
3914 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3915 }
3916 var integer tc := f_gsm_compute_tc(sig.frame_number);
3917 log("SI received at TC=", tc, ": ", sig.si);
3918 /* append to the per-TC bucket */
3919 si_per_tc[tc] := si_per_tc[tc] & { sig };
3920 repeat;
3921 }
3922 [] pt.receive { repeat; }
3923 [] T.timeout { }
3924 }
3925
3926 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3927 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3928 }
3929 log("si_per_tc=", si_per_tc);
3930 return si_per_tc;
3931}
3932
3933/* helper function: Set given SI via RSL + validate scheduling.
3934 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003935private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003936 var SystemInformationVectorPerTc si_per_tc;
3937 f_init_l1ctl();
3938 f_l1_tune(L1CTL);
3939
3940 /* Sample + Validate Scheduling */
3941 si_per_tc := f_l1_sample_si(L1CTL);
3942 f_validate_si_scheduling(si_cfg, si_per_tc);
3943
3944 setverdict(pass);
3945}
3946
3947testcase TC_si_sched_default() runs on test_CT {
3948 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003949 /* 2+3+4 are mandatory and set in f_init() */
3950 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003952}
3953
3954testcase TC_si_sched_1() runs on test_CT {
3955 f_init();
3956 si_cfg.si1_present := true;
3957 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003958 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003960}
3961
3962testcase TC_si_sched_2bis() runs on test_CT {
3963 f_init();
3964 si_cfg.si2bis_present := true;
3965 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3966 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003968}
3969
3970testcase TC_si_sched_2ter() runs on test_CT {
3971 f_init();
3972 si_cfg.si2ter_present := true;
3973 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3974 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003976}
3977
3978testcase TC_si_sched_2ter_2bis() runs on test_CT {
3979 f_init();
3980 si_cfg.si2bis_present := true;
3981 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3982 si_cfg.si2ter_present := true;
3983 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3984 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003986}
3987
3988testcase TC_si_sched_2quater() runs on test_CT {
3989 f_init();
3990 si_cfg.si2quater_present := true;
3991 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3992 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003994}
3995
3996testcase TC_si_sched_13() runs on test_CT {
3997 f_init();
3998 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003999 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004000 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004002}
4003
4004testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4005 f_init();
4006 si_cfg.si2bis_present := true;
4007 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4008 si_cfg.si2ter_present := true;
4009 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4010 si_cfg.si2quater_present := true;
4011 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4012 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004013 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004014 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004016}
4017
4018
Harald Welte68e495b2018-02-25 00:05:57 +01004019testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004020 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004021 /* FIXME: enable / disable individual BCCH info */
4022 //ts_RSL_BCCH_INFO(si_type, info);
4023 /* expect no ERROR REPORT after either of them *
4024 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004026}
4027
Harald Welte93640c62018-02-25 16:59:33 +01004028/***********************************************************************
4029 * Low-Level Protocol Errors / ERROR REPORT
4030 ***********************************************************************/
4031
Harald Welte01d982c2018-02-25 01:31:40 +01004032private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4033 timer T := 5.0;
4034 T.start;
4035 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004036 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004037 setverdict(pass);
4038 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004039 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004041 }
4042 [] RSL_CCHAN.receive {
4043 repeat;
4044 }
4045 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004047 }
4048 }
4049}
4050
4051/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4052testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004053 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004054 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4055 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004056 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004057
4058 f_exp_err_rep(RSL_ERR_PROTO);
4059}
4060
4061/* Provoke a mandatory IE error and match on ERROR REPORT */
4062testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004063 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004064
4065 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4066 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004067 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004068
4069 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4070}
4071
4072/* Provoke an IE content error and match on ERROR REPORT */
4073testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004074 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004075 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4076 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004077 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004078
4079 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4080}
4081
Harald Welteee25aae2019-05-19 14:32:37 +02004082/* attempt to activate channel with wrong RSL Message Discriminator IE */
4083function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4084 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4085 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4086 RSL.send(rsl);
4087 f_rslem_unregister(0, g_chan_nr);
4088}
4089testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4090 var ConnHdlr vc_conn;
4091 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4092
Harald Welte10474062019-05-30 16:48:17 +02004093 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004094
4095 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4096 vc_conn.done;
4097 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4098
4099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4100}
4101
4102/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004103private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004104 var template (value) RSL_Message rsl_tx;
4105 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4106 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4107 RSL.send(rsl_tx);
4108 f_rslem_unregister(0, g_chan_nr);
4109}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004110private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004111 var template (value) RSL_Message rsl_tx;
4112 /* we first have to activate the dedicated channel */
4113 f_rsl_chan_act(g_pars.chan_mode);
4114 /* ... to then send an invalid RLL message */
4115 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4116 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4117 RSL.send(rsl_tx);
4118 f_rslem_unregister(0, g_chan_nr);
4119}
4120testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4121 var ConnHdlr vc_conn;
4122 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4123 var template (value) RSL_Message rsl_tx;
4124
Harald Welte10474062019-05-30 16:48:17 +02004125 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004126
4127 /* Common Channel with wrong message type */
4128 RSL_CCHAN.clear;
4129 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4130 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004131 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004132 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4133
4134 /* TRX Management */
4135 RSL_CCHAN.clear;
4136 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4137 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004138 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004139 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4140
4141 /* Dedicated Channel */
4142 RSL_CCHAN.clear;
4143 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4144 vc_conn.done;
4145 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4146
4147 /* RLL */
4148 RSL_CCHAN.clear;
4149 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4150 vc_conn.done;
4151 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4152}
4153
4154/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004155private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004156 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4157 f_rslem_unregister(0, g_chan_nr);
4158}
4159testcase TC_err_rep_wrong_sequence() runs on test_CT {
4160 var ConnHdlr vc_conn;
4161 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4162
Harald Welte10474062019-05-30 16:48:17 +02004163 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004164
4165 RSL_CCHAN.clear;
4166 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4167 vc_conn.done;
4168 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4169}
4170
Harald Welte93640c62018-02-25 16:59:33 +01004171/***********************************************************************
4172 * IPA CRCX/MDCX/DLCS media stream handling
4173 ***********************************************************************/
4174
Harald Weltea871a382018-02-25 02:03:14 +01004175/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004176private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004177 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4178 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004179}
4180testcase TC_ipa_dlcx_not_active() runs on test_CT {
4181 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004182 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004183 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4184 vc_conn.done;
4185}
Harald Welte68e495b2018-02-25 00:05:57 +01004186
Harald Weltea3f1df92018-02-25 12:49:55 +01004187/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004188private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004189 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4190 "IPA CRCX ACK");
4191 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4192 "IPA CRCX NACK");
4193}
4194testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4195 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004196 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004197 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4198 vc_conn.done;
4199}
4200
4201/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004202private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004203 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4204 "IPA CRCX ACK");
4205 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4206 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4207 var uint7_t rtp_pt2 := f_rnd_int(127);
4208 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4209 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4210 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4211 "IPA MDCX ACK");
4212 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4213 "IPA DLCX ACK");
4214}
4215testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4216 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004217 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004218 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4219 vc_conn.done;
4220}
4221
Harald Welte3ae11da2018-02-25 13:36:06 +01004222/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004223private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004224 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4225 "IPA CRCX ACK");
4226 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4227 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4228 var uint7_t rtp_pt2 := f_rnd_int(127);
4229 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4230 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4231 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4232 "IPA MDCX ACK");
4233 /* Second MDCX */
4234 remote_ip := f_rnd_int(c_UINT32_MAX);
4235 remote_port := f_rnd_int(c_UINT16_MAX);
4236 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4237 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4238 "IPA MDCX ACK");
4239 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4240 "IPA DLCX ACK");
4241}
4242testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4243 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004244 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004245 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4246 vc_conn.done;
4247}
4248
Harald Welte9912eb52018-02-25 13:30:15 +01004249/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004250private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004251 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4252 "IPA CRCX NACK");
4253}
4254testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4255 var ConnHdlrPars pars;
4256 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004257 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004258
4259 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4260 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4261 vc_conn.done;
4262
4263 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4264 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4265 vc_conn.done;
4266}
4267
Harald Weltea3f1df92018-02-25 12:49:55 +01004268
Harald Welte883340c2018-02-28 18:59:29 +01004269/***********************************************************************
4270 * PCU Socket related tests
4271 ***********************************************************************/
4272
Harald Welte07bd2d22019-05-25 11:03:30 +02004273/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004274friend 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 +01004275runs on test_CT {
4276 timer T := 3.0;
4277
4278 /* we don't expect any RTS.req before PDCH are active */
4279 T.start;
4280 alt {
4281 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004283 }
4284 [] PCU.receive { repeat; }
4285 [] T.timeout { }
4286 }
4287
4288 /* Send PDCH activate request for known PDCH timeslot */
4289 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4290
4291 /* we now expect RTS.req for this timeslot (only) */
4292 T.start;
4293 alt {
4294 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4295 setverdict(pass);
4296 }
4297 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4298 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004300 }
4301 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004303 }
4304 [] PCU.receive { repeat; }
4305 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004307 }
4308 [not exp_success] T.timeout {
4309 setverdict(pass);
4310 }
4311 }
4312}
4313
Harald Welte07bd2d22019-05-25 11:03:30 +02004314/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004315friend 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 +01004316runs on test_CT {
4317 timer T := 3.0;
4318
4319 /* Send PDCH activate request for known PDCH timeslot */
4320 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4321
4322 PCU.clear;
4323 /* we now expect no RTS.req for this timeslot */
4324 T.start;
4325 alt {
4326 [] 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 +02004327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004328 }
4329 [] PCU.receive { repeat; }
4330 [] T.timeout {
4331 setverdict(pass);
4332 }
4333 }
4334}
4335
Harald Weltead033dc2019-05-25 17:28:16 +02004336friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004337 f_init();
4338 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4339}
4340
Harald Welte883340c2018-02-28 18:59:29 +01004341/* PDCH activation via PCU socket; check for presence of RTS.req */
4342testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004343 f_init_pcu_test();
4344
Harald Welte883340c2018-02-28 18:59:29 +01004345 f_TC_pcu_act_req(0, 0, 7, true);
4346}
4347
4348/* PDCH activation via PCU socket on non-PDCU timeslot */
4349testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004350 f_init_pcu_test();
4351
Harald Welte883340c2018-02-28 18:59:29 +01004352 f_TC_pcu_act_req(0, 0, 1, false);
4353}
4354
4355/* PDCH activation via PCU socket on wrong BTS */
4356testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004357 f_init_pcu_test();
4358
Harald Welte883340c2018-02-28 18:59:29 +01004359 f_TC_pcu_act_req(23, 0, 7, false);
4360}
4361
4362/* PDCH activation via PCU socket on wrong TRX */
4363testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004364 f_init_pcu_test();
4365
Harald Welte883340c2018-02-28 18:59:29 +01004366 f_TC_pcu_act_req(0, 23, 7, false);
4367}
4368
4369/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4370testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004371 f_init_pcu_test();
4372
Harald Welte883340c2018-02-28 18:59:29 +01004373 /* Activate PDCH */
4374 f_TC_pcu_act_req(0, 0, 7, true);
4375 f_sleep(1.0);
4376 /* and De-Activate again */
4377 f_TC_pcu_deact_req(0, 0, 7);
4378}
4379
4380/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4381testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004382 f_init_pcu_test();
4383
Harald Welte883340c2018-02-28 18:59:29 +01004384 f_TC_pcu_deact_req(0, 0, 1);
4385}
4386
4387/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4388testcase TC_pcu_ver_si13() runs on test_CT {
4389 const octetstring si13 := '00010203040506070909'O;
4390 var PCUIF_send_data sd;
4391 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004392 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004393
4394 /* Set SI13 via RSL */
4395 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004396
Harald Welte883340c2018-02-28 18:59:29 +01004397 T.start;
4398 alt {
4399 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4400 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4401 setverdict(pass);
4402 } else {
4403 repeat;
4404 }
4405 }
4406 [] PCU.receive { repeat; }
4407 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004409 }
4410 }
4411}
4412
4413private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4414
4415/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004416friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004417 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4418runs on test_CT
4419{
4420 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4421 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4422}
4423
4424/* 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 +02004425friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4426 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004427runs on test_CT
4428{
4429 var PCUIF_send_data sd;
4430
4431 timer T := 3.0;
4432 T.start;
4433 alt {
4434 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4435 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4436 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4437 sd.data.u.rts_req.fn, sapi, data);
4438 }
4439 [] PCU.receive { repeat; }
4440 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004442 }
4443 }
4444}
4445
4446/* Send DATA.req on invalid BTS */
4447testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004448 var TfiUsfArr tua := f_TfiUsfArrInit();
4449 var octetstring data := '0000'O & f_rnd_octstring(21);
4450
4451 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004452
Harald Welte883340c2018-02-28 18:59:29 +01004453 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004454 f_TfiUsfArrSet(tua, 7, 0);
4455 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4456 f_sleep(1.0);
4457
4458 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004459}
4460
4461/* Send DATA.req on invalid TRX */
4462testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004463 var TfiUsfArr tua := f_TfiUsfArrInit();
4464 var octetstring data := '0000'O & f_rnd_octstring(21);
4465
4466 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004467
Harald Welte883340c2018-02-28 18:59:29 +01004468 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004469 f_TfiUsfArrSet(tua, 7, 0);
4470 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4471 f_sleep(1.0);
4472
4473 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004474}
4475
4476/* Send DATA.req on invalid timeslot */
4477testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004478 var TfiUsfArr tua := f_TfiUsfArrInit();
4479 var octetstring data := '0000'O & f_rnd_octstring(21);
4480
4481 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004482
Harald Welte883340c2018-02-28 18:59:29 +01004483 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004484 f_TfiUsfArrSet(tua, 7, 0);
4485 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4486 f_sleep(1.0);
4487
4488 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004489}
4490
4491/* Send DATA.req on timeslot that hasn't been activated */
4492testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004493 var TfiUsfArr tua := f_TfiUsfArrInit();
4494 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004495
Harald Welte7162a612019-05-26 12:56:09 +02004496 f_virtphy_common();
4497
4498 f_TfiUsfArrSet(tua, 7, 0);
4499 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4500 f_sleep(1.0);
4501
4502 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004503}
4504
Harald Weltead033dc2019-05-25 17:28:16 +02004505private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004506 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4507 boolean wait_rts := true)
4508runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004509 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004510 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004511
4512 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004513 if (wait_rts) {
4514 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4515 } else {
4516 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4517 }
Harald Weltead033dc2019-05-25 17:28:16 +02004518
4519 T.start;
4520 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004521 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004522 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4523 setverdict(pass);
4524 }
Harald Welte7162a612019-05-26 12:56:09 +02004525 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4526 setverdict(fail, "Received unexpected ", rx_dl);
4527 }
Harald Weltead033dc2019-05-25 17:28:16 +02004528 [] L1CTL.receive {
4529 repeat;
4530 }
Harald Welte7162a612019-05-26 12:56:09 +02004531 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004532 setverdict(fail, "Timeout waiting for ", data);
4533 }
Harald Welte7162a612019-05-26 12:56:09 +02004534 [not expect_data] T.timeout {
4535 setverdict(pass);
4536 }
Harald Weltead033dc2019-05-25 17:28:16 +02004537 }
4538}
4539
4540private function f_disable_dynamic_ts() runs on test_CT
4541{
4542 f_init_vty_bsc();
4543 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4544 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4545 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4546 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004547 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004548}
4549
4550private function f_virtphy_common() runs on test_CT {
4551 f_disable_dynamic_ts();
4552 f_init_l1ctl();
4553 f_l1_tune(L1CTL);
4554}
4555
4556testcase TC_pcu_data_req_pdtch() runs on test_CT {
4557 var TfiUsfArr tua := f_TfiUsfArrInit();
4558 var octetstring data := '0000'O & f_rnd_octstring(21);
4559
4560 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004561
Harald Welte883340c2018-02-28 18:59:29 +01004562 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004563 f_TfiUsfArrSet(tua, 7, 0);
4564 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4565 f_sleep(1.0);
4566
4567 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004568}
4569
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004570/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004571testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004572 var TfiUsfArr tua := f_TfiUsfArrInit();
4573 var octetstring data := '0000'O & f_rnd_octstring(21);
4574
4575 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004576
Harald Welte883340c2018-02-28 18:59:29 +01004577 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004578 f_TfiUsfArrSet(tua, 7, 0);
4579 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4580 f_sleep(1.0);
4581
4582 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004583}
4584
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004585private function f_TC_pcu_ptcch_ul(uint16_t ra)
4586runs on test_CT {
4587 var template PCUIF_Message pcu_rach_ind;
4588 var PCUIF_send_data sd;
4589 var GsmFrameNumber fn;
4590 timer T;
4591
4592 /* Send an Access Burst on PTCCH/U over the Um-interface */
4593 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4594 chan_nr := ts_RslChanNr_PDCH(7),
4595 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4596
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004597 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4598 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004599
4600 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4601 T.start(52.0 * 4.615 / 1000.0);
4602 alt {
4603 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4604 log("Rx an Access Burst on the PCU interface: ", sd.data);
4605 setverdict(pass);
4606 T.stop;
4607 }
4608 [] PCU.receive { repeat; }
4609 [] T.timeout {
4610 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4611 /* Keep going, that's not the end of the world */
4612 }
4613 }
4614}
4615
4616testcase TC_pcu_ptcch() runs on test_CT {
4617 var L1ctlDlMessage dl;
4618 var octetstring data;
4619 timer T;
4620
4621 f_init_pcu_test();
4622 f_init_l1ctl();
4623 f_l1_tune(L1CTL);
4624
4625 /* Activate PDCH channel on TS7 */
4626 f_TC_pcu_act_req(0, 0, 7, true);
4627
4628 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004629 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004630
4631 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4632 for (var integer i := 0; i < 16; i := i + 1) {
4633 log("Sending an Access Burst towards the L1CTL interface");
4634 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4635 }
4636
4637 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4638 data := f_rnd_octstring(23);
4639
4640 /* Verify PTCCH/D: send a random data block, make sure it's received */
4641 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4642 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4643
4644 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4645 * let's give it more time in case if we miss the beginning. */
4646 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4647 alt {
4648 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4649 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4650 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4651 frame := data)) -> value dl {
4652 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4653 setverdict(pass);
4654 T.stop;
4655 }
4656 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4657 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4658 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4659 l2_data := data)) -> value dl {
4660 log("Rx PTCCH/D data block on L1CTL: ", dl);
4661 setverdict(pass);
4662 T.stop;
4663 }
4664 [] L1CTL.receive { repeat; }
4665 [] T.timeout {
4666 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4667 }
4668 }
4669}
4670
Harald Welte883340c2018-02-28 18:59:29 +01004671/* Send AGCH from PCU; check it appears on Um side */
4672testcase TC_pcu_data_req_agch() runs on test_CT {
4673 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004674 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004675 f_init_l1ctl();
4676 f_l1_tune(L1CTL);
4677
4678 f_TC_pcu_act_req(0, 0, 7, true);
4679 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4680
4681 T.start;
4682 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004683 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004684 setverdict(pass);
4685 }
4686 [] L1CTL.receive { repeat; }
4687 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004689 }
4690 }
4691}
4692
Harald Welte928622b2019-05-26 13:22:59 +02004693/* Send AGCH from PCU; check it appears on Um side */
4694testcase TC_pcu_data_req_pch() runs on test_CT {
4695 timer T := 3.0;
4696 f_init_pcu_test();
4697 f_init_l1ctl();
4698 f_l1_tune(L1CTL);
4699
4700 f_TC_pcu_act_req(0, 0, 7, true);
4701 /* three characters prefix: last 3 digits of IMSI as ASCII */
4702 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4703
4704 T.start;
4705 alt {
4706 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4707 setverdict(pass);
4708 }
4709 [] L1CTL.receive { repeat; }
4710 [] T.timeout {
4711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4712 }
4713 }
4714}
4715
Harald Welte883340c2018-02-28 18:59:29 +01004716/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4717testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4718 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004719 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004720 f_init_l1ctl();
4721 f_l1_tune(L1CTL);
4722
4723 /* append 3 last imsi digits so BTS can compute pagng group */
4724 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4725
4726 timer T := 0.5;
4727 T.start;
4728 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004729 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004730 /* TODO: verify paging group */
4731 setverdict(pass);
4732 }
4733 [] L1CTL.receive { repeat; }
4734 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004736 }
4737 }
4738}
4739
4740/* Send RACH from Um side, expect it to show up on PCU socket */
4741testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004742 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004743 f_init_l1ctl();
4744 f_l1_tune(L1CTL);
4745
4746 var GsmFrameNumber fn_last := 0;
4747 for (var integer i := 0; i < 1000; i := i+1) {
4748 var OCT1 ra := f_rnd_ra_ps();
4749 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4750 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004752 }
4753 fn_last := fn;
4754
4755 timer T := 2.0;
4756 T.start;
4757 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004758 [] 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 +01004759 T.stop;
4760 }
4761 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004763 }
4764 [] PCU.receive { repeat; }
4765 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004767 }
4768 }
4769 }
4770 setverdict(pass);
4771}
4772
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004773/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4774 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4775testcase TC_pcu_ext_rach_content() runs on test_CT {
4776 var template PCUIF_Message pcu_rach_ind;
4777 var GsmFrameNumber fn_last := 0;
4778 var L1ctlRachSynchSeq synch_seq;
4779 var PCUIF_BurstType pcu_bt;
4780 var GsmFrameNumber fn;
4781 var BIT11 ra11;
4782
4783 f_init_pcu_test();
4784 f_init_l1ctl();
4785 f_l1_tune(L1CTL);
4786
4787 for (var integer i := 0; i < 1000; i := i+1) {
4788 /* We need to test both TS1 & TS2 */
4789 if (i rem 2 == 0) {
4790 synch_seq := RACH_SYNCH_SEQ_TS1;
4791 pcu_bt := BURST_TYPE_1;
4792 } else {
4793 synch_seq := RACH_SYNCH_SEQ_TS2;
4794 pcu_bt := BURST_TYPE_2;
4795 }
4796
4797 ra11 := f_rnd_ra11_ps();
4798 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4799 if (fn == fn_last) {
4800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4801 "Two RACH in same FN?!?");
4802 }
4803 fn_last := fn;
4804
4805 /* Compose the expected message */
4806 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004807 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004808 ra := bit2int(ra11),
4809 is_11bit := 1,
4810 burst_type := pcu_bt,
4811 fn := fn);
4812
4813 timer T := 2.0;
4814 T.start;
4815 alt {
4816 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4817 T.stop;
4818 }
4819 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4821 }
4822 [] PCU.receive { repeat; }
4823 [] T.timeout {
4824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4825 }
4826 }
4827 }
4828 setverdict(pass);
4829}
4830
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004831private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4832runs on test_CT {
4833 var template PCUIF_send_data sdt;
4834 var PCUIF_send_data sd;
4835 var int16_t lqual_cb;
4836 timer T := 1.0;
4837
4838 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4839 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4840
4841 /* Send a random PDTCH frame over Um */
4842 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4843 '0000'O & f_rnd_octstring(21)));
4844
4845 T.start;
4846 alt {
4847 /* If expected link quality is above the threshold */
4848 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4849 lqual_cb := sd.data.u.data_ind.lqual_cb;
4850 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4851
4852 /* Make sure the actual link quality matches the expected value */
4853 if (not match(lqual_cb, lqual_cb_exp)) {
4854 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4855 "expected value ", lqual_cb_exp));
4856 } else {
4857 setverdict(pass);
4858 }
4859 }
4860 /* If expected link quality is below the threshold */
4861 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4862 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4863 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4864 }
4865 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4866 [] PCU.receive { repeat; }
4867 [lqual_cb_exp < thresh] T.timeout {
4868 log("Rx nothing, as expected");
4869 setverdict(pass);
4870 }
4871 [lqual_cb_exp >= thresh] T.timeout {
4872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4873 "Timeout waiting for PCUIF_DATA.ind");
4874 }
4875 }
4876}
4877
4878/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4879testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4880 f_init_pcu_test();
4881 PCU.clear;
4882
4883 f_init_l1ctl();
4884 f_l1_tune(L1CTL);
4885
4886 /* Activate a PDCH channel on TS7 */
4887 f_TC_pcu_act_req(0, 0, 7, true);
4888
4889 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004890 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004891
4892 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4893 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4894 var TrxcMessage ret;
4895
4896 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4897 valueof(ts_TRXC_FAKE_CI(i)));
4898
4899 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4900 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4901 }
4902}
4903
Harald Welte883340c2018-02-28 18:59:29 +01004904/* Send PAGING via RSL, expect it to shw up on PCU socket */
4905testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004906 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004907
4908 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004909 var MobileIdentityLV mi_lv;
4910 var octetstring mi_lv_enc;
4911 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004912 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004913
Harald Welte883340c2018-02-28 18:59:29 +01004914 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004915 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004916 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004917 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004918 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004919
4920 /* Fancy encoding for PCUIF */
4921 mi_lv := valueof(ts_MI_LV(mi));
4922 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4923 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004924
4925 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004926 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004927 T.start;
4928 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004929 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004930 }
4931 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004933 }
4934 [] PCU.receive { repeat; }
4935 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004937 }
4938 }
4939 }
4940 setverdict(pass);
4941}
4942
Harald Welted66c9b82019-05-25 09:03:15 +02004943/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4944testcase TC_pcu_time_ind() runs on test_CT {
4945 var PCUIF_send_data pcu_sd;
4946 var integer num_time_ind := 0;
4947 var integer first_fn, last_fn;
4948 var float test_duration := 5.0;
4949 timer T;
4950
4951 f_init_pcu_test();
4952 f_TC_pcu_act_req(0, 0, 7, true);
4953
4954 PCU.clear;
4955 T.start(test_duration);
4956 alt {
4957 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4958 num_time_ind := num_time_ind + 1;
4959 if (not isbound(first_fn)) {
4960 first_fn := pcu_sd.data.u.time_ind.fn;
4961 }
4962 last_fn := pcu_sd.data.u.time_ind.fn;
4963 repeat;
4964 }
4965 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4966 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4967 repeat;
4968 }
4969 [] PCU.receive {
4970 repeat;
4971 }
4972 [] T.timeout {}
4973 }
4974 var integer fn_expired := last_fn - first_fn;
4975 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4976
4977 /* verify the number of frames expired matches our expectation */
4978 const float c_GSM_FN_DURATION_MS := 4.61538;
4979 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004980 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004981 if (not match(fn_expired, t_fn_expected)) {
4982 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4983 }
4984
4985 /* There are three TIME.ind in every fn MOD 13 */
4986 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4987 /* Add some tolerance */
4988 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4989 if (not match(num_time_ind, t_time_ind_exp)) {
4990 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4991 }
4992
4993 setverdict(pass);
4994}
4995
Harald Welte4832c862019-05-25 14:57:18 +02004996/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4997testcase TC_pcu_rts_req() runs on test_CT {
4998 var PCUIF_send_data pcu_sd;
4999 var integer first_fn, last_fn;
5000 var integer num_rts_pdtch := 0;
5001 var integer num_rts_ptcch := 0;
5002 var float test_duration := 5.0;
5003 timer T;
5004
5005 f_init_pcu_test();
5006 f_TC_pcu_act_req(0, 0, 7, true);
5007
5008 PCU.clear;
5009 T.start(test_duration);
5010 alt {
5011 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5012 -> value pcu_sd {
5013 num_rts_pdtch := num_rts_pdtch + 1;
5014 if (not isbound(first_fn)) {
5015 first_fn := pcu_sd.data.u.rts_req.fn;
5016 }
5017 last_fn := pcu_sd.data.u.rts_req.fn;
5018 repeat;
5019 }
5020 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5021 -> value pcu_sd {
5022 num_rts_ptcch := num_rts_ptcch + 1;
5023 if (not isbound(first_fn)) {
5024 first_fn := pcu_sd.data.u.rts_req.fn;
5025 }
5026 last_fn := pcu_sd.data.u.rts_req.fn;
5027 repeat;
5028 }
5029 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5030 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5031 repeat;
5032 }
5033 [] PCU.receive {
5034 repeat;
5035 }
5036 [] T.timeout {}
5037 }
5038 var integer fn_expired := last_fn - first_fn;
5039 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5040 ", num_rts_ptcch=", num_rts_ptcch);
5041
5042 /* verify the number of frames expired matches our expectation */
5043 const float c_GSM_FN_DURATION_MS := 4.61538;
5044 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005045 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005046 if (not match(fn_expired, t_fn_expected)) {
5047 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5048 }
5049
5050 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5051 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5052 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5053 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5054 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5055 t_ptcch_exp);
5056 }
5057
5058 /* We have 12 PDTCH blocks every 52-multiframe */
5059 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5060 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5061 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5062 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5063 t_pdtch_exp);
5064 }
5065
5066 setverdict(pass);
5067}
5068
Harald Welte07bd2d22019-05-25 11:03:30 +02005069/* test for generating Abis side OML ALERT from the PCU */
5070testcase TC_pcu_oml_alert() runs on test_CT {
5071 var PCUIF_send_data pcu_sd;
5072 var integer num_time_ind := 0;
5073 var integer first_fn, last_fn;
5074 var float test_duration := 5.0;
5075 timer T;
5076
5077 f_init_pcu_test();
5078 f_TC_pcu_act_req(0, 0, 7, true);
5079
5080 /* re-connect CTRL port from BTS to BSC */
5081 f_ipa_ctrl_stop();
5082 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5083
5084 /* Send that OML Alert */
5085 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5086
5087 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5088 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5089 setverdict(pass);
5090}
5091
Harald Welteeaa9a862019-05-26 23:01:08 +02005092template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
5093 template (value) RoutingAreaIdentificationV rai,
5094 template (value) OCT1 cause) := {
5095 discriminator := '0000'B, /* overwritten */
5096 tiOrSkip := {
5097 skipIndicator := '0000'B
5098 },
5099 msgs := {
5100 rrm := {
5101 gPRS_suspensionRequest := {
5102 messageType := '00110100'B,
5103 tLLI := tlli,
5104 routingAreaIdentification := rai,
5105 suspensionCause := cause,
5106 service_Support := omit
5107 }
5108 }
5109 }
5110}
5111
5112/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5113private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5114 var PCUIF_Message first_info;
5115 var integer pcu_conn_id := -1;
5116 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5117 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5118 var OCT4 tlli := '01020304'O;
5119 var OCT1 cause := '23'O;
5120 timer T := 5.0;
5121
5122 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5123
5124 f_l1_tune(L1CTL);
5125 RSL.clear;
5126
5127 f_est_dchan();
5128 L1CTL.clear;
5129
5130 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5131
5132 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5133 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5134 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5135
5136 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5137 T.start;
5138 alt {
5139 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5140 setverdict(pass);
5141 }
5142 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5143 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5144 }
5145 [] PCU.receive {
5146 repeat;
5147 }
5148 [] T.timeout {
5149 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5150 }
5151 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005152
5153 /* release the channel */
5154 f_rsl_chan_deact();
5155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5156 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005157}
5158testcase TC_pcu_rr_suspend() runs on test_CT {
5159 var ConnHdlrPars pars;
5160 var ConnHdlr vc_conn;
5161
5162 f_init();
5163
5164 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5165 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5166 vc_conn.done;
5167}
Harald Welte07bd2d22019-05-25 11:03:30 +02005168
Harald Weltea2e0e942019-05-27 18:12:53 +02005169/* Ensure that PCUIF socket can accept only a single connection */
5170testcase TC_pcu_socket_connect_multi() runs on test_CT {
5171 timer T := 5.0;
5172
5173 /* this (among other things) establishes the first connection to the PCUIF socket */
5174 f_init();
5175
5176 /* try to establish a second connection, expect it to fail */
5177 PCU.send(UD_connect:{mp_pcu_socket, -1});
5178 T.start;
5179 alt {
5180 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5181 setverdict(pass);
5182 }
5183 [] PCU.receive(UD_connect_result:?) {
5184 setverdict(fail, "Unexpected unix domain connect result");
5185 }
5186 [] T.timeout {
5187 setverdict(pass);
5188 }
5189 }
5190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5191}
5192
Harald Weltec8effb72019-05-27 18:23:04 +02005193/* Ensure that PCUIF socket can disconnect + reconnect */
5194testcase TC_pcu_socket_reconnect() runs on test_CT {
5195 /* this (among other things) establishes the first connection to the PCUIF socket */
5196 f_init();
5197
5198 f_sleep(1.0);
5199
5200 f_pcuif_close(PCU, g_pcu_conn_id);
5201 g_pcu_conn_id := -1;
5202
5203 f_sleep(1.0);
5204
5205 /* re-connect */
5206 PCU.clear;
5207 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5208 setverdict(pass);
5209
5210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5211}
5212
Harald Weltebe030482019-05-27 22:29:35 +02005213/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005214private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5215runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005216 var L1ctlDlMessage l1_dl;
5217 var SystemInformation si;
5218 timer T := 5.0;
5219 T.start;
5220 alt {
5221 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
5222 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
5223 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
5224 log("Ignoring non-RR SI ", l1_dl);
5225 repeat;
5226 }
5227 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005228 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005229 repeat;
5230 }
5231 }
5232 [] pt.receive {
5233 repeat;
5234 }
5235 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5237 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005238 }
5239 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005240 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005241}
5242
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005243/* Check if GPRS Indicator is present in RR System Information of a given type */
5244private function f_si_has_gprs_indicator(RrMessageType si_type)
5245runs on test_CT return boolean {
5246 var SystemInformation si := f_get_si(L1CTL, si_type);
5247
5248 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
5249 var RestOctets ro := si.payload.si3.rest_octets;
5250 var SI3RestOctets rest := dec_SI3RestOctets(ro);
5251 return rest.gprs_ind.presence == '1'B;
5252 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
5253 var RestOctets ro := si.payload.si4.rest_octets;
5254 var SI4RestOctets rest := dec_SI4RestOctets(ro);
5255 return rest.gprs_ind.presence == '1'B;
5256 }
5257
5258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5259 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005260}
5261
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005262/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5263private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5264runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005265 /* don't call f_init() as this would connect PCU socket */
5266 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005267
5268 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005269 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005270 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005271
5272 f_init_l1ctl();
5273 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005274 f_sleep(2.0);
5275 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005276
5277 if (f_si_has_gprs_indicator(si_type)) {
5278 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005279 } else {
5280 setverdict(pass);
5281 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005282
Harald Weltebe030482019-05-27 22:29:35 +02005283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5284}
5285
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005286testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5287 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5288}
Harald Weltebe030482019-05-27 22:29:35 +02005289
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005290testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5291 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5292}
5293
5294/* Ensure that GPRS capability is advertised after PCU socket connect */
5295private function f_TC_pcu_socket_connect(RrMessageType si_type)
5296runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005297 /* this (among other things) establishes the first connection to the PCUIF socket */
5298 f_init();
5299 f_init_l1ctl();
5300 f_l1_tune(L1CTL);
5301
5302 f_sleep(2.0);
5303 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005304
5305 if (not f_si_has_gprs_indicator(si_type)) {
5306 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005307 } else {
5308 setverdict(pass);
5309 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005310
Harald Weltebe030482019-05-27 22:29:35 +02005311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5312}
5313
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005314testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5315 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5316}
Harald Weltebe030482019-05-27 22:29:35 +02005317
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005318testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5319 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5320}
5321
5322/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5323private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5324runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005325 /* this (among other things) establishes the first connection to the PCUIF socket */
5326 f_init();
5327 f_init_l1ctl();
5328 f_l1_tune(L1CTL);
5329
5330 f_pcuif_close(PCU, g_pcu_conn_id);
5331 g_pcu_conn_id := -1;
5332
5333 f_sleep(1.0);
5334
5335 /* re-connect */
5336 PCU.clear;
5337 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5338
5339 f_sleep(2.0);
5340 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005341
5342 if (f_si_has_gprs_indicator(si_type)) {
5343 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005344 } else {
5345 setverdict(pass);
5346 }
5347
5348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5349}
5350
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005351testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5352 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5353}
5354
5355testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5356 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5357}
5358
Oliver Smithf5239c72019-08-28 10:01:25 +02005359/* 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) */
5360testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5361 var SystemInformation si3 := valueof(ts_SI3_default);
5362
5363 f_init();
5364
5365 /* Verify cell_id */
5366 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5367 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5368 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005369 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5370 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5371 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005372 }
5373
5374 /* Verify LAC */
5375 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5376 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5377 if (lac_si3 != lac_pcu) {
5378 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5379 }
5380
5381 setverdict(pass);
5382}
Harald Welted66c9b82019-05-25 09:03:15 +02005383
Harald Welte3d04ae62018-04-04 20:29:05 +02005384/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005385 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005386 ***********************************************************************/
5387
5388private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5389runs on ConnHdlr {
5390 var PCUIF_send_data sd;
5391 /* Expect BTS to immediately acknowledge activation as PDCH */
5392 PCU.clear;
5393 f_rsl_chan_act(g_pars.chan_mode);
5394 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005395 timer T_wait := 2.0;
5396 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005397 alt {
5398 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5399 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 +02005400 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5401 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5402 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005403 }
5404 }
5405 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005406 [] T_wait.timeout {
5407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5408 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5409 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005410 }
5411 /* try to activate this PDCH from the PCU point of view */
5412 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5413 /* FIXME: is there a response? */
5414}
5415
5416private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5417runs on ConnHdlr {
5418 var PCUIF_send_data sd;
5419 /* Send RSL CHAN REL (deactivate) */
5420 PCU.clear;
5421 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5422 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005423 timer T_wait := 2.0;
5424 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005425 alt {
5426 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5427 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 +02005428 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5429 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5430 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005431 }
5432 }
5433 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005434 [] T_wait.timeout {
5435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5436 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5437 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005438 }
5439 /* Emulate PCU asking BTS to deactivate PDCH */
5440 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5441 alt {
5442 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5443 setverdict(pass);
5444 }
5445 [] RSL.receive { repeat; }
5446 }
5447}
5448
5449/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005450private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005451 var PCUIF_Message first_info;
5452 var integer ts_nr := g_chan_nr.tn;
5453 var integer trx_nr := 0;
5454 var integer bts_nr := 0;
5455 var integer pcu_conn_id := -1;
5456
5457 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5458
5459 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5460 f_sleep(3.0);
5461 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5462 setverdict(pass);
5463}
5464testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5465 var ConnHdlrPars pars;
5466 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005467 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005468
5469 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5470 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5471 vc_conn.done;
5472}
5473
5474/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005475private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005476 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005477 var integer pcu_conn_id := -1;
5478
5479 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5480
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005481 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5482 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5483 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005484 setverdict(pass);
5485}
5486testcase TC_dyn_osmo_pdch_unsol_deact() 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_unsol_deact), pars, true);
5493 vc_conn.done;
5494}
5495
5496/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005497private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005498 var PCUIF_Message first_info;
5499 var integer ts_nr := g_chan_nr.tn;
5500 var integer trx_nr := 0;
5501 var integer bts_nr := 0;
5502 var integer pcu_conn_id := -1;
5503
5504 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5505
5506 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005507 /* Send a second Chan Activ and expect it to be NACKed */
5508 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5509 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005510 setverdict(pass);
5511}
5512testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5513 var ConnHdlrPars pars;
5514 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005515 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005516
5517 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5518 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5519 vc_conn.done;
5520}
5521
5522/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005523private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005524 var PCUIF_Message first_info;
5525 var integer ts_nr := g_chan_nr.tn;
5526 var integer trx_nr := 0;
5527 var integer bts_nr := 0;
5528 var integer pcu_conn_id := -1;
5529 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5530
5531 /* register for the TCH/F channel number */
5532 f_rslem_register(0, chan_nr);
5533
5534 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5535
5536 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5537 "RSL CHAN ACT");
5538 setverdict(pass);
5539}
5540testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5541 var ConnHdlrPars pars;
5542 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005543 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005544
5545 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5546 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5547 vc_conn.done;
5548}
5549
5550/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005551private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005552 var PCUIF_Message first_info;
5553 var integer ts_nr := g_chan_nr.tn;
5554 var integer trx_nr := 0;
5555 var integer bts_nr := 0;
5556 var integer pcu_conn_id := -1;
5557 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5558 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5559
5560 /* register for the TCH/H channel numbers */
5561 f_rslem_register(0, chan_nr[0]);
5562 f_rslem_register(0, chan_nr[1]);
5563
5564 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5565
5566 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5567 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5568 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5569 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5570 setverdict(pass);
5571}
5572testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5573 var ConnHdlrPars pars;
5574 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005575 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005576
5577 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5578 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5579 vc_conn.done;
5580}
5581
Harald Welte9bbbfb52018-04-05 09:33:19 +02005582/***********************************************************************
5583 * IPA Style Dynamic Timeslot Support
5584 ***********************************************************************/
5585
5586private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5587runs on ConnHdlr {
5588 var PCUIF_send_data sd;
5589 /* Expect BTS to immediately acknowledge activation as PDCH */
5590 PCU.clear;
5591 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5592 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005593 timer T_wait := 2.0;
5594 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005595 alt {
5596 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5597 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 +01005598 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5599 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5600 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005601 }
5602 }
5603 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005604 [] T_wait.timeout {
5605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5606 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5607 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005608 }
5609 /* try to activate this PDCH from the PCU point of view */
5610 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5611 /* FIXME: is there a response? */
5612
5613 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5614}
5615
5616private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5617runs on ConnHdlr {
5618 var PCUIF_send_data sd;
5619 /* Send RSL CHAN REL (deactivate) */
5620 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5621 PCU.clear;
5622 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005623 timer T_wait := 2.0;
5624 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005625 alt {
5626 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5627 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 +01005628 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5629 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5630 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005631 }
5632 }
5633 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005634 [] T_wait.timeout {
5635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5636 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5637 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005638 }
5639 /* Emulate PCU asking BTS to deactivate PDCH */
5640 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5641 alt {
5642 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5643 setverdict(pass);
5644 }
5645 [] RSL.receive { repeat; }
5646 }
5647}
5648
5649/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005650private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005651 var PCUIF_Message first_info;
5652 var integer ts_nr := g_chan_nr.tn;
5653 var integer trx_nr := 0;
5654 var integer bts_nr := 0;
5655 var integer pcu_conn_id := -1;
5656
5657 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5658
5659 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5660 f_sleep(3.0);
5661 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5662
5663 setverdict(pass);
5664
5665}
5666testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5667 var ConnHdlrPars pars;
5668 var ConnHdlr vc_conn;
5669 f_init();
5670
5671 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5672 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5673 vc_conn.done;
5674}
5675
5676/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005677private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005678 var PCUIF_Message first_info;
5679 var integer ts_nr := g_chan_nr.tn;
5680 var integer trx_nr := 0;
5681 var integer bts_nr := 0;
5682 var integer pcu_conn_id := -1;
5683
5684 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5685
5686 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5687 "RSL CHAN ACT");
5688 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5689 "RF CHAN REL", true);
5690 setverdict(pass);
5691}
5692testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5693 var ConnHdlrPars pars;
5694 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005695 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005696
5697 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5698 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5699 vc_conn.done;
5700}
5701
5702/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005703private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005704 var PCUIF_Message first_info;
5705 var integer ts_nr := g_chan_nr.tn;
5706 var integer trx_nr := 0;
5707 var integer bts_nr := 0;
5708 var integer pcu_conn_id := -1;
5709
5710 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5711
5712 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5713 "RSL CHAN ACT");
5714
5715 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5716 alt {
5717 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5718 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005720 }
5721 [] RSL.receive { repeat; }
5722 }
5723
5724 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5725 "RF CHAN REL", true);
5726 setverdict(pass);
5727}
5728testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5729 var ConnHdlrPars pars;
5730 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005731 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005732
5733 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5734 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5735 vc_conn.done;
5736}
5737
5738/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005739private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005740 var PCUIF_Message first_info;
5741 var integer ts_nr := g_chan_nr.tn;
5742 var integer trx_nr := 0;
5743 var integer bts_nr := 0;
5744 var integer pcu_conn_id := -1;
5745
5746 /* register for the TCH/F channel number */
5747 f_rslem_register(0, g_chan_nr);
5748
5749 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5750
5751 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5752
5753 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5754 "RSL CHAN ACT");
5755
5756 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5757
5758 setverdict(pass);
5759}
5760testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5761 var ConnHdlrPars pars;
5762 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005763 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005764
5765 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5766 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5767 vc_conn.done;
5768}
5769
5770
Harald Welte0472ab42018-03-12 15:02:26 +01005771/***********************************************************************
5772 * LAPDm / RLL related
5773 ***********************************************************************/
5774
5775private function f_tx_lapdm(template (value) LapdmFrame l,
5776 template (value) RslLinkId link_id) runs on ConnHdlr {
5777 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005778 var template (value) SacchL1Header l1h;
5779
5780 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005781 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005782 /* Compose dummy L1 header */
5783 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5784 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 +02005785 } else {
5786 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005787 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 +01005788 }
Harald Welte0472ab42018-03-12 15:02:26 +01005789}
5790
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005791private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005792 uint3_t sapi,
5793 RslLinkId link_id,
5794 octetstring l3,
5795 boolean exp
5796}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005797private type record of RllTestCase RllTestCases;
5798private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5799 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005800 sapi := sapi,
5801 link_id := id,
5802 l3 := l3,
5803 exp := exp
5804}
5805
5806/* execute the same callback function with a set of different parameters (tcs) on a
5807 * variety of logical channels */
5808private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5809 var ConnHdlrPars pars;
5810 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005811 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005812
5813 /* test on each of the channels we have */
5814 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5815 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5816
5817 /* test each of the test cases on the current channel */
5818 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5819 pars.spec.rll := tcs[j];
5820 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5821 vc_conn := f_start_handler(fn, pars);
5822 vc_conn.done;
5823 }
5824 }
5825
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005827}
5828
5829/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5830private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5831 var RllTestCase tc := g_pars.spec.rll;
5832 timer T := 3.0;
5833
5834 f_l1_tune(L1CTL);
5835 RSL.clear;
5836
5837 /* activate the logical channel */
5838 f_est_dchan();
5839 L1CTL.clear;
5840
5841 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5842 T.start;
5843 alt {
5844 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5845 if (tc.exp) {
5846 setverdict(pass);
5847 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005849 }
5850 }
5851 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5852 if (tc.exp) {
5853 setverdict(pass);
5854 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005856 }
5857 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005858 /* We also expect to receive the measurements */
5859 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005860 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005862 }
5863 [not tc.exp] T.timeout {
5864 setverdict(pass);
5865 }
5866 }
5867
5868 f_rsl_chan_deact();
5869 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5870 f_rslem_unregister(0, g_chan_nr);
5871}
5872testcase TC_rll_est_ind() runs on test_CT {
5873 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005874 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005875 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005876 /* normal SAPI0 establishment */
5877 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005878 /* SAPI 3 doesn't support contention resolution */
5879 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5880 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5881 /* normal SAPI3 establishment on main DCCH */
5882 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5883 /* normal SAPI3 establishment on SACCH */
5884 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5885 };
5886 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5887}
5888
5889/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5890private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5891 var RllTestCase tc := g_pars.spec.rll;
5892 var L1ctlDlMessage dl;
5893 timer T := 3.0;
5894
5895 f_l1_tune(L1CTL);
5896 RSL.clear;
5897
5898 /* activate the logical channel */
5899 f_est_dchan();
5900 L1CTL.clear;
5901
5902 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5903 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5904 T.start;
5905 alt {
5906 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5907 var LapdmFrame lapdm;
5908 var octetstring l2 := dl.payload.data_ind.payload;
5909 if (dl.dl_info.link_id.c == SACCH) {
5910 /* remove L1 header */
5911 l2 := substr(l2, 2, lengthof(l2)-2);
5912 }
5913 lapdm.ab := dec_LapdmFrameAB(l2);
5914 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5915 setverdict(pass);
5916 } else {
5917 repeat;
5918 }
5919 }
5920 [] L1CTL.receive { repeat; }
5921 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005923 }
5924 }
5925
5926 f_rsl_chan_deact();
5927 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5928 f_rslem_unregister(0, g_chan_nr);
5929}
5930testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5931 var RllTestCases tcs := {
5932 /* normal SAPI3 establishment on main DCCH */
5933 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5934 };
5935 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5936}
5937testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5938 var RllTestCases tcs := {
5939 /* normal SAPI3 establishment on SACCH */
5940 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5941 }
5942 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5943}
5944
5945/* altstep to receive a LAPDm frame matching the given template */
5946private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5947 var L1ctlDlMessage dl;
5948 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5949 var LapdmFrame lapdm;
5950 var octetstring l2 := dl.payload.data_ind.payload;
5951 if (dl.dl_info.link_id.c == SACCH) {
5952 /* remove L1 header */
5953 l2 := substr(l2, 2, lengthof(l2)-2);
5954 }
5955 if (ischosen(exp.ab)) {
5956 lapdm.ab := dec_LapdmFrameAB(l2);
5957 } else if (ischosen(exp.b4)) {
5958 lapdm.b4 := dec_LapdmFrameB4(l2);
5959 } else if (ischosen(exp.bbis)) {
5960 lapdm.bbis := dec_LapdmFrameBbis(l2);
5961 }
5962 log("Rx LAPDm ", lapdm);
5963 if (match(lapdm, exp)) {
5964 setverdict(pass);
5965 } else {
5966 repeat;
5967 }
5968 }
5969 [] L1CTL.receive { repeat; }
5970}
5971private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5972 timer T := t;
5973 T.start;
5974 alt {
5975 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005977 }
5978 [] as_l1_exp_lapdm(exp);
5979 }
5980}
5981
5982/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5983private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5984 /* send SABM from MS -> BTS */
5985 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5986 /* expect RLL EST IND on Abis */
5987 alt {
5988 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5989 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5990 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005992 }
5993 [] RSL.receive { repeat; }
5994 }
5995 /* expect UA from BTS -> MS */
5996 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5997}
5998
5999/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6000private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6001 var RllTestCase tc := g_pars.spec.rll;
6002
6003 f_l1_tune(L1CTL);
6004 RSL.clear;
6005
6006 /* activate the logical channel */
6007 f_est_dchan();
6008 L1CTL.clear;
6009
6010 /* first establish the link-layer */
6011 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6012
6013 /* then send the DISC */
6014 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6015 /* ... and expect the REL IND on the RSL side */
6016 alt {
6017 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6018 setverdict(pass);
6019 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006020 /* We also expect to receive the measurements */
6021 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006022 }
6023
6024 /* release the channel */
6025 f_rsl_chan_deact();
6026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6027 f_rslem_unregister(0, g_chan_nr);
6028}
6029testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6030 var RllTestCases tcs := {
6031 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6032 };
6033 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6034}
6035
6036testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6037 var RllTestCases tcs := {
6038 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6039 };
6040 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6041}
6042testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6043 var RllTestCases tcs := {
6044 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6045 };
6046 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6047}
6048testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6049 var RllTestCases tcs := {
6050 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6051 };
6052 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6053}
6054
6055/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6056private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6057 var RllTestCase tc := g_pars.spec.rll;
6058 f_l1_tune(L1CTL);
6059 RSL.clear;
6060
6061 /* activate the logical channel */
6062 f_est_dchan();
6063 L1CTL.clear;
6064
6065 /* first establish the link-layer */
6066 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6067
6068 /* then send the REL REQ via RSL */
6069 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6070 /* ... and expect the DISC on the Um side */
6071 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006072 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006073 /* FIXME: send a UA in resposne to the DISC */
6074 }
6075 }
6076
6077 /* release the channel */
6078 f_rsl_chan_deact();
6079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6080 f_rslem_unregister(0, g_chan_nr);
6081}
6082testcase TC_rll_rel_req() runs on test_CT {
6083 var RllTestCases tcs := {
6084 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6085 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6086 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6087 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6088 };
6089 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6090}
6091
6092/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
6093testcase TC_rll_data_req() runs on test_CT {
6094}
6095
6096/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
6097testcase TC_rll_data_ind() runs on test_CT {
6098}
6099
6100/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6101private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6102 var RllTestCase tc := g_pars.spec.rll;
6103
6104 f_l1_tune(L1CTL);
6105 RSL.clear;
6106
6107 f_est_dchan();
6108 L1CTL.clear;
6109
6110 /* Send UNITDATA REQ on RSL side */
6111 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6112 /* Expect it to arrive on the other side */
6113 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006114 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006115 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006116 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006117 }
6118
6119 /* release the channel */
6120 f_rsl_chan_deact();
6121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6122 f_rslem_unregister(0, g_chan_nr);
6123}
6124testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6125 var octetstring l3 := f_rnd_octstring(15);
6126 var RllTestCases tcs := {
6127 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6128 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6129 };
6130 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6131}
6132testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6133 var octetstring l3 := f_rnd_octstring(19);
6134 var RllTestCases tcs := {
6135 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6136 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6137 };
6138 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6139}
6140
6141/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6142private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6143 var RllTestCase tc := g_pars.spec.rll;
6144
6145 f_l1_tune(L1CTL);
6146 RSL.clear;
6147
6148 f_est_dchan();
6149 L1CTL.clear;
6150
6151 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006152 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006153 /* Expdct RLL UNITDATA IND on RSL side */
6154 alt {
6155 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6156 setverdict(pass);
6157 }
6158 [] RSL.receive { repeat; }
6159 }
6160
6161 /* release the channel */
6162 f_rsl_chan_deact();
6163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6164 f_rslem_unregister(0, g_chan_nr);
6165}
6166testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006167 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006168 var RllTestCases tcs := {
6169 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6170 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6171 };
6172 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6173}
6174testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6175 var octetstring l3 := f_rnd_octstring(18);
6176 var RllTestCases tcs := {
6177 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6178 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6179 };
6180 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6181}
6182
Harald Weltee613f962018-04-18 22:38:16 +02006183/***********************************************************************
6184 * Encryption Related
6185 ***********************************************************************/
6186
6187/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006188private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006189 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6190 if (link_id.c == SACCH) {
6191 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6192 } else {
6193 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6194 }
6195}
6196
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006197/* Expect (or not expect) other kinds of messages */
6198private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6199 [exp_any] RSL.receive { repeat; }
6200 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006202 }
6203}
6204
Harald Weltee613f962018-04-18 22:38:16 +02006205/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006206private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006207 RslLinkId link_id,
6208 octetstring l3,
6209 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006210 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006211) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006212 timer T := 3.0;
6213 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6214 T.start;
6215 /* Expect RLL UNITDATA IND on RSL side */
6216 alt {
6217 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6218 setverdict(pass);
6219 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006220 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006221 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006222 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006224 }
Harald Weltee613f962018-04-18 22:38:16 +02006225 }
6226}
6227
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006228/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6229private function f_data_mo(
6230 RslLinkId link_id,
6231 boolean p, uint3_t nr, uint3_t ns,
6232 octetstring l3,
6233 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006234 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006235) runs on ConnHdlr {
6236 timer T := 3.0;
6237 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6238 T.start;
6239 /* Expect RLL DATA IND on RSL side */
6240 alt {
6241 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6242 setverdict(pass);
6243 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006244 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006245 [] as_rsl_any_ind(exp_any);
6246 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006248 }
6249 }
6250}
6251
Harald Weltee613f962018-04-18 22:38:16 +02006252/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006253private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006254 f_l1_tune(L1CTL);
6255 f_est_dchan(true);
6256
6257 /* now we actually need to transmit some data both ways to check if the encryption works */
6258 var L1ctlDlMessage dl;
6259
Stefan Sperling603d98e2018-07-25 16:47:28 +02006260 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006261 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6262
6263 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6264 f_unitdata_mt(link_id, l3);
6265
6266 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6267 f_unitdata_mo(link_id, l3);
6268
6269 /* release the channel */
6270 f_rsl_chan_deact();
6271 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6272 f_rslem_unregister(0, g_chan_nr);
6273}
6274testcase TC_chan_act_a51() runs on test_CT {
6275 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6276 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6277 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6278}
6279testcase TC_chan_act_a52() runs on test_CT {
6280 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6281 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6282 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6283}
6284testcase TC_chan_act_a53() runs on test_CT {
6285 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6286 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6287 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6288}
6289
Eric Wildf1827a72019-05-28 17:37:35 +02006290/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6291 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006292private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006293 f_l1_tune(L1CTL);
6294 f_est_dchan(true);
6295
6296 /* now we actually need to transmit some data both ways to check if the encryption works */
6297 var L1ctlDlMessage dl;
6298
6299 var octetstring l3 := f_rnd_octstring(20);
6300 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6301
6302 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6303 f_unitdata_mt(link_id, l3);
6304
6305 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6306 f_unitdata_mo(link_id, l3);
6307
6308 var RSL_Message rsl;
6309 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6310
6311 /* modify key to break proper encryption */
6312 g_pars.encr.key := f_rnd_octstring(8);
6313 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6314 rsl.ies := rsl.ies & { ei };
6315 RSL.send(rsl);
6316
6317 timer T0 := 1.0;
6318 T0.start;
6319 /* Expect RSL MODIFY ACK */
6320 alt {
6321 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6322 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6324 }
6325 [] T0.timeout {
6326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6327 }
6328 }
6329
6330 var octetstring l3msg := f_rnd_octstring(15);
6331 timer T1 := 3.0;
6332 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6333 due to broken encryption */
6334 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6335 T1.start;
6336 alt {
6337 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6339 }
6340 [] T1.timeout {
6341 setverdict(pass);
6342 }
6343 }
6344
6345 /* release the channel */
6346 f_rsl_chan_deact();
6347 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6348 f_rslem_unregister(0, g_chan_nr);
6349}
6350testcase TC_rsl_modify_encr() runs on test_CT {
6351 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6352 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6353 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6354}
Harald Weltee613f962018-04-18 22:38:16 +02006355
6356/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006357private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006358 /* L3 payload doesn't matter, as it is passed transparently */
6359 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6360 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6361 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6362
6363 f_l1_tune(L1CTL);
6364
6365 /* first establish a dedicated channel in the clear */
6366 f_est_dchan(false);
6367
6368 /* Establish ABM */
6369 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6370
6371 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6372 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6373 /* expect the L3 to arrive still unencrypted on the MS side */
6374 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6375
6376 /* configure L1 to apply ciphering */
6377 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6378 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6379
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006380 /* send first ciphered I-frame in response and expect it on RSL */
6381 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006382
6383 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6384 * and hence enable encryption also on the downlink */
6385
6386 /* expect bi-directional communication work in encrypted mode */
6387 f_unitdata_mo(link_id, f_rnd_octstring(15));
6388 f_unitdata_mt(link_id, f_rnd_octstring(15));
6389
6390 /* release the channel */
6391 f_rsl_chan_deact();
6392 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6393 f_rslem_unregister(0, g_chan_nr);
6394}
6395testcase TC_encr_cmd_a51() runs on test_CT {
6396 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6397 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6398 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6399}
6400testcase TC_encr_cmd_a52() runs on test_CT {
6401 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6402 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6403 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6404}
6405testcase TC_encr_cmd_a53() runs on test_CT {
6406 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6407 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6408 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6409}
6410
6411private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6412 var LapdmFrame lf;
6413 var octetstring reenc;
6414
6415 /* decode the LAPDm frame */
6416 if (ischosen(exp_match.ab)) {
6417 lf.ab := dec_LapdmFrameAB(enc);
6418 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006420 }
6421
6422 /* check if decoder result matches expectation */
6423 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006425 } else {
6426 log(name, ": matched");
6427 setverdict(pass);
6428 }
6429
6430 /* test if re-encoded frame equals original input */
6431 reenc := enc_LapdmFrame(lf);
6432 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006434 } else {
6435 setverdict(pass);
6436 }
6437}
6438
6439testcase TC_lapdm_selftest() runs on test_CT {
6440 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6441 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6442 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6443 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6444 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6445 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6446 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6447}
6448
Stefan Sperling4880be42018-08-07 18:12:59 +02006449/***********************************************************************
6450 * DTX Related (see GSM 05.08, section 8.3)
6451 ***********************************************************************/
6452
6453/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006454private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006455 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6456 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6457 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6458 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6459}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006460private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006461 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6462 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6463}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006464private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006465 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6466 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6467 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6468 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6469}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006470private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006471 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6472 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6473 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6474 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6475 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6476 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6477 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6478 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6479}
6480
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006481private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006482 var L1ctlDlMessage dl;
6483 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6484 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6485 var GsmFrameNumber first_fn;
6486 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006487 var integer nfill_frames_sacch := 0;
6488 var integer nfill_frames_nonsacch := 0;
6489 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006490 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6491 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006492 const integer frame_dtx_tchf_mod := 104;
6493 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6494 * which operates in terms of blocks rather than frames. */
6495 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6496 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006497 timer T := 5.0;
6498
6499 f_l1_tune(L1CTL);
6500 RSL.clear;
6501 L1CTL.clear;
6502
6503 /* activate TCHF signalling channel */
6504 f_est_dchan(false);
6505
6506 T.start;
6507 alt {
6508 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6509 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6510 var octetstring l2 := dl.payload.data_ind.payload;
6511
6512 if (is_first_frame) {
6513 is_first_frame := false;
6514 first_fn := dl.dl_info.frame_nr;
6515 }
6516
6517 if (dl.dl_info.link_id.c == SACCH) {
6518 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6519 if (not match(l2_fill_frame_sacch, l2)) {
6520 repeat;
6521 }
6522 } else if (not match(l2_fill_frame, l2)) {
6523 repeat;
6524 }
6525
6526 if (dtxd) {
6527 if (not f_g_chan_is_tchf()) {
6528 T.stop;
6529 f_rsl_chan_deact();
6530 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006531 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 +02006532 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006533 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006534 T.stop;
6535 f_rsl_chan_deact();
6536 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006537
6538 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6539 * 2 SACCH, 1 TCH/F */
6540 expected_fill_frames := 3;
6541
6542 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6543 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6544 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006546 } else {
6547 setverdict(pass);
6548 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006549 } else {
6550 if (dl.dl_info.link_id.c == SACCH) {
6551 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006552 repeat;
6553 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006554 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6555 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6556 * we should only see the subset of frames numbers which correspond to a block boundary.
6557 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6558 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6559 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6560 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6561 repeat;
6562 }
6563 }
6564 log("Received DTX TCH fill frame with bad frame number: ", fn,
6565 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6566 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6567 f_rsl_chan_deact();
6568 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006570 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006571 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006572 if (dl.dl_info.link_id.c == SACCH) {
6573 nfill_frames_sacch := nfill_frames_sacch + 1;
6574 } else {
6575 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6576 }
6577 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006578 T.stop;
6579 if (f_g_chan_is_tchf()) {
6580 /* Without DTX we can expect 25 fill frames for every 104 frames.
6581 * (24 FACCH + 1 SACCH filling) */
6582 expected_fill_frames := 25;
6583 } else if (f_g_chan_is_tchh()) {
6584 /* We can expect 2 fill frames for every 104 frames. */
6585 expected_fill_frames := 2;
6586 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6587 /* We can expect 5 fill frames for every 104 frames. */
6588 expected_fill_frames := 5;
6589 } else {
6590 f_rsl_chan_deact();
6591 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006593 }
6594
6595 f_rsl_chan_deact();
6596 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006597
6598 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 setverdict(pass);
6600 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006601 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6602 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006604 }
6605 } else {
6606 repeat;
6607 }
6608 }
6609 }
6610 [] L1CTL.receive { repeat; }
6611 [] T.timeout {
6612 f_rsl_chan_deact();
6613 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006615 }
6616 }
6617}
6618
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006619private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006620 f_test_l2_fill_frames(false);
6621}
6622
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006623private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006624 f_test_l2_fill_frames(true);
6625}
6626
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006627private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006628 var ConnHdlr vc_conn;
6629 var ConnHdlrPars pars;
6630 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006631 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006632 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6633 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6634 if (dtxd) {
6635 if (i >= 4) { /* DTX is only allowed on TCH/F */
6636 break;
6637 }
6638 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6639 } else {
6640 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6641 }
6642 vc_conn.done;
6643 }
6644}
6645
6646/* Verify that L2 fill frames are sent on TCH in signaling mode if
6647 * there is nothing to transmit while DTX is disabled on downlink. */
6648testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6649 f_tch_sign_l2_fill_frame(false);
6650}
6651
6652/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6653 * there is nothing to transmit while DTX is enabled on downlink. */
6654testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6655 f_tch_sign_l2_fill_frame(true);
6656}
Harald Welte0472ab42018-03-12 15:02:26 +01006657
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006658testcase TC_chopped_ipa_ping() runs on test_CT {
6659 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6660}
6661
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006662testcase TC_chopped_ipa_payload() runs on test_CT {
6663 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6664}
6665
Harald Welte0472ab42018-03-12 15:02:26 +01006666/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6667/* protocol error as per 44.006 */
6668/* link layer failure (repetition of I-frame N200 times without ACK */
6669/* repetition of SABM or DISC N200 times without ACK */
6670/* receptiom of SABM in multi-frame established state */
6671
6672
Harald Welte68e495b2018-02-25 00:05:57 +01006673/* TODO Areas:
6674
6675* channel activation
6676** with BS_Power / MS_Power, bypassing power control loop
6677** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006678** with timing advance from initial activation on
6679* mode modify
6680** encryption
6681** multirate
6682* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006683** unsupported algorithm
6684* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006685* BS Power Control
6686* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006687* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006688* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006689** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006690* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006691** DATA_IND from BTS->PCU
6692** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006693
6694*/
Harald Welte70767382018-02-21 12:16:40 +01006695
6696control {
6697 execute( TC_chan_act_stress() );
6698 execute( TC_chan_act_react() );
6699 execute( TC_chan_deact_not_active() );
6700 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006701 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006702 execute( TC_sacch_filling() );
6703 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006704 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006705 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006706 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006707 execute( TC_sacch_chan_act_ho_async() );
6708 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006709 execute( TC_rach_content() );
6710 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006711 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006712 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006713 execute( TC_rach_load_idle_thresh0() );
6714 execute( TC_rach_load_idle_below_thresh() );
6715 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006716 execute( TC_meas_res_sign_tchf() );
6717 execute( TC_meas_res_sign_tchh() );
6718 execute( TC_meas_res_sign_sdcch4() );
6719 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006720 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006721 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006722 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006723 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006724 execute( TC_rsl_bs_pwr_static_ass() );
6725 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006726 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006727 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006728 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006729 execute( TC_rsl_ms_pwr_dyn_up() );
6730 execute( TC_rsl_ms_pwr_dyn_down() );
6731 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6732 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006733 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006734 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006735 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006736 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006737 execute( TC_paging_imsi_80percent() );
6738 execute( TC_paging_tmsi_80percent() );
6739 execute( TC_paging_imsi_200percent() );
6740 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006741 execute( TC_rsl_protocol_error() );
6742 execute( TC_rsl_mand_ie_error() );
6743 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006744 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006745 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006746 execute( TC_si_sched_2bis() );
6747 execute( TC_si_sched_2ter() );
6748 execute( TC_si_sched_2ter_2bis() );
6749 execute( TC_si_sched_2quater() );
6750 execute( TC_si_sched_13() );
6751 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006752 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006753 execute( TC_ipa_crcx_twice_not_active() );
6754 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006755 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006756 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006757
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006758 if (mp_pcu_socket != "") {
6759 execute( TC_pcu_act_req() );
6760 execute( TC_pcu_act_req_wrong_ts() );
6761 execute( TC_pcu_act_req_wrong_bts() );
6762 execute( TC_pcu_act_req_wrong_trx() );
6763 execute( TC_pcu_deact_req() );
6764 execute( TC_pcu_deact_req_wrong_ts() );
6765 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006766 if (mp_l1_supports_gprs) {
6767 execute( TC_pcu_data_req_pdtch() );
6768 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006769 execute( TC_pcu_data_req_wrong_bts() );
6770 execute( TC_pcu_data_req_wrong_trx() );
6771 execute( TC_pcu_data_req_wrong_ts() );
6772 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006773 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006774 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006775 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006776 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006777 execute( TC_pcu_data_req_imm_ass_pch() );
6778 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006779 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006780 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006781 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006782 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006783 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006784 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006785 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006786 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006787 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006788 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006789 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006790 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006791 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006792 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006793 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006794 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006795 execute( TC_dyn_osmo_pdch_act_deact() );
6796 execute( TC_dyn_osmo_pdch_double_act() );
6797 execute( TC_dyn_ipa_pdch_act_deact() );
6798 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6799
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006800 } else {
6801 log("PCU socket path not available, skipping PCU tests");
6802 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006803
Harald Welte3d04ae62018-04-04 20:29:05 +02006804 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006805 execute( TC_dyn_osmo_pdch_tchf_act() );
6806 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006807 execute( TC_dyn_ipa_pdch_tchf_act() );
6808 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006809
6810 execute( TC_rll_est_ind() );
6811 execute( TC_rll_est_req_DCCH_3() );
6812 execute( TC_rll_est_req_ACCH_3() );
6813 execute( TC_rll_rel_ind_DCCH_0() );
6814 execute( TC_rll_rel_ind_DCCH_3() );
6815 execute( TC_rll_rel_ind_ACCH_0() );
6816 execute( TC_rll_rel_ind_ACCH_3() );
6817 execute( TC_rll_rel_req() );
6818 execute( TC_rll_unit_data_req_DCCH() );
6819 execute( TC_rll_unit_data_req_ACCH() );
6820 execute( TC_rll_unit_data_ind_DCCH() );
6821 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006822
6823 execute( TC_chan_act_a51() );
6824 execute( TC_chan_act_a52() );
6825 execute( TC_chan_act_a53() );
6826 execute( TC_encr_cmd_a51() );
6827 execute( TC_encr_cmd_a52() );
6828 execute( TC_encr_cmd_a53() );
6829
Harald Welteee25aae2019-05-19 14:32:37 +02006830 execute( TC_err_rep_wrong_mdisc() );
6831 execute( TC_err_rep_wrong_msg_type() );
6832 execute( TC_err_rep_wrong_sequence() );
6833
Harald Weltee613f962018-04-18 22:38:16 +02006834 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006835
6836 execute( TC_tch_sign_l2_fill_frame() );
6837 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006838
6839 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006840 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006841}
6842
6843
6844}