blob: 47f8a299ce43c778112478e0043a58a69c01b73b [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,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200325 rest_octets := 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,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200350 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100351 }
352 }
353}
354
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700355private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100356runs on test_CT {
357 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700358 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100359}
360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100362runs on test_CT {
363 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
364 log("Setting ", rsl_si_type, ": ", si_dec);
365 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
366}
367
Harald Welte505cf9b2018-09-15 17:47:23 +0300368friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100369 map(self:BTSVTY, system:BTSVTY);
370 f_vty_set_prompts(BTSVTY);
371 f_vty_transceive(BTSVTY, "enable");
372}
373
Harald Welte505cf9b2018-09-15 17:47:23 +0300374friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200375 map(self:BSCVTY, system:BSCVTY);
376 f_vty_set_prompts(BSCVTY, "OsmoBSC");
377 f_vty_transceive(BSCVTY, "enable");
378}
379
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200380friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
381 map(self:BSCVTY, system:BSCVTY);
382 f_vty_set_prompts(BSCVTY, "OsmoBSC");
383 f_vty_transceive(BSCVTY, "enable");
384}
385
Harald Welte883340c2018-02-28 18:59:29 +0100386/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200387private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
388 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100389 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200390 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
391 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100392 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200393 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100395 }
396}
397
Harald Weltef26de0b2018-04-04 20:28:05 +0200398private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
399 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100400 timer T := 2.0;
401 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100402 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200403 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100404 return;
405 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200406 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100407
408 T.start;
409 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200410 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100411 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100413 }
414 }
415}
416
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700417private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
418 out integer trxc_conn_id) {
419 var Result res;
420
421 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
422 "", -1, -1, { udp := {} }, {});
423 if (not ispresent(res.connId)) {
424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
425 "Could not connect to the control (TRXC) interface " &
426 "of FakeTRX, check your configuration");
427 }
428 trxc_conn_id := res.connId;
429}
430
Harald Welte70767382018-02-21 12:16:40 +0100431/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700432friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200433 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100434 g_AllChannels := {
435 /* TS 1..4: TCH/F */
436 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
437 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
438 /* TS 5: TCH/H */
439 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
440 /* TS 0: SDCCH/4 */
441 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
442 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
443 /* TS 6: SDCCH/8 */
444 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
445 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
446 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
447 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
448 };
449
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200450 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700451 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200452 g_AllChanTypes := {
453 /* TS 1..4: TCH/F */
454 valueof(ts_RslChanNr_Bm(1)),
455 /* TS 5: TCH/H */
456 valueof(ts_RslChanNr_Lm(5,1)),
457 /* TS 0: SDCCH/4 */
458 valueof(ts_RslChanNr_SDCCH4(0,2)),
459 /* TS 6: SDCCH/8 */
460 valueof(ts_RslChanNr_SDCCH8(6,4))
461 };
462 } else {
463 g_AllChanTypes := {
464 /* TS 1..4: TCH/F */
465 valueof(ts_RslChanNr_Bm(1)),
466 /* TS 0: SDCCH/4 */
467 valueof(ts_RslChanNr_SDCCH4(0,2)),
468 /* TS 6: SDCCH/8 */
469 valueof(ts_RslChanNr_SDCCH8(6,4))
470 };
471 }
Harald Welte70767382018-02-21 12:16:40 +0100472 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100473 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100474 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200475 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100476
477 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100478 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
479 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
480 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
481 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100482
Harald Weltef26de0b2018-04-04 20:28:05 +0200483 map(self:PCU, system:PCU);
484 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100485
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700486 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100487 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488
489 /* Init TRXC interface to FakeTRX */
490 map(self:BTS_TRXC, system:BTS_TRXC);
491 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
492
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700493 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700494 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700495 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700496 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
497 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100498 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200499
500 /* Wait some extra time to make sure the BTS emits a stable carrier.
501 * (this is only relevant when running the tests with a physical BTS.) */
502 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100503}
504
Harald Welte68e495b2018-02-25 00:05:57 +0100505/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700506friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100507 map(self:L1CTL, system:L1CTL);
508 f_connect_reset(L1CTL);
509}
510
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700511private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100512
513/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700514friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
515 boolean pcu_comp := false,
516 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100517runs on test_CT return ConnHdlr {
518 var charstring id := testcasename();
519 var ConnHdlr vc_conn;
520
521 vc_conn := ConnHdlr.create(id);
522 /* connect to RSL Emulation main component */
523 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
524 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700525
526 /* The ConnHdlr component may want to talk to some ports directly,
527 * so we disconnect it from the test_CT and connect it to the component.
528 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200529 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200530 unmap(self:PCU, system:PCU);
531 map(vc_conn:PCU, system:PCU);
532 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700533 if (trxc_comp) {
534 unmap(self:BTS_TRXC, system:BTS_TRXC);
535 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
536 }
Harald Welte70767382018-02-21 12:16:40 +0100537
538 vc_conn.start(f_handler_init(fn, id, pars));
539 return vc_conn;
540}
541
Harald Welte70767382018-02-21 12:16:40 +0100542private altstep as_Tguard() runs on ConnHdlr {
543 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100545 }
546}
547
Harald Welte990a3612019-05-27 14:02:13 +0200548friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
549 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100550}
551
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700552private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100553 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700554 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100555}
556
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700557private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100558 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700559 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100560}
561
562/* first function started in ConnHdlr component */
563private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
564runs on ConnHdlr {
565 g_pars := pars;
566 g_chan_nr := pars.chan_nr;
567
568 map(self:L1CTL, system:L1CTL);
569 f_connect_reset(L1CTL);
570
Harald Welted48c0c72019-06-05 10:01:15 +0200571 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700572 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100573 }
Harald Welte70767382018-02-21 12:16:40 +0100574
575 g_Tguard.start(pars.t_guard);
576 activate(as_Tguard());
577
578 f_rslem_register(0, pars.chan_nr);
579
580 /* call the user-supplied test case function */
581 fn.apply(id);
582}
583
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700584private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
585 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200586runs on ConnHdlr return RSL_Message {
587 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100588 timer T := 3.0;
589 RSL.send(tx);
590 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100591 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200592 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100593 T.stop;
594 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100595 }
Harald Welte1eba3742018-02-25 12:48:14 +0100596 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100598 }
Harald Welte21240e62018-03-11 21:43:35 +0100599 [not ignore_other] as_l1_sacch();
600 [not ignore_other] as_meas_res();
601 [not ignore_other] as_l1_dcch();
602 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100604 }
Harald Welte21240e62018-03-11 21:43:35 +0100605 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100606 }
Harald Welteb1726c92018-03-30 11:56:38 +0200607 return rx;
608}
609
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700610friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
611 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200612runs on ConnHdlr {
613 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100614}
615
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700616friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
617 boolean encr_enable := false,
618 RSL_IE_List more_ies := {},
619 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
620runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200621 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200622 if (encr_enable) {
623 /* append encryption related IEs, if requested */
624 var RSL_IE_EncryptionInfo encr_info;
625 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
626 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
627encr_info})) };
628 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200629 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200630 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100631}
632
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700633friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100634 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100635 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100636}
637
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700638/* Default Mobile Allocation to be used for frequency hopping */
639private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
640 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
641
Harald Welte2f2b2b72019-05-31 22:24:57 +0200642friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100643 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700644 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100645 float t_guard := 20.0) := {
646 chan_nr := valueof(chan_nr),
647 chan_mode := valueof(chan_mode),
648 t_guard := t_guard,
649 l1_pars := {
650 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100651 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100652 meas_ul := {
653 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200654 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100655 rxqual := 0
656 },
657 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200658 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100659 rxqual := 0
660 }
661 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200662 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100663 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200664 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200665 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100666 },
Harald Weltee613f962018-04-18 22:38:16 +0200667 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200668 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700669 bts0_band := omit,
670 maio_hsn := maio_hsn,
671 ma_map := c_MA_null,
672 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100673}
674
Harald Welte93640c62018-02-25 16:59:33 +0100675/***********************************************************************
676 * Channel Activation / Deactivation
677 ***********************************************************************/
678
Harald Welte70767382018-02-21 12:16:40 +0100679/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700680private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100681 for (var integer i := 0; i < 500; i := i+1) {
682 f_rsl_chan_act(g_pars.chan_mode);
683 f_rsl_chan_deact();
684 }
685 setverdict(pass);
686}
687testcase TC_chan_act_stress() runs on test_CT {
688 var ConnHdlr vc_conn;
689 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200690 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100691 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
692 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100694}
695
696/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700697private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100698 f_rsl_chan_act(g_pars.chan_mode);
699 /* attempt to activate the same lchan again -> expect reject */
700 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
701 alt {
702 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100704 }
705 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
706 setverdict(pass);
707 }
708 }
709 f_rsl_chan_deact();
710}
711testcase TC_chan_act_react() runs on test_CT {
712 var ConnHdlr vc_conn;
713 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100714 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100715 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
716 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
720/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700721private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100722 timer T := 3.0;
723 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
724 T.start;
725 alt {
726 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
727 setverdict(pass);
728 }
729 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100731 }
732 }
733}
734testcase TC_chan_deact_not_active() runs on test_CT {
735 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100736 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100737 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
738 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100740}
741
742/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700743private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100744 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
745 alt {
746 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100748 }
749 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
750 setverdict(pass);
751 }
752 }
753}
754private type record WrongChanNrCase {
755 RslChannelNr chan_nr,
756 charstring description
757}
758private type record of WrongChanNrCase WrongChanNrCases;
759private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
760 chan_nr := chan_nr,
761 description := desc
762}
763
764testcase TC_chan_act_wrong_nr() runs on test_CT {
765 var ConnHdlr vc_conn;
766 var ConnHdlrPars pars;
767
Harald Welte294b0a22018-03-10 23:26:48 +0100768 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100769
770 var WrongChanNrCases wrong := {
771 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
772 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
773 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
774 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
775 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
776 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
777 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
778 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
779 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
780 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
781 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
782 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
783 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
784 };
785
786 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
787 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
788 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
789 vc_conn.done;
790 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100792}
793
Harald Weltee613f962018-04-18 22:38:16 +0200794/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200795friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200796 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200797 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200798
799 /* test on each of the channels we have */
800 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
801 pars.chan_nr := valueof(g_AllChanTypes[i]);
802
803 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
804 vc_conn := f_start_handler(fn, pars);
805 vc_conn.done;
806 }
807
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200809}
810
Harald Welte93640c62018-02-25 16:59:33 +0100811/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100812 * SACCH handling
813 ***********************************************************************/
814
815private function f_exp_sacch(boolean exp) runs on ConnHdlr {
816 timer T_sacch := 3.0;
817 T_sacch.start;
818 alt {
819 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100821 }
822 [not exp] T_sacch.timeout {
823 setverdict(pass);
824 }
825 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
826 setverdict(pass);
827 }
828 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100830 }
831 [] L1CTL.receive { repeat; }
832 [] RSL.receive { repeat; }
833 }
834}
835
836/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
837private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
838 f_l1_tune(L1CTL);
839 RSL.clear;
840
841 /* activate the logical channel */
842 f_est_dchan();
843 L1CTL.clear;
844
845 /* check that SACCH actually are received as expected */
846 f_exp_sacch(true);
847
848 /* deactivate SACCH on the logical channel */
849 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
850 f_sleep(1.0);
851 L1CTL.clear;
852
853 /* check that no SACCH are received anymore */
854 f_exp_sacch(false);
855
856 /* release the channel */
857 f_rsl_chan_deact();
858 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
859}
860testcase TC_deact_sacch() runs on test_CT {
861 var ConnHdlr vc_conn;
862 var ConnHdlrPars pars;
863 f_init();
864 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
865 //for (var integer i := 0; i < 1; i := i+1) {
866 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
867 log(testcasename(), ": Starting for ", g_AllChannels[i]);
868 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
869 vc_conn.done;
870 }
871 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100873}
874
Harald Welte55700662018-03-12 13:15:43 +0100875/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100876private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
877 var L1ctlDlMessage dl;
878 /* check that the specified SI5 value is actually sent */
879 timer T_sacch := 3.0;
880 L1CTL.clear;
881 T_sacch.start;
882 alt {
883 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
884 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
885 if (match(l3, l3_exp)) {
886 setverdict(pass);
887 } else {
888 repeat;
889 }
890 }
891 [] L1CTL.receive { repeat; }
892 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100894 }
895 }
896}
897
Harald Welte55700662018-03-12 13:15:43 +0100898/* verify that given SACCH payload is not present */
899private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
900 var L1ctlDlMessage dl;
901 /* check that the specified SI5 value is actually sent */
902 timer T_sacch := 3.0;
903 L1CTL.clear;
904 T_sacch.start;
905 alt {
906 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
907 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
908 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100910 } else {
911 repeat;
912 }
913 }
914 [] L1CTL.receive { repeat; }
915 [] T_sacch.timeout {
916 setverdict(pass);
917 }
918 }
919}
920
Harald Welte629cc6b2018-03-11 17:19:05 +0100921/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100922private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
923 /* Set a known default SACCH filling for SI5 */
924 var octetstring si5 := f_rnd_octstring(19);
925 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
926
927 f_l1_tune(L1CTL);
928 RSL.clear;
929
930 /* activate the logical channel */
931 f_est_dchan();
932
933 /* check that the specified SI5 value is actually sent */
934 f_sacch_present(si5);
935
936 /* release the channel */
937 RSL.clear;
938 f_rsl_chan_deact();
939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
940}
941testcase TC_sacch_filling() runs on test_CT {
942 var ConnHdlr vc_conn;
943 var ConnHdlrPars pars;
944 f_init();
945 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
946 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
947 log(testcasename(), ": Starting for ", g_AllChannels[i]);
948 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
949 vc_conn.done;
950 }
951 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100953}
954
Harald Welte629cc6b2018-03-11 17:19:05 +0100955/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100956private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
957 /* Set a known default SACCH filling for SI5 */
958 var octetstring si5 := f_rnd_octstring(19);
959 var octetstring si5_diff := f_rnd_octstring(19);
960 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
961
962 f_l1_tune(L1CTL);
963 RSL.clear;
964
965 log("Activating channel, expecting standard SI5");
966 /* activate the logical channel */
967 f_est_dchan();
968 /* check that the specified SI5 value is actually sent */
969 f_sacch_present(si5);
970
971 /* set channel-specific different SI5 */
972 log("Setting channel specific SACCH INFO, expecting it");
973 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
974 /* check that the specified lchan-specific value is now used */
975 f_sacch_present(si5_diff);
976
977 /* deactivate the channel and re-activate it, this should result in default SI5 */
978 log("De-activating and re-activating channel, expecting standard SI5");
979 f_rsl_chan_deact();
980 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
981 /* Verify that the TRX-wide default SACCH filling is present again */
982 f_sacch_present(si5);
983
984 /* release the channel */
985 RSL.clear;
986 f_rsl_chan_deact();
987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
988}
989testcase TC_sacch_info_mod() runs on test_CT {
990 var ConnHdlr vc_conn;
991 var ConnHdlrPars pars;
992 f_init();
993 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
994 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
995 log(testcasename(), ": Starting for ", g_AllChannels[i]);
996 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
997 vc_conn.done;
998 }
999 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001001}
1002
Harald Welte075d84c2018-03-12 13:07:24 +01001003/* Test SACCH scheduling of multiple different SI message types */
1004private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1005 var octetstring si5 := f_rnd_octstring(19);
1006 var octetstring si5bis := f_rnd_octstring(19);
1007 var octetstring si5ter := f_rnd_octstring(19);
1008 var octetstring si6 := f_rnd_octstring(19);
1009
1010 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1011 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1012 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1013 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1014
1015 f_l1_tune(L1CTL);
1016 RSL.clear;
1017
1018 /* activate the logical channel */
1019 f_est_dchan();
1020 L1CTL.clear;
1021
1022 /* check that SACCH actually are received as expected */
1023 f_sacch_present(si5);
1024 f_sacch_present(si5bis);
1025 f_sacch_present(si5ter);
1026 f_sacch_present(si6);
1027
1028 /* release the channel */
1029 f_rsl_chan_deact();
1030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1031}
1032testcase TC_sacch_multi() runs on test_CT {
1033 var ConnHdlr vc_conn;
1034 var ConnHdlrPars pars;
1035 f_init();
1036 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1037 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1038 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1039 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1040 vc_conn.done;
1041 }
1042 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001044}
1045
Harald Welte55700662018-03-12 13:15:43 +01001046/* Test if SACH information is modified as expected */
1047private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1048 var octetstring si5 := f_rnd_octstring(19);
1049 var octetstring si6 := f_rnd_octstring(19);
1050
1051 /* First, configure both SI5 and SI6 to be transmitted */
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 /* activate the logical channel */
1059 f_est_dchan();
1060 L1CTL.clear;
1061
1062 /* check that SACCH actually are received as expected */
1063 f_sacch_present(si5);
1064 f_sacch_present(si6);
1065
1066 /* disable SI6 */
1067 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1068
1069 /* check that SI5 is still transmitted */
1070 f_sacch_present(si5);
1071 /* check if SI6 is now gone */
1072 f_sacch_missing(si6);
1073
1074 /* release the channel */
1075 f_rsl_chan_deact();
1076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1077}
1078testcase TC_sacch_multi_chg() runs on test_CT {
1079 var ConnHdlr vc_conn;
1080 var ConnHdlrPars pars;
1081 f_init();
1082 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1083 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1084 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1085 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1086 vc_conn.done;
1087 }
1088 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001090}
1091
Harald Weltec8d363c2019-05-19 20:36:48 +02001092/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1093private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1094 var octetstring si5 := f_rnd_octstring(19);
1095 var octetstring si6 := f_rnd_octstring(19);
1096 var octetstring si5_specific := f_rnd_octstring(19);
1097 var octetstring si6_specific := f_rnd_octstring(19);
1098
1099 /* First, configure both SI5 and SI6 to be transmitted */
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1102
1103 f_l1_tune(L1CTL);
1104 RSL.clear;
1105
1106 /* activate channel with different SACCH filling */
1107 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1108 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1109 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1110 }));
1111 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1112 RSL_IE_Body:{sacch_info := sacch_info})) };
1113 f_est_dchan(more_ies := addl_ies);
1114
1115 /* check that SACCH actually are received as expected */
1116 f_sacch_present(si5_specific);
1117 f_sacch_present(si6_specific);
1118
1119 /* release the channel */
1120 f_rsl_chan_deact();
1121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1122}
1123testcase TC_sacch_chan_act() runs on test_CT {
1124 var ConnHdlr vc_conn;
1125 var ConnHdlrPars pars;
1126 f_init();
1127
1128 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1129 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1130 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1131 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1132 vc_conn.done;
1133 }
1134 /* TODO: do the above in parallel, rather than sequentially? */
1135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1136}
1137
Harald Welte8b01c792019-05-19 22:51:25 +02001138/* verify that SACCH DL transmission is started only if MS power IE present
1139 * see section 4.1.3 of 3GPP TS 48.058 */
1140private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1141 var octetstring si5 := f_rnd_octstring(19);
1142
1143 f_l1_tune(L1CTL);
1144 RSL.clear;
1145
1146 /* Step 1: Activate ASYNC HO channel without MS power IE */
1147
1148 /* Activate channel on BTS side */
1149 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1150 /* don't perform immediate assignment here, as we're testing non-IA case */
1151 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001152 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001153
1154 /* Verify that no DL SACCH is being received */
1155 f_sacch_missing(?);
1156
1157 f_rsl_chan_deact();
1158 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1159
1160
1161 /* Step 2: Activate ASYNC HO channel with MS power IE */
1162
1163 /* Activate channel on BTS side */
1164 var RSL_IE_List addl_ies := {
1165 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1166 };
1167 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1168 /* don't perform immediate assignment here, as we're testing non-IA case */
1169 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001170 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001171
1172 /* Verify that DL SACCH is being received */
1173 f_sacch_present(si5);
1174
1175 f_rsl_chan_deact();
1176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1177}
1178testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1179 var ConnHdlr vc_conn;
1180 var ConnHdlrPars pars;
1181 f_init();
1182
1183 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1184 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1185 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1186 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1187 vc_conn.done;
1188 }
1189 /* TODO: do the above in parallel, rather than sequentially? */
1190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1191}
1192
1193/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1194 * see section 4.1.4 of 3GPP TS 48.058 */
1195private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1196 var octetstring si5 := f_rnd_octstring(19);
1197 var RSL_IE_List addl_ies;
1198
1199 f_l1_tune(L1CTL);
1200 RSL.clear;
1201
1202 /* Step 1: Activate SYNC HO channel without MS power IE */
1203
1204 /* Activate channel on BTS side */
1205 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1206 /* don't perform immediate assignment here, as we're testing non-IA case */
1207 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001208 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001209
1210 /* Verify that no DL SACCH is being received */
1211 f_sacch_missing(?);
1212
1213 f_rsl_chan_deact();
1214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1215
1216
1217 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1218
1219 /* Activate channel on BTS side */
1220 addl_ies := {
1221 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1222 };
1223 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1224 /* don't perform immediate assignment here, as we're testing non-IA case */
1225 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001226 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001227
1228 /* Verify that no DL SACCH is being received */
1229 f_sacch_missing(?);
1230
1231 f_rsl_chan_deact();
1232 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1233
1234
1235 /* Step 2b: Activate SYNC HO channel with TA IE */
1236
1237 /* Activate channel on BTS side */
1238 addl_ies := {
1239 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1240 };
1241 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1242 /* don't perform immediate assignment here, as we're testing non-IA case */
1243 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001244 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001245
1246 /* Verify that no DL SACCH is being received */
1247 f_sacch_missing(?);
1248
1249 f_rsl_chan_deact();
1250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1251
1252
1253 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1254
1255 /* Activate channel on BTS side */
1256 addl_ies := {
1257 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1258 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1259 };
1260 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1261 /* don't perform immediate assignment here, as we're testing non-IA case */
1262 /* enable dedicated mode */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001263 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Harald Welte8b01c792019-05-19 22:51:25 +02001264
1265 /* Verify that DL SACCH is being received */
1266 f_sacch_present(si5);
1267
1268 f_rsl_chan_deact();
1269 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1270}
1271testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1272 var ConnHdlr vc_conn;
1273 var ConnHdlrPars pars;
1274 f_init();
1275
1276 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1277 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1278 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1279 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1280 vc_conn.done;
1281 }
1282 /* TODO: do the above in parallel, rather than sequentially? */
1283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1284}
Harald Welte629cc6b2018-03-11 17:19:05 +01001285
1286
1287/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001288 * RACH Handling
1289 ***********************************************************************/
1290
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291/* like L1SAP_IS_PACKET_RACH */
1292private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001293 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 return true;
1295 }
1296 return false;
1297}
1298
Philipp Maier16ade782020-07-08 21:36:00 +02001299private function ra_is_emerg(OCT1 ra) return boolean {
1300 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1301 if ((ra and4b 'E0'O == 'A0'O) and (ra and4b '1F'O != '1F'O)) {
1302 return true;
1303 }
1304 return false;
1305}
1306
Harald Welte8c24c2b2018-02-26 08:31:31 +01001307/* generate a random RACH for circuit-switched */
1308private function f_rnd_ra_cs() return OCT1 {
1309 var OCT1 ra;
1310 do {
1311 ra := f_rnd_octstring(1);
1312 } while (ra_is_ps(ra));
1313 return ra;
1314}
1315
Philipp Maier16ade782020-07-08 21:36:00 +02001316/* generate a random RACH for emergency */
1317private function f_rnd_ra_emerg() return OCT1 {
1318 var OCT1 ra;
1319 do {
1320 ra := f_rnd_octstring(1);
1321 } while (not ra_is_emerg(ra));
1322 return ra;
1323}
1324
Harald Welte883340c2018-02-28 18:59:29 +01001325/* generate a random RACH for packet-switched */
1326private function f_rnd_ra_ps() return OCT1 {
1327 var OCT1 ra;
1328 do {
1329 ra := f_rnd_octstring(1);
1330 } while (not ra_is_ps(ra));
1331 return ra;
1332}
1333
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001334/* generate a random 11-bit RA (packet-switched only) */
1335private function f_rnd_ra11_ps() return BIT11 {
1336 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1337 return int2bit(ra11, 11);
1338}
1339
Harald Welte8c24c2b2018-02-26 08:31:31 +01001340/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001341private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001342 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001343 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001344 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001345
Harald Welte8c24c2b2018-02-26 08:31:31 +01001346 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001347 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001348 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001349 var OCT1 ra := f_rnd_ra_emerg();
1350 if (emerg == true) {
1351 ra := f_rnd_ra_emerg();
1352 } else {
1353 ra := f_rnd_ra_cs();
1354 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001355 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1356 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001358 }
1359 fn_last := fn;
1360
1361 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001362 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001363 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001364 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001365 T.stop;
1366 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001367 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001369 }
1370 [] RSL_CCHAN.receive { repeat; }
1371 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001372 test_failed := true;
1373 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001374 }
1375 }
1376 }
Maxba06feb2019-03-05 10:52:46 +01001377 if (test_failed) {
1378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001379 }
Maxba06feb2019-03-05 10:52:46 +01001380 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001382}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001383
Philipp Maier16ade782020-07-08 21:36:00 +02001384/* Normal variant */
1385testcase TC_rach_content() runs on test_CT {
1386 f_TC_rach_content(emerg := false);
1387}
1388
1389/* Emergency call variant */
1390testcase TC_rach_content_emerg() runs on test_CT {
1391 f_TC_rach_content(emerg := true);
1392}
1393
Harald Welte8c24c2b2018-02-26 08:31:31 +01001394/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1395testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001396 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001397 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001398 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001399 f_l1_tune(L1CTL);
1400
1401 var GsmFrameNumber fn_last := 0;
1402 for (var integer i := 0; i < 1000; i := i+1) {
1403 var OCT1 ra := f_rnd_ra_cs();
1404 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1405 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001407 }
1408 fn_last := fn;
1409 }
1410 var integer rsl_chrqd := 0;
1411 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001412 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001413 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001414 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001415 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001416 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417 repeat;
1418 }
1419 [] RSL_CCHAN.receive { repeat; }
1420 [] T.timeout { }
1421 }
1422 if (rsl_chrqd == 1000) {
1423 setverdict(pass);
1424 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001426 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001428}
1429
Harald Welte3453ab42019-05-24 21:19:58 +02001430private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1431 var charstring bts_str := "bts " & int2str(bts_nr);
1432 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1433}
1434
1435/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1436private template integer tr_rach_slots_per_interval := (90 .. 130);
1437
1438/* Expect 0 RACH load on an idle BTS that has just started up */
1439testcase TC_rach_load_idle_thresh0() runs on test_CT {
1440 var ASP_RSL_Unitdata rx_ud;
1441
1442 f_init_vty_bsc();
1443 /* send load indications even at 0% load */
1444 f_vty_load_ind_thresh(0);
1445 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1446 f_sleep(2.0);
1447
1448 f_init();
1449
1450 timer T := 5.0;
1451 T.start;
1452 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001453 [] 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 +02001454 setverdict(pass);
1455 repeat;
1456 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001457 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001458 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1459 repeat;
1460 }
1461 [] RSL_CCHAN.receive {
1462 repeat;
1463 }
1464 [] T.timeout { }
1465 }
1466
1467 f_vty_load_ind_thresh(10);
1468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1469}
1470
1471/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1472testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1473 var ASP_RSL_Unitdata rx_ud;
1474
1475 f_init_vty_bsc();
1476 f_init();
1477
1478 timer T := 5.0;
1479 T.start;
1480 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001481 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001482 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1483 repeat;
1484 }
1485 [] RSL_CCHAN.receive {
1486 repeat;
1487 }
1488 [] T.timeout {
1489 setverdict(pass);
1490 }
1491 }
1492
1493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1494}
1495
1496/* Expect 0 RACH load on an idle BTS that has just started up */
1497testcase TC_rach_load_count() runs on test_CT {
1498 var ASP_RSL_Unitdata rx_ud;
1499 var integer load_access_count := 0;
1500
1501 f_init_vty_bsc();
1502 /* send load indications even at 0% load */
1503 f_vty_load_ind_thresh(0);
1504 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1505 f_sleep(2.0);
1506 f_init();
1507
1508 f_init_l1ctl();
1509 f_sleep(1.0);
1510 f_l1_tune(L1CTL);
1511
1512 var GsmFrameNumber fn_last := 0;
1513 for (var integer i := 0; i < 1000; i := i+1) {
1514 var OCT1 ra := f_rnd_ra_cs();
1515 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1516 if (fn == fn_last) {
1517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1518 }
1519 fn_last := fn;
1520 }
1521
1522 timer T := 5.0;
1523 T.start;
1524 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001525 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001526 -> value rx_ud {
1527 var RSL_IE_Body ie;
1528 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1529 load_access_count := load_access_count + ie.rach_load.access_count;
1530 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1531 setverdict(fail, "Access count cannot be < Busy count");
1532 }
1533 repeat;
1534 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001535 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001536 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1537 repeat;
1538 }
1539 [] RSL_CCHAN.receive {
1540 repeat;
1541 }
1542 [] T.timeout { }
1543 }
1544 if (load_access_count == 1000) {
1545 setverdict(pass);
1546 } else {
1547 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1548 }
1549
1550 f_vty_load_ind_thresh(10);
1551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1552}
1553
Harald Welte54a2a2d2018-02-26 09:14:05 +01001554private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001555 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001556 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001557 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001558 f_sleep(0.5);
1559
1560 /* Transmit RACH request + wait for confirmation */
1561 var OCT1 ra := f_rnd_ra_cs();
1562 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1563
1564 /* Check for expected result */
1565 timer T := 1.5;
1566 T.start;
1567 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001568 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001569 setverdict(pass);
1570 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001571 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001573 }
1574 [] RSL_CCHAN.receive { repeat; }
1575 [not expect_pass] T.timeout {
1576 setverdict(pass);
1577 }
1578 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001580 }
1581 }
1582}
1583
1584/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1585testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001586 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001587 f_init_l1ctl();
1588 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001589 f_sleep(1.0);
1590
1591 /* default max-ta is 63 (full range of GSM timing advance */
1592
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001593 /* We allow early arrival up to 2 symbols */
1594 f_rach_toffs(-1*256, true);
1595 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001596 f_rach_toffs(-10*256, false);
1597
1598 /* 0 / 32 / 63 bits is legal / permitted */
1599 f_rach_toffs(0, true);
1600 f_rach_toffs(32*256, true);
1601 f_rach_toffs(63*256, true);
1602
1603 /* more than 63 bits is not legal / permitted */
1604 f_rach_toffs(64*256, false);
1605 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001607}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001608
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001609private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001610 var GsmFrameNumber fn;
1611 var RSL_Message rm;
1612
1613 f_l1_tune(L1CTL);
1614 RSL.clear;
1615
1616 /* Generate a random Handover Reference */
1617 var integer ho_ref := oct2int(f_rnd_octstring(1));
1618
1619 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1620 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1621 RSL_IE_Body:{ handover_ref := ho_ref }));
1622
1623 /* Activate a channel on the BTS side (no encryption) */
1624 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1625 act_type := t_RSL_IE_ActType_HO_SYNC);
1626
1627 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1628 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07001629 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(g_pars.chan_nr, 7, mp_trx0_arfcn));
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001630
1631 /* Send handover Access Burst */
1632 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1633
1634 /* TODO: test mismatching Handover Reference, and missing IE */
1635
1636 /* Wait for handover detection */
1637 timer T := 3.0;
1638 T.start;
1639 alt {
1640 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1641 log("Handover RACH has been detected: ", rm);
1642 setverdict(pass);
1643 }
1644 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1646 log2str("RSL_CHAN_RQD was not expected: ", rm));
1647 }
1648 [] RSL.receive { repeat; }
1649 [] T.timeout {
1650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1651 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1652 }
1653 }
1654
1655 /* Release the channel */
1656 f_rsl_chan_deact();
1657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1658}
1659
1660/* Test handover RACH detection */
1661testcase TC_ho_rach() runs on test_CT {
1662 var ConnHdlrPars pars;
1663 var ConnHdlr vc_conn;
1664
1665 f_init();
1666
1667 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1668 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1669 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1670 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1671 vc_conn.done;
1672 }
1673
1674 /* TODO: do the above in parallel, rather than sequentially? */
1675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1676}
1677
Harald Welte93640c62018-02-25 16:59:33 +01001678/***********************************************************************
1679 * Measurement Processing / Reporting
1680 ***********************************************************************/
1681
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001682private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001683 spare := '0'B,
1684 lpd := 0,
1685 sapi := sapi,
1686 c_r := c_r,
1687 ea := true
1688}
1689
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001690private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001691 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001692 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001693 len := 0, /* overwritten */
1694 m := false,
1695 el := 1,
1696 payload := pl
1697}
1698
1699/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001700private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001701 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001702 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001703 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001704 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 +01001705 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001706 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001707
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001708 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1709 g_pars.l1_pars.ms_power_level, false,
1710 g_pars.l1_pars.ms_actual_ta);
1711
1712 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1713 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1714
1715 log("Sending Measurement Report: ", l1h, l2);
1716 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001717 repeat;
1718 }
1719}
1720
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001721private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001722 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001723 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001724 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1725 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001726 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1727 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001728 repeat;
1729 }
1730}
1731
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001732private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001733 uint6_t rxlev,
1734 uint3_t rxqual
1735}
1736
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001737private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001738 MeasElem full,
1739 MeasElem sub
1740}
1741
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001742private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001743 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001744 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001745 MeasElemFS meas_ul,
1746 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001747 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001748 uint5_t ms_power_level,
1749 uint8_t ms_actual_ta
1750}
1751
1752/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1753private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1754 return 63 + (toffs256s/256);
1755}
1756
Harald Welted5684392018-03-10 18:22:04 +01001757private function f_max(integer a, integer b) return integer {
1758 if (a > b) {
1759 return a;
1760 } else {
1761 return b;
1762 }
1763}
1764
1765private function f_min(integer a, integer b) return integer {
1766 if (a < b) {
1767 return a;
1768 } else {
1769 return b;
1770 }
1771}
1772
1773/* compute negative tolerance val-tolerance, ensure >= min */
1774private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1775 val := val - tolerance;
1776 return f_max(val, min);
1777}
1778
1779/* compute positive tolerance val+tolerance, ensure <= max */
1780private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1781 val := val + tolerance;
1782 return f_min(val, max);
1783}
1784
1785/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1786private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1787return template integer {
1788 var template integer ret;
1789 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1790 return ret;
1791}
1792
1793
Harald Welte70767382018-02-21 12:16:40 +01001794/* build a template for matching measurement results against */
1795private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1796 var ConnL1Pars l1p := g_pars.l1_pars;
1797 var template RSL_IE_UplinkMeas ul_meas := {
1798 len := 3,
1799 rfu := '0'B,
1800 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001801 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001802 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001803 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001804 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001805 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1806 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001807 supp_meas_info := omit
1808 };
Harald Welte685d5982018-02-27 20:42:05 +01001809 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001810 ul_meas.len := (3+8);
1811 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001812 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001813 toa256_min := ?,
1814 toa256_max := ?,
1815 toa256_std_dev := ?
1816 }
Harald Welte685d5982018-02-27 20:42:05 +01001817 }
Harald Welte70767382018-02-21 12:16:40 +01001818 var template RSL_IE_BS_Power bs_power := {
1819 reserved := 0,
1820 epc := false,
1821 fpc := false,
1822 power_level := l1p.bs_power_level
1823 };
1824 var template RSL_IE_L1Info l1_info := {
1825 ms_power_lvl := l1p.ms_power_level,
1826 fpc := false,
1827 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001828 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001829 };
1830 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001831 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001832 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1833 ?, t_toffs);
1834}
1835
Philipp Maierdd841d32019-12-17 14:44:54 +01001836/* build a template for matching measurement results that do not contain any
1837 * MS related measurement (l1_info, l3_info and ms timing offset). */
1838private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1839 var ConnL1Pars l1p := g_pars.l1_pars;
1840 var template RSL_IE_UplinkMeas ul_meas := {
1841 len := 3,
1842 rfu := '0'B,
1843 dtx_d := l1p.dtx_enabled,
1844 rxlev_f_u := ?,
1845 reserved1 := '00'B,
1846 rxlev_s_u := ?,
1847 reserved2 := '00'B,
1848 rxq_f_u := ?,
1849 rxq_s_u := ?,
1850 supp_meas_info := omit
1851 };
1852 if (l1p.toa256_enabled) {
1853 ul_meas.len := (3+8);
1854 ul_meas.supp_meas_info := {
1855 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1856 toa256_min := ?,
1857 toa256_max := ?,
1858 toa256_std_dev := ?
1859 }
1860 }
1861 var template RSL_IE_BS_Power bs_power := {
1862 reserved := 0,
1863 epc := false,
1864 fpc := false,
1865 power_level := l1p.bs_power_level
1866 };
1867
1868 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1869}
1870
Harald Welte70767382018-02-21 12:16:40 +01001871/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001872private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001873 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001874 var boolean chan_est := false;
1875
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001876 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001877
1878 /* Receive osmocom specific measurement reports. This is the normal
1879 * case. Here we verify that the measurement reports we sent are
1880 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001881 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1882 /* increment counter of next to-be-expected meas rep */
1883 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1884 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001885 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001886
1887 /* The following two cases may only happen in the beginning
1888 * of the channel establishment phase. Once we have received
1889 * the "our" measurement report the first time, the channel
1890 * is established and empty or hardcoded TRXCON reports must
1891 * not occur anymore. */
1892 chan_est := true;
1893
1894 repeat;
1895 }
1896
1897 /* When the BTS has established the channel, the MS might need slightly
1898 * more time to establish the channel and actually start sending. The
1899 * result is then a measurement report that just lacks the measurement
1900 * information of the MS. This is normal and we tolerate this behavior. */
1901 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1902 /* increment counter of next to-be-expected meas rep */
1903 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1904 /* Re-start the timer expecting the next MEAS RES */
1905 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001906 repeat;
1907 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001908
1909 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1910 * measurements if the TTCN3 side does not supply measurement input in
1911 * time. In those cases TRXCON will either use a cached measurement
1912 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1913 * report the templates above will not match. We tolerate this
1914 * behavior, but only once. */
1915 [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 +01001916 /* increment counter of next to-be-expected meas rep */
1917 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1918 if (g_first_meas_res) {
1919 g_first_meas_res := false;
1920 repeat;
1921 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001923 }
Harald Welte70767382018-02-21 12:16:40 +01001924 }
1925 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001927 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001928 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001930 }
1931}
1932
Harald Weltee613f962018-04-18 22:38:16 +02001933private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1934 select (rsl_alg_id) {
1935 case (RSL_ALG_ID_A5_0) { return 0; }
1936 case (RSL_ALG_ID_A5_1) { return 1; }
1937 case (RSL_ALG_ID_A5_2) { return 2; }
1938 case (RSL_ALG_ID_A5_3) { return 3; }
1939 case (RSL_ALG_ID_A5_4) { return 4; }
1940 case (RSL_ALG_ID_A5_5) { return 5; }
1941 case (RSL_ALG_ID_A5_6) { return 6; }
1942 case (RSL_ALG_ID_A5_7) { return 7; }
1943 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1945 /* Make compiler happy by calling mtc.stop here. It is already
1946 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001947 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001948 }
1949 }
1950}
1951
1952private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1953 select (rsl_alg_id) {
1954 case (RSL_ALG_ID_A5_1) { return '000'B; }
1955 case (RSL_ALG_ID_A5_2) { return '001'B; }
1956 case (RSL_ALG_ID_A5_3) { return '010'B; }
1957 case (RSL_ALG_ID_A5_4) { return '011'B; }
1958 case (RSL_ALG_ID_A5_5) { return '100'B; }
1959 case (RSL_ALG_ID_A5_6) { return '101'B; }
1960 case (RSL_ALG_ID_A5_7) { return '110'B; }
1961 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1963 /* Make compiler happy by calling mtc.stop here. It is already
1964 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001965 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001966 }
1967 }
1968}
1969
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001970/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1971private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1972 var GsmFrameNumber fn;
1973 timer T := 8.0;
1974
1975 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1976 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1977
1978 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1979 /* Send the actual RACH */
1980 fn := f_L1CTL_RACH(L1CTL, ra);
1981
1982 T.start;
1983 alt {
1984 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1985 [] T.timeout {
1986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1987 }
1988 }
1989 T.stop
1990 return fn;
1991}
Harald Weltee613f962018-04-18 22:38:16 +02001992
Harald Welte70767382018-02-21 12:16:40 +01001993/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001994private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001995 var GsmFrameNumber fn;
1996 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07001997 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01001998 var integer ra := 23;
1999
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002000 /* Send RACH request and wait for ChanReq */
2001 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002002
2003 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002004 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002005
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002006 /* Craft channel description (with or without frequency hopping parameters) */
2007 if (ispresent(g_pars.maio_hsn)) {
2008 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, maio_hsn := g_pars.maio_hsn));
2009 } else {
2010 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr));
2011 }
2012
Harald Welte70767382018-02-21 12:16:40 +01002013 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002014 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002015 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2016
2017 /* receive IMM.ASS on MS side */
2018 var ImmediateAssignment ia_um;
2019 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002020
2021 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2022 if (ch_desc.h != ia_um.chan_desc.h) {
2023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2024 }
2025
Harald Welte70767382018-02-21 12:16:40 +01002026 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002027 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002028 /* enable encryption, if requested */
2029 if (encr_enable) {
2030 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2031 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2032 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002033
2034 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002035}
2036
2037/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002038private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002039 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002040 RSL.clear;
2041
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002042 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002043 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002044 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002045 }
Harald Welte70767382018-02-21 12:16:40 +01002046
2047 f_est_dchan();
2048
2049 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2050 * RSL measurement reports on Abis side */
2051 timer T := 8.0;
2052 T.start;
2053 alt {
2054 [] as_l1_sacch();
2055 [] as_meas_res();
2056 [] as_l1_dcch();
2057 [] L1CTL.receive { repeat; }
2058 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002059 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002060 * of any earlier errors, so if we reach this timeout, we're good */
2061 setverdict(pass);
2062 }
2063 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002065 }
2066 }
2067 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002068 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002069}
Harald Welte0472ab42018-03-12 15:02:26 +01002070
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002071/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2072private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002073 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002074 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2075 timer Tup := 10.0;
2076 Tup.start;
2077 alt {
2078 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2079 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2080 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002081
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002082 if (rx_lvl != max_rx_lvl) {
2083 repeat;
2084 }
2085 Tup.stop;
2086 }
2087 [] L1CTL.receive { repeat; }
2088 [] Tup.timeout {
2089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2090 log2str("Didn't reach full power ", max_rx_lvl));
2091 }
2092 }
2093 return max_rx_lvl;
2094}
2095
2096/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2097private function f_verify_ramp_up() runs on ConnHdlr {
2098 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002099 var integer initial_rx_lvl := -1;
2100 var integer last_rx_lvl := -1;
2101 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2102
2103 timer T := 2.0;
2104 alt {
2105 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2106 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2107 log("Received rx_level=", rx_lvl);
2108 if (initial_rx_lvl == -1) {
2109 initial_rx_lvl := rx_lvl;
2110 last_rx_lvl := rx_lvl;
2111
2112 /* Expect a somehow low value during first received messages */
2113 if (initial_rx_lvl >= max_rx_lvl / 2) {
2114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2115 log2str("Detected high initial tx power during ramp up: ",
2116 initial_rx_lvl , ", full power is", max_rx_lvl));
2117 }
2118 }
2119
2120 /* received Rx level bigger than maximum allowed power by CN */
2121 if (rx_lvl > max_rx_lvl) {
2122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2123 log2str("Detected Tx power higher than full power: ",
2124 rx_lvl , " > ", max_rx_lvl));
2125 }
2126
2127 /* Make sure it never decreases, since we are rumping up */
2128 if (last_rx_lvl > rx_lvl) {
2129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2130 log2str("Detected Tx power decrease during ramp up: ",
2131 last_rx_lvl , " -> ", rx_lvl));
2132 }
2133
2134 if (rx_lvl == max_rx_lvl and not T.running) {
2135 /* We reached the maximum power, start timer and receive
2136 /* a few more to make sure we don't surpass it */
2137 log("Reached full power, wating a bit more until success");
2138 T.start;
2139 }
2140
2141 last_rx_lvl := rx_lvl;
2142 repeat;
2143 }
2144 [] L1CTL.receive { repeat; }
2145 [] T.timeout { }
2146 }
2147
2148 /* We didn't increase tx power during ramp up */
2149 if (initial_rx_lvl < last_rx_lvl) {
2150 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2151 } else {
2152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2153 log2str("No Tx power increase during whole ramp up: ",
2154 initial_rx_lvl , " -> ", last_rx_lvl));
2155 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002156}
2157
2158/* verify BTS ramps power down to rx_level 0 */
2159private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2160 var L1ctlDlMessage l1_dl;
2161 var integer last_rx_lvl := max_rx_lvl;
2162
2163 timer Tdown := 5.0;
2164 Tdown.start;
2165 alt {
2166 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2167 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2168 log("Received rx_level=", rx_lvl);
2169
2170 /* received Rx level bigger than maximum allowed power by CN */
2171 if (rx_lvl > max_rx_lvl) {
2172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2173 log2str("Detected Tx power higher than full power: ",
2174 rx_lvl , " > ", max_rx_lvl));
2175 }
2176
2177 /* Make sure it never increases, since we are rumping down */
2178 if (last_rx_lvl < rx_lvl) {
2179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2180 log2str("Detected Tx power increase during ramp up: ",
2181 last_rx_lvl , " -> ", rx_lvl));
2182 }
2183
2184 last_rx_lvl := rx_lvl;
2185 if (last_rx_lvl != 0) {
2186 repeat;
2187 }
2188 /* we reached power level 0, we are done */
2189 Tdown.stop;
2190 }
2191 [] L1CTL.receive { repeat; }
2192 [] Tdown.timeout { }
2193 }
2194
2195 /* We didn't increase tx power during ramp down */
2196 if (max_rx_lvl > last_rx_lvl) {
2197 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2198 } else {
2199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2200 log2str("No Tx power decrease during whole ramp down: ",
2201 max_rx_lvl , " -> ", last_rx_lvl));
2202 }
2203}
2204
2205/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002206private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002207 f_l1_tune(L1CTL);
2208 RSL.clear;
2209
2210 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002211
2212 setverdict(pass);
2213}
2214testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2215 var ConnHdlr vc_conn;
2216 var ConnHdlrPars pars;
2217 f_init();
2218 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2219 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2220 pcu_comp := false, trxc_comp := true);
2221 vc_conn.done;
2222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2223}
2224
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002225/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002226private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002227 f_connhdlr_init_vty_bsc();
2228
2229 f_l1_tune(L1CTL);
2230 RSL.clear;
2231
2232 /* Wait until BTS is started and at full power */
2233 var integer max_rx_lvl := f_wait_ramp_up();
2234 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2235
2236 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2237 f_verify_ramp_down(max_rx_lvl);
2238
2239 setverdict(pass);
2240}
2241testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2242 var ConnHdlr vc_conn;
2243 var ConnHdlrPars pars;
2244 f_init();
2245 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2246 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2247 pcu_comp := false, trxc_comp := true);
2248 vc_conn.done;
2249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2250}
2251
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002252/* Verify Tx power:
2253 * + ramping down during ADM state UNLOCKED->LOCKED
2254 * + ramping up during ADM state LOCKED->UNLOCKED
2255 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002256private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002257 var L1ctlDlMessage l1_dl;
2258 var integer last_rx_lvl;
2259
2260 f_connhdlr_init_vty_bsc();
2261
2262 f_l1_tune(L1CTL);
2263 RSL.clear;
2264
2265 /* Wait until BTS is started and at full power */
2266 var integer max_rx_lvl := f_wait_ramp_up();
2267 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2268
2269 log("ADM STATE UNLOCKED->LOCKED");
2270 f_vty_enter_cfg_trx(BSCVTY);
2271 f_vty_transceive(BSCVTY, "rf_locked 1");
2272 last_rx_lvl := max_rx_lvl;
2273 f_verify_ramp_down(max_rx_lvl);
2274
2275 /* Let some time after we received 0dBm, then check we don't receive BCCH
2276 * anymore because scheduler has stopped after ramping down */
2277 f_sleep(2.0);
2278 L1CTL.clear;
2279 timer Tlocked := 2.0;
2280 Tlocked.start;
2281 alt {
2282 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2284 log2str("Received data_ind during rf_locked: ", l1_dl));
2285 }
2286 [] L1CTL.receive { repeat; }
2287 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2288 }
2289
2290 log("ADM STATE LOCKED->UNLOCKED");
2291 f_vty_transceive(BSCVTY, "rf_locked 0");
2292 f_verify_ramp_up();
2293 setverdict(pass);
2294}
2295testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2296 var ConnHdlr vc_conn;
2297 var ConnHdlrPars pars;
2298 f_init();
2299 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2300 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2301 pcu_comp := false, trxc_comp := true);
2302 vc_conn.done;
2303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2304}
2305
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002306private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002307 timer T := 8.0;
2308 T.start;
2309 var RSL_Message rsl;
2310 alt {
2311 [] as_l1_sacch();
2312 [] L1CTL.receive { repeat; }
2313 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2314 if (rsl.ies[3].body.bs_power.power_level == level) {
2315 setverdict(pass)
2316 } else {
2317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2318 }
2319 }
2320 [] T.timeout {
2321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2322 }
2323 }
2324}
2325
2326/* see if the rsl meas res contains our expeced bs power level
2327bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002328private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002329 f_l1_tune(L1CTL);
2330 RSL.clear;
2331
2332 if (mp_bts_trxc_port != -1) {
2333 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2334 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2335 }
2336
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002337 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002338 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2339 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2340
2341 f_est_dchan(more_ies :={valueof(pwr)});
2342
2343 f_check_meas_bs_power_level(pwr_var);
2344
2345 f_rsl_chan_deact();
2346 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2347}
2348
2349/* see if the rsl meas res contains our expeced bs power level
2350bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002351private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002352 f_l1_tune(L1CTL);
2353 RSL.clear;
2354
2355 if (mp_bts_trxc_port != -1) {
2356 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2357 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2358 }
2359
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002360 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002361 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2362
2363 f_est_dchan();
2364
2365 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2366
2367 f_check_meas_bs_power_level(pwr_var);
2368
2369 f_rsl_chan_deact();
2370 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2371}
2372
2373testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2374 var ConnHdlr vc_conn;
2375 var ConnHdlrPars pars;
2376 f_init();
2377 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2378 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2379 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2380 pcu_comp := false, trxc_comp := true);
2381 vc_conn.done;
2382 }
2383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2384}
2385
2386testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2387 var ConnHdlr vc_conn;
2388 var ConnHdlrPars pars;
2389 f_init();
2390 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2391 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2392 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2393 pcu_comp := false, trxc_comp := true);
2394 vc_conn.done;
2395 }
2396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2397}
2398
Eric Wild61edb7e2019-06-03 12:38:31 +02002399/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2400second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2401These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002402private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002403 var uint5_t pwr_var := 7;
2404 var L1ctlDlMessage l1_dl;
2405
2406 f_trxc_fake_rssi(rxlev2dbm(10));
2407 f_l1_tune(L1CTL);
2408 RSL.clear;
2409
2410 var RSL_IE_List addl_ies;
2411 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2412
2413 addl_ies := {
2414 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2415 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2416 };
2417
2418 /* establish with power parameters */
2419 f_est_dchan(more_ies := addl_ies);
2420
2421 /* set a high value to ensure L1 power control level increases */
2422 f_trxc_fake_rssi(rxlev2dbm(20));
2423
2424 timer T2 := 6.0;
2425 T2.start;
2426 alt {
2427 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002428 /* Update sent MS power to follow what BTS requests */
2429 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2430 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002431 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002432 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002433 T2.stop;
2434 }
2435 [] L1CTL.receive { repeat; }
2436 [] T2.timeout {
2437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2438 "Power Level in L1 header has not increased sufficiently");
2439 }
2440 }
2441
2442 /* set a low value to ensure L1 power control level decreases */
2443 f_trxc_fake_rssi(rxlev2dbm(0));
2444
2445 timer T4 := 6.0;
2446 T4.start;
2447 alt {
2448 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002449 /* Update sent MS power to follow what BTS requests */
2450 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2451 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002452 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002453 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002454 T4.stop;
2455 setverdict(pass, "Power level in L1 decreased/increased as expected");
2456 }
2457 [] L1CTL.receive { repeat; }
2458 [] T4.timeout {
2459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2460 "Power Level in L1 header has not decreased sufficiently");
2461 }
2462 }
2463
2464 f_rsl_chan_deact();
2465 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2466
2467}
2468
2469/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002470private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002471 var uint5_t pwr_var := 7;
2472 var L1ctlDlMessage l1_dl;
2473
2474 /* set a low value to ensure power increases */
2475 f_trxc_fake_rssi(rxlev2dbm(10));
2476 f_l1_tune(L1CTL);
2477 RSL.clear;
2478
2479 var RSL_IE_List addl_ies;
2480 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2481
2482 addl_ies := {
2483 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2484 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2485 };
2486
2487 /* establish with power parameters */
2488 f_est_dchan(more_ies := addl_ies);
2489
2490 timer T1 := 10.0;
2491 T1.start;
2492 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002493 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2494 /* Update sent MS power to follow what BTS requests */
2495 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2496 repeat;
2497 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002498 [] L1CTL.receive { repeat; }
2499 [] T1.timeout {
2500 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2501 setverdict(fail, "Power level in L1 header should not have changed");
2502 }
2503 }
2504 }
2505
2506 f_rsl_chan_deact();
2507 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2508
2509}
2510
2511/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002512private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002513 var L1ctlDlMessage l1_dl;
2514 var uint5_t pwr_var := 15;
2515 var uint5_t pwr_max_var := f_get_max_power_from_band();
2516
2517 /* set a low value to ensure power increases */
2518 f_trxc_fake_rssi(rxlev2dbm(10));
2519 f_l1_tune(L1CTL);
2520 RSL.clear;
2521
2522 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2523 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2524
2525 /* establish with fixed power level */
2526 f_est_dchan(more_ies :={valueof(pwr)});
2527
2528 /* check our initial power level */
2529 f_wait_for_l1_power_level(pwr_var);
2530
2531 /* update power param to enable power loop
2532 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2533 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2534
2535 /* wait, then check that our power level was reduced */
2536 timer T1 := 10.0;
2537 T1.start;
2538 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002539 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2540 /* Update sent MS power to follow what BTS requests */
2541 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2542 repeat;
2543 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002544 [] L1CTL.receive { repeat; }
2545 [] T1.timeout {
2546 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2547 if( f_power_level_is_highest_dbm(rcv) ){
2548 setverdict(pass, "Power level in L1 header reduced as expected");
2549 } else {
2550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2551 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2552 }
2553 }
2554 }
2555
2556 f_rsl_chan_deact();
2557 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2558
2559}
2560
2561/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002562private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002563 var L1ctlDlMessage l1_dl;
2564
2565 /* set a high value to ensure power decreases */
2566 f_trxc_fake_rssi(rxlev2dbm(50));
2567 f_l1_tune(L1CTL);
2568 RSL.clear;
2569
2570 var uint5_t pwr_var := 5;
2571 var uint5_t pwr_target_val := 15;
2572
2573 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2574 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2575
2576 /* establish with fixed power level */
2577 f_est_dchan(more_ies :={valueof(pwr)});
2578
2579 /* check our initial power level */
2580 f_wait_for_l1_power_level(pwr_var);
2581
2582 /* update power param to enable power loop
2583 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002584 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002585
2586 /* wait, then check that our power level was increased */
2587 timer T1 := 10.0;
2588 T1.start;
2589 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002590 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2591 /* Update sent MS power to follow what BTS requests */
2592 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2593 repeat;
2594 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002595 [] L1CTL.receive { repeat; }
2596 [] T1.timeout {
2597 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2598 setverdict(pass, "Power level in L1 header increased to lowest power value");
2599 } else {
2600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2601 "Power level in L1 header NOT increased to lowest power value");
2602 }
2603 }
2604 }
2605
2606 f_rsl_chan_deact();
2607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2608
2609}
2610
Eric Wild095024b2019-06-17 15:08:57 +02002611/* see if we change the power level without receiving power parameters, which should not happen
2612rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002613private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002614 var L1ctlDlMessage l1_dl;
2615
2616 /* set a high value to ensure power decreases */
2617 f_trxc_fake_rssi(rxlev2dbm(50));
2618 f_l1_tune(L1CTL);
2619 RSL.clear;
2620
2621 var uint5_t pwr_var := 5;
2622
2623 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2624 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2625
2626 /* establish with fixed power level */
2627 f_est_dchan(more_ies :={valueof(pwr)});
2628
2629 /* check our initial power level */
2630 f_wait_for_l1_power_level(pwr_var);
2631
2632 /* wait, then check that our power level did not change */
2633 timer T1 := 10.0;
2634 T1.start;
2635 alt {
2636 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2637 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2639 "BS power control should not be active unless we receive a power parameters IE!");
2640 }
2641 repeat;
2642 }
2643 [] L1CTL.receive { repeat; }
2644 [] T1.timeout { setverdict(pass); }
2645 }
2646
2647 f_rsl_chan_deact();
2648 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2649
2650}
2651
Eric Wild095024b2019-06-17 15:08:57 +02002652/* see if we change the power level without receiving power parameters, which should not happen
2653ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002654private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002655 var L1ctlDlMessage l1_dl;
2656
2657 /* set a high value to ensure power decreases */
2658 f_trxc_fake_rssi(rxlev2dbm(50));
2659 f_l1_tune(L1CTL);
2660 RSL.clear;
2661
2662 var uint5_t pwr_var := 5;
2663
2664 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2665 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2666
2667 /* establish with fixed power level */
2668 f_est_dchan(more_ies :={valueof(pwr)});
2669
2670 /* check our initial power level */
2671 f_wait_for_l1_power_level(pwr_var);
2672
2673 /* pwr control without power params IE, should NOT activate MS power control*/
2674 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2675
2676 /* wait, then check that our power level did not change */
2677 timer T1 := 10.0;
2678 T1.start;
2679 alt {
2680 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2681 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2683 "BS power control should not be active unless we receive a power parameters IE!");
2684 }
2685 repeat;
2686 }
2687 [] L1CTL.receive { repeat; }
2688 [] T1.timeout { setverdict(pass); }
2689 }
2690
2691 f_rsl_chan_deact();
2692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2693
2694}
2695
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002696private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002697 var L1ctlDlMessage l1_dl;
2698 timer T0 := 10.0;
2699 T0.start;
2700 alt {
2701 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2702 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2704 "Power level in L1 header != signaled (RSL) power level.");
2705 }
2706 }
2707 [] L1CTL.receive { repeat; }
2708 [] T0.timeout {
2709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2710 "Timeout waiting for initial power level");
2711 }
2712 }
2713 T0.stop;
2714}
2715
2716private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2717 var IntegerRecord min_dbm_level;
2718 var IntegerRecord max_dbm_level;
2719 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2720
2721 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2722 if (min_dbm_level[i] == level) {
2723 return true;
2724 }
2725 }
2726 return false;
2727}
2728
2729private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2730 var IntegerRecord min_dbm_level;
2731 var IntegerRecord max_dbm_level;
2732 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2733
2734 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2735 if (max_dbm_level[i] == level) {
2736 return true;
2737 }
2738 }
2739 return false;
2740}
2741
2742private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2743 var IntegerRecord min_dbm_level;
2744 var IntegerRecord max_dbm_level;
2745 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2746 return max_dbm_level[0];
2747}
2748
2749type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002750private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002751private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2752 // 45.005 4.1.1
2753 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2754 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2755 2, 1, 0};
2756 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2757 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2758 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2759 var IntegerRecord rv;
2760
2761 select(band){
2762 case (BtsBand_allGSM){
2763 rv := gsm_power;
2764 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2765 max_dbm_level := {2, 1, 0};
2766 }
2767 case("DCS1800"){
2768 rv := dcs_power;
2769 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2770 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2771 }
2772 case("PCS1900"){
2773 rv := pcs_power;
2774 min_dbm_level := {15};
2775 max_dbm_level := {30};
2776 }
2777 }
2778
2779 return rv;
2780}
2781
2782private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2783 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2784}
2785
2786testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2787 var ConnHdlr vc_conn;
2788 var ConnHdlrPars pars;
2789 f_init();
2790 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2791 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2792 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2793 pars.bts0_band := f_vty_get_bts0_band();
2794 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2795 vc_conn.done;
2796 }
2797 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2799}
2800
2801testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2802 var ConnHdlr vc_conn;
2803 var ConnHdlrPars pars;
2804 f_init();
2805 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2806 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2807 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2808 pars.bts0_band := f_vty_get_bts0_band();
2809 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2810 vc_conn.done;
2811 }
2812 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2814}
2815
2816testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2817 var ConnHdlr vc_conn;
2818 var ConnHdlrPars pars;
2819 f_init();
2820 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2821 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2822 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2823 pars.bts0_band := f_vty_get_bts0_band();
2824 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2825 vc_conn.done;
2826 }
2827 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2829}
2830
2831testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2832 var ConnHdlr vc_conn;
2833 var ConnHdlrPars pars;
2834 f_init();
2835 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2836 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2837 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2838 pars.bts0_band := f_vty_get_bts0_band();
2839 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2840 vc_conn.done;
2841 }
2842 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2844}
2845
Eric Wild280ccb82019-06-17 11:11:52 +02002846testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2847 var ConnHdlr vc_conn;
2848 var ConnHdlrPars pars;
2849 f_init();
2850 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2851 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2852 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2853 pars.bts0_band := f_vty_get_bts0_band();
2854 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2855 vc_conn.done;
2856 }
2857 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2859}
2860
Eric Wild095024b2019-06-17 15:08:57 +02002861testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2862 var ConnHdlr vc_conn;
2863 var ConnHdlrPars pars;
2864 f_init();
2865 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2866 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2867 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2868 pars.bts0_band := f_vty_get_bts0_band();
2869 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2870 vc_conn.done;
2871 }
2872 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2874}
2875
Harald Welte70767382018-02-21 12:16:40 +01002876testcase TC_meas_res_sign_tchf() runs on test_CT {
2877 var ConnHdlr vc_conn;
2878 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002879 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002880 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2881 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002882 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2883 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002884 vc_conn.done;
2885 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002887}
2888testcase TC_meas_res_sign_tchh() runs on test_CT {
2889 var ConnHdlr vc_conn;
2890 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002891 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002892 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2893 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002894 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2895 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002896 vc_conn.done;
2897 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002899}
2900testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2901 var ConnHdlr vc_conn;
2902 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002903 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002904 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2905 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002906 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2907 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002908 vc_conn.done;
2909 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002911}
2912testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2913 var ConnHdlr vc_conn;
2914 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002915 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002916 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2917 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002918 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2919 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002920 vc_conn.done;
2921 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002923}
Harald Welte685d5982018-02-27 20:42:05 +01002924testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2925 var ConnHdlr vc_conn;
2926 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002927 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002928 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2929 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2930 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2931 pars.l1_pars.toa256_enabled := true;
2932 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2933 vc_conn.done;
2934 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002935 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002936}
2937
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002938/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2939 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002940private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002941 var L1ctlDlMessage l1_dl;
2942 var RSL_IE_MS_Power ms_power;
2943 var RSL_Message rsl;
2944 var uint5_t power_level := 0;
2945
2946 f_l1_tune(L1CTL);
2947 RSL.clear;
2948
2949 f_est_dchan();
2950
2951 ms_power.reserved := 0;
2952 ms_power.fpc_epc := false;
2953
2954 /* Send the first power control command. This will disable any BTS/TRX
2955 * internal power control and switch the MS (which is not in scope of
2956 * this test) to a constant power level. We start with a power level
2957 * of 0 */
2958 ms_power.power_level := power_level;
2959 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2960 RSL.send(rsl);
2961
2962 alt {
2963
2964 /* Pick all SACCH blocks for checking */
2965 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2966
2967 /* The first byte of the L1 header contains the power level.
2968 * The reserved bits and the fpc bit is set to 0, so we may
2969 * compare directly. */
2970 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2971 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2972 }
2973
2974 /* Signal a new power level via RSL for the next turn. */
2975 if (power_level < 31) {
2976 power_level := power_level + 1;
2977 ms_power.power_level := power_level;
2978 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2979 RSL.send(rsl);
2980 repeat;
2981 }
2982
2983 }
2984
2985 /* Ignore all other blocks */
2986 [] L1CTL.receive { repeat; }
2987
2988 }
2989
2990 f_rsl_chan_deact();
2991 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2992
2993 setverdict(pass);
2994}
2995
2996testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2997 var ConnHdlr vc_conn;
2998 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002999 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003000
3001 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3002 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3003 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3004 vc_conn.done;
3005 }
3006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3007}
Harald Welte70767382018-02-21 12:16:40 +01003008
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003009/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003010TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003011private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003012 var L1ctlDlMessage l1_dl;
3013 var uint5_t ta_to_test := 16;
3014
3015
3016 f_l1_tune(L1CTL);
3017 RSL.clear;
3018
3019 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003020 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003021
3022 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3023
3024
3025 alt {
3026
3027 /* Pick all SACCH blocks for checking */
3028 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3029
3030 /* The second byte of the L1 header contains the TA. */
3031 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3032 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3033 }
3034
3035 }
3036
3037 /* Ignore all other blocks */
3038 [] L1CTL.receive { repeat; }
3039
3040 }
3041
3042 f_rsl_chan_deact();
3043 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3044
3045 setverdict(pass);
3046}
3047
3048testcase TC_rsl_chan_initial_ta() runs on test_CT {
3049 var ConnHdlr vc_conn;
3050 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003051 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003052 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003053 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3054 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003055 vc_conn.done;
3056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3057}
3058
Eric Wilde57e1a62019-05-28 13:30:55 +02003059/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003060private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003061 var L1ctlDlMessage l1_dl;
3062 var uint5_t ms_power_level := 7;
3063
3064 var RSL_IE_MS_Power ms_power;
3065 ms_power.reserved := 0;
3066 ms_power.fpc_epc := false;
3067 ms_power.power_level := ms_power_level;
3068
3069 f_l1_tune(L1CTL);
3070 RSL.clear;
3071
3072 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3073
3074 timer T := 1.0;
3075 T.start;
3076 alt {
3077 /* Pick all SACCH blocks for checking */
3078 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3079 /* The first byte of the L1 header contains the power level.. */
3080 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3081 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3082 }
3083 }
3084 /* Ignore all other blocks */
3085 [] L1CTL.receive { repeat; }
3086 [] T.timeout {
3087 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3088 }
3089 }
3090
3091 f_rsl_chan_deact();
3092 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3093 setverdict(pass);
3094}
3095
3096testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3097 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3098 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3099}
3100
Harald Welte0472ab42018-03-12 15:02:26 +01003101/* 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 +01003102private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003103 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003104 RSL.clear;
3105
3106 f_est_dchan();
3107 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003108 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003109
3110 timer T := 40.0;
3111 T.start;
3112 alt {
3113 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3114 setverdict(pass)
3115 }
3116 [] RSL.receive { repeat };
3117 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003118 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003119 }
3120 }
3121 f_rsl_chan_deact();
3122}
3123testcase TC_conn_fail_crit() runs on test_CT {
3124 var ConnHdlr vc_conn;
3125 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003126 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003127 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3128 pars.t_guard := 60.0;
3129 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3130 vc_conn.done;
3131}
3132
Harald Welte93640c62018-02-25 16:59:33 +01003133/***********************************************************************
3134 * Paging
3135 ***********************************************************************/
3136
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003137private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003138 if (tmsi == 'FFFFFFFF'O) {
3139 return true;
3140 } else {
3141 return false;
3142 }
3143}
Harald Welte70767382018-02-21 12:16:40 +01003144
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003145private type record allowedFn { integer frame_nr }
3146private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3147private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3148private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3149private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3150private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3151private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3152private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3153private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3154private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003155{
3156 var integer frame_nr_51;
3157 frame_nr_51 := frame_nr mod 51
3158
3159 var allowedFn fn_check;
3160 fn_check.frame_nr := frame_nr_51;
3161
3162 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003164 return;
3165 }
3166
3167 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3168 return;
3169 }
3170 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3171 return;
3172 }
3173 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3174 return;
3175 }
3176 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3177 return;
3178 }
3179 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3180 return;
3181 }
3182 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3183 return;
3184 }
3185 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3186 return;
3187 }
3188 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3189 return;
3190 }
3191
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003193 return;
3194}
3195
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003196private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3197 inout integer num_paging_rcv_ids,
3198 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003199runs on test_CT {
3200 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003201 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003202 repeat;
3203 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003204 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003205 var octetstring without_plen :=
3206 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3207 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003208
3209 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3210
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003211 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3212 /* Ignore empty RR Paging Request (PCH filling) messages.
3213 * TODO: does it make sense to count them? */
3214 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003215 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3216 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003217 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003218 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3219 }
3220 } else if (match(rr, tr_PAGING_REQ2)) {
3221 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3222 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3223 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3224 }
3225 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3226 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3227 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003228 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003229 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3230 }
3231 } else if (match(rr, tr_PAGING_REQ3)) {
3232 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3233 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3234 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3235 }
3236 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3237 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3238 }
3239 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3240 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3241 }
3242 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3243 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3244 }
3245 }
3246 repeat;
3247 }
3248}
3249
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003250private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003251 boolean combined_ccch,
3252 integer bs_ag_blks_res,
3253 float load_factor,
3254 boolean exp_load_ind,
3255 boolean exp_overload,
3256 boolean use_tmsi
3257}
3258
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003259private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003260 integer num_paging_sent,
3261 integer num_paging_rcv_msgs,
3262 integer num_paging_rcv_ids,
3263 integer num_overload
3264}
3265
Harald Welte68e495b2018-02-25 00:05:57 +01003266/* Helper function for paging related testing */
3267private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003268 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003269 f_init_l1ctl();
3270 f_l1_tune(L1CTL);
3271
3272 var PagingTestState st := {
3273 num_paging_sent := 0,
3274 num_paging_rcv_msgs := 0,
3275 num_paging_rcv_ids := 0,
3276 num_overload := 0
3277 };
3278
3279 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3280 var float max_pch_imsi_per_sec;
3281 if (cfg.use_tmsi) {
3282 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3283 } else {
3284 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3285 }
3286 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3287 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003288 var float time_total := 20.0;
3289 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3290 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003291
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003292 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3293 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003294
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003295 timer T_itv := 0.0;
3296 T_itv.start;
3297 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003298 alt {
3299 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003300 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003301 st.num_overload := st.num_overload + 1;
3302 repeat;
3303 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003304 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003306 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003307 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003308 log("Rx LOAD_IND");
3309 /* FIXME: analyze/verify interval + contents */
3310 repeat;
3311 }
3312 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003313 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003314 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003315 [] T_itv.timeout {
3316 /* Send paging cmds based on elapsed time */
3317 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3318 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003319 var MobileIdentityV mi;
3320
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003321 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003322 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003323 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003324 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003325 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003326 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003327
3328 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003329 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 +02003330
3331 st.num_paging_sent := st.num_paging_sent + 1;
3332 }
3333 if (st.num_paging_sent < pkt_total) {
3334 /* Wait for interval to next PAGING COMMAND */
3335 var float time_now := T_total.read;
3336 var float next_sched := int2float(st.num_paging_sent)*interval;
3337 if (next_sched > time_now) {
3338 T_itv.start(next_sched - time_now);
3339 } else {
3340 T_itv.start(0.0);
3341 }
3342 } else {
3343 /* We are done, no need to keep counting */
3344 T_total.stop;
3345 }
3346 }
3347 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003348 }
3349 }
3350
3351 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3352 timer T_wait := 18.0;
3353 T_wait.start;
3354 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003355 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003356 [] L1CTL.receive { repeat; }
3357 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003358 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3359 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003360 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003362 }
Harald Welte68e495b2018-02-25 00:05:57 +01003363 }
3364
3365 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3366 " rcvd_ids=", st.num_paging_rcv_ids);
3367 return st;
3368}
3369
3370/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3371 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3372 * - that CCCH LOAD IND (PCH) are being generated
3373 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3374testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003375 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003376 var PagingTestCfg cfg := {
3377 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003378 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003379 load_factor := 0.8,
3380 exp_load_ind := true,
3381 exp_overload := false,
3382 use_tmsi := false
3383 };
3384 var PagingTestState st := f_TC_paging(cfg);
3385 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3387 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003388 } else {
3389 setverdict(pass);
3390 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003392}
3393
3394/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3395 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3396 * - that CCCH LOAD IND (PCH) are being generated
3397 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3398testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003399 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003400 var PagingTestCfg cfg := {
3401 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003402 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003403 load_factor := 0.8,
3404 exp_load_ind := true,
3405 exp_overload := false,
3406 use_tmsi := true
3407 };
3408 var PagingTestState st := f_TC_paging(cfg);
3409 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3411 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003412 } else {
3413 setverdict(pass);
3414 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003416}
3417
3418/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3419 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3420 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3421 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3422testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003423 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003424 var PagingTestCfg cfg := {
3425 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003426 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003427 load_factor := 2.0,
3428 exp_load_ind := true,
3429 exp_overload := true,
3430 use_tmsi := false
3431 };
3432 var PagingTestState st := f_TC_paging(cfg);
3433 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3434 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003435 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003436 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003437 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 +01003438 } else {
3439 setverdict(pass);
3440 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003442}
3443
3444/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3445 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3446 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3447 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3448testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003449 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003450 var PagingTestCfg cfg := {
3451 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003452 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003453 load_factor := 2.0,
3454 exp_load_ind := true,
3455 exp_overload := true,
3456 use_tmsi := true
3457 };
3458 var PagingTestState st := f_TC_paging(cfg);
3459 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3460 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003461 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003462 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 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 +01003464 } else {
3465 setverdict(pass);
3466 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003468}
3469
3470
Harald Welte93640c62018-02-25 16:59:33 +01003471/***********************************************************************
3472 * Immediate Assignment / AGCH
3473 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003474private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003475 len := 0,
3476 ma := ''B
3477}
Harald Welte93640c62018-02-25 16:59:33 +01003478
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003479private template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr,
3480 template (value) uint3_t tsc := 7,
3481 template (value) uint12_t arfcn := mp_trx0_arfcn) := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003482 chan_nr := chan_nr,
3483 tsc := tsc,
3484 h := false,
3485 arfcn := arfcn,
3486 maio_hsn := omit
3487}
3488
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003489private template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr,
3490 template (value) uint3_t tsc := 7,
3491 template (value) MaioHsn maio_hsn) := {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003492 chan_nr := chan_nr,
3493 tsc := tsc,
3494 h := true,
3495 arfcn := omit,
3496 maio_hsn := maio_hsn
3497}
3498
Harald Weltee8d750e2018-06-10 21:41:35 +02003499private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3500 return int2str(num_tx) & " sent, "
3501 & int2str(num_rx) & " received, "
3502 & int2str(num_del) & " deleted";
3503}
3504
3505private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3506 var L1ctlDlMessage l1_dl;
3507 timer T := 10.0;
3508 var integer num_tx := 0;
3509 var integer num_rx := 0;
3510 var integer num_del := 0;
3511 var charstring res_str;
3512 var float rx_ratio;
3513
Harald Welte10474062019-05-30 16:48:17 +02003514 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003515 f_init_l1ctl();
3516 f_l1_tune(L1CTL);
3517
3518 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy92484562020-05-27 02:05:04 +07003519 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(valueof(t_RslChanNr_SDCCH4(0, 0))));
Harald Weltee8d750e2018-06-10 21:41:35 +02003520 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3521 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003522 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003523 num_tx := num_tx+1;
3524 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003525 }
3526 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003527 T.start;
3528 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003529 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003530 num_del := num_del+1;
3531 repeat;
3532 }
3533 [] RSL_CCHAN.receive {
3534 repeat;
3535 }
3536 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003537 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3538 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3539 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003540 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003541 } else {
3542 num_rx := num_rx+1;
3543 }
3544 repeat;
3545 }
3546 [] L1CTL.receive { repeat; }
3547 [] T.timeout { }
3548 }
3549 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3550 log("AGCH test: " & res_str);
3551 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003553 }
3554 rx_ratio := int2float(num_rx) / int2float(num_tx);
3555 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003556 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 +02003557 } else {
3558 setverdict(pass);
3559 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003561}
3562
Harald Weltee8d750e2018-06-10 21:41:35 +02003563/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3564testcase TC_imm_ass_1000_20ms() runs on test_CT {
3565 f_TC_imm_ass(1000, 0.02, 0.25);
3566}
3567
3568/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3569testcase TC_imm_ass_200_0ms() runs on test_CT {
3570 f_TC_imm_ass(200, 0.0, 0.05);
3571}
3572
3573/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3574testcase TC_imm_ass_200_76ms() runs on test_CT {
3575 f_TC_imm_ass(150, 0.076, 1.00);
3576}
3577
3578
3579
Harald Welte48494ca2018-02-25 16:59:50 +01003580/***********************************************************************
3581 * BCCH
3582 ***********************************************************************/
3583
3584/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003585private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003586 GsmFrameNumber frame_number,
3587 SystemInformation si
3588}
3589
3590/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003591private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003592
3593/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003594private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003595
3596/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003597private function f_si_vecslot_contains(SystemInformationVector arr,
3598 RrMessageType key,
3599 boolean bcch_ext := false)
3600return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003601 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3602 var integer fn_mod51 := arr[i].frame_number mod 51;
3603 if (not bcch_ext and fn_mod51 == 2 or
3604 bcch_ext and fn_mod51 == 6) {
3605 if (arr[i].si.header.message_type == key) {
3606 return true;
3607 }
3608 }
3609 }
3610 return false;
3611}
3612
3613/* 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 +07003614private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3615 integer tc, RrMessageType key,
3616 boolean ext_bcch := false)
3617{
Harald Welte48494ca2018-02-25 16:59:50 +01003618 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003620 }
3621}
3622
3623/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003624private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3625 RrMessageType key)
3626return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003627 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3628 if (f_si_vecslot_contains(arr[tc], key) or
3629 f_si_vecslot_contains(arr[tc], key, true)) {
3630 return true;
3631 }
3632 }
3633 return false;
3634}
3635
3636/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003637private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3638 RrMessageType key,
3639 boolean bcch_ext := false,
3640 integer n := 1, integer m := 4)
3641return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003642 var integer count := 0;
3643 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003645 }
3646 for (var integer i:= 0; i < m; i := i + 1) {
3647 var integer fn_mod51 := arr[i].frame_number mod 51;
3648 if (not bcch_ext and fn_mod51 == 2 or
3649 bcch_ext and fn_mod51 == 6) {
3650 if (arr[i].si.header.message_type == key) {
3651 count := count + 1;
3652 }
3653 }
3654 }
3655 if (count >= n) {
3656 return true;
3657 } else {
3658 return false;
3659 }
3660}
3661
3662/* 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 +07003663private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3664 integer tc, RrMessageType key,
3665 boolean ext_bcch := false,
3666 integer n, integer m)
3667{
Harald Welte48494ca2018-02-25 16:59:50 +01003668 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003670 }
3671}
3672
3673/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003674private function f_si_vecslot_contains_only(SystemInformationVector arr,
3675 RrMessageType key,
3676 boolean bcch_ext := false)
3677return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003678 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3679 var integer fn_mod51 := arr[i].frame_number mod 51;
3680 if (not bcch_ext and fn_mod51 == 2 or
3681 bcch_ext and fn_mod51 == 6) {
3682 if (arr[i].si.header.message_type != key) {
3683 return false;
3684 }
3685 }
3686 }
3687 return true;
3688}
3689
3690/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003691private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3692 integer tc, RrMessageType key,
3693 boolean ext_bcch := false)
3694{
Harald Welte48494ca2018-02-25 16:59:50 +01003695 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003697 }
3698}
3699
3700/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003701private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003702 boolean bcch_extended,
3703 boolean si1_present,
3704 boolean si2bis_present,
3705 boolean si2ter_present,
3706 boolean si2quater_present,
3707 boolean si7_present,
3708 boolean si8_present,
3709 boolean si9_present,
3710 boolean si13_present,
3711 boolean si13alt_present,
3712 boolean si15_present,
3713 boolean si16_present,
3714 boolean si17_present,
3715 boolean si2n_present,
3716 boolean si21_present,
3717 boolean si22_present
3718}
3719
3720/* 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 +07003721private function f_validate_si_scheduling(SystemInformationConfig cfg,
3722 SystemInformationVectorPerTc si_per_tc)
3723{
Harald Welte48494ca2018-02-25 16:59:50 +01003724 var integer i;
3725 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3726 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003728 }
3729 }
3730 if (cfg.si1_present) {
3731 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3732 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3733 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3734 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3735 /* make sure *ALL* contain SI1 */
3736 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3737 }
3738 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3739 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3740 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3741 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3742 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3743 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3744
3745 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3746 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3747 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3748 * consecutive occurrences of TC = 4. */
3749 if (cfg.si2bis_present and not cfg.si2ter_present) {
3750 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3751 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3752 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3753 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3754 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3755 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3756 }
3757
3758 if (cfg.si7_present or cfg.si8_present) {
3759 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3760 * if System Information type 4 does not contain all information needed for cell
3761 * selection and reselection. */
3762 if (not cfg.bcch_extended) {
3763 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3764 }
3765 if (cfg.si7_present) {
3766 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3767 }
3768 if (cfg.si8_present) {
3769 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3770 }
3771 }
3772
3773 if (cfg.si2quater_present) {
3774 /* iii) System information type 2 quater is sent if needed, as determined by the system
3775 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3776 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3777 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3778 * within any of 4 consecutive occurrences of TC = 5. */
3779 if (not (cfg.bcch_extended)) {
3780 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3781 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3782 } else {
3783 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3784 }
3785 } else {
3786 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3787 }
3788 }
3789 if (cfg.si9_present) {
3790 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3791 * in system information type 3 as defined in 3GPP TS 44.018. */
3792 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3793 }
3794 if (cfg.si13_present) {
3795 /* vii) System Information type 13 is only related to the GPRS service. System Information
3796 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3797 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3798 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3799 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3800 * within any of 4 consecutive occurrences of TC=4. */
3801 if (not cfg.bcch_extended) {
3802 log("not-bccch-extended");
3803 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3804 } else {
3805 log("bccch-extended");
3806 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3807 }
3808 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003810 }
3811 }
3812 if (cfg.si16_present or cfg.si17_present) {
3813 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3814 * should not be sent in a cell where network sharing is used (see rule xv). */
3815 if (cfg.si22_present) {
3816 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3817 }
3818 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003820 }
3821 if (not cfg.bcch_extended) {
3822 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3823 }
3824 if (cfg.si16_present) {
3825 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3826 }
3827 if (cfg.si17_present) {
3828 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3829 }
3830 }
3831
3832 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3833 * broadcast information. The frequency with which they are sent is determined by the
3834 * system operator. System Information type 9 identifies the scheduling of System
3835 * Information type 18 and 20 messages. */
3836
3837 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3838 * Information Type 19 is present, then its scheduling shall be indicated in System
3839 * Information Type 9. */
3840
3841 if (cfg.si15_present) {
3842 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3843 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3844 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3845 * 4 consecutive occurrences of TC = 1. */
3846 if (not cfg.bcch_extended) {
3847 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3848 } else {
3849 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3850 }
3851 }
3852 if (cfg.si13alt_present) {
3853 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3854 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3855 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3856 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3857 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3858 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3859 * of TC = 4. */
3860 if (cfg.si13_present) {
3861 testcase.stop("Error: Cannot have SI13alt and SI13");
3862 }
3863 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003865 }
3866 if (not cfg.bcch_extended) {
3867 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3868 } else {
3869 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3870 }
3871 }
3872 if (cfg.si2n_present) {
3873 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3874 * as determined by the system operator. In the case that the message is sent on the
3875 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3876 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3877 * consecutive occurrences of TC = 4. */
3878 if (not cfg.bcch_extended) {
3879 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3880 } else {
3881 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3882 }
3883 }
3884 if (cfg.si21_present) {
3885 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3886 * determined by the system operator. If Extended Access Barring is in use in the cell
3887 * then this message is sent at least once within any of 4 consecutive occurrences of
3888 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3889 * cell then this message shall only be sent on BCCH Ext. */
3890 if (not cfg.bcch_extended) {
3891 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3892 } else {
3893 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3894 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003896 }
3897 }
3898 }
3899 if (cfg.si22_present) {
3900 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3901 * should not be sent in a cell where SoLSA is used (see rule viii). System
3902 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3903 * =2 and TC=6. */
3904 if (cfg.si16_present or cfg.si17_present) {
3905 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3906 }
3907 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3908 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003910 }
3911 if (not cfg.bcch_extended) {
3912 testcase.stop("Error: SI22 requires BCCH Extd!");
3913 } else {
3914 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3915 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3916 }
3917 }
3918}
3919
3920/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003921private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3922return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003923 timer T := duration;
3924 var SystemInformationVectorPerTc si_per_tc;
3925 var L1ctlDlMessage l1_dl;
3926
3927 /* initialize all per-TC vectors empty */
3928 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3929 si_per_tc[i] := {};
3930 }
3931
3932 /* flush all previous L1 queued msgs */
3933 pt.clear;
3934
3935 T.start;
3936 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003937 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003938 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3939 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3940 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003941 repeat;
3942 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003943
Harald Welte48494ca2018-02-25 16:59:50 +01003944 var integer tc := f_gsm_compute_tc(sig.frame_number);
3945 log("SI received at TC=", tc, ": ", sig.si);
3946 /* append to the per-TC bucket */
3947 si_per_tc[tc] := si_per_tc[tc] & { sig };
3948 repeat;
3949 }
3950 [] pt.receive { repeat; }
3951 [] T.timeout { }
3952 }
3953
3954 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3955 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3956 }
3957 log("si_per_tc=", si_per_tc);
3958 return si_per_tc;
3959}
3960
3961/* helper function: Set given SI via RSL + validate scheduling.
3962 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003963private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003964 var SystemInformationVectorPerTc si_per_tc;
3965 f_init_l1ctl();
3966 f_l1_tune(L1CTL);
3967
3968 /* Sample + Validate Scheduling */
3969 si_per_tc := f_l1_sample_si(L1CTL);
3970 f_validate_si_scheduling(si_cfg, si_per_tc);
3971
3972 setverdict(pass);
3973}
3974
3975testcase TC_si_sched_default() runs on test_CT {
3976 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003977 /* 2+3+4 are mandatory and set in f_init() */
3978 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003980}
3981
3982testcase TC_si_sched_1() runs on test_CT {
3983 f_init();
3984 si_cfg.si1_present := true;
3985 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003986 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003988}
3989
3990testcase TC_si_sched_2bis() runs on test_CT {
3991 f_init();
3992 si_cfg.si2bis_present := true;
3993 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3994 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003996}
3997
3998testcase TC_si_sched_2ter() runs on test_CT {
3999 f_init();
4000 si_cfg.si2ter_present := true;
4001 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4002 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004004}
4005
4006testcase TC_si_sched_2ter_2bis() runs on test_CT {
4007 f_init();
4008 si_cfg.si2bis_present := true;
4009 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4010 si_cfg.si2ter_present := true;
4011 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4012 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004014}
4015
4016testcase TC_si_sched_2quater() runs on test_CT {
4017 f_init();
4018 si_cfg.si2quater_present := true;
4019 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4020 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004022}
4023
4024testcase TC_si_sched_13() runs on test_CT {
4025 f_init();
4026 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004027 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004028 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004030}
4031
4032testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4033 f_init();
4034 si_cfg.si2bis_present := true;
4035 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4036 si_cfg.si2ter_present := true;
4037 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4038 si_cfg.si2quater_present := true;
4039 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4040 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004041 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004042 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004044}
4045
4046
Harald Welte68e495b2018-02-25 00:05:57 +01004047testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004048 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004049 /* FIXME: enable / disable individual BCCH info */
4050 //ts_RSL_BCCH_INFO(si_type, info);
4051 /* expect no ERROR REPORT after either of them *
4052 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004054}
4055
Harald Welte93640c62018-02-25 16:59:33 +01004056/***********************************************************************
4057 * Low-Level Protocol Errors / ERROR REPORT
4058 ***********************************************************************/
4059
Harald Welte01d982c2018-02-25 01:31:40 +01004060private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4061 timer T := 5.0;
4062 T.start;
4063 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004064 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004065 setverdict(pass);
4066 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004067 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004069 }
4070 [] RSL_CCHAN.receive {
4071 repeat;
4072 }
4073 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004075 }
4076 }
4077}
4078
4079/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4080testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004081 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004082 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4083 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004084 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004085
4086 f_exp_err_rep(RSL_ERR_PROTO);
4087}
4088
4089/* Provoke a mandatory IE error and match on ERROR REPORT */
4090testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004091 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004092
4093 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4094 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004095 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004096
4097 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4098}
4099
4100/* Provoke an IE content error and match on ERROR REPORT */
4101testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004102 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004103 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4104 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004105 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004106
4107 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4108}
4109
Harald Welteee25aae2019-05-19 14:32:37 +02004110/* attempt to activate channel with wrong RSL Message Discriminator IE */
4111function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4112 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4113 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4114 RSL.send(rsl);
4115 f_rslem_unregister(0, g_chan_nr);
4116}
4117testcase TC_err_rep_wrong_mdisc() 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
Harald Welte10474062019-05-30 16:48:17 +02004121 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004122
4123 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4124 vc_conn.done;
4125 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4126
4127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4128}
4129
4130/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004131private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004132 var template (value) RSL_Message rsl_tx;
4133 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4134 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4135 RSL.send(rsl_tx);
4136 f_rslem_unregister(0, g_chan_nr);
4137}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004138private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004139 var template (value) RSL_Message rsl_tx;
4140 /* we first have to activate the dedicated channel */
4141 f_rsl_chan_act(g_pars.chan_mode);
4142 /* ... to then send an invalid RLL message */
4143 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4144 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4145 RSL.send(rsl_tx);
4146 f_rslem_unregister(0, g_chan_nr);
4147}
4148testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4149 var ConnHdlr vc_conn;
4150 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4151 var template (value) RSL_Message rsl_tx;
4152
Harald Welte10474062019-05-30 16:48:17 +02004153 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004154
4155 /* Common Channel with wrong message type */
4156 RSL_CCHAN.clear;
4157 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4158 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004159 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004160 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4161
4162 /* TRX Management */
4163 RSL_CCHAN.clear;
4164 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4165 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004166 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004167 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4168
4169 /* Dedicated Channel */
4170 RSL_CCHAN.clear;
4171 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4172 vc_conn.done;
4173 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4174
4175 /* RLL */
4176 RSL_CCHAN.clear;
4177 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4178 vc_conn.done;
4179 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4180}
4181
4182/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004183private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004184 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4185 f_rslem_unregister(0, g_chan_nr);
4186}
4187testcase TC_err_rep_wrong_sequence() runs on test_CT {
4188 var ConnHdlr vc_conn;
4189 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4190
Harald Welte10474062019-05-30 16:48:17 +02004191 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004192
4193 RSL_CCHAN.clear;
4194 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4195 vc_conn.done;
4196 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4197}
4198
Harald Welte93640c62018-02-25 16:59:33 +01004199/***********************************************************************
4200 * IPA CRCX/MDCX/DLCS media stream handling
4201 ***********************************************************************/
4202
Harald Weltea871a382018-02-25 02:03:14 +01004203/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004204private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004205 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4206 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004207}
4208testcase TC_ipa_dlcx_not_active() runs on test_CT {
4209 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004210 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004211 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4212 vc_conn.done;
4213}
Harald Welte68e495b2018-02-25 00:05:57 +01004214
Harald Weltea3f1df92018-02-25 12:49:55 +01004215/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004216private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004217 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4218 "IPA CRCX ACK");
4219 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4220 "IPA CRCX NACK");
4221}
4222testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4223 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004224 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004225 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4226 vc_conn.done;
4227}
4228
4229/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004230private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004231 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4232 "IPA CRCX ACK");
4233 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4234 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4235 var uint7_t rtp_pt2 := f_rnd_int(127);
4236 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4237 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4238 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4239 "IPA MDCX ACK");
4240 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4241 "IPA DLCX ACK");
4242}
4243testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4244 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004245 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004246 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4247 vc_conn.done;
4248}
4249
Harald Welte3ae11da2018-02-25 13:36:06 +01004250/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004251private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004252 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4253 "IPA CRCX ACK");
4254 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4255 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4256 var uint7_t rtp_pt2 := f_rnd_int(127);
4257 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4258 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4259 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4260 "IPA MDCX ACK");
4261 /* Second MDCX */
4262 remote_ip := f_rnd_int(c_UINT32_MAX);
4263 remote_port := f_rnd_int(c_UINT16_MAX);
4264 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4265 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4266 "IPA MDCX ACK");
4267 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4268 "IPA DLCX ACK");
4269}
4270testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4271 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004272 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004273 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4274 vc_conn.done;
4275}
4276
Harald Welte9912eb52018-02-25 13:30:15 +01004277/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004278private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004279 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4280 "IPA CRCX NACK");
4281}
4282testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4283 var ConnHdlrPars pars;
4284 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004285 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004286
4287 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4288 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4289 vc_conn.done;
4290
4291 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4292 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4293 vc_conn.done;
4294}
4295
Harald Weltea3f1df92018-02-25 12:49:55 +01004296
Harald Welte883340c2018-02-28 18:59:29 +01004297/***********************************************************************
4298 * PCU Socket related tests
4299 ***********************************************************************/
4300
Harald Welte07bd2d22019-05-25 11:03:30 +02004301/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004302friend 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 +01004303runs on test_CT {
4304 timer T := 3.0;
4305
4306 /* we don't expect any RTS.req before PDCH are active */
4307 T.start;
4308 alt {
4309 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004311 }
4312 [] PCU.receive { repeat; }
4313 [] T.timeout { }
4314 }
4315
4316 /* Send PDCH activate request for known PDCH timeslot */
4317 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4318
4319 /* we now expect RTS.req for this timeslot (only) */
4320 T.start;
4321 alt {
4322 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4323 setverdict(pass);
4324 }
4325 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4326 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004328 }
4329 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004331 }
4332 [] PCU.receive { repeat; }
4333 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004335 }
4336 [not exp_success] T.timeout {
4337 setverdict(pass);
4338 }
4339 }
4340}
4341
Harald Welte07bd2d22019-05-25 11:03:30 +02004342/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004343friend 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 +01004344runs on test_CT {
4345 timer T := 3.0;
4346
4347 /* Send PDCH activate request for known PDCH timeslot */
4348 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4349
4350 PCU.clear;
4351 /* we now expect no RTS.req for this timeslot */
4352 T.start;
4353 alt {
4354 [] 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 +02004355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004356 }
4357 [] PCU.receive { repeat; }
4358 [] T.timeout {
4359 setverdict(pass);
4360 }
4361 }
4362}
4363
Harald Weltead033dc2019-05-25 17:28:16 +02004364friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004365 f_init();
4366 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4367}
4368
Harald Welte883340c2018-02-28 18:59:29 +01004369/* PDCH activation via PCU socket; check for presence of RTS.req */
4370testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004371 f_init_pcu_test();
4372
Harald Welte883340c2018-02-28 18:59:29 +01004373 f_TC_pcu_act_req(0, 0, 7, true);
4374}
4375
4376/* PDCH activation via PCU socket on non-PDCU timeslot */
4377testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004378 f_init_pcu_test();
4379
Harald Welte883340c2018-02-28 18:59:29 +01004380 f_TC_pcu_act_req(0, 0, 1, false);
4381}
4382
4383/* PDCH activation via PCU socket on wrong BTS */
4384testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004385 f_init_pcu_test();
4386
Harald Welte883340c2018-02-28 18:59:29 +01004387 f_TC_pcu_act_req(23, 0, 7, false);
4388}
4389
4390/* PDCH activation via PCU socket on wrong TRX */
4391testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004392 f_init_pcu_test();
4393
Harald Welte883340c2018-02-28 18:59:29 +01004394 f_TC_pcu_act_req(0, 23, 7, false);
4395}
4396
4397/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4398testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004399 f_init_pcu_test();
4400
Harald Welte883340c2018-02-28 18:59:29 +01004401 /* Activate PDCH */
4402 f_TC_pcu_act_req(0, 0, 7, true);
4403 f_sleep(1.0);
4404 /* and De-Activate again */
4405 f_TC_pcu_deact_req(0, 0, 7);
4406}
4407
4408/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4409testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004410 f_init_pcu_test();
4411
Harald Welte883340c2018-02-28 18:59:29 +01004412 f_TC_pcu_deact_req(0, 0, 1);
4413}
4414
4415/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4416testcase TC_pcu_ver_si13() runs on test_CT {
4417 const octetstring si13 := '00010203040506070909'O;
4418 var PCUIF_send_data sd;
4419 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004420 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004421
4422 /* Set SI13 via RSL */
4423 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004424
Harald Welte883340c2018-02-28 18:59:29 +01004425 T.start;
4426 alt {
4427 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4428 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4429 setverdict(pass);
4430 } else {
4431 repeat;
4432 }
4433 }
4434 [] PCU.receive { repeat; }
4435 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004437 }
4438 }
4439}
4440
4441private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4442
4443/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004444friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004445 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4446runs on test_CT
4447{
4448 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4449 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4450}
4451
4452/* 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 +02004453friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4454 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004455runs on test_CT
4456{
4457 var PCUIF_send_data sd;
4458
4459 timer T := 3.0;
4460 T.start;
4461 alt {
4462 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4463 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4464 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4465 sd.data.u.rts_req.fn, sapi, data);
4466 }
4467 [] PCU.receive { repeat; }
4468 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004470 }
4471 }
4472}
4473
4474/* Send DATA.req on invalid BTS */
4475testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004476 var TfiUsfArr tua := f_TfiUsfArrInit();
4477 var octetstring data := '0000'O & f_rnd_octstring(21);
4478
4479 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004480
Harald Welte883340c2018-02-28 18:59:29 +01004481 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004482 f_TfiUsfArrSet(tua, 7, 0);
4483 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4484 f_sleep(1.0);
4485
4486 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004487}
4488
4489/* Send DATA.req on invalid TRX */
4490testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004491 var TfiUsfArr tua := f_TfiUsfArrInit();
4492 var octetstring data := '0000'O & f_rnd_octstring(21);
4493
4494 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004495
Harald Welte883340c2018-02-28 18:59:29 +01004496 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004497 f_TfiUsfArrSet(tua, 7, 0);
4498 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4499 f_sleep(1.0);
4500
4501 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004502}
4503
4504/* Send DATA.req on invalid timeslot */
4505testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004506 var TfiUsfArr tua := f_TfiUsfArrInit();
4507 var octetstring data := '0000'O & f_rnd_octstring(21);
4508
4509 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004510
Harald Welte883340c2018-02-28 18:59:29 +01004511 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004512 f_TfiUsfArrSet(tua, 7, 0);
4513 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4514 f_sleep(1.0);
4515
4516 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004517}
4518
4519/* Send DATA.req on timeslot that hasn't been activated */
4520testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004521 var TfiUsfArr tua := f_TfiUsfArrInit();
4522 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004523
Harald Welte7162a612019-05-26 12:56:09 +02004524 f_virtphy_common();
4525
4526 f_TfiUsfArrSet(tua, 7, 0);
4527 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4528 f_sleep(1.0);
4529
4530 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004531}
4532
Harald Weltead033dc2019-05-25 17:28:16 +02004533private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004534 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4535 boolean wait_rts := true)
4536runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004537 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004538 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004539
4540 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004541 if (wait_rts) {
4542 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4543 } else {
4544 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4545 }
Harald Weltead033dc2019-05-25 17:28:16 +02004546
4547 T.start;
4548 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004549 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004550 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4551 setverdict(pass);
4552 }
Harald Welte7162a612019-05-26 12:56:09 +02004553 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4554 setverdict(fail, "Received unexpected ", rx_dl);
4555 }
Harald Weltead033dc2019-05-25 17:28:16 +02004556 [] L1CTL.receive {
4557 repeat;
4558 }
Harald Welte7162a612019-05-26 12:56:09 +02004559 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004560 setverdict(fail, "Timeout waiting for ", data);
4561 }
Harald Welte7162a612019-05-26 12:56:09 +02004562 [not expect_data] T.timeout {
4563 setverdict(pass);
4564 }
Harald Weltead033dc2019-05-25 17:28:16 +02004565 }
4566}
4567
4568private function f_disable_dynamic_ts() runs on test_CT
4569{
4570 f_init_vty_bsc();
4571 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4572 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4573 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4574 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004575 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004576}
4577
4578private function f_virtphy_common() runs on test_CT {
4579 f_disable_dynamic_ts();
4580 f_init_l1ctl();
4581 f_l1_tune(L1CTL);
4582}
4583
4584testcase TC_pcu_data_req_pdtch() runs on test_CT {
4585 var TfiUsfArr tua := f_TfiUsfArrInit();
4586 var octetstring data := '0000'O & f_rnd_octstring(21);
4587
4588 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004589
Harald Welte883340c2018-02-28 18:59:29 +01004590 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004591 f_TfiUsfArrSet(tua, 7, 0);
4592 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4593 f_sleep(1.0);
4594
4595 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004596}
4597
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004598/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004599testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004600 var TfiUsfArr tua := f_TfiUsfArrInit();
4601 var octetstring data := '0000'O & f_rnd_octstring(21);
4602
4603 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004604
Harald Welte883340c2018-02-28 18:59:29 +01004605 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004606 f_TfiUsfArrSet(tua, 7, 0);
4607 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4608 f_sleep(1.0);
4609
4610 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004611}
4612
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004613private function f_TC_pcu_ptcch_ul(uint16_t ra)
4614runs on test_CT {
4615 var template PCUIF_Message pcu_rach_ind;
4616 var PCUIF_send_data sd;
4617 var GsmFrameNumber fn;
4618 timer T;
4619
4620 /* Send an Access Burst on PTCCH/U over the Um-interface */
4621 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4622 chan_nr := ts_RslChanNr_PDCH(7),
4623 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4624
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004625 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4626 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004627
4628 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4629 T.start(52.0 * 4.615 / 1000.0);
4630 alt {
4631 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4632 log("Rx an Access Burst on the PCU interface: ", sd.data);
4633 setverdict(pass);
4634 T.stop;
4635 }
4636 [] PCU.receive { repeat; }
4637 [] T.timeout {
4638 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4639 /* Keep going, that's not the end of the world */
4640 }
4641 }
4642}
4643
4644testcase TC_pcu_ptcch() runs on test_CT {
4645 var L1ctlDlMessage dl;
4646 var octetstring data;
4647 timer T;
4648
4649 f_init_pcu_test();
4650 f_init_l1ctl();
4651 f_l1_tune(L1CTL);
4652
4653 /* Activate PDCH channel on TS7 */
4654 f_TC_pcu_act_req(0, 0, 7, true);
4655
4656 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004657 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004658
4659 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4660 for (var integer i := 0; i < 16; i := i + 1) {
4661 log("Sending an Access Burst towards the L1CTL interface");
4662 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4663 }
4664
4665 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4666 data := f_rnd_octstring(23);
4667
4668 /* Verify PTCCH/D: send a random data block, make sure it's received */
4669 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4670 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4671
4672 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4673 * let's give it more time in case if we miss the beginning. */
4674 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4675 alt {
4676 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4677 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4678 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4679 frame := data)) -> value dl {
4680 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4681 setverdict(pass);
4682 T.stop;
4683 }
4684 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4685 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4686 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4687 l2_data := data)) -> value dl {
4688 log("Rx PTCCH/D data block on L1CTL: ", dl);
4689 setverdict(pass);
4690 T.stop;
4691 }
4692 [] L1CTL.receive { repeat; }
4693 [] T.timeout {
4694 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4695 }
4696 }
4697}
4698
Harald Welte883340c2018-02-28 18:59:29 +01004699/* Send AGCH from PCU; check it appears on Um side */
4700testcase TC_pcu_data_req_agch() runs on test_CT {
4701 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004702 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004703 f_init_l1ctl();
4704 f_l1_tune(L1CTL);
4705
4706 f_TC_pcu_act_req(0, 0, 7, true);
4707 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4708
4709 T.start;
4710 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004711 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004712 setverdict(pass);
4713 }
4714 [] L1CTL.receive { repeat; }
4715 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004717 }
4718 }
4719}
4720
Harald Welte928622b2019-05-26 13:22:59 +02004721/* Send AGCH from PCU; check it appears on Um side */
4722testcase TC_pcu_data_req_pch() runs on test_CT {
4723 timer T := 3.0;
4724 f_init_pcu_test();
4725 f_init_l1ctl();
4726 f_l1_tune(L1CTL);
4727
4728 f_TC_pcu_act_req(0, 0, 7, true);
4729 /* three characters prefix: last 3 digits of IMSI as ASCII */
4730 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4731
4732 T.start;
4733 alt {
4734 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4735 setverdict(pass);
4736 }
4737 [] L1CTL.receive { repeat; }
4738 [] T.timeout {
4739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4740 }
4741 }
4742}
4743
Harald Welte883340c2018-02-28 18:59:29 +01004744/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4745testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4746 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004747 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004748 f_init_l1ctl();
4749 f_l1_tune(L1CTL);
4750
4751 /* append 3 last imsi digits so BTS can compute pagng group */
4752 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4753
4754 timer T := 0.5;
4755 T.start;
4756 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004757 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004758 /* TODO: verify paging group */
4759 setverdict(pass);
4760 }
4761 [] L1CTL.receive { repeat; }
4762 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004764 }
4765 }
4766}
4767
4768/* Send RACH from Um side, expect it to show up on PCU socket */
4769testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004770 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004771 f_init_l1ctl();
4772 f_l1_tune(L1CTL);
4773
4774 var GsmFrameNumber fn_last := 0;
4775 for (var integer i := 0; i < 1000; i := i+1) {
4776 var OCT1 ra := f_rnd_ra_ps();
4777 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4778 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004780 }
4781 fn_last := fn;
4782
4783 timer T := 2.0;
4784 T.start;
4785 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004786 [] 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 +01004787 T.stop;
4788 }
4789 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004791 }
4792 [] PCU.receive { repeat; }
4793 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004795 }
4796 }
4797 }
4798 setverdict(pass);
4799}
4800
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004801/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4802 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4803testcase TC_pcu_ext_rach_content() runs on test_CT {
4804 var template PCUIF_Message pcu_rach_ind;
4805 var GsmFrameNumber fn_last := 0;
4806 var L1ctlRachSynchSeq synch_seq;
4807 var PCUIF_BurstType pcu_bt;
4808 var GsmFrameNumber fn;
4809 var BIT11 ra11;
4810
4811 f_init_pcu_test();
4812 f_init_l1ctl();
4813 f_l1_tune(L1CTL);
4814
4815 for (var integer i := 0; i < 1000; i := i+1) {
4816 /* We need to test both TS1 & TS2 */
4817 if (i rem 2 == 0) {
4818 synch_seq := RACH_SYNCH_SEQ_TS1;
4819 pcu_bt := BURST_TYPE_1;
4820 } else {
4821 synch_seq := RACH_SYNCH_SEQ_TS2;
4822 pcu_bt := BURST_TYPE_2;
4823 }
4824
4825 ra11 := f_rnd_ra11_ps();
4826 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4827 if (fn == fn_last) {
4828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4829 "Two RACH in same FN?!?");
4830 }
4831 fn_last := fn;
4832
4833 /* Compose the expected message */
4834 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004835 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004836 ra := bit2int(ra11),
4837 is_11bit := 1,
4838 burst_type := pcu_bt,
4839 fn := fn);
4840
4841 timer T := 2.0;
4842 T.start;
4843 alt {
4844 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4845 T.stop;
4846 }
4847 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4849 }
4850 [] PCU.receive { repeat; }
4851 [] T.timeout {
4852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4853 }
4854 }
4855 }
4856 setverdict(pass);
4857}
4858
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004859private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4860runs on test_CT {
4861 var template PCUIF_send_data sdt;
4862 var PCUIF_send_data sd;
4863 var int16_t lqual_cb;
4864 timer T := 1.0;
4865
4866 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4867 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4868
4869 /* Send a random PDTCH frame over Um */
4870 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4871 '0000'O & f_rnd_octstring(21)));
4872
4873 T.start;
4874 alt {
4875 /* If expected link quality is above the threshold */
4876 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4877 lqual_cb := sd.data.u.data_ind.lqual_cb;
4878 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4879
4880 /* Make sure the actual link quality matches the expected value */
4881 if (not match(lqual_cb, lqual_cb_exp)) {
4882 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4883 "expected value ", lqual_cb_exp));
4884 } else {
4885 setverdict(pass);
4886 }
4887 }
4888 /* If expected link quality is below the threshold */
4889 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4891 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4892 }
4893 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4894 [] PCU.receive { repeat; }
4895 [lqual_cb_exp < thresh] T.timeout {
4896 log("Rx nothing, as expected");
4897 setverdict(pass);
4898 }
4899 [lqual_cb_exp >= thresh] T.timeout {
4900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4901 "Timeout waiting for PCUIF_DATA.ind");
4902 }
4903 }
4904}
4905
4906/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4907testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4908 f_init_pcu_test();
4909 PCU.clear;
4910
4911 f_init_l1ctl();
4912 f_l1_tune(L1CTL);
4913
4914 /* Activate a PDCH channel on TS7 */
4915 f_TC_pcu_act_req(0, 0, 7, true);
4916
4917 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004918 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004919
4920 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4921 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4922 var TrxcMessage ret;
4923
4924 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4925 valueof(ts_TRXC_FAKE_CI(i)));
4926
4927 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4928 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4929 }
4930}
4931
Harald Welte883340c2018-02-28 18:59:29 +01004932/* Send PAGING via RSL, expect it to shw up on PCU socket */
4933testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004934 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004935
4936 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004937 var MobileIdentityLV mi_lv;
4938 var octetstring mi_lv_enc;
4939 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004940 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004941
Harald Welte883340c2018-02-28 18:59:29 +01004942 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004943 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004944 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004945 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004946 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004947
4948 /* Fancy encoding for PCUIF */
4949 mi_lv := valueof(ts_MI_LV(mi));
4950 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4951 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004952
4953 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004954 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004955 T.start;
4956 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004957 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004958 }
4959 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004961 }
4962 [] PCU.receive { repeat; }
4963 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004965 }
4966 }
4967 }
4968 setverdict(pass);
4969}
4970
Harald Welted66c9b82019-05-25 09:03:15 +02004971/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4972testcase TC_pcu_time_ind() runs on test_CT {
4973 var PCUIF_send_data pcu_sd;
4974 var integer num_time_ind := 0;
4975 var integer first_fn, last_fn;
4976 var float test_duration := 5.0;
4977 timer T;
4978
4979 f_init_pcu_test();
4980 f_TC_pcu_act_req(0, 0, 7, true);
4981
4982 PCU.clear;
4983 T.start(test_duration);
4984 alt {
4985 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4986 num_time_ind := num_time_ind + 1;
4987 if (not isbound(first_fn)) {
4988 first_fn := pcu_sd.data.u.time_ind.fn;
4989 }
4990 last_fn := pcu_sd.data.u.time_ind.fn;
4991 repeat;
4992 }
4993 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4994 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4995 repeat;
4996 }
4997 [] PCU.receive {
4998 repeat;
4999 }
5000 [] T.timeout {}
5001 }
5002 var integer fn_expired := last_fn - first_fn;
5003 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5004
5005 /* verify the number of frames expired matches our expectation */
5006 const float c_GSM_FN_DURATION_MS := 4.61538;
5007 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005008 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005009 if (not match(fn_expired, t_fn_expected)) {
5010 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5011 }
5012
5013 /* There are three TIME.ind in every fn MOD 13 */
5014 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5015 /* Add some tolerance */
5016 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5017 if (not match(num_time_ind, t_time_ind_exp)) {
5018 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5019 }
5020
5021 setverdict(pass);
5022}
5023
Harald Welte4832c862019-05-25 14:57:18 +02005024/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5025testcase TC_pcu_rts_req() runs on test_CT {
5026 var PCUIF_send_data pcu_sd;
5027 var integer first_fn, last_fn;
5028 var integer num_rts_pdtch := 0;
5029 var integer num_rts_ptcch := 0;
5030 var float test_duration := 5.0;
5031 timer T;
5032
5033 f_init_pcu_test();
5034 f_TC_pcu_act_req(0, 0, 7, true);
5035
5036 PCU.clear;
5037 T.start(test_duration);
5038 alt {
5039 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5040 -> value pcu_sd {
5041 num_rts_pdtch := num_rts_pdtch + 1;
5042 if (not isbound(first_fn)) {
5043 first_fn := pcu_sd.data.u.rts_req.fn;
5044 }
5045 last_fn := pcu_sd.data.u.rts_req.fn;
5046 repeat;
5047 }
5048 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5049 -> value pcu_sd {
5050 num_rts_ptcch := num_rts_ptcch + 1;
5051 if (not isbound(first_fn)) {
5052 first_fn := pcu_sd.data.u.rts_req.fn;
5053 }
5054 last_fn := pcu_sd.data.u.rts_req.fn;
5055 repeat;
5056 }
5057 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5058 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5059 repeat;
5060 }
5061 [] PCU.receive {
5062 repeat;
5063 }
5064 [] T.timeout {}
5065 }
5066 var integer fn_expired := last_fn - first_fn;
5067 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5068 ", num_rts_ptcch=", num_rts_ptcch);
5069
5070 /* verify the number of frames expired matches our expectation */
5071 const float c_GSM_FN_DURATION_MS := 4.61538;
5072 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005073 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005074 if (not match(fn_expired, t_fn_expected)) {
5075 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5076 }
5077
5078 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5079 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5080 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5081 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5082 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5083 t_ptcch_exp);
5084 }
5085
5086 /* We have 12 PDTCH blocks every 52-multiframe */
5087 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5088 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5089 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5090 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5091 t_pdtch_exp);
5092 }
5093
5094 setverdict(pass);
5095}
5096
Harald Welte07bd2d22019-05-25 11:03:30 +02005097/* test for generating Abis side OML ALERT from the PCU */
5098testcase TC_pcu_oml_alert() runs on test_CT {
5099 var PCUIF_send_data pcu_sd;
5100 var integer num_time_ind := 0;
5101 var integer first_fn, last_fn;
5102 var float test_duration := 5.0;
5103 timer T;
5104
5105 f_init_pcu_test();
5106 f_TC_pcu_act_req(0, 0, 7, true);
5107
5108 /* re-connect CTRL port from BTS to BSC */
5109 f_ipa_ctrl_stop();
5110 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5111
5112 /* Send that OML Alert */
5113 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5114
5115 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5116 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5117 setverdict(pass);
5118}
5119
Harald Welteeaa9a862019-05-26 23:01:08 +02005120/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5121private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5122 var PCUIF_Message first_info;
5123 var integer pcu_conn_id := -1;
5124 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5125 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5126 var OCT4 tlli := '01020304'O;
5127 var OCT1 cause := '23'O;
5128 timer T := 5.0;
5129
5130 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5131
5132 f_l1_tune(L1CTL);
5133 RSL.clear;
5134
5135 f_est_dchan();
5136 L1CTL.clear;
5137
5138 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5139
5140 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5141 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5142 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5143
5144 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5145 T.start;
5146 alt {
5147 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5148 setverdict(pass);
5149 }
5150 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5151 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5152 }
5153 [] PCU.receive {
5154 repeat;
5155 }
5156 [] T.timeout {
5157 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5158 }
5159 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005160
5161 /* release the channel */
5162 f_rsl_chan_deact();
5163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5164 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005165}
5166testcase TC_pcu_rr_suspend() runs on test_CT {
5167 var ConnHdlrPars pars;
5168 var ConnHdlr vc_conn;
5169
5170 f_init();
5171
5172 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5173 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5174 vc_conn.done;
5175}
Harald Welte07bd2d22019-05-25 11:03:30 +02005176
Harald Weltea2e0e942019-05-27 18:12:53 +02005177/* Ensure that PCUIF socket can accept only a single connection */
5178testcase TC_pcu_socket_connect_multi() runs on test_CT {
5179 timer T := 5.0;
5180
5181 /* this (among other things) establishes the first connection to the PCUIF socket */
5182 f_init();
5183
5184 /* try to establish a second connection, expect it to fail */
5185 PCU.send(UD_connect:{mp_pcu_socket, -1});
5186 T.start;
5187 alt {
5188 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5189 setverdict(pass);
5190 }
5191 [] PCU.receive(UD_connect_result:?) {
5192 setverdict(fail, "Unexpected unix domain connect result");
5193 }
5194 [] T.timeout {
5195 setverdict(pass);
5196 }
5197 }
5198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5199}
5200
Harald Weltec8effb72019-05-27 18:23:04 +02005201/* Ensure that PCUIF socket can disconnect + reconnect */
5202testcase TC_pcu_socket_reconnect() runs on test_CT {
5203 /* this (among other things) establishes the first connection to the PCUIF socket */
5204 f_init();
5205
5206 f_sleep(1.0);
5207
5208 f_pcuif_close(PCU, g_pcu_conn_id);
5209 g_pcu_conn_id := -1;
5210
5211 f_sleep(1.0);
5212
5213 /* re-connect */
5214 PCU.clear;
5215 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5216 setverdict(pass);
5217
5218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5219}
5220
Harald Weltebe030482019-05-27 22:29:35 +02005221/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005222private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5223runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005224 var L1ctlDlMessage l1_dl;
5225 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005226 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005227 timer T := 5.0;
5228 T.start;
5229 alt {
5230 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005231 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5232 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005233 repeat;
5234 }
5235 }
5236 [] pt.receive {
5237 repeat;
5238 }
5239 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5241 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005242 }
5243 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005244 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005245}
5246
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005247/* Check if GPRS Indicator is present in RR System Information of a given type */
5248private function f_si_has_gprs_indicator(RrMessageType si_type)
5249runs on test_CT return boolean {
5250 var SystemInformation si := f_get_si(L1CTL, si_type);
5251
5252 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005253 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005254 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005255 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005256 }
5257
5258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5259 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005260}
5261
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005262/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5263private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5264runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005265 /* don't call f_init() as this would connect PCU socket */
5266 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005267
5268 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005269 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005270 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005271
5272 f_init_l1ctl();
5273 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005274 f_sleep(2.0);
5275 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005276
5277 if (f_si_has_gprs_indicator(si_type)) {
5278 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005279 } else {
5280 setverdict(pass);
5281 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005282
Harald Weltebe030482019-05-27 22:29:35 +02005283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5284}
5285
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005286testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5287 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5288}
Harald Weltebe030482019-05-27 22:29:35 +02005289
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005290testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5291 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5292}
5293
5294/* Ensure that GPRS capability is advertised after PCU socket connect */
5295private function f_TC_pcu_socket_connect(RrMessageType si_type)
5296runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005297 /* this (among other things) establishes the first connection to the PCUIF socket */
5298 f_init();
5299 f_init_l1ctl();
5300 f_l1_tune(L1CTL);
5301
5302 f_sleep(2.0);
5303 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005304
5305 if (not f_si_has_gprs_indicator(si_type)) {
5306 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005307 } else {
5308 setverdict(pass);
5309 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005310
Harald Weltebe030482019-05-27 22:29:35 +02005311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5312}
5313
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005314testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5315 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5316}
Harald Weltebe030482019-05-27 22:29:35 +02005317
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005318testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5319 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5320}
5321
5322/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5323private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5324runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005325 /* this (among other things) establishes the first connection to the PCUIF socket */
5326 f_init();
5327 f_init_l1ctl();
5328 f_l1_tune(L1CTL);
5329
5330 f_pcuif_close(PCU, g_pcu_conn_id);
5331 g_pcu_conn_id := -1;
5332
5333 f_sleep(1.0);
5334
5335 /* re-connect */
5336 PCU.clear;
5337 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5338
5339 f_sleep(2.0);
5340 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005341
5342 if (f_si_has_gprs_indicator(si_type)) {
5343 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005344 } else {
5345 setverdict(pass);
5346 }
5347
5348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5349}
5350
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005351testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5352 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5353}
5354
5355testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5356 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5357}
5358
Oliver Smithf5239c72019-08-28 10:01:25 +02005359/* Verify that the cell_id of SI3 (TS 04.08 9.1.35) and other values are passed properly to the PCU socket (OS#3854) */
5360testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5361 var SystemInformation si3 := valueof(ts_SI3_default);
5362
5363 f_init();
5364
5365 /* Verify cell_id */
5366 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5367 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5368 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005369 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5370 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5371 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005372 }
5373
5374 /* Verify LAC */
5375 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5376 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5377 if (lac_si3 != lac_pcu) {
5378 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5379 }
5380
5381 setverdict(pass);
5382}
Harald Welted66c9b82019-05-25 09:03:15 +02005383
Harald Welte3d04ae62018-04-04 20:29:05 +02005384/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005385 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005386 ***********************************************************************/
5387
5388private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5389runs on ConnHdlr {
5390 var PCUIF_send_data sd;
5391 /* Expect BTS to immediately acknowledge activation as PDCH */
5392 PCU.clear;
5393 f_rsl_chan_act(g_pars.chan_mode);
5394 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005395 timer T_wait := 2.0;
5396 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005397 alt {
5398 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5399 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005400 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5401 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5402 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005403 }
5404 }
5405 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005406 [] T_wait.timeout {
5407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5408 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5409 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005410 }
5411 /* try to activate this PDCH from the PCU point of view */
5412 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5413 /* FIXME: is there a response? */
5414}
5415
5416private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5417runs on ConnHdlr {
5418 var PCUIF_send_data sd;
5419 /* Send RSL CHAN REL (deactivate) */
5420 PCU.clear;
5421 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5422 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005423 timer T_wait := 2.0;
5424 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005425 alt {
5426 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5427 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005428 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5429 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5430 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005431 }
5432 }
5433 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005434 [] T_wait.timeout {
5435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5436 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5437 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005438 }
5439 /* Emulate PCU asking BTS to deactivate PDCH */
5440 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5441 alt {
5442 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5443 setverdict(pass);
5444 }
5445 [] RSL.receive { repeat; }
5446 }
5447}
5448
5449/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005450private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005451 var PCUIF_Message first_info;
5452 var integer ts_nr := g_chan_nr.tn;
5453 var integer trx_nr := 0;
5454 var integer bts_nr := 0;
5455 var integer pcu_conn_id := -1;
5456
5457 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5458
5459 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5460 f_sleep(3.0);
5461 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5462 setverdict(pass);
5463}
5464testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5465 var ConnHdlrPars pars;
5466 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005467 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005468
5469 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5470 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5471 vc_conn.done;
5472}
5473
5474/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005475private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005476 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005477 var integer pcu_conn_id := -1;
5478
5479 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5480
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005481 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5482 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5483 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005484 setverdict(pass);
5485}
5486testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5487 var ConnHdlrPars pars;
5488 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005489 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005490
5491 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5492 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5493 vc_conn.done;
5494}
5495
5496/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005497private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005498 var PCUIF_Message first_info;
5499 var integer ts_nr := g_chan_nr.tn;
5500 var integer trx_nr := 0;
5501 var integer bts_nr := 0;
5502 var integer pcu_conn_id := -1;
5503
5504 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5505
5506 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005507 /* Send a second Chan Activ and expect it to be NACKed */
5508 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5509 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005510 setverdict(pass);
5511}
5512testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5513 var ConnHdlrPars pars;
5514 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005515 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005516
5517 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5518 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5519 vc_conn.done;
5520}
5521
5522/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005523private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005524 var PCUIF_Message first_info;
5525 var integer ts_nr := g_chan_nr.tn;
5526 var integer trx_nr := 0;
5527 var integer bts_nr := 0;
5528 var integer pcu_conn_id := -1;
5529 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5530
5531 /* register for the TCH/F channel number */
5532 f_rslem_register(0, chan_nr);
5533
5534 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5535
5536 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5537 "RSL CHAN ACT");
5538 setverdict(pass);
5539}
5540testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5541 var ConnHdlrPars pars;
5542 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005543 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005544
5545 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5546 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5547 vc_conn.done;
5548}
5549
5550/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005551private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005552 var PCUIF_Message first_info;
5553 var integer ts_nr := g_chan_nr.tn;
5554 var integer trx_nr := 0;
5555 var integer bts_nr := 0;
5556 var integer pcu_conn_id := -1;
5557 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5558 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5559
5560 /* register for the TCH/H channel numbers */
5561 f_rslem_register(0, chan_nr[0]);
5562 f_rslem_register(0, chan_nr[1]);
5563
5564 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5565
5566 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5567 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5568 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5569 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5570 setverdict(pass);
5571}
5572testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5573 var ConnHdlrPars pars;
5574 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005575 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005576
5577 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5578 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5579 vc_conn.done;
5580}
5581
Harald Welte9bbbfb52018-04-05 09:33:19 +02005582/***********************************************************************
5583 * IPA Style Dynamic Timeslot Support
5584 ***********************************************************************/
5585
5586private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5587runs on ConnHdlr {
5588 var PCUIF_send_data sd;
5589 /* Expect BTS to immediately acknowledge activation as PDCH */
5590 PCU.clear;
5591 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5592 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005593 timer T_wait := 2.0;
5594 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005595 alt {
5596 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5597 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005598 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5599 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5600 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005601 }
5602 }
5603 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005604 [] T_wait.timeout {
5605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5606 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5607 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005608 }
5609 /* try to activate this PDCH from the PCU point of view */
5610 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5611 /* FIXME: is there a response? */
5612
5613 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5614}
5615
5616private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5617runs on ConnHdlr {
5618 var PCUIF_send_data sd;
5619 /* Send RSL CHAN REL (deactivate) */
5620 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5621 PCU.clear;
5622 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005623 timer T_wait := 2.0;
5624 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005625 alt {
5626 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5627 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005628 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5629 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5630 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005631 }
5632 }
5633 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005634 [] T_wait.timeout {
5635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5636 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5637 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005638 }
5639 /* Emulate PCU asking BTS to deactivate PDCH */
5640 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5641 alt {
5642 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5643 setverdict(pass);
5644 }
5645 [] RSL.receive { repeat; }
5646 }
5647}
5648
5649/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005650private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005651 var PCUIF_Message first_info;
5652 var integer ts_nr := g_chan_nr.tn;
5653 var integer trx_nr := 0;
5654 var integer bts_nr := 0;
5655 var integer pcu_conn_id := -1;
5656
5657 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5658
5659 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5660 f_sleep(3.0);
5661 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5662
5663 setverdict(pass);
5664
5665}
5666testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5667 var ConnHdlrPars pars;
5668 var ConnHdlr vc_conn;
5669 f_init();
5670
5671 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5672 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5673 vc_conn.done;
5674}
5675
5676/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005677private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005678 var PCUIF_Message first_info;
5679 var integer ts_nr := g_chan_nr.tn;
5680 var integer trx_nr := 0;
5681 var integer bts_nr := 0;
5682 var integer pcu_conn_id := -1;
5683
5684 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5685
5686 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5687 "RSL CHAN ACT");
5688 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5689 "RF CHAN REL", true);
5690 setverdict(pass);
5691}
5692testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5693 var ConnHdlrPars pars;
5694 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005695 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005696
5697 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5698 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5699 vc_conn.done;
5700}
5701
5702/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005703private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005704 var PCUIF_Message first_info;
5705 var integer ts_nr := g_chan_nr.tn;
5706 var integer trx_nr := 0;
5707 var integer bts_nr := 0;
5708 var integer pcu_conn_id := -1;
5709
5710 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5711
5712 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5713 "RSL CHAN ACT");
5714
5715 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5716 alt {
5717 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5718 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005720 }
5721 [] RSL.receive { repeat; }
5722 }
5723
5724 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5725 "RF CHAN REL", true);
5726 setverdict(pass);
5727}
5728testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5729 var ConnHdlrPars pars;
5730 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005731 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005732
5733 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5734 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5735 vc_conn.done;
5736}
5737
5738/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005739private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005740 var PCUIF_Message first_info;
5741 var integer ts_nr := g_chan_nr.tn;
5742 var integer trx_nr := 0;
5743 var integer bts_nr := 0;
5744 var integer pcu_conn_id := -1;
5745
5746 /* register for the TCH/F channel number */
5747 f_rslem_register(0, g_chan_nr);
5748
5749 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5750
5751 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5752
5753 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5754 "RSL CHAN ACT");
5755
5756 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5757
5758 setverdict(pass);
5759}
5760testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5761 var ConnHdlrPars pars;
5762 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005763 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005764
5765 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5766 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5767 vc_conn.done;
5768}
5769
5770
Harald Welte0472ab42018-03-12 15:02:26 +01005771/***********************************************************************
5772 * LAPDm / RLL related
5773 ***********************************************************************/
5774
5775private function f_tx_lapdm(template (value) LapdmFrame l,
5776 template (value) RslLinkId link_id) runs on ConnHdlr {
5777 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005778 var template (value) SacchL1Header l1h;
5779
5780 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005781 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005782 /* Compose dummy L1 header */
5783 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5784 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1h, f_pad_oct(l2, 21, '2B'O)));
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02005785 } else {
5786 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005787 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, f_pad_oct(l2, 23, '2B'O)));
Harald Welte0472ab42018-03-12 15:02:26 +01005788 }
Harald Welte0472ab42018-03-12 15:02:26 +01005789}
5790
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005791private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005792 uint3_t sapi,
5793 RslLinkId link_id,
5794 octetstring l3,
5795 boolean exp
5796}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005797private type record of RllTestCase RllTestCases;
5798private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5799 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005800 sapi := sapi,
5801 link_id := id,
5802 l3 := l3,
5803 exp := exp
5804}
5805
5806/* execute the same callback function with a set of different parameters (tcs) on a
5807 * variety of logical channels */
5808private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5809 var ConnHdlrPars pars;
5810 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005811 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005812
5813 /* test on each of the channels we have */
5814 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5815 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5816
5817 /* test each of the test cases on the current channel */
5818 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5819 pars.spec.rll := tcs[j];
5820 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5821 vc_conn := f_start_handler(fn, pars);
5822 vc_conn.done;
5823 }
5824 }
5825
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005827}
5828
5829/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5830private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5831 var RllTestCase tc := g_pars.spec.rll;
5832 timer T := 3.0;
5833
5834 f_l1_tune(L1CTL);
5835 RSL.clear;
5836
5837 /* activate the logical channel */
5838 f_est_dchan();
5839 L1CTL.clear;
5840
5841 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5842 T.start;
5843 alt {
5844 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5845 if (tc.exp) {
5846 setverdict(pass);
5847 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005849 }
5850 }
5851 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5852 if (tc.exp) {
5853 setverdict(pass);
5854 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005856 }
5857 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005858 /* We also expect to receive the measurements */
5859 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005860 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005862 }
5863 [not tc.exp] T.timeout {
5864 setverdict(pass);
5865 }
5866 }
5867
5868 f_rsl_chan_deact();
5869 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5870 f_rslem_unregister(0, g_chan_nr);
5871}
5872testcase TC_rll_est_ind() runs on test_CT {
5873 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005874 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005875 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005876 /* normal SAPI0 establishment */
5877 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005878 /* SAPI 3 doesn't support contention resolution */
5879 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5880 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5881 /* normal SAPI3 establishment on main DCCH */
5882 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5883 /* normal SAPI3 establishment on SACCH */
5884 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5885 };
5886 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5887}
5888
5889/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5890private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5891 var RllTestCase tc := g_pars.spec.rll;
5892 var L1ctlDlMessage dl;
5893 timer T := 3.0;
5894
5895 f_l1_tune(L1CTL);
5896 RSL.clear;
5897
5898 /* activate the logical channel */
5899 f_est_dchan();
5900 L1CTL.clear;
5901
5902 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5903 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5904 T.start;
5905 alt {
5906 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5907 var LapdmFrame lapdm;
5908 var octetstring l2 := dl.payload.data_ind.payload;
5909 if (dl.dl_info.link_id.c == SACCH) {
5910 /* remove L1 header */
5911 l2 := substr(l2, 2, lengthof(l2)-2);
5912 }
5913 lapdm.ab := dec_LapdmFrameAB(l2);
5914 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5915 setverdict(pass);
5916 } else {
5917 repeat;
5918 }
5919 }
5920 [] L1CTL.receive { repeat; }
5921 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005923 }
5924 }
5925
5926 f_rsl_chan_deact();
5927 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5928 f_rslem_unregister(0, g_chan_nr);
5929}
5930testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5931 var RllTestCases tcs := {
5932 /* normal SAPI3 establishment on main DCCH */
5933 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5934 };
5935 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5936}
5937testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5938 var RllTestCases tcs := {
5939 /* normal SAPI3 establishment on SACCH */
5940 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5941 }
5942 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5943}
5944
5945/* altstep to receive a LAPDm frame matching the given template */
5946private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5947 var L1ctlDlMessage dl;
5948 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5949 var LapdmFrame lapdm;
5950 var octetstring l2 := dl.payload.data_ind.payload;
5951 if (dl.dl_info.link_id.c == SACCH) {
5952 /* remove L1 header */
5953 l2 := substr(l2, 2, lengthof(l2)-2);
5954 }
5955 if (ischosen(exp.ab)) {
5956 lapdm.ab := dec_LapdmFrameAB(l2);
5957 } else if (ischosen(exp.b4)) {
5958 lapdm.b4 := dec_LapdmFrameB4(l2);
5959 } else if (ischosen(exp.bbis)) {
5960 lapdm.bbis := dec_LapdmFrameBbis(l2);
5961 }
5962 log("Rx LAPDm ", lapdm);
5963 if (match(lapdm, exp)) {
5964 setverdict(pass);
5965 } else {
5966 repeat;
5967 }
5968 }
5969 [] L1CTL.receive { repeat; }
5970}
5971private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5972 timer T := t;
5973 T.start;
5974 alt {
5975 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005977 }
5978 [] as_l1_exp_lapdm(exp);
5979 }
5980}
5981
5982/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5983private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5984 /* send SABM from MS -> BTS */
5985 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5986 /* expect RLL EST IND on Abis */
5987 alt {
5988 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5989 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5990 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005992 }
5993 [] RSL.receive { repeat; }
5994 }
5995 /* expect UA from BTS -> MS */
5996 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5997}
5998
5999/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6000private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6001 var RllTestCase tc := g_pars.spec.rll;
6002
6003 f_l1_tune(L1CTL);
6004 RSL.clear;
6005
6006 /* activate the logical channel */
6007 f_est_dchan();
6008 L1CTL.clear;
6009
6010 /* first establish the link-layer */
6011 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6012
6013 /* then send the DISC */
6014 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6015 /* ... and expect the REL IND on the RSL side */
6016 alt {
6017 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6018 setverdict(pass);
6019 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006020 /* We also expect to receive the measurements */
6021 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006022 }
6023
6024 /* release the channel */
6025 f_rsl_chan_deact();
6026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6027 f_rslem_unregister(0, g_chan_nr);
6028}
6029testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6030 var RllTestCases tcs := {
6031 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6032 };
6033 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6034}
6035
6036testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6037 var RllTestCases tcs := {
6038 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6039 };
6040 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6041}
6042testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6043 var RllTestCases tcs := {
6044 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6045 };
6046 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6047}
6048testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6049 var RllTestCases tcs := {
6050 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6051 };
6052 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6053}
6054
6055/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6056private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6057 var RllTestCase tc := g_pars.spec.rll;
6058 f_l1_tune(L1CTL);
6059 RSL.clear;
6060
6061 /* activate the logical channel */
6062 f_est_dchan();
6063 L1CTL.clear;
6064
6065 /* first establish the link-layer */
6066 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6067
6068 /* then send the REL REQ via RSL */
6069 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6070 /* ... and expect the DISC on the Um side */
6071 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006072 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006073 /* FIXME: send a UA in resposne to the DISC */
6074 }
6075 }
6076
6077 /* release the channel */
6078 f_rsl_chan_deact();
6079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6080 f_rslem_unregister(0, g_chan_nr);
6081}
6082testcase TC_rll_rel_req() runs on test_CT {
6083 var RllTestCases tcs := {
6084 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6085 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6086 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6087 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6088 };
6089 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6090}
6091
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006092/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006093testcase TC_rll_data_req() runs on test_CT {
6094}
6095
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006096/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006097testcase TC_rll_data_ind() runs on test_CT {
6098}
6099
6100/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6101private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6102 var RllTestCase tc := g_pars.spec.rll;
6103
6104 f_l1_tune(L1CTL);
6105 RSL.clear;
6106
6107 f_est_dchan();
6108 L1CTL.clear;
6109
6110 /* Send UNITDATA REQ on RSL side */
6111 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6112 /* Expect it to arrive on the other side */
6113 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006114 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006115 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006116 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006117 }
6118
6119 /* release the channel */
6120 f_rsl_chan_deact();
6121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6122 f_rslem_unregister(0, g_chan_nr);
6123}
6124testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6125 var octetstring l3 := f_rnd_octstring(15);
6126 var RllTestCases tcs := {
6127 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6128 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6129 };
6130 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6131}
6132testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6133 var octetstring l3 := f_rnd_octstring(19);
6134 var RllTestCases tcs := {
6135 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6136 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6137 };
6138 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6139}
6140
6141/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6142private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6143 var RllTestCase tc := g_pars.spec.rll;
6144
6145 f_l1_tune(L1CTL);
6146 RSL.clear;
6147
6148 f_est_dchan();
6149 L1CTL.clear;
6150
6151 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006152 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006153 /* Expdct RLL UNITDATA IND on RSL side */
6154 alt {
6155 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6156 setverdict(pass);
6157 }
6158 [] RSL.receive { repeat; }
6159 }
6160
6161 /* release the channel */
6162 f_rsl_chan_deact();
6163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6164 f_rslem_unregister(0, g_chan_nr);
6165}
6166testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006167 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006168 var RllTestCases tcs := {
6169 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6170 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6171 };
6172 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6173}
6174testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6175 var octetstring l3 := f_rnd_octstring(18);
6176 var RllTestCases tcs := {
6177 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6178 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6179 };
6180 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6181}
6182
Harald Weltee613f962018-04-18 22:38:16 +02006183/***********************************************************************
6184 * Encryption Related
6185 ***********************************************************************/
6186
6187/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006188private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006189 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6190 if (link_id.c == SACCH) {
6191 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6192 } else {
6193 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6194 }
6195}
6196
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006197/* Expect (or not expect) other kinds of messages */
6198private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6199 [exp_any] RSL.receive { repeat; }
6200 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006202 }
6203}
6204
Harald Weltee613f962018-04-18 22:38:16 +02006205/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006206private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006207 RslLinkId link_id,
6208 octetstring l3,
6209 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006210 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006211) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006212 timer T := 3.0;
6213 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6214 T.start;
6215 /* Expect RLL UNITDATA IND on RSL side */
6216 alt {
6217 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6218 setverdict(pass);
6219 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006220 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006221 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006222 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006224 }
Harald Weltee613f962018-04-18 22:38:16 +02006225 }
6226}
6227
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006228/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6229private function f_data_mo(
6230 RslLinkId link_id,
6231 boolean p, uint3_t nr, uint3_t ns,
6232 octetstring l3,
6233 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006234 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006235) runs on ConnHdlr {
6236 timer T := 3.0;
6237 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6238 T.start;
6239 /* Expect RLL DATA IND on RSL side */
6240 alt {
6241 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6242 setverdict(pass);
6243 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006244 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006245 [] as_rsl_any_ind(exp_any);
6246 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006248 }
6249 }
6250}
6251
Harald Weltee613f962018-04-18 22:38:16 +02006252/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006253private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006254 f_l1_tune(L1CTL);
6255 f_est_dchan(true);
6256
6257 /* now we actually need to transmit some data both ways to check if the encryption works */
6258 var L1ctlDlMessage dl;
6259
Stefan Sperling603d98e2018-07-25 16:47:28 +02006260 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006261 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6262
6263 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6264 f_unitdata_mt(link_id, l3);
6265
6266 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6267 f_unitdata_mo(link_id, l3);
6268
6269 /* release the channel */
6270 f_rsl_chan_deact();
6271 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6272 f_rslem_unregister(0, g_chan_nr);
6273}
6274testcase TC_chan_act_a51() runs on test_CT {
6275 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6276 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6277 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6278}
6279testcase TC_chan_act_a52() runs on test_CT {
6280 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6281 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6282 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6283}
6284testcase TC_chan_act_a53() runs on test_CT {
6285 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6286 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6287 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6288}
6289
Eric Wildf1827a72019-05-28 17:37:35 +02006290/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6291 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006292private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006293 f_l1_tune(L1CTL);
6294 f_est_dchan(true);
6295
6296 /* now we actually need to transmit some data both ways to check if the encryption works */
6297 var L1ctlDlMessage dl;
6298
6299 var octetstring l3 := f_rnd_octstring(20);
6300 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6301
6302 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6303 f_unitdata_mt(link_id, l3);
6304
6305 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6306 f_unitdata_mo(link_id, l3);
6307
6308 var RSL_Message rsl;
6309 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6310
6311 /* modify key to break proper encryption */
6312 g_pars.encr.key := f_rnd_octstring(8);
6313 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6314 rsl.ies := rsl.ies & { ei };
6315 RSL.send(rsl);
6316
6317 timer T0 := 1.0;
6318 T0.start;
6319 /* Expect RSL MODIFY ACK */
6320 alt {
6321 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6322 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6324 }
6325 [] T0.timeout {
6326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6327 }
6328 }
6329
6330 var octetstring l3msg := f_rnd_octstring(15);
6331 timer T1 := 3.0;
6332 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6333 due to broken encryption */
6334 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6335 T1.start;
6336 alt {
6337 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6339 }
6340 [] T1.timeout {
6341 setverdict(pass);
6342 }
6343 }
6344
6345 /* release the channel */
6346 f_rsl_chan_deact();
6347 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6348 f_rslem_unregister(0, g_chan_nr);
6349}
6350testcase TC_rsl_modify_encr() runs on test_CT {
6351 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6352 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6353 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6354}
Harald Weltee613f962018-04-18 22:38:16 +02006355
6356/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006357private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006358 /* L3 payload doesn't matter, as it is passed transparently */
6359 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6360 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6361 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6362
6363 f_l1_tune(L1CTL);
6364
6365 /* first establish a dedicated channel in the clear */
6366 f_est_dchan(false);
6367
6368 /* Establish ABM */
6369 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6370
6371 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6372 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6373 /* expect the L3 to arrive still unencrypted on the MS side */
6374 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6375
6376 /* configure L1 to apply ciphering */
6377 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6378 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6379
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006380 /* send first ciphered I-frame in response and expect it on RSL */
6381 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006382
6383 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6384 * and hence enable encryption also on the downlink */
6385
6386 /* expect bi-directional communication work in encrypted mode */
6387 f_unitdata_mo(link_id, f_rnd_octstring(15));
6388 f_unitdata_mt(link_id, f_rnd_octstring(15));
6389
6390 /* release the channel */
6391 f_rsl_chan_deact();
6392 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6393 f_rslem_unregister(0, g_chan_nr);
6394}
6395testcase TC_encr_cmd_a51() runs on test_CT {
6396 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6397 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6398 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6399}
6400testcase TC_encr_cmd_a52() runs on test_CT {
6401 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6402 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6403 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6404}
6405testcase TC_encr_cmd_a53() runs on test_CT {
6406 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6407 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6408 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6409}
6410
6411private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6412 var LapdmFrame lf;
6413 var octetstring reenc;
6414
6415 /* decode the LAPDm frame */
6416 if (ischosen(exp_match.ab)) {
6417 lf.ab := dec_LapdmFrameAB(enc);
6418 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006420 }
6421
6422 /* check if decoder result matches expectation */
6423 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006425 } else {
6426 log(name, ": matched");
6427 setverdict(pass);
6428 }
6429
6430 /* test if re-encoded frame equals original input */
6431 reenc := enc_LapdmFrame(lf);
6432 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006434 } else {
6435 setverdict(pass);
6436 }
6437}
6438
6439testcase TC_lapdm_selftest() runs on test_CT {
6440 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6441 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6442 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6443 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6444 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6445 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6446 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6447}
6448
Stefan Sperling4880be42018-08-07 18:12:59 +02006449/***********************************************************************
6450 * DTX Related (see GSM 05.08, section 8.3)
6451 ***********************************************************************/
6452
6453/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006454private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006455 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6456 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6457 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6458 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6459}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006460private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006461 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6462 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6463}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006464private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006465 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6466 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6467 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6468 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6469}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006470private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006471 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6472 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6473 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6474 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6475 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6476 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6477 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6478 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6479}
6480
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006481private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006482 var L1ctlDlMessage dl;
6483 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6484 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6485 var GsmFrameNumber first_fn;
6486 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006487 var integer nfill_frames_sacch := 0;
6488 var integer nfill_frames_nonsacch := 0;
6489 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006490 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6491 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006492 const integer frame_dtx_tchf_mod := 104;
6493 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6494 * which operates in terms of blocks rather than frames. */
6495 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6496 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006497 timer T := 5.0;
6498
6499 f_l1_tune(L1CTL);
6500 RSL.clear;
6501 L1CTL.clear;
6502
6503 /* activate TCHF signalling channel */
6504 f_est_dchan(false);
6505
6506 T.start;
6507 alt {
6508 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6509 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6510 var octetstring l2 := dl.payload.data_ind.payload;
6511
6512 if (is_first_frame) {
6513 is_first_frame := false;
6514 first_fn := dl.dl_info.frame_nr;
6515 }
6516
6517 if (dl.dl_info.link_id.c == SACCH) {
6518 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6519 if (not match(l2_fill_frame_sacch, l2)) {
6520 repeat;
6521 }
6522 } else if (not match(l2_fill_frame, l2)) {
6523 repeat;
6524 }
6525
6526 if (dtxd) {
6527 if (not f_g_chan_is_tchf()) {
6528 T.stop;
6529 f_rsl_chan_deact();
6530 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02006532 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006533 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006534 T.stop;
6535 f_rsl_chan_deact();
6536 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006537
6538 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6539 * 2 SACCH, 1 TCH/F */
6540 expected_fill_frames := 3;
6541
6542 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6543 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6544 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006546 } else {
6547 setverdict(pass);
6548 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006549 } else {
6550 if (dl.dl_info.link_id.c == SACCH) {
6551 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006552 repeat;
6553 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006554 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6555 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6556 * we should only see the subset of frames numbers which correspond to a block boundary.
6557 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6558 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6559 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6560 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6561 repeat;
6562 }
6563 }
6564 log("Received DTX TCH fill frame with bad frame number: ", fn,
6565 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6566 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6567 f_rsl_chan_deact();
6568 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006570 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006571 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006572 if (dl.dl_info.link_id.c == SACCH) {
6573 nfill_frames_sacch := nfill_frames_sacch + 1;
6574 } else {
6575 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6576 }
6577 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006578 T.stop;
6579 if (f_g_chan_is_tchf()) {
6580 /* Without DTX we can expect 25 fill frames for every 104 frames.
6581 * (24 FACCH + 1 SACCH filling) */
6582 expected_fill_frames := 25;
6583 } else if (f_g_chan_is_tchh()) {
6584 /* We can expect 2 fill frames for every 104 frames. */
6585 expected_fill_frames := 2;
6586 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6587 /* We can expect 5 fill frames for every 104 frames. */
6588 expected_fill_frames := 5;
6589 } else {
6590 f_rsl_chan_deact();
6591 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006593 }
6594
6595 f_rsl_chan_deact();
6596 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006597
6598 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 setverdict(pass);
6600 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006601 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6602 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006604 }
6605 } else {
6606 repeat;
6607 }
6608 }
6609 }
6610 [] L1CTL.receive { repeat; }
6611 [] T.timeout {
6612 f_rsl_chan_deact();
6613 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006615 }
6616 }
6617}
6618
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006619private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006620 f_test_l2_fill_frames(false);
6621}
6622
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006623private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006624 f_test_l2_fill_frames(true);
6625}
6626
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006627private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006628 var ConnHdlr vc_conn;
6629 var ConnHdlrPars pars;
6630 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006631 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006632 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6633 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6634 if (dtxd) {
6635 if (i >= 4) { /* DTX is only allowed on TCH/F */
6636 break;
6637 }
6638 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6639 } else {
6640 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6641 }
6642 vc_conn.done;
6643 }
6644}
6645
6646/* Verify that L2 fill frames are sent on TCH in signaling mode if
6647 * there is nothing to transmit while DTX is disabled on downlink. */
6648testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6649 f_tch_sign_l2_fill_frame(false);
6650}
6651
6652/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6653 * there is nothing to transmit while DTX is enabled on downlink. */
6654testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6655 f_tch_sign_l2_fill_frame(true);
6656}
Harald Welte0472ab42018-03-12 15:02:26 +01006657
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006658testcase TC_chopped_ipa_ping() runs on test_CT {
6659 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6660}
6661
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006662testcase TC_chopped_ipa_payload() runs on test_CT {
6663 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6664}
6665
Harald Welte0472ab42018-03-12 15:02:26 +01006666/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6667/* protocol error as per 44.006 */
6668/* link layer failure (repetition of I-frame N200 times without ACK */
6669/* repetition of SABM or DISC N200 times without ACK */
6670/* receptiom of SABM in multi-frame established state */
6671
6672
Harald Welte68e495b2018-02-25 00:05:57 +01006673/* TODO Areas:
6674
6675* channel activation
6676** with BS_Power / MS_Power, bypassing power control loop
6677** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006678** with timing advance from initial activation on
6679* mode modify
6680** encryption
6681** multirate
6682* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006683** unsupported algorithm
6684* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006685* BS Power Control
6686* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006687* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006688* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006689** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006690* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006691** DATA_IND from BTS->PCU
6692** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006693
6694*/
Harald Welte70767382018-02-21 12:16:40 +01006695
6696control {
6697 execute( TC_chan_act_stress() );
6698 execute( TC_chan_act_react() );
6699 execute( TC_chan_deact_not_active() );
6700 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006701 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006702 execute( TC_sacch_filling() );
6703 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006704 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006705 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006706 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006707 execute( TC_sacch_chan_act_ho_async() );
6708 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006709 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006710 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006711 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006712 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006713 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006714 execute( TC_rach_load_idle_thresh0() );
6715 execute( TC_rach_load_idle_below_thresh() );
6716 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006717 execute( TC_meas_res_sign_tchf() );
6718 execute( TC_meas_res_sign_tchh() );
6719 execute( TC_meas_res_sign_sdcch4() );
6720 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006721 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006722 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006723 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006724 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006725 execute( TC_rsl_bs_pwr_static_ass() );
6726 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006727 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006728 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006729 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006730 execute( TC_rsl_ms_pwr_dyn_up() );
6731 execute( TC_rsl_ms_pwr_dyn_down() );
6732 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6733 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006734 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006735 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006736 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006737 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006738 execute( TC_paging_imsi_80percent() );
6739 execute( TC_paging_tmsi_80percent() );
6740 execute( TC_paging_imsi_200percent() );
6741 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006742 execute( TC_rsl_protocol_error() );
6743 execute( TC_rsl_mand_ie_error() );
6744 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006745 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006746 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006747 execute( TC_si_sched_2bis() );
6748 execute( TC_si_sched_2ter() );
6749 execute( TC_si_sched_2ter_2bis() );
6750 execute( TC_si_sched_2quater() );
6751 execute( TC_si_sched_13() );
6752 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006753 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006754 execute( TC_ipa_crcx_twice_not_active() );
6755 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006756 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006757 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006758
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006759 if (mp_pcu_socket != "") {
6760 execute( TC_pcu_act_req() );
6761 execute( TC_pcu_act_req_wrong_ts() );
6762 execute( TC_pcu_act_req_wrong_bts() );
6763 execute( TC_pcu_act_req_wrong_trx() );
6764 execute( TC_pcu_deact_req() );
6765 execute( TC_pcu_deact_req_wrong_ts() );
6766 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006767 if (mp_l1_supports_gprs) {
6768 execute( TC_pcu_data_req_pdtch() );
6769 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006770 execute( TC_pcu_data_req_wrong_bts() );
6771 execute( TC_pcu_data_req_wrong_trx() );
6772 execute( TC_pcu_data_req_wrong_ts() );
6773 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006774 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006775 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006776 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006777 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006778 execute( TC_pcu_data_req_imm_ass_pch() );
6779 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006780 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006781 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006782 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006783 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006784 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006785 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006786 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006787 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006788 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006789 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006790 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006791 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006792 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006793 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006794 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006795 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006796 execute( TC_dyn_osmo_pdch_act_deact() );
6797 execute( TC_dyn_osmo_pdch_double_act() );
6798 execute( TC_dyn_ipa_pdch_act_deact() );
6799 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6800
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006801 } else {
6802 log("PCU socket path not available, skipping PCU tests");
6803 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006804
Harald Welte3d04ae62018-04-04 20:29:05 +02006805 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006806 execute( TC_dyn_osmo_pdch_tchf_act() );
6807 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006808 execute( TC_dyn_ipa_pdch_tchf_act() );
6809 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006810
6811 execute( TC_rll_est_ind() );
6812 execute( TC_rll_est_req_DCCH_3() );
6813 execute( TC_rll_est_req_ACCH_3() );
6814 execute( TC_rll_rel_ind_DCCH_0() );
6815 execute( TC_rll_rel_ind_DCCH_3() );
6816 execute( TC_rll_rel_ind_ACCH_0() );
6817 execute( TC_rll_rel_ind_ACCH_3() );
6818 execute( TC_rll_rel_req() );
6819 execute( TC_rll_unit_data_req_DCCH() );
6820 execute( TC_rll_unit_data_req_ACCH() );
6821 execute( TC_rll_unit_data_ind_DCCH() );
6822 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006823
6824 execute( TC_chan_act_a51() );
6825 execute( TC_chan_act_a52() );
6826 execute( TC_chan_act_a53() );
6827 execute( TC_encr_cmd_a51() );
6828 execute( TC_encr_cmd_a52() );
6829 execute( TC_encr_cmd_a53() );
6830
Harald Welteee25aae2019-05-19 14:32:37 +02006831 execute( TC_err_rep_wrong_mdisc() );
6832 execute( TC_err_rep_wrong_msg_type() );
6833 execute( TC_err_rep_wrong_sequence() );
6834
Harald Weltee613f962018-04-18 22:38:16 +02006835 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006836
6837 execute( TC_tch_sign_l2_fill_frame() );
6838 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006839
6840 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006841 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006842}
6843
6844
6845}