blob: a42f62842211d24d0e766bb8cbb7a2b525ae33e6 [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 */
Harald Welte10474062019-05-30 16:48:17 +0200432function f_init() runs on test_CT {
433 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100434 g_AllChannels := {
435 /* TS 1..4: TCH/F */
436 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
437 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
438 /* TS 5: TCH/H */
439 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
440 /* TS 0: SDCCH/4 */
441 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
442 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
443 /* TS 6: SDCCH/8 */
444 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
445 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
446 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
447 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
448 };
449
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200450 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700451 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200452 g_AllChanTypes := {
453 /* TS 1..4: TCH/F */
454 valueof(ts_RslChanNr_Bm(1)),
455 /* TS 5: TCH/H */
456 valueof(ts_RslChanNr_Lm(5,1)),
457 /* TS 0: SDCCH/4 */
458 valueof(ts_RslChanNr_SDCCH4(0,2)),
459 /* TS 6: SDCCH/8 */
460 valueof(ts_RslChanNr_SDCCH8(6,4))
461 };
462 } else {
463 g_AllChanTypes := {
464 /* TS 1..4: TCH/F */
465 valueof(ts_RslChanNr_Bm(1)),
466 /* TS 0: SDCCH/4 */
467 valueof(ts_RslChanNr_SDCCH4(0,2)),
468 /* TS 6: SDCCH/8 */
469 valueof(ts_RslChanNr_SDCCH8(6,4))
470 };
471 }
Harald Welte70767382018-02-21 12:16:40 +0100472 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100473 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100474 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200475 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100476
477 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100478 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
479 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
480 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
481 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100482
Harald Weltef26de0b2018-04-04 20:28:05 +0200483 map(self:PCU, system:PCU);
484 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100485
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700486 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100487 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488
489 /* Init TRXC interface to FakeTRX */
490 map(self:BTS_TRXC, system:BTS_TRXC);
491 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
492
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700493 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700494 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700495 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700496 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
497 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100498 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200499
500 /* Wait some extra time to make sure the BTS emits a stable carrier.
501 * (this is only relevant when running the tests with a physical BTS.) */
502 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100503}
504
Harald Welte68e495b2018-02-25 00:05:57 +0100505/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
506function f_init_l1ctl() runs on test_CT {
507 map(self:L1CTL, system:L1CTL);
508 f_connect_reset(L1CTL);
509}
510
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 Yanitskiyf4e997c2019-06-04 21:40:33 +0700514function f_start_handler(void_fn fn, ConnHdlrPars pars,
515 boolean pcu_comp := false,
516 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100517runs on test_CT return ConnHdlr {
518 var charstring id := testcasename();
519 var ConnHdlr vc_conn;
520
521 vc_conn := ConnHdlr.create(id);
522 /* connect to RSL Emulation main component */
523 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
524 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700525
526 /* The ConnHdlr component may want to talk to some ports directly,
527 * so we disconnect it from the test_CT and connect it to the component.
528 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200529 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200530 unmap(self:PCU, system:PCU);
531 map(vc_conn:PCU, system:PCU);
532 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700533 if (trxc_comp) {
534 unmap(self:BTS_TRXC, system:BTS_TRXC);
535 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
536 }
Harald Welte70767382018-02-21 12:16:40 +0100537
538 vc_conn.start(f_handler_init(fn, id, pars));
539 return vc_conn;
540}
541
Harald Welte70767382018-02-21 12:16:40 +0100542private altstep as_Tguard() runs on ConnHdlr {
543 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100545 }
546}
547
Harald Welte990a3612019-05-27 14:02:13 +0200548friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
549 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100550}
551
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700552private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100553 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700554 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100555}
556
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700557private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100558 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700559 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100560}
561
562/* first function started in ConnHdlr component */
563private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
564runs on ConnHdlr {
565 g_pars := pars;
566 g_chan_nr := pars.chan_nr;
567
568 map(self:L1CTL, system:L1CTL);
569 f_connect_reset(L1CTL);
570
Harald Welted48c0c72019-06-05 10:01:15 +0200571 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700572 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100573 }
Harald Welte70767382018-02-21 12:16:40 +0100574
575 g_Tguard.start(pars.t_guard);
576 activate(as_Tguard());
577
578 f_rslem_register(0, pars.chan_nr);
579
580 /* call the user-supplied test case function */
581 fn.apply(id);
582}
583
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
610function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
611 boolean ignore_other := false)
612runs on ConnHdlr {
613 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100614}
615
Harald Welte8b01c792019-05-19 22:51:25 +0200616function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
617 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
618 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200619 if (encr_enable) {
620 /* append encryption related IEs, if requested */
621 var RSL_IE_EncryptionInfo encr_info;
622 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
623 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
624encr_info})) };
625 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200626 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200627 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100628}
629
Harald Welte70767382018-02-21 12:16:40 +0100630function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100631 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100632 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100633}
634
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700635/* Default Mobile Allocation to be used for frequency hopping */
636private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
637 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
638
Harald Welte2f2b2b72019-05-31 22:24:57 +0200639friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100640 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700641 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100642 float t_guard := 20.0) := {
643 chan_nr := valueof(chan_nr),
644 chan_mode := valueof(chan_mode),
645 t_guard := t_guard,
646 l1_pars := {
647 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100648 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100649 meas_ul := {
650 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200651 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100652 rxqual := 0
653 },
654 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200655 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100656 rxqual := 0
657 }
658 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200659 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100660 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200661 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200662 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100663 },
Harald Weltee613f962018-04-18 22:38:16 +0200664 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200665 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700666 bts0_band := omit,
667 maio_hsn := maio_hsn,
668 ma_map := c_MA_null,
669 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100670}
671
Harald Welte93640c62018-02-25 16:59:33 +0100672/***********************************************************************
673 * Channel Activation / Deactivation
674 ***********************************************************************/
675
Harald Welte70767382018-02-21 12:16:40 +0100676/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700677private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100678 for (var integer i := 0; i < 500; i := i+1) {
679 f_rsl_chan_act(g_pars.chan_mode);
680 f_rsl_chan_deact();
681 }
682 setverdict(pass);
683}
684testcase TC_chan_act_stress() runs on test_CT {
685 var ConnHdlr vc_conn;
686 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200687 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100688 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
689 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100691}
692
693/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700694private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100695 f_rsl_chan_act(g_pars.chan_mode);
696 /* attempt to activate the same lchan again -> expect reject */
697 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
698 alt {
699 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100701 }
702 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
703 setverdict(pass);
704 }
705 }
706 f_rsl_chan_deact();
707}
708testcase TC_chan_act_react() runs on test_CT {
709 var ConnHdlr vc_conn;
710 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100711 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100712 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
713 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100715}
716
717/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700718private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100719 timer T := 3.0;
720 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
721 T.start;
722 alt {
723 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
724 setverdict(pass);
725 }
726 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100728 }
729 }
730}
731testcase TC_chan_deact_not_active() runs on test_CT {
732 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100733 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100734 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
735 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100737}
738
739/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700740private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100741 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
742 alt {
743 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100745 }
746 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
747 setverdict(pass);
748 }
749 }
750}
751private type record WrongChanNrCase {
752 RslChannelNr chan_nr,
753 charstring description
754}
755private type record of WrongChanNrCase WrongChanNrCases;
756private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
757 chan_nr := chan_nr,
758 description := desc
759}
760
761testcase TC_chan_act_wrong_nr() runs on test_CT {
762 var ConnHdlr vc_conn;
763 var ConnHdlrPars pars;
764
Harald Welte294b0a22018-03-10 23:26:48 +0100765 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100766
767 var WrongChanNrCases wrong := {
768 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
769 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
770 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
771 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
772 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
773 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
774 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
775 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
776 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
777 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
778 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
779 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
780 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
781 };
782
783 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
784 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
785 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
786 vc_conn.done;
787 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100789}
790
Harald Weltee613f962018-04-18 22:38:16 +0200791/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200792friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200793 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200794 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200795
796 /* test on each of the channels we have */
797 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
798 pars.chan_nr := valueof(g_AllChanTypes[i]);
799
800 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
801 vc_conn := f_start_handler(fn, pars);
802 vc_conn.done;
803 }
804
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200806}
807
Harald Welte93640c62018-02-25 16:59:33 +0100808/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100809 * SACCH handling
810 ***********************************************************************/
811
812private function f_exp_sacch(boolean exp) runs on ConnHdlr {
813 timer T_sacch := 3.0;
814 T_sacch.start;
815 alt {
816 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100818 }
819 [not exp] T_sacch.timeout {
820 setverdict(pass);
821 }
822 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
823 setverdict(pass);
824 }
825 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100827 }
828 [] L1CTL.receive { repeat; }
829 [] RSL.receive { repeat; }
830 }
831}
832
833/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
834private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
835 f_l1_tune(L1CTL);
836 RSL.clear;
837
838 /* activate the logical channel */
839 f_est_dchan();
840 L1CTL.clear;
841
842 /* check that SACCH actually are received as expected */
843 f_exp_sacch(true);
844
845 /* deactivate SACCH on the logical channel */
846 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
847 f_sleep(1.0);
848 L1CTL.clear;
849
850 /* check that no SACCH are received anymore */
851 f_exp_sacch(false);
852
853 /* release the channel */
854 f_rsl_chan_deact();
855 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
856}
857testcase TC_deact_sacch() runs on test_CT {
858 var ConnHdlr vc_conn;
859 var ConnHdlrPars pars;
860 f_init();
861 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
862 //for (var integer i := 0; i < 1; i := i+1) {
863 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
864 log(testcasename(), ": Starting for ", g_AllChannels[i]);
865 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
866 vc_conn.done;
867 }
868 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100870}
871
Harald Welte55700662018-03-12 13:15:43 +0100872/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100873private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
874 var L1ctlDlMessage dl;
875 /* check that the specified SI5 value is actually sent */
876 timer T_sacch := 3.0;
877 L1CTL.clear;
878 T_sacch.start;
879 alt {
880 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
881 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
882 if (match(l3, l3_exp)) {
883 setverdict(pass);
884 } else {
885 repeat;
886 }
887 }
888 [] L1CTL.receive { repeat; }
889 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100891 }
892 }
893}
894
Harald Welte55700662018-03-12 13:15:43 +0100895/* verify that given SACCH payload is not present */
896private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
897 var L1ctlDlMessage dl;
898 /* check that the specified SI5 value is actually sent */
899 timer T_sacch := 3.0;
900 L1CTL.clear;
901 T_sacch.start;
902 alt {
903 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
904 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
905 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100907 } else {
908 repeat;
909 }
910 }
911 [] L1CTL.receive { repeat; }
912 [] T_sacch.timeout {
913 setverdict(pass);
914 }
915 }
916}
917
Harald Welte629cc6b2018-03-11 17:19:05 +0100918/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100919private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
920 /* Set a known default SACCH filling for SI5 */
921 var octetstring si5 := f_rnd_octstring(19);
922 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
923
924 f_l1_tune(L1CTL);
925 RSL.clear;
926
927 /* activate the logical channel */
928 f_est_dchan();
929
930 /* check that the specified SI5 value is actually sent */
931 f_sacch_present(si5);
932
933 /* release the channel */
934 RSL.clear;
935 f_rsl_chan_deact();
936 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
937}
938testcase TC_sacch_filling() runs on test_CT {
939 var ConnHdlr vc_conn;
940 var ConnHdlrPars pars;
941 f_init();
942 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
943 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
944 log(testcasename(), ": Starting for ", g_AllChannels[i]);
945 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
946 vc_conn.done;
947 }
948 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100950}
951
Harald Welte629cc6b2018-03-11 17:19:05 +0100952/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100953private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
954 /* Set a known default SACCH filling for SI5 */
955 var octetstring si5 := f_rnd_octstring(19);
956 var octetstring si5_diff := f_rnd_octstring(19);
957 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
958
959 f_l1_tune(L1CTL);
960 RSL.clear;
961
962 log("Activating channel, expecting standard SI5");
963 /* activate the logical channel */
964 f_est_dchan();
965 /* check that the specified SI5 value is actually sent */
966 f_sacch_present(si5);
967
968 /* set channel-specific different SI5 */
969 log("Setting channel specific SACCH INFO, expecting it");
970 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
971 /* check that the specified lchan-specific value is now used */
972 f_sacch_present(si5_diff);
973
974 /* deactivate the channel and re-activate it, this should result in default SI5 */
975 log("De-activating and re-activating channel, expecting standard SI5");
976 f_rsl_chan_deact();
977 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
978 /* Verify that the TRX-wide default SACCH filling is present again */
979 f_sacch_present(si5);
980
981 /* release the channel */
982 RSL.clear;
983 f_rsl_chan_deact();
984 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
985}
986testcase TC_sacch_info_mod() runs on test_CT {
987 var ConnHdlr vc_conn;
988 var ConnHdlrPars pars;
989 f_init();
990 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
991 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
992 log(testcasename(), ": Starting for ", g_AllChannels[i]);
993 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
994 vc_conn.done;
995 }
996 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100998}
999
Harald Welte075d84c2018-03-12 13:07:24 +01001000/* Test SACCH scheduling of multiple different SI message types */
1001private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1002 var octetstring si5 := f_rnd_octstring(19);
1003 var octetstring si5bis := f_rnd_octstring(19);
1004 var octetstring si5ter := f_rnd_octstring(19);
1005 var octetstring si6 := f_rnd_octstring(19);
1006
1007 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1008 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1009 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1010 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1011
1012 f_l1_tune(L1CTL);
1013 RSL.clear;
1014
1015 /* activate the logical channel */
1016 f_est_dchan();
1017 L1CTL.clear;
1018
1019 /* check that SACCH actually are received as expected */
1020 f_sacch_present(si5);
1021 f_sacch_present(si5bis);
1022 f_sacch_present(si5ter);
1023 f_sacch_present(si6);
1024
1025 /* release the channel */
1026 f_rsl_chan_deact();
1027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1028}
1029testcase TC_sacch_multi() runs on test_CT {
1030 var ConnHdlr vc_conn;
1031 var ConnHdlrPars pars;
1032 f_init();
1033 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1034 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1035 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1036 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1037 vc_conn.done;
1038 }
1039 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001041}
1042
Harald Welte55700662018-03-12 13:15:43 +01001043/* Test if SACH information is modified as expected */
1044private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1045 var octetstring si5 := f_rnd_octstring(19);
1046 var octetstring si6 := f_rnd_octstring(19);
1047
1048 /* First, configure both SI5 and SI6 to be transmitted */
1049 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1050 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1051
1052 f_l1_tune(L1CTL);
1053 RSL.clear;
1054
1055 /* activate the logical channel */
1056 f_est_dchan();
1057 L1CTL.clear;
1058
1059 /* check that SACCH actually are received as expected */
1060 f_sacch_present(si5);
1061 f_sacch_present(si6);
1062
1063 /* disable SI6 */
1064 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1065
1066 /* check that SI5 is still transmitted */
1067 f_sacch_present(si5);
1068 /* check if SI6 is now gone */
1069 f_sacch_missing(si6);
1070
1071 /* release the channel */
1072 f_rsl_chan_deact();
1073 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1074}
1075testcase TC_sacch_multi_chg() runs on test_CT {
1076 var ConnHdlr vc_conn;
1077 var ConnHdlrPars pars;
1078 f_init();
1079 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1080 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1081 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1082 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1083 vc_conn.done;
1084 }
1085 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001087}
1088
Harald Weltec8d363c2019-05-19 20:36:48 +02001089/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1090private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1091 var octetstring si5 := f_rnd_octstring(19);
1092 var octetstring si6 := f_rnd_octstring(19);
1093 var octetstring si5_specific := f_rnd_octstring(19);
1094 var octetstring si6_specific := f_rnd_octstring(19);
1095
1096 /* First, configure both SI5 and SI6 to be transmitted */
1097 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1098 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1099
1100 f_l1_tune(L1CTL);
1101 RSL.clear;
1102
1103 /* activate channel with different SACCH filling */
1104 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1105 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1106 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1107 }));
1108 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1109 RSL_IE_Body:{sacch_info := sacch_info})) };
1110 f_est_dchan(more_ies := addl_ies);
1111
1112 /* check that SACCH actually are received as expected */
1113 f_sacch_present(si5_specific);
1114 f_sacch_present(si6_specific);
1115
1116 /* release the channel */
1117 f_rsl_chan_deact();
1118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1119}
1120testcase TC_sacch_chan_act() runs on test_CT {
1121 var ConnHdlr vc_conn;
1122 var ConnHdlrPars pars;
1123 f_init();
1124
1125 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1126 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1127 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1128 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1129 vc_conn.done;
1130 }
1131 /* TODO: do the above in parallel, rather than sequentially? */
1132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1133}
1134
Harald Welte8b01c792019-05-19 22:51:25 +02001135/* verify that SACCH DL transmission is started only if MS power IE present
1136 * see section 4.1.3 of 3GPP TS 48.058 */
1137private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1138 var octetstring si5 := f_rnd_octstring(19);
1139
1140 f_l1_tune(L1CTL);
1141 RSL.clear;
1142
1143 /* Step 1: Activate ASYNC HO channel without MS power IE */
1144
1145 /* Activate channel on BTS side */
1146 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1147 /* don't perform immediate assignment here, as we're testing non-IA case */
1148 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001149 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001150
1151 /* Verify that no DL SACCH is being received */
1152 f_sacch_missing(?);
1153
1154 f_rsl_chan_deact();
1155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1156
1157
1158 /* Step 2: Activate ASYNC HO channel with MS power IE */
1159
1160 /* Activate channel on BTS side */
1161 var RSL_IE_List addl_ies := {
1162 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1163 };
1164 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1165 /* don't perform immediate assignment here, as we're testing non-IA case */
1166 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001167 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001168
1169 /* Verify that DL SACCH is being received */
1170 f_sacch_present(si5);
1171
1172 f_rsl_chan_deact();
1173 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1174}
1175testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1176 var ConnHdlr vc_conn;
1177 var ConnHdlrPars pars;
1178 f_init();
1179
1180 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1181 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1182 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1183 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1184 vc_conn.done;
1185 }
1186 /* TODO: do the above in parallel, rather than sequentially? */
1187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1188}
1189
1190/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1191 * see section 4.1.4 of 3GPP TS 48.058 */
1192private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1193 var octetstring si5 := f_rnd_octstring(19);
1194 var RSL_IE_List addl_ies;
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* Step 1: Activate SYNC HO channel without MS power IE */
1200
1201 /* Activate channel on BTS side */
1202 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1203 /* don't perform immediate assignment here, as we're testing non-IA case */
1204 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001205 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001206
1207 /* Verify that no DL SACCH is being received */
1208 f_sacch_missing(?);
1209
1210 f_rsl_chan_deact();
1211 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1212
1213
1214 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1215
1216 /* Activate channel on BTS side */
1217 addl_ies := {
1218 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1219 };
1220 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1221 /* don't perform immediate assignment here, as we're testing non-IA case */
1222 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001223 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001224
1225 /* Verify that no DL SACCH is being received */
1226 f_sacch_missing(?);
1227
1228 f_rsl_chan_deact();
1229 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1230
1231
1232 /* Step 2b: Activate SYNC HO channel with TA IE */
1233
1234 /* Activate channel on BTS side */
1235 addl_ies := {
1236 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1237 };
1238 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1239 /* don't perform immediate assignment here, as we're testing non-IA case */
1240 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001241 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001242
1243 /* Verify that no DL SACCH is being received */
1244 f_sacch_missing(?);
1245
1246 f_rsl_chan_deact();
1247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1248
1249
1250 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1251
1252 /* Activate channel on BTS side */
1253 addl_ies := {
1254 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1255 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1256 };
1257 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1258 /* don't perform immediate assignment here, as we're testing non-IA case */
1259 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001260 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001261
1262 /* Verify that DL SACCH is being received */
1263 f_sacch_present(si5);
1264
1265 f_rsl_chan_deact();
1266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1267}
1268testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1269 var ConnHdlr vc_conn;
1270 var ConnHdlrPars pars;
1271 f_init();
1272
1273 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1274 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1275 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1276 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1277 vc_conn.done;
1278 }
1279 /* TODO: do the above in parallel, rather than sequentially? */
1280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1281}
Harald Welte629cc6b2018-03-11 17:19:05 +01001282
1283
1284/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001285 * RACH Handling
1286 ***********************************************************************/
1287
Harald Welte8c24c2b2018-02-26 08:31:31 +01001288/* like L1SAP_IS_PACKET_RACH */
1289private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001290 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291 return true;
1292 }
1293 return false;
1294}
1295
1296/* generate a random RACH for circuit-switched */
1297private function f_rnd_ra_cs() return OCT1 {
1298 var OCT1 ra;
1299 do {
1300 ra := f_rnd_octstring(1);
1301 } while (ra_is_ps(ra));
1302 return ra;
1303}
1304
Harald Welte883340c2018-02-28 18:59:29 +01001305/* generate a random RACH for packet-switched */
1306private function f_rnd_ra_ps() return OCT1 {
1307 var OCT1 ra;
1308 do {
1309 ra := f_rnd_octstring(1);
1310 } while (not ra_is_ps(ra));
1311 return ra;
1312}
1313
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001314/* generate a random 11-bit RA (packet-switched only) */
1315private function f_rnd_ra11_ps() return BIT11 {
1316 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1317 return int2bit(ra11, 11);
1318}
1319
Harald Welte8c24c2b2018-02-26 08:31:31 +01001320/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1321testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001322 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001323 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001324 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001325
Harald Welte8c24c2b2018-02-26 08:31:31 +01001326 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001327 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001328 for (var integer i := 0; i < 1000; i := i+1) {
1329 var OCT1 ra := f_rnd_ra_cs();
1330 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1331 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001333 }
1334 fn_last := fn;
1335
1336 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001337 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001338 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001339 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001340 T.stop;
1341 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001342 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001344 }
1345 [] RSL_CCHAN.receive { repeat; }
1346 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001347 test_failed := true;
1348 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001349 }
1350 }
1351 }
Maxba06feb2019-03-05 10:52:46 +01001352 if (test_failed) {
1353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001354 }
Maxba06feb2019-03-05 10:52:46 +01001355 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001357}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001358
1359/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1360testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001361 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001362 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001363 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001364 f_l1_tune(L1CTL);
1365
1366 var GsmFrameNumber fn_last := 0;
1367 for (var integer i := 0; i < 1000; i := i+1) {
1368 var OCT1 ra := f_rnd_ra_cs();
1369 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1370 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001372 }
1373 fn_last := fn;
1374 }
1375 var integer rsl_chrqd := 0;
1376 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001377 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001378 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001379 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001380 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001381 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001382 repeat;
1383 }
1384 [] RSL_CCHAN.receive { repeat; }
1385 [] T.timeout { }
1386 }
1387 if (rsl_chrqd == 1000) {
1388 setverdict(pass);
1389 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001391 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001393}
1394
Harald Welte3453ab42019-05-24 21:19:58 +02001395private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1396 var charstring bts_str := "bts " & int2str(bts_nr);
1397 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1398}
1399
1400/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1401private template integer tr_rach_slots_per_interval := (90 .. 130);
1402
1403/* Expect 0 RACH load on an idle BTS that has just started up */
1404testcase TC_rach_load_idle_thresh0() runs on test_CT {
1405 var ASP_RSL_Unitdata rx_ud;
1406
1407 f_init_vty_bsc();
1408 /* send load indications even at 0% load */
1409 f_vty_load_ind_thresh(0);
1410 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1411 f_sleep(2.0);
1412
1413 f_init();
1414
1415 timer T := 5.0;
1416 T.start;
1417 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001418 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001419 setverdict(pass);
1420 repeat;
1421 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001422 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001423 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1424 repeat;
1425 }
1426 [] RSL_CCHAN.receive {
1427 repeat;
1428 }
1429 [] T.timeout { }
1430 }
1431
1432 f_vty_load_ind_thresh(10);
1433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1434}
1435
1436/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1437testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1438 var ASP_RSL_Unitdata rx_ud;
1439
1440 f_init_vty_bsc();
1441 f_init();
1442
1443 timer T := 5.0;
1444 T.start;
1445 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001446 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001447 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1448 repeat;
1449 }
1450 [] RSL_CCHAN.receive {
1451 repeat;
1452 }
1453 [] T.timeout {
1454 setverdict(pass);
1455 }
1456 }
1457
1458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1459}
1460
1461/* Expect 0 RACH load on an idle BTS that has just started up */
1462testcase TC_rach_load_count() runs on test_CT {
1463 var ASP_RSL_Unitdata rx_ud;
1464 var integer load_access_count := 0;
1465
1466 f_init_vty_bsc();
1467 /* send load indications even at 0% load */
1468 f_vty_load_ind_thresh(0);
1469 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1470 f_sleep(2.0);
1471 f_init();
1472
1473 f_init_l1ctl();
1474 f_sleep(1.0);
1475 f_l1_tune(L1CTL);
1476
1477 var GsmFrameNumber fn_last := 0;
1478 for (var integer i := 0; i < 1000; i := i+1) {
1479 var OCT1 ra := f_rnd_ra_cs();
1480 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1481 if (fn == fn_last) {
1482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1483 }
1484 fn_last := fn;
1485 }
1486
1487 timer T := 5.0;
1488 T.start;
1489 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001490 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001491 -> value rx_ud {
1492 var RSL_IE_Body ie;
1493 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1494 load_access_count := load_access_count + ie.rach_load.access_count;
1495 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1496 setverdict(fail, "Access count cannot be < Busy count");
1497 }
1498 repeat;
1499 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001500 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001501 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1502 repeat;
1503 }
1504 [] RSL_CCHAN.receive {
1505 repeat;
1506 }
1507 [] T.timeout { }
1508 }
1509 if (load_access_count == 1000) {
1510 setverdict(pass);
1511 } else {
1512 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1513 }
1514
1515 f_vty_load_ind_thresh(10);
1516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1517}
1518
Harald Welte54a2a2d2018-02-26 09:14:05 +01001519private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001520 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001521 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001522 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001523 f_sleep(0.5);
1524
1525 /* Transmit RACH request + wait for confirmation */
1526 var OCT1 ra := f_rnd_ra_cs();
1527 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1528
1529 /* Check for expected result */
1530 timer T := 1.5;
1531 T.start;
1532 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001533 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001534 setverdict(pass);
1535 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001536 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001538 }
1539 [] RSL_CCHAN.receive { repeat; }
1540 [not expect_pass] T.timeout {
1541 setverdict(pass);
1542 }
1543 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001545 }
1546 }
1547}
1548
1549/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1550testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001551 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001552 f_init_l1ctl();
1553 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001554 f_sleep(1.0);
1555
1556 /* default max-ta is 63 (full range of GSM timing advance */
1557
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001558 /* We allow early arrival up to 2 symbols */
1559 f_rach_toffs(-1*256, true);
1560 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001561 f_rach_toffs(-10*256, false);
1562
1563 /* 0 / 32 / 63 bits is legal / permitted */
1564 f_rach_toffs(0, true);
1565 f_rach_toffs(32*256, true);
1566 f_rach_toffs(63*256, true);
1567
1568 /* more than 63 bits is not legal / permitted */
1569 f_rach_toffs(64*256, false);
1570 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001572}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001573
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001574private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001575 var GsmFrameNumber fn;
1576 var RSL_Message rm;
1577
1578 f_l1_tune(L1CTL);
1579 RSL.clear;
1580
1581 /* Generate a random Handover Reference */
1582 var integer ho_ref := oct2int(f_rnd_octstring(1));
1583
1584 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1585 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1586 RSL_IE_Body:{ handover_ref := ho_ref }));
1587
1588 /* Activate a channel on the BTS side (no encryption) */
1589 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1590 act_type := t_RSL_IE_ActType_HO_SYNC);
1591
1592 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1593 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001594 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001595
1596 /* Send handover Access Burst */
1597 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1598
1599 /* TODO: test mismatching Handover Reference, and missing IE */
1600
1601 /* Wait for handover detection */
1602 timer T := 3.0;
1603 T.start;
1604 alt {
1605 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1606 log("Handover RACH has been detected: ", rm);
1607 setverdict(pass);
1608 }
1609 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1611 log2str("RSL_CHAN_RQD was not expected: ", rm));
1612 }
1613 [] RSL.receive { repeat; }
1614 [] T.timeout {
1615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1616 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1617 }
1618 }
1619
1620 /* Release the channel */
1621 f_rsl_chan_deact();
1622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1623}
1624
1625/* Test handover RACH detection */
1626testcase TC_ho_rach() runs on test_CT {
1627 var ConnHdlrPars pars;
1628 var ConnHdlr vc_conn;
1629
1630 f_init();
1631
1632 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1633 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1634 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1635 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1636 vc_conn.done;
1637 }
1638
1639 /* TODO: do the above in parallel, rather than sequentially? */
1640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1641}
1642
Harald Welte93640c62018-02-25 16:59:33 +01001643/***********************************************************************
1644 * Measurement Processing / Reporting
1645 ***********************************************************************/
1646
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001647private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001648 spare := '0'B,
1649 lpd := 0,
1650 sapi := sapi,
1651 c_r := c_r,
1652 ea := true
1653}
1654
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001655private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001656 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001657 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001658 len := 0, /* overwritten */
1659 m := false,
1660 el := 1,
1661 payload := pl
1662}
1663
1664/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001665private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001666 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001667 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001668 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001669 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001670 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001671 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001672
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001673 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1674 g_pars.l1_pars.ms_power_level, false,
1675 g_pars.l1_pars.ms_actual_ta);
1676
1677 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1678 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1679
1680 log("Sending Measurement Report: ", l1h, l2);
1681 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001682 repeat;
1683 }
1684}
1685
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001686private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001687 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001688 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001689 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1690 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001691 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1692 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001693 repeat;
1694 }
1695}
1696
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001697private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001698 uint6_t rxlev,
1699 uint3_t rxqual
1700}
1701
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001702private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001703 MeasElem full,
1704 MeasElem sub
1705}
1706
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001707private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001708 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001709 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001710 MeasElemFS meas_ul,
1711 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001712 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001713 uint5_t ms_power_level,
1714 uint8_t ms_actual_ta
1715}
1716
1717/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1718private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1719 return 63 + (toffs256s/256);
1720}
1721
Harald Welted5684392018-03-10 18:22:04 +01001722private function f_max(integer a, integer b) return integer {
1723 if (a > b) {
1724 return a;
1725 } else {
1726 return b;
1727 }
1728}
1729
1730private function f_min(integer a, integer b) return integer {
1731 if (a < b) {
1732 return a;
1733 } else {
1734 return b;
1735 }
1736}
1737
1738/* compute negative tolerance val-tolerance, ensure >= min */
1739private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1740 val := val - tolerance;
1741 return f_max(val, min);
1742}
1743
1744/* compute positive tolerance val+tolerance, ensure <= max */
1745private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1746 val := val + tolerance;
1747 return f_min(val, max);
1748}
1749
1750/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1751private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1752return template integer {
1753 var template integer ret;
1754 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1755 return ret;
1756}
1757
1758
Harald Welte70767382018-02-21 12:16:40 +01001759/* build a template for matching measurement results against */
1760private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1761 var ConnL1Pars l1p := g_pars.l1_pars;
1762 var template RSL_IE_UplinkMeas ul_meas := {
1763 len := 3,
1764 rfu := '0'B,
1765 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001766 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001767 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001768 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001769 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001770 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1771 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001772 supp_meas_info := omit
1773 };
Harald Welte685d5982018-02-27 20:42:05 +01001774 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001775 ul_meas.len := (3+8);
1776 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001777 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001778 toa256_min := ?,
1779 toa256_max := ?,
1780 toa256_std_dev := ?
1781 }
Harald Welte685d5982018-02-27 20:42:05 +01001782 }
Harald Welte70767382018-02-21 12:16:40 +01001783 var template RSL_IE_BS_Power bs_power := {
1784 reserved := 0,
1785 epc := false,
1786 fpc := false,
1787 power_level := l1p.bs_power_level
1788 };
1789 var template RSL_IE_L1Info l1_info := {
1790 ms_power_lvl := l1p.ms_power_level,
1791 fpc := false,
1792 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001793 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001794 };
1795 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001796 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001797 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1798 ?, t_toffs);
1799}
1800
Philipp Maierdd841d32019-12-17 14:44:54 +01001801/* build a template for matching measurement results that do not contain any
1802 * MS related measurement (l1_info, l3_info and ms timing offset). */
1803private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1804 var ConnL1Pars l1p := g_pars.l1_pars;
1805 var template RSL_IE_UplinkMeas ul_meas := {
1806 len := 3,
1807 rfu := '0'B,
1808 dtx_d := l1p.dtx_enabled,
1809 rxlev_f_u := ?,
1810 reserved1 := '00'B,
1811 rxlev_s_u := ?,
1812 reserved2 := '00'B,
1813 rxq_f_u := ?,
1814 rxq_s_u := ?,
1815 supp_meas_info := omit
1816 };
1817 if (l1p.toa256_enabled) {
1818 ul_meas.len := (3+8);
1819 ul_meas.supp_meas_info := {
1820 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1821 toa256_min := ?,
1822 toa256_max := ?,
1823 toa256_std_dev := ?
1824 }
1825 }
1826 var template RSL_IE_BS_Power bs_power := {
1827 reserved := 0,
1828 epc := false,
1829 fpc := false,
1830 power_level := l1p.bs_power_level
1831 };
1832
1833 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1834}
1835
Harald Welte70767382018-02-21 12:16:40 +01001836/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001837private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001838 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001839 var boolean chan_est := false;
1840
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001841 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001842
1843 /* Receive osmocom specific measurement reports. This is the normal
1844 * case. Here we verify that the measurement reports we sent are
1845 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001846 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1847 /* increment counter of next to-be-expected meas rep */
1848 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1849 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001850 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001851
1852 /* The following two cases may only happen in the beginning
1853 * of the channel establishment phase. Once we have received
1854 * the "our" measurement report the first time, the channel
1855 * is established and empty or hardcoded TRXCON reports must
1856 * not occur anymore. */
1857 chan_est := true;
1858
1859 repeat;
1860 }
1861
1862 /* When the BTS has established the channel, the MS might need slightly
1863 * more time to establish the channel and actually start sending. The
1864 * result is then a measurement report that just lacks the measurement
1865 * information of the MS. This is normal and we tolerate this behavior. */
1866 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1867 /* increment counter of next to-be-expected meas rep */
1868 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1869 /* Re-start the timer expecting the next MEAS RES */
1870 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001871 repeat;
1872 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001873
1874 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1875 * measurements if the TTCN3 side does not supply measurement input in
1876 * time. In those cases TRXCON will either use a cached measurement
1877 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1878 * report the templates above will not match. We tolerate this
1879 * behavior, but only once. */
1880 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001881 /* increment counter of next to-be-expected meas rep */
1882 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1883 if (g_first_meas_res) {
1884 g_first_meas_res := false;
1885 repeat;
1886 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001888 }
Harald Welte70767382018-02-21 12:16:40 +01001889 }
1890 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001892 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001893 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001895 }
1896}
1897
Harald Weltee613f962018-04-18 22:38:16 +02001898private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1899 select (rsl_alg_id) {
1900 case (RSL_ALG_ID_A5_0) { return 0; }
1901 case (RSL_ALG_ID_A5_1) { return 1; }
1902 case (RSL_ALG_ID_A5_2) { return 2; }
1903 case (RSL_ALG_ID_A5_3) { return 3; }
1904 case (RSL_ALG_ID_A5_4) { return 4; }
1905 case (RSL_ALG_ID_A5_5) { return 5; }
1906 case (RSL_ALG_ID_A5_6) { return 6; }
1907 case (RSL_ALG_ID_A5_7) { return 7; }
1908 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1910 /* Make compiler happy by calling mtc.stop here. It is already
1911 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001912 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001913 }
1914 }
1915}
1916
1917private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1918 select (rsl_alg_id) {
1919 case (RSL_ALG_ID_A5_1) { return '000'B; }
1920 case (RSL_ALG_ID_A5_2) { return '001'B; }
1921 case (RSL_ALG_ID_A5_3) { return '010'B; }
1922 case (RSL_ALG_ID_A5_4) { return '011'B; }
1923 case (RSL_ALG_ID_A5_5) { return '100'B; }
1924 case (RSL_ALG_ID_A5_6) { return '101'B; }
1925 case (RSL_ALG_ID_A5_7) { return '110'B; }
1926 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1928 /* Make compiler happy by calling mtc.stop here. It is already
1929 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001930 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001931 }
1932 }
1933}
1934
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001935/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1936private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1937 var GsmFrameNumber fn;
1938 timer T := 8.0;
1939
1940 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1941 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1942
1943 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1944 /* Send the actual RACH */
1945 fn := f_L1CTL_RACH(L1CTL, ra);
1946
1947 T.start;
1948 alt {
1949 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1950 [] T.timeout {
1951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1952 }
1953 }
1954 T.stop
1955 return fn;
1956}
Harald Weltee613f962018-04-18 22:38:16 +02001957
Harald Welte70767382018-02-21 12:16:40 +01001958/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001959private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001960 var GsmFrameNumber fn;
1961 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001962 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001963 var integer ra := 23;
1964
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001965 /* Send RACH request and wait for ChanReq */
1966 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001967
1968 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001969 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001970
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001971 /* Craft channel description (with or without frequency hopping parameters) */
1972 if (ispresent(g_pars.maio_hsn)) {
1973 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
1974 } else {
1975 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
1976 }
1977
Harald Welte70767382018-02-21 12:16:40 +01001978 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001979 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01001980 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1981
1982 /* receive IMM.ASS on MS side */
1983 var ImmediateAssignment ia_um;
1984 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001985
1986 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
1987 if (ch_desc.h != ia_um.chan_desc.h) {
1988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
1989 }
1990
Harald Welte70767382018-02-21 12:16:40 +01001991 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001992 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02001993 /* enable encryption, if requested */
1994 if (encr_enable) {
1995 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1996 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1997 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001998
1999 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002000}
2001
2002/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002003private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002004 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002005 RSL.clear;
2006
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002007 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002008 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002009 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002010 }
Harald Welte70767382018-02-21 12:16:40 +01002011
2012 f_est_dchan();
2013
2014 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2015 * RSL measurement reports on Abis side */
2016 timer T := 8.0;
2017 T.start;
2018 alt {
2019 [] as_l1_sacch();
2020 [] as_meas_res();
2021 [] as_l1_dcch();
2022 [] L1CTL.receive { repeat; }
2023 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002024 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002025 * of any earlier errors, so if we reach this timeout, we're good */
2026 setverdict(pass);
2027 }
2028 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002030 }
2031 }
2032 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002033 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002034}
Harald Welte0472ab42018-03-12 15:02:26 +01002035
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002036/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2037private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002038 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002039 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2040 timer Tup := 10.0;
2041 Tup.start;
2042 alt {
2043 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2044 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2045 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002046
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002047 if (rx_lvl != max_rx_lvl) {
2048 repeat;
2049 }
2050 Tup.stop;
2051 }
2052 [] L1CTL.receive { repeat; }
2053 [] Tup.timeout {
2054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2055 log2str("Didn't reach full power ", max_rx_lvl));
2056 }
2057 }
2058 return max_rx_lvl;
2059}
2060
2061/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2062private function f_verify_ramp_up() runs on ConnHdlr {
2063 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002064 var integer initial_rx_lvl := -1;
2065 var integer last_rx_lvl := -1;
2066 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2067
2068 timer T := 2.0;
2069 alt {
2070 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2071 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2072 log("Received rx_level=", rx_lvl);
2073 if (initial_rx_lvl == -1) {
2074 initial_rx_lvl := rx_lvl;
2075 last_rx_lvl := rx_lvl;
2076
2077 /* Expect a somehow low value during first received messages */
2078 if (initial_rx_lvl >= max_rx_lvl / 2) {
2079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2080 log2str("Detected high initial tx power during ramp up: ",
2081 initial_rx_lvl , ", full power is", max_rx_lvl));
2082 }
2083 }
2084
2085 /* received Rx level bigger than maximum allowed power by CN */
2086 if (rx_lvl > max_rx_lvl) {
2087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2088 log2str("Detected Tx power higher than full power: ",
2089 rx_lvl , " > ", max_rx_lvl));
2090 }
2091
2092 /* Make sure it never decreases, since we are rumping up */
2093 if (last_rx_lvl > rx_lvl) {
2094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2095 log2str("Detected Tx power decrease during ramp up: ",
2096 last_rx_lvl , " -> ", rx_lvl));
2097 }
2098
2099 if (rx_lvl == max_rx_lvl and not T.running) {
2100 /* We reached the maximum power, start timer and receive
2101 /* a few more to make sure we don't surpass it */
2102 log("Reached full power, wating a bit more until success");
2103 T.start;
2104 }
2105
2106 last_rx_lvl := rx_lvl;
2107 repeat;
2108 }
2109 [] L1CTL.receive { repeat; }
2110 [] T.timeout { }
2111 }
2112
2113 /* We didn't increase tx power during ramp up */
2114 if (initial_rx_lvl < last_rx_lvl) {
2115 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2116 } else {
2117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2118 log2str("No Tx power increase during whole ramp up: ",
2119 initial_rx_lvl , " -> ", last_rx_lvl));
2120 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002121}
2122
2123/* verify BTS ramps power down to rx_level 0 */
2124private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2125 var L1ctlDlMessage l1_dl;
2126 var integer last_rx_lvl := max_rx_lvl;
2127
2128 timer Tdown := 5.0;
2129 Tdown.start;
2130 alt {
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2132 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2133 log("Received rx_level=", rx_lvl);
2134
2135 /* received Rx level bigger than maximum allowed power by CN */
2136 if (rx_lvl > max_rx_lvl) {
2137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2138 log2str("Detected Tx power higher than full power: ",
2139 rx_lvl , " > ", max_rx_lvl));
2140 }
2141
2142 /* Make sure it never increases, since we are rumping down */
2143 if (last_rx_lvl < rx_lvl) {
2144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2145 log2str("Detected Tx power increase during ramp up: ",
2146 last_rx_lvl , " -> ", rx_lvl));
2147 }
2148
2149 last_rx_lvl := rx_lvl;
2150 if (last_rx_lvl != 0) {
2151 repeat;
2152 }
2153 /* we reached power level 0, we are done */
2154 Tdown.stop;
2155 }
2156 [] L1CTL.receive { repeat; }
2157 [] Tdown.timeout { }
2158 }
2159
2160 /* We didn't increase tx power during ramp down */
2161 if (max_rx_lvl > last_rx_lvl) {
2162 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2163 } else {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 log2str("No Tx power decrease during whole ramp down: ",
2166 max_rx_lvl , " -> ", last_rx_lvl));
2167 }
2168}
2169
2170/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002171private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002172 f_l1_tune(L1CTL);
2173 RSL.clear;
2174
2175 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002176
2177 setverdict(pass);
2178}
2179testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2180 var ConnHdlr vc_conn;
2181 var ConnHdlrPars pars;
2182 f_init();
2183 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2184 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2185 pcu_comp := false, trxc_comp := true);
2186 vc_conn.done;
2187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2188}
2189
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002190/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002191private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002192 f_connhdlr_init_vty_bsc();
2193
2194 f_l1_tune(L1CTL);
2195 RSL.clear;
2196
2197 /* Wait until BTS is started and at full power */
2198 var integer max_rx_lvl := f_wait_ramp_up();
2199 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2200
2201 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2202 f_verify_ramp_down(max_rx_lvl);
2203
2204 setverdict(pass);
2205}
2206testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2207 var ConnHdlr vc_conn;
2208 var ConnHdlrPars pars;
2209 f_init();
2210 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2211 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2212 pcu_comp := false, trxc_comp := true);
2213 vc_conn.done;
2214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2215}
2216
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002217/* Verify Tx power:
2218 * + ramping down during ADM state UNLOCKED->LOCKED
2219 * + ramping up during ADM state LOCKED->UNLOCKED
2220 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002221private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002222 var L1ctlDlMessage l1_dl;
2223 var integer last_rx_lvl;
2224
2225 f_connhdlr_init_vty_bsc();
2226
2227 f_l1_tune(L1CTL);
2228 RSL.clear;
2229
2230 /* Wait until BTS is started and at full power */
2231 var integer max_rx_lvl := f_wait_ramp_up();
2232 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2233
2234 log("ADM STATE UNLOCKED->LOCKED");
2235 f_vty_enter_cfg_trx(BSCVTY);
2236 f_vty_transceive(BSCVTY, "rf_locked 1");
2237 last_rx_lvl := max_rx_lvl;
2238 f_verify_ramp_down(max_rx_lvl);
2239
2240 /* Let some time after we received 0dBm, then check we don't receive BCCH
2241 * anymore because scheduler has stopped after ramping down */
2242 f_sleep(2.0);
2243 L1CTL.clear;
2244 timer Tlocked := 2.0;
2245 Tlocked.start;
2246 alt {
2247 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2249 log2str("Received data_ind during rf_locked: ", l1_dl));
2250 }
2251 [] L1CTL.receive { repeat; }
2252 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2253 }
2254
2255 log("ADM STATE LOCKED->UNLOCKED");
2256 f_vty_transceive(BSCVTY, "rf_locked 0");
2257 f_verify_ramp_up();
2258 setverdict(pass);
2259}
2260testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2261 var ConnHdlr vc_conn;
2262 var ConnHdlrPars pars;
2263 f_init();
2264 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2265 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2266 pcu_comp := false, trxc_comp := true);
2267 vc_conn.done;
2268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2269}
2270
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002271private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002272 timer T := 8.0;
2273 T.start;
2274 var RSL_Message rsl;
2275 alt {
2276 [] as_l1_sacch();
2277 [] L1CTL.receive { repeat; }
2278 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2279 if (rsl.ies[3].body.bs_power.power_level == level) {
2280 setverdict(pass)
2281 } else {
2282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2283 }
2284 }
2285 [] T.timeout {
2286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2287 }
2288 }
2289}
2290
2291/* see if the rsl meas res contains our expeced bs power level
2292bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002293private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002294 f_l1_tune(L1CTL);
2295 RSL.clear;
2296
2297 if (mp_bts_trxc_port != -1) {
2298 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2299 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2300 }
2301
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002302 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002303 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2304 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2305
2306 f_est_dchan(more_ies :={valueof(pwr)});
2307
2308 f_check_meas_bs_power_level(pwr_var);
2309
2310 f_rsl_chan_deact();
2311 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2312}
2313
2314/* see if the rsl meas res contains our expeced bs power level
2315bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002316private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002317 f_l1_tune(L1CTL);
2318 RSL.clear;
2319
2320 if (mp_bts_trxc_port != -1) {
2321 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2322 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2323 }
2324
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002325 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002326 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2327
2328 f_est_dchan();
2329
2330 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2331
2332 f_check_meas_bs_power_level(pwr_var);
2333
2334 f_rsl_chan_deact();
2335 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2336}
2337
2338testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2339 var ConnHdlr vc_conn;
2340 var ConnHdlrPars pars;
2341 f_init();
2342 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2343 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2344 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2345 pcu_comp := false, trxc_comp := true);
2346 vc_conn.done;
2347 }
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2349}
2350
2351testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2352 var ConnHdlr vc_conn;
2353 var ConnHdlrPars pars;
2354 f_init();
2355 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2356 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2357 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2358 pcu_comp := false, trxc_comp := true);
2359 vc_conn.done;
2360 }
2361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2362}
2363
Eric Wild61edb7e2019-06-03 12:38:31 +02002364/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2365second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2366These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002367private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002368 var uint5_t pwr_var := 7;
2369 var L1ctlDlMessage l1_dl;
2370
2371 f_trxc_fake_rssi(rxlev2dbm(10));
2372 f_l1_tune(L1CTL);
2373 RSL.clear;
2374
2375 var RSL_IE_List addl_ies;
2376 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2377
2378 addl_ies := {
2379 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2380 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2381 };
2382
2383 /* establish with power parameters */
2384 f_est_dchan(more_ies := addl_ies);
2385
2386 /* set a high value to ensure L1 power control level increases */
2387 f_trxc_fake_rssi(rxlev2dbm(20));
2388
2389 timer T2 := 6.0;
2390 T2.start;
2391 alt {
2392 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002393 /* Update sent MS power to follow what BTS requests */
2394 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2395 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002396 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002397 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002398 T2.stop;
2399 }
2400 [] L1CTL.receive { repeat; }
2401 [] T2.timeout {
2402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2403 "Power Level in L1 header has not increased sufficiently");
2404 }
2405 }
2406
2407 /* set a low value to ensure L1 power control level decreases */
2408 f_trxc_fake_rssi(rxlev2dbm(0));
2409
2410 timer T4 := 6.0;
2411 T4.start;
2412 alt {
2413 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002414 /* Update sent MS power to follow what BTS requests */
2415 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2416 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002417 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002418 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002419 T4.stop;
2420 setverdict(pass, "Power level in L1 decreased/increased as expected");
2421 }
2422 [] L1CTL.receive { repeat; }
2423 [] T4.timeout {
2424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2425 "Power Level in L1 header has not decreased sufficiently");
2426 }
2427 }
2428
2429 f_rsl_chan_deact();
2430 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2431
2432}
2433
2434/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002435private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002436 var uint5_t pwr_var := 7;
2437 var L1ctlDlMessage l1_dl;
2438
2439 /* set a low value to ensure power increases */
2440 f_trxc_fake_rssi(rxlev2dbm(10));
2441 f_l1_tune(L1CTL);
2442 RSL.clear;
2443
2444 var RSL_IE_List addl_ies;
2445 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2446
2447 addl_ies := {
2448 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2449 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2450 };
2451
2452 /* establish with power parameters */
2453 f_est_dchan(more_ies := addl_ies);
2454
2455 timer T1 := 10.0;
2456 T1.start;
2457 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002458 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2459 /* Update sent MS power to follow what BTS requests */
2460 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2461 repeat;
2462 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002463 [] L1CTL.receive { repeat; }
2464 [] T1.timeout {
2465 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2466 setverdict(fail, "Power level in L1 header should not have changed");
2467 }
2468 }
2469 }
2470
2471 f_rsl_chan_deact();
2472 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2473
2474}
2475
2476/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002477private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002478 var L1ctlDlMessage l1_dl;
2479 var uint5_t pwr_var := 15;
2480 var uint5_t pwr_max_var := f_get_max_power_from_band();
2481
2482 /* set a low value to ensure power increases */
2483 f_trxc_fake_rssi(rxlev2dbm(10));
2484 f_l1_tune(L1CTL);
2485 RSL.clear;
2486
2487 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2488 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2489
2490 /* establish with fixed power level */
2491 f_est_dchan(more_ies :={valueof(pwr)});
2492
2493 /* check our initial power level */
2494 f_wait_for_l1_power_level(pwr_var);
2495
2496 /* update power param to enable power loop
2497 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2498 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2499
2500 /* wait, then check that our power level was reduced */
2501 timer T1 := 10.0;
2502 T1.start;
2503 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002504 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2505 /* Update sent MS power to follow what BTS requests */
2506 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2507 repeat;
2508 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002509 [] L1CTL.receive { repeat; }
2510 [] T1.timeout {
2511 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2512 if( f_power_level_is_highest_dbm(rcv) ){
2513 setverdict(pass, "Power level in L1 header reduced as expected");
2514 } else {
2515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2516 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2517 }
2518 }
2519 }
2520
2521 f_rsl_chan_deact();
2522 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2523
2524}
2525
2526/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002527private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002528 var L1ctlDlMessage l1_dl;
2529
2530 /* set a high value to ensure power decreases */
2531 f_trxc_fake_rssi(rxlev2dbm(50));
2532 f_l1_tune(L1CTL);
2533 RSL.clear;
2534
2535 var uint5_t pwr_var := 5;
2536 var uint5_t pwr_target_val := 15;
2537
2538 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2539 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2540
2541 /* establish with fixed power level */
2542 f_est_dchan(more_ies :={valueof(pwr)});
2543
2544 /* check our initial power level */
2545 f_wait_for_l1_power_level(pwr_var);
2546
2547 /* update power param to enable power loop
2548 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002549 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002550
2551 /* wait, then check that our power level was increased */
2552 timer T1 := 10.0;
2553 T1.start;
2554 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002555 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2556 /* Update sent MS power to follow what BTS requests */
2557 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2558 repeat;
2559 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002560 [] L1CTL.receive { repeat; }
2561 [] T1.timeout {
2562 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2563 setverdict(pass, "Power level in L1 header increased to lowest power value");
2564 } else {
2565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2566 "Power level in L1 header NOT increased to lowest power value");
2567 }
2568 }
2569 }
2570
2571 f_rsl_chan_deact();
2572 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2573
2574}
2575
Eric Wild095024b2019-06-17 15:08:57 +02002576/* see if we change the power level without receiving power parameters, which should not happen
2577rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002578private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002579 var L1ctlDlMessage l1_dl;
2580
2581 /* set a high value to ensure power decreases */
2582 f_trxc_fake_rssi(rxlev2dbm(50));
2583 f_l1_tune(L1CTL);
2584 RSL.clear;
2585
2586 var uint5_t pwr_var := 5;
2587
2588 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2589 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2590
2591 /* establish with fixed power level */
2592 f_est_dchan(more_ies :={valueof(pwr)});
2593
2594 /* check our initial power level */
2595 f_wait_for_l1_power_level(pwr_var);
2596
2597 /* wait, then check that our power level did not change */
2598 timer T1 := 10.0;
2599 T1.start;
2600 alt {
2601 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2602 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2604 "BS power control should not be active unless we receive a power parameters IE!");
2605 }
2606 repeat;
2607 }
2608 [] L1CTL.receive { repeat; }
2609 [] T1.timeout { setverdict(pass); }
2610 }
2611
2612 f_rsl_chan_deact();
2613 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2614
2615}
2616
Eric Wild095024b2019-06-17 15:08:57 +02002617/* see if we change the power level without receiving power parameters, which should not happen
2618ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002619private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002620 var L1ctlDlMessage l1_dl;
2621
2622 /* set a high value to ensure power decreases */
2623 f_trxc_fake_rssi(rxlev2dbm(50));
2624 f_l1_tune(L1CTL);
2625 RSL.clear;
2626
2627 var uint5_t pwr_var := 5;
2628
2629 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2630 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2631
2632 /* establish with fixed power level */
2633 f_est_dchan(more_ies :={valueof(pwr)});
2634
2635 /* check our initial power level */
2636 f_wait_for_l1_power_level(pwr_var);
2637
2638 /* pwr control without power params IE, should NOT activate MS power control*/
2639 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2640
2641 /* wait, then check that our power level did not change */
2642 timer T1 := 10.0;
2643 T1.start;
2644 alt {
2645 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2646 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2648 "BS power control should not be active unless we receive a power parameters IE!");
2649 }
2650 repeat;
2651 }
2652 [] L1CTL.receive { repeat; }
2653 [] T1.timeout { setverdict(pass); }
2654 }
2655
2656 f_rsl_chan_deact();
2657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2658
2659}
2660
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002661private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002662 var L1ctlDlMessage l1_dl;
2663 timer T0 := 10.0;
2664 T0.start;
2665 alt {
2666 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2667 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2669 "Power level in L1 header != signaled (RSL) power level.");
2670 }
2671 }
2672 [] L1CTL.receive { repeat; }
2673 [] T0.timeout {
2674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2675 "Timeout waiting for initial power level");
2676 }
2677 }
2678 T0.stop;
2679}
2680
2681private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2682 var IntegerRecord min_dbm_level;
2683 var IntegerRecord max_dbm_level;
2684 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2685
2686 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2687 if (min_dbm_level[i] == level) {
2688 return true;
2689 }
2690 }
2691 return false;
2692}
2693
2694private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2695 var IntegerRecord min_dbm_level;
2696 var IntegerRecord max_dbm_level;
2697 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2698
2699 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2700 if (max_dbm_level[i] == level) {
2701 return true;
2702 }
2703 }
2704 return false;
2705}
2706
2707private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2708 var IntegerRecord min_dbm_level;
2709 var IntegerRecord max_dbm_level;
2710 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2711 return max_dbm_level[0];
2712}
2713
2714type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002715private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002716private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2717 // 45.005 4.1.1
2718 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2719 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2720 2, 1, 0};
2721 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2722 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2723 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2724 var IntegerRecord rv;
2725
2726 select(band){
2727 case (BtsBand_allGSM){
2728 rv := gsm_power;
2729 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2730 max_dbm_level := {2, 1, 0};
2731 }
2732 case("DCS1800"){
2733 rv := dcs_power;
2734 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2735 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2736 }
2737 case("PCS1900"){
2738 rv := pcs_power;
2739 min_dbm_level := {15};
2740 max_dbm_level := {30};
2741 }
2742 }
2743
2744 return rv;
2745}
2746
2747private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2748 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2749}
2750
2751testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2752 var ConnHdlr vc_conn;
2753 var ConnHdlrPars pars;
2754 f_init();
2755 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2756 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2757 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2758 pars.bts0_band := f_vty_get_bts0_band();
2759 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2760 vc_conn.done;
2761 }
2762 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2764}
2765
2766testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2767 var ConnHdlr vc_conn;
2768 var ConnHdlrPars pars;
2769 f_init();
2770 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2771 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2772 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2773 pars.bts0_band := f_vty_get_bts0_band();
2774 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2775 vc_conn.done;
2776 }
2777 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2779}
2780
2781testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2782 var ConnHdlr vc_conn;
2783 var ConnHdlrPars pars;
2784 f_init();
2785 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2786 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2787 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2788 pars.bts0_band := f_vty_get_bts0_band();
2789 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2790 vc_conn.done;
2791 }
2792 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2794}
2795
2796testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2797 var ConnHdlr vc_conn;
2798 var ConnHdlrPars pars;
2799 f_init();
2800 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2801 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2802 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2803 pars.bts0_band := f_vty_get_bts0_band();
2804 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2805 vc_conn.done;
2806 }
2807 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2809}
2810
Eric Wild280ccb82019-06-17 11:11:52 +02002811testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2812 var ConnHdlr vc_conn;
2813 var ConnHdlrPars pars;
2814 f_init();
2815 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2816 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2817 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2818 pars.bts0_band := f_vty_get_bts0_band();
2819 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2820 vc_conn.done;
2821 }
2822 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2824}
2825
Eric Wild095024b2019-06-17 15:08:57 +02002826testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2827 var ConnHdlr vc_conn;
2828 var ConnHdlrPars pars;
2829 f_init();
2830 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2831 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2832 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2833 pars.bts0_band := f_vty_get_bts0_band();
2834 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2835 vc_conn.done;
2836 }
2837 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2839}
2840
Harald Welte70767382018-02-21 12:16:40 +01002841testcase TC_meas_res_sign_tchf() runs on test_CT {
2842 var ConnHdlr vc_conn;
2843 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002844 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002845 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2846 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002847 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2848 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002849 vc_conn.done;
2850 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002852}
2853testcase TC_meas_res_sign_tchh() runs on test_CT {
2854 var ConnHdlr vc_conn;
2855 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002856 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002857 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2858 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002859 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2860 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002861 vc_conn.done;
2862 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002864}
2865testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2866 var ConnHdlr vc_conn;
2867 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002868 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002869 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2870 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002871 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2872 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002873 vc_conn.done;
2874 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002876}
2877testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2878 var ConnHdlr vc_conn;
2879 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002880 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002881 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2882 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002883 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2884 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002885 vc_conn.done;
2886 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002888}
Harald Welte685d5982018-02-27 20:42:05 +01002889testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2890 var ConnHdlr vc_conn;
2891 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002892 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002893 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2894 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2895 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2896 pars.l1_pars.toa256_enabled := true;
2897 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2898 vc_conn.done;
2899 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002901}
2902
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002903/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2904 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002905private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002906 var L1ctlDlMessage l1_dl;
2907 var RSL_IE_MS_Power ms_power;
2908 var RSL_Message rsl;
2909 var uint5_t power_level := 0;
2910
2911 f_l1_tune(L1CTL);
2912 RSL.clear;
2913
2914 f_est_dchan();
2915
2916 ms_power.reserved := 0;
2917 ms_power.fpc_epc := false;
2918
2919 /* Send the first power control command. This will disable any BTS/TRX
2920 * internal power control and switch the MS (which is not in scope of
2921 * this test) to a constant power level. We start with a power level
2922 * of 0 */
2923 ms_power.power_level := power_level;
2924 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2925 RSL.send(rsl);
2926
2927 alt {
2928
2929 /* Pick all SACCH blocks for checking */
2930 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2931
2932 /* The first byte of the L1 header contains the power level.
2933 * The reserved bits and the fpc bit is set to 0, so we may
2934 * compare directly. */
2935 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2936 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2937 }
2938
2939 /* Signal a new power level via RSL for the next turn. */
2940 if (power_level < 31) {
2941 power_level := power_level + 1;
2942 ms_power.power_level := power_level;
2943 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2944 RSL.send(rsl);
2945 repeat;
2946 }
2947
2948 }
2949
2950 /* Ignore all other blocks */
2951 [] L1CTL.receive { repeat; }
2952
2953 }
2954
2955 f_rsl_chan_deact();
2956 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2957
2958 setverdict(pass);
2959}
2960
2961testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2962 var ConnHdlr vc_conn;
2963 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002964 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002965
2966 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2967 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2968 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2969 vc_conn.done;
2970 }
2971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2972}
Harald Welte70767382018-02-21 12:16:40 +01002973
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02002974/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02002975TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002976private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02002977 var L1ctlDlMessage l1_dl;
2978 var uint5_t ta_to_test := 16;
2979
2980
2981 f_l1_tune(L1CTL);
2982 RSL.clear;
2983
2984 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002985 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02002986
2987 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2988
2989
2990 alt {
2991
2992 /* Pick all SACCH blocks for checking */
2993 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2994
2995 /* The second byte of the L1 header contains the TA. */
2996 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2997 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2998 }
2999
3000 }
3001
3002 /* Ignore all other blocks */
3003 [] L1CTL.receive { repeat; }
3004
3005 }
3006
3007 f_rsl_chan_deact();
3008 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3009
3010 setverdict(pass);
3011}
3012
3013testcase TC_rsl_chan_initial_ta() runs on test_CT {
3014 var ConnHdlr vc_conn;
3015 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003016 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003017 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003018 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3019 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003020 vc_conn.done;
3021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3022}
3023
Eric Wilde57e1a62019-05-28 13:30:55 +02003024/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003025private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003026 var L1ctlDlMessage l1_dl;
3027 var uint5_t ms_power_level := 7;
3028
3029 var RSL_IE_MS_Power ms_power;
3030 ms_power.reserved := 0;
3031 ms_power.fpc_epc := false;
3032 ms_power.power_level := ms_power_level;
3033
3034 f_l1_tune(L1CTL);
3035 RSL.clear;
3036
3037 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3038
3039 timer T := 1.0;
3040 T.start;
3041 alt {
3042 /* Pick all SACCH blocks for checking */
3043 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3044 /* The first byte of the L1 header contains the power level.. */
3045 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3046 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3047 }
3048 }
3049 /* Ignore all other blocks */
3050 [] L1CTL.receive { repeat; }
3051 [] T.timeout {
3052 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3053 }
3054 }
3055
3056 f_rsl_chan_deact();
3057 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3058 setverdict(pass);
3059}
3060
3061testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3062 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3063 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3064}
3065
Harald Welte0472ab42018-03-12 15:02:26 +01003066/* 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 +01003067private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003068 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003069 RSL.clear;
3070
3071 f_est_dchan();
3072 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003073 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003074
3075 timer T := 40.0;
3076 T.start;
3077 alt {
3078 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3079 setverdict(pass)
3080 }
3081 [] RSL.receive { repeat };
3082 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003084 }
3085 }
3086 f_rsl_chan_deact();
3087}
3088testcase TC_conn_fail_crit() runs on test_CT {
3089 var ConnHdlr vc_conn;
3090 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003091 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003092 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3093 pars.t_guard := 60.0;
3094 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3095 vc_conn.done;
3096}
3097
Harald Welte93640c62018-02-25 16:59:33 +01003098/***********************************************************************
3099 * Paging
3100 ***********************************************************************/
3101
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003102private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003103 if (tmsi == 'FFFFFFFF'O) {
3104 return true;
3105 } else {
3106 return false;
3107 }
3108}
Harald Welte70767382018-02-21 12:16:40 +01003109
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003110private type record allowedFn { integer frame_nr }
3111private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3112private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3113private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3114private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3115private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3116private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3117private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3118private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3119private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003120{
3121 var integer frame_nr_51;
3122 frame_nr_51 := frame_nr mod 51
3123
3124 var allowedFn fn_check;
3125 fn_check.frame_nr := frame_nr_51;
3126
3127 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003129 return;
3130 }
3131
3132 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3133 return;
3134 }
3135 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3136 return;
3137 }
3138 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3139 return;
3140 }
3141 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3142 return;
3143 }
3144 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3145 return;
3146 }
3147 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3148 return;
3149 }
3150 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3151 return;
3152 }
3153 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3154 return;
3155 }
3156
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003158 return;
3159}
3160
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003161private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3162 inout integer num_paging_rcv_ids,
3163 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003164runs on test_CT {
3165 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003166 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003167 repeat;
3168 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003169 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003170 var octetstring without_plen :=
3171 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3172 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003173
3174 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3175
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003176 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3177 /* Ignore empty RR Paging Request (PCH filling) messages.
3178 * TODO: does it make sense to count them? */
3179 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003180 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3181 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003182 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003183 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3184 }
3185 } else if (match(rr, tr_PAGING_REQ2)) {
3186 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3187 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3188 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3189 }
3190 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3191 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3192 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003193 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003194 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3195 }
3196 } else if (match(rr, tr_PAGING_REQ3)) {
3197 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3198 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3199 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3200 }
3201 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3202 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3203 }
3204 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3205 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3206 }
3207 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3208 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3209 }
3210 }
3211 repeat;
3212 }
3213}
3214
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003215private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003216 boolean combined_ccch,
3217 integer bs_ag_blks_res,
3218 float load_factor,
3219 boolean exp_load_ind,
3220 boolean exp_overload,
3221 boolean use_tmsi
3222}
3223
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003224private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003225 integer num_paging_sent,
3226 integer num_paging_rcv_msgs,
3227 integer num_paging_rcv_ids,
3228 integer num_overload
3229}
3230
Harald Welte68e495b2018-02-25 00:05:57 +01003231/* Helper function for paging related testing */
3232private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003233 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003234 f_init_l1ctl();
3235 f_l1_tune(L1CTL);
3236
3237 var PagingTestState st := {
3238 num_paging_sent := 0,
3239 num_paging_rcv_msgs := 0,
3240 num_paging_rcv_ids := 0,
3241 num_overload := 0
3242 };
3243
3244 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3245 var float max_pch_imsi_per_sec;
3246 if (cfg.use_tmsi) {
3247 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3248 } else {
3249 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3250 }
3251 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3252 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003253 var float time_total := 20.0;
3254 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3255 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003256
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003257 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3258 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003259
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003260 timer T_itv := 0.0;
3261 T_itv.start;
3262 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003263 alt {
3264 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003265 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003266 st.num_overload := st.num_overload + 1;
3267 repeat;
3268 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003269 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003271 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003272 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003273 log("Rx LOAD_IND");
3274 /* FIXME: analyze/verify interval + contents */
3275 repeat;
3276 }
3277 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003278 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003279 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003280 [] T_itv.timeout {
3281 /* Send paging cmds based on elapsed time */
3282 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3283 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003284 var MobileIdentityV mi;
3285
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003286 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003287 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003288 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003289 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003290 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003291 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003292
3293 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003294 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 +02003295
3296 st.num_paging_sent := st.num_paging_sent + 1;
3297 }
3298 if (st.num_paging_sent < pkt_total) {
3299 /* Wait for interval to next PAGING COMMAND */
3300 var float time_now := T_total.read;
3301 var float next_sched := int2float(st.num_paging_sent)*interval;
3302 if (next_sched > time_now) {
3303 T_itv.start(next_sched - time_now);
3304 } else {
3305 T_itv.start(0.0);
3306 }
3307 } else {
3308 /* We are done, no need to keep counting */
3309 T_total.stop;
3310 }
3311 }
3312 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003313 }
3314 }
3315
3316 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3317 timer T_wait := 18.0;
3318 T_wait.start;
3319 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003320 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003321 [] L1CTL.receive { repeat; }
3322 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003323 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3324 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003325 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003327 }
Harald Welte68e495b2018-02-25 00:05:57 +01003328 }
3329
3330 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3331 " rcvd_ids=", st.num_paging_rcv_ids);
3332 return st;
3333}
3334
3335/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3336 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3337 * - that CCCH LOAD IND (PCH) are being generated
3338 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3339testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003340 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003341 var PagingTestCfg cfg := {
3342 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003343 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003344 load_factor := 0.8,
3345 exp_load_ind := true,
3346 exp_overload := false,
3347 use_tmsi := false
3348 };
3349 var PagingTestState st := f_TC_paging(cfg);
3350 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3352 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003353 } else {
3354 setverdict(pass);
3355 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003357}
3358
3359/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3360 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3361 * - that CCCH LOAD IND (PCH) are being generated
3362 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3363testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003364 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003365 var PagingTestCfg cfg := {
3366 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003367 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003368 load_factor := 0.8,
3369 exp_load_ind := true,
3370 exp_overload := false,
3371 use_tmsi := true
3372 };
3373 var PagingTestState st := f_TC_paging(cfg);
3374 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3376 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003377 } else {
3378 setverdict(pass);
3379 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003381}
3382
3383/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3384 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3385 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3386 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3387testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003388 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003389 var PagingTestCfg cfg := {
3390 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003391 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003392 load_factor := 2.0,
3393 exp_load_ind := true,
3394 exp_overload := true,
3395 use_tmsi := false
3396 };
3397 var PagingTestState st := f_TC_paging(cfg);
3398 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3399 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003400 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003401 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003402 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 +01003403 } else {
3404 setverdict(pass);
3405 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003407}
3408
3409/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3410 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3411 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3412 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3413testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003414 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003415 var PagingTestCfg cfg := {
3416 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003417 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003418 load_factor := 2.0,
3419 exp_load_ind := true,
3420 exp_overload := true,
3421 use_tmsi := true
3422 };
3423 var PagingTestState st := f_TC_paging(cfg);
3424 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3425 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003426 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003427 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003428 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 +01003429 } else {
3430 setverdict(pass);
3431 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003433}
3434
3435
Harald Welte93640c62018-02-25 16:59:33 +01003436/***********************************************************************
3437 * Immediate Assignment / AGCH
3438 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003439private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003440 len := 0,
3441 ma := ''B
3442}
Harald Welte93640c62018-02-25 16:59:33 +01003443
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003444private template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr,
3445 template (value) uint3_t tsc := 7,
3446 template (value) uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003447 chan_nr := chan_nr,
3448 tsc := tsc,
3449 h := false,
3450 arfcn := arfcn,
3451 maio_hsn := omit
3452}
3453
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003454private template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr,
3455 template (value) uint3_t tsc := 7,
3456 template (value) MaioHsn maio_hsn) := {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003457 chan_nr := chan_nr,
3458 tsc := tsc,
3459 h := true,
3460 arfcn := omit,
3461 maio_hsn := maio_hsn
3462}
3463
Harald Weltee8d750e2018-06-10 21:41:35 +02003464private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3465 return int2str(num_tx) & " sent, "
3466 & int2str(num_rx) & " received, "
3467 & int2str(num_del) & " deleted";
3468}
3469
3470private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3471 var L1ctlDlMessage l1_dl;
3472 timer T := 10.0;
3473 var integer num_tx := 0;
3474 var integer num_rx := 0;
3475 var integer num_del := 0;
3476 var charstring res_str;
3477 var float rx_ratio;
3478
Harald Welte10474062019-05-30 16:48:17 +02003479 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003480 f_init_l1ctl();
3481 f_l1_tune(L1CTL);
3482
3483 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003484 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003485 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3486 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003487 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003488 num_tx := num_tx+1;
3489 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003490 }
3491 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003492 T.start;
3493 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003494 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003495 num_del := num_del+1;
3496 repeat;
3497 }
3498 [] RSL_CCHAN.receive {
3499 repeat;
3500 }
3501 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
3502 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3503 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3504 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3505 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003506 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003507 } else {
3508 num_rx := num_rx+1;
3509 }
3510 repeat;
3511 }
3512 [] L1CTL.receive { repeat; }
3513 [] T.timeout { }
3514 }
3515 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3516 log("AGCH test: " & res_str);
3517 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003519 }
3520 rx_ratio := int2float(num_rx) / int2float(num_tx);
3521 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003522 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 +02003523 } else {
3524 setverdict(pass);
3525 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003527}
3528
Harald Weltee8d750e2018-06-10 21:41:35 +02003529/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3530testcase TC_imm_ass_1000_20ms() runs on test_CT {
3531 f_TC_imm_ass(1000, 0.02, 0.25);
3532}
3533
3534/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3535testcase TC_imm_ass_200_0ms() runs on test_CT {
3536 f_TC_imm_ass(200, 0.0, 0.05);
3537}
3538
3539/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3540testcase TC_imm_ass_200_76ms() runs on test_CT {
3541 f_TC_imm_ass(150, 0.076, 1.00);
3542}
3543
3544
3545
Harald Welte48494ca2018-02-25 16:59:50 +01003546/***********************************************************************
3547 * BCCH
3548 ***********************************************************************/
3549
3550/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003551private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003552 GsmFrameNumber frame_number,
3553 SystemInformation si
3554}
3555
3556/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003557private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003558
3559/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003560private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003561
3562/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003563private function f_si_vecslot_contains(SystemInformationVector arr,
3564 RrMessageType key,
3565 boolean bcch_ext := false)
3566return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003567 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3568 var integer fn_mod51 := arr[i].frame_number mod 51;
3569 if (not bcch_ext and fn_mod51 == 2 or
3570 bcch_ext and fn_mod51 == 6) {
3571 if (arr[i].si.header.message_type == key) {
3572 return true;
3573 }
3574 }
3575 }
3576 return false;
3577}
3578
3579/* 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 +07003580private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3581 integer tc, RrMessageType key,
3582 boolean ext_bcch := false)
3583{
Harald Welte48494ca2018-02-25 16:59:50 +01003584 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003586 }
3587}
3588
3589/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003590private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3591 RrMessageType key)
3592return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003593 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3594 if (f_si_vecslot_contains(arr[tc], key) or
3595 f_si_vecslot_contains(arr[tc], key, true)) {
3596 return true;
3597 }
3598 }
3599 return false;
3600}
3601
3602/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003603private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3604 RrMessageType key,
3605 boolean bcch_ext := false,
3606 integer n := 1, integer m := 4)
3607return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003608 var integer count := 0;
3609 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003611 }
3612 for (var integer i:= 0; i < m; i := i + 1) {
3613 var integer fn_mod51 := arr[i].frame_number mod 51;
3614 if (not bcch_ext and fn_mod51 == 2 or
3615 bcch_ext and fn_mod51 == 6) {
3616 if (arr[i].si.header.message_type == key) {
3617 count := count + 1;
3618 }
3619 }
3620 }
3621 if (count >= n) {
3622 return true;
3623 } else {
3624 return false;
3625 }
3626}
3627
3628/* 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 +07003629private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3630 integer tc, RrMessageType key,
3631 boolean ext_bcch := false,
3632 integer n, integer m)
3633{
Harald Welte48494ca2018-02-25 16:59:50 +01003634 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003636 }
3637}
3638
3639/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003640private function f_si_vecslot_contains_only(SystemInformationVector arr,
3641 RrMessageType key,
3642 boolean bcch_ext := false)
3643return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003644 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3645 var integer fn_mod51 := arr[i].frame_number mod 51;
3646 if (not bcch_ext and fn_mod51 == 2 or
3647 bcch_ext and fn_mod51 == 6) {
3648 if (arr[i].si.header.message_type != key) {
3649 return false;
3650 }
3651 }
3652 }
3653 return true;
3654}
3655
3656/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003657private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3658 integer tc, RrMessageType key,
3659 boolean ext_bcch := false)
3660{
Harald Welte48494ca2018-02-25 16:59:50 +01003661 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003663 }
3664}
3665
3666/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003667private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003668 boolean bcch_extended,
3669 boolean si1_present,
3670 boolean si2bis_present,
3671 boolean si2ter_present,
3672 boolean si2quater_present,
3673 boolean si7_present,
3674 boolean si8_present,
3675 boolean si9_present,
3676 boolean si13_present,
3677 boolean si13alt_present,
3678 boolean si15_present,
3679 boolean si16_present,
3680 boolean si17_present,
3681 boolean si2n_present,
3682 boolean si21_present,
3683 boolean si22_present
3684}
3685
3686/* 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 +07003687private function f_validate_si_scheduling(SystemInformationConfig cfg,
3688 SystemInformationVectorPerTc si_per_tc)
3689{
Harald Welte48494ca2018-02-25 16:59:50 +01003690 var integer i;
3691 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3692 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003694 }
3695 }
3696 if (cfg.si1_present) {
3697 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3698 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3699 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3700 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3701 /* make sure *ALL* contain SI1 */
3702 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3703 }
3704 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3705 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3706 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3707 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3708 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3709 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3710
3711 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3712 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3713 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3714 * consecutive occurrences of TC = 4. */
3715 if (cfg.si2bis_present and not cfg.si2ter_present) {
3716 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3717 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3718 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3719 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3720 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3721 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3722 }
3723
3724 if (cfg.si7_present or cfg.si8_present) {
3725 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3726 * if System Information type 4 does not contain all information needed for cell
3727 * selection and reselection. */
3728 if (not cfg.bcch_extended) {
3729 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3730 }
3731 if (cfg.si7_present) {
3732 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3733 }
3734 if (cfg.si8_present) {
3735 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3736 }
3737 }
3738
3739 if (cfg.si2quater_present) {
3740 /* iii) System information type 2 quater is sent if needed, as determined by the system
3741 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3742 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3743 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3744 * within any of 4 consecutive occurrences of TC = 5. */
3745 if (not (cfg.bcch_extended)) {
3746 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3747 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3748 } else {
3749 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3750 }
3751 } else {
3752 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3753 }
3754 }
3755 if (cfg.si9_present) {
3756 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3757 * in system information type 3 as defined in 3GPP TS 44.018. */
3758 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3759 }
3760 if (cfg.si13_present) {
3761 /* vii) System Information type 13 is only related to the GPRS service. System Information
3762 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3763 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3764 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3765 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3766 * within any of 4 consecutive occurrences of TC=4. */
3767 if (not cfg.bcch_extended) {
3768 log("not-bccch-extended");
3769 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3770 } else {
3771 log("bccch-extended");
3772 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3773 }
3774 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003776 }
3777 }
3778 if (cfg.si16_present or cfg.si17_present) {
3779 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3780 * should not be sent in a cell where network sharing is used (see rule xv). */
3781 if (cfg.si22_present) {
3782 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3783 }
3784 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003786 }
3787 if (not cfg.bcch_extended) {
3788 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3789 }
3790 if (cfg.si16_present) {
3791 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3792 }
3793 if (cfg.si17_present) {
3794 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3795 }
3796 }
3797
3798 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3799 * broadcast information. The frequency with which they are sent is determined by the
3800 * system operator. System Information type 9 identifies the scheduling of System
3801 * Information type 18 and 20 messages. */
3802
3803 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3804 * Information Type 19 is present, then its scheduling shall be indicated in System
3805 * Information Type 9. */
3806
3807 if (cfg.si15_present) {
3808 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3809 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3810 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3811 * 4 consecutive occurrences of TC = 1. */
3812 if (not cfg.bcch_extended) {
3813 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3814 } else {
3815 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3816 }
3817 }
3818 if (cfg.si13alt_present) {
3819 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3820 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3821 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3822 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3823 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3824 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3825 * of TC = 4. */
3826 if (cfg.si13_present) {
3827 testcase.stop("Error: Cannot have SI13alt and SI13");
3828 }
3829 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003831 }
3832 if (not cfg.bcch_extended) {
3833 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3834 } else {
3835 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3836 }
3837 }
3838 if (cfg.si2n_present) {
3839 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3840 * as determined by the system operator. In the case that the message is sent on the
3841 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3842 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3843 * consecutive occurrences of TC = 4. */
3844 if (not cfg.bcch_extended) {
3845 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3846 } else {
3847 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3848 }
3849 }
3850 if (cfg.si21_present) {
3851 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3852 * determined by the system operator. If Extended Access Barring is in use in the cell
3853 * then this message is sent at least once within any of 4 consecutive occurrences of
3854 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3855 * cell then this message shall only be sent on BCCH Ext. */
3856 if (not cfg.bcch_extended) {
3857 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3858 } else {
3859 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3860 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003862 }
3863 }
3864 }
3865 if (cfg.si22_present) {
3866 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3867 * should not be sent in a cell where SoLSA is used (see rule viii). System
3868 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3869 * =2 and TC=6. */
3870 if (cfg.si16_present or cfg.si17_present) {
3871 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3872 }
3873 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3874 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003876 }
3877 if (not cfg.bcch_extended) {
3878 testcase.stop("Error: SI22 requires BCCH Extd!");
3879 } else {
3880 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3881 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3882 }
3883 }
3884}
3885
3886/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003887private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3888return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003889 timer T := duration;
3890 var SystemInformationVectorPerTc si_per_tc;
3891 var L1ctlDlMessage l1_dl;
3892
3893 /* initialize all per-TC vectors empty */
3894 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3895 si_per_tc[i] := {};
3896 }
3897
3898 /* flush all previous L1 queued msgs */
3899 pt.clear;
3900
3901 T.start;
3902 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003903 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01003904 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
3905 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
3906 log("Ignoring non-RR SI ", l1_dl);
3907 repeat;
3908 }
3909 var SystemInformationFn sig := {
3910 frame_number := l1_dl.dl_info.frame_nr,
3911 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
3912 }
3913 var integer tc := f_gsm_compute_tc(sig.frame_number);
3914 log("SI received at TC=", tc, ": ", sig.si);
3915 /* append to the per-TC bucket */
3916 si_per_tc[tc] := si_per_tc[tc] & { sig };
3917 repeat;
3918 }
3919 [] pt.receive { repeat; }
3920 [] T.timeout { }
3921 }
3922
3923 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3924 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3925 }
3926 log("si_per_tc=", si_per_tc);
3927 return si_per_tc;
3928}
3929
3930/* helper function: Set given SI via RSL + validate scheduling.
3931 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003932private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003933 var SystemInformationVectorPerTc si_per_tc;
3934 f_init_l1ctl();
3935 f_l1_tune(L1CTL);
3936
3937 /* Sample + Validate Scheduling */
3938 si_per_tc := f_l1_sample_si(L1CTL);
3939 f_validate_si_scheduling(si_cfg, si_per_tc);
3940
3941 setverdict(pass);
3942}
3943
3944testcase TC_si_sched_default() runs on test_CT {
3945 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003946 /* 2+3+4 are mandatory and set in f_init() */
3947 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003949}
3950
3951testcase TC_si_sched_1() runs on test_CT {
3952 f_init();
3953 si_cfg.si1_present := true;
3954 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003955 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003957}
3958
3959testcase TC_si_sched_2bis() runs on test_CT {
3960 f_init();
3961 si_cfg.si2bis_present := true;
3962 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3963 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003965}
3966
3967testcase TC_si_sched_2ter() runs on test_CT {
3968 f_init();
3969 si_cfg.si2ter_present := true;
3970 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3971 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003973}
3974
3975testcase TC_si_sched_2ter_2bis() runs on test_CT {
3976 f_init();
3977 si_cfg.si2bis_present := true;
3978 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3979 si_cfg.si2ter_present := true;
3980 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3981 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003983}
3984
3985testcase TC_si_sched_2quater() runs on test_CT {
3986 f_init();
3987 si_cfg.si2quater_present := true;
3988 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3989 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003991}
3992
3993testcase TC_si_sched_13() runs on test_CT {
3994 f_init();
3995 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003996 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003997 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003999}
4000
4001testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4002 f_init();
4003 si_cfg.si2bis_present := true;
4004 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4005 si_cfg.si2ter_present := true;
4006 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4007 si_cfg.si2quater_present := true;
4008 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4009 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004010 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004011 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004013}
4014
4015
Harald Welte68e495b2018-02-25 00:05:57 +01004016testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004017 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004018 /* FIXME: enable / disable individual BCCH info */
4019 //ts_RSL_BCCH_INFO(si_type, info);
4020 /* expect no ERROR REPORT after either of them *
4021 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004023}
4024
Harald Welte93640c62018-02-25 16:59:33 +01004025/***********************************************************************
4026 * Low-Level Protocol Errors / ERROR REPORT
4027 ***********************************************************************/
4028
Harald Welte01d982c2018-02-25 01:31:40 +01004029private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4030 timer T := 5.0;
4031 T.start;
4032 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004033 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004034 setverdict(pass);
4035 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004036 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004038 }
4039 [] RSL_CCHAN.receive {
4040 repeat;
4041 }
4042 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004044 }
4045 }
4046}
4047
4048/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4049testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004050 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004051 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4052 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004053 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004054
4055 f_exp_err_rep(RSL_ERR_PROTO);
4056}
4057
4058/* Provoke a mandatory IE error and match on ERROR REPORT */
4059testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004060 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004061
4062 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4063 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004064 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004065
4066 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4067}
4068
4069/* Provoke an IE content error and match on ERROR REPORT */
4070testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004071 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004072 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4073 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004074 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004075
4076 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4077}
4078
Harald Welteee25aae2019-05-19 14:32:37 +02004079/* attempt to activate channel with wrong RSL Message Discriminator IE */
4080function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4081 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4082 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4083 RSL.send(rsl);
4084 f_rslem_unregister(0, g_chan_nr);
4085}
4086testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4087 var ConnHdlr vc_conn;
4088 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4089
Harald Welte10474062019-05-30 16:48:17 +02004090 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004091
4092 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4093 vc_conn.done;
4094 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4095
4096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4097}
4098
4099/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004100private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004101 var template (value) RSL_Message rsl_tx;
4102 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4103 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4104 RSL.send(rsl_tx);
4105 f_rslem_unregister(0, g_chan_nr);
4106}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004107private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004108 var template (value) RSL_Message rsl_tx;
4109 /* we first have to activate the dedicated channel */
4110 f_rsl_chan_act(g_pars.chan_mode);
4111 /* ... to then send an invalid RLL message */
4112 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4113 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4114 RSL.send(rsl_tx);
4115 f_rslem_unregister(0, g_chan_nr);
4116}
4117testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4118 var ConnHdlr vc_conn;
4119 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4120 var template (value) RSL_Message rsl_tx;
4121
Harald Welte10474062019-05-30 16:48:17 +02004122 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004123
4124 /* Common Channel with wrong message type */
4125 RSL_CCHAN.clear;
4126 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4127 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004128 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004129 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4130
4131 /* TRX Management */
4132 RSL_CCHAN.clear;
4133 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4134 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004135 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004136 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4137
4138 /* Dedicated Channel */
4139 RSL_CCHAN.clear;
4140 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4141 vc_conn.done;
4142 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4143
4144 /* RLL */
4145 RSL_CCHAN.clear;
4146 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4147 vc_conn.done;
4148 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4149}
4150
4151/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004152private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004153 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4154 f_rslem_unregister(0, g_chan_nr);
4155}
4156testcase TC_err_rep_wrong_sequence() runs on test_CT {
4157 var ConnHdlr vc_conn;
4158 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4159
Harald Welte10474062019-05-30 16:48:17 +02004160 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004161
4162 RSL_CCHAN.clear;
4163 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4164 vc_conn.done;
4165 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4166}
4167
Harald Welte93640c62018-02-25 16:59:33 +01004168/***********************************************************************
4169 * IPA CRCX/MDCX/DLCS media stream handling
4170 ***********************************************************************/
4171
Harald Weltea871a382018-02-25 02:03:14 +01004172/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004173private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004174 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4175 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004176}
4177testcase TC_ipa_dlcx_not_active() runs on test_CT {
4178 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004179 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004180 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4181 vc_conn.done;
4182}
Harald Welte68e495b2018-02-25 00:05:57 +01004183
Harald Weltea3f1df92018-02-25 12:49:55 +01004184/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004185private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004186 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4187 "IPA CRCX ACK");
4188 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4189 "IPA CRCX NACK");
4190}
4191testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4192 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004193 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004194 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4195 vc_conn.done;
4196}
4197
4198/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004199private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004200 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4201 "IPA CRCX ACK");
4202 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4203 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4204 var uint7_t rtp_pt2 := f_rnd_int(127);
4205 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4206 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4207 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4208 "IPA MDCX ACK");
4209 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4210 "IPA DLCX ACK");
4211}
4212testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4213 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004214 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004215 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4216 vc_conn.done;
4217}
4218
Harald Welte3ae11da2018-02-25 13:36:06 +01004219/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004220private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004221 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4222 "IPA CRCX ACK");
4223 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4224 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4225 var uint7_t rtp_pt2 := f_rnd_int(127);
4226 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4227 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4228 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4229 "IPA MDCX ACK");
4230 /* Second MDCX */
4231 remote_ip := f_rnd_int(c_UINT32_MAX);
4232 remote_port := f_rnd_int(c_UINT16_MAX);
4233 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4234 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4235 "IPA MDCX ACK");
4236 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4237 "IPA DLCX ACK");
4238}
4239testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4240 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004241 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004242 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4243 vc_conn.done;
4244}
4245
Harald Welte9912eb52018-02-25 13:30:15 +01004246/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004247private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004248 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4249 "IPA CRCX NACK");
4250}
4251testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4252 var ConnHdlrPars pars;
4253 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004254 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004255
4256 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4257 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4258 vc_conn.done;
4259
4260 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4261 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4262 vc_conn.done;
4263}
4264
Harald Weltea3f1df92018-02-25 12:49:55 +01004265
Harald Welte883340c2018-02-28 18:59:29 +01004266/***********************************************************************
4267 * PCU Socket related tests
4268 ***********************************************************************/
4269
Harald Welte07bd2d22019-05-25 11:03:30 +02004270/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004271friend 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 +01004272runs on test_CT {
4273 timer T := 3.0;
4274
4275 /* we don't expect any RTS.req before PDCH are active */
4276 T.start;
4277 alt {
4278 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004280 }
4281 [] PCU.receive { repeat; }
4282 [] T.timeout { }
4283 }
4284
4285 /* Send PDCH activate request for known PDCH timeslot */
4286 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4287
4288 /* we now expect RTS.req for this timeslot (only) */
4289 T.start;
4290 alt {
4291 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4292 setverdict(pass);
4293 }
4294 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4295 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004297 }
4298 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004300 }
4301 [] PCU.receive { repeat; }
4302 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004304 }
4305 [not exp_success] T.timeout {
4306 setverdict(pass);
4307 }
4308 }
4309}
4310
Harald Welte07bd2d22019-05-25 11:03:30 +02004311/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004312friend 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 +01004313runs on test_CT {
4314 timer T := 3.0;
4315
4316 /* Send PDCH activate request for known PDCH timeslot */
4317 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4318
4319 PCU.clear;
4320 /* we now expect no RTS.req for this timeslot */
4321 T.start;
4322 alt {
4323 [] 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 +02004324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004325 }
4326 [] PCU.receive { repeat; }
4327 [] T.timeout {
4328 setverdict(pass);
4329 }
4330 }
4331}
4332
Harald Weltead033dc2019-05-25 17:28:16 +02004333friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004334 f_init();
4335 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4336}
4337
Harald Welte883340c2018-02-28 18:59:29 +01004338/* PDCH activation via PCU socket; check for presence of RTS.req */
4339testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004340 f_init_pcu_test();
4341
Harald Welte883340c2018-02-28 18:59:29 +01004342 f_TC_pcu_act_req(0, 0, 7, true);
4343}
4344
4345/* PDCH activation via PCU socket on non-PDCU timeslot */
4346testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004347 f_init_pcu_test();
4348
Harald Welte883340c2018-02-28 18:59:29 +01004349 f_TC_pcu_act_req(0, 0, 1, false);
4350}
4351
4352/* PDCH activation via PCU socket on wrong BTS */
4353testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004354 f_init_pcu_test();
4355
Harald Welte883340c2018-02-28 18:59:29 +01004356 f_TC_pcu_act_req(23, 0, 7, false);
4357}
4358
4359/* PDCH activation via PCU socket on wrong TRX */
4360testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004361 f_init_pcu_test();
4362
Harald Welte883340c2018-02-28 18:59:29 +01004363 f_TC_pcu_act_req(0, 23, 7, false);
4364}
4365
4366/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4367testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004368 f_init_pcu_test();
4369
Harald Welte883340c2018-02-28 18:59:29 +01004370 /* Activate PDCH */
4371 f_TC_pcu_act_req(0, 0, 7, true);
4372 f_sleep(1.0);
4373 /* and De-Activate again */
4374 f_TC_pcu_deact_req(0, 0, 7);
4375}
4376
4377/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4378testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004379 f_init_pcu_test();
4380
Harald Welte883340c2018-02-28 18:59:29 +01004381 f_TC_pcu_deact_req(0, 0, 1);
4382}
4383
4384/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4385testcase TC_pcu_ver_si13() runs on test_CT {
4386 const octetstring si13 := '00010203040506070909'O;
4387 var PCUIF_send_data sd;
4388 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004389 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004390
4391 /* Set SI13 via RSL */
4392 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004393
Harald Welte883340c2018-02-28 18:59:29 +01004394 T.start;
4395 alt {
4396 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4397 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4398 setverdict(pass);
4399 } else {
4400 repeat;
4401 }
4402 }
4403 [] PCU.receive { repeat; }
4404 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004406 }
4407 }
4408}
4409
4410private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4411
4412/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004413friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004414 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4415runs on test_CT
4416{
4417 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4418 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4419}
4420
4421/* 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 +02004422friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4423 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004424runs on test_CT
4425{
4426 var PCUIF_send_data sd;
4427
4428 timer T := 3.0;
4429 T.start;
4430 alt {
4431 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4432 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4433 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4434 sd.data.u.rts_req.fn, sapi, data);
4435 }
4436 [] PCU.receive { repeat; }
4437 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004439 }
4440 }
4441}
4442
4443/* Send DATA.req on invalid BTS */
4444testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004445 var TfiUsfArr tua := f_TfiUsfArrInit();
4446 var octetstring data := '0000'O & f_rnd_octstring(21);
4447
4448 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004449
Harald Welte883340c2018-02-28 18:59:29 +01004450 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004451 f_TfiUsfArrSet(tua, 7, 0);
4452 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4453 f_sleep(1.0);
4454
4455 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004456}
4457
4458/* Send DATA.req on invalid TRX */
4459testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004460 var TfiUsfArr tua := f_TfiUsfArrInit();
4461 var octetstring data := '0000'O & f_rnd_octstring(21);
4462
4463 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004464
Harald Welte883340c2018-02-28 18:59:29 +01004465 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004466 f_TfiUsfArrSet(tua, 7, 0);
4467 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4468 f_sleep(1.0);
4469
4470 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004471}
4472
4473/* Send DATA.req on invalid timeslot */
4474testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004475 var TfiUsfArr tua := f_TfiUsfArrInit();
4476 var octetstring data := '0000'O & f_rnd_octstring(21);
4477
4478 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004479
Harald Welte883340c2018-02-28 18:59:29 +01004480 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004481 f_TfiUsfArrSet(tua, 7, 0);
4482 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4483 f_sleep(1.0);
4484
4485 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004486}
4487
4488/* Send DATA.req on timeslot that hasn't been activated */
4489testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004490 var TfiUsfArr tua := f_TfiUsfArrInit();
4491 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004492
Harald Welte7162a612019-05-26 12:56:09 +02004493 f_virtphy_common();
4494
4495 f_TfiUsfArrSet(tua, 7, 0);
4496 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4497 f_sleep(1.0);
4498
4499 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004500}
4501
Harald Weltead033dc2019-05-25 17:28:16 +02004502private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004503 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4504 boolean wait_rts := true)
4505runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004506 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004507 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004508
4509 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004510 if (wait_rts) {
4511 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4512 } else {
4513 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4514 }
Harald Weltead033dc2019-05-25 17:28:16 +02004515
4516 T.start;
4517 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004518 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004519 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4520 setverdict(pass);
4521 }
Harald Welte7162a612019-05-26 12:56:09 +02004522 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4523 setverdict(fail, "Received unexpected ", rx_dl);
4524 }
Harald Weltead033dc2019-05-25 17:28:16 +02004525 [] L1CTL.receive {
4526 repeat;
4527 }
Harald Welte7162a612019-05-26 12:56:09 +02004528 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004529 setverdict(fail, "Timeout waiting for ", data);
4530 }
Harald Welte7162a612019-05-26 12:56:09 +02004531 [not expect_data] T.timeout {
4532 setverdict(pass);
4533 }
Harald Weltead033dc2019-05-25 17:28:16 +02004534 }
4535}
4536
4537private function f_disable_dynamic_ts() runs on test_CT
4538{
4539 f_init_vty_bsc();
4540 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4541 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4542 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4543 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004544 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004545}
4546
4547private function f_virtphy_common() runs on test_CT {
4548 f_disable_dynamic_ts();
4549 f_init_l1ctl();
4550 f_l1_tune(L1CTL);
4551}
4552
4553testcase TC_pcu_data_req_pdtch() runs on test_CT {
4554 var TfiUsfArr tua := f_TfiUsfArrInit();
4555 var octetstring data := '0000'O & f_rnd_octstring(21);
4556
4557 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004558
Harald Welte883340c2018-02-28 18:59:29 +01004559 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004560 f_TfiUsfArrSet(tua, 7, 0);
4561 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4562 f_sleep(1.0);
4563
4564 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004565}
4566
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004567/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004568testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004569 var TfiUsfArr tua := f_TfiUsfArrInit();
4570 var octetstring data := '0000'O & f_rnd_octstring(21);
4571
4572 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004573
Harald Welte883340c2018-02-28 18:59:29 +01004574 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004575 f_TfiUsfArrSet(tua, 7, 0);
4576 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4577 f_sleep(1.0);
4578
4579 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004580}
4581
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004582private function f_TC_pcu_ptcch_ul(uint16_t ra)
4583runs on test_CT {
4584 var template PCUIF_Message pcu_rach_ind;
4585 var PCUIF_send_data sd;
4586 var GsmFrameNumber fn;
4587 timer T;
4588
4589 /* Send an Access Burst on PTCCH/U over the Um-interface */
4590 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4591 chan_nr := ts_RslChanNr_PDCH(7),
4592 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4593
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004594 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4595 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004596
4597 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4598 T.start(52.0 * 4.615 / 1000.0);
4599 alt {
4600 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4601 log("Rx an Access Burst on the PCU interface: ", sd.data);
4602 setverdict(pass);
4603 T.stop;
4604 }
4605 [] PCU.receive { repeat; }
4606 [] T.timeout {
4607 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4608 /* Keep going, that's not the end of the world */
4609 }
4610 }
4611}
4612
4613testcase TC_pcu_ptcch() runs on test_CT {
4614 var L1ctlDlMessage dl;
4615 var octetstring data;
4616 timer T;
4617
4618 f_init_pcu_test();
4619 f_init_l1ctl();
4620 f_l1_tune(L1CTL);
4621
4622 /* Activate PDCH channel on TS7 */
4623 f_TC_pcu_act_req(0, 0, 7, true);
4624
4625 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004626 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004627
4628 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4629 for (var integer i := 0; i < 16; i := i + 1) {
4630 log("Sending an Access Burst towards the L1CTL interface");
4631 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4632 }
4633
4634 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4635 data := f_rnd_octstring(23);
4636
4637 /* Verify PTCCH/D: send a random data block, make sure it's received */
4638 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4639 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4640
4641 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4642 * let's give it more time in case if we miss the beginning. */
4643 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4644 alt {
4645 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4646 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4647 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4648 frame := data)) -> value dl {
4649 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4650 setverdict(pass);
4651 T.stop;
4652 }
4653 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4654 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4655 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4656 l2_data := data)) -> value dl {
4657 log("Rx PTCCH/D data block on L1CTL: ", dl);
4658 setverdict(pass);
4659 T.stop;
4660 }
4661 [] L1CTL.receive { repeat; }
4662 [] T.timeout {
4663 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4664 }
4665 }
4666}
4667
Harald Welte883340c2018-02-28 18:59:29 +01004668/* Send AGCH from PCU; check it appears on Um side */
4669testcase TC_pcu_data_req_agch() runs on test_CT {
4670 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004671 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004672 f_init_l1ctl();
4673 f_l1_tune(L1CTL);
4674
4675 f_TC_pcu_act_req(0, 0, 7, true);
4676 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4677
4678 T.start;
4679 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004680 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004681 setverdict(pass);
4682 }
4683 [] L1CTL.receive { repeat; }
4684 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004686 }
4687 }
4688}
4689
Harald Welte928622b2019-05-26 13:22:59 +02004690/* Send AGCH from PCU; check it appears on Um side */
4691testcase TC_pcu_data_req_pch() runs on test_CT {
4692 timer T := 3.0;
4693 f_init_pcu_test();
4694 f_init_l1ctl();
4695 f_l1_tune(L1CTL);
4696
4697 f_TC_pcu_act_req(0, 0, 7, true);
4698 /* three characters prefix: last 3 digits of IMSI as ASCII */
4699 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4700
4701 T.start;
4702 alt {
4703 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4704 setverdict(pass);
4705 }
4706 [] L1CTL.receive { repeat; }
4707 [] T.timeout {
4708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4709 }
4710 }
4711}
4712
Harald Welte883340c2018-02-28 18:59:29 +01004713/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4714testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4715 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004716 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004717 f_init_l1ctl();
4718 f_l1_tune(L1CTL);
4719
4720 /* append 3 last imsi digits so BTS can compute pagng group */
4721 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4722
4723 timer T := 0.5;
4724 T.start;
4725 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004726 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004727 /* TODO: verify paging group */
4728 setverdict(pass);
4729 }
4730 [] L1CTL.receive { repeat; }
4731 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004733 }
4734 }
4735}
4736
4737/* Send RACH from Um side, expect it to show up on PCU socket */
4738testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004739 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004740 f_init_l1ctl();
4741 f_l1_tune(L1CTL);
4742
4743 var GsmFrameNumber fn_last := 0;
4744 for (var integer i := 0; i < 1000; i := i+1) {
4745 var OCT1 ra := f_rnd_ra_ps();
4746 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4747 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004749 }
4750 fn_last := fn;
4751
4752 timer T := 2.0;
4753 T.start;
4754 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004755 [] 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 +01004756 T.stop;
4757 }
4758 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004760 }
4761 [] PCU.receive { repeat; }
4762 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004764 }
4765 }
4766 }
4767 setverdict(pass);
4768}
4769
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004770/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4771 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4772testcase TC_pcu_ext_rach_content() runs on test_CT {
4773 var template PCUIF_Message pcu_rach_ind;
4774 var GsmFrameNumber fn_last := 0;
4775 var L1ctlRachSynchSeq synch_seq;
4776 var PCUIF_BurstType pcu_bt;
4777 var GsmFrameNumber fn;
4778 var BIT11 ra11;
4779
4780 f_init_pcu_test();
4781 f_init_l1ctl();
4782 f_l1_tune(L1CTL);
4783
4784 for (var integer i := 0; i < 1000; i := i+1) {
4785 /* We need to test both TS1 & TS2 */
4786 if (i rem 2 == 0) {
4787 synch_seq := RACH_SYNCH_SEQ_TS1;
4788 pcu_bt := BURST_TYPE_1;
4789 } else {
4790 synch_seq := RACH_SYNCH_SEQ_TS2;
4791 pcu_bt := BURST_TYPE_2;
4792 }
4793
4794 ra11 := f_rnd_ra11_ps();
4795 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4796 if (fn == fn_last) {
4797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4798 "Two RACH in same FN?!?");
4799 }
4800 fn_last := fn;
4801
4802 /* Compose the expected message */
4803 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004804 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004805 ra := bit2int(ra11),
4806 is_11bit := 1,
4807 burst_type := pcu_bt,
4808 fn := fn);
4809
4810 timer T := 2.0;
4811 T.start;
4812 alt {
4813 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4814 T.stop;
4815 }
4816 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4818 }
4819 [] PCU.receive { repeat; }
4820 [] T.timeout {
4821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4822 }
4823 }
4824 }
4825 setverdict(pass);
4826}
4827
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004828private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4829runs on test_CT {
4830 var template PCUIF_send_data sdt;
4831 var PCUIF_send_data sd;
4832 var int16_t lqual_cb;
4833 timer T := 1.0;
4834
4835 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4836 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4837
4838 /* Send a random PDTCH frame over Um */
4839 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4840 '0000'O & f_rnd_octstring(21)));
4841
4842 T.start;
4843 alt {
4844 /* If expected link quality is above the threshold */
4845 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4846 lqual_cb := sd.data.u.data_ind.lqual_cb;
4847 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4848
4849 /* Make sure the actual link quality matches the expected value */
4850 if (not match(lqual_cb, lqual_cb_exp)) {
4851 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4852 "expected value ", lqual_cb_exp));
4853 } else {
4854 setverdict(pass);
4855 }
4856 }
4857 /* If expected link quality is below the threshold */
4858 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4860 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4861 }
4862 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4863 [] PCU.receive { repeat; }
4864 [lqual_cb_exp < thresh] T.timeout {
4865 log("Rx nothing, as expected");
4866 setverdict(pass);
4867 }
4868 [lqual_cb_exp >= thresh] T.timeout {
4869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4870 "Timeout waiting for PCUIF_DATA.ind");
4871 }
4872 }
4873}
4874
4875/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4876testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4877 f_init_pcu_test();
4878 PCU.clear;
4879
4880 f_init_l1ctl();
4881 f_l1_tune(L1CTL);
4882
4883 /* Activate a PDCH channel on TS7 */
4884 f_TC_pcu_act_req(0, 0, 7, true);
4885
4886 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004887 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004888
4889 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4890 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4891 var TrxcMessage ret;
4892
4893 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4894 valueof(ts_TRXC_FAKE_CI(i)));
4895
4896 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4897 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4898 }
4899}
4900
Harald Welte883340c2018-02-28 18:59:29 +01004901/* Send PAGING via RSL, expect it to shw up on PCU socket */
4902testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004903 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004904
4905 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004906 var MobileIdentityLV mi_lv;
4907 var octetstring mi_lv_enc;
4908 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004909 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004910
Harald Welte883340c2018-02-28 18:59:29 +01004911 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004912 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004913 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004914 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004915 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004916
4917 /* Fancy encoding for PCUIF */
4918 mi_lv := valueof(ts_MI_LV(mi));
4919 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4920 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004921
4922 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004923 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004924 T.start;
4925 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004926 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004927 }
4928 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004930 }
4931 [] PCU.receive { repeat; }
4932 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004934 }
4935 }
4936 }
4937 setverdict(pass);
4938}
4939
Harald Welted66c9b82019-05-25 09:03:15 +02004940/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4941testcase TC_pcu_time_ind() runs on test_CT {
4942 var PCUIF_send_data pcu_sd;
4943 var integer num_time_ind := 0;
4944 var integer first_fn, last_fn;
4945 var float test_duration := 5.0;
4946 timer T;
4947
4948 f_init_pcu_test();
4949 f_TC_pcu_act_req(0, 0, 7, true);
4950
4951 PCU.clear;
4952 T.start(test_duration);
4953 alt {
4954 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4955 num_time_ind := num_time_ind + 1;
4956 if (not isbound(first_fn)) {
4957 first_fn := pcu_sd.data.u.time_ind.fn;
4958 }
4959 last_fn := pcu_sd.data.u.time_ind.fn;
4960 repeat;
4961 }
4962 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4963 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4964 repeat;
4965 }
4966 [] PCU.receive {
4967 repeat;
4968 }
4969 [] T.timeout {}
4970 }
4971 var integer fn_expired := last_fn - first_fn;
4972 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4973
4974 /* verify the number of frames expired matches our expectation */
4975 const float c_GSM_FN_DURATION_MS := 4.61538;
4976 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02004977 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02004978 if (not match(fn_expired, t_fn_expected)) {
4979 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
4980 }
4981
4982 /* There are three TIME.ind in every fn MOD 13 */
4983 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
4984 /* Add some tolerance */
4985 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
4986 if (not match(num_time_ind, t_time_ind_exp)) {
4987 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
4988 }
4989
4990 setverdict(pass);
4991}
4992
Harald Welte4832c862019-05-25 14:57:18 +02004993/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
4994testcase TC_pcu_rts_req() runs on test_CT {
4995 var PCUIF_send_data pcu_sd;
4996 var integer first_fn, last_fn;
4997 var integer num_rts_pdtch := 0;
4998 var integer num_rts_ptcch := 0;
4999 var float test_duration := 5.0;
5000 timer T;
5001
5002 f_init_pcu_test();
5003 f_TC_pcu_act_req(0, 0, 7, true);
5004
5005 PCU.clear;
5006 T.start(test_duration);
5007 alt {
5008 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5009 -> value pcu_sd {
5010 num_rts_pdtch := num_rts_pdtch + 1;
5011 if (not isbound(first_fn)) {
5012 first_fn := pcu_sd.data.u.rts_req.fn;
5013 }
5014 last_fn := pcu_sd.data.u.rts_req.fn;
5015 repeat;
5016 }
5017 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5018 -> value pcu_sd {
5019 num_rts_ptcch := num_rts_ptcch + 1;
5020 if (not isbound(first_fn)) {
5021 first_fn := pcu_sd.data.u.rts_req.fn;
5022 }
5023 last_fn := pcu_sd.data.u.rts_req.fn;
5024 repeat;
5025 }
5026 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5027 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5028 repeat;
5029 }
5030 [] PCU.receive {
5031 repeat;
5032 }
5033 [] T.timeout {}
5034 }
5035 var integer fn_expired := last_fn - first_fn;
5036 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5037 ", num_rts_ptcch=", num_rts_ptcch);
5038
5039 /* verify the number of frames expired matches our expectation */
5040 const float c_GSM_FN_DURATION_MS := 4.61538;
5041 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005042 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005043 if (not match(fn_expired, t_fn_expected)) {
5044 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5045 }
5046
5047 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5048 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5049 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5050 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5051 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5052 t_ptcch_exp);
5053 }
5054
5055 /* We have 12 PDTCH blocks every 52-multiframe */
5056 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5057 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5058 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5059 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5060 t_pdtch_exp);
5061 }
5062
5063 setverdict(pass);
5064}
5065
Harald Welte07bd2d22019-05-25 11:03:30 +02005066/* test for generating Abis side OML ALERT from the PCU */
5067testcase TC_pcu_oml_alert() runs on test_CT {
5068 var PCUIF_send_data pcu_sd;
5069 var integer num_time_ind := 0;
5070 var integer first_fn, last_fn;
5071 var float test_duration := 5.0;
5072 timer T;
5073
5074 f_init_pcu_test();
5075 f_TC_pcu_act_req(0, 0, 7, true);
5076
5077 /* re-connect CTRL port from BTS to BSC */
5078 f_ipa_ctrl_stop();
5079 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5080
5081 /* Send that OML Alert */
5082 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5083
5084 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5085 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5086 setverdict(pass);
5087}
5088
Harald Welteeaa9a862019-05-26 23:01:08 +02005089template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
5090 template (value) RoutingAreaIdentificationV rai,
5091 template (value) OCT1 cause) := {
5092 discriminator := '0000'B, /* overwritten */
5093 tiOrSkip := {
5094 skipIndicator := '0000'B
5095 },
5096 msgs := {
5097 rrm := {
5098 gPRS_suspensionRequest := {
5099 messageType := '00110100'B,
5100 tLLI := tlli,
5101 routingAreaIdentification := rai,
5102 suspensionCause := cause,
5103 service_Support := omit
5104 }
5105 }
5106 }
5107}
5108
5109/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5110private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5111 var PCUIF_Message first_info;
5112 var integer pcu_conn_id := -1;
5113 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5114 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5115 var OCT4 tlli := '01020304'O;
5116 var OCT1 cause := '23'O;
5117 timer T := 5.0;
5118
5119 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5120
5121 f_l1_tune(L1CTL);
5122 RSL.clear;
5123
5124 f_est_dchan();
5125 L1CTL.clear;
5126
5127 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5128
5129 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5130 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5131 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5132
5133 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5134 T.start;
5135 alt {
5136 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5137 setverdict(pass);
5138 }
5139 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5140 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5141 }
5142 [] PCU.receive {
5143 repeat;
5144 }
5145 [] T.timeout {
5146 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5147 }
5148 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005149
5150 /* release the channel */
5151 f_rsl_chan_deact();
5152 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5153 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005154}
5155testcase TC_pcu_rr_suspend() runs on test_CT {
5156 var ConnHdlrPars pars;
5157 var ConnHdlr vc_conn;
5158
5159 f_init();
5160
5161 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5162 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5163 vc_conn.done;
5164}
Harald Welte07bd2d22019-05-25 11:03:30 +02005165
Harald Weltea2e0e942019-05-27 18:12:53 +02005166/* Ensure that PCUIF socket can accept only a single connection */
5167testcase TC_pcu_socket_connect_multi() runs on test_CT {
5168 timer T := 5.0;
5169
5170 /* this (among other things) establishes the first connection to the PCUIF socket */
5171 f_init();
5172
5173 /* try to establish a second connection, expect it to fail */
5174 PCU.send(UD_connect:{mp_pcu_socket, -1});
5175 T.start;
5176 alt {
5177 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5178 setverdict(pass);
5179 }
5180 [] PCU.receive(UD_connect_result:?) {
5181 setverdict(fail, "Unexpected unix domain connect result");
5182 }
5183 [] T.timeout {
5184 setverdict(pass);
5185 }
5186 }
5187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5188}
5189
Harald Weltec8effb72019-05-27 18:23:04 +02005190/* Ensure that PCUIF socket can disconnect + reconnect */
5191testcase TC_pcu_socket_reconnect() runs on test_CT {
5192 /* this (among other things) establishes the first connection to the PCUIF socket */
5193 f_init();
5194
5195 f_sleep(1.0);
5196
5197 f_pcuif_close(PCU, g_pcu_conn_id);
5198 g_pcu_conn_id := -1;
5199
5200 f_sleep(1.0);
5201
5202 /* re-connect */
5203 PCU.clear;
5204 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5205 setverdict(pass);
5206
5207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5208}
5209
Harald Weltebe030482019-05-27 22:29:35 +02005210/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005211private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5212runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005213 var L1ctlDlMessage l1_dl;
5214 var SystemInformation si;
5215 timer T := 5.0;
5216 T.start;
5217 alt {
5218 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
5219 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
5220 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
5221 log("Ignoring non-RR SI ", l1_dl);
5222 repeat;
5223 }
5224 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005225 if (si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005226 repeat;
5227 }
5228 }
5229 [] pt.receive {
5230 repeat;
5231 }
5232 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5234 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005235 }
5236 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005237 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005238}
5239
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005240/* Check if GPRS Indicator is present in RR System Information of a given type */
5241private function f_si_has_gprs_indicator(RrMessageType si_type)
5242runs on test_CT return boolean {
5243 var SystemInformation si := f_get_si(L1CTL, si_type);
5244
5245 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
5246 var RestOctets ro := si.payload.si3.rest_octets;
5247 var SI3RestOctets rest := dec_SI3RestOctets(ro);
5248 return rest.gprs_ind.presence == '1'B;
5249 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
5250 var RestOctets ro := si.payload.si4.rest_octets;
5251 var SI4RestOctets rest := dec_SI4RestOctets(ro);
5252 return rest.gprs_ind.presence == '1'B;
5253 }
5254
5255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5256 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005257}
5258
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005259/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5260private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5261runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005262 /* don't call f_init() as this would connect PCU socket */
5263 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005264
5265 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005266 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005267 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005268
5269 f_init_l1ctl();
5270 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005271 f_sleep(2.0);
5272 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005273
5274 if (f_si_has_gprs_indicator(si_type)) {
5275 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005276 } else {
5277 setverdict(pass);
5278 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005279
Harald Weltebe030482019-05-27 22:29:35 +02005280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5281}
5282
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005283testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5284 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5285}
Harald Weltebe030482019-05-27 22:29:35 +02005286
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005287testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5288 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5289}
5290
5291/* Ensure that GPRS capability is advertised after PCU socket connect */
5292private function f_TC_pcu_socket_connect(RrMessageType si_type)
5293runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005294 /* this (among other things) establishes the first connection to the PCUIF socket */
5295 f_init();
5296 f_init_l1ctl();
5297 f_l1_tune(L1CTL);
5298
5299 f_sleep(2.0);
5300 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005301
5302 if (not f_si_has_gprs_indicator(si_type)) {
5303 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005304 } else {
5305 setverdict(pass);
5306 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005307
Harald Weltebe030482019-05-27 22:29:35 +02005308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5309}
5310
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005311testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5312 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5313}
Harald Weltebe030482019-05-27 22:29:35 +02005314
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005315testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5316 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5317}
5318
5319/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5320private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5321runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005322 /* this (among other things) establishes the first connection to the PCUIF socket */
5323 f_init();
5324 f_init_l1ctl();
5325 f_l1_tune(L1CTL);
5326
5327 f_pcuif_close(PCU, g_pcu_conn_id);
5328 g_pcu_conn_id := -1;
5329
5330 f_sleep(1.0);
5331
5332 /* re-connect */
5333 PCU.clear;
5334 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5335
5336 f_sleep(2.0);
5337 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005338
5339 if (f_si_has_gprs_indicator(si_type)) {
5340 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005341 } else {
5342 setverdict(pass);
5343 }
5344
5345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5346}
5347
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005348testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5349 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5350}
5351
5352testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5353 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5354}
5355
Oliver Smithf5239c72019-08-28 10:01:25 +02005356/* 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) */
5357testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5358 var SystemInformation si3 := valueof(ts_SI3_default);
5359
5360 f_init();
5361
5362 /* Verify cell_id */
5363 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5364 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5365 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005366 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5367 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5368 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005369 }
5370
5371 /* Verify LAC */
5372 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5373 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5374 if (lac_si3 != lac_pcu) {
5375 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5376 }
5377
5378 setverdict(pass);
5379}
Harald Welted66c9b82019-05-25 09:03:15 +02005380
Harald Welte3d04ae62018-04-04 20:29:05 +02005381/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005382 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005383 ***********************************************************************/
5384
5385private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5386runs on ConnHdlr {
5387 var PCUIF_send_data sd;
5388 /* Expect BTS to immediately acknowledge activation as PDCH */
5389 PCU.clear;
5390 f_rsl_chan_act(g_pars.chan_mode);
5391 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005392 timer T_wait := 2.0;
5393 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005394 alt {
5395 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5396 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 +02005397 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5398 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5399 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005400 }
5401 }
5402 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005403 [] T_wait.timeout {
5404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5405 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5406 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005407 }
5408 /* try to activate this PDCH from the PCU point of view */
5409 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5410 /* FIXME: is there a response? */
5411}
5412
5413private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5414runs on ConnHdlr {
5415 var PCUIF_send_data sd;
5416 /* Send RSL CHAN REL (deactivate) */
5417 PCU.clear;
5418 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5419 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005420 timer T_wait := 2.0;
5421 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005422 alt {
5423 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5424 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 +02005425 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5426 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5427 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005428 }
5429 }
5430 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005431 [] T_wait.timeout {
5432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5433 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5434 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005435 }
5436 /* Emulate PCU asking BTS to deactivate PDCH */
5437 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5438 alt {
5439 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5440 setverdict(pass);
5441 }
5442 [] RSL.receive { repeat; }
5443 }
5444}
5445
5446/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005447private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005448 var PCUIF_Message first_info;
5449 var integer ts_nr := g_chan_nr.tn;
5450 var integer trx_nr := 0;
5451 var integer bts_nr := 0;
5452 var integer pcu_conn_id := -1;
5453
5454 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5455
5456 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5457 f_sleep(3.0);
5458 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5459 setverdict(pass);
5460}
5461testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5462 var ConnHdlrPars pars;
5463 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005464 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005465
5466 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5467 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5468 vc_conn.done;
5469}
5470
5471/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005472private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005473 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005474 var integer pcu_conn_id := -1;
5475
5476 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5477
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005478 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5479 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5480 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005481 setverdict(pass);
5482}
5483testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5484 var ConnHdlrPars pars;
5485 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005486 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005487
5488 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5489 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5490 vc_conn.done;
5491}
5492
5493/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005494private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005495 var PCUIF_Message first_info;
5496 var integer ts_nr := g_chan_nr.tn;
5497 var integer trx_nr := 0;
5498 var integer bts_nr := 0;
5499 var integer pcu_conn_id := -1;
5500
5501 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5502
5503 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005504 /* Send a second Chan Activ and expect it to be NACKed */
5505 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5506 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005507 setverdict(pass);
5508}
5509testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5510 var ConnHdlrPars pars;
5511 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005512 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005513
5514 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5515 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5516 vc_conn.done;
5517}
5518
5519/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005520private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005521 var PCUIF_Message first_info;
5522 var integer ts_nr := g_chan_nr.tn;
5523 var integer trx_nr := 0;
5524 var integer bts_nr := 0;
5525 var integer pcu_conn_id := -1;
5526 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5527
5528 /* register for the TCH/F channel number */
5529 f_rslem_register(0, chan_nr);
5530
5531 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5532
5533 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5534 "RSL CHAN ACT");
5535 setverdict(pass);
5536}
5537testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5538 var ConnHdlrPars pars;
5539 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005540 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005541
5542 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5543 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5544 vc_conn.done;
5545}
5546
5547/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005548private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005549 var PCUIF_Message first_info;
5550 var integer ts_nr := g_chan_nr.tn;
5551 var integer trx_nr := 0;
5552 var integer bts_nr := 0;
5553 var integer pcu_conn_id := -1;
5554 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5555 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5556
5557 /* register for the TCH/H channel numbers */
5558 f_rslem_register(0, chan_nr[0]);
5559 f_rslem_register(0, chan_nr[1]);
5560
5561 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5562
5563 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5564 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5565 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5566 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5567 setverdict(pass);
5568}
5569testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5570 var ConnHdlrPars pars;
5571 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005572 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005573
5574 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5575 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5576 vc_conn.done;
5577}
5578
Harald Welte9bbbfb52018-04-05 09:33:19 +02005579/***********************************************************************
5580 * IPA Style Dynamic Timeslot Support
5581 ***********************************************************************/
5582
5583private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5584runs on ConnHdlr {
5585 var PCUIF_send_data sd;
5586 /* Expect BTS to immediately acknowledge activation as PDCH */
5587 PCU.clear;
5588 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5589 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005590 timer T_wait := 2.0;
5591 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005592 alt {
5593 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5594 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 +01005595 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5596 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5597 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005598 }
5599 }
5600 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005601 [] T_wait.timeout {
5602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5603 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5604 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005605 }
5606 /* try to activate this PDCH from the PCU point of view */
5607 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5608 /* FIXME: is there a response? */
5609
5610 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5611}
5612
5613private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5614runs on ConnHdlr {
5615 var PCUIF_send_data sd;
5616 /* Send RSL CHAN REL (deactivate) */
5617 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5618 PCU.clear;
5619 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005620 timer T_wait := 2.0;
5621 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005622 alt {
5623 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5624 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 +01005625 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5626 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5627 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005628 }
5629 }
5630 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005631 [] T_wait.timeout {
5632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5633 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5634 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005635 }
5636 /* Emulate PCU asking BTS to deactivate PDCH */
5637 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5638 alt {
5639 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5640 setverdict(pass);
5641 }
5642 [] RSL.receive { repeat; }
5643 }
5644}
5645
5646/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005647private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005648 var PCUIF_Message first_info;
5649 var integer ts_nr := g_chan_nr.tn;
5650 var integer trx_nr := 0;
5651 var integer bts_nr := 0;
5652 var integer pcu_conn_id := -1;
5653
5654 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5655
5656 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5657 f_sleep(3.0);
5658 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5659
5660 setverdict(pass);
5661
5662}
5663testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5664 var ConnHdlrPars pars;
5665 var ConnHdlr vc_conn;
5666 f_init();
5667
5668 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5669 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5670 vc_conn.done;
5671}
5672
5673/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005674private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005675 var PCUIF_Message first_info;
5676 var integer ts_nr := g_chan_nr.tn;
5677 var integer trx_nr := 0;
5678 var integer bts_nr := 0;
5679 var integer pcu_conn_id := -1;
5680
5681 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5682
5683 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5684 "RSL CHAN ACT");
5685 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5686 "RF CHAN REL", true);
5687 setverdict(pass);
5688}
5689testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5690 var ConnHdlrPars pars;
5691 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005692 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005693
5694 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5695 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5696 vc_conn.done;
5697}
5698
5699/* 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 +07005700private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005701 var PCUIF_Message first_info;
5702 var integer ts_nr := g_chan_nr.tn;
5703 var integer trx_nr := 0;
5704 var integer bts_nr := 0;
5705 var integer pcu_conn_id := -1;
5706
5707 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5708
5709 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5710 "RSL CHAN ACT");
5711
5712 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5713 alt {
5714 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5715 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005717 }
5718 [] RSL.receive { repeat; }
5719 }
5720
5721 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5722 "RF CHAN REL", true);
5723 setverdict(pass);
5724}
5725testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5726 var ConnHdlrPars pars;
5727 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005728 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005729
5730 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5731 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5732 vc_conn.done;
5733}
5734
5735/* 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 +07005736private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005737 var PCUIF_Message first_info;
5738 var integer ts_nr := g_chan_nr.tn;
5739 var integer trx_nr := 0;
5740 var integer bts_nr := 0;
5741 var integer pcu_conn_id := -1;
5742
5743 /* register for the TCH/F channel number */
5744 f_rslem_register(0, g_chan_nr);
5745
5746 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5747
5748 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5749
5750 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5751 "RSL CHAN ACT");
5752
5753 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5754
5755 setverdict(pass);
5756}
5757testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5758 var ConnHdlrPars pars;
5759 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005760 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005761
5762 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5763 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5764 vc_conn.done;
5765}
5766
5767
Harald Welte0472ab42018-03-12 15:02:26 +01005768/***********************************************************************
5769 * LAPDm / RLL related
5770 ***********************************************************************/
5771
5772private function f_tx_lapdm(template (value) LapdmFrame l,
5773 template (value) RslLinkId link_id) runs on ConnHdlr {
5774 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005775 var template (value) SacchL1Header l1h;
5776
5777 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005778 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005779 /* Compose dummy L1 header */
5780 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5781 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 +02005782 } else {
5783 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005784 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 +01005785 }
Harald Welte0472ab42018-03-12 15:02:26 +01005786}
5787
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005788private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005789 uint3_t sapi,
5790 RslLinkId link_id,
5791 octetstring l3,
5792 boolean exp
5793}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005794private type record of RllTestCase RllTestCases;
5795private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5796 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005797 sapi := sapi,
5798 link_id := id,
5799 l3 := l3,
5800 exp := exp
5801}
5802
5803/* execute the same callback function with a set of different parameters (tcs) on a
5804 * variety of logical channels */
5805private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5806 var ConnHdlrPars pars;
5807 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005808 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005809
5810 /* test on each of the channels we have */
5811 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5812 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5813
5814 /* test each of the test cases on the current channel */
5815 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5816 pars.spec.rll := tcs[j];
5817 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5818 vc_conn := f_start_handler(fn, pars);
5819 vc_conn.done;
5820 }
5821 }
5822
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005824}
5825
5826/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5827private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5828 var RllTestCase tc := g_pars.spec.rll;
5829 timer T := 3.0;
5830
5831 f_l1_tune(L1CTL);
5832 RSL.clear;
5833
5834 /* activate the logical channel */
5835 f_est_dchan();
5836 L1CTL.clear;
5837
5838 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5839 T.start;
5840 alt {
5841 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5842 if (tc.exp) {
5843 setverdict(pass);
5844 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005846 }
5847 }
5848 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5849 if (tc.exp) {
5850 setverdict(pass);
5851 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005853 }
5854 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005855 /* We also expect to receive the measurements */
5856 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005857 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005859 }
5860 [not tc.exp] T.timeout {
5861 setverdict(pass);
5862 }
5863 }
5864
5865 f_rsl_chan_deact();
5866 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5867 f_rslem_unregister(0, g_chan_nr);
5868}
5869testcase TC_rll_est_ind() runs on test_CT {
5870 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005871 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005872 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005873 /* normal SAPI0 establishment */
5874 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005875 /* SAPI 3 doesn't support contention resolution */
5876 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5877 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5878 /* normal SAPI3 establishment on main DCCH */
5879 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5880 /* normal SAPI3 establishment on SACCH */
5881 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5882 };
5883 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5884}
5885
5886/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5887private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5888 var RllTestCase tc := g_pars.spec.rll;
5889 var L1ctlDlMessage dl;
5890 timer T := 3.0;
5891
5892 f_l1_tune(L1CTL);
5893 RSL.clear;
5894
5895 /* activate the logical channel */
5896 f_est_dchan();
5897 L1CTL.clear;
5898
5899 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5900 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5901 T.start;
5902 alt {
5903 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5904 var LapdmFrame lapdm;
5905 var octetstring l2 := dl.payload.data_ind.payload;
5906 if (dl.dl_info.link_id.c == SACCH) {
5907 /* remove L1 header */
5908 l2 := substr(l2, 2, lengthof(l2)-2);
5909 }
5910 lapdm.ab := dec_LapdmFrameAB(l2);
5911 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5912 setverdict(pass);
5913 } else {
5914 repeat;
5915 }
5916 }
5917 [] L1CTL.receive { repeat; }
5918 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005920 }
5921 }
5922
5923 f_rsl_chan_deact();
5924 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5925 f_rslem_unregister(0, g_chan_nr);
5926}
5927testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5928 var RllTestCases tcs := {
5929 /* normal SAPI3 establishment on main DCCH */
5930 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5931 };
5932 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5933}
5934testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5935 var RllTestCases tcs := {
5936 /* normal SAPI3 establishment on SACCH */
5937 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5938 }
5939 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5940}
5941
5942/* altstep to receive a LAPDm frame matching the given template */
5943private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5944 var L1ctlDlMessage dl;
5945 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5946 var LapdmFrame lapdm;
5947 var octetstring l2 := dl.payload.data_ind.payload;
5948 if (dl.dl_info.link_id.c == SACCH) {
5949 /* remove L1 header */
5950 l2 := substr(l2, 2, lengthof(l2)-2);
5951 }
5952 if (ischosen(exp.ab)) {
5953 lapdm.ab := dec_LapdmFrameAB(l2);
5954 } else if (ischosen(exp.b4)) {
5955 lapdm.b4 := dec_LapdmFrameB4(l2);
5956 } else if (ischosen(exp.bbis)) {
5957 lapdm.bbis := dec_LapdmFrameBbis(l2);
5958 }
5959 log("Rx LAPDm ", lapdm);
5960 if (match(lapdm, exp)) {
5961 setverdict(pass);
5962 } else {
5963 repeat;
5964 }
5965 }
5966 [] L1CTL.receive { repeat; }
5967}
5968private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5969 timer T := t;
5970 T.start;
5971 alt {
5972 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005974 }
5975 [] as_l1_exp_lapdm(exp);
5976 }
5977}
5978
5979/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5980private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5981 /* send SABM from MS -> BTS */
5982 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5983 /* expect RLL EST IND on Abis */
5984 alt {
5985 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5986 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5987 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005989 }
5990 [] RSL.receive { repeat; }
5991 }
5992 /* expect UA from BTS -> MS */
5993 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5994}
5995
5996/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5997private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5998 var RllTestCase tc := g_pars.spec.rll;
5999
6000 f_l1_tune(L1CTL);
6001 RSL.clear;
6002
6003 /* activate the logical channel */
6004 f_est_dchan();
6005 L1CTL.clear;
6006
6007 /* first establish the link-layer */
6008 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6009
6010 /* then send the DISC */
6011 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6012 /* ... and expect the REL IND on the RSL side */
6013 alt {
6014 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6015 setverdict(pass);
6016 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006017 /* We also expect to receive the measurements */
6018 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006019 }
6020
6021 /* release the channel */
6022 f_rsl_chan_deact();
6023 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6024 f_rslem_unregister(0, g_chan_nr);
6025}
6026testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6027 var RllTestCases tcs := {
6028 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6029 };
6030 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6031}
6032
6033testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6034 var RllTestCases tcs := {
6035 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6036 };
6037 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6038}
6039testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6040 var RllTestCases tcs := {
6041 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6042 };
6043 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6044}
6045testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6046 var RllTestCases tcs := {
6047 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6048 };
6049 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6050}
6051
6052/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6053private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6054 var RllTestCase tc := g_pars.spec.rll;
6055 f_l1_tune(L1CTL);
6056 RSL.clear;
6057
6058 /* activate the logical channel */
6059 f_est_dchan();
6060 L1CTL.clear;
6061
6062 /* first establish the link-layer */
6063 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6064
6065 /* then send the REL REQ via RSL */
6066 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6067 /* ... and expect the DISC on the Um side */
6068 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006069 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006070 /* FIXME: send a UA in resposne to the DISC */
6071 }
6072 }
6073
6074 /* release the channel */
6075 f_rsl_chan_deact();
6076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6077 f_rslem_unregister(0, g_chan_nr);
6078}
6079testcase TC_rll_rel_req() runs on test_CT {
6080 var RllTestCases tcs := {
6081 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6082 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6083 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6084 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6085 };
6086 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6087}
6088
6089/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
6090testcase TC_rll_data_req() runs on test_CT {
6091}
6092
6093/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
6094testcase TC_rll_data_ind() runs on test_CT {
6095}
6096
6097/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6098private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6099 var RllTestCase tc := g_pars.spec.rll;
6100
6101 f_l1_tune(L1CTL);
6102 RSL.clear;
6103
6104 f_est_dchan();
6105 L1CTL.clear;
6106
6107 /* Send UNITDATA REQ on RSL side */
6108 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6109 /* Expect it to arrive on the other side */
6110 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006111 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006112 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006113 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006114 }
6115
6116 /* release the channel */
6117 f_rsl_chan_deact();
6118 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6119 f_rslem_unregister(0, g_chan_nr);
6120}
6121testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6122 var octetstring l3 := f_rnd_octstring(15);
6123 var RllTestCases tcs := {
6124 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6125 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6126 };
6127 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6128}
6129testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6130 var octetstring l3 := f_rnd_octstring(19);
6131 var RllTestCases tcs := {
6132 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6133 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6134 };
6135 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6136}
6137
6138/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6139private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6140 var RllTestCase tc := g_pars.spec.rll;
6141
6142 f_l1_tune(L1CTL);
6143 RSL.clear;
6144
6145 f_est_dchan();
6146 L1CTL.clear;
6147
6148 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006149 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006150 /* Expdct RLL UNITDATA IND on RSL side */
6151 alt {
6152 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6153 setverdict(pass);
6154 }
6155 [] RSL.receive { repeat; }
6156 }
6157
6158 /* release the channel */
6159 f_rsl_chan_deact();
6160 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6161 f_rslem_unregister(0, g_chan_nr);
6162}
6163testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006164 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006165 var RllTestCases tcs := {
6166 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6167 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6168 };
6169 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6170}
6171testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6172 var octetstring l3 := f_rnd_octstring(18);
6173 var RllTestCases tcs := {
6174 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6175 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6176 };
6177 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6178}
6179
Harald Weltee613f962018-04-18 22:38:16 +02006180/***********************************************************************
6181 * Encryption Related
6182 ***********************************************************************/
6183
6184/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006185private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006186 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6187 if (link_id.c == SACCH) {
6188 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6189 } else {
6190 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6191 }
6192}
6193
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006194/* Expect (or not expect) other kinds of messages */
6195private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6196 [exp_any] RSL.receive { repeat; }
6197 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006199 }
6200}
6201
Harald Weltee613f962018-04-18 22:38:16 +02006202/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006203private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006204 RslLinkId link_id,
6205 octetstring l3,
6206 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006207 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006208) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006209 timer T := 3.0;
6210 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6211 T.start;
6212 /* Expect RLL UNITDATA IND on RSL side */
6213 alt {
6214 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6215 setverdict(pass);
6216 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006217 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006218 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006219 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006221 }
Harald Weltee613f962018-04-18 22:38:16 +02006222 }
6223}
6224
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006225/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6226private function f_data_mo(
6227 RslLinkId link_id,
6228 boolean p, uint3_t nr, uint3_t ns,
6229 octetstring l3,
6230 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006231 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006232) runs on ConnHdlr {
6233 timer T := 3.0;
6234 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6235 T.start;
6236 /* Expect RLL DATA IND on RSL side */
6237 alt {
6238 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6239 setverdict(pass);
6240 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006241 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006242 [] as_rsl_any_ind(exp_any);
6243 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006245 }
6246 }
6247}
6248
Harald Weltee613f962018-04-18 22:38:16 +02006249/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006250private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006251 f_l1_tune(L1CTL);
6252 f_est_dchan(true);
6253
6254 /* now we actually need to transmit some data both ways to check if the encryption works */
6255 var L1ctlDlMessage dl;
6256
Stefan Sperling603d98e2018-07-25 16:47:28 +02006257 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006258 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6259
6260 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6261 f_unitdata_mt(link_id, l3);
6262
6263 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6264 f_unitdata_mo(link_id, l3);
6265
6266 /* release the channel */
6267 f_rsl_chan_deact();
6268 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6269 f_rslem_unregister(0, g_chan_nr);
6270}
6271testcase TC_chan_act_a51() runs on test_CT {
6272 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6273 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6274 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6275}
6276testcase TC_chan_act_a52() runs on test_CT {
6277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6278 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6279 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6280}
6281testcase TC_chan_act_a53() runs on test_CT {
6282 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6283 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6284 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6285}
6286
Eric Wildf1827a72019-05-28 17:37:35 +02006287/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6288 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 +07006289private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006290 f_l1_tune(L1CTL);
6291 f_est_dchan(true);
6292
6293 /* now we actually need to transmit some data both ways to check if the encryption works */
6294 var L1ctlDlMessage dl;
6295
6296 var octetstring l3 := f_rnd_octstring(20);
6297 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6298
6299 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6300 f_unitdata_mt(link_id, l3);
6301
6302 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6303 f_unitdata_mo(link_id, l3);
6304
6305 var RSL_Message rsl;
6306 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6307
6308 /* modify key to break proper encryption */
6309 g_pars.encr.key := f_rnd_octstring(8);
6310 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6311 rsl.ies := rsl.ies & { ei };
6312 RSL.send(rsl);
6313
6314 timer T0 := 1.0;
6315 T0.start;
6316 /* Expect RSL MODIFY ACK */
6317 alt {
6318 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6319 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6321 }
6322 [] T0.timeout {
6323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6324 }
6325 }
6326
6327 var octetstring l3msg := f_rnd_octstring(15);
6328 timer T1 := 3.0;
6329 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6330 due to broken encryption */
6331 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6332 T1.start;
6333 alt {
6334 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6336 }
6337 [] T1.timeout {
6338 setverdict(pass);
6339 }
6340 }
6341
6342 /* release the channel */
6343 f_rsl_chan_deact();
6344 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6345 f_rslem_unregister(0, g_chan_nr);
6346}
6347testcase TC_rsl_modify_encr() runs on test_CT {
6348 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6349 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6350 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6351}
Harald Weltee613f962018-04-18 22:38:16 +02006352
6353/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006354private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006355 /* L3 payload doesn't matter, as it is passed transparently */
6356 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6357 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6358 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6359
6360 f_l1_tune(L1CTL);
6361
6362 /* first establish a dedicated channel in the clear */
6363 f_est_dchan(false);
6364
6365 /* Establish ABM */
6366 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6367
6368 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6369 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6370 /* expect the L3 to arrive still unencrypted on the MS side */
6371 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6372
6373 /* configure L1 to apply ciphering */
6374 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6375 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6376
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006377 /* send first ciphered I-frame in response and expect it on RSL */
6378 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006379
6380 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6381 * and hence enable encryption also on the downlink */
6382
6383 /* expect bi-directional communication work in encrypted mode */
6384 f_unitdata_mo(link_id, f_rnd_octstring(15));
6385 f_unitdata_mt(link_id, f_rnd_octstring(15));
6386
6387 /* release the channel */
6388 f_rsl_chan_deact();
6389 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6390 f_rslem_unregister(0, g_chan_nr);
6391}
6392testcase TC_encr_cmd_a51() runs on test_CT {
6393 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6394 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6395 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6396}
6397testcase TC_encr_cmd_a52() runs on test_CT {
6398 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6399 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6400 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6401}
6402testcase TC_encr_cmd_a53() runs on test_CT {
6403 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6404 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6405 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6406}
6407
6408private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6409 var LapdmFrame lf;
6410 var octetstring reenc;
6411
6412 /* decode the LAPDm frame */
6413 if (ischosen(exp_match.ab)) {
6414 lf.ab := dec_LapdmFrameAB(enc);
6415 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006417 }
6418
6419 /* check if decoder result matches expectation */
6420 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006422 } else {
6423 log(name, ": matched");
6424 setverdict(pass);
6425 }
6426
6427 /* test if re-encoded frame equals original input */
6428 reenc := enc_LapdmFrame(lf);
6429 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006431 } else {
6432 setverdict(pass);
6433 }
6434}
6435
6436testcase TC_lapdm_selftest() runs on test_CT {
6437 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6438 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6439 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6440 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6441 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6442 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6443 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6444}
6445
Stefan Sperling4880be42018-08-07 18:12:59 +02006446/***********************************************************************
6447 * DTX Related (see GSM 05.08, section 8.3)
6448 ***********************************************************************/
6449
6450/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006451private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006452 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6453 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6454 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6455 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6456}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006457private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006458 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6459 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6460}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006461private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006462 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6463 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6464 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6465 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6466}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006467private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006468 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6469 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6470 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6471 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6472 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6473 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6474 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6475 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6476}
6477
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006478private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006479 var L1ctlDlMessage dl;
6480 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6481 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6482 var GsmFrameNumber first_fn;
6483 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006484 var integer nfill_frames_sacch := 0;
6485 var integer nfill_frames_nonsacch := 0;
6486 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006487 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6488 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006489 const integer frame_dtx_tchf_mod := 104;
6490 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6491 * which operates in terms of blocks rather than frames. */
6492 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6493 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006494 timer T := 5.0;
6495
6496 f_l1_tune(L1CTL);
6497 RSL.clear;
6498 L1CTL.clear;
6499
6500 /* activate TCHF signalling channel */
6501 f_est_dchan(false);
6502
6503 T.start;
6504 alt {
6505 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6506 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6507 var octetstring l2 := dl.payload.data_ind.payload;
6508
6509 if (is_first_frame) {
6510 is_first_frame := false;
6511 first_fn := dl.dl_info.frame_nr;
6512 }
6513
6514 if (dl.dl_info.link_id.c == SACCH) {
6515 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6516 if (not match(l2_fill_frame_sacch, l2)) {
6517 repeat;
6518 }
6519 } else if (not match(l2_fill_frame, l2)) {
6520 repeat;
6521 }
6522
6523 if (dtxd) {
6524 if (not f_g_chan_is_tchf()) {
6525 T.stop;
6526 f_rsl_chan_deact();
6527 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006528 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 +02006529 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006530 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006531 T.stop;
6532 f_rsl_chan_deact();
6533 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006534
6535 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6536 * 2 SACCH, 1 TCH/F */
6537 expected_fill_frames := 3;
6538
6539 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6540 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6541 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006543 } else {
6544 setverdict(pass);
6545 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006546 } else {
6547 if (dl.dl_info.link_id.c == SACCH) {
6548 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006549 repeat;
6550 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006551 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6552 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6553 * we should only see the subset of frames numbers which correspond to a block boundary.
6554 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6555 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6556 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6557 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6558 repeat;
6559 }
6560 }
6561 log("Received DTX TCH fill frame with bad frame number: ", fn,
6562 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6563 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6564 f_rsl_chan_deact();
6565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006567 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006568 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006569 if (dl.dl_info.link_id.c == SACCH) {
6570 nfill_frames_sacch := nfill_frames_sacch + 1;
6571 } else {
6572 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6573 }
6574 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006575 T.stop;
6576 if (f_g_chan_is_tchf()) {
6577 /* Without DTX we can expect 25 fill frames for every 104 frames.
6578 * (24 FACCH + 1 SACCH filling) */
6579 expected_fill_frames := 25;
6580 } else if (f_g_chan_is_tchh()) {
6581 /* We can expect 2 fill frames for every 104 frames. */
6582 expected_fill_frames := 2;
6583 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6584 /* We can expect 5 fill frames for every 104 frames. */
6585 expected_fill_frames := 5;
6586 } else {
6587 f_rsl_chan_deact();
6588 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006590 }
6591
6592 f_rsl_chan_deact();
6593 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006594
6595 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006596 setverdict(pass);
6597 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006598 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6599 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006601 }
6602 } else {
6603 repeat;
6604 }
6605 }
6606 }
6607 [] L1CTL.receive { repeat; }
6608 [] T.timeout {
6609 f_rsl_chan_deact();
6610 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006612 }
6613 }
6614}
6615
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006616private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006617 f_test_l2_fill_frames(false);
6618}
6619
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006620private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006621 f_test_l2_fill_frames(true);
6622}
6623
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006624private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006625 var ConnHdlr vc_conn;
6626 var ConnHdlrPars pars;
6627 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006628 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006629 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6630 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6631 if (dtxd) {
6632 if (i >= 4) { /* DTX is only allowed on TCH/F */
6633 break;
6634 }
6635 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6636 } else {
6637 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6638 }
6639 vc_conn.done;
6640 }
6641}
6642
6643/* Verify that L2 fill frames are sent on TCH in signaling mode if
6644 * there is nothing to transmit while DTX is disabled on downlink. */
6645testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6646 f_tch_sign_l2_fill_frame(false);
6647}
6648
6649/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6650 * there is nothing to transmit while DTX is enabled on downlink. */
6651testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6652 f_tch_sign_l2_fill_frame(true);
6653}
Harald Welte0472ab42018-03-12 15:02:26 +01006654
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006655testcase TC_chopped_ipa_ping() runs on test_CT {
6656 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6657}
6658
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006659testcase TC_chopped_ipa_payload() runs on test_CT {
6660 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6661}
6662
Harald Welte0472ab42018-03-12 15:02:26 +01006663/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6664/* protocol error as per 44.006 */
6665/* link layer failure (repetition of I-frame N200 times without ACK */
6666/* repetition of SABM or DISC N200 times without ACK */
6667/* receptiom of SABM in multi-frame established state */
6668
6669
Harald Welte68e495b2018-02-25 00:05:57 +01006670/* TODO Areas:
6671
6672* channel activation
6673** with BS_Power / MS_Power, bypassing power control loop
6674** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006675** with timing advance from initial activation on
6676* mode modify
6677** encryption
6678** multirate
6679* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006680** unsupported algorithm
6681* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006682* BS Power Control
6683* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006684* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006685* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006686** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006687* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006688** DATA_IND from BTS->PCU
6689** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006690
6691*/
Harald Welte70767382018-02-21 12:16:40 +01006692
6693control {
6694 execute( TC_chan_act_stress() );
6695 execute( TC_chan_act_react() );
6696 execute( TC_chan_deact_not_active() );
6697 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006698 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006699 execute( TC_sacch_filling() );
6700 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006701 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006702 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006703 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006704 execute( TC_sacch_chan_act_ho_async() );
6705 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006706 execute( TC_rach_content() );
6707 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006708 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006709 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006710 execute( TC_rach_load_idle_thresh0() );
6711 execute( TC_rach_load_idle_below_thresh() );
6712 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006713 execute( TC_meas_res_sign_tchf() );
6714 execute( TC_meas_res_sign_tchh() );
6715 execute( TC_meas_res_sign_sdcch4() );
6716 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006717 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006718 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006719 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006720 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006721 execute( TC_rsl_bs_pwr_static_ass() );
6722 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006723 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006724 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006725 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006726 execute( TC_rsl_ms_pwr_dyn_up() );
6727 execute( TC_rsl_ms_pwr_dyn_down() );
6728 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6729 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006730 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006731 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006732 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006733 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006734 execute( TC_paging_imsi_80percent() );
6735 execute( TC_paging_tmsi_80percent() );
6736 execute( TC_paging_imsi_200percent() );
6737 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006738 execute( TC_rsl_protocol_error() );
6739 execute( TC_rsl_mand_ie_error() );
6740 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006741 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006742 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006743 execute( TC_si_sched_2bis() );
6744 execute( TC_si_sched_2ter() );
6745 execute( TC_si_sched_2ter_2bis() );
6746 execute( TC_si_sched_2quater() );
6747 execute( TC_si_sched_13() );
6748 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006749 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006750 execute( TC_ipa_crcx_twice_not_active() );
6751 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006752 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006753 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006754
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006755 if (mp_pcu_socket != "") {
6756 execute( TC_pcu_act_req() );
6757 execute( TC_pcu_act_req_wrong_ts() );
6758 execute( TC_pcu_act_req_wrong_bts() );
6759 execute( TC_pcu_act_req_wrong_trx() );
6760 execute( TC_pcu_deact_req() );
6761 execute( TC_pcu_deact_req_wrong_ts() );
6762 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006763 if (mp_l1_supports_gprs) {
6764 execute( TC_pcu_data_req_pdtch() );
6765 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006766 execute( TC_pcu_data_req_wrong_bts() );
6767 execute( TC_pcu_data_req_wrong_trx() );
6768 execute( TC_pcu_data_req_wrong_ts() );
6769 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006770 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006771 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006772 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006773 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006774 execute( TC_pcu_data_req_imm_ass_pch() );
6775 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006776 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006777 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006778 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006779 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006780 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006781 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006782 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006783 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006784 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006785 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006786 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006787 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006788 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006789 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006790 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006791 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006792 execute( TC_dyn_osmo_pdch_act_deact() );
6793 execute( TC_dyn_osmo_pdch_double_act() );
6794 execute( TC_dyn_ipa_pdch_act_deact() );
6795 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6796
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006797 } else {
6798 log("PCU socket path not available, skipping PCU tests");
6799 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006800
Harald Welte3d04ae62018-04-04 20:29:05 +02006801 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006802 execute( TC_dyn_osmo_pdch_tchf_act() );
6803 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006804 execute( TC_dyn_ipa_pdch_tchf_act() );
6805 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006806
6807 execute( TC_rll_est_ind() );
6808 execute( TC_rll_est_req_DCCH_3() );
6809 execute( TC_rll_est_req_ACCH_3() );
6810 execute( TC_rll_rel_ind_DCCH_0() );
6811 execute( TC_rll_rel_ind_DCCH_3() );
6812 execute( TC_rll_rel_ind_ACCH_0() );
6813 execute( TC_rll_rel_ind_ACCH_3() );
6814 execute( TC_rll_rel_req() );
6815 execute( TC_rll_unit_data_req_DCCH() );
6816 execute( TC_rll_unit_data_req_ACCH() );
6817 execute( TC_rll_unit_data_ind_DCCH() );
6818 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006819
6820 execute( TC_chan_act_a51() );
6821 execute( TC_chan_act_a52() );
6822 execute( TC_chan_act_a53() );
6823 execute( TC_encr_cmd_a51() );
6824 execute( TC_encr_cmd_a52() );
6825 execute( TC_encr_cmd_a53() );
6826
Harald Welteee25aae2019-05-19 14:32:37 +02006827 execute( TC_err_rep_wrong_mdisc() );
6828 execute( TC_err_rep_wrong_msg_type() );
6829 execute( TC_err_rep_wrong_sequence() );
6830
Harald Weltee613f962018-04-18 22:38:16 +02006831 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006832
6833 execute( TC_tch_sign_l2_fill_frame() );
6834 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006835
6836 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006837 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006838}
6839
6840
6841}