blob: 1cecf4e4609dc5c34ac1e34541382714ead82a94 [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 Yanitskiy6c71c172020-07-13 21:49:48 +07001152 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001170 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001208 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001226 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001244 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001263 f_l1ctl_est_dchan(L1CTL, g_pars);
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 Yanitskiy6c71c172020-07-13 21:49:48 +07001629 f_l1ctl_est_dchan(L1CTL, g_pars);
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
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001993/* Tune to a dedicated channel: L1CTL only */
1994private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
1995 if (not ispresent(pars.maio_hsn)) {
1996 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
1997 7 /* TODO: mp_tsc */,
1998 mp_trx0_arfcn));
1999 } else {
2000 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2001 7 /* TODO: mp_tsc */,
2002 pars.maio_hsn.hsn,
2003 pars.maio_hsn.maio,
2004 pars.ma));
2005 }
2006}
2007
Harald Welte70767382018-02-21 12:16:40 +01002008/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002009private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002010 var GsmFrameNumber fn;
2011 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002012 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002013 var integer ra := 23;
2014
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002015 /* Send RACH request and wait for ChanReq */
2016 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002017
2018 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002019 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002020
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002021 /* Craft channel description (with or without frequency hopping parameters) */
2022 if (ispresent(g_pars.maio_hsn)) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002023 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002024 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002025 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002026 }
2027
Harald Welte70767382018-02-21 12:16:40 +01002028 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002029 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002030 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2031
2032 /* receive IMM.ASS on MS side */
2033 var ImmediateAssignment ia_um;
2034 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002035
2036 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2037 if (ch_desc.h != ia_um.chan_desc.h) {
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2039 }
2040
Harald Welte70767382018-02-21 12:16:40 +01002041 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002042 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002043 /* enable encryption, if requested */
2044 if (encr_enable) {
2045 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2046 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2047 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002048
2049 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002050}
2051
2052/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002053private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002054 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002055 RSL.clear;
2056
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002057 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002058 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002059 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002060 }
Harald Welte70767382018-02-21 12:16:40 +01002061
2062 f_est_dchan();
2063
2064 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2065 * RSL measurement reports on Abis side */
2066 timer T := 8.0;
2067 T.start;
2068 alt {
2069 [] as_l1_sacch();
2070 [] as_meas_res();
2071 [] as_l1_dcch();
2072 [] L1CTL.receive { repeat; }
2073 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002074 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002075 * of any earlier errors, so if we reach this timeout, we're good */
2076 setverdict(pass);
2077 }
2078 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002080 }
2081 }
2082 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002083 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002084}
Harald Welte0472ab42018-03-12 15:02:26 +01002085
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002086/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2087private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002088 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002089 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2090 timer Tup := 10.0;
2091 Tup.start;
2092 alt {
2093 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2094 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2095 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002096
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002097 if (rx_lvl != max_rx_lvl) {
2098 repeat;
2099 }
2100 Tup.stop;
2101 }
2102 [] L1CTL.receive { repeat; }
2103 [] Tup.timeout {
2104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2105 log2str("Didn't reach full power ", max_rx_lvl));
2106 }
2107 }
2108 return max_rx_lvl;
2109}
2110
2111/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2112private function f_verify_ramp_up() runs on ConnHdlr {
2113 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002114 var integer initial_rx_lvl := -1;
2115 var integer last_rx_lvl := -1;
2116 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2117
2118 timer T := 2.0;
2119 alt {
2120 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2121 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2122 log("Received rx_level=", rx_lvl);
2123 if (initial_rx_lvl == -1) {
2124 initial_rx_lvl := rx_lvl;
2125 last_rx_lvl := rx_lvl;
2126
2127 /* Expect a somehow low value during first received messages */
2128 if (initial_rx_lvl >= max_rx_lvl / 2) {
2129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2130 log2str("Detected high initial tx power during ramp up: ",
2131 initial_rx_lvl , ", full power is", max_rx_lvl));
2132 }
2133 }
2134
2135 /* received Rx level bigger than maximum allowed power by CN */
2136 if (rx_lvl > max_rx_lvl) {
2137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2138 log2str("Detected Tx power higher than full power: ",
2139 rx_lvl , " > ", max_rx_lvl));
2140 }
2141
2142 /* Make sure it never decreases, since we are rumping up */
2143 if (last_rx_lvl > rx_lvl) {
2144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2145 log2str("Detected Tx power decrease during ramp up: ",
2146 last_rx_lvl , " -> ", rx_lvl));
2147 }
2148
2149 if (rx_lvl == max_rx_lvl and not T.running) {
2150 /* We reached the maximum power, start timer and receive
2151 /* a few more to make sure we don't surpass it */
2152 log("Reached full power, wating a bit more until success");
2153 T.start;
2154 }
2155
2156 last_rx_lvl := rx_lvl;
2157 repeat;
2158 }
2159 [] L1CTL.receive { repeat; }
2160 [] T.timeout { }
2161 }
2162
2163 /* We didn't increase tx power during ramp up */
2164 if (initial_rx_lvl < last_rx_lvl) {
2165 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2166 } else {
2167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2168 log2str("No Tx power increase during whole ramp up: ",
2169 initial_rx_lvl , " -> ", last_rx_lvl));
2170 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002171}
2172
2173/* verify BTS ramps power down to rx_level 0 */
2174private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2175 var L1ctlDlMessage l1_dl;
2176 var integer last_rx_lvl := max_rx_lvl;
2177
2178 timer Tdown := 5.0;
2179 Tdown.start;
2180 alt {
2181 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2182 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2183 log("Received rx_level=", rx_lvl);
2184
2185 /* received Rx level bigger than maximum allowed power by CN */
2186 if (rx_lvl > max_rx_lvl) {
2187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2188 log2str("Detected Tx power higher than full power: ",
2189 rx_lvl , " > ", max_rx_lvl));
2190 }
2191
2192 /* Make sure it never increases, since we are rumping down */
2193 if (last_rx_lvl < rx_lvl) {
2194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2195 log2str("Detected Tx power increase during ramp up: ",
2196 last_rx_lvl , " -> ", rx_lvl));
2197 }
2198
2199 last_rx_lvl := rx_lvl;
2200 if (last_rx_lvl != 0) {
2201 repeat;
2202 }
2203 /* we reached power level 0, we are done */
2204 Tdown.stop;
2205 }
2206 [] L1CTL.receive { repeat; }
2207 [] Tdown.timeout { }
2208 }
2209
2210 /* We didn't increase tx power during ramp down */
2211 if (max_rx_lvl > last_rx_lvl) {
2212 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2213 } else {
2214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2215 log2str("No Tx power decrease during whole ramp down: ",
2216 max_rx_lvl , " -> ", last_rx_lvl));
2217 }
2218}
2219
2220/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002221private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002222 f_l1_tune(L1CTL);
2223 RSL.clear;
2224
2225 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002226
2227 setverdict(pass);
2228}
2229testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2230 var ConnHdlr vc_conn;
2231 var ConnHdlrPars pars;
2232 f_init();
2233 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2234 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2235 pcu_comp := false, trxc_comp := true);
2236 vc_conn.done;
2237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2238}
2239
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002240/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002241private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002242 f_connhdlr_init_vty_bsc();
2243
2244 f_l1_tune(L1CTL);
2245 RSL.clear;
2246
2247 /* Wait until BTS is started and at full power */
2248 var integer max_rx_lvl := f_wait_ramp_up();
2249 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2250
2251 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2252 f_verify_ramp_down(max_rx_lvl);
2253
2254 setverdict(pass);
2255}
2256testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2257 var ConnHdlr vc_conn;
2258 var ConnHdlrPars pars;
2259 f_init();
2260 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2261 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2262 pcu_comp := false, trxc_comp := true);
2263 vc_conn.done;
2264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2265}
2266
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002267/* Verify Tx power:
2268 * + ramping down during ADM state UNLOCKED->LOCKED
2269 * + ramping up during ADM state LOCKED->UNLOCKED
2270 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002271private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002272 var L1ctlDlMessage l1_dl;
2273 var integer last_rx_lvl;
2274
2275 f_connhdlr_init_vty_bsc();
2276
2277 f_l1_tune(L1CTL);
2278 RSL.clear;
2279
2280 /* Wait until BTS is started and at full power */
2281 var integer max_rx_lvl := f_wait_ramp_up();
2282 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2283
2284 log("ADM STATE UNLOCKED->LOCKED");
2285 f_vty_enter_cfg_trx(BSCVTY);
2286 f_vty_transceive(BSCVTY, "rf_locked 1");
2287 last_rx_lvl := max_rx_lvl;
2288 f_verify_ramp_down(max_rx_lvl);
2289
2290 /* Let some time after we received 0dBm, then check we don't receive BCCH
2291 * anymore because scheduler has stopped after ramping down */
2292 f_sleep(2.0);
2293 L1CTL.clear;
2294 timer Tlocked := 2.0;
2295 Tlocked.start;
2296 alt {
2297 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2299 log2str("Received data_ind during rf_locked: ", l1_dl));
2300 }
2301 [] L1CTL.receive { repeat; }
2302 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2303 }
2304
2305 log("ADM STATE LOCKED->UNLOCKED");
2306 f_vty_transceive(BSCVTY, "rf_locked 0");
2307 f_verify_ramp_up();
2308 setverdict(pass);
2309}
2310testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2311 var ConnHdlr vc_conn;
2312 var ConnHdlrPars pars;
2313 f_init();
2314 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2315 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2316 pcu_comp := false, trxc_comp := true);
2317 vc_conn.done;
2318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2319}
2320
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002321private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002322 timer T := 8.0;
2323 T.start;
2324 var RSL_Message rsl;
2325 alt {
2326 [] as_l1_sacch();
2327 [] L1CTL.receive { repeat; }
2328 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2329 if (rsl.ies[3].body.bs_power.power_level == level) {
2330 setverdict(pass)
2331 } else {
2332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2333 }
2334 }
2335 [] T.timeout {
2336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2337 }
2338 }
2339}
2340
2341/* see if the rsl meas res contains our expeced bs power level
2342bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002343private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002344 f_l1_tune(L1CTL);
2345 RSL.clear;
2346
2347 if (mp_bts_trxc_port != -1) {
2348 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2349 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2350 }
2351
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002352 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002353 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2354 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2355
2356 f_est_dchan(more_ies :={valueof(pwr)});
2357
2358 f_check_meas_bs_power_level(pwr_var);
2359
2360 f_rsl_chan_deact();
2361 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2362}
2363
2364/* see if the rsl meas res contains our expeced bs power level
2365bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002366private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002367 f_l1_tune(L1CTL);
2368 RSL.clear;
2369
2370 if (mp_bts_trxc_port != -1) {
2371 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2372 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2373 }
2374
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002375 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002376 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2377
2378 f_est_dchan();
2379
2380 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2381
2382 f_check_meas_bs_power_level(pwr_var);
2383
2384 f_rsl_chan_deact();
2385 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2386}
2387
2388testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2389 var ConnHdlr vc_conn;
2390 var ConnHdlrPars pars;
2391 f_init();
2392 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2393 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2394 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2395 pcu_comp := false, trxc_comp := true);
2396 vc_conn.done;
2397 }
2398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2399}
2400
2401testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2402 var ConnHdlr vc_conn;
2403 var ConnHdlrPars pars;
2404 f_init();
2405 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2406 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2407 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2408 pcu_comp := false, trxc_comp := true);
2409 vc_conn.done;
2410 }
2411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2412}
2413
Eric Wild61edb7e2019-06-03 12:38:31 +02002414/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2415second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2416These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002417private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002418 var uint5_t pwr_var := 7;
2419 var L1ctlDlMessage l1_dl;
2420
2421 f_trxc_fake_rssi(rxlev2dbm(10));
2422 f_l1_tune(L1CTL);
2423 RSL.clear;
2424
2425 var RSL_IE_List addl_ies;
2426 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2427
2428 addl_ies := {
2429 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2430 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2431 };
2432
2433 /* establish with power parameters */
2434 f_est_dchan(more_ies := addl_ies);
2435
2436 /* set a high value to ensure L1 power control level increases */
2437 f_trxc_fake_rssi(rxlev2dbm(20));
2438
2439 timer T2 := 6.0;
2440 T2.start;
2441 alt {
2442 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002443 /* Update sent MS power to follow what BTS requests */
2444 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2445 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002446 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002447 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002448 T2.stop;
2449 }
2450 [] L1CTL.receive { repeat; }
2451 [] T2.timeout {
2452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2453 "Power Level in L1 header has not increased sufficiently");
2454 }
2455 }
2456
2457 /* set a low value to ensure L1 power control level decreases */
2458 f_trxc_fake_rssi(rxlev2dbm(0));
2459
2460 timer T4 := 6.0;
2461 T4.start;
2462 alt {
2463 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002464 /* Update sent MS power to follow what BTS requests */
2465 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2466 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002467 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002468 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002469 T4.stop;
2470 setverdict(pass, "Power level in L1 decreased/increased as expected");
2471 }
2472 [] L1CTL.receive { repeat; }
2473 [] T4.timeout {
2474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2475 "Power Level in L1 header has not decreased sufficiently");
2476 }
2477 }
2478
2479 f_rsl_chan_deact();
2480 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2481
2482}
2483
2484/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002485private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002486 var uint5_t pwr_var := 7;
2487 var L1ctlDlMessage l1_dl;
2488
2489 /* set a low value to ensure power increases */
2490 f_trxc_fake_rssi(rxlev2dbm(10));
2491 f_l1_tune(L1CTL);
2492 RSL.clear;
2493
2494 var RSL_IE_List addl_ies;
2495 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2496
2497 addl_ies := {
2498 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2499 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2500 };
2501
2502 /* establish with power parameters */
2503 f_est_dchan(more_ies := addl_ies);
2504
2505 timer T1 := 10.0;
2506 T1.start;
2507 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002508 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2509 /* Update sent MS power to follow what BTS requests */
2510 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2511 repeat;
2512 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002513 [] L1CTL.receive { repeat; }
2514 [] T1.timeout {
2515 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2516 setverdict(fail, "Power level in L1 header should not have changed");
2517 }
2518 }
2519 }
2520
2521 f_rsl_chan_deact();
2522 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2523
2524}
2525
2526/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002527private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002528 var L1ctlDlMessage l1_dl;
2529 var uint5_t pwr_var := 15;
2530 var uint5_t pwr_max_var := f_get_max_power_from_band();
2531
2532 /* set a low value to ensure power increases */
2533 f_trxc_fake_rssi(rxlev2dbm(10));
2534 f_l1_tune(L1CTL);
2535 RSL.clear;
2536
2537 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2538 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2539
2540 /* establish with fixed power level */
2541 f_est_dchan(more_ies :={valueof(pwr)});
2542
2543 /* check our initial power level */
2544 f_wait_for_l1_power_level(pwr_var);
2545
2546 /* update power param to enable power loop
2547 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2548 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2549
2550 /* wait, then check that our power level was reduced */
2551 timer T1 := 10.0;
2552 T1.start;
2553 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002554 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2555 /* Update sent MS power to follow what BTS requests */
2556 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2557 repeat;
2558 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002559 [] L1CTL.receive { repeat; }
2560 [] T1.timeout {
2561 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2562 if( f_power_level_is_highest_dbm(rcv) ){
2563 setverdict(pass, "Power level in L1 header reduced as expected");
2564 } else {
2565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2566 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2567 }
2568 }
2569 }
2570
2571 f_rsl_chan_deact();
2572 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2573
2574}
2575
2576/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002577private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002578 var L1ctlDlMessage l1_dl;
2579
2580 /* set a high value to ensure power decreases */
2581 f_trxc_fake_rssi(rxlev2dbm(50));
2582 f_l1_tune(L1CTL);
2583 RSL.clear;
2584
2585 var uint5_t pwr_var := 5;
2586 var uint5_t pwr_target_val := 15;
2587
2588 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2589 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2590
2591 /* establish with fixed power level */
2592 f_est_dchan(more_ies :={valueof(pwr)});
2593
2594 /* check our initial power level */
2595 f_wait_for_l1_power_level(pwr_var);
2596
2597 /* update power param to enable power loop
2598 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002599 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002600
2601 /* wait, then check that our power level was increased */
2602 timer T1 := 10.0;
2603 T1.start;
2604 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002605 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2606 /* Update sent MS power to follow what BTS requests */
2607 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2608 repeat;
2609 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002610 [] L1CTL.receive { repeat; }
2611 [] T1.timeout {
2612 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2613 setverdict(pass, "Power level in L1 header increased to lowest power value");
2614 } else {
2615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2616 "Power level in L1 header NOT increased to lowest power value");
2617 }
2618 }
2619 }
2620
2621 f_rsl_chan_deact();
2622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2623
2624}
2625
Eric Wild095024b2019-06-17 15:08:57 +02002626/* see if we change the power level without receiving power parameters, which should not happen
2627rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002628private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002629 var L1ctlDlMessage l1_dl;
2630
2631 /* set a high value to ensure power decreases */
2632 f_trxc_fake_rssi(rxlev2dbm(50));
2633 f_l1_tune(L1CTL);
2634 RSL.clear;
2635
2636 var uint5_t pwr_var := 5;
2637
2638 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2639 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2640
2641 /* establish with fixed power level */
2642 f_est_dchan(more_ies :={valueof(pwr)});
2643
2644 /* check our initial power level */
2645 f_wait_for_l1_power_level(pwr_var);
2646
2647 /* wait, then check that our power level did not change */
2648 timer T1 := 10.0;
2649 T1.start;
2650 alt {
2651 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2652 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2654 "BS power control should not be active unless we receive a power parameters IE!");
2655 }
2656 repeat;
2657 }
2658 [] L1CTL.receive { repeat; }
2659 [] T1.timeout { setverdict(pass); }
2660 }
2661
2662 f_rsl_chan_deact();
2663 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2664
2665}
2666
Eric Wild095024b2019-06-17 15:08:57 +02002667/* see if we change the power level without receiving power parameters, which should not happen
2668ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002669private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002670 var L1ctlDlMessage l1_dl;
2671
2672 /* set a high value to ensure power decreases */
2673 f_trxc_fake_rssi(rxlev2dbm(50));
2674 f_l1_tune(L1CTL);
2675 RSL.clear;
2676
2677 var uint5_t pwr_var := 5;
2678
2679 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2680 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2681
2682 /* establish with fixed power level */
2683 f_est_dchan(more_ies :={valueof(pwr)});
2684
2685 /* check our initial power level */
2686 f_wait_for_l1_power_level(pwr_var);
2687
2688 /* pwr control without power params IE, should NOT activate MS power control*/
2689 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2690
2691 /* wait, then check that our power level did not change */
2692 timer T1 := 10.0;
2693 T1.start;
2694 alt {
2695 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2696 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2698 "BS power control should not be active unless we receive a power parameters IE!");
2699 }
2700 repeat;
2701 }
2702 [] L1CTL.receive { repeat; }
2703 [] T1.timeout { setverdict(pass); }
2704 }
2705
2706 f_rsl_chan_deact();
2707 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2708
2709}
2710
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002711private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002712 var L1ctlDlMessage l1_dl;
2713 timer T0 := 10.0;
2714 T0.start;
2715 alt {
2716 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2717 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2719 "Power level in L1 header != signaled (RSL) power level.");
2720 }
2721 }
2722 [] L1CTL.receive { repeat; }
2723 [] T0.timeout {
2724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2725 "Timeout waiting for initial power level");
2726 }
2727 }
2728 T0.stop;
2729}
2730
2731private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2732 var IntegerRecord min_dbm_level;
2733 var IntegerRecord max_dbm_level;
2734 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2735
2736 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2737 if (min_dbm_level[i] == level) {
2738 return true;
2739 }
2740 }
2741 return false;
2742}
2743
2744private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2745 var IntegerRecord min_dbm_level;
2746 var IntegerRecord max_dbm_level;
2747 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2748
2749 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2750 if (max_dbm_level[i] == level) {
2751 return true;
2752 }
2753 }
2754 return false;
2755}
2756
2757private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2758 var IntegerRecord min_dbm_level;
2759 var IntegerRecord max_dbm_level;
2760 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2761 return max_dbm_level[0];
2762}
2763
2764type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002765private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002766private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2767 // 45.005 4.1.1
2768 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2769 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2770 2, 1, 0};
2771 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2772 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2773 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2774 var IntegerRecord rv;
2775
2776 select(band){
2777 case (BtsBand_allGSM){
2778 rv := gsm_power;
2779 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2780 max_dbm_level := {2, 1, 0};
2781 }
2782 case("DCS1800"){
2783 rv := dcs_power;
2784 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2785 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2786 }
2787 case("PCS1900"){
2788 rv := pcs_power;
2789 min_dbm_level := {15};
2790 max_dbm_level := {30};
2791 }
2792 }
2793
2794 return rv;
2795}
2796
2797private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2798 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2799}
2800
2801testcase TC_rsl_ms_pwr_dyn_ass_updown() 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 -100");
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_ass_updown), 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_up() 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_up), 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_max() 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 -10");
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_max), 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
2846testcase TC_rsl_ms_pwr_dyn_down() 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_down), 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 Wild280ccb82019-06-17 11:11:52 +02002861testcase TC_rsl_ms_pwr_dyn_active() 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_active), 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
Eric Wild095024b2019-06-17 15:08:57 +02002876testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2877 var ConnHdlr vc_conn;
2878 var ConnHdlrPars pars;
2879 f_init();
2880 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2881 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2882 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2883 pars.bts0_band := f_vty_get_bts0_band();
2884 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2885 vc_conn.done;
2886 }
2887 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2889}
2890
Harald Welte70767382018-02-21 12:16:40 +01002891testcase TC_meas_res_sign_tchf() runs on test_CT {
2892 var ConnHdlr vc_conn;
2893 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002894 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002895 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2896 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002897 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2898 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002899 vc_conn.done;
2900 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002902}
2903testcase TC_meas_res_sign_tchh() runs on test_CT {
2904 var ConnHdlr vc_conn;
2905 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002906 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002907 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2908 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002909 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2910 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002911 vc_conn.done;
2912 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002914}
2915testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2916 var ConnHdlr vc_conn;
2917 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002918 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002919 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2920 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002921 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2922 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002923 vc_conn.done;
2924 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002926}
2927testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2928 var ConnHdlr vc_conn;
2929 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002930 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002931 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2932 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002933 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2934 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002935 vc_conn.done;
2936 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002938}
Harald Welte685d5982018-02-27 20:42:05 +01002939testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2940 var ConnHdlr vc_conn;
2941 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002942 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002943 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2944 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2945 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2946 pars.l1_pars.toa256_enabled := true;
2947 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
2948 vc_conn.done;
2949 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01002951}
2952
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002953/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
2954 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002955private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002956 var L1ctlDlMessage l1_dl;
2957 var RSL_IE_MS_Power ms_power;
2958 var RSL_Message rsl;
2959 var uint5_t power_level := 0;
2960
2961 f_l1_tune(L1CTL);
2962 RSL.clear;
2963
2964 f_est_dchan();
2965
2966 ms_power.reserved := 0;
2967 ms_power.fpc_epc := false;
2968
2969 /* Send the first power control command. This will disable any BTS/TRX
2970 * internal power control and switch the MS (which is not in scope of
2971 * this test) to a constant power level. We start with a power level
2972 * of 0 */
2973 ms_power.power_level := power_level;
2974 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2975 RSL.send(rsl);
2976
2977 alt {
2978
2979 /* Pick all SACCH blocks for checking */
2980 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2981
2982 /* The first byte of the L1 header contains the power level.
2983 * The reserved bits and the fpc bit is set to 0, so we may
2984 * compare directly. */
2985 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
2986 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
2987 }
2988
2989 /* Signal a new power level via RSL for the next turn. */
2990 if (power_level < 31) {
2991 power_level := power_level + 1;
2992 ms_power.power_level := power_level;
2993 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2994 RSL.send(rsl);
2995 repeat;
2996 }
2997
2998 }
2999
3000 /* Ignore all other blocks */
3001 [] L1CTL.receive { repeat; }
3002
3003 }
3004
3005 f_rsl_chan_deact();
3006 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3007
3008 setverdict(pass);
3009}
3010
3011testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3012 var ConnHdlr vc_conn;
3013 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003014 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003015
3016 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3017 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3018 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3019 vc_conn.done;
3020 }
3021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3022}
Harald Welte70767382018-02-21 12:16:40 +01003023
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003024/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003025TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003026private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003027 var L1ctlDlMessage l1_dl;
3028 var uint5_t ta_to_test := 16;
3029
3030
3031 f_l1_tune(L1CTL);
3032 RSL.clear;
3033
3034 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003035 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003036
3037 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3038
3039
3040 alt {
3041
3042 /* Pick all SACCH blocks for checking */
3043 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3044
3045 /* The second byte of the L1 header contains the TA. */
3046 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3047 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3048 }
3049
3050 }
3051
3052 /* Ignore all other blocks */
3053 [] L1CTL.receive { repeat; }
3054
3055 }
3056
3057 f_rsl_chan_deact();
3058 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3059
3060 setverdict(pass);
3061}
3062
3063testcase TC_rsl_chan_initial_ta() runs on test_CT {
3064 var ConnHdlr vc_conn;
3065 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003066 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003067 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003068 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3069 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003070 vc_conn.done;
3071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3072}
3073
Eric Wilde57e1a62019-05-28 13:30:55 +02003074/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003075private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003076 var L1ctlDlMessage l1_dl;
3077 var uint5_t ms_power_level := 7;
3078
3079 var RSL_IE_MS_Power ms_power;
3080 ms_power.reserved := 0;
3081 ms_power.fpc_epc := false;
3082 ms_power.power_level := ms_power_level;
3083
3084 f_l1_tune(L1CTL);
3085 RSL.clear;
3086
3087 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3088
3089 timer T := 1.0;
3090 T.start;
3091 alt {
3092 /* Pick all SACCH blocks for checking */
3093 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3094 /* The first byte of the L1 header contains the power level.. */
3095 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3096 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3097 }
3098 }
3099 /* Ignore all other blocks */
3100 [] L1CTL.receive { repeat; }
3101 [] T.timeout {
3102 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3103 }
3104 }
3105
3106 f_rsl_chan_deact();
3107 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3108 setverdict(pass);
3109}
3110
3111testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3112 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3113 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3114}
3115
Harald Welte0472ab42018-03-12 15:02:26 +01003116/* 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 +01003117private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003118 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003119 RSL.clear;
3120
3121 f_est_dchan();
3122 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003123 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003124
3125 timer T := 40.0;
3126 T.start;
3127 alt {
3128 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3129 setverdict(pass)
3130 }
3131 [] RSL.receive { repeat };
3132 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003134 }
3135 }
3136 f_rsl_chan_deact();
3137}
3138testcase TC_conn_fail_crit() runs on test_CT {
3139 var ConnHdlr vc_conn;
3140 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003141 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003142 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3143 pars.t_guard := 60.0;
3144 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3145 vc_conn.done;
3146}
3147
Harald Welte93640c62018-02-25 16:59:33 +01003148/***********************************************************************
3149 * Paging
3150 ***********************************************************************/
3151
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003152private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003153 if (tmsi == 'FFFFFFFF'O) {
3154 return true;
3155 } else {
3156 return false;
3157 }
3158}
Harald Welte70767382018-02-21 12:16:40 +01003159
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003160private type record allowedFn { integer frame_nr }
3161private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3162private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3163private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3164private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3165private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3166private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3167private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3168private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3169private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003170{
3171 var integer frame_nr_51;
3172 frame_nr_51 := frame_nr mod 51
3173
3174 var allowedFn fn_check;
3175 fn_check.frame_nr := frame_nr_51;
3176
3177 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003179 return;
3180 }
3181
3182 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3183 return;
3184 }
3185 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3186 return;
3187 }
3188 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3189 return;
3190 }
3191 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3192 return;
3193 }
3194 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3195 return;
3196 }
3197 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3198 return;
3199 }
3200 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3201 return;
3202 }
3203 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3204 return;
3205 }
3206
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003208 return;
3209}
3210
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003211private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3212 inout integer num_paging_rcv_ids,
3213 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003214runs on test_CT {
3215 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003216 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003217 repeat;
3218 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003219 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003220 var octetstring without_plen :=
3221 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3222 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003223
3224 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3225
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003226 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3227 /* Ignore empty RR Paging Request (PCH filling) messages.
3228 * TODO: does it make sense to count them? */
3229 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003230 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3231 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003232 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003233 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3234 }
3235 } else if (match(rr, tr_PAGING_REQ2)) {
3236 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3237 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3238 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3239 }
3240 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3241 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3242 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003243 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003244 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3245 }
3246 } else if (match(rr, tr_PAGING_REQ3)) {
3247 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3248 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3249 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3250 }
3251 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3252 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3253 }
3254 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3255 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3256 }
3257 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3258 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3259 }
3260 }
3261 repeat;
3262 }
3263}
3264
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003265private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003266 boolean combined_ccch,
3267 integer bs_ag_blks_res,
3268 float load_factor,
3269 boolean exp_load_ind,
3270 boolean exp_overload,
3271 boolean use_tmsi
3272}
3273
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003274private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003275 integer num_paging_sent,
3276 integer num_paging_rcv_msgs,
3277 integer num_paging_rcv_ids,
3278 integer num_overload
3279}
3280
Harald Welte68e495b2018-02-25 00:05:57 +01003281/* Helper function for paging related testing */
3282private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003283 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003284 f_init_l1ctl();
3285 f_l1_tune(L1CTL);
3286
3287 var PagingTestState st := {
3288 num_paging_sent := 0,
3289 num_paging_rcv_msgs := 0,
3290 num_paging_rcv_ids := 0,
3291 num_overload := 0
3292 };
3293
3294 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3295 var float max_pch_imsi_per_sec;
3296 if (cfg.use_tmsi) {
3297 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3298 } else {
3299 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3300 }
3301 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3302 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003303 var float time_total := 20.0;
3304 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3305 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003306
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003307 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3308 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003309
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003310 timer T_itv := 0.0;
3311 T_itv.start;
3312 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003313 alt {
3314 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003315 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003316 st.num_overload := st.num_overload + 1;
3317 repeat;
3318 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003319 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003321 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003322 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003323 log("Rx LOAD_IND");
3324 /* FIXME: analyze/verify interval + contents */
3325 repeat;
3326 }
3327 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003328 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003329 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003330 [] T_itv.timeout {
3331 /* Send paging cmds based on elapsed time */
3332 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3333 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003334 var MobileIdentityV mi;
3335
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003336 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003337 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003338 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003339 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003340 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003341 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003342
3343 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003344 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 +02003345
3346 st.num_paging_sent := st.num_paging_sent + 1;
3347 }
3348 if (st.num_paging_sent < pkt_total) {
3349 /* Wait for interval to next PAGING COMMAND */
3350 var float time_now := T_total.read;
3351 var float next_sched := int2float(st.num_paging_sent)*interval;
3352 if (next_sched > time_now) {
3353 T_itv.start(next_sched - time_now);
3354 } else {
3355 T_itv.start(0.0);
3356 }
3357 } else {
3358 /* We are done, no need to keep counting */
3359 T_total.stop;
3360 }
3361 }
3362 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003363 }
3364 }
3365
3366 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3367 timer T_wait := 18.0;
3368 T_wait.start;
3369 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003370 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003371 [] L1CTL.receive { repeat; }
3372 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003373 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3374 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003375 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003377 }
Harald Welte68e495b2018-02-25 00:05:57 +01003378 }
3379
3380 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3381 " rcvd_ids=", st.num_paging_rcv_ids);
3382 return st;
3383}
3384
3385/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3386 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3387 * - that CCCH LOAD IND (PCH) are being generated
3388 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3389testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003390 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003391 var PagingTestCfg cfg := {
3392 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003393 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003394 load_factor := 0.8,
3395 exp_load_ind := true,
3396 exp_overload := false,
3397 use_tmsi := false
3398 };
3399 var PagingTestState st := f_TC_paging(cfg);
3400 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3402 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003403 } else {
3404 setverdict(pass);
3405 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003407}
3408
3409/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3410 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3411 * - that CCCH LOAD IND (PCH) are being generated
3412 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3413testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003414 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003415 var PagingTestCfg cfg := {
3416 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003417 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003418 load_factor := 0.8,
3419 exp_load_ind := true,
3420 exp_overload := false,
3421 use_tmsi := true
3422 };
3423 var PagingTestState st := f_TC_paging(cfg);
3424 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3426 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003427 } else {
3428 setverdict(pass);
3429 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003431}
3432
3433/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3434 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3435 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3436 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3437testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003438 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003439 var PagingTestCfg cfg := {
3440 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003441 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003442 load_factor := 2.0,
3443 exp_load_ind := true,
3444 exp_overload := true,
3445 use_tmsi := false
3446 };
3447 var PagingTestState st := f_TC_paging(cfg);
3448 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3449 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003450 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003451 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003452 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 +01003453 } else {
3454 setverdict(pass);
3455 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003457}
3458
3459/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3460 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3461 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3462 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3463testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003464 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003465 var PagingTestCfg cfg := {
3466 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003467 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003468 load_factor := 2.0,
3469 exp_load_ind := true,
3470 exp_overload := true,
3471 use_tmsi := true
3472 };
3473 var PagingTestState st := f_TC_paging(cfg);
3474 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3475 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003476 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003477 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003478 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 +01003479 } else {
3480 setverdict(pass);
3481 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003483}
3484
3485
Harald Welte93640c62018-02-25 16:59:33 +01003486/***********************************************************************
3487 * Immediate Assignment / AGCH
3488 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003489private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003490 len := 0,
3491 ma := ''B
3492}
Harald Welte93640c62018-02-25 16:59:33 +01003493
Harald Weltee8d750e2018-06-10 21:41:35 +02003494private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3495 return int2str(num_tx) & " sent, "
3496 & int2str(num_rx) & " received, "
3497 & int2str(num_del) & " deleted";
3498}
3499
3500private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3501 var L1ctlDlMessage l1_dl;
3502 timer T := 10.0;
3503 var integer num_tx := 0;
3504 var integer num_rx := 0;
3505 var integer num_del := 0;
3506 var charstring res_str;
3507 var float rx_ratio;
3508
Harald Welte10474062019-05-30 16:48:17 +02003509 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003510 f_init_l1ctl();
3511 f_l1_tune(L1CTL);
3512
3513 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003514 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003515 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3516 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003517 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003518 num_tx := num_tx+1;
3519 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003520 }
3521 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003522 T.start;
3523 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003524 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003525 num_del := num_del+1;
3526 repeat;
3527 }
3528 [] RSL_CCHAN.receive {
3529 repeat;
3530 }
3531 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003532 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3533 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3534 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003535 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003536 } else {
3537 num_rx := num_rx+1;
3538 }
3539 repeat;
3540 }
3541 [] L1CTL.receive { repeat; }
3542 [] T.timeout { }
3543 }
3544 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3545 log("AGCH test: " & res_str);
3546 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003548 }
3549 rx_ratio := int2float(num_rx) / int2float(num_tx);
3550 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003551 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 +02003552 } else {
3553 setverdict(pass);
3554 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003556}
3557
Harald Weltee8d750e2018-06-10 21:41:35 +02003558/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3559testcase TC_imm_ass_1000_20ms() runs on test_CT {
3560 f_TC_imm_ass(1000, 0.02, 0.25);
3561}
3562
3563/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3564testcase TC_imm_ass_200_0ms() runs on test_CT {
3565 f_TC_imm_ass(200, 0.0, 0.05);
3566}
3567
3568/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3569testcase TC_imm_ass_200_76ms() runs on test_CT {
3570 f_TC_imm_ass(150, 0.076, 1.00);
3571}
3572
3573
3574
Harald Welte48494ca2018-02-25 16:59:50 +01003575/***********************************************************************
3576 * BCCH
3577 ***********************************************************************/
3578
3579/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003580private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003581 GsmFrameNumber frame_number,
3582 SystemInformation si
3583}
3584
3585/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003586private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003587
3588/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003589private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003590
3591/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003592private function f_si_vecslot_contains(SystemInformationVector arr,
3593 RrMessageType key,
3594 boolean bcch_ext := false)
3595return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003596 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3597 var integer fn_mod51 := arr[i].frame_number mod 51;
3598 if (not bcch_ext and fn_mod51 == 2 or
3599 bcch_ext and fn_mod51 == 6) {
3600 if (arr[i].si.header.message_type == key) {
3601 return true;
3602 }
3603 }
3604 }
3605 return false;
3606}
3607
3608/* 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 +07003609private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3610 integer tc, RrMessageType key,
3611 boolean ext_bcch := false)
3612{
Harald Welte48494ca2018-02-25 16:59:50 +01003613 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003615 }
3616}
3617
3618/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003619private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3620 RrMessageType key)
3621return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003622 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3623 if (f_si_vecslot_contains(arr[tc], key) or
3624 f_si_vecslot_contains(arr[tc], key, true)) {
3625 return true;
3626 }
3627 }
3628 return false;
3629}
3630
3631/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003632private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3633 RrMessageType key,
3634 boolean bcch_ext := false,
3635 integer n := 1, integer m := 4)
3636return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003637 var integer count := 0;
3638 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003640 }
3641 for (var integer i:= 0; i < m; i := i + 1) {
3642 var integer fn_mod51 := arr[i].frame_number mod 51;
3643 if (not bcch_ext and fn_mod51 == 2 or
3644 bcch_ext and fn_mod51 == 6) {
3645 if (arr[i].si.header.message_type == key) {
3646 count := count + 1;
3647 }
3648 }
3649 }
3650 if (count >= n) {
3651 return true;
3652 } else {
3653 return false;
3654 }
3655}
3656
3657/* 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 +07003658private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3659 integer tc, RrMessageType key,
3660 boolean ext_bcch := false,
3661 integer n, integer m)
3662{
Harald Welte48494ca2018-02-25 16:59:50 +01003663 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003665 }
3666}
3667
3668/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003669private function f_si_vecslot_contains_only(SystemInformationVector arr,
3670 RrMessageType key,
3671 boolean bcch_ext := false)
3672return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003673 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3674 var integer fn_mod51 := arr[i].frame_number mod 51;
3675 if (not bcch_ext and fn_mod51 == 2 or
3676 bcch_ext and fn_mod51 == 6) {
3677 if (arr[i].si.header.message_type != key) {
3678 return false;
3679 }
3680 }
3681 }
3682 return true;
3683}
3684
3685/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003686private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3687 integer tc, RrMessageType key,
3688 boolean ext_bcch := false)
3689{
Harald Welte48494ca2018-02-25 16:59:50 +01003690 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003692 }
3693}
3694
3695/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003696private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003697 boolean bcch_extended,
3698 boolean si1_present,
3699 boolean si2bis_present,
3700 boolean si2ter_present,
3701 boolean si2quater_present,
3702 boolean si7_present,
3703 boolean si8_present,
3704 boolean si9_present,
3705 boolean si13_present,
3706 boolean si13alt_present,
3707 boolean si15_present,
3708 boolean si16_present,
3709 boolean si17_present,
3710 boolean si2n_present,
3711 boolean si21_present,
3712 boolean si22_present
3713}
3714
3715/* 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 +07003716private function f_validate_si_scheduling(SystemInformationConfig cfg,
3717 SystemInformationVectorPerTc si_per_tc)
3718{
Harald Welte48494ca2018-02-25 16:59:50 +01003719 var integer i;
3720 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3721 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003723 }
3724 }
3725 if (cfg.si1_present) {
3726 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3727 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3728 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3729 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3730 /* make sure *ALL* contain SI1 */
3731 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3732 }
3733 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3734 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3735 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3736 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3737 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3738 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3739
3740 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3741 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3742 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3743 * consecutive occurrences of TC = 4. */
3744 if (cfg.si2bis_present and not cfg.si2ter_present) {
3745 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3746 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3747 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3748 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3749 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3750 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3751 }
3752
3753 if (cfg.si7_present or cfg.si8_present) {
3754 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3755 * if System Information type 4 does not contain all information needed for cell
3756 * selection and reselection. */
3757 if (not cfg.bcch_extended) {
3758 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3759 }
3760 if (cfg.si7_present) {
3761 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3762 }
3763 if (cfg.si8_present) {
3764 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3765 }
3766 }
3767
3768 if (cfg.si2quater_present) {
3769 /* iii) System information type 2 quater is sent if needed, as determined by the system
3770 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3771 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3772 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3773 * within any of 4 consecutive occurrences of TC = 5. */
3774 if (not (cfg.bcch_extended)) {
3775 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3776 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3777 } else {
3778 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3779 }
3780 } else {
3781 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3782 }
3783 }
3784 if (cfg.si9_present) {
3785 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3786 * in system information type 3 as defined in 3GPP TS 44.018. */
3787 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3788 }
3789 if (cfg.si13_present) {
3790 /* vii) System Information type 13 is only related to the GPRS service. System Information
3791 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3792 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3793 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3794 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3795 * within any of 4 consecutive occurrences of TC=4. */
3796 if (not cfg.bcch_extended) {
3797 log("not-bccch-extended");
3798 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3799 } else {
3800 log("bccch-extended");
3801 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3802 }
3803 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003805 }
3806 }
3807 if (cfg.si16_present or cfg.si17_present) {
3808 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3809 * should not be sent in a cell where network sharing is used (see rule xv). */
3810 if (cfg.si22_present) {
3811 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3812 }
3813 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003815 }
3816 if (not cfg.bcch_extended) {
3817 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3818 }
3819 if (cfg.si16_present) {
3820 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3821 }
3822 if (cfg.si17_present) {
3823 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3824 }
3825 }
3826
3827 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3828 * broadcast information. The frequency with which they are sent is determined by the
3829 * system operator. System Information type 9 identifies the scheduling of System
3830 * Information type 18 and 20 messages. */
3831
3832 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3833 * Information Type 19 is present, then its scheduling shall be indicated in System
3834 * Information Type 9. */
3835
3836 if (cfg.si15_present) {
3837 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3838 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3839 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3840 * 4 consecutive occurrences of TC = 1. */
3841 if (not cfg.bcch_extended) {
3842 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3843 } else {
3844 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3845 }
3846 }
3847 if (cfg.si13alt_present) {
3848 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3849 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3850 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3851 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3852 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3853 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3854 * of TC = 4. */
3855 if (cfg.si13_present) {
3856 testcase.stop("Error: Cannot have SI13alt and SI13");
3857 }
3858 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003860 }
3861 if (not cfg.bcch_extended) {
3862 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3863 } else {
3864 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3865 }
3866 }
3867 if (cfg.si2n_present) {
3868 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3869 * as determined by the system operator. In the case that the message is sent on the
3870 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3871 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3872 * consecutive occurrences of TC = 4. */
3873 if (not cfg.bcch_extended) {
3874 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3875 } else {
3876 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3877 }
3878 }
3879 if (cfg.si21_present) {
3880 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3881 * determined by the system operator. If Extended Access Barring is in use in the cell
3882 * then this message is sent at least once within any of 4 consecutive occurrences of
3883 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3884 * cell then this message shall only be sent on BCCH Ext. */
3885 if (not cfg.bcch_extended) {
3886 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3887 } else {
3888 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3889 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003891 }
3892 }
3893 }
3894 if (cfg.si22_present) {
3895 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3896 * should not be sent in a cell where SoLSA is used (see rule viii). System
3897 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3898 * =2 and TC=6. */
3899 if (cfg.si16_present or cfg.si17_present) {
3900 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3901 }
3902 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3903 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003905 }
3906 if (not cfg.bcch_extended) {
3907 testcase.stop("Error: SI22 requires BCCH Extd!");
3908 } else {
3909 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3910 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3911 }
3912 }
3913}
3914
3915/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003916private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3917return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003918 timer T := duration;
3919 var SystemInformationVectorPerTc si_per_tc;
3920 var L1ctlDlMessage l1_dl;
3921
3922 /* initialize all per-TC vectors empty */
3923 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3924 si_per_tc[i] := {};
3925 }
3926
3927 /* flush all previous L1 queued msgs */
3928 pt.clear;
3929
3930 T.start;
3931 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003932 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003933 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3934 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3935 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003936 repeat;
3937 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003938
Harald Welte48494ca2018-02-25 16:59:50 +01003939 var integer tc := f_gsm_compute_tc(sig.frame_number);
3940 log("SI received at TC=", tc, ": ", sig.si);
3941 /* append to the per-TC bucket */
3942 si_per_tc[tc] := si_per_tc[tc] & { sig };
3943 repeat;
3944 }
3945 [] pt.receive { repeat; }
3946 [] T.timeout { }
3947 }
3948
3949 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3950 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
3951 }
3952 log("si_per_tc=", si_per_tc);
3953 return si_per_tc;
3954}
3955
3956/* helper function: Set given SI via RSL + validate scheduling.
3957 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003958private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01003959 var SystemInformationVectorPerTc si_per_tc;
3960 f_init_l1ctl();
3961 f_l1_tune(L1CTL);
3962
3963 /* Sample + Validate Scheduling */
3964 si_per_tc := f_l1_sample_si(L1CTL);
3965 f_validate_si_scheduling(si_cfg, si_per_tc);
3966
3967 setverdict(pass);
3968}
3969
3970testcase TC_si_sched_default() runs on test_CT {
3971 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01003972 /* 2+3+4 are mandatory and set in f_init() */
3973 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01003975}
3976
3977testcase TC_si_sched_1() runs on test_CT {
3978 f_init();
3979 si_cfg.si1_present := true;
3980 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003981 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003983}
3984
3985testcase TC_si_sched_2bis() runs on test_CT {
3986 f_init();
3987 si_cfg.si2bis_present := true;
3988 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3989 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003991}
3992
3993testcase TC_si_sched_2ter() runs on test_CT {
3994 f_init();
3995 si_cfg.si2ter_present := true;
3996 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3997 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003999}
4000
4001testcase TC_si_sched_2ter_2bis() runs on test_CT {
4002 f_init();
4003 si_cfg.si2bis_present := true;
4004 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4005 si_cfg.si2ter_present := true;
4006 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4007 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004009}
4010
4011testcase TC_si_sched_2quater() runs on test_CT {
4012 f_init();
4013 si_cfg.si2quater_present := true;
4014 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4015 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004017}
4018
4019testcase TC_si_sched_13() runs on test_CT {
4020 f_init();
4021 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004022 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004023 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004025}
4026
4027testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4028 f_init();
4029 si_cfg.si2bis_present := true;
4030 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4031 si_cfg.si2ter_present := true;
4032 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4033 si_cfg.si2quater_present := true;
4034 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4035 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004036 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004037 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004039}
4040
4041
Harald Welte68e495b2018-02-25 00:05:57 +01004042testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004043 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004044 /* FIXME: enable / disable individual BCCH info */
4045 //ts_RSL_BCCH_INFO(si_type, info);
4046 /* expect no ERROR REPORT after either of them *
4047 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004049}
4050
Harald Welte93640c62018-02-25 16:59:33 +01004051/***********************************************************************
4052 * Low-Level Protocol Errors / ERROR REPORT
4053 ***********************************************************************/
4054
Harald Welte01d982c2018-02-25 01:31:40 +01004055private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4056 timer T := 5.0;
4057 T.start;
4058 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004059 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004060 setverdict(pass);
4061 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004062 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004064 }
4065 [] RSL_CCHAN.receive {
4066 repeat;
4067 }
4068 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004070 }
4071 }
4072}
4073
4074/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4075testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004076 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004077 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4078 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004079 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004080
4081 f_exp_err_rep(RSL_ERR_PROTO);
4082}
4083
4084/* Provoke a mandatory IE error and match on ERROR REPORT */
4085testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004086 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004087
4088 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4089 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004090 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004091
4092 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4093}
4094
4095/* Provoke an IE content error and match on ERROR REPORT */
4096testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004097 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004098 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4099 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004100 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004101
4102 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4103}
4104
Harald Welteee25aae2019-05-19 14:32:37 +02004105/* attempt to activate channel with wrong RSL Message Discriminator IE */
4106function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4107 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4108 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4109 RSL.send(rsl);
4110 f_rslem_unregister(0, g_chan_nr);
4111}
4112testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4113 var ConnHdlr vc_conn;
4114 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4115
Harald Welte10474062019-05-30 16:48:17 +02004116 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004117
4118 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4119 vc_conn.done;
4120 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4121
4122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4123}
4124
4125/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004126private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004127 var template (value) RSL_Message rsl_tx;
4128 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4129 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4130 RSL.send(rsl_tx);
4131 f_rslem_unregister(0, g_chan_nr);
4132}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004133private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004134 var template (value) RSL_Message rsl_tx;
4135 /* we first have to activate the dedicated channel */
4136 f_rsl_chan_act(g_pars.chan_mode);
4137 /* ... to then send an invalid RLL message */
4138 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4139 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4140 RSL.send(rsl_tx);
4141 f_rslem_unregister(0, g_chan_nr);
4142}
4143testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4144 var ConnHdlr vc_conn;
4145 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4146 var template (value) RSL_Message rsl_tx;
4147
Harald Welte10474062019-05-30 16:48:17 +02004148 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004149
4150 /* Common Channel with wrong message type */
4151 RSL_CCHAN.clear;
4152 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4153 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004154 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004155 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4156
4157 /* TRX Management */
4158 RSL_CCHAN.clear;
4159 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4160 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004161 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004162 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4163
4164 /* Dedicated Channel */
4165 RSL_CCHAN.clear;
4166 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4167 vc_conn.done;
4168 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4169
4170 /* RLL */
4171 RSL_CCHAN.clear;
4172 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4173 vc_conn.done;
4174 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4175}
4176
4177/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004178private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004179 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4180 f_rslem_unregister(0, g_chan_nr);
4181}
4182testcase TC_err_rep_wrong_sequence() runs on test_CT {
4183 var ConnHdlr vc_conn;
4184 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4185
Harald Welte10474062019-05-30 16:48:17 +02004186 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004187
4188 RSL_CCHAN.clear;
4189 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4190 vc_conn.done;
4191 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4192}
4193
Harald Welte93640c62018-02-25 16:59:33 +01004194/***********************************************************************
4195 * IPA CRCX/MDCX/DLCS media stream handling
4196 ***********************************************************************/
4197
Harald Weltea871a382018-02-25 02:03:14 +01004198/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004199private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004200 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4201 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004202}
4203testcase TC_ipa_dlcx_not_active() runs on test_CT {
4204 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004205 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004206 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4207 vc_conn.done;
4208}
Harald Welte68e495b2018-02-25 00:05:57 +01004209
Harald Weltea3f1df92018-02-25 12:49:55 +01004210/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004211private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004212 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4213 "IPA CRCX ACK");
4214 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4215 "IPA CRCX NACK");
4216}
4217testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4218 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004219 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004220 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4221 vc_conn.done;
4222}
4223
4224/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004225private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004226 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4227 "IPA CRCX ACK");
4228 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4229 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4230 var uint7_t rtp_pt2 := f_rnd_int(127);
4231 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4232 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4233 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4234 "IPA MDCX ACK");
4235 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4236 "IPA DLCX ACK");
4237}
4238testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4239 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004240 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004241 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4242 vc_conn.done;
4243}
4244
Harald Welte3ae11da2018-02-25 13:36:06 +01004245/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004246private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004247 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4248 "IPA CRCX ACK");
4249 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4250 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4251 var uint7_t rtp_pt2 := f_rnd_int(127);
4252 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4253 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4254 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4255 "IPA MDCX ACK");
4256 /* Second MDCX */
4257 remote_ip := f_rnd_int(c_UINT32_MAX);
4258 remote_port := f_rnd_int(c_UINT16_MAX);
4259 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4260 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4261 "IPA MDCX ACK");
4262 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4263 "IPA DLCX ACK");
4264}
4265testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4266 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004267 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004268 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4269 vc_conn.done;
4270}
4271
Harald Welte9912eb52018-02-25 13:30:15 +01004272/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004273private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004274 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4275 "IPA CRCX NACK");
4276}
4277testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4278 var ConnHdlrPars pars;
4279 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004280 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004281
4282 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4283 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4284 vc_conn.done;
4285
4286 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4287 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4288 vc_conn.done;
4289}
4290
Harald Weltea3f1df92018-02-25 12:49:55 +01004291
Harald Welte883340c2018-02-28 18:59:29 +01004292/***********************************************************************
4293 * PCU Socket related tests
4294 ***********************************************************************/
4295
Harald Welte07bd2d22019-05-25 11:03:30 +02004296/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004297friend 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 +01004298runs on test_CT {
4299 timer T := 3.0;
4300
4301 /* we don't expect any RTS.req before PDCH are active */
4302 T.start;
4303 alt {
4304 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004306 }
4307 [] PCU.receive { repeat; }
4308 [] T.timeout { }
4309 }
4310
4311 /* Send PDCH activate request for known PDCH timeslot */
4312 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4313
4314 /* we now expect RTS.req for this timeslot (only) */
4315 T.start;
4316 alt {
4317 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4318 setverdict(pass);
4319 }
4320 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4321 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004323 }
4324 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004326 }
4327 [] PCU.receive { repeat; }
4328 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004330 }
4331 [not exp_success] T.timeout {
4332 setverdict(pass);
4333 }
4334 }
4335}
4336
Harald Welte07bd2d22019-05-25 11:03:30 +02004337/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004338friend 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 +01004339runs on test_CT {
4340 timer T := 3.0;
4341
4342 /* Send PDCH activate request for known PDCH timeslot */
4343 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4344
4345 PCU.clear;
4346 /* we now expect no RTS.req for this timeslot */
4347 T.start;
4348 alt {
4349 [] 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 +02004350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004351 }
4352 [] PCU.receive { repeat; }
4353 [] T.timeout {
4354 setverdict(pass);
4355 }
4356 }
4357}
4358
Harald Weltead033dc2019-05-25 17:28:16 +02004359friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004360 f_init();
4361 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4362}
4363
Harald Welte883340c2018-02-28 18:59:29 +01004364/* PDCH activation via PCU socket; check for presence of RTS.req */
4365testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004366 f_init_pcu_test();
4367
Harald Welte883340c2018-02-28 18:59:29 +01004368 f_TC_pcu_act_req(0, 0, 7, true);
4369}
4370
4371/* PDCH activation via PCU socket on non-PDCU timeslot */
4372testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004373 f_init_pcu_test();
4374
Harald Welte883340c2018-02-28 18:59:29 +01004375 f_TC_pcu_act_req(0, 0, 1, false);
4376}
4377
4378/* PDCH activation via PCU socket on wrong BTS */
4379testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004380 f_init_pcu_test();
4381
Harald Welte883340c2018-02-28 18:59:29 +01004382 f_TC_pcu_act_req(23, 0, 7, false);
4383}
4384
4385/* PDCH activation via PCU socket on wrong TRX */
4386testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004387 f_init_pcu_test();
4388
Harald Welte883340c2018-02-28 18:59:29 +01004389 f_TC_pcu_act_req(0, 23, 7, false);
4390}
4391
4392/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4393testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004394 f_init_pcu_test();
4395
Harald Welte883340c2018-02-28 18:59:29 +01004396 /* Activate PDCH */
4397 f_TC_pcu_act_req(0, 0, 7, true);
4398 f_sleep(1.0);
4399 /* and De-Activate again */
4400 f_TC_pcu_deact_req(0, 0, 7);
4401}
4402
4403/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4404testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004405 f_init_pcu_test();
4406
Harald Welte883340c2018-02-28 18:59:29 +01004407 f_TC_pcu_deact_req(0, 0, 1);
4408}
4409
4410/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4411testcase TC_pcu_ver_si13() runs on test_CT {
4412 const octetstring si13 := '00010203040506070909'O;
4413 var PCUIF_send_data sd;
4414 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004415 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004416
4417 /* Set SI13 via RSL */
4418 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004419
Harald Welte883340c2018-02-28 18:59:29 +01004420 T.start;
4421 alt {
4422 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4423 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4424 setverdict(pass);
4425 } else {
4426 repeat;
4427 }
4428 }
4429 [] PCU.receive { repeat; }
4430 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004432 }
4433 }
4434}
4435
4436private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4437
4438/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004439friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004440 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4441runs on test_CT
4442{
4443 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4444 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4445}
4446
4447/* 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 +02004448friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4449 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004450runs on test_CT
4451{
4452 var PCUIF_send_data sd;
4453
4454 timer T := 3.0;
4455 T.start;
4456 alt {
4457 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4458 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4459 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4460 sd.data.u.rts_req.fn, sapi, data);
4461 }
4462 [] PCU.receive { repeat; }
4463 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004465 }
4466 }
4467}
4468
4469/* Send DATA.req on invalid BTS */
4470testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004471 var TfiUsfArr tua := f_TfiUsfArrInit();
4472 var octetstring data := '0000'O & f_rnd_octstring(21);
4473
4474 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004475
Harald Welte883340c2018-02-28 18:59:29 +01004476 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004477 f_TfiUsfArrSet(tua, 7, 0);
4478 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4479 f_sleep(1.0);
4480
4481 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004482}
4483
4484/* Send DATA.req on invalid TRX */
4485testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004486 var TfiUsfArr tua := f_TfiUsfArrInit();
4487 var octetstring data := '0000'O & f_rnd_octstring(21);
4488
4489 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004490
Harald Welte883340c2018-02-28 18:59:29 +01004491 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004492 f_TfiUsfArrSet(tua, 7, 0);
4493 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4494 f_sleep(1.0);
4495
4496 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004497}
4498
4499/* Send DATA.req on invalid timeslot */
4500testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004501 var TfiUsfArr tua := f_TfiUsfArrInit();
4502 var octetstring data := '0000'O & f_rnd_octstring(21);
4503
4504 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004505
Harald Welte883340c2018-02-28 18:59:29 +01004506 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004507 f_TfiUsfArrSet(tua, 7, 0);
4508 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4509 f_sleep(1.0);
4510
4511 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004512}
4513
4514/* Send DATA.req on timeslot that hasn't been activated */
4515testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004516 var TfiUsfArr tua := f_TfiUsfArrInit();
4517 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004518
Harald Welte7162a612019-05-26 12:56:09 +02004519 f_virtphy_common();
4520
4521 f_TfiUsfArrSet(tua, 7, 0);
4522 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4523 f_sleep(1.0);
4524
4525 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004526}
4527
Harald Weltead033dc2019-05-25 17:28:16 +02004528private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004529 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4530 boolean wait_rts := true)
4531runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004532 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004533 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004534
4535 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004536 if (wait_rts) {
4537 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4538 } else {
4539 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4540 }
Harald Weltead033dc2019-05-25 17:28:16 +02004541
4542 T.start;
4543 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004544 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004545 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4546 setverdict(pass);
4547 }
Harald Welte7162a612019-05-26 12:56:09 +02004548 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4549 setverdict(fail, "Received unexpected ", rx_dl);
4550 }
Harald Weltead033dc2019-05-25 17:28:16 +02004551 [] L1CTL.receive {
4552 repeat;
4553 }
Harald Welte7162a612019-05-26 12:56:09 +02004554 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004555 setverdict(fail, "Timeout waiting for ", data);
4556 }
Harald Welte7162a612019-05-26 12:56:09 +02004557 [not expect_data] T.timeout {
4558 setverdict(pass);
4559 }
Harald Weltead033dc2019-05-25 17:28:16 +02004560 }
4561}
4562
4563private function f_disable_dynamic_ts() runs on test_CT
4564{
4565 f_init_vty_bsc();
4566 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4567 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4568 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4569 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004570 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004571}
4572
4573private function f_virtphy_common() runs on test_CT {
4574 f_disable_dynamic_ts();
4575 f_init_l1ctl();
4576 f_l1_tune(L1CTL);
4577}
4578
4579testcase TC_pcu_data_req_pdtch() runs on test_CT {
4580 var TfiUsfArr tua := f_TfiUsfArrInit();
4581 var octetstring data := '0000'O & f_rnd_octstring(21);
4582
4583 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004584
Harald Welte883340c2018-02-28 18:59:29 +01004585 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004586 f_TfiUsfArrSet(tua, 7, 0);
4587 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4588 f_sleep(1.0);
4589
4590 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004591}
4592
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004593/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004594testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004595 var TfiUsfArr tua := f_TfiUsfArrInit();
4596 var octetstring data := '0000'O & f_rnd_octstring(21);
4597
4598 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004599
Harald Welte883340c2018-02-28 18:59:29 +01004600 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004601 f_TfiUsfArrSet(tua, 7, 0);
4602 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4603 f_sleep(1.0);
4604
4605 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004606}
4607
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004608private function f_TC_pcu_ptcch_ul(uint16_t ra)
4609runs on test_CT {
4610 var template PCUIF_Message pcu_rach_ind;
4611 var PCUIF_send_data sd;
4612 var GsmFrameNumber fn;
4613 timer T;
4614
4615 /* Send an Access Burst on PTCCH/U over the Um-interface */
4616 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4617 chan_nr := ts_RslChanNr_PDCH(7),
4618 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4619
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004620 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4621 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004622
4623 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4624 T.start(52.0 * 4.615 / 1000.0);
4625 alt {
4626 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4627 log("Rx an Access Burst on the PCU interface: ", sd.data);
4628 setverdict(pass);
4629 T.stop;
4630 }
4631 [] PCU.receive { repeat; }
4632 [] T.timeout {
4633 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4634 /* Keep going, that's not the end of the world */
4635 }
4636 }
4637}
4638
4639testcase TC_pcu_ptcch() runs on test_CT {
4640 var L1ctlDlMessage dl;
4641 var octetstring data;
4642 timer T;
4643
4644 f_init_pcu_test();
4645 f_init_l1ctl();
4646 f_l1_tune(L1CTL);
4647
4648 /* Activate PDCH channel on TS7 */
4649 f_TC_pcu_act_req(0, 0, 7, true);
4650
4651 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004652 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004653
4654 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4655 for (var integer i := 0; i < 16; i := i + 1) {
4656 log("Sending an Access Burst towards the L1CTL interface");
4657 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4658 }
4659
4660 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4661 data := f_rnd_octstring(23);
4662
4663 /* Verify PTCCH/D: send a random data block, make sure it's received */
4664 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4665 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4666
4667 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4668 * let's give it more time in case if we miss the beginning. */
4669 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4670 alt {
4671 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4672 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4673 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4674 frame := data)) -> value dl {
4675 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4676 setverdict(pass);
4677 T.stop;
4678 }
4679 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4680 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4681 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4682 l2_data := data)) -> value dl {
4683 log("Rx PTCCH/D data block on L1CTL: ", dl);
4684 setverdict(pass);
4685 T.stop;
4686 }
4687 [] L1CTL.receive { repeat; }
4688 [] T.timeout {
4689 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4690 }
4691 }
4692}
4693
Harald Welte883340c2018-02-28 18:59:29 +01004694/* Send AGCH from PCU; check it appears on Um side */
4695testcase TC_pcu_data_req_agch() runs on test_CT {
4696 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004697 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004698 f_init_l1ctl();
4699 f_l1_tune(L1CTL);
4700
4701 f_TC_pcu_act_req(0, 0, 7, true);
4702 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4703
4704 T.start;
4705 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004706 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004707 setverdict(pass);
4708 }
4709 [] L1CTL.receive { repeat; }
4710 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004712 }
4713 }
4714}
4715
Harald Welte928622b2019-05-26 13:22:59 +02004716/* Send AGCH from PCU; check it appears on Um side */
4717testcase TC_pcu_data_req_pch() runs on test_CT {
4718 timer T := 3.0;
4719 f_init_pcu_test();
4720 f_init_l1ctl();
4721 f_l1_tune(L1CTL);
4722
4723 f_TC_pcu_act_req(0, 0, 7, true);
4724 /* three characters prefix: last 3 digits of IMSI as ASCII */
4725 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4726
4727 T.start;
4728 alt {
4729 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4730 setverdict(pass);
4731 }
4732 [] L1CTL.receive { repeat; }
4733 [] T.timeout {
4734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4735 }
4736 }
4737}
4738
Harald Welte883340c2018-02-28 18:59:29 +01004739/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4740testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4741 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004742 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004743 f_init_l1ctl();
4744 f_l1_tune(L1CTL);
4745
4746 /* append 3 last imsi digits so BTS can compute pagng group */
4747 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4748
4749 timer T := 0.5;
4750 T.start;
4751 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004752 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004753 /* TODO: verify paging group */
4754 setverdict(pass);
4755 }
4756 [] L1CTL.receive { repeat; }
4757 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004759 }
4760 }
4761}
4762
4763/* Send RACH from Um side, expect it to show up on PCU socket */
4764testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004765 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004766 f_init_l1ctl();
4767 f_l1_tune(L1CTL);
4768
4769 var GsmFrameNumber fn_last := 0;
4770 for (var integer i := 0; i < 1000; i := i+1) {
4771 var OCT1 ra := f_rnd_ra_ps();
4772 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4773 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004775 }
4776 fn_last := fn;
4777
4778 timer T := 2.0;
4779 T.start;
4780 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004781 [] 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 +01004782 T.stop;
4783 }
4784 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004786 }
4787 [] PCU.receive { repeat; }
4788 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004790 }
4791 }
4792 }
4793 setverdict(pass);
4794}
4795
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004796/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4797 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4798testcase TC_pcu_ext_rach_content() runs on test_CT {
4799 var template PCUIF_Message pcu_rach_ind;
4800 var GsmFrameNumber fn_last := 0;
4801 var L1ctlRachSynchSeq synch_seq;
4802 var PCUIF_BurstType pcu_bt;
4803 var GsmFrameNumber fn;
4804 var BIT11 ra11;
4805
4806 f_init_pcu_test();
4807 f_init_l1ctl();
4808 f_l1_tune(L1CTL);
4809
4810 for (var integer i := 0; i < 1000; i := i+1) {
4811 /* We need to test both TS1 & TS2 */
4812 if (i rem 2 == 0) {
4813 synch_seq := RACH_SYNCH_SEQ_TS1;
4814 pcu_bt := BURST_TYPE_1;
4815 } else {
4816 synch_seq := RACH_SYNCH_SEQ_TS2;
4817 pcu_bt := BURST_TYPE_2;
4818 }
4819
4820 ra11 := f_rnd_ra11_ps();
4821 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4822 if (fn == fn_last) {
4823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4824 "Two RACH in same FN?!?");
4825 }
4826 fn_last := fn;
4827
4828 /* Compose the expected message */
4829 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004830 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004831 ra := bit2int(ra11),
4832 is_11bit := 1,
4833 burst_type := pcu_bt,
4834 fn := fn);
4835
4836 timer T := 2.0;
4837 T.start;
4838 alt {
4839 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4840 T.stop;
4841 }
4842 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4844 }
4845 [] PCU.receive { repeat; }
4846 [] T.timeout {
4847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4848 }
4849 }
4850 }
4851 setverdict(pass);
4852}
4853
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004854private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4855runs on test_CT {
4856 var template PCUIF_send_data sdt;
4857 var PCUIF_send_data sd;
4858 var int16_t lqual_cb;
4859 timer T := 1.0;
4860
4861 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4862 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4863
4864 /* Send a random PDTCH frame over Um */
4865 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4866 '0000'O & f_rnd_octstring(21)));
4867
4868 T.start;
4869 alt {
4870 /* If expected link quality is above the threshold */
4871 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4872 lqual_cb := sd.data.u.data_ind.lqual_cb;
4873 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4874
4875 /* Make sure the actual link quality matches the expected value */
4876 if (not match(lqual_cb, lqual_cb_exp)) {
4877 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4878 "expected value ", lqual_cb_exp));
4879 } else {
4880 setverdict(pass);
4881 }
4882 }
4883 /* If expected link quality is below the threshold */
4884 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4886 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4887 }
4888 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4889 [] PCU.receive { repeat; }
4890 [lqual_cb_exp < thresh] T.timeout {
4891 log("Rx nothing, as expected");
4892 setverdict(pass);
4893 }
4894 [lqual_cb_exp >= thresh] T.timeout {
4895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4896 "Timeout waiting for PCUIF_DATA.ind");
4897 }
4898 }
4899}
4900
4901/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4902testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4903 f_init_pcu_test();
4904 PCU.clear;
4905
4906 f_init_l1ctl();
4907 f_l1_tune(L1CTL);
4908
4909 /* Activate a PDCH channel on TS7 */
4910 f_TC_pcu_act_req(0, 0, 7, true);
4911
4912 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy5afe8852020-05-27 14:40:51 +07004913 L1CTL.send(ts_L1CTL_DM_EST_REQ_H0(ts_RslChanNr_PDCH(7), 7, mp_trx0_arfcn));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004914
4915 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4916 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4917 var TrxcMessage ret;
4918
4919 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4920 valueof(ts_TRXC_FAKE_CI(i)));
4921
4922 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4923 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4924 }
4925}
4926
Harald Welte883340c2018-02-28 18:59:29 +01004927/* Send PAGING via RSL, expect it to shw up on PCU socket */
4928testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004929 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004930
4931 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004932 var MobileIdentityLV mi_lv;
4933 var octetstring mi_lv_enc;
4934 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004935 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004936
Harald Welte883340c2018-02-28 18:59:29 +01004937 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004938 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004939 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004940 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004941 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004942
4943 /* Fancy encoding for PCUIF */
4944 mi_lv := valueof(ts_MI_LV(mi));
4945 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
4946 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01004947
4948 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004949 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01004950 T.start;
4951 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004952 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01004953 }
4954 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004956 }
4957 [] PCU.receive { repeat; }
4958 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01004960 }
4961 }
4962 }
4963 setverdict(pass);
4964}
4965
Harald Welted66c9b82019-05-25 09:03:15 +02004966/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
4967testcase TC_pcu_time_ind() runs on test_CT {
4968 var PCUIF_send_data pcu_sd;
4969 var integer num_time_ind := 0;
4970 var integer first_fn, last_fn;
4971 var float test_duration := 5.0;
4972 timer T;
4973
4974 f_init_pcu_test();
4975 f_TC_pcu_act_req(0, 0, 7, true);
4976
4977 PCU.clear;
4978 T.start(test_duration);
4979 alt {
4980 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
4981 num_time_ind := num_time_ind + 1;
4982 if (not isbound(first_fn)) {
4983 first_fn := pcu_sd.data.u.time_ind.fn;
4984 }
4985 last_fn := pcu_sd.data.u.time_ind.fn;
4986 repeat;
4987 }
4988 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
4989 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
4990 repeat;
4991 }
4992 [] PCU.receive {
4993 repeat;
4994 }
4995 [] T.timeout {}
4996 }
4997 var integer fn_expired := last_fn - first_fn;
4998 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
4999
5000 /* verify the number of frames expired matches our expectation */
5001 const float c_GSM_FN_DURATION_MS := 4.61538;
5002 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005003 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005004 if (not match(fn_expired, t_fn_expected)) {
5005 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5006 }
5007
5008 /* There are three TIME.ind in every fn MOD 13 */
5009 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5010 /* Add some tolerance */
5011 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5012 if (not match(num_time_ind, t_time_ind_exp)) {
5013 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5014 }
5015
5016 setverdict(pass);
5017}
5018
Harald Welte4832c862019-05-25 14:57:18 +02005019/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5020testcase TC_pcu_rts_req() runs on test_CT {
5021 var PCUIF_send_data pcu_sd;
5022 var integer first_fn, last_fn;
5023 var integer num_rts_pdtch := 0;
5024 var integer num_rts_ptcch := 0;
5025 var float test_duration := 5.0;
5026 timer T;
5027
5028 f_init_pcu_test();
5029 f_TC_pcu_act_req(0, 0, 7, true);
5030
5031 PCU.clear;
5032 T.start(test_duration);
5033 alt {
5034 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5035 -> value pcu_sd {
5036 num_rts_pdtch := num_rts_pdtch + 1;
5037 if (not isbound(first_fn)) {
5038 first_fn := pcu_sd.data.u.rts_req.fn;
5039 }
5040 last_fn := pcu_sd.data.u.rts_req.fn;
5041 repeat;
5042 }
5043 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5044 -> value pcu_sd {
5045 num_rts_ptcch := num_rts_ptcch + 1;
5046 if (not isbound(first_fn)) {
5047 first_fn := pcu_sd.data.u.rts_req.fn;
5048 }
5049 last_fn := pcu_sd.data.u.rts_req.fn;
5050 repeat;
5051 }
5052 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5053 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5054 repeat;
5055 }
5056 [] PCU.receive {
5057 repeat;
5058 }
5059 [] T.timeout {}
5060 }
5061 var integer fn_expired := last_fn - first_fn;
5062 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5063 ", num_rts_ptcch=", num_rts_ptcch);
5064
5065 /* verify the number of frames expired matches our expectation */
5066 const float c_GSM_FN_DURATION_MS := 4.61538;
5067 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005068 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005069 if (not match(fn_expired, t_fn_expected)) {
5070 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5071 }
5072
5073 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5074 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5075 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5076 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5077 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5078 t_ptcch_exp);
5079 }
5080
5081 /* We have 12 PDTCH blocks every 52-multiframe */
5082 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5083 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5084 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5085 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5086 t_pdtch_exp);
5087 }
5088
5089 setverdict(pass);
5090}
5091
Harald Welte07bd2d22019-05-25 11:03:30 +02005092/* test for generating Abis side OML ALERT from the PCU */
5093testcase TC_pcu_oml_alert() runs on test_CT {
5094 var PCUIF_send_data pcu_sd;
5095 var integer num_time_ind := 0;
5096 var integer first_fn, last_fn;
5097 var float test_duration := 5.0;
5098 timer T;
5099
5100 f_init_pcu_test();
5101 f_TC_pcu_act_req(0, 0, 7, true);
5102
5103 /* re-connect CTRL port from BTS to BSC */
5104 f_ipa_ctrl_stop();
5105 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5106
5107 /* Send that OML Alert */
5108 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5109
5110 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5111 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5112 setverdict(pass);
5113}
5114
Harald Welteeaa9a862019-05-26 23:01:08 +02005115/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5116private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5117 var PCUIF_Message first_info;
5118 var integer pcu_conn_id := -1;
5119 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5120 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5121 var OCT4 tlli := '01020304'O;
5122 var OCT1 cause := '23'O;
5123 timer T := 5.0;
5124
5125 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5126
5127 f_l1_tune(L1CTL);
5128 RSL.clear;
5129
5130 f_est_dchan();
5131 L1CTL.clear;
5132
5133 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5134
5135 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5136 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5137 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5138
5139 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5140 T.start;
5141 alt {
5142 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5143 setverdict(pass);
5144 }
5145 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5146 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5147 }
5148 [] PCU.receive {
5149 repeat;
5150 }
5151 [] T.timeout {
5152 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5153 }
5154 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005155
5156 /* release the channel */
5157 f_rsl_chan_deact();
5158 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5159 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005160}
5161testcase TC_pcu_rr_suspend() runs on test_CT {
5162 var ConnHdlrPars pars;
5163 var ConnHdlr vc_conn;
5164
5165 f_init();
5166
5167 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5168 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5169 vc_conn.done;
5170}
Harald Welte07bd2d22019-05-25 11:03:30 +02005171
Harald Weltea2e0e942019-05-27 18:12:53 +02005172/* Ensure that PCUIF socket can accept only a single connection */
5173testcase TC_pcu_socket_connect_multi() runs on test_CT {
5174 timer T := 5.0;
5175
5176 /* this (among other things) establishes the first connection to the PCUIF socket */
5177 f_init();
5178
5179 /* try to establish a second connection, expect it to fail */
5180 PCU.send(UD_connect:{mp_pcu_socket, -1});
5181 T.start;
5182 alt {
5183 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5184 setverdict(pass);
5185 }
5186 [] PCU.receive(UD_connect_result:?) {
5187 setverdict(fail, "Unexpected unix domain connect result");
5188 }
5189 [] T.timeout {
5190 setverdict(pass);
5191 }
5192 }
5193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5194}
5195
Harald Weltec8effb72019-05-27 18:23:04 +02005196/* Ensure that PCUIF socket can disconnect + reconnect */
5197testcase TC_pcu_socket_reconnect() runs on test_CT {
5198 /* this (among other things) establishes the first connection to the PCUIF socket */
5199 f_init();
5200
5201 f_sleep(1.0);
5202
5203 f_pcuif_close(PCU, g_pcu_conn_id);
5204 g_pcu_conn_id := -1;
5205
5206 f_sleep(1.0);
5207
5208 /* re-connect */
5209 PCU.clear;
5210 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5211 setverdict(pass);
5212
5213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5214}
5215
Harald Weltebe030482019-05-27 22:29:35 +02005216/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005217private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5218runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005219 var L1ctlDlMessage l1_dl;
5220 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005221 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005222 timer T := 5.0;
5223 T.start;
5224 alt {
5225 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005226 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5227 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005228 repeat;
5229 }
5230 }
5231 [] pt.receive {
5232 repeat;
5233 }
5234 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5236 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005237 }
5238 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005239 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005240}
5241
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005242/* Check if GPRS Indicator is present in RR System Information of a given type */
5243private function f_si_has_gprs_indicator(RrMessageType si_type)
5244runs on test_CT return boolean {
5245 var SystemInformation si := f_get_si(L1CTL, si_type);
5246
5247 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005248 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005249 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005250 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005251 }
5252
5253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5254 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005255}
5256
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005257/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5258private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5259runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005260 /* don't call f_init() as this would connect PCU socket */
5261 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005262
5263 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005264 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005265 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005266
5267 f_init_l1ctl();
5268 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005269 f_sleep(2.0);
5270 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005271
5272 if (f_si_has_gprs_indicator(si_type)) {
5273 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005274 } else {
5275 setverdict(pass);
5276 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005277
Harald Weltebe030482019-05-27 22:29:35 +02005278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5279}
5280
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005281testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5282 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5283}
Harald Weltebe030482019-05-27 22:29:35 +02005284
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005285testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5286 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5287}
5288
5289/* Ensure that GPRS capability is advertised after PCU socket connect */
5290private function f_TC_pcu_socket_connect(RrMessageType si_type)
5291runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005292 /* this (among other things) establishes the first connection to the PCUIF socket */
5293 f_init();
5294 f_init_l1ctl();
5295 f_l1_tune(L1CTL);
5296
5297 f_sleep(2.0);
5298 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005299
5300 if (not f_si_has_gprs_indicator(si_type)) {
5301 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005302 } else {
5303 setverdict(pass);
5304 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005305
Harald Weltebe030482019-05-27 22:29:35 +02005306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5307}
5308
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005309testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5310 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5311}
Harald Weltebe030482019-05-27 22:29:35 +02005312
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005313testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5314 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5315}
5316
5317/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5318private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5319runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005320 /* this (among other things) establishes the first connection to the PCUIF socket */
5321 f_init();
5322 f_init_l1ctl();
5323 f_l1_tune(L1CTL);
5324
5325 f_pcuif_close(PCU, g_pcu_conn_id);
5326 g_pcu_conn_id := -1;
5327
5328 f_sleep(1.0);
5329
5330 /* re-connect */
5331 PCU.clear;
5332 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5333
5334 f_sleep(2.0);
5335 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005336
5337 if (f_si_has_gprs_indicator(si_type)) {
5338 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005339 } else {
5340 setverdict(pass);
5341 }
5342
5343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5344}
5345
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005346testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5347 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5348}
5349
5350testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5351 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5352}
5353
Oliver Smithf5239c72019-08-28 10:01:25 +02005354/* 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) */
5355testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5356 var SystemInformation si3 := valueof(ts_SI3_default);
5357
5358 f_init();
5359
5360 /* Verify cell_id */
5361 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5362 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5363 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005364 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5365 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5366 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005367 }
5368
5369 /* Verify LAC */
5370 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5371 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5372 if (lac_si3 != lac_pcu) {
5373 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5374 }
5375
5376 setverdict(pass);
5377}
Harald Welted66c9b82019-05-25 09:03:15 +02005378
Harald Welte3d04ae62018-04-04 20:29:05 +02005379/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005380 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005381 ***********************************************************************/
5382
5383private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5384runs on ConnHdlr {
5385 var PCUIF_send_data sd;
5386 /* Expect BTS to immediately acknowledge activation as PDCH */
5387 PCU.clear;
5388 f_rsl_chan_act(g_pars.chan_mode);
5389 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005390 timer T_wait := 2.0;
5391 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005392 alt {
5393 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5394 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 +02005395 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5396 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5397 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005398 }
5399 }
5400 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005401 [] T_wait.timeout {
5402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5403 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5404 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005405 }
5406 /* try to activate this PDCH from the PCU point of view */
5407 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5408 /* FIXME: is there a response? */
5409}
5410
5411private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5412runs on ConnHdlr {
5413 var PCUIF_send_data sd;
5414 /* Send RSL CHAN REL (deactivate) */
5415 PCU.clear;
5416 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5417 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005418 timer T_wait := 2.0;
5419 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005420 alt {
5421 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5422 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 +02005423 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5424 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5425 repeat;
Harald Welte3d04ae62018-04-04 20:29:05 +02005426 }
5427 }
5428 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005429 [] T_wait.timeout {
5430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5431 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5432 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005433 }
5434 /* Emulate PCU asking BTS to deactivate PDCH */
5435 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5436 alt {
5437 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5438 setverdict(pass);
5439 }
5440 [] RSL.receive { repeat; }
5441 }
5442}
5443
5444/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005445private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005446 var PCUIF_Message first_info;
5447 var integer ts_nr := g_chan_nr.tn;
5448 var integer trx_nr := 0;
5449 var integer bts_nr := 0;
5450 var integer pcu_conn_id := -1;
5451
5452 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5453
5454 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5455 f_sleep(3.0);
5456 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5457 setverdict(pass);
5458}
5459testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5460 var ConnHdlrPars pars;
5461 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005462 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005463
5464 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5465 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5466 vc_conn.done;
5467}
5468
5469/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005470private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005471 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005472 var integer pcu_conn_id := -1;
5473
5474 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5475
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005476 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5477 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5478 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005479 setverdict(pass);
5480}
5481testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5482 var ConnHdlrPars pars;
5483 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005484 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005485
5486 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5487 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5488 vc_conn.done;
5489}
5490
5491/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005492private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005493 var PCUIF_Message first_info;
5494 var integer ts_nr := g_chan_nr.tn;
5495 var integer trx_nr := 0;
5496 var integer bts_nr := 0;
5497 var integer pcu_conn_id := -1;
5498
5499 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5500
5501 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005502 /* Send a second Chan Activ and expect it to be NACKed */
5503 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5504 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005505 setverdict(pass);
5506}
5507testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5508 var ConnHdlrPars pars;
5509 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005510 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005511
5512 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5513 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5514 vc_conn.done;
5515}
5516
5517/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005518private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005519 var PCUIF_Message first_info;
5520 var integer ts_nr := g_chan_nr.tn;
5521 var integer trx_nr := 0;
5522 var integer bts_nr := 0;
5523 var integer pcu_conn_id := -1;
5524 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5525
5526 /* register for the TCH/F channel number */
5527 f_rslem_register(0, chan_nr);
5528
5529 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5530
5531 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5532 "RSL CHAN ACT");
5533 setverdict(pass);
5534}
5535testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5536 var ConnHdlrPars pars;
5537 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005538 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005539
5540 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5541 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5542 vc_conn.done;
5543}
5544
5545/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005546private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005547 var PCUIF_Message first_info;
5548 var integer ts_nr := g_chan_nr.tn;
5549 var integer trx_nr := 0;
5550 var integer bts_nr := 0;
5551 var integer pcu_conn_id := -1;
5552 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5553 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5554
5555 /* register for the TCH/H channel numbers */
5556 f_rslem_register(0, chan_nr[0]);
5557 f_rslem_register(0, chan_nr[1]);
5558
5559 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5560
5561 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5562 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5563 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5564 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5565 setverdict(pass);
5566}
5567testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5568 var ConnHdlrPars pars;
5569 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005570 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005571
5572 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5573 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5574 vc_conn.done;
5575}
5576
Harald Welte9bbbfb52018-04-05 09:33:19 +02005577/***********************************************************************
5578 * IPA Style Dynamic Timeslot Support
5579 ***********************************************************************/
5580
5581private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5582runs on ConnHdlr {
5583 var PCUIF_send_data sd;
5584 /* Expect BTS to immediately acknowledge activation as PDCH */
5585 PCU.clear;
5586 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5587 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005588 timer T_wait := 2.0;
5589 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005590 alt {
5591 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5592 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 +01005593 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
5594 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5595 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005596 }
5597 }
5598 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005599 [] T_wait.timeout {
5600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5601 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5602 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005603 }
5604 /* try to activate this PDCH from the PCU point of view */
5605 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5606 /* FIXME: is there a response? */
5607
5608 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5609}
5610
5611private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5612runs on ConnHdlr {
5613 var PCUIF_send_data sd;
5614 /* Send RSL CHAN REL (deactivate) */
5615 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5616 PCU.clear;
5617 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005618 timer T_wait := 2.0;
5619 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005620 alt {
5621 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5622 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 +01005623 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
5624 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
5625 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005626 }
5627 }
5628 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005629 [] T_wait.timeout {
5630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5631 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5632 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005633 }
5634 /* Emulate PCU asking BTS to deactivate PDCH */
5635 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5636 alt {
5637 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5638 setverdict(pass);
5639 }
5640 [] RSL.receive { repeat; }
5641 }
5642}
5643
5644/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005645private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005646 var PCUIF_Message first_info;
5647 var integer ts_nr := g_chan_nr.tn;
5648 var integer trx_nr := 0;
5649 var integer bts_nr := 0;
5650 var integer pcu_conn_id := -1;
5651
5652 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5653
5654 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5655 f_sleep(3.0);
5656 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5657
5658 setverdict(pass);
5659
5660}
5661testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5662 var ConnHdlrPars pars;
5663 var ConnHdlr vc_conn;
5664 f_init();
5665
5666 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5667 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5668 vc_conn.done;
5669}
5670
5671/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005672private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005673 var PCUIF_Message first_info;
5674 var integer ts_nr := g_chan_nr.tn;
5675 var integer trx_nr := 0;
5676 var integer bts_nr := 0;
5677 var integer pcu_conn_id := -1;
5678
5679 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5680
5681 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5682 "RSL CHAN ACT");
5683 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5684 "RF CHAN REL", true);
5685 setverdict(pass);
5686}
5687testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5688 var ConnHdlrPars pars;
5689 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005690 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005691
5692 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5693 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5694 vc_conn.done;
5695}
5696
5697/* 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 +07005698private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005699 var PCUIF_Message first_info;
5700 var integer ts_nr := g_chan_nr.tn;
5701 var integer trx_nr := 0;
5702 var integer bts_nr := 0;
5703 var integer pcu_conn_id := -1;
5704
5705 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5706
5707 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5708 "RSL CHAN ACT");
5709
5710 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5711 alt {
5712 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5713 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005715 }
5716 [] RSL.receive { repeat; }
5717 }
5718
5719 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5720 "RF CHAN REL", true);
5721 setverdict(pass);
5722}
5723testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5724 var ConnHdlrPars pars;
5725 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005726 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005727
5728 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5729 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5730 vc_conn.done;
5731}
5732
5733/* 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 +07005734private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005735 var PCUIF_Message first_info;
5736 var integer ts_nr := g_chan_nr.tn;
5737 var integer trx_nr := 0;
5738 var integer bts_nr := 0;
5739 var integer pcu_conn_id := -1;
5740
5741 /* register for the TCH/F channel number */
5742 f_rslem_register(0, g_chan_nr);
5743
5744 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5745
5746 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5747
5748 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5749 "RSL CHAN ACT");
5750
5751 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5752
5753 setverdict(pass);
5754}
5755testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5756 var ConnHdlrPars pars;
5757 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005758 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005759
5760 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5761 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5762 vc_conn.done;
5763}
5764
5765
Harald Welte0472ab42018-03-12 15:02:26 +01005766/***********************************************************************
5767 * LAPDm / RLL related
5768 ***********************************************************************/
5769
5770private function f_tx_lapdm(template (value) LapdmFrame l,
5771 template (value) RslLinkId link_id) runs on ConnHdlr {
5772 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005773 var template (value) SacchL1Header l1h;
5774
5775 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005776 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005777 /* Compose dummy L1 header */
5778 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5779 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 +02005780 } else {
5781 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005782 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 +01005783 }
Harald Welte0472ab42018-03-12 15:02:26 +01005784}
5785
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005786private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005787 uint3_t sapi,
5788 RslLinkId link_id,
5789 octetstring l3,
5790 boolean exp
5791}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005792private type record of RllTestCase RllTestCases;
5793private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5794 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005795 sapi := sapi,
5796 link_id := id,
5797 l3 := l3,
5798 exp := exp
5799}
5800
5801/* execute the same callback function with a set of different parameters (tcs) on a
5802 * variety of logical channels */
5803private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5804 var ConnHdlrPars pars;
5805 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005806 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005807
5808 /* test on each of the channels we have */
5809 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5810 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5811
5812 /* test each of the test cases on the current channel */
5813 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5814 pars.spec.rll := tcs[j];
5815 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5816 vc_conn := f_start_handler(fn, pars);
5817 vc_conn.done;
5818 }
5819 }
5820
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005822}
5823
5824/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5825private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5826 var RllTestCase tc := g_pars.spec.rll;
5827 timer T := 3.0;
5828
5829 f_l1_tune(L1CTL);
5830 RSL.clear;
5831
5832 /* activate the logical channel */
5833 f_est_dchan();
5834 L1CTL.clear;
5835
5836 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5837 T.start;
5838 alt {
5839 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5840 if (tc.exp) {
5841 setverdict(pass);
5842 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005844 }
5845 }
5846 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5847 if (tc.exp) {
5848 setverdict(pass);
5849 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005851 }
5852 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005853 /* We also expect to receive the measurements */
5854 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005855 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005857 }
5858 [not tc.exp] T.timeout {
5859 setverdict(pass);
5860 }
5861 }
5862
5863 f_rsl_chan_deact();
5864 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5865 f_rslem_unregister(0, g_chan_nr);
5866}
5867testcase TC_rll_est_ind() runs on test_CT {
5868 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005869 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005870 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005871 /* normal SAPI0 establishment */
5872 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005873 /* SAPI 3 doesn't support contention resolution */
5874 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5875 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5876 /* normal SAPI3 establishment on main DCCH */
5877 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5878 /* normal SAPI3 establishment on SACCH */
5879 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5880 };
5881 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5882}
5883
5884/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5885private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5886 var RllTestCase tc := g_pars.spec.rll;
5887 var L1ctlDlMessage dl;
5888 timer T := 3.0;
5889
5890 f_l1_tune(L1CTL);
5891 RSL.clear;
5892
5893 /* activate the logical channel */
5894 f_est_dchan();
5895 L1CTL.clear;
5896
5897 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5898 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5899 T.start;
5900 alt {
5901 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5902 var LapdmFrame lapdm;
5903 var octetstring l2 := dl.payload.data_ind.payload;
5904 if (dl.dl_info.link_id.c == SACCH) {
5905 /* remove L1 header */
5906 l2 := substr(l2, 2, lengthof(l2)-2);
5907 }
5908 lapdm.ab := dec_LapdmFrameAB(l2);
5909 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5910 setverdict(pass);
5911 } else {
5912 repeat;
5913 }
5914 }
5915 [] L1CTL.receive { repeat; }
5916 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005918 }
5919 }
5920
5921 f_rsl_chan_deact();
5922 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5923 f_rslem_unregister(0, g_chan_nr);
5924}
5925testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5926 var RllTestCases tcs := {
5927 /* normal SAPI3 establishment on main DCCH */
5928 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5929 };
5930 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5931}
5932testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5933 var RllTestCases tcs := {
5934 /* normal SAPI3 establishment on SACCH */
5935 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5936 }
5937 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5938}
5939
5940/* altstep to receive a LAPDm frame matching the given template */
5941private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5942 var L1ctlDlMessage dl;
5943 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5944 var LapdmFrame lapdm;
5945 var octetstring l2 := dl.payload.data_ind.payload;
5946 if (dl.dl_info.link_id.c == SACCH) {
5947 /* remove L1 header */
5948 l2 := substr(l2, 2, lengthof(l2)-2);
5949 }
5950 if (ischosen(exp.ab)) {
5951 lapdm.ab := dec_LapdmFrameAB(l2);
5952 } else if (ischosen(exp.b4)) {
5953 lapdm.b4 := dec_LapdmFrameB4(l2);
5954 } else if (ischosen(exp.bbis)) {
5955 lapdm.bbis := dec_LapdmFrameBbis(l2);
5956 }
5957 log("Rx LAPDm ", lapdm);
5958 if (match(lapdm, exp)) {
5959 setverdict(pass);
5960 } else {
5961 repeat;
5962 }
5963 }
5964 [] L1CTL.receive { repeat; }
5965}
5966private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
5967 timer T := t;
5968 T.start;
5969 alt {
5970 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01005972 }
5973 [] as_l1_exp_lapdm(exp);
5974 }
5975}
5976
5977/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
5978private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5979 /* send SABM from MS -> BTS */
5980 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
5981 /* expect RLL EST IND on Abis */
5982 alt {
5983 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
5984 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
5985 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005987 }
5988 [] RSL.receive { repeat; }
5989 }
5990 /* expect UA from BTS -> MS */
5991 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
5992}
5993
5994/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
5995private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
5996 var RllTestCase tc := g_pars.spec.rll;
5997
5998 f_l1_tune(L1CTL);
5999 RSL.clear;
6000
6001 /* activate the logical channel */
6002 f_est_dchan();
6003 L1CTL.clear;
6004
6005 /* first establish the link-layer */
6006 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6007
6008 /* then send the DISC */
6009 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6010 /* ... and expect the REL IND on the RSL side */
6011 alt {
6012 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6013 setverdict(pass);
6014 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006015 /* We also expect to receive the measurements */
6016 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006017 }
6018
6019 /* release the channel */
6020 f_rsl_chan_deact();
6021 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6022 f_rslem_unregister(0, g_chan_nr);
6023}
6024testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6025 var RllTestCases tcs := {
6026 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6027 };
6028 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6029}
6030
6031testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6032 var RllTestCases tcs := {
6033 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6034 };
6035 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6036}
6037testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6038 var RllTestCases tcs := {
6039 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6040 };
6041 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6042}
6043testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6044 var RllTestCases tcs := {
6045 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6046 };
6047 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6048}
6049
6050/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6051private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6052 var RllTestCase tc := g_pars.spec.rll;
6053 f_l1_tune(L1CTL);
6054 RSL.clear;
6055
6056 /* activate the logical channel */
6057 f_est_dchan();
6058 L1CTL.clear;
6059
6060 /* first establish the link-layer */
6061 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6062
6063 /* then send the REL REQ via RSL */
6064 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6065 /* ... and expect the DISC on the Um side */
6066 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006067 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006068 /* FIXME: send a UA in resposne to the DISC */
6069 }
6070 }
6071
6072 /* release the channel */
6073 f_rsl_chan_deact();
6074 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6075 f_rslem_unregister(0, g_chan_nr);
6076}
6077testcase TC_rll_rel_req() runs on test_CT {
6078 var RllTestCases tcs := {
6079 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6080 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6081 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6082 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6083 };
6084 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6085}
6086
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006087/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006088testcase TC_rll_data_req() runs on test_CT {
6089}
6090
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006091/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006092testcase TC_rll_data_ind() runs on test_CT {
6093}
6094
6095/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6096private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6097 var RllTestCase tc := g_pars.spec.rll;
6098
6099 f_l1_tune(L1CTL);
6100 RSL.clear;
6101
6102 f_est_dchan();
6103 L1CTL.clear;
6104
6105 /* Send UNITDATA REQ on RSL side */
6106 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6107 /* Expect it to arrive on the other side */
6108 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006109 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006110 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006111 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006112 }
6113
6114 /* release the channel */
6115 f_rsl_chan_deact();
6116 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6117 f_rslem_unregister(0, g_chan_nr);
6118}
6119testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6120 var octetstring l3 := f_rnd_octstring(15);
6121 var RllTestCases tcs := {
6122 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6123 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6124 };
6125 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6126}
6127testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6128 var octetstring l3 := f_rnd_octstring(19);
6129 var RllTestCases tcs := {
6130 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6131 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6132 };
6133 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6134}
6135
6136/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6137private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6138 var RllTestCase tc := g_pars.spec.rll;
6139
6140 f_l1_tune(L1CTL);
6141 RSL.clear;
6142
6143 f_est_dchan();
6144 L1CTL.clear;
6145
6146 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006147 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006148 /* Expdct RLL UNITDATA IND on RSL side */
6149 alt {
6150 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6151 setverdict(pass);
6152 }
6153 [] RSL.receive { repeat; }
6154 }
6155
6156 /* release the channel */
6157 f_rsl_chan_deact();
6158 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6159 f_rslem_unregister(0, g_chan_nr);
6160}
6161testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006162 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006163 var RllTestCases tcs := {
6164 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6165 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6166 };
6167 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6168}
6169testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6170 var octetstring l3 := f_rnd_octstring(18);
6171 var RllTestCases tcs := {
6172 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6173 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6174 };
6175 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6176}
6177
Harald Weltee613f962018-04-18 22:38:16 +02006178/***********************************************************************
6179 * Encryption Related
6180 ***********************************************************************/
6181
6182/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006183private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006184 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6185 if (link_id.c == SACCH) {
6186 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6187 } else {
6188 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6189 }
6190}
6191
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006192/* Expect (or not expect) other kinds of messages */
6193private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6194 [exp_any] RSL.receive { repeat; }
6195 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006197 }
6198}
6199
Harald Weltee613f962018-04-18 22:38:16 +02006200/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006201private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006202 RslLinkId link_id,
6203 octetstring l3,
6204 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006205 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006206) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006207 timer T := 3.0;
6208 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6209 T.start;
6210 /* Expect RLL UNITDATA IND on RSL side */
6211 alt {
6212 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6213 setverdict(pass);
6214 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006215 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006216 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006217 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006219 }
Harald Weltee613f962018-04-18 22:38:16 +02006220 }
6221}
6222
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006223/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6224private function f_data_mo(
6225 RslLinkId link_id,
6226 boolean p, uint3_t nr, uint3_t ns,
6227 octetstring l3,
6228 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006229 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006230) runs on ConnHdlr {
6231 timer T := 3.0;
6232 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6233 T.start;
6234 /* Expect RLL DATA IND on RSL side */
6235 alt {
6236 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6237 setverdict(pass);
6238 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006239 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006240 [] as_rsl_any_ind(exp_any);
6241 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006243 }
6244 }
6245}
6246
Harald Weltee613f962018-04-18 22:38:16 +02006247/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006248private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006249 f_l1_tune(L1CTL);
6250 f_est_dchan(true);
6251
6252 /* now we actually need to transmit some data both ways to check if the encryption works */
6253 var L1ctlDlMessage dl;
6254
Stefan Sperling603d98e2018-07-25 16:47:28 +02006255 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006256 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6257
6258 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6259 f_unitdata_mt(link_id, l3);
6260
6261 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6262 f_unitdata_mo(link_id, l3);
6263
6264 /* release the channel */
6265 f_rsl_chan_deact();
6266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6267 f_rslem_unregister(0, g_chan_nr);
6268}
6269testcase TC_chan_act_a51() runs on test_CT {
6270 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6271 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6272 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6273}
6274testcase TC_chan_act_a52() 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_2, f_rnd_octstring(8)));
6277 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6278}
6279testcase TC_chan_act_a53() 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_3, f_rnd_octstring(8)));
6282 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6283}
6284
Eric Wildf1827a72019-05-28 17:37:35 +02006285/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6286 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 +07006287private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006288 f_l1_tune(L1CTL);
6289 f_est_dchan(true);
6290
6291 /* now we actually need to transmit some data both ways to check if the encryption works */
6292 var L1ctlDlMessage dl;
6293
6294 var octetstring l3 := f_rnd_octstring(20);
6295 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6296
6297 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6298 f_unitdata_mt(link_id, l3);
6299
6300 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6301 f_unitdata_mo(link_id, l3);
6302
6303 var RSL_Message rsl;
6304 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6305
6306 /* modify key to break proper encryption */
6307 g_pars.encr.key := f_rnd_octstring(8);
6308 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6309 rsl.ies := rsl.ies & { ei };
6310 RSL.send(rsl);
6311
6312 timer T0 := 1.0;
6313 T0.start;
6314 /* Expect RSL MODIFY ACK */
6315 alt {
6316 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6317 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6319 }
6320 [] T0.timeout {
6321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6322 }
6323 }
6324
6325 var octetstring l3msg := f_rnd_octstring(15);
6326 timer T1 := 3.0;
6327 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6328 due to broken encryption */
6329 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6330 T1.start;
6331 alt {
6332 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6334 }
6335 [] T1.timeout {
6336 setverdict(pass);
6337 }
6338 }
6339
6340 /* release the channel */
6341 f_rsl_chan_deact();
6342 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6343 f_rslem_unregister(0, g_chan_nr);
6344}
6345testcase TC_rsl_modify_encr() runs on test_CT {
6346 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6347 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6348 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6349}
Harald Weltee613f962018-04-18 22:38:16 +02006350
6351/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006352private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006353 /* L3 payload doesn't matter, as it is passed transparently */
6354 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6355 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6356 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6357
6358 f_l1_tune(L1CTL);
6359
6360 /* first establish a dedicated channel in the clear */
6361 f_est_dchan(false);
6362
6363 /* Establish ABM */
6364 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6365
6366 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6367 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6368 /* expect the L3 to arrive still unencrypted on the MS side */
6369 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6370
6371 /* configure L1 to apply ciphering */
6372 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6373 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6374
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006375 /* send first ciphered I-frame in response and expect it on RSL */
6376 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006377
6378 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6379 * and hence enable encryption also on the downlink */
6380
6381 /* expect bi-directional communication work in encrypted mode */
6382 f_unitdata_mo(link_id, f_rnd_octstring(15));
6383 f_unitdata_mt(link_id, f_rnd_octstring(15));
6384
6385 /* release the channel */
6386 f_rsl_chan_deact();
6387 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6388 f_rslem_unregister(0, g_chan_nr);
6389}
6390testcase TC_encr_cmd_a51() runs on test_CT {
6391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6392 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6393 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6394}
6395testcase TC_encr_cmd_a52() 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_2, f_rnd_octstring(8)));
6398 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6399}
6400testcase TC_encr_cmd_a53() 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_3, f_rnd_octstring(8)));
6403 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6404}
6405
6406private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6407 var LapdmFrame lf;
6408 var octetstring reenc;
6409
6410 /* decode the LAPDm frame */
6411 if (ischosen(exp_match.ab)) {
6412 lf.ab := dec_LapdmFrameAB(enc);
6413 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006415 }
6416
6417 /* check if decoder result matches expectation */
6418 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006420 } else {
6421 log(name, ": matched");
6422 setverdict(pass);
6423 }
6424
6425 /* test if re-encoded frame equals original input */
6426 reenc := enc_LapdmFrame(lf);
6427 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006429 } else {
6430 setverdict(pass);
6431 }
6432}
6433
6434testcase TC_lapdm_selftest() runs on test_CT {
6435 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6436 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6437 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6438 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6439 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6440 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6441 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6442}
6443
Stefan Sperling4880be42018-08-07 18:12:59 +02006444/***********************************************************************
6445 * DTX Related (see GSM 05.08, section 8.3)
6446 ***********************************************************************/
6447
6448/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006449private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006450 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6451 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6452 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6453 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6454}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006455private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006456 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6457 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6458}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006459private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006460 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6461 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6462 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6463 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6464}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006465private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006466 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6467 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6468 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6469 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6470 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6471 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6472 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6473 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6474}
6475
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006476private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006477 var L1ctlDlMessage dl;
6478 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6479 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6480 var GsmFrameNumber first_fn;
6481 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006482 var integer nfill_frames_sacch := 0;
6483 var integer nfill_frames_nonsacch := 0;
6484 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006485 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6486 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006487 const integer frame_dtx_tchf_mod := 104;
6488 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6489 * which operates in terms of blocks rather than frames. */
6490 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6491 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006492 timer T := 5.0;
6493
6494 f_l1_tune(L1CTL);
6495 RSL.clear;
6496 L1CTL.clear;
6497
6498 /* activate TCHF signalling channel */
6499 f_est_dchan(false);
6500
6501 T.start;
6502 alt {
6503 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6504 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6505 var octetstring l2 := dl.payload.data_ind.payload;
6506
6507 if (is_first_frame) {
6508 is_first_frame := false;
6509 first_fn := dl.dl_info.frame_nr;
6510 }
6511
6512 if (dl.dl_info.link_id.c == SACCH) {
6513 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6514 if (not match(l2_fill_frame_sacch, l2)) {
6515 repeat;
6516 }
6517 } else if (not match(l2_fill_frame, l2)) {
6518 repeat;
6519 }
6520
6521 if (dtxd) {
6522 if (not f_g_chan_is_tchf()) {
6523 T.stop;
6524 f_rsl_chan_deact();
6525 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006526 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 +02006527 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006528 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006529 T.stop;
6530 f_rsl_chan_deact();
6531 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006532
6533 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6534 * 2 SACCH, 1 TCH/F */
6535 expected_fill_frames := 3;
6536
6537 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6538 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6539 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006541 } else {
6542 setverdict(pass);
6543 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006544 } else {
6545 if (dl.dl_info.link_id.c == SACCH) {
6546 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006547 repeat;
6548 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006549 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6550 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6551 * we should only see the subset of frames numbers which correspond to a block boundary.
6552 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6553 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6554 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6555 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6556 repeat;
6557 }
6558 }
6559 log("Received DTX TCH fill frame with bad frame number: ", fn,
6560 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6561 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6562 f_rsl_chan_deact();
6563 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006565 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006566 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006567 if (dl.dl_info.link_id.c == SACCH) {
6568 nfill_frames_sacch := nfill_frames_sacch + 1;
6569 } else {
6570 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6571 }
6572 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006573 T.stop;
6574 if (f_g_chan_is_tchf()) {
6575 /* Without DTX we can expect 25 fill frames for every 104 frames.
6576 * (24 FACCH + 1 SACCH filling) */
6577 expected_fill_frames := 25;
6578 } else if (f_g_chan_is_tchh()) {
6579 /* We can expect 2 fill frames for every 104 frames. */
6580 expected_fill_frames := 2;
6581 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6582 /* We can expect 5 fill frames for every 104 frames. */
6583 expected_fill_frames := 5;
6584 } else {
6585 f_rsl_chan_deact();
6586 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006588 }
6589
6590 f_rsl_chan_deact();
6591 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006592
6593 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006594 setverdict(pass);
6595 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006596 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6597 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006599 }
6600 } else {
6601 repeat;
6602 }
6603 }
6604 }
6605 [] L1CTL.receive { repeat; }
6606 [] T.timeout {
6607 f_rsl_chan_deact();
6608 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006610 }
6611 }
6612}
6613
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006614private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006615 f_test_l2_fill_frames(false);
6616}
6617
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006618private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006619 f_test_l2_fill_frames(true);
6620}
6621
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006622private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006623 var ConnHdlr vc_conn;
6624 var ConnHdlrPars pars;
6625 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006626 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006627 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6628 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6629 if (dtxd) {
6630 if (i >= 4) { /* DTX is only allowed on TCH/F */
6631 break;
6632 }
6633 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6634 } else {
6635 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6636 }
6637 vc_conn.done;
6638 }
6639}
6640
6641/* Verify that L2 fill frames are sent on TCH in signaling mode if
6642 * there is nothing to transmit while DTX is disabled on downlink. */
6643testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6644 f_tch_sign_l2_fill_frame(false);
6645}
6646
6647/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6648 * there is nothing to transmit while DTX is enabled on downlink. */
6649testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6650 f_tch_sign_l2_fill_frame(true);
6651}
Harald Welte0472ab42018-03-12 15:02:26 +01006652
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006653testcase TC_chopped_ipa_ping() runs on test_CT {
6654 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6655}
6656
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006657testcase TC_chopped_ipa_payload() runs on test_CT {
6658 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6659}
6660
Harald Welte0472ab42018-03-12 15:02:26 +01006661/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6662/* protocol error as per 44.006 */
6663/* link layer failure (repetition of I-frame N200 times without ACK */
6664/* repetition of SABM or DISC N200 times without ACK */
6665/* receptiom of SABM in multi-frame established state */
6666
6667
Harald Welte68e495b2018-02-25 00:05:57 +01006668/* TODO Areas:
6669
6670* channel activation
6671** with BS_Power / MS_Power, bypassing power control loop
6672** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006673** with timing advance from initial activation on
6674* mode modify
6675** encryption
6676** multirate
6677* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006678** unsupported algorithm
6679* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006680* BS Power Control
6681* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006682* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006683* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006684** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006685* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006686** DATA_IND from BTS->PCU
6687** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006688
6689*/
Harald Welte70767382018-02-21 12:16:40 +01006690
6691control {
6692 execute( TC_chan_act_stress() );
6693 execute( TC_chan_act_react() );
6694 execute( TC_chan_deact_not_active() );
6695 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006696 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006697 execute( TC_sacch_filling() );
6698 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006699 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006700 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006701 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006702 execute( TC_sacch_chan_act_ho_async() );
6703 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006704 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006705 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006706 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006707 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006708 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006709 execute( TC_rach_load_idle_thresh0() );
6710 execute( TC_rach_load_idle_below_thresh() );
6711 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006712 execute( TC_meas_res_sign_tchf() );
6713 execute( TC_meas_res_sign_tchh() );
6714 execute( TC_meas_res_sign_sdcch4() );
6715 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006716 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006717 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006718 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006719 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006720 execute( TC_rsl_bs_pwr_static_ass() );
6721 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006722 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006723 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006724 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006725 execute( TC_rsl_ms_pwr_dyn_up() );
6726 execute( TC_rsl_ms_pwr_dyn_down() );
6727 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6728 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006729 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006730 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006731 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006732 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006733 execute( TC_paging_imsi_80percent() );
6734 execute( TC_paging_tmsi_80percent() );
6735 execute( TC_paging_imsi_200percent() );
6736 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006737 execute( TC_rsl_protocol_error() );
6738 execute( TC_rsl_mand_ie_error() );
6739 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006740 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006741 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006742 execute( TC_si_sched_2bis() );
6743 execute( TC_si_sched_2ter() );
6744 execute( TC_si_sched_2ter_2bis() );
6745 execute( TC_si_sched_2quater() );
6746 execute( TC_si_sched_13() );
6747 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006748 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006749 execute( TC_ipa_crcx_twice_not_active() );
6750 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006751 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006752 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006753
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006754 if (mp_pcu_socket != "") {
6755 execute( TC_pcu_act_req() );
6756 execute( TC_pcu_act_req_wrong_ts() );
6757 execute( TC_pcu_act_req_wrong_bts() );
6758 execute( TC_pcu_act_req_wrong_trx() );
6759 execute( TC_pcu_deact_req() );
6760 execute( TC_pcu_deact_req_wrong_ts() );
6761 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006762 if (mp_l1_supports_gprs) {
6763 execute( TC_pcu_data_req_pdtch() );
6764 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006765 execute( TC_pcu_data_req_wrong_bts() );
6766 execute( TC_pcu_data_req_wrong_trx() );
6767 execute( TC_pcu_data_req_wrong_ts() );
6768 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006769 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006770 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006771 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006772 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006773 execute( TC_pcu_data_req_imm_ass_pch() );
6774 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006775 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006776 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006777 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006778 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006779 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006780 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006781 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006782 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006783 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006784 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006785 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006786 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006787 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006788 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006789 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006790 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006791 execute( TC_dyn_osmo_pdch_act_deact() );
6792 execute( TC_dyn_osmo_pdch_double_act() );
6793 execute( TC_dyn_ipa_pdch_act_deact() );
6794 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6795
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006796 } else {
6797 log("PCU socket path not available, skipping PCU tests");
6798 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006799
Harald Welte3d04ae62018-04-04 20:29:05 +02006800 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006801 execute( TC_dyn_osmo_pdch_tchf_act() );
6802 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006803 execute( TC_dyn_ipa_pdch_tchf_act() );
6804 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006805
6806 execute( TC_rll_est_ind() );
6807 execute( TC_rll_est_req_DCCH_3() );
6808 execute( TC_rll_est_req_ACCH_3() );
6809 execute( TC_rll_rel_ind_DCCH_0() );
6810 execute( TC_rll_rel_ind_DCCH_3() );
6811 execute( TC_rll_rel_ind_ACCH_0() );
6812 execute( TC_rll_rel_ind_ACCH_3() );
6813 execute( TC_rll_rel_req() );
6814 execute( TC_rll_unit_data_req_DCCH() );
6815 execute( TC_rll_unit_data_req_ACCH() );
6816 execute( TC_rll_unit_data_ind_DCCH() );
6817 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006818
6819 execute( TC_chan_act_a51() );
6820 execute( TC_chan_act_a52() );
6821 execute( TC_chan_act_a53() );
6822 execute( TC_encr_cmd_a51() );
6823 execute( TC_encr_cmd_a52() );
6824 execute( TC_encr_cmd_a53() );
6825
Harald Welteee25aae2019-05-19 14:32:37 +02006826 execute( TC_err_rep_wrong_mdisc() );
6827 execute( TC_err_rep_wrong_msg_type() );
6828 execute( TC_err_rep_wrong_sequence() );
6829
Harald Weltee613f962018-04-18 22:38:16 +02006830 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006831
6832 execute( TC_tch_sign_l2_fill_frame() );
6833 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006834
6835 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006836 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006837}
6838
6839
6840}