blob: cb37677197d8a14d100f5956d2df3b32ae1ce242 [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;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020069friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020070friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020071friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010072friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020073friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030074
Harald Welte70767382018-02-21 12:16:40 +010075/* The tests assume a BTS with the following timeslot configuration:
76 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020077 * TS1 : TCH/F
78 * TS2 : TCH/F
79 * TS3 : TCH/F_PDCH (IPA Style)
80 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010081 * TS5 : TCH/H
82 * TS6 : SDCCH/8
83 * TS7 : PDCH
84 */
85
86modulepar {
87 charstring mp_rsl_ip := "127.0.0.2";
88 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070089 charstring mp_bts_trxc_ip := "127.0.0.1";
90 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010091 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020092 charstring mp_ctrl_ip := "127.0.0.1";
93 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020094 charstring mp_bsc_ctrl_ip := "127.0.0.1";
95 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020096 integer mp_tolerance_rxqual := 1;
97 integer mp_tolerance_rxlev := 3;
98 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020099 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200100 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200101 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200102 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
103 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 +0200104 integer mp_ms_actual_ta_exp := 0;
105 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700106 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700107 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100108 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200109 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200110 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200111 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
112 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700113 /* how many transceivers do we expect to connect */
114 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700115 /* frequency hopping status */
116 boolean mp_freq_hop_enabled := false;
117 /* frequency hopping parameters */
118 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700119 /* configuration for each individual transceiver */
120 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700121 /* default Training Sequence Code */
122 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200123 /* Default interference boundaries in osmo-bsc (in dBm):
124 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
125 * Default interference level reported by fake_trx.py:
126 * 0: -109 >= -85 dBm (no)
127 * X1: -109 >= -91 dBm (no)
128 * X2: -109 >= -97 dBm (no)
129 * X3: -109 >= -103 dBm (no)
130 * X4: -109 >= -109 dBm (yes)
131 * X5: -109 >= -115 dBm (no)
132 * So all channels should be in band 4. */
133 uint3_t mp_interf_band := 4;
Harald Welte70767382018-02-21 12:16:40 +0100134}
135
Harald Welte629cc6b2018-03-11 17:19:05 +0100136type record of RslChannelNr ChannelNrs;
137
Harald Welte70767382018-02-21 12:16:40 +0100138type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100139 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100140 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100141 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100142 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100143 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100144 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100145
146 /* L1CTL port (for classic tests) */
147 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100148
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700149 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700150 port TRXC_CODEC_PT BTS_TRXC;
151 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100152
Harald Weltef50e3ae2018-09-10 10:27:56 +0200153 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100154 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200155 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100156
Harald Welte883340c2018-02-28 18:59:29 +0100157 /* PCU Interface of BTS */
158 port PCUIF_CODEC_PT PCU;
159 var integer g_pcu_conn_id;
160 /* Last PCU INFO IND we received */
161 var PCUIF_Message g_pcu_last_info;
162
Harald Welte48494ca2018-02-25 16:59:50 +0100163 /* SI configuration */
164 var SystemInformationConfig si_cfg := {
165 bcch_extended := false,
166 si1_present := false,
167 si2bis_present := false,
168 si2ter_present := false,
169 si2quater_present := false,
170 si7_present := false,
171 si8_present := false,
172 si9_present := false,
173 si13_present := false,
174 si13alt_present := false,
175 si15_present := false,
176 si16_present := false,
177 si17_present := false,
178 si2n_present := false,
179 si21_present := false,
180 si22_present := false
181 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100182
183 /* all logical channels available on the BTS */
184 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100185 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100186}
187
188/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200189type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100190 port L1CTL_PT L1CTL;
191
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700192 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700193 port TRXC_CODEC_PT BTS_TRXC;
194 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100195
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200196 /* port to be initialized optionally to access BSC VTY */
197 port TELNETasp_PT BSCVTY;
198
Harald Welte70767382018-02-21 12:16:40 +0100199 timer g_Tguard;
200 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
201
202 var ConnHdlrPars g_pars;
203 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100204 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200205
206 /* PCU Interface of BTS */
207 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100208}
209
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700210private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700211 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200212 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700213 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200214 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200216 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700217 timer T;
218
Harald Welte70767382018-02-21 12:16:40 +0100219 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
220 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
221
222 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
223 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
224 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
225
226 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
227 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700228
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700229 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700230 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700231 T.start(mp_ipa_up_timeout);
232 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700233 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700234 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
235 /* Make sure that all transceivers use unique stream ID */
236 if (trx_mask[enum2int(ev.sid)] == '1'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
239 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700240
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700241 trx_mask[enum2int(ev.sid)] := '1'B;
242 trx_count := trx_count + 1;
243
244 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200245 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700246 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200247 /* This message (RF RESource INDication) is sent by the IUT itself */
248 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
249 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
251 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
252 }
253 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
255 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
256 }
257
258 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
259 rfind_count := rfind_count + 1;
260 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
261 if (rfind_count < mp_transceiver_num) { repeat; }
262 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700263 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
264 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
265 [] T.timeout {
266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
267 "Timeout waiting for RSL bring up");
268 }
269 }
Harald Welte70767382018-02-21 12:16:40 +0100270}
271
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700272friend type record length(1 .. 256) of TrxParsItem TrxPars;
273friend type record TrxParsItem {
274 GsmArfcn arfcn,
275 TrxTsPars ts
276};
277
278friend type record length(8) of TrxTsParsItem TrxTsPars;
279friend type record TrxTsParsItem {
280 PchanConfig config
281};
282
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700283friend type record FreqHopPars {
284 /* Whether frequency hopping is in use */
285 boolean enabled,
286 /* Mobile Allocation Index Offset / Hopping Sequence Number */
287 MaioHsn maio_hsn,
288 /* MA bitmap to be indicated in RR Immediate Assignment */
289 MobileAllocationLV ma_map,
290 /* The actual Mobile Allocation (ARFCN list) to be used */
291 L1ctlMA ma
292};
293
Harald Welte70767382018-02-21 12:16:40 +0100294type record ConnHdlrPars {
295 RslChannelNr chan_nr,
296 RSL_IE_ChannelMode chan_mode,
297 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100298 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200299 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200300 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700301 BtsBand bts0_band optional,
302
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700303 /* Training Sequence Code */
304 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700305 /* Frequency hopping parameters */
306 FreqHopPars fhp
307};
Harald Welte0472ab42018-03-12 15:02:26 +0100308
309/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200310friend type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100311 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100312}
313
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700314private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100315 max_retrans := RACH_MAX_RETRANS_7,
316 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100317 cell_barr_access := false,
318 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100319 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100320};
321
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700322private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100323 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200324 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100325 acs := '0'B,
326 neci := true,
327 rxlev_access_min := 0
328}
329
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700330private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100331 mcc_mnc := '262F42'H,
332 lac := 42
333}
334
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700335private template (value) GPRSIndicator ts_GPRSIndicator_def := {
336 ra_colour := 0,
337 si13_pos := '0'B
338}
339
340private template (value) SI3RestOctets ts_SI3RestOctets_def
341modifies ts_SI3RestOctets := {
342 gprs_ind := {
343 presence := CSN1_H,
344 ind := ts_GPRSIndicator_def
345 }
346}
347
348private template (value) SI4RestOctets ts_SI4RestOctets_def
349modifies ts_SI4RestOctets := {
350 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700351 presence := CSN1_H,
352 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700353 }
354}
355
Harald Welte7484fc42018-02-24 14:09:45 +0100356/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700357private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100358 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100359 payload := {
360 si3 := {
361 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100362 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100363 ctrl_chan_desc := {
364 msc_r99 := true,
365 att := true,
366 bs_ag_blks_res := 1,
367 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100368 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100369 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
370 spare := '00'B,
371 bs_pa_mfrms := 0, /* 2 multiframes */
372 t3212 := 1 /* 6 minutes */
373 },
Harald Welte82ccef72018-02-25 16:17:33 +0100374 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100375 dn_ind := false,
376 pwrc := false,
377 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100378 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100379 },
Harald Weltef10153f2018-02-25 16:34:05 +0100380 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100381 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200382 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100383 }
384 }
385}
Harald Welte70767382018-02-21 12:16:40 +0100386
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700387private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100388 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100389 payload := {
390 si2 := {
391 bcch_freq_list := '00000000000000000000000000000000'O,
392 ncc_permitted := '11111111'B,
393 rach_control := ts_RachCtrl_default
394 }
395 }
396}
397
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700398private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100399 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100400 payload := {
401 si4 := {
402 lai := ts_LAI_default,
403 cell_sel_par := ts_CellSelPar_default,
404 rach_control := ts_RachCtrl_default,
405 cbch_chan_desc := omit,
406 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200407 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100408 }
409 }
410}
411
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700412private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100413runs on test_CT {
414 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700415 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100416}
417
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700418private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100419runs on test_CT {
420 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
421 log("Setting ", rsl_si_type, ": ", si_dec);
422 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
423}
424
Harald Welte505cf9b2018-09-15 17:47:23 +0300425friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100426 map(self:BTSVTY, system:BTSVTY);
427 f_vty_set_prompts(BTSVTY);
428 f_vty_transceive(BTSVTY, "enable");
429}
430
Harald Welte505cf9b2018-09-15 17:47:23 +0300431friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200432 map(self:BSCVTY, system:BSCVTY);
433 f_vty_set_prompts(BSCVTY, "OsmoBSC");
434 f_vty_transceive(BSCVTY, "enable");
435}
436
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200437friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
438 map(self:BSCVTY, system:BSCVTY);
439 f_vty_set_prompts(BSCVTY, "OsmoBSC");
440 f_vty_transceive(BSCVTY, "enable");
441}
442
Harald Welte883340c2018-02-28 18:59:29 +0100443/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200444friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200445 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100446 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200447 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
448 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100449 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200450 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100452 }
453}
454
Harald Weltef26de0b2018-04-04 20:28:05 +0200455private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
456 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100457 timer T := 2.0;
458 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100459 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100461 return;
462 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200463 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100464
465 T.start;
466 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200467 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100468 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100470 }
471 }
472}
473
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700474private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
475 out integer trxc_conn_id) {
476 var Result res;
477
478 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
479 "", -1, -1, { udp := {} }, {});
480 if (not ispresent(res.connId)) {
481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
482 "Could not connect to the control (TRXC) interface " &
483 "of FakeTRX, check your configuration");
484 }
485 trxc_conn_id := res.connId;
486}
487
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100488/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700489friend function f_init(uint8_t trx_nr := 0)
490runs on test_CT
491{
492 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200493 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100494
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700495 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
496 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700497 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200498 g_AllChanTypes := {
499 /* TS 1..4: TCH/F */
500 valueof(ts_RslChanNr_Bm(1)),
501 /* TS 5: TCH/H */
502 valueof(ts_RslChanNr_Lm(5,1)),
503 /* TS 0: SDCCH/4 */
504 valueof(ts_RslChanNr_SDCCH4(0,2)),
505 /* TS 6: SDCCH/8 */
506 valueof(ts_RslChanNr_SDCCH8(6,4))
507 };
508 } else {
509 g_AllChanTypes := {
510 /* TS 1..4: TCH/F */
511 valueof(ts_RslChanNr_Bm(1)),
512 /* TS 0: SDCCH/4 */
513 valueof(ts_RslChanNr_SDCCH4(0,2)),
514 /* TS 6: SDCCH/8 */
515 valueof(ts_RslChanNr_SDCCH8(6,4))
516 };
517 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700518
519 g_AllChannels := { };
520
521 /* Generate list of all logical channels from module parameters */
522 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
523 select (trx_pars.ts[tn].config) {
524 case (GSM_PCHAN_CCCH_SDCCH4) {
525 g_AllChannels := g_AllChannels &
526 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
527 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
528 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
529 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
530 }
531 case (GSM_PCHAN_SDCCH8) {
532 g_AllChannels := g_AllChannels &
533 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
534 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
535 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
536 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
537 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
538 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
539 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
540 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
541 }
542 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
543 g_AllChannels := g_AllChannels &
544 { valueof(ts_RslChanNr_Lm(tn, 0)),
545 valueof(ts_RslChanNr_Lm(tn, 1)),
546 valueof(ts_RslChanNr_Bm(tn)) };
547 }
548 case (GSM_PCHAN_TCHH) {
549 g_AllChannels := g_AllChannels &
550 { valueof(ts_RslChanNr_Lm(tn, 0)),
551 valueof(ts_RslChanNr_Lm(tn, 1)) };
552 }
553 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
554 g_AllChannels := g_AllChannels &
555 { valueof(ts_RslChanNr_Bm(tn)) };
556 }
557 }
558 }
559
Harald Welte70767382018-02-21 12:16:40 +0100560 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100561 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100562 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100563 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100564
565 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100566 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
567 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
568 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
569 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100570
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700571 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100572 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700573
574 /* Init TRXC interface to FakeTRX */
575 map(self:BTS_TRXC, system:BTS_TRXC);
576 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
577
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700578 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700579 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 +0700580 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700581 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
582 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100583 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200584
585 /* Wait some extra time to make sure the BTS emits a stable carrier.
586 * (this is only relevant when running the tests with a physical BTS.) */
587 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100588}
589
Harald Welte68e495b2018-02-25 00:05:57 +0100590/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700591friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100592 map(self:L1CTL, system:L1CTL);
593 f_connect_reset(L1CTL);
594}
595
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200596friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100597
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700598private type record length(8) of FreqHopGroups FreqHopConfig;
599
600private type record of FreqHopGroup FreqHopGroups;
601private type record FreqHopGroup {
602 uint6_t hsn,
603 FreqHopGroupItems trx_maio
604};
605
606private type record of FreqHopGroupItem FreqHopGroupItems;
607private type record FreqHopGroupItem {
608 uint8_t trx_nr,
609 uint6_t maio
610};
611
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700612friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
613 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700614{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700615 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700616 var integer i, j;
617
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700618 fhp.enabled := false;
619
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700620 for (i := 0; i < lengthof(groups); i := i + 1) {
621 var FreqHopGroup g := groups[i];
622 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
623 var FreqHopGroupItem gi := g.trx_maio[j];
624 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700625 fhp.maio_hsn.maio := gi.maio;
626 fhp.maio_hsn.hsn := g.hsn;
627 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700628 break;
629 }
630 }
631
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700632 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700633 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700634 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
635 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
636 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700637
638 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700639 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
640 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700641 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700642 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700643 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700644 }
645
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700646 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700647 break; /* We're done */
648 }
649 }
650}
651
Harald Welte70767382018-02-21 12:16:40 +0100652/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700653friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
654 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200655 boolean trxc_comp := false,
656 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100657runs on test_CT return ConnHdlr {
658 var charstring id := testcasename();
659 var ConnHdlr vc_conn;
660
661 vc_conn := ConnHdlr.create(id);
662 /* connect to RSL Emulation main component */
663 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
664 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700665
666 /* The ConnHdlr component may want to talk to some ports directly,
667 * so we disconnect it from the test_CT and connect it to the component.
668 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200669 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200670 unmap(self:PCU, system:PCU);
671 map(vc_conn:PCU, system:PCU);
672 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700673 if (trxc_comp) {
674 unmap(self:BTS_TRXC, system:BTS_TRXC);
675 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
676 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200677 if (l1ctl) {
678 map(vc_conn:L1CTL, system:L1CTL);
679 }
Harald Welte70767382018-02-21 12:16:40 +0100680
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700681 /* Obtain frequency hopping parameters for a given timeslot */
682 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700683 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700684 }
685
Harald Welte70767382018-02-21 12:16:40 +0100686 vc_conn.start(f_handler_init(fn, id, pars));
687 return vc_conn;
688}
689
Harald Welte70767382018-02-21 12:16:40 +0100690private altstep as_Tguard() runs on ConnHdlr {
691 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100693 }
694}
695
Harald Welte990a3612019-05-27 14:02:13 +0200696friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700697 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700698 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100699}
700
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700701private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100702 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700703 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100704}
705
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700706private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100707 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700708 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100709}
710
711/* first function started in ConnHdlr component */
712private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
713runs on ConnHdlr {
714 g_pars := pars;
715 g_chan_nr := pars.chan_nr;
716
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200717 if (L1CTL.checkstate("Mapped")) {
718 f_connect_reset(L1CTL);
719 }
Harald Welte70767382018-02-21 12:16:40 +0100720
Harald Welted48c0c72019-06-05 10:01:15 +0200721 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700722 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100723 }
Harald Welte70767382018-02-21 12:16:40 +0100724
725 g_Tguard.start(pars.t_guard);
726 activate(as_Tguard());
727
728 f_rslem_register(0, pars.chan_nr);
729
730 /* call the user-supplied test case function */
731 fn.apply(id);
732}
733
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700734private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
735 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200736runs on ConnHdlr return RSL_Message {
737 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100738 timer T := 3.0;
739 RSL.send(tx);
740 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100741 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200742 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100743 T.stop;
744 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100745 }
Harald Welte1eba3742018-02-25 12:48:14 +0100746 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100748 }
Harald Welte21240e62018-03-11 21:43:35 +0100749 [not ignore_other] as_l1_sacch();
750 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700751 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700752 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100753 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100755 }
Harald Welte21240e62018-03-11 21:43:35 +0100756 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100757 }
Harald Welteb1726c92018-03-30 11:56:38 +0200758 return rx;
759}
760
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700761friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
762 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200763runs on ConnHdlr {
764 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100765}
766
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700767friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
768 boolean encr_enable := false,
769 RSL_IE_List more_ies := {},
770 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
771runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200772 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200773 if (encr_enable) {
774 /* append encryption related IEs, if requested */
775 var RSL_IE_EncryptionInfo encr_info;
776 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
777 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
778encr_info})) };
779 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200780 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200781 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100782}
783
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700784friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100785 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 +0100786 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100787}
788
Harald Welte2f2b2b72019-05-31 22:24:57 +0200789friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200790 template RSL_IE_ChannelMode chan_mode,
791 template (omit) TestSpecUnion spec := omit,
792 float t_guard := 20.0) := {
Harald Welte70767382018-02-21 12:16:40 +0100793 chan_nr := valueof(chan_nr),
794 chan_mode := valueof(chan_mode),
795 t_guard := t_guard,
796 l1_pars := {
797 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100798 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100799 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100800 meas_ul := {
801 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200802 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100803 rxqual := 0
804 },
805 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200806 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100807 rxqual := 0
808 }
809 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200810 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100811 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200812 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200813 ms_actual_ta := mp_ms_actual_ta_exp,
814 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100815 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200816 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200817 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700818 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700819 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700820 fhp := {
821 enabled := false,
822 maio_hsn := ts_HsnMaio(0, 0),
823 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700824 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700825 }
Harald Welte70767382018-02-21 12:16:40 +0100826}
827
Harald Welte93640c62018-02-25 16:59:33 +0100828/***********************************************************************
829 * Channel Activation / Deactivation
830 ***********************************************************************/
831
Harald Welte70767382018-02-21 12:16:40 +0100832/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700833private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100834 for (var integer i := 0; i < 500; i := i+1) {
835 f_rsl_chan_act(g_pars.chan_mode);
836 f_rsl_chan_deact();
837 }
838 setverdict(pass);
839}
840testcase TC_chan_act_stress() runs on test_CT {
841 var ConnHdlr vc_conn;
842 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200843 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100844 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
845 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100847}
848
849/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700850private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100851 f_rsl_chan_act(g_pars.chan_mode);
852 /* attempt to activate the same lchan again -> expect reject */
853 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
854 alt {
855 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100857 }
858 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
859 setverdict(pass);
860 }
861 }
862 f_rsl_chan_deact();
863}
864testcase TC_chan_act_react() runs on test_CT {
865 var ConnHdlr vc_conn;
866 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100867 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100868 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
869 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100871}
872
873/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700874private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100875 timer T := 3.0;
876 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
877 T.start;
878 alt {
879 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
880 setverdict(pass);
881 }
882 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100884 }
885 }
886}
887testcase TC_chan_deact_not_active() runs on test_CT {
888 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100889 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100890 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
891 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100893}
894
895/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700896private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100897 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
898 alt {
899 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100901 }
902 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
903 setverdict(pass);
904 }
905 }
906}
907private type record WrongChanNrCase {
908 RslChannelNr chan_nr,
909 charstring description
910}
911private type record of WrongChanNrCase WrongChanNrCases;
912private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
913 chan_nr := chan_nr,
914 description := desc
915}
916
917testcase TC_chan_act_wrong_nr() runs on test_CT {
918 var ConnHdlr vc_conn;
919 var ConnHdlrPars pars;
920
Harald Welte294b0a22018-03-10 23:26:48 +0100921 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100922
923 var WrongChanNrCases wrong := {
924 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
925 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
926 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
927 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
928 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
929 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
930 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
931 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
932 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
933 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
934 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
935 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
936 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
937 };
938
939 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
940 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
941 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
942 vc_conn.done;
943 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100945}
946
Harald Weltee613f962018-04-18 22:38:16 +0200947/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200948friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200949 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200950 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200951
952 /* test on each of the channels we have */
953 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
954 pars.chan_nr := valueof(g_AllChanTypes[i]);
955
956 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
957 vc_conn := f_start_handler(fn, pars);
958 vc_conn.done;
959 }
960
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200962}
963
Harald Welte93640c62018-02-25 16:59:33 +0100964/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100965 * SACCH handling
966 ***********************************************************************/
967
968private function f_exp_sacch(boolean exp) runs on ConnHdlr {
969 timer T_sacch := 3.0;
970 T_sacch.start;
971 alt {
972 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100974 }
975 [not exp] T_sacch.timeout {
976 setverdict(pass);
977 }
978 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
979 setverdict(pass);
980 }
981 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100983 }
984 [] L1CTL.receive { repeat; }
985 [] RSL.receive { repeat; }
986 }
987}
988
989/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
990private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
991 f_l1_tune(L1CTL);
992 RSL.clear;
993
994 /* activate the logical channel */
995 f_est_dchan();
996 L1CTL.clear;
997
998 /* check that SACCH actually are received as expected */
999 f_exp_sacch(true);
1000
1001 /* deactivate SACCH on the logical channel */
1002 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1003 f_sleep(1.0);
1004 L1CTL.clear;
1005
1006 /* check that no SACCH are received anymore */
1007 f_exp_sacch(false);
1008
1009 /* release the channel */
1010 f_rsl_chan_deact();
1011 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1012}
1013testcase TC_deact_sacch() runs on test_CT {
1014 var ConnHdlr vc_conn;
1015 var ConnHdlrPars pars;
1016 f_init();
1017 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1018 //for (var integer i := 0; i < 1; i := i+1) {
1019 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1020 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1021 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1022 vc_conn.done;
1023 }
1024 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001026}
1027
Harald Welte55700662018-03-12 13:15:43 +01001028/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001029private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1030 var L1ctlDlMessage dl;
1031 /* check that the specified SI5 value is actually sent */
1032 timer T_sacch := 3.0;
1033 L1CTL.clear;
1034 T_sacch.start;
1035 alt {
1036 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1037 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1038 if (match(l3, l3_exp)) {
1039 setverdict(pass);
1040 } else {
1041 repeat;
1042 }
1043 }
1044 [] L1CTL.receive { repeat; }
1045 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001047 }
1048 }
1049}
1050
Harald Welte55700662018-03-12 13:15:43 +01001051/* verify that given SACCH payload is not present */
1052private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1053 var L1ctlDlMessage dl;
1054 /* check that the specified SI5 value is actually sent */
1055 timer T_sacch := 3.0;
1056 L1CTL.clear;
1057 T_sacch.start;
1058 alt {
1059 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1060 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1061 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001063 } else {
1064 repeat;
1065 }
1066 }
1067 [] L1CTL.receive { repeat; }
1068 [] T_sacch.timeout {
1069 setverdict(pass);
1070 }
1071 }
1072}
1073
Harald Welte629cc6b2018-03-11 17:19:05 +01001074/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001075private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1076 /* Set a known default SACCH filling for SI5 */
1077 var octetstring si5 := f_rnd_octstring(19);
1078 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1079
1080 f_l1_tune(L1CTL);
1081 RSL.clear;
1082
1083 /* activate the logical channel */
1084 f_est_dchan();
1085
1086 /* check that the specified SI5 value is actually sent */
1087 f_sacch_present(si5);
1088
1089 /* release the channel */
1090 RSL.clear;
1091 f_rsl_chan_deact();
1092 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1093}
1094testcase TC_sacch_filling() runs on test_CT {
1095 var ConnHdlr vc_conn;
1096 var ConnHdlrPars pars;
1097 f_init();
1098 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1099 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1100 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1101 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1102 vc_conn.done;
1103 }
1104 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001106}
1107
Harald Welte629cc6b2018-03-11 17:19:05 +01001108/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001109private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1110 /* Set a known default SACCH filling for SI5 */
1111 var octetstring si5 := f_rnd_octstring(19);
1112 var octetstring si5_diff := f_rnd_octstring(19);
1113 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1114
1115 f_l1_tune(L1CTL);
1116 RSL.clear;
1117
1118 log("Activating channel, expecting standard SI5");
1119 /* activate the logical channel */
1120 f_est_dchan();
1121 /* check that the specified SI5 value is actually sent */
1122 f_sacch_present(si5);
1123
1124 /* set channel-specific different SI5 */
1125 log("Setting channel specific SACCH INFO, expecting it");
1126 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1127 /* check that the specified lchan-specific value is now used */
1128 f_sacch_present(si5_diff);
1129
1130 /* deactivate the channel and re-activate it, this should result in default SI5 */
1131 log("De-activating and re-activating channel, expecting standard SI5");
1132 f_rsl_chan_deact();
1133 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1134 /* Verify that the TRX-wide default SACCH filling is present again */
1135 f_sacch_present(si5);
1136
1137 /* release the channel */
1138 RSL.clear;
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_sacch_info_mod() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1148 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1149 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1150 vc_conn.done;
1151 }
1152 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001154}
1155
Harald Welte075d84c2018-03-12 13:07:24 +01001156/* Test SACCH scheduling of multiple different SI message types */
1157private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1158 var octetstring si5 := f_rnd_octstring(19);
1159 var octetstring si5bis := f_rnd_octstring(19);
1160 var octetstring si5ter := f_rnd_octstring(19);
1161 var octetstring si6 := f_rnd_octstring(19);
1162
1163 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1164 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1165 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1166 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1167
1168 f_l1_tune(L1CTL);
1169 RSL.clear;
1170
1171 /* activate the logical channel */
1172 f_est_dchan();
1173 L1CTL.clear;
1174
1175 /* check that SACCH actually are received as expected */
1176 f_sacch_present(si5);
1177 f_sacch_present(si5bis);
1178 f_sacch_present(si5ter);
1179 f_sacch_present(si6);
1180
1181 /* release the channel */
1182 f_rsl_chan_deact();
1183 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1184}
1185testcase TC_sacch_multi() runs on test_CT {
1186 var ConnHdlr vc_conn;
1187 var ConnHdlrPars pars;
1188 f_init();
1189 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1190 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1191 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1192 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1193 vc_conn.done;
1194 }
1195 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001197}
1198
Harald Welte55700662018-03-12 13:15:43 +01001199/* Test if SACH information is modified as expected */
1200private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1201 var octetstring si5 := f_rnd_octstring(19);
1202 var octetstring si6 := f_rnd_octstring(19);
1203
1204 /* First, configure both SI5 and SI6 to be transmitted */
1205 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1206 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1207
1208 f_l1_tune(L1CTL);
1209 RSL.clear;
1210
1211 /* activate the logical channel */
1212 f_est_dchan();
1213 L1CTL.clear;
1214
1215 /* check that SACCH actually are received as expected */
1216 f_sacch_present(si5);
1217 f_sacch_present(si6);
1218
1219 /* disable SI6 */
1220 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1221
1222 /* check that SI5 is still transmitted */
1223 f_sacch_present(si5);
1224 /* check if SI6 is now gone */
1225 f_sacch_missing(si6);
1226
1227 /* release the channel */
1228 f_rsl_chan_deact();
1229 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1230}
1231testcase TC_sacch_multi_chg() runs on test_CT {
1232 var ConnHdlr vc_conn;
1233 var ConnHdlrPars pars;
1234 f_init();
1235 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1236 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1237 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1238 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1239 vc_conn.done;
1240 }
1241 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001243}
1244
Harald Weltec8d363c2019-05-19 20:36:48 +02001245/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1246private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1247 var octetstring si5 := f_rnd_octstring(19);
1248 var octetstring si6 := f_rnd_octstring(19);
1249 var octetstring si5_specific := f_rnd_octstring(19);
1250 var octetstring si6_specific := f_rnd_octstring(19);
1251
1252 /* First, configure both SI5 and SI6 to be transmitted */
1253 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1254 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1255
1256 f_l1_tune(L1CTL);
1257 RSL.clear;
1258
1259 /* activate channel with different SACCH filling */
1260 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1261 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1262 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1263 }));
1264 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1265 RSL_IE_Body:{sacch_info := sacch_info})) };
1266 f_est_dchan(more_ies := addl_ies);
1267
1268 /* check that SACCH actually are received as expected */
1269 f_sacch_present(si5_specific);
1270 f_sacch_present(si6_specific);
1271
1272 /* release the channel */
1273 f_rsl_chan_deact();
1274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1275}
1276testcase TC_sacch_chan_act() runs on test_CT {
1277 var ConnHdlr vc_conn;
1278 var ConnHdlrPars pars;
1279 f_init();
1280
1281 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1282 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1283 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1284 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1285 vc_conn.done;
1286 }
1287 /* TODO: do the above in parallel, rather than sequentially? */
1288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1289}
1290
Harald Welte8b01c792019-05-19 22:51:25 +02001291/* verify that SACCH DL transmission is started only if MS power IE present
1292 * see section 4.1.3 of 3GPP TS 48.058 */
1293private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1294 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001295 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001296
1297 f_l1_tune(L1CTL);
1298 RSL.clear;
1299
1300 /* Step 1: Activate ASYNC HO channel without MS power IE */
1301
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001302 var integer ho_ref := oct2int(f_rnd_octstring(1));
1303 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1304 RSL_IE_Body:{ handover_ref := ho_ref }));
1305 var RSL_IE_List addl_ies := {
1306 ho_ref_ie
1307 };
1308
Harald Welte8b01c792019-05-19 22:51:25 +02001309 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001310 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001311 /* don't perform immediate assignment here, as we're testing non-IA case */
1312 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001313 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001314
1315 /* Verify that no DL SACCH is being received */
1316 f_sacch_missing(?);
1317
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001318 /* Send handover Access Burst and expect SACCH to start */
1319 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1320
1321 f_sacch_present(si5);
1322
Harald Welte8b01c792019-05-19 22:51:25 +02001323 f_rsl_chan_deact();
1324 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1325
1326
1327 /* Step 2: Activate ASYNC HO channel with MS power IE */
1328
1329 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001330 addl_ies := {
1331 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001332 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1333 };
1334 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1335 /* don't perform immediate assignment here, as we're testing non-IA case */
1336 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001337 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001338
1339 /* Verify that DL SACCH is being received */
1340 f_sacch_present(si5);
1341
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001342 /* Send handover Access Burst and expect SACCH to remain present */
1343 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1344
1345 f_sacch_present(si5);
1346
Harald Welte8b01c792019-05-19 22:51:25 +02001347 f_rsl_chan_deact();
1348 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1349}
1350testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1351 var ConnHdlr vc_conn;
1352 var ConnHdlrPars pars;
1353 f_init();
1354
1355 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1356 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1357 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1358 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1359 vc_conn.done;
1360 }
1361 /* TODO: do the above in parallel, rather than sequentially? */
1362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1363}
1364
1365/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1366 * see section 4.1.4 of 3GPP TS 48.058 */
1367private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1368 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001369 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1370
Harald Welte8b01c792019-05-19 22:51:25 +02001371 var RSL_IE_List addl_ies;
1372
1373 f_l1_tune(L1CTL);
1374 RSL.clear;
1375
1376 /* Step 1: Activate SYNC HO channel without MS power IE */
1377
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001378 var integer ho_ref := oct2int(f_rnd_octstring(1));
1379 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1380 RSL_IE_Body:{ handover_ref := ho_ref }));
1381 addl_ies := {
1382 ho_ref_ie
1383 };
1384
Harald Welte8b01c792019-05-19 22:51:25 +02001385 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001386 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001387 /* don't perform immediate assignment here, as we're testing non-IA case */
1388 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001389 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001390
1391 /* Verify that no DL SACCH is being received */
1392 f_sacch_missing(?);
1393
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001394 /* Send handover Access Burst and expect SACCH to start */
1395 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1396
1397 f_sacch_present(si5);
1398
Harald Welte8b01c792019-05-19 22:51:25 +02001399 f_rsl_chan_deact();
1400 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1401
1402
1403 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1404
1405 /* Activate channel on BTS side */
1406 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001407 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001408 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1409 };
1410 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1411 /* don't perform immediate assignment here, as we're testing non-IA case */
1412 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001413 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001414
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001415 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1416 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001417
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001418 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001419 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1420
1421 f_sacch_present(si5);
1422
Harald Welte8b01c792019-05-19 22:51:25 +02001423 f_rsl_chan_deact();
1424 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1425
1426
1427 /* Step 2b: Activate SYNC HO channel with TA IE */
1428
1429 /* Activate channel on BTS side */
1430 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001431 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001432 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1433 };
1434 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1435 /* don't perform immediate assignment here, as we're testing non-IA case */
1436 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001437 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001438
1439 /* Verify that no DL SACCH is being received */
1440 f_sacch_missing(?);
1441
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001442 /* Send handover Access Burst and expect SACCH to start */
1443 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1444
1445 f_sacch_present(si5);
1446
Harald Welte8b01c792019-05-19 22:51:25 +02001447 f_rsl_chan_deact();
1448 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1449
1450
1451 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1452
1453 /* Activate channel on BTS side */
1454 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001455 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001456 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1457 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1458 };
1459 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1460 /* don't perform immediate assignment here, as we're testing non-IA case */
1461 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001462 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001463
1464 /* Verify that DL SACCH is being received */
1465 f_sacch_present(si5);
1466
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001467 /* Send handover Access Burst and expect SACCH to remain present */
1468 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1469
1470 f_sacch_present(si5);
1471
Harald Welte8b01c792019-05-19 22:51:25 +02001472 f_rsl_chan_deact();
1473 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1474}
1475testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1476 var ConnHdlr vc_conn;
1477 var ConnHdlrPars pars;
1478 f_init();
1479
1480 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1481 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1482 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1483 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1484 vc_conn.done;
1485 }
1486 /* TODO: do the above in parallel, rather than sequentially? */
1487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1488}
Harald Welte629cc6b2018-03-11 17:19:05 +01001489
1490
1491/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001492 * RACH Handling
1493 ***********************************************************************/
1494
Harald Welte8c24c2b2018-02-26 08:31:31 +01001495/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001496private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001497 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001498 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001499 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001500
Harald Welte8c24c2b2018-02-26 08:31:31 +01001501 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001502 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001503 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001504 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001505 if (emerg == true) {
1506 ra := f_rnd_ra_emerg();
1507 } else {
1508 ra := f_rnd_ra_cs();
1509 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001510 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1511 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001513 }
1514 fn_last := fn;
1515
1516 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001517 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001518 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001519 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001520 T.stop;
1521 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001522 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001524 }
1525 [] RSL_CCHAN.receive { repeat; }
1526 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001527 test_failed := true;
1528 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001529 }
1530 }
1531 }
Maxba06feb2019-03-05 10:52:46 +01001532 if (test_failed) {
1533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001534 }
Maxba06feb2019-03-05 10:52:46 +01001535 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001537}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001538
Philipp Maier16ade782020-07-08 21:36:00 +02001539/* Normal variant */
1540testcase TC_rach_content() runs on test_CT {
1541 f_TC_rach_content(emerg := false);
1542}
1543
1544/* Emergency call variant */
1545testcase TC_rach_content_emerg() runs on test_CT {
1546 f_TC_rach_content(emerg := true);
1547}
1548
Harald Welte8c24c2b2018-02-26 08:31:31 +01001549/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1550testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001551 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001552 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001553 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001554 f_l1_tune(L1CTL);
1555
1556 var GsmFrameNumber fn_last := 0;
1557 for (var integer i := 0; i < 1000; i := i+1) {
1558 var OCT1 ra := f_rnd_ra_cs();
1559 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1560 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001562 }
1563 fn_last := fn;
1564 }
1565 var integer rsl_chrqd := 0;
1566 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001567 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001568 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001569 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001570 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001571 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001572 repeat;
1573 }
1574 [] RSL_CCHAN.receive { repeat; }
1575 [] T.timeout { }
1576 }
1577 if (rsl_chrqd == 1000) {
1578 setverdict(pass);
1579 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001581 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001583}
1584
Harald Welte3453ab42019-05-24 21:19:58 +02001585private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1586 var charstring bts_str := "bts " & int2str(bts_nr);
1587 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1588}
1589
1590/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1591private template integer tr_rach_slots_per_interval := (90 .. 130);
1592
1593/* Expect 0 RACH load on an idle BTS that has just started up */
1594testcase TC_rach_load_idle_thresh0() runs on test_CT {
1595 var ASP_RSL_Unitdata rx_ud;
1596
1597 f_init_vty_bsc();
1598 /* send load indications even at 0% load */
1599 f_vty_load_ind_thresh(0);
1600 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1601 f_sleep(2.0);
1602
1603 f_init();
1604
Harald Weltee37f9a52020-10-11 20:45:23 +02001605 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1606 alt {
1607 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1608 [] RSL_CCHAN.receive { repeat }
1609 }
1610
Harald Welte3453ab42019-05-24 21:19:58 +02001611 timer T := 5.0;
1612 T.start;
1613 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001614 [] 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 +02001615 setverdict(pass);
1616 repeat;
1617 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001618 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001619 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1620 repeat;
1621 }
1622 [] RSL_CCHAN.receive {
1623 repeat;
1624 }
1625 [] T.timeout { }
1626 }
1627
1628 f_vty_load_ind_thresh(10);
1629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1630}
1631
1632/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1633testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1634 var ASP_RSL_Unitdata rx_ud;
1635
1636 f_init_vty_bsc();
1637 f_init();
1638
1639 timer T := 5.0;
1640 T.start;
1641 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001642 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001643 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1644 repeat;
1645 }
1646 [] RSL_CCHAN.receive {
1647 repeat;
1648 }
1649 [] T.timeout {
1650 setverdict(pass);
1651 }
1652 }
1653
1654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1655}
1656
1657/* Expect 0 RACH load on an idle BTS that has just started up */
1658testcase TC_rach_load_count() runs on test_CT {
1659 var ASP_RSL_Unitdata rx_ud;
1660 var integer load_access_count := 0;
1661
1662 f_init_vty_bsc();
1663 /* send load indications even at 0% load */
1664 f_vty_load_ind_thresh(0);
1665 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1666 f_sleep(2.0);
1667 f_init();
1668
1669 f_init_l1ctl();
1670 f_sleep(1.0);
1671 f_l1_tune(L1CTL);
1672
Harald Welte52ae1682020-10-11 20:45:55 +02001673 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1674 alt {
1675 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1676 [] RSL_CCHAN.receive { repeat }
1677 }
1678
Harald Welte3453ab42019-05-24 21:19:58 +02001679 var GsmFrameNumber fn_last := 0;
1680 for (var integer i := 0; i < 1000; i := i+1) {
1681 var OCT1 ra := f_rnd_ra_cs();
1682 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1683 if (fn == fn_last) {
1684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1685 }
1686 fn_last := fn;
1687 }
1688
1689 timer T := 5.0;
1690 T.start;
1691 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001692 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001693 -> value rx_ud {
1694 var RSL_IE_Body ie;
1695 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1696 load_access_count := load_access_count + ie.rach_load.access_count;
1697 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1698 setverdict(fail, "Access count cannot be < Busy count");
1699 }
1700 repeat;
1701 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001702 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001703 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1704 repeat;
1705 }
1706 [] RSL_CCHAN.receive {
1707 repeat;
1708 }
1709 [] T.timeout { }
1710 }
1711 if (load_access_count == 1000) {
1712 setverdict(pass);
1713 } else {
1714 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1715 }
1716
1717 f_vty_load_ind_thresh(10);
1718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1719}
1720
Harald Welte54a2a2d2018-02-26 09:14:05 +01001721private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001722 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001723 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001724 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001725 f_sleep(0.5);
1726
1727 /* Transmit RACH request + wait for confirmation */
1728 var OCT1 ra := f_rnd_ra_cs();
1729 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1730
1731 /* Check for expected result */
1732 timer T := 1.5;
1733 T.start;
1734 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001735 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001736 setverdict(pass);
1737 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001738 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001740 }
1741 [] RSL_CCHAN.receive { repeat; }
1742 [not expect_pass] T.timeout {
1743 setverdict(pass);
1744 }
1745 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001747 }
1748 }
1749}
1750
1751/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1752testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001753 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001754 f_init_l1ctl();
1755 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001756 f_sleep(1.0);
1757
1758 /* default max-ta is 63 (full range of GSM timing advance */
1759
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001760 /* We allow early arrival up to 2 symbols */
1761 f_rach_toffs(-1*256, true);
1762 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001763 f_rach_toffs(-10*256, false);
1764
1765 /* 0 / 32 / 63 bits is legal / permitted */
1766 f_rach_toffs(0, true);
1767 f_rach_toffs(32*256, true);
1768 f_rach_toffs(63*256, true);
1769
1770 /* more than 63 bits is not legal / permitted */
1771 f_rach_toffs(64*256, false);
1772 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001774}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001775
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001776private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001777 var GsmFrameNumber fn;
1778 var RSL_Message rm;
1779
1780 f_l1_tune(L1CTL);
1781 RSL.clear;
1782
1783 /* Generate a random Handover Reference */
1784 var integer ho_ref := oct2int(f_rnd_octstring(1));
1785
1786 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1787 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1788 RSL_IE_Body:{ handover_ref := ho_ref }));
1789
1790 /* Activate a channel on the BTS side (no encryption) */
1791 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1792 act_type := t_RSL_IE_ActType_HO_SYNC);
1793
1794 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1795 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001796 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001797
1798 /* Send handover Access Burst */
1799 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1800
1801 /* TODO: test mismatching Handover Reference, and missing IE */
1802
1803 /* Wait for handover detection */
1804 timer T := 3.0;
1805 T.start;
1806 alt {
1807 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1808 log("Handover RACH has been detected: ", rm);
1809 setverdict(pass);
1810 }
1811 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1813 log2str("RSL_CHAN_RQD was not expected: ", rm));
1814 }
1815 [] RSL.receive { repeat; }
1816 [] T.timeout {
1817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1818 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1819 }
1820 }
1821
1822 /* Release the channel */
1823 f_rsl_chan_deact();
1824 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1825}
1826
1827/* Test handover RACH detection */
1828testcase TC_ho_rach() runs on test_CT {
1829 var ConnHdlrPars pars;
1830 var ConnHdlr vc_conn;
1831
1832 f_init();
1833
1834 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1835 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1836 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1837 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1838 vc_conn.done;
1839 }
1840
1841 /* TODO: do the above in parallel, rather than sequentially? */
1842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1843}
1844
Harald Welte93640c62018-02-25 16:59:33 +01001845/***********************************************************************
1846 * Measurement Processing / Reporting
1847 ***********************************************************************/
1848
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001849private template (value) LapdmAddressField
1850ts_LapdmAddr(template (value) LapdmSapi sapi,
1851 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001852 spare := '0'B,
1853 lpd := 0,
1854 sapi := sapi,
1855 c_r := c_r,
1856 ea := true
1857}
1858
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001859private template (value) LapdmFrameAB
1860ts_LAPDm_AB(template (value) LapdmSapi sapi,
1861 template (value) GsmRrL3Message l3,
1862 template (value) boolean c_r := false,
1863 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001864 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001865 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001866 len := 0, /* overwritten */
1867 m := false,
1868 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001869 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001870}
1871
1872/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001873private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001874 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001875 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001876
Harald Weltef8df4cb2018-03-10 15:15:08 +01001877 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001878 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001879
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001880 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001881 g_pars.l1_pars.meas_ul.full.rxlev,
1882 g_pars.l1_pars.meas_ul.sub.rxlev,
1883 g_pars.l1_pars.meas_ul.full.rxqual,
1884 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001885 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001886
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001887 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1888 g_pars.l1_pars.ms_power_level, false,
1889 g_pars.l1_pars.ms_actual_ta);
1890
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001891 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1892 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001893
1894 log("Sending Measurement Report: ", l1h, l2);
1895 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001896 repeat;
1897 }
1898}
1899
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001900/* handle incoming downlink SACCH, decode the L1 header into the given record */
1901private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1902 boolean do_apply := true)
1903runs on ConnHdlr
1904{
1905 var L1ctlDlMessage l1_dl;
1906
1907 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1908 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1909 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1910 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1911
1912 if (do_apply) {
1913 /* Update TA and MS power to follow what BTS requests */
1914 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1915 }
1916 }
1917}
1918
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001919private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001920 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001921 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001922 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1923 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001924 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1925 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001926 repeat;
1927 }
1928}
1929
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001930private altstep as_l1_tch_loop() runs on ConnHdlr {
1931 var L1ctlDlMessage l1_dl;
1932 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1933 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001934
1935 /* occasionaly inject FACCH frames into the uplink */
1936 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1937 var octetstring pl := '010301'O;
1938 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1939 f_pad_oct(pl, 23, '2B'O)));
1940 } else {
1941 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1942 l1_dl.payload.traffic_ind.data));
1943 }
1944
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001945 repeat;
1946 }
1947}
1948
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001949private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001950 uint6_t rxlev,
1951 uint3_t rxqual
1952}
1953
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001954private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001955 MeasElem full,
1956 MeasElem sub
1957}
1958
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001959private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001960 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001961 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001962 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001963 MeasElemFS meas_ul,
1964 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001965 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001966 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001967 uint8_t ms_actual_ta,
1968 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001969}
1970
1971/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1972private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1973 return 63 + (toffs256s/256);
1974}
1975
Harald Welted5684392018-03-10 18:22:04 +01001976private function f_max(integer a, integer b) return integer {
1977 if (a > b) {
1978 return a;
1979 } else {
1980 return b;
1981 }
1982}
1983
1984private function f_min(integer a, integer b) return integer {
1985 if (a < b) {
1986 return a;
1987 } else {
1988 return b;
1989 }
1990}
1991
1992/* compute negative tolerance val-tolerance, ensure >= min */
1993private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1994 val := val - tolerance;
1995 return f_max(val, min);
1996}
1997
1998/* compute positive tolerance val+tolerance, ensure <= max */
1999private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2000 val := val + tolerance;
2001 return f_min(val, max);
2002}
2003
2004/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2005private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2006return template integer {
2007 var template integer ret;
2008 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2009 return ret;
2010}
2011
2012
Harald Welte70767382018-02-21 12:16:40 +01002013/* build a template for matching measurement results against */
2014private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2015 var ConnL1Pars l1p := g_pars.l1_pars;
2016 var template RSL_IE_UplinkMeas ul_meas := {
2017 len := 3,
2018 rfu := '0'B,
2019 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002020 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002021 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002022 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002023 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002024 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2025 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002026 supp_meas_info := omit
2027 };
Harald Welte685d5982018-02-27 20:42:05 +01002028 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002029 ul_meas.len := (3+8);
2030 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002031 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002032 toa256_min := ?,
2033 toa256_max := ?,
2034 toa256_std_dev := ?
2035 }
Harald Welte685d5982018-02-27 20:42:05 +01002036 }
Harald Welte70767382018-02-21 12:16:40 +01002037 var template RSL_IE_BS_Power bs_power := {
2038 reserved := 0,
2039 epc := false,
2040 fpc := false,
2041 power_level := l1p.bs_power_level
2042 };
2043 var template RSL_IE_L1Info l1_info := {
2044 ms_power_lvl := l1p.ms_power_level,
2045 fpc := false,
2046 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002047 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002048 };
2049 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002050 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002051 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2052 ?, t_toffs);
2053}
2054
Philipp Maierdd841d32019-12-17 14:44:54 +01002055/* build a template for matching measurement results that do not contain any
2056 * MS related measurement (l1_info, l3_info and ms timing offset). */
2057private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2058 var ConnL1Pars l1p := g_pars.l1_pars;
2059 var template RSL_IE_UplinkMeas ul_meas := {
2060 len := 3,
2061 rfu := '0'B,
2062 dtx_d := l1p.dtx_enabled,
2063 rxlev_f_u := ?,
2064 reserved1 := '00'B,
2065 rxlev_s_u := ?,
2066 reserved2 := '00'B,
2067 rxq_f_u := ?,
2068 rxq_s_u := ?,
2069 supp_meas_info := omit
2070 };
2071 if (l1p.toa256_enabled) {
2072 ul_meas.len := (3+8);
2073 ul_meas.supp_meas_info := {
2074 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2075 toa256_min := ?,
2076 toa256_max := ?,
2077 toa256_std_dev := ?
2078 }
2079 }
2080 var template RSL_IE_BS_Power bs_power := {
2081 reserved := 0,
2082 epc := false,
2083 fpc := false,
2084 power_level := l1p.bs_power_level
2085 };
2086
2087 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2088}
2089
Harald Welte70767382018-02-21 12:16:40 +01002090/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002091private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002092 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002093 var boolean chan_est := false;
2094
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002095 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002096
2097 /* Receive osmocom specific measurement reports. This is the normal
2098 * case. Here we verify that the measurement reports we sent are
2099 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002100 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2101 /* increment counter of next to-be-expected meas rep */
2102 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2103 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002104 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002105
2106 /* The following two cases may only happen in the beginning
2107 * of the channel establishment phase. Once we have received
2108 * the "our" measurement report the first time, the channel
2109 * is established and empty or hardcoded TRXCON reports must
2110 * not occur anymore. */
2111 chan_est := true;
2112
2113 repeat;
2114 }
2115
2116 /* When the BTS has established the channel, the MS might need slightly
2117 * more time to establish the channel and actually start sending. The
2118 * result is then a measurement report that just lacks the measurement
2119 * information of the MS. This is normal and we tolerate this behavior. */
2120 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2121 /* increment counter of next to-be-expected meas rep */
2122 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2123 /* Re-start the timer expecting the next MEAS RES */
2124 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002125 repeat;
2126 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002127
2128 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2129 * measurements if the TTCN3 side does not supply measurement input in
2130 * time. In those cases TRXCON will either use a cached measurement
2131 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2132 * report the templates above will not match. We tolerate this
2133 * behavior, but only once. */
2134 [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 +01002135 /* increment counter of next to-be-expected meas rep */
2136 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2137 if (g_first_meas_res) {
2138 g_first_meas_res := false;
2139 repeat;
2140 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002142 }
Harald Welte70767382018-02-21 12:16:40 +01002143 }
2144 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002146 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002147 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002149 }
2150}
2151
Harald Weltee613f962018-04-18 22:38:16 +02002152private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2153 select (rsl_alg_id) {
2154 case (RSL_ALG_ID_A5_0) { return 0; }
2155 case (RSL_ALG_ID_A5_1) { return 1; }
2156 case (RSL_ALG_ID_A5_2) { return 2; }
2157 case (RSL_ALG_ID_A5_3) { return 3; }
2158 case (RSL_ALG_ID_A5_4) { return 4; }
2159 case (RSL_ALG_ID_A5_5) { return 5; }
2160 case (RSL_ALG_ID_A5_6) { return 6; }
2161 case (RSL_ALG_ID_A5_7) { return 7; }
2162 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2164 /* Make compiler happy by calling mtc.stop here. It is already
2165 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002166 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002167 }
2168 }
2169}
2170
2171private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2172 select (rsl_alg_id) {
2173 case (RSL_ALG_ID_A5_1) { return '000'B; }
2174 case (RSL_ALG_ID_A5_2) { return '001'B; }
2175 case (RSL_ALG_ID_A5_3) { return '010'B; }
2176 case (RSL_ALG_ID_A5_4) { return '011'B; }
2177 case (RSL_ALG_ID_A5_5) { return '100'B; }
2178 case (RSL_ALG_ID_A5_6) { return '101'B; }
2179 case (RSL_ALG_ID_A5_7) { return '110'B; }
2180 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2182 /* Make compiler happy by calling mtc.stop here. It is already
2183 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002184 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002185 }
2186 }
2187}
2188
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002189/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2190private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2191 var GsmFrameNumber fn;
2192 timer T := 8.0;
2193
2194 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2195 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2196
2197 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2198 /* Send the actual RACH */
2199 fn := f_L1CTL_RACH(L1CTL, ra);
2200
2201 T.start;
2202 alt {
2203 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2204 [] T.timeout {
2205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2206 }
2207 }
2208 T.stop
2209 return fn;
2210}
Harald Weltee613f962018-04-18 22:38:16 +02002211
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002212/* Tune to a dedicated channel: L1CTL only */
2213private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002214 if (not pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002215 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07002216 mp_trx_pars[0].arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002217 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002218 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002219 pars.fhp.maio_hsn.hsn,
2220 pars.fhp.maio_hsn.maio,
2221 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002222 }
2223}
2224
Harald Welte70767382018-02-21 12:16:40 +01002225/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002226private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002227 var GsmFrameNumber fn;
2228 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002229 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002230 var integer ra := 23;
2231
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002232 /* Send RACH request and wait for ChanReq */
2233 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002234
2235 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002236 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002237
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002238 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002239 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002240 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002241 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002242 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002243 }
2244
Harald Welte70767382018-02-21 12:16:40 +01002245 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002246 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002247 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2248
2249 /* receive IMM.ASS on MS side */
2250 var ImmediateAssignment ia_um;
2251 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002252
2253 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2254 if (ch_desc.h != ia_um.chan_desc.h) {
2255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2256 }
2257
Harald Welte70767382018-02-21 12:16:40 +01002258 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002259 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002260 /* enable encryption, if requested */
2261 if (encr_enable) {
2262 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2263 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2264 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002265
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002266 /* Send TCH Mode Request to the L1 if needed */
2267 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2268 var L1ctlTchMode tch_mode;
2269
2270 select (g_pars.chan_mode.coding_alg_rate) {
2271 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2272 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2273 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2274 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2275 case else {
2276 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2277 " is not supported by the L1, falling back to signalling");
2278 tch_mode := L1CTL_CHAN_MODE_SIGN;
2279 }
2280 }
2281
2282 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2283 }
2284
Harald Weltefa45e9e2018-03-10 18:59:03 +01002285 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002286}
2287
2288/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002289private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002290 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002291 RSL.clear;
2292
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002293 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002294 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002295 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002296 }
Harald Welte70767382018-02-21 12:16:40 +01002297
2298 f_est_dchan();
2299
2300 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2301 * RSL measurement reports on Abis side */
2302 timer T := 8.0;
2303 T.start;
2304 alt {
2305 [] as_l1_sacch();
2306 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002307 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002308 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002309 [] L1CTL.receive { repeat; }
2310 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002311 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002312 * of any earlier errors, so if we reach this timeout, we're good */
2313 setverdict(pass);
2314 }
2315 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002317 }
2318 }
2319 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002320 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002321}
Harald Welte0472ab42018-03-12 15:02:26 +01002322
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002323/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2324private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002325 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002326 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2327 timer Tup := 10.0;
2328 Tup.start;
2329 alt {
2330 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2331 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2332 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002333
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002334 if (rx_lvl != max_rx_lvl) {
2335 repeat;
2336 }
2337 Tup.stop;
2338 }
2339 [] L1CTL.receive { repeat; }
2340 [] Tup.timeout {
2341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2342 log2str("Didn't reach full power ", max_rx_lvl));
2343 }
2344 }
2345 return max_rx_lvl;
2346}
2347
2348/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2349private function f_verify_ramp_up() runs on ConnHdlr {
2350 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002351 var integer initial_rx_lvl := -1;
2352 var integer last_rx_lvl := -1;
2353 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2354
2355 timer T := 2.0;
2356 alt {
2357 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2358 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2359 log("Received rx_level=", rx_lvl);
2360 if (initial_rx_lvl == -1) {
2361 initial_rx_lvl := rx_lvl;
2362 last_rx_lvl := rx_lvl;
2363
2364 /* Expect a somehow low value during first received messages */
2365 if (initial_rx_lvl >= max_rx_lvl / 2) {
2366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2367 log2str("Detected high initial tx power during ramp up: ",
2368 initial_rx_lvl , ", full power is", max_rx_lvl));
2369 }
2370 }
2371
2372 /* received Rx level bigger than maximum allowed power by CN */
2373 if (rx_lvl > max_rx_lvl) {
2374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2375 log2str("Detected Tx power higher than full power: ",
2376 rx_lvl , " > ", max_rx_lvl));
2377 }
2378
2379 /* Make sure it never decreases, since we are rumping up */
2380 if (last_rx_lvl > rx_lvl) {
2381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2382 log2str("Detected Tx power decrease during ramp up: ",
2383 last_rx_lvl , " -> ", rx_lvl));
2384 }
2385
2386 if (rx_lvl == max_rx_lvl and not T.running) {
2387 /* We reached the maximum power, start timer and receive
2388 /* a few more to make sure we don't surpass it */
2389 log("Reached full power, wating a bit more until success");
2390 T.start;
2391 }
2392
2393 last_rx_lvl := rx_lvl;
2394 repeat;
2395 }
2396 [] L1CTL.receive { repeat; }
2397 [] T.timeout { }
2398 }
2399
2400 /* We didn't increase tx power during ramp up */
2401 if (initial_rx_lvl < last_rx_lvl) {
2402 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2403 } else {
2404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2405 log2str("No Tx power increase during whole ramp up: ",
2406 initial_rx_lvl , " -> ", last_rx_lvl));
2407 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002408}
2409
2410/* verify BTS ramps power down to rx_level 0 */
2411private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2412 var L1ctlDlMessage l1_dl;
2413 var integer last_rx_lvl := max_rx_lvl;
2414
2415 timer Tdown := 5.0;
2416 Tdown.start;
2417 alt {
2418 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2419 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2420 log("Received rx_level=", rx_lvl);
2421
2422 /* received Rx level bigger than maximum allowed power by CN */
2423 if (rx_lvl > max_rx_lvl) {
2424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2425 log2str("Detected Tx power higher than full power: ",
2426 rx_lvl , " > ", max_rx_lvl));
2427 }
2428
2429 /* Make sure it never increases, since we are rumping down */
2430 if (last_rx_lvl < rx_lvl) {
2431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2432 log2str("Detected Tx power increase during ramp up: ",
2433 last_rx_lvl , " -> ", rx_lvl));
2434 }
2435
2436 last_rx_lvl := rx_lvl;
2437 if (last_rx_lvl != 0) {
2438 repeat;
2439 }
2440 /* we reached power level 0, we are done */
2441 Tdown.stop;
2442 }
2443 [] L1CTL.receive { repeat; }
2444 [] Tdown.timeout { }
2445 }
2446
2447 /* We didn't increase tx power during ramp down */
2448 if (max_rx_lvl > last_rx_lvl) {
2449 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2450 } else {
2451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2452 log2str("No Tx power decrease during whole ramp down: ",
2453 max_rx_lvl , " -> ", last_rx_lvl));
2454 }
2455}
2456
2457/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002458private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002459 f_l1_tune(L1CTL);
2460 RSL.clear;
2461
2462 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002463
2464 setverdict(pass);
2465}
2466testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2467 var ConnHdlr vc_conn;
2468 var ConnHdlrPars pars;
2469 f_init();
2470 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2471 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2472 pcu_comp := false, trxc_comp := true);
2473 vc_conn.done;
2474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2475}
2476
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002477/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002478private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002479 f_connhdlr_init_vty_bsc();
2480
2481 f_l1_tune(L1CTL);
2482 RSL.clear;
2483
2484 /* Wait until BTS is started and at full power */
2485 var integer max_rx_lvl := f_wait_ramp_up();
2486 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2487
2488 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2489 f_verify_ramp_down(max_rx_lvl);
2490
2491 setverdict(pass);
2492}
2493testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2494 var ConnHdlr vc_conn;
2495 var ConnHdlrPars pars;
2496 f_init();
2497 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2498 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2499 pcu_comp := false, trxc_comp := true);
2500 vc_conn.done;
2501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2502}
2503
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002504/* Verify Tx power:
2505 * + ramping down during ADM state UNLOCKED->LOCKED
2506 * + ramping up during ADM state LOCKED->UNLOCKED
2507 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002508private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002509 var L1ctlDlMessage l1_dl;
2510 var integer last_rx_lvl;
2511
2512 f_connhdlr_init_vty_bsc();
2513
2514 f_l1_tune(L1CTL);
2515 RSL.clear;
2516
2517 /* Wait until BTS is started and at full power */
2518 var integer max_rx_lvl := f_wait_ramp_up();
2519 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2520
2521 log("ADM STATE UNLOCKED->LOCKED");
2522 f_vty_enter_cfg_trx(BSCVTY);
2523 f_vty_transceive(BSCVTY, "rf_locked 1");
2524 last_rx_lvl := max_rx_lvl;
2525 f_verify_ramp_down(max_rx_lvl);
2526
2527 /* Let some time after we received 0dBm, then check we don't receive BCCH
2528 * anymore because scheduler has stopped after ramping down */
2529 f_sleep(2.0);
2530 L1CTL.clear;
2531 timer Tlocked := 2.0;
2532 Tlocked.start;
2533 alt {
2534 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2536 log2str("Received data_ind during rf_locked: ", l1_dl));
2537 }
2538 [] L1CTL.receive { repeat; }
2539 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2540 }
2541
2542 log("ADM STATE LOCKED->UNLOCKED");
2543 f_vty_transceive(BSCVTY, "rf_locked 0");
2544 f_verify_ramp_up();
2545 setverdict(pass);
2546}
2547testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2548 var ConnHdlr vc_conn;
2549 var ConnHdlrPars pars;
2550 f_init();
2551 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2552 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2553 pcu_comp := false, trxc_comp := true);
2554 vc_conn.done;
2555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2556}
2557
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002558private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002559 timer T := 8.0;
2560 T.start;
2561 var RSL_Message rsl;
2562 alt {
2563 [] as_l1_sacch();
2564 [] L1CTL.receive { repeat; }
2565 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2566 if (rsl.ies[3].body.bs_power.power_level == level) {
2567 setverdict(pass)
2568 } else {
2569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2570 }
2571 }
2572 [] T.timeout {
2573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2574 }
2575 }
2576}
2577
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002578/* See if the RSL MEASurement RESult contains expeced BS power level
2579 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002580private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002581 f_l1_tune(L1CTL);
2582 RSL.clear;
2583
2584 if (mp_bts_trxc_port != -1) {
2585 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2586 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2587 }
2588
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002589 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002590 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2591 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2592
2593 f_est_dchan(more_ies :={valueof(pwr)});
2594
2595 f_check_meas_bs_power_level(pwr_var);
2596
2597 f_rsl_chan_deact();
2598 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2599}
2600
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002601/* See if the RSL MEASurement RESult contains expeced BS power level
2602 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002603private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002604 f_l1_tune(L1CTL);
2605 RSL.clear;
2606
2607 if (mp_bts_trxc_port != -1) {
2608 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2609 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2610 }
2611
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002612 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002613 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2614
2615 f_est_dchan();
2616
2617 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2618
2619 f_check_meas_bs_power_level(pwr_var);
2620
2621 f_rsl_chan_deact();
2622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2623}
2624
2625testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2626 var ConnHdlr vc_conn;
2627 var ConnHdlrPars pars;
2628 f_init();
2629 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2630 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2631 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2632 pcu_comp := false, trxc_comp := true);
2633 vc_conn.done;
2634 }
2635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2636}
2637
2638testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2639 var ConnHdlr vc_conn;
2640 var ConnHdlrPars pars;
2641 f_init();
2642 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2643 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2644 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2645 pcu_comp := false, trxc_comp := true);
2646 vc_conn.done;
2647 }
2648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2649}
2650
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002651/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2652 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2653 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002654private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002655 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002656 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002657
2658 f_trxc_fake_rssi(rxlev2dbm(10));
2659 f_l1_tune(L1CTL);
2660 RSL.clear;
2661
2662 var RSL_IE_List addl_ies;
2663 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2664
2665 addl_ies := {
2666 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2667 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2668 };
2669
2670 /* establish with power parameters */
2671 f_est_dchan(more_ies := addl_ies);
2672
2673 /* set a high value to ensure L1 power control level increases */
2674 f_trxc_fake_rssi(rxlev2dbm(20));
2675
2676 timer T2 := 6.0;
2677 T2.start;
2678 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002679 [] as_l1_sacch_l1h(l1h) {
2680 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002681 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002682 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002683 T2.stop;
2684 }
2685 [] L1CTL.receive { repeat; }
2686 [] T2.timeout {
2687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2688 "Power Level in L1 header has not increased sufficiently");
2689 }
2690 }
2691
2692 /* set a low value to ensure L1 power control level decreases */
2693 f_trxc_fake_rssi(rxlev2dbm(0));
2694
2695 timer T4 := 6.0;
2696 T4.start;
2697 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002698 [] as_l1_sacch_l1h(l1h) {
2699 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002700 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002701 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002702 T4.stop;
2703 setverdict(pass, "Power level in L1 decreased/increased as expected");
2704 }
2705 [] L1CTL.receive { repeat; }
2706 [] T4.timeout {
2707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2708 "Power Level in L1 header has not decreased sufficiently");
2709 }
2710 }
2711
2712 f_rsl_chan_deact();
2713 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2714
2715}
2716
2717/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002718private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002719 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002720 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002721
2722 /* set a low value to ensure power increases */
2723 f_trxc_fake_rssi(rxlev2dbm(10));
2724 f_l1_tune(L1CTL);
2725 RSL.clear;
2726
2727 var RSL_IE_List addl_ies;
2728 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2729
2730 addl_ies := {
2731 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2732 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2733 };
2734
2735 /* establish with power parameters */
2736 f_est_dchan(more_ies := addl_ies);
2737
2738 timer T1 := 10.0;
2739 T1.start;
2740 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002741 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002742 [] L1CTL.receive { repeat; }
2743 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002744 if (not isbound(l1h)) {
2745 setverdict(fail, "No SACCH blocks were received");
2746 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002747 setverdict(fail, "Power level in L1 header should not have changed");
2748 }
2749 }
2750 }
2751
2752 f_rsl_chan_deact();
2753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2754
2755}
2756
2757/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002758private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002759 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002760 var uint5_t pwr_var := 15;
2761 var uint5_t pwr_max_var := f_get_max_power_from_band();
2762
2763 /* set a low value to ensure power increases */
2764 f_trxc_fake_rssi(rxlev2dbm(10));
2765 f_l1_tune(L1CTL);
2766 RSL.clear;
2767
2768 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2769 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2770
2771 /* establish with fixed power level */
2772 f_est_dchan(more_ies :={valueof(pwr)});
2773
2774 /* check our initial power level */
2775 f_wait_for_l1_power_level(pwr_var);
2776
2777 /* update power param to enable power loop
2778 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2779 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2780
2781 /* wait, then check that our power level was reduced */
2782 timer T1 := 10.0;
2783 T1.start;
2784 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002785 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002786 [] L1CTL.receive { repeat; }
2787 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002788 if (not isbound(l1h)) {
2789 setverdict(fail, "No SACCH blocks were received");
2790 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002791 setverdict(pass, "Power level in L1 header reduced as expected");
2792 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002793 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2794 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002795 }
2796 }
2797 }
2798
2799 f_rsl_chan_deact();
2800 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2801
2802}
2803
2804/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002805private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002806 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002807
2808 /* set a high value to ensure power decreases */
2809 f_trxc_fake_rssi(rxlev2dbm(50));
2810 f_l1_tune(L1CTL);
2811 RSL.clear;
2812
2813 var uint5_t pwr_var := 5;
2814 var uint5_t pwr_target_val := 15;
2815
2816 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2817 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2818
2819 /* establish with fixed power level */
2820 f_est_dchan(more_ies :={valueof(pwr)});
2821
2822 /* check our initial power level */
2823 f_wait_for_l1_power_level(pwr_var);
2824
2825 /* update power param to enable power loop
2826 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002827 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002828
2829 /* wait, then check that our power level was increased */
2830 timer T1 := 10.0;
2831 T1.start;
2832 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002833 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002834 [] L1CTL.receive { repeat; }
2835 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002836 if (not isbound(l1h)) {
2837 setverdict(fail, "No SACCH blocks were received");
2838 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2839 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002840 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002841 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002842 }
2843 }
2844 }
2845
2846 f_rsl_chan_deact();
2847 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2848
2849}
2850
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002851/* See if the power level remains constant when MS Power Parameters IE
2852 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002853private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002854 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002855
2856 /* set a high value to ensure power decreases */
2857 f_trxc_fake_rssi(rxlev2dbm(50));
2858 f_l1_tune(L1CTL);
2859 RSL.clear;
2860
2861 var uint5_t pwr_var := 5;
2862
2863 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2864 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2865
2866 /* establish with fixed power level */
2867 f_est_dchan(more_ies :={valueof(pwr)});
2868
2869 /* check our initial power level */
2870 f_wait_for_l1_power_level(pwr_var);
2871
2872 /* wait, then check that our power level did not change */
2873 timer T1 := 10.0;
2874 T1.start;
2875 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002876 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2877 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2879 "BS power control should not be active unless we receive a power parameters IE!");
2880 }
2881 repeat;
2882 }
2883 [] L1CTL.receive { repeat; }
2884 [] T1.timeout { setverdict(pass); }
2885 }
2886
2887 f_rsl_chan_deact();
2888 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2889
2890}
2891
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002892/* See if the power level remains constant when MS Power Parameters IE
2893 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002894private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002895 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002896
2897 /* set a high value to ensure power decreases */
2898 f_trxc_fake_rssi(rxlev2dbm(50));
2899 f_l1_tune(L1CTL);
2900 RSL.clear;
2901
2902 var uint5_t pwr_var := 5;
2903
2904 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2905 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2906
2907 /* establish with fixed power level */
2908 f_est_dchan(more_ies :={valueof(pwr)});
2909
2910 /* check our initial power level */
2911 f_wait_for_l1_power_level(pwr_var);
2912
2913 /* pwr control without power params IE, should NOT activate MS power control*/
2914 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2915
2916 /* wait, then check that our power level did not change */
2917 timer T1 := 10.0;
2918 T1.start;
2919 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002920 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2921 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2923 "BS power control should not be active unless we receive a power parameters IE!");
2924 }
2925 repeat;
2926 }
2927 [] L1CTL.receive { repeat; }
2928 [] T1.timeout { setverdict(pass); }
2929 }
2930
2931 f_rsl_chan_deact();
2932 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2933
2934}
2935
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002936private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002937 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002938 timer T0 := 10.0;
2939 T0.start;
2940 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002941 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2942 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2944 "Power level in L1 header != signaled (RSL) power level.");
2945 }
2946 }
2947 [] L1CTL.receive { repeat; }
2948 [] T0.timeout {
2949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2950 "Timeout waiting for initial power level");
2951 }
2952 }
2953 T0.stop;
2954}
2955
2956private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2957 var IntegerRecord min_dbm_level;
2958 var IntegerRecord max_dbm_level;
2959 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2960
2961 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2962 if (min_dbm_level[i] == level) {
2963 return true;
2964 }
2965 }
2966 return false;
2967}
2968
2969private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2970 var IntegerRecord min_dbm_level;
2971 var IntegerRecord max_dbm_level;
2972 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2973
2974 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2975 if (max_dbm_level[i] == level) {
2976 return true;
2977 }
2978 }
2979 return false;
2980}
2981
2982private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2983 var IntegerRecord min_dbm_level;
2984 var IntegerRecord max_dbm_level;
2985 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2986 return max_dbm_level[0];
2987}
2988
2989type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002990private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002991private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2992 // 45.005 4.1.1
2993 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2994 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2995 2, 1, 0};
2996 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2997 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2998 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2999 var IntegerRecord rv;
3000
3001 select(band){
3002 case (BtsBand_allGSM){
3003 rv := gsm_power;
3004 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3005 max_dbm_level := {2, 1, 0};
3006 }
3007 case("DCS1800"){
3008 rv := dcs_power;
3009 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3010 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3011 }
3012 case("PCS1900"){
3013 rv := pcs_power;
3014 min_dbm_level := {15};
3015 max_dbm_level := {30};
3016 }
Harald Welte194b6912020-10-11 21:01:55 +02003017 case else {
3018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3019 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003020 }
3021
3022 return rv;
3023}
3024
3025private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003026 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of*type* in band (\w+),*", 0);
Eric Wild61edb7e2019-06-03 12:38:31 +02003027}
3028
3029testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3030 var ConnHdlr vc_conn;
3031 var ConnHdlrPars pars;
3032 f_init();
3033 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3034 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3035 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3036 pars.bts0_band := f_vty_get_bts0_band();
3037 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3038 vc_conn.done;
3039 }
3040 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3042}
3043
3044testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3045 var ConnHdlr vc_conn;
3046 var ConnHdlrPars pars;
3047 f_init();
3048 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3049 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3050 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3051 pars.bts0_band := f_vty_get_bts0_band();
3052 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3053 vc_conn.done;
3054 }
3055 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3057}
3058
3059testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3060 var ConnHdlr vc_conn;
3061 var ConnHdlrPars pars;
3062 f_init();
3063 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3064 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3065 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3066 pars.bts0_band := f_vty_get_bts0_band();
3067 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3068 vc_conn.done;
3069 }
3070 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3072}
3073
3074testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3075 var ConnHdlr vc_conn;
3076 var ConnHdlrPars pars;
3077 f_init();
3078 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3079 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3080 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3081 pars.bts0_band := f_vty_get_bts0_band();
3082 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3083 vc_conn.done;
3084 }
3085 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3087}
3088
Eric Wild280ccb82019-06-17 11:11:52 +02003089testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3090 var ConnHdlr vc_conn;
3091 var ConnHdlrPars pars;
3092 f_init();
3093 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3094 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3095 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3096 pars.bts0_band := f_vty_get_bts0_band();
3097 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3098 vc_conn.done;
3099 }
3100 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3102}
3103
Eric Wild095024b2019-06-17 15:08:57 +02003104testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3105 var ConnHdlr vc_conn;
3106 var ConnHdlrPars pars;
3107 f_init();
3108 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3109 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3110 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3111 pars.bts0_band := f_vty_get_bts0_band();
3112 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3113 vc_conn.done;
3114 }
3115 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3117}
3118
Philipp Maier149c3922020-10-22 17:29:36 +02003119function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003120 var template RSL_IE_ChannelMode ch_mode;
3121 var ConnHdlr vc_conn;
3122 var ConnHdlrPars pars;
3123 f_init();
3124 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3125 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3126 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003127 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003128 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3129 pcu_comp := false, trxc_comp := true);
3130 vc_conn.done;
3131 }
3132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3133}
Philipp Maier149c3922020-10-22 17:29:36 +02003134
3135testcase TC_meas_res_speech_tchf() runs on test_CT {
3136 f_TC_meas_res_speech_tchf(false);
3137}
3138
3139testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3140 f_TC_meas_res_speech_tchf(true);
3141}
3142
3143function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003144 var template RSL_IE_ChannelMode ch_mode;
3145 var ConnHdlr vc_conn;
3146 var ConnHdlrPars pars;
3147 f_init();
3148 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3149 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3150 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003151 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003152 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3153 pcu_comp := false, trxc_comp := true);
3154 vc_conn.done;
3155 }
3156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3157}
Philipp Maier149c3922020-10-22 17:29:36 +02003158
3159testcase TC_meas_res_speech_tchh() runs on test_CT {
3160 f_TC_meas_res_speech_tchh(false)
3161}
3162
3163testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3164 f_TC_meas_res_speech_tchh(true)
3165}
3166
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003167testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3168 var template RSL_IE_ChannelMode ch_mode;
3169 var ConnHdlr vc_conn;
3170 var ConnHdlrPars pars;
3171 f_init();
3172 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3173 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3174 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3175 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3176 pars.l1_pars.toa256_enabled := true;
3177 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3178 pcu_comp := false, trxc_comp := true);
3179 vc_conn.done;
3180 }
3181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3182}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003183
Harald Welte70767382018-02-21 12:16:40 +01003184testcase TC_meas_res_sign_tchf() runs on test_CT {
3185 var ConnHdlr vc_conn;
3186 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003187 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003188 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003189 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003190 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3191 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003192 vc_conn.done;
3193 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003195}
3196testcase TC_meas_res_sign_tchh() runs on test_CT {
3197 var ConnHdlr vc_conn;
3198 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003199 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003200 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003201 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003202 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3203 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003204 vc_conn.done;
3205 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003207}
3208testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3209 var ConnHdlr vc_conn;
3210 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003211 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003212 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3213 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003214 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3215 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003216 vc_conn.done;
3217 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003219}
3220testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3221 var ConnHdlr vc_conn;
3222 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003223 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003224 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3225 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003226 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3227 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003228 vc_conn.done;
3229 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003231}
Harald Welte685d5982018-02-27 20:42:05 +01003232testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3233 var ConnHdlr vc_conn;
3234 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003235 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003236 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3237 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003238 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003239 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003240 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3241 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003242 vc_conn.done;
3243 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003245}
3246
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003247/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3248 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003249private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003250 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003251 var RSL_IE_MS_Power ms_power;
3252 var RSL_Message rsl;
3253 var uint5_t power_level := 0;
3254
3255 f_l1_tune(L1CTL);
3256 RSL.clear;
3257
3258 f_est_dchan();
3259
3260 ms_power.reserved := 0;
3261 ms_power.fpc_epc := false;
3262
3263 /* Send the first power control command. This will disable any BTS/TRX
3264 * internal power control and switch the MS (which is not in scope of
3265 * this test) to a constant power level. We start with a power level
3266 * of 0 */
3267 ms_power.power_level := power_level;
3268 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3269 RSL.send(rsl);
3270
3271 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003272 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3273 if (l1h.ms_power_lvl != power_level) {
3274 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3275 "match the signaled (RSL) power level := ", power_level);
3276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003277 }
3278
3279 /* Signal a new power level via RSL for the next turn. */
3280 if (power_level < 31) {
3281 power_level := power_level + 1;
3282 ms_power.power_level := power_level;
3283 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3284 RSL.send(rsl);
3285 repeat;
3286 }
3287
3288 }
3289
3290 /* Ignore all other blocks */
3291 [] L1CTL.receive { repeat; }
3292
3293 }
3294
3295 f_rsl_chan_deact();
3296 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3297
3298 setverdict(pass);
3299}
3300
3301testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3302 var ConnHdlr vc_conn;
3303 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003304 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003305
3306 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3307 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3308 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3309 vc_conn.done;
3310 }
3311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3312}
Harald Welte70767382018-02-21 12:16:40 +01003313
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003314/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003315TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003316private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003317 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003318 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003319
3320 f_l1_tune(L1CTL);
3321 RSL.clear;
3322
3323 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003324 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003325
3326 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3327
3328
3329 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003330 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3331 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003332 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3333 }
3334
3335 }
3336
3337 /* Ignore all other blocks */
3338 [] L1CTL.receive { repeat; }
3339
3340 }
3341
3342 f_rsl_chan_deact();
3343 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3344
3345 setverdict(pass);
3346}
3347
3348testcase TC_rsl_chan_initial_ta() runs on test_CT {
3349 var ConnHdlr vc_conn;
3350 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003351 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003352 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003353 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3354 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003355 vc_conn.done;
3356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3357}
3358
Eric Wilde57e1a62019-05-28 13:30:55 +02003359/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003360private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003361 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003362 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003363
3364 var RSL_IE_MS_Power ms_power;
3365 ms_power.reserved := 0;
3366 ms_power.fpc_epc := false;
3367 ms_power.power_level := ms_power_level;
3368
3369 f_l1_tune(L1CTL);
3370 RSL.clear;
3371
3372 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3373
3374 timer T := 1.0;
3375 T.start;
3376 alt {
3377 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003378 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3379 if (l1h.ms_power_lvl != ms_power_level) {
3380 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3381 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003382 }
3383 }
3384 /* Ignore all other blocks */
3385 [] L1CTL.receive { repeat; }
3386 [] T.timeout {
3387 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3388 }
3389 }
3390
3391 f_rsl_chan_deact();
3392 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3393 setverdict(pass);
3394}
3395
3396testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3397 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3398 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3399}
3400
Harald Welte0472ab42018-03-12 15:02:26 +01003401/* 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 +01003402private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003403 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003404 RSL.clear;
3405
3406 f_est_dchan();
3407 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003408 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003409
3410 timer T := 40.0;
3411 T.start;
3412 alt {
3413 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3414 setverdict(pass)
3415 }
3416 [] RSL.receive { repeat };
3417 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003419 }
3420 }
3421 f_rsl_chan_deact();
3422}
3423testcase TC_conn_fail_crit() runs on test_CT {
3424 var ConnHdlr vc_conn;
3425 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003426 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003427 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3428 pars.t_guard := 60.0;
3429 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3430 vc_conn.done;
3431}
3432
Harald Welte93640c62018-02-25 16:59:33 +01003433/***********************************************************************
3434 * Paging
3435 ***********************************************************************/
3436
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003437private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003438 if (tmsi == 'FFFFFFFF'O) {
3439 return true;
3440 } else {
3441 return false;
3442 }
3443}
Harald Welte70767382018-02-21 12:16:40 +01003444
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003445private type record allowedFn { integer frame_nr }
3446private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3447private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3448private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3449private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3450private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3451private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3452private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3453private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3454private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003455{
3456 var integer frame_nr_51;
3457 frame_nr_51 := frame_nr mod 51
3458
3459 var allowedFn fn_check;
3460 fn_check.frame_nr := frame_nr_51;
3461
3462 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003464 return;
3465 }
3466
3467 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3468 return;
3469 }
3470 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3471 return;
3472 }
3473 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3474 return;
3475 }
3476 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3477 return;
3478 }
3479 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3480 return;
3481 }
3482 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3483 return;
3484 }
3485 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3486 return;
3487 }
3488 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3489 return;
3490 }
3491
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003493 return;
3494}
3495
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003496private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3497 inout integer num_paging_rcv_ids,
3498 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003499runs on test_CT {
3500 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003501 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003502 repeat;
3503 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003504 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003505 var octetstring without_plen :=
3506 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3507 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003508
3509 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3510
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003511 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3512 /* Ignore empty RR Paging Request (PCH filling) messages.
3513 * TODO: does it make sense to count them? */
3514 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003515 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3516 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003517 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003518 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3519 }
3520 } else if (match(rr, tr_PAGING_REQ2)) {
3521 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3522 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3523 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3524 }
3525 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3526 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3527 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003528 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003529 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3530 }
3531 } else if (match(rr, tr_PAGING_REQ3)) {
3532 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3533 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3534 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3535 }
3536 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3537 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3538 }
3539 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3540 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3541 }
3542 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3543 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3544 }
3545 }
3546 repeat;
3547 }
3548}
3549
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003550private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003551 boolean combined_ccch,
3552 integer bs_ag_blks_res,
3553 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003554 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3555 * paging command that is issued via RSL. */
3556 integer ps_load_modulus,
3557 /* Wait until the paging queue inside the BTS is congested before starting to add
3558 * pagings via the PCU socket (0 = disabled) */
3559 boolean ps_wait_cong,
3560 /* Maximum time to wait until the paging queue is drained at the end of the test.
3561 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3562 * to set this value to 18s, however the draining process may take significantly
3563 * longer when the queue contains paging requests for PS as those are implemented
3564 * as immediate assignments and require an entire MAC block alone. */
3565 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003566 boolean exp_load_ind,
3567 boolean exp_overload,
3568 boolean use_tmsi
3569}
3570
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003571private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003572 integer num_paging_sent,
3573 integer num_paging_rcv_msgs,
3574 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003575 integer num_overload,
3576 /* When free space inside the paging queue reaches more than 2 thirds
3577 * of its capacity cong_detected is set to true. */
3578 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003579}
3580
Harald Welte68e495b2018-02-25 00:05:57 +01003581/* Helper function for paging related testing */
3582private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003583 /* Using the PCU socket affects the timing of the paging processing. We only
3584 * activate the PCU socket if we do paging load tests that include additional
3585 * paging load that is introduced through the PCU socket. */
3586 if (cfg.ps_load_modulus > 0) {
3587 f_init_with_pcuif();
3588 } else {
3589 f_init();
3590 }
Harald Welte68e495b2018-02-25 00:05:57 +01003591 f_init_l1ctl();
3592 f_l1_tune(L1CTL);
3593
Philipp Maierca058272021-06-23 10:35:23 +02003594 var octetstring imm_ass := f_rnd_octstring(23);
3595 var ASP_RSL_Unitdata load_ind;
3596
Harald Welte68e495b2018-02-25 00:05:57 +01003597 var PagingTestState st := {
3598 num_paging_sent := 0,
3599 num_paging_rcv_msgs := 0,
3600 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003601 num_overload := 0,
3602 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003603 };
3604
3605 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3606 var float max_pch_imsi_per_sec;
3607 if (cfg.use_tmsi) {
3608 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3609 } else {
3610 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3611 }
3612 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3613 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003614 var float time_total := 20.0;
3615 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3616 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003617
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003618 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3619 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003620
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003621 timer T_itv := 0.0;
3622 T_itv.start;
3623 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003624 alt {
3625 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003626 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003627 st.num_overload := st.num_overload + 1;
3628 repeat;
3629 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003630 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003632 }
Philipp Maierca058272021-06-23 10:35:23 +02003633 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind {
Harald Welte68e495b2018-02-25 00:05:57 +01003634 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003635
3636 /* Detect paging congestion: The logic inside the BTS will diagnose the
3637 * paging queue as congested when the fill state is more than 66% (which
3638 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3639 * paging congestion is detected pagings that are issued through the PCU
3640 * socket (PS) are dropped in order to prefer the CS related pagings. */
3641 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3642 st.cong_detected := true;
3643 }
3644
Harald Welte68e495b2018-02-25 00:05:57 +01003645 /* FIXME: analyze/verify interval + contents */
3646 repeat;
3647 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003648 /* ignore other RSL messages like RF RESource INDication */
3649 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003650 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003651 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003652 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003653 /* Only relevant when testing including with PCU sock connected */
3654 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003655 [] T_itv.timeout {
3656 /* Send paging cmds based on elapsed time */
3657 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3658 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003659 var MobileIdentityV mi;
3660
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003661 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003662 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003663 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003664 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003665 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003666 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003667
3668 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003669 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 +02003670
Philipp Maierca058272021-06-23 10:35:23 +02003671 /* Add additional pagings through the PCU socket interface. */
3672 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3673 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3674 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3675 }
3676 }
3677
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003678 st.num_paging_sent := st.num_paging_sent + 1;
3679 }
3680 if (st.num_paging_sent < pkt_total) {
3681 /* Wait for interval to next PAGING COMMAND */
3682 var float time_now := T_total.read;
3683 var float next_sched := int2float(st.num_paging_sent)*interval;
3684 if (next_sched > time_now) {
3685 T_itv.start(next_sched - time_now);
3686 } else {
3687 T_itv.start(0.0);
3688 }
3689 } else {
3690 /* We are done, no need to keep counting */
3691 T_total.stop;
3692 }
3693 }
3694 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003695 }
3696 }
3697
Philipp Maierca058272021-06-23 10:35:23 +02003698 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003699 T_wait.start;
3700 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003701 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003702 [] L1CTL.receive { repeat; }
3703 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003704 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003705 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003706 /* ignore other RSL messages like RF RESource INDication */
3707 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003708 /* Only relevant when testing including with PCU sock connected */
3709 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003710 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Waiting for paging queue, last detected fill state: ", load_ind.rsl.ies[1].body.paging_load));
Harald Welte68e495b2018-02-25 00:05:57 +01003712 }
Harald Welte68e495b2018-02-25 00:05:57 +01003713 }
3714
3715 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3716 " rcvd_ids=", st.num_paging_rcv_ids);
3717 return st;
3718}
3719
3720/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3721 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3722 * - that CCCH LOAD IND (PCH) are being generated
3723 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3724testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003725 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003726 var PagingTestCfg cfg := {
3727 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003728 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003729 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003730 ps_load_modulus := 0,
3731 ps_wait_cong := false,
3732 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003733 exp_load_ind := true,
3734 exp_overload := false,
3735 use_tmsi := false
3736 };
3737 var PagingTestState st := f_TC_paging(cfg);
3738 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3740 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003741 } else {
3742 setverdict(pass);
3743 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003745}
3746
3747/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3748 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3749 * - that CCCH LOAD IND (PCH) are being generated
3750 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3751testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003752 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003753 var PagingTestCfg cfg := {
3754 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003755 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003756 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003757 ps_load_modulus := 0,
3758 ps_wait_cong := false,
3759 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003760 exp_load_ind := true,
3761 exp_overload := false,
3762 use_tmsi := true
3763 };
3764 var PagingTestState st := f_TC_paging(cfg);
3765 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3767 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003768 } else {
3769 setverdict(pass);
3770 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003772}
3773
3774/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3775 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3776 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3777 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3778testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003779 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003780 var PagingTestCfg cfg := {
3781 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003782 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003783 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003784 ps_load_modulus := 0,
3785 ps_wait_cong := false,
3786 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003787 exp_load_ind := true,
3788 exp_overload := true,
3789 use_tmsi := false
3790 };
3791 var PagingTestState st := f_TC_paging(cfg);
3792 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3793 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003794 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003795 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003796 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 +01003797 } else {
3798 setverdict(pass);
3799 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003801}
3802
3803/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3804 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3805 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3806 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3807testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003808 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003809 var PagingTestCfg cfg := {
3810 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003811 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003812 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003813 ps_load_modulus := 0,
3814 ps_wait_cong := false,
3815 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003816 exp_load_ind := true,
3817 exp_overload := true,
3818 use_tmsi := true
3819 };
3820 var PagingTestState st := f_TC_paging(cfg);
3821 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3822 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003823 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003824 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 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 +01003826 } else {
3827 setverdict(pass);
3828 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003830}
3831
Philipp Maierca058272021-06-23 10:35:23 +02003832/* Same as above, but with additional paging load created by PS pagings that
3833 * are issued through the PCU socket. The additional load is introduced when
3834 * the paging queue is already two thirds full. Since the BTS implements a
3835 * prioritization logic that drops the pagings from the PCU under in those
3836 * congestive sitautions the behaviour on the PS side is expected to be
3837 * unaffected and match the behavior of TC_paging_imsi_200percent() */
3838testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
3839 var SystemInformation si3 := valueof(ts_SI3_default);
3840 var PagingTestCfg cfg := {
3841 combined_ccch := true,
3842 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
3843 load_factor := 2.0,
3844 ps_load_modulus := 16,
3845 ps_wait_cong := true,
3846 queue_drain_timeout := 18.0,
3847 exp_load_ind := true,
3848 exp_overload := true,
3849 use_tmsi := false
3850 };
3851 var PagingTestState st := f_TC_paging(cfg);
3852 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3853 * slots and will fully drain that buffer before returning */
3854 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
3855 if (not match(st.num_paging_rcv_ids, tpl)) {
3856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
3857 } else {
3858 setverdict(pass);
3859 }
3860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3861}
3862
3863
Harald Welte68e495b2018-02-25 00:05:57 +01003864
Harald Welte93640c62018-02-25 16:59:33 +01003865/***********************************************************************
3866 * Immediate Assignment / AGCH
3867 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003868private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003869 len := 0,
3870 ma := ''B
3871}
Harald Welte93640c62018-02-25 16:59:33 +01003872
Harald Weltee8d750e2018-06-10 21:41:35 +02003873private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3874 return int2str(num_tx) & " sent, "
3875 & int2str(num_rx) & " received, "
3876 & int2str(num_del) & " deleted";
3877}
3878
3879private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3880 var L1ctlDlMessage l1_dl;
3881 timer T := 10.0;
3882 var integer num_tx := 0;
3883 var integer num_rx := 0;
3884 var integer num_del := 0;
3885 var charstring res_str;
3886 var float rx_ratio;
3887
Harald Welte10474062019-05-30 16:48:17 +02003888 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003889 f_init_l1ctl();
3890 f_l1_tune(L1CTL);
3891
3892 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07003893 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07003894 mp_trx_pars[0].arfcn,
3895 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02003896 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3897 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003898 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003899 num_tx := num_tx+1;
3900 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003901 }
3902 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003903 T.start;
3904 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003905 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003906 num_del := num_del+1;
3907 repeat;
3908 }
3909 [] RSL_CCHAN.receive {
3910 repeat;
3911 }
3912 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003913 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3914 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3915 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003916 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003917 } else {
3918 num_rx := num_rx+1;
3919 }
3920 repeat;
3921 }
3922 [] L1CTL.receive { repeat; }
3923 [] T.timeout { }
3924 }
3925 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3926 log("AGCH test: " & res_str);
3927 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003929 }
3930 rx_ratio := int2float(num_rx) / int2float(num_tx);
3931 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003932 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 +02003933 } else {
3934 setverdict(pass);
3935 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003937}
3938
Harald Weltee8d750e2018-06-10 21:41:35 +02003939/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3940testcase TC_imm_ass_1000_20ms() runs on test_CT {
3941 f_TC_imm_ass(1000, 0.02, 0.25);
3942}
3943
3944/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3945testcase TC_imm_ass_200_0ms() runs on test_CT {
3946 f_TC_imm_ass(200, 0.0, 0.05);
3947}
3948
3949/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3950testcase TC_imm_ass_200_76ms() runs on test_CT {
3951 f_TC_imm_ass(150, 0.076, 1.00);
3952}
3953
3954
3955
Harald Welte48494ca2018-02-25 16:59:50 +01003956/***********************************************************************
3957 * BCCH
3958 ***********************************************************************/
3959
3960/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003961private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003962 GsmFrameNumber frame_number,
3963 SystemInformation si
3964}
3965
3966/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003967private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003968
3969/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003970private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003971
3972/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003973private function f_si_vecslot_contains(SystemInformationVector arr,
3974 RrMessageType key,
3975 boolean bcch_ext := false)
3976return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003977 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3978 var integer fn_mod51 := arr[i].frame_number mod 51;
3979 if (not bcch_ext and fn_mod51 == 2 or
3980 bcch_ext and fn_mod51 == 6) {
3981 if (arr[i].si.header.message_type == key) {
3982 return true;
3983 }
3984 }
3985 }
3986 return false;
3987}
3988
3989/* 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 +07003990private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3991 integer tc, RrMessageType key,
3992 boolean ext_bcch := false)
3993{
Harald Welte48494ca2018-02-25 16:59:50 +01003994 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003996 }
3997}
3998
3999/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004000private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4001 RrMessageType key)
4002return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004003 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4004 if (f_si_vecslot_contains(arr[tc], key) or
4005 f_si_vecslot_contains(arr[tc], key, true)) {
4006 return true;
4007 }
4008 }
4009 return false;
4010}
4011
4012/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004013private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4014 RrMessageType key,
4015 boolean bcch_ext := false,
4016 integer n := 1, integer m := 4)
4017return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004018 var integer count := 0;
4019 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4021 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004022 }
4023 for (var integer i:= 0; i < m; i := i + 1) {
4024 var integer fn_mod51 := arr[i].frame_number mod 51;
4025 if (not bcch_ext and fn_mod51 == 2 or
4026 bcch_ext and fn_mod51 == 6) {
4027 if (arr[i].si.header.message_type == key) {
4028 count := count + 1;
4029 }
4030 }
4031 }
4032 if (count >= n) {
4033 return true;
4034 } else {
4035 return false;
4036 }
4037}
4038
4039/* 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 +07004040private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4041 integer tc, RrMessageType key,
4042 boolean ext_bcch := false,
4043 integer n, integer m)
4044{
Harald Welte48494ca2018-02-25 16:59:50 +01004045 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004047 }
4048}
4049
4050/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004051private function f_si_vecslot_contains_only(SystemInformationVector arr,
4052 RrMessageType key,
4053 boolean bcch_ext := false)
4054return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004055 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4056 var integer fn_mod51 := arr[i].frame_number mod 51;
4057 if (not bcch_ext and fn_mod51 == 2 or
4058 bcch_ext and fn_mod51 == 6) {
4059 if (arr[i].si.header.message_type != key) {
4060 return false;
4061 }
4062 }
4063 }
4064 return true;
4065}
4066
4067/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004068private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4069 integer tc, RrMessageType key,
4070 boolean ext_bcch := false)
4071{
Harald Welte48494ca2018-02-25 16:59:50 +01004072 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004074 }
4075}
4076
4077/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004078private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004079 boolean bcch_extended,
4080 boolean si1_present,
4081 boolean si2bis_present,
4082 boolean si2ter_present,
4083 boolean si2quater_present,
4084 boolean si7_present,
4085 boolean si8_present,
4086 boolean si9_present,
4087 boolean si13_present,
4088 boolean si13alt_present,
4089 boolean si15_present,
4090 boolean si16_present,
4091 boolean si17_present,
4092 boolean si2n_present,
4093 boolean si21_present,
4094 boolean si22_present
4095}
4096
4097/* 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 +07004098private function f_validate_si_scheduling(SystemInformationConfig cfg,
4099 SystemInformationVectorPerTc si_per_tc)
4100{
Harald Welte48494ca2018-02-25 16:59:50 +01004101 var integer i;
4102 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4103 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004105 }
4106 }
4107 if (cfg.si1_present) {
4108 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4109 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4110 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4111 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4112 /* make sure *ALL* contain SI1 */
4113 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4114 }
4115 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4116 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4117 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4118 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4119 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4120 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4121
4122 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4123 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4124 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4125 * consecutive occurrences of TC = 4. */
4126 if (cfg.si2bis_present and not cfg.si2ter_present) {
4127 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4128 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4129 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4130 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4131 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4132 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4133 }
4134
4135 if (cfg.si7_present or cfg.si8_present) {
4136 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4137 * if System Information type 4 does not contain all information needed for cell
4138 * selection and reselection. */
4139 if (not cfg.bcch_extended) {
4140 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4141 }
4142 if (cfg.si7_present) {
4143 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4144 }
4145 if (cfg.si8_present) {
4146 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4147 }
4148 }
4149
4150 if (cfg.si2quater_present) {
4151 /* iii) System information type 2 quater is sent if needed, as determined by the system
4152 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4153 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4154 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4155 * within any of 4 consecutive occurrences of TC = 5. */
4156 if (not (cfg.bcch_extended)) {
4157 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4158 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4159 } else {
4160 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4161 }
4162 } else {
4163 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4164 }
4165 }
4166 if (cfg.si9_present) {
4167 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4168 * in system information type 3 as defined in 3GPP TS 44.018. */
4169 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4170 }
4171 if (cfg.si13_present) {
4172 /* vii) System Information type 13 is only related to the GPRS service. System Information
4173 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4174 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4175 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4176 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4177 * within any of 4 consecutive occurrences of TC=4. */
4178 if (not cfg.bcch_extended) {
4179 log("not-bccch-extended");
4180 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4181 } else {
4182 log("bccch-extended");
4183 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4184 }
4185 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004187 }
4188 }
4189 if (cfg.si16_present or cfg.si17_present) {
4190 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4191 * should not be sent in a cell where network sharing is used (see rule xv). */
4192 if (cfg.si22_present) {
4193 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4194 }
4195 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004197 }
4198 if (not cfg.bcch_extended) {
4199 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4200 }
4201 if (cfg.si16_present) {
4202 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4203 }
4204 if (cfg.si17_present) {
4205 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4206 }
4207 }
4208
4209 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4210 * broadcast information. The frequency with which they are sent is determined by the
4211 * system operator. System Information type 9 identifies the scheduling of System
4212 * Information type 18 and 20 messages. */
4213
4214 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4215 * Information Type 19 is present, then its scheduling shall be indicated in System
4216 * Information Type 9. */
4217
4218 if (cfg.si15_present) {
4219 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4220 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4221 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4222 * 4 consecutive occurrences of TC = 1. */
4223 if (not cfg.bcch_extended) {
4224 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4225 } else {
4226 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4227 }
4228 }
4229 if (cfg.si13alt_present) {
4230 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4231 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4232 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4233 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4234 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4235 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4236 * of TC = 4. */
4237 if (cfg.si13_present) {
4238 testcase.stop("Error: Cannot have SI13alt and SI13");
4239 }
4240 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004242 }
4243 if (not cfg.bcch_extended) {
4244 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4245 } else {
4246 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4247 }
4248 }
4249 if (cfg.si2n_present) {
4250 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4251 * as determined by the system operator. In the case that the message is sent on the
4252 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4253 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4254 * consecutive occurrences of TC = 4. */
4255 if (not cfg.bcch_extended) {
4256 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4257 } else {
4258 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4259 }
4260 }
4261 if (cfg.si21_present) {
4262 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4263 * determined by the system operator. If Extended Access Barring is in use in the cell
4264 * then this message is sent at least once within any of 4 consecutive occurrences of
4265 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4266 * cell then this message shall only be sent on BCCH Ext. */
4267 if (not cfg.bcch_extended) {
4268 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4269 } else {
4270 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4271 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004273 }
4274 }
4275 }
4276 if (cfg.si22_present) {
4277 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4278 * should not be sent in a cell where SoLSA is used (see rule viii). System
4279 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4280 * =2 and TC=6. */
4281 if (cfg.si16_present or cfg.si17_present) {
4282 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4283 }
4284 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4285 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004287 }
4288 if (not cfg.bcch_extended) {
4289 testcase.stop("Error: SI22 requires BCCH Extd!");
4290 } else {
4291 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4292 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4293 }
4294 }
4295}
4296
4297/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004298private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4299return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004300 timer T := duration;
4301 var SystemInformationVectorPerTc si_per_tc;
4302 var L1ctlDlMessage l1_dl;
4303
4304 /* initialize all per-TC vectors empty */
4305 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4306 si_per_tc[i] := {};
4307 }
4308
4309 /* flush all previous L1 queued msgs */
4310 pt.clear;
4311
4312 T.start;
4313 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004314 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004315 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4316 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4317 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004318 repeat;
4319 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004320
Harald Welte48494ca2018-02-25 16:59:50 +01004321 var integer tc := f_gsm_compute_tc(sig.frame_number);
4322 log("SI received at TC=", tc, ": ", sig.si);
4323 /* append to the per-TC bucket */
4324 si_per_tc[tc] := si_per_tc[tc] & { sig };
4325 repeat;
4326 }
4327 [] pt.receive { repeat; }
4328 [] T.timeout { }
4329 }
4330
4331 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4332 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4333 }
4334 log("si_per_tc=", si_per_tc);
4335 return si_per_tc;
4336}
4337
4338/* helper function: Set given SI via RSL + validate scheduling.
4339 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004340private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004341 var SystemInformationVectorPerTc si_per_tc;
4342 f_init_l1ctl();
4343 f_l1_tune(L1CTL);
4344
4345 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004346 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004347 f_validate_si_scheduling(si_cfg, si_per_tc);
4348
4349 setverdict(pass);
4350}
4351
4352testcase TC_si_sched_default() runs on test_CT {
4353 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004354 /* 2+3+4 are mandatory and set in f_init() */
4355 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004357}
4358
4359testcase TC_si_sched_1() runs on test_CT {
4360 f_init();
4361 si_cfg.si1_present := true;
4362 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004363 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004365}
4366
4367testcase TC_si_sched_2bis() runs on test_CT {
4368 f_init();
4369 si_cfg.si2bis_present := true;
4370 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4371 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004373}
4374
4375testcase TC_si_sched_2ter() runs on test_CT {
4376 f_init();
4377 si_cfg.si2ter_present := true;
4378 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4379 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004381}
4382
4383testcase TC_si_sched_2ter_2bis() runs on test_CT {
4384 f_init();
4385 si_cfg.si2bis_present := true;
4386 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4387 si_cfg.si2ter_present := true;
4388 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4389 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004391}
4392
4393testcase TC_si_sched_2quater() runs on test_CT {
4394 f_init();
4395 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004396 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004397 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004399}
4400
4401testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004402 /* NOTE: PCUIF connection is not used in this test case, but
4403 * without it the IUT would not broadcast SI13 (see OS#3075). */
4404 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004405 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004406 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004407 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004409}
4410
4411testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004412 /* NOTE: PCUIF connection is not used in this test case, but
4413 * without it the IUT would not broadcast SI13 (see OS#3075). */
4414 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004415 si_cfg.si2bis_present := true;
4416 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4417 si_cfg.si2ter_present := true;
4418 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4419 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004420 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004421 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004422 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004423 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004425}
4426
4427
Harald Welte68e495b2018-02-25 00:05:57 +01004428testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004429 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004430 /* FIXME: enable / disable individual BCCH info */
4431 //ts_RSL_BCCH_INFO(si_type, info);
4432 /* expect no ERROR REPORT after either of them *
4433 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004435}
4436
Harald Welte93640c62018-02-25 16:59:33 +01004437/***********************************************************************
4438 * Low-Level Protocol Errors / ERROR REPORT
4439 ***********************************************************************/
4440
Harald Welte01d982c2018-02-25 01:31:40 +01004441private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4442 timer T := 5.0;
4443 T.start;
4444 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004445 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004446 setverdict(pass);
4447 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004448 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004450 }
4451 [] RSL_CCHAN.receive {
4452 repeat;
4453 }
4454 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004456 }
4457 }
4458}
4459
4460/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4461testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004462 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004463 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4464 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004465 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004466
4467 f_exp_err_rep(RSL_ERR_PROTO);
4468}
4469
4470/* Provoke a mandatory IE error and match on ERROR REPORT */
4471testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004472 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004473
4474 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4475 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004476 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004477
4478 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4479}
4480
4481/* Provoke an IE content error and match on ERROR REPORT */
4482testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004483 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004484 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4485 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004486 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004487
4488 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4489}
4490
Harald Welteee25aae2019-05-19 14:32:37 +02004491/* attempt to activate channel with wrong RSL Message Discriminator IE */
4492function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4493 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4494 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4495 RSL.send(rsl);
4496 f_rslem_unregister(0, g_chan_nr);
4497}
4498testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4499 var ConnHdlr vc_conn;
4500 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4501
Harald Welte10474062019-05-30 16:48:17 +02004502 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004503
4504 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4505 vc_conn.done;
4506 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4507
4508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4509}
4510
4511/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004512private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004513 var template (value) RSL_Message rsl_tx;
4514 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4515 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4516 RSL.send(rsl_tx);
4517 f_rslem_unregister(0, g_chan_nr);
4518}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004519private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004520 var template (value) RSL_Message rsl_tx;
4521 /* we first have to activate the dedicated channel */
4522 f_rsl_chan_act(g_pars.chan_mode);
4523 /* ... to then send an invalid RLL message */
4524 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4525 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4526 RSL.send(rsl_tx);
4527 f_rslem_unregister(0, g_chan_nr);
4528}
4529testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4530 var ConnHdlr vc_conn;
4531 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4532 var template (value) RSL_Message rsl_tx;
4533
Harald Welte10474062019-05-30 16:48:17 +02004534 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004535
4536 /* Common Channel with wrong message type */
4537 RSL_CCHAN.clear;
4538 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4539 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004540 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004541 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4542
4543 /* TRX Management */
4544 RSL_CCHAN.clear;
4545 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4546 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004547 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004548 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4549
4550 /* Dedicated Channel */
4551 RSL_CCHAN.clear;
4552 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4553 vc_conn.done;
4554 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4555
4556 /* RLL */
4557 RSL_CCHAN.clear;
4558 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4559 vc_conn.done;
4560 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4561}
4562
4563/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004564private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004565 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4566 f_rslem_unregister(0, g_chan_nr);
4567}
4568testcase TC_err_rep_wrong_sequence() runs on test_CT {
4569 var ConnHdlr vc_conn;
4570 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4571
Harald Welte10474062019-05-30 16:48:17 +02004572 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004573
4574 RSL_CCHAN.clear;
4575 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4576 vc_conn.done;
4577 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4578}
4579
Harald Welte93640c62018-02-25 16:59:33 +01004580/***********************************************************************
4581 * IPA CRCX/MDCX/DLCS media stream handling
4582 ***********************************************************************/
4583
Harald Weltea871a382018-02-25 02:03:14 +01004584/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004585private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004586 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4587 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004588}
4589testcase TC_ipa_dlcx_not_active() runs on test_CT {
4590 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004591 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004592 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4593 vc_conn.done;
4594}
Harald Welte68e495b2018-02-25 00:05:57 +01004595
Harald Weltea3f1df92018-02-25 12:49:55 +01004596/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004597private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004598 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4599 "IPA CRCX ACK");
4600 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4601 "IPA CRCX NACK");
4602}
4603testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4604 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004605 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004606 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4607 vc_conn.done;
4608}
4609
4610/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004611private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004612 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4613 "IPA CRCX ACK");
4614 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4615 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4616 var uint7_t rtp_pt2 := f_rnd_int(127);
4617 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4618 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4619 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4620 "IPA MDCX ACK");
4621 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4622 "IPA DLCX ACK");
4623}
4624testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4625 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004626 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004627 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4628 vc_conn.done;
4629}
4630
Harald Welte3ae11da2018-02-25 13:36:06 +01004631/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004632private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004633 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4634 "IPA CRCX ACK");
4635 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4636 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4637 var uint7_t rtp_pt2 := f_rnd_int(127);
4638 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4639 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4640 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4641 "IPA MDCX ACK");
4642 /* Second MDCX */
4643 remote_ip := f_rnd_int(c_UINT32_MAX);
4644 remote_port := f_rnd_int(c_UINT16_MAX);
4645 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4646 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4647 "IPA MDCX ACK");
4648 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4649 "IPA DLCX ACK");
4650}
4651testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4652 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004653 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004654 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4655 vc_conn.done;
4656}
4657
Harald Welte9912eb52018-02-25 13:30:15 +01004658/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004659private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004660 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4661 "IPA CRCX NACK");
4662}
4663testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4664 var ConnHdlrPars pars;
4665 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004666 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004667
4668 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4669 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4670 vc_conn.done;
4671
4672 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4673 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4674 vc_conn.done;
4675}
4676
Harald Weltea3f1df92018-02-25 12:49:55 +01004677
Harald Welte883340c2018-02-28 18:59:29 +01004678/***********************************************************************
4679 * PCU Socket related tests
4680 ***********************************************************************/
4681
Harald Welte07bd2d22019-05-25 11:03:30 +02004682/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004683friend 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 +01004684runs on test_CT {
4685 timer T := 3.0;
4686
4687 /* we don't expect any RTS.req before PDCH are active */
4688 T.start;
4689 alt {
4690 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004692 }
4693 [] PCU.receive { repeat; }
4694 [] T.timeout { }
4695 }
4696
4697 /* Send PDCH activate request for known PDCH timeslot */
4698 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4699
4700 /* we now expect RTS.req for this timeslot (only) */
4701 T.start;
4702 alt {
4703 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4704 setverdict(pass);
4705 }
4706 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4707 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004709 }
4710 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004712 }
4713 [] PCU.receive { repeat; }
4714 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004716 }
4717 [not exp_success] T.timeout {
4718 setverdict(pass);
4719 }
4720 }
4721}
4722
Harald Welte07bd2d22019-05-25 11:03:30 +02004723/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004724friend 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 +01004725runs on test_CT {
4726 timer T := 3.0;
4727
4728 /* Send PDCH activate request for known PDCH timeslot */
4729 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
Harald Weltec87d81f2020-10-11 18:17:25 +02004730 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4731 * when it will actually have been executed in the BTS */
4732 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004733 PCU.clear;
4734 /* we now expect no RTS.req for this timeslot */
4735 T.start;
4736 alt {
4737 [] 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 +02004738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004739 }
4740 [] PCU.receive { repeat; }
4741 [] T.timeout {
4742 setverdict(pass);
4743 }
4744 }
4745}
4746
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004747friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004748 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004749 map(self:PCU, system:PCU);
4750 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004751 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4752}
4753
Harald Welte883340c2018-02-28 18:59:29 +01004754/* PDCH activation via PCU socket; check for presence of RTS.req */
4755testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004756 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004757
Harald Welte883340c2018-02-28 18:59:29 +01004758 f_TC_pcu_act_req(0, 0, 7, true);
4759}
4760
4761/* PDCH activation via PCU socket on non-PDCU timeslot */
4762testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004763 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004764
Harald Welte883340c2018-02-28 18:59:29 +01004765 f_TC_pcu_act_req(0, 0, 1, false);
4766}
4767
4768/* PDCH activation via PCU socket on wrong BTS */
4769testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004770 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004771
Harald Welte883340c2018-02-28 18:59:29 +01004772 f_TC_pcu_act_req(23, 0, 7, false);
4773}
4774
4775/* PDCH activation via PCU socket on wrong TRX */
4776testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004777 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004778
Harald Welte883340c2018-02-28 18:59:29 +01004779 f_TC_pcu_act_req(0, 23, 7, false);
4780}
4781
4782/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4783testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004784 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004785
Harald Welte883340c2018-02-28 18:59:29 +01004786 /* Activate PDCH */
4787 f_TC_pcu_act_req(0, 0, 7, true);
4788 f_sleep(1.0);
4789 /* and De-Activate again */
4790 f_TC_pcu_deact_req(0, 0, 7);
4791}
4792
4793/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4794testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004795 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004796
Harald Welte883340c2018-02-28 18:59:29 +01004797 f_TC_pcu_deact_req(0, 0, 1);
4798}
4799
4800/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004801function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004802 var PCUIF_send_data sd;
4803 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004804 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004805
4806 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004807 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004808
Harald Welte883340c2018-02-28 18:59:29 +01004809 T.start;
4810 alt {
4811 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
Philipp Maier94c08482021-02-01 17:36:05 +01004812 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004813 setverdict(pass);
4814 } else {
4815 repeat;
4816 }
4817 }
4818 [] PCU.receive { repeat; }
4819 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004821 }
4822 }
4823}
4824
Philipp Maier94c08482021-02-01 17:36:05 +01004825/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4826testcase TC_pcu_ver_si1() runs on test_CT {
4827 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4828 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4829}
4830
4831/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4832testcase TC_pcu_ver_si3() runs on test_CT {
4833 const octetstring si3 := '49012223242526272929AABBCC'O;
4834 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4835}
4836
4837/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4838testcase TC_pcu_ver_si13() runs on test_CT {
4839 const octetstring si13 := '01010203040506070909'O;
4840 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4841}
4842
Harald Welte883340c2018-02-28 18:59:29 +01004843private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4844
4845/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004846friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004847 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4848runs on test_CT
4849{
4850 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4851 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4852}
4853
4854/* 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 +02004855friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4856 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004857runs on test_CT
4858{
4859 var PCUIF_send_data sd;
4860
4861 timer T := 3.0;
4862 T.start;
4863 alt {
4864 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4865 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4866 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4867 sd.data.u.rts_req.fn, sapi, data);
4868 }
4869 [] PCU.receive { repeat; }
4870 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004872 }
4873 }
4874}
4875
4876/* Send DATA.req on invalid BTS */
4877testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004878 var TfiUsfArr tua := f_TfiUsfArrInit();
4879 var octetstring data := '0000'O & f_rnd_octstring(21);
4880
4881 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004882
Harald Welte883340c2018-02-28 18:59:29 +01004883 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004884 f_TfiUsfArrSet(tua, 7, 0);
4885 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4886 f_sleep(1.0);
4887
4888 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004889}
4890
4891/* Send DATA.req on invalid TRX */
4892testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004893 var TfiUsfArr tua := f_TfiUsfArrInit();
4894 var octetstring data := '0000'O & f_rnd_octstring(21);
4895
4896 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004897
Harald Welte883340c2018-02-28 18:59:29 +01004898 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004899 f_TfiUsfArrSet(tua, 7, 0);
4900 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4901 f_sleep(1.0);
4902
4903 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004904}
4905
4906/* Send DATA.req on invalid timeslot */
4907testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004908 var TfiUsfArr tua := f_TfiUsfArrInit();
4909 var octetstring data := '0000'O & f_rnd_octstring(21);
4910
4911 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004912
Harald Welte883340c2018-02-28 18:59:29 +01004913 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004914 f_TfiUsfArrSet(tua, 7, 0);
4915 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4916 f_sleep(1.0);
4917
4918 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004919}
4920
4921/* Send DATA.req on timeslot that hasn't been activated */
4922testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004923 var TfiUsfArr tua := f_TfiUsfArrInit();
4924 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004925
Harald Welte7162a612019-05-26 12:56:09 +02004926 f_virtphy_common();
4927
4928 f_TfiUsfArrSet(tua, 7, 0);
4929 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4930 f_sleep(1.0);
4931
4932 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004933}
4934
Harald Weltead033dc2019-05-25 17:28:16 +02004935private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004936 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4937 boolean wait_rts := true)
4938runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004939 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004940 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004941
4942 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004943 if (wait_rts) {
4944 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4945 } else {
4946 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4947 }
Harald Weltead033dc2019-05-25 17:28:16 +02004948
4949 T.start;
4950 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004951 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004952 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4953 setverdict(pass);
4954 }
Harald Welte7162a612019-05-26 12:56:09 +02004955 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4956 setverdict(fail, "Received unexpected ", rx_dl);
4957 }
Harald Weltead033dc2019-05-25 17:28:16 +02004958 [] L1CTL.receive {
4959 repeat;
4960 }
Harald Welte7162a612019-05-26 12:56:09 +02004961 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004962 setverdict(fail, "Timeout waiting for ", data);
4963 }
Harald Welte7162a612019-05-26 12:56:09 +02004964 [not expect_data] T.timeout {
4965 setverdict(pass);
4966 }
Harald Weltead033dc2019-05-25 17:28:16 +02004967 }
4968}
4969
4970private function f_disable_dynamic_ts() runs on test_CT
4971{
4972 f_init_vty_bsc();
4973 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4974 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4975 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4976 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004977 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02004978}
4979
4980private function f_virtphy_common() runs on test_CT {
4981 f_disable_dynamic_ts();
4982 f_init_l1ctl();
4983 f_l1_tune(L1CTL);
4984}
4985
4986testcase TC_pcu_data_req_pdtch() runs on test_CT {
4987 var TfiUsfArr tua := f_TfiUsfArrInit();
4988 var octetstring data := '0000'O & f_rnd_octstring(21);
4989
4990 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004991
Harald Welte883340c2018-02-28 18:59:29 +01004992 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004993 f_TfiUsfArrSet(tua, 7, 0);
4994 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4995 f_sleep(1.0);
4996
4997 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004998}
4999
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005000/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005001testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005002 var TfiUsfArr tua := f_TfiUsfArrInit();
5003 var octetstring data := '0000'O & f_rnd_octstring(21);
5004
5005 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005006
Harald Welte883340c2018-02-28 18:59:29 +01005007 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005008 f_TfiUsfArrSet(tua, 7, 0);
5009 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5010 f_sleep(1.0);
5011
5012 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005013}
5014
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005015private function f_TC_pcu_ptcch_ul(uint16_t ra)
5016runs on test_CT {
5017 var template PCUIF_Message pcu_rach_ind;
5018 var PCUIF_send_data sd;
5019 var GsmFrameNumber fn;
5020 timer T;
5021
5022 /* Send an Access Burst on PTCCH/U over the Um-interface */
5023 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5024 chan_nr := ts_RslChanNr_PDCH(7),
5025 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5026
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005027 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5028 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005029
5030 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5031 T.start(52.0 * 4.615 / 1000.0);
5032 alt {
5033 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5034 log("Rx an Access Burst on the PCU interface: ", sd.data);
5035 setverdict(pass);
5036 T.stop;
5037 }
5038 [] PCU.receive { repeat; }
5039 [] T.timeout {
5040 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5041 /* Keep going, that's not the end of the world */
5042 }
5043 }
5044}
5045
5046testcase TC_pcu_ptcch() runs on test_CT {
5047 var L1ctlDlMessage dl;
5048 var octetstring data;
5049 timer T;
5050
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005051 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005052 f_init_l1ctl();
5053 f_l1_tune(L1CTL);
5054
5055 /* Activate PDCH channel on TS7 */
5056 f_TC_pcu_act_req(0, 0, 7, true);
5057
5058 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005059 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005060 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005061 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005062 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005063
5064 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5065 for (var integer i := 0; i < 16; i := i + 1) {
5066 log("Sending an Access Burst towards the L1CTL interface");
5067 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5068 }
5069
5070 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5071 data := f_rnd_octstring(23);
5072
5073 /* Verify PTCCH/D: send a random data block, make sure it's received */
5074 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5075 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5076
5077 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5078 * let's give it more time in case if we miss the beginning. */
5079 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5080 alt {
5081 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5082 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5083 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5084 frame := data)) -> value dl {
5085 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5086 setverdict(pass);
5087 T.stop;
5088 }
5089 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5090 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5091 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5092 l2_data := data)) -> value dl {
5093 log("Rx PTCCH/D data block on L1CTL: ", dl);
5094 setverdict(pass);
5095 T.stop;
5096 }
5097 [] L1CTL.receive { repeat; }
5098 [] T.timeout {
5099 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5100 }
5101 }
5102}
5103
Harald Welte883340c2018-02-28 18:59:29 +01005104/* Send AGCH from PCU; check it appears on Um side */
5105testcase TC_pcu_data_req_agch() runs on test_CT {
5106 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005107 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005108 f_init_l1ctl();
5109 f_l1_tune(L1CTL);
5110
5111 f_TC_pcu_act_req(0, 0, 7, true);
5112 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5113
5114 T.start;
5115 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005116 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005117 setverdict(pass);
5118 }
5119 [] L1CTL.receive { repeat; }
5120 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005122 }
5123 }
5124}
5125
Harald Welte928622b2019-05-26 13:22:59 +02005126/* Send AGCH from PCU; check it appears on Um side */
5127testcase TC_pcu_data_req_pch() runs on test_CT {
5128 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005129 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005130 f_init_l1ctl();
5131 f_l1_tune(L1CTL);
5132
5133 f_TC_pcu_act_req(0, 0, 7, true);
5134 /* three characters prefix: last 3 digits of IMSI as ASCII */
5135 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5136
5137 T.start;
5138 alt {
5139 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5140 setverdict(pass);
5141 }
5142 [] L1CTL.receive { repeat; }
5143 [] T.timeout {
5144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5145 }
5146 }
5147}
5148
Harald Welte883340c2018-02-28 18:59:29 +01005149/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5150testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5151 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005152 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005153 f_init_l1ctl();
5154 f_l1_tune(L1CTL);
5155
5156 /* append 3 last imsi digits so BTS can compute pagng group */
5157 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5158
5159 timer T := 0.5;
5160 T.start;
5161 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005162 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005163 /* TODO: verify paging group */
5164 setverdict(pass);
5165 }
5166 [] L1CTL.receive { repeat; }
5167 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005169 }
5170 }
5171}
5172
5173/* Send RACH from Um side, expect it to show up on PCU socket */
5174testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005175 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005176 f_init_l1ctl();
5177 f_l1_tune(L1CTL);
5178
5179 var GsmFrameNumber fn_last := 0;
5180 for (var integer i := 0; i < 1000; i := i+1) {
5181 var OCT1 ra := f_rnd_ra_ps();
5182 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5183 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005185 }
5186 fn_last := fn;
5187
5188 timer T := 2.0;
5189 T.start;
5190 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005191 [] 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 +01005192 T.stop;
5193 }
5194 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005196 }
5197 [] PCU.receive { repeat; }
5198 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005200 }
5201 }
5202 }
5203 setverdict(pass);
5204}
5205
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005206/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5207 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5208testcase TC_pcu_ext_rach_content() runs on test_CT {
5209 var template PCUIF_Message pcu_rach_ind;
5210 var GsmFrameNumber fn_last := 0;
5211 var L1ctlRachSynchSeq synch_seq;
5212 var PCUIF_BurstType pcu_bt;
5213 var GsmFrameNumber fn;
5214 var BIT11 ra11;
5215
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005216 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005217 f_init_l1ctl();
5218 f_l1_tune(L1CTL);
5219
5220 for (var integer i := 0; i < 1000; i := i+1) {
5221 /* We need to test both TS1 & TS2 */
5222 if (i rem 2 == 0) {
5223 synch_seq := RACH_SYNCH_SEQ_TS1;
5224 pcu_bt := BURST_TYPE_1;
5225 } else {
5226 synch_seq := RACH_SYNCH_SEQ_TS2;
5227 pcu_bt := BURST_TYPE_2;
5228 }
5229
5230 ra11 := f_rnd_ra11_ps();
5231 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5232 if (fn == fn_last) {
5233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5234 "Two RACH in same FN?!?");
5235 }
5236 fn_last := fn;
5237
5238 /* Compose the expected message */
5239 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005240 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005241 ra := bit2int(ra11),
5242 is_11bit := 1,
5243 burst_type := pcu_bt,
5244 fn := fn);
5245
5246 timer T := 2.0;
5247 T.start;
5248 alt {
5249 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5250 T.stop;
5251 }
5252 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5254 }
5255 [] PCU.receive { repeat; }
5256 [] T.timeout {
5257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5258 }
5259 }
5260 }
5261 setverdict(pass);
5262}
5263
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005264private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5265runs on test_CT {
5266 var template PCUIF_send_data sdt;
5267 var PCUIF_send_data sd;
5268 var int16_t lqual_cb;
5269 timer T := 1.0;
5270
5271 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5272 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5273
5274 /* Send a random PDTCH frame over Um */
5275 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5276 '0000'O & f_rnd_octstring(21)));
5277
5278 T.start;
5279 alt {
5280 /* If expected link quality is above the threshold */
5281 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5282 lqual_cb := sd.data.u.data_ind.lqual_cb;
5283 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5284
5285 /* Make sure the actual link quality matches the expected value */
5286 if (not match(lqual_cb, lqual_cb_exp)) {
5287 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5288 "expected value ", lqual_cb_exp));
5289 } else {
5290 setverdict(pass);
5291 }
5292 }
5293 /* If expected link quality is below the threshold */
5294 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5296 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5297 }
5298 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5299 [] PCU.receive { repeat; }
5300 [lqual_cb_exp < thresh] T.timeout {
5301 log("Rx nothing, as expected");
5302 setverdict(pass);
5303 }
5304 [lqual_cb_exp >= thresh] T.timeout {
5305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5306 "Timeout waiting for PCUIF_DATA.ind");
5307 }
5308 }
5309}
5310
5311/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5312testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005313 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005314 PCU.clear;
5315
5316 f_init_l1ctl();
5317 f_l1_tune(L1CTL);
5318
5319 /* Activate a PDCH channel on TS7 */
5320 f_TC_pcu_act_req(0, 0, 7, true);
5321
5322 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005323 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005324 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005325 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005326 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005327
5328 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5329 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5330 var TrxcMessage ret;
5331
5332 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5333 valueof(ts_TRXC_FAKE_CI(i)));
5334
5335 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5336 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5337 }
5338}
5339
Harald Welte883340c2018-02-28 18:59:29 +01005340/* Send PAGING via RSL, expect it to shw up on PCU socket */
5341testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005342 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005343
5344 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005345 var MobileIdentityLV mi_lv;
5346 var octetstring mi_lv_enc;
5347 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005348 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005349
Harald Welte883340c2018-02-28 18:59:29 +01005350 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005351 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005352 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005353 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005354 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005355
5356 /* Fancy encoding for PCUIF */
5357 mi_lv := valueof(ts_MI_LV(mi));
5358 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5359 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005360
5361 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005362 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005363 T.start;
5364 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005365 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005366 }
5367 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005369 }
5370 [] PCU.receive { repeat; }
5371 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005373 }
5374 }
5375 }
5376 setverdict(pass);
5377}
5378
Harald Welted66c9b82019-05-25 09:03:15 +02005379/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5380testcase TC_pcu_time_ind() runs on test_CT {
5381 var PCUIF_send_data pcu_sd;
5382 var integer num_time_ind := 0;
5383 var integer first_fn, last_fn;
5384 var float test_duration := 5.0;
5385 timer T;
5386
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005387 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005388 f_TC_pcu_act_req(0, 0, 7, true);
5389
5390 PCU.clear;
5391 T.start(test_duration);
5392 alt {
5393 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5394 num_time_ind := num_time_ind + 1;
5395 if (not isbound(first_fn)) {
5396 first_fn := pcu_sd.data.u.time_ind.fn;
5397 }
5398 last_fn := pcu_sd.data.u.time_ind.fn;
5399 repeat;
5400 }
5401 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5402 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5403 repeat;
5404 }
5405 [] PCU.receive {
5406 repeat;
5407 }
5408 [] T.timeout {}
5409 }
5410 var integer fn_expired := last_fn - first_fn;
5411 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5412
5413 /* verify the number of frames expired matches our expectation */
5414 const float c_GSM_FN_DURATION_MS := 4.61538;
5415 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005416 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005417 if (not match(fn_expired, t_fn_expected)) {
5418 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5419 }
5420
5421 /* There are three TIME.ind in every fn MOD 13 */
5422 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5423 /* Add some tolerance */
5424 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5425 if (not match(num_time_ind, t_time_ind_exp)) {
5426 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5427 }
5428
5429 setverdict(pass);
5430}
5431
Harald Welte4832c862019-05-25 14:57:18 +02005432/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5433testcase TC_pcu_rts_req() runs on test_CT {
5434 var PCUIF_send_data pcu_sd;
5435 var integer first_fn, last_fn;
5436 var integer num_rts_pdtch := 0;
5437 var integer num_rts_ptcch := 0;
5438 var float test_duration := 5.0;
5439 timer T;
5440
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005441 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005442 f_TC_pcu_act_req(0, 0, 7, true);
5443
5444 PCU.clear;
5445 T.start(test_duration);
5446 alt {
5447 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5448 -> value pcu_sd {
5449 num_rts_pdtch := num_rts_pdtch + 1;
5450 if (not isbound(first_fn)) {
5451 first_fn := pcu_sd.data.u.rts_req.fn;
5452 }
5453 last_fn := pcu_sd.data.u.rts_req.fn;
5454 repeat;
5455 }
5456 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5457 -> value pcu_sd {
5458 num_rts_ptcch := num_rts_ptcch + 1;
5459 if (not isbound(first_fn)) {
5460 first_fn := pcu_sd.data.u.rts_req.fn;
5461 }
5462 last_fn := pcu_sd.data.u.rts_req.fn;
5463 repeat;
5464 }
5465 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5466 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5467 repeat;
5468 }
5469 [] PCU.receive {
5470 repeat;
5471 }
5472 [] T.timeout {}
5473 }
5474 var integer fn_expired := last_fn - first_fn;
5475 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5476 ", num_rts_ptcch=", num_rts_ptcch);
5477
5478 /* verify the number of frames expired matches our expectation */
5479 const float c_GSM_FN_DURATION_MS := 4.61538;
5480 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005481 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005482 if (not match(fn_expired, t_fn_expected)) {
5483 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5484 }
5485
5486 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5487 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5488 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5489 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5490 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5491 t_ptcch_exp);
5492 }
5493
5494 /* We have 12 PDTCH blocks every 52-multiframe */
5495 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5496 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5497 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5498 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5499 t_pdtch_exp);
5500 }
5501
5502 setverdict(pass);
5503}
5504
Harald Welte07bd2d22019-05-25 11:03:30 +02005505/* test for generating Abis side OML ALERT from the PCU */
5506testcase TC_pcu_oml_alert() runs on test_CT {
5507 var PCUIF_send_data pcu_sd;
5508 var integer num_time_ind := 0;
5509 var integer first_fn, last_fn;
5510 var float test_duration := 5.0;
5511 timer T;
5512
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005513 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005514 f_TC_pcu_act_req(0, 0, 7, true);
5515
5516 /* re-connect CTRL port from BTS to BSC */
5517 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005518 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005519
5520 /* Send that OML Alert */
5521 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5522
5523 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5524 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5525 setverdict(pass);
5526}
5527
Harald Welteeaa9a862019-05-26 23:01:08 +02005528/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5529private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5530 var PCUIF_Message first_info;
5531 var integer pcu_conn_id := -1;
5532 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5533 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5534 var OCT4 tlli := '01020304'O;
5535 var OCT1 cause := '23'O;
5536 timer T := 5.0;
5537
5538 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5539
5540 f_l1_tune(L1CTL);
5541 RSL.clear;
5542
5543 f_est_dchan();
5544 L1CTL.clear;
5545
5546 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5547
5548 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5549 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5550 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5551
5552 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5553 T.start;
5554 alt {
5555 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5556 setverdict(pass);
5557 }
5558 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5559 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5560 }
5561 [] PCU.receive {
5562 repeat;
5563 }
5564 [] T.timeout {
5565 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5566 }
5567 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005568
5569 /* release the channel */
5570 f_rsl_chan_deact();
5571 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5572 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005573}
5574testcase TC_pcu_rr_suspend() runs on test_CT {
5575 var ConnHdlrPars pars;
5576 var ConnHdlr vc_conn;
5577
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005578 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005579
5580 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5581 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5582 vc_conn.done;
5583}
Harald Welte07bd2d22019-05-25 11:03:30 +02005584
Harald Weltea2e0e942019-05-27 18:12:53 +02005585/* Ensure that PCUIF socket can accept only a single connection */
5586testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005587 var boolean connected := false;
5588 var UD_connect_result cr;
5589 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005590 timer T := 5.0;
5591
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005592 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5593 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5594
Harald Weltea2e0e942019-05-27 18:12:53 +02005595 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005596 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005597
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005598 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005599 PCU.send(UD_connect:{mp_pcu_socket, -1});
5600 T.start;
5601 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005602 /* the IUT will first accept() the new connection, and close() it immediately */
5603 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5604 log("BTS has accept()ed connection");
5605 connected := true;
5606 cid := cr.id;
5607 repeat;
5608 }
5609 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5610 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005611 setverdict(pass);
5612 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005613 /* ignore other messages related to the first connection */
5614 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005615 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005616 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005617 }
5618 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005619
Harald Weltea2e0e942019-05-27 18:12:53 +02005620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5621}
5622
Harald Weltec8effb72019-05-27 18:23:04 +02005623/* Ensure that PCUIF socket can disconnect + reconnect */
5624testcase TC_pcu_socket_reconnect() runs on test_CT {
5625 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005626 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005627
5628 f_sleep(1.0);
5629
5630 f_pcuif_close(PCU, g_pcu_conn_id);
5631 g_pcu_conn_id := -1;
5632
5633 f_sleep(1.0);
5634
5635 /* re-connect */
5636 PCU.clear;
5637 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5638 setverdict(pass);
5639
5640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5641}
5642
Harald Weltebe030482019-05-27 22:29:35 +02005643/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005644private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5645runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005646 var L1ctlDlMessage l1_dl;
5647 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005648 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005649 timer T := 5.0;
5650 T.start;
5651 alt {
5652 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005653 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5654 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005655 repeat;
5656 }
5657 }
5658 [] pt.receive {
5659 repeat;
5660 }
5661 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5663 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005664 }
5665 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005666 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005667}
5668
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005669/* Check if GPRS Indicator is present in RR System Information of a given type */
5670private function f_si_has_gprs_indicator(RrMessageType si_type)
5671runs on test_CT return boolean {
5672 var SystemInformation si := f_get_si(L1CTL, si_type);
5673
5674 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005675 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005676 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005677 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005678 }
5679
5680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5681 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005682}
5683
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005684/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5685private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5686runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005687 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005688 f_init_l1ctl();
5689 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005690 f_sleep(2.0);
5691 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005692
5693 if (f_si_has_gprs_indicator(si_type)) {
5694 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005695 } else {
5696 setverdict(pass);
5697 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005698
Harald Weltebe030482019-05-27 22:29:35 +02005699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5700}
5701
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005702testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5703 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5704}
Harald Weltebe030482019-05-27 22:29:35 +02005705
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005706testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5707 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5708}
5709
5710/* Ensure that GPRS capability is advertised after PCU socket connect */
5711private function f_TC_pcu_socket_connect(RrMessageType si_type)
5712runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005713 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005714 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005715 f_init_l1ctl();
5716 f_l1_tune(L1CTL);
5717
5718 f_sleep(2.0);
5719 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005720
5721 if (not f_si_has_gprs_indicator(si_type)) {
5722 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005723 } else {
5724 setverdict(pass);
5725 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005726
Harald Weltebe030482019-05-27 22:29:35 +02005727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5728}
5729
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005730testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5731 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5732}
Harald Weltebe030482019-05-27 22:29:35 +02005733
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005734testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5735 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5736}
5737
5738/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5739private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5740runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005741 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005742 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005743 f_init_l1ctl();
5744 f_l1_tune(L1CTL);
5745
5746 f_pcuif_close(PCU, g_pcu_conn_id);
5747 g_pcu_conn_id := -1;
5748
5749 f_sleep(1.0);
5750
5751 /* re-connect */
5752 PCU.clear;
5753 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5754
5755 f_sleep(2.0);
5756 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005757
5758 if (f_si_has_gprs_indicator(si_type)) {
5759 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005760 } else {
5761 setverdict(pass);
5762 }
5763
5764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5765}
5766
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005767testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5768 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5769}
5770
5771testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5772 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5773}
5774
Oliver Smithf5239c72019-08-28 10:01:25 +02005775/* 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) */
5776testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5777 var SystemInformation si3 := valueof(ts_SI3_default);
5778
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005779 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005780
Harald Welte76220222020-10-11 20:32:44 +02005781 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5782 * information */
5783 timer T := 2.0;
5784 T.start;
5785 alt {
5786 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5787 [] T.timeout {}
5788 }
5789
Oliver Smithf5239c72019-08-28 10:01:25 +02005790 /* Verify cell_id */
5791 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5792 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5793 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005794 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5795 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5796 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005797 }
5798
5799 /* Verify LAC */
5800 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5801 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5802 if (lac_si3 != lac_pcu) {
5803 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5804 }
5805
5806 setverdict(pass);
5807}
Harald Welted66c9b82019-05-25 09:03:15 +02005808
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005809/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5810testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5811 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005812 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005813
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005814 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005815
5816 info_ind := g_pcu_last_info.u.info_ind;
5817
5818 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5819 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005820 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005821 /* Skip inactive timeslots */
5822 continue;
5823 }
5824
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005825 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005826 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005827 else
5828 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005829
5830 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005831 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005832 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005833 hsn := fhp.maio_hsn.hsn,
5834 maio := fhp.maio_hsn.maio,
5835 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005836 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005837 } else {
5838 tr_ts := tr_PCUIF_InfoTrxTsH0;
5839 }
5840
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005841 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005842 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5843 if (not match(ts, tr_ts)) {
5844 setverdict(fail, "Hopping parameters do not match: ",
5845 "received ", ts, " vs expected ", tr_ts);
5846 } else {
5847 setverdict(pass);
5848 }
5849 }
5850 }
5851}
5852
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005853/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005854testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5855 f_init_vty_bsc();
5856 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5857 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5858
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005859 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005860
5861 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005862 var template PCUIF_RemoteAddr tr_remote_addr := {
5863 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005864 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005865 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005866
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005867 if (not match(remote_addr, tr_remote_addr)) {
5868 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005869 }
5870
5871 setverdict(pass);
5872}
5873
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005874/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005875testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5876 f_init_vty_bsc();
5877 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5878
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005879 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005880
5881 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005882 var template PCUIF_RemoteAddr tr_remote_addr := {
5883 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
5884 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
5885 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005886
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005887 if (not match(remote_addr, tr_remote_addr)) {
5888 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005889 }
5890
5891 setverdict(pass);
5892}
5893
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005894/* Verify coding of two NSVCs in the INFO.ind message */
5895testcase TC_pcu_socket_two_nsvc() runs on test_CT {
5896 f_init_vty_bsc();
5897
5898 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
5899 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
5900 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5901 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
5902
5903 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
5904 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
5905 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
5906 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
5907
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005908 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005909
5910 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
5911 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
5912 var template PCUIF_RemoteAddr tr_remote_addr := {
5913 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005914 addr := {
5915 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
5916 f_inet6_addr("fd00::ca:ff:ee")
5917 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005918 };
5919
5920 if (not match(info_ind.nsvci, { 1234, 5678 }))
5921 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
5922 if (not match(remote_addr, tr_remote_addr))
5923 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
5924 if (not match(info_ind.local_port, { 1234, 5678 }))
5925 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
5926 if (not match(info_ind.remote_port, { 1234, 5678 }))
5927 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
5928
5929 setverdict(pass);
5930}
5931
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02005932/* Verify periodic interference reports on PDCH */
5933testcase TC_pcu_interf_ind() runs on test_CT {
5934 var template PCUIF_Message tr_interf_ind;
5935 var template PCUIF_interf ts_interf;
5936 var integer interf_ind_num := 0;
5937 var PCUIF_send_data sd;
5938 timer T;
5939
5940 f_init_with_pcuif();
5941 f_TC_pcu_act_req(0, 0, 7, true);
5942
5943 /* We need trxcon for NOPE indications */
5944 f_init_l1ctl();
5945 f_l1_tune(L1CTL);
5946
5947 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
5948 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
5949 tr_interf_ind := tr_PCUIF_INTERF_IND(
5950 bts_nr := 0,
5951 trx_nr := 0,
5952 fn := ?,
5953 interf := ts_interf
5954 );
5955
5956 /* 4 SACCH periods => 4 reports (plus some guard time) */
5957 var float Tval := int2float(4 * 480) / 1000.0 + 0.5;
5958
5959 /* Let it some time to stabilize */
5960 f_sleep(0.5);
5961 PCU.clear;
5962
5963 T.start(Tval);
5964 alt {
5965 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
5966 /* Check TDMA frame number period */
5967 if (sd.data.u.interf_ind.fn mod 104 != 0) {
5968 setverdict(fail, "Odd TDMA frame number := ",
5969 sd.data.u.interf_ind.fn);
5970 }
5971 interf_ind_num := interf_ind_num + 1;
5972 if (interf_ind_num < 4)
5973 { repeat; }
5974 }
5975 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
5976 setverdict(fail, "Received unexpected interference report: ", sd.data);
5977 }
5978 [] PCU.receive { repeat; }
5979 [] T.timeout {
5980 setverdict(fail, "Timeout waiting for interference reports");
5981 }
5982 }
5983
5984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5985}
5986
Harald Welte3d04ae62018-04-04 20:29:05 +02005987/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005988 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005989 ***********************************************************************/
5990
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005991private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5992 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005993runs on ConnHdlr {
5994 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005995
5996 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005997 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005998 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5999 repeat;
6000 }
6001 }
6002}
6003
6004private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6005runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006006 /* Expect BTS to immediately acknowledge activation as PDCH */
6007 PCU.clear;
6008 f_rsl_chan_act(g_pars.chan_mode);
6009 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006010 timer T_wait := 2.0;
6011 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006012 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006013 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006014 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006015 [] T_wait.timeout {
6016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6017 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6018 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006019 }
6020 /* try to activate this PDCH from the PCU point of view */
6021 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6022 /* FIXME: is there a response? */
6023}
6024
6025private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6026runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006027 /* Send RSL CHAN REL (deactivate) */
6028 PCU.clear;
6029 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6030 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006031 timer T_wait := 2.0;
6032 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006033 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006034 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006035 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006036 [] T_wait.timeout {
6037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6038 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6039 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006040 }
6041 /* Emulate PCU asking BTS to deactivate PDCH */
6042 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6043 alt {
6044 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6045 setverdict(pass);
6046 }
6047 [] RSL.receive { repeat; }
6048 }
6049}
6050
6051/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006052private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006053 var PCUIF_Message first_info;
6054 var integer ts_nr := g_chan_nr.tn;
6055 var integer trx_nr := 0;
6056 var integer bts_nr := 0;
6057 var integer pcu_conn_id := -1;
6058
6059 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6060
6061 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6062 f_sleep(3.0);
6063 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6064 setverdict(pass);
6065}
6066testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6067 var ConnHdlrPars pars;
6068 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006069 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006070
6071 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6072 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6073 vc_conn.done;
6074}
6075
6076/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006077private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006078 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006079 var integer pcu_conn_id := -1;
6080
6081 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6082
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006083 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6084 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6085 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006086 setverdict(pass);
6087}
6088testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6089 var ConnHdlrPars pars;
6090 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006091 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006092
6093 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6094 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6095 vc_conn.done;
6096}
6097
6098/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006099private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006100 var PCUIF_Message first_info;
6101 var integer ts_nr := g_chan_nr.tn;
6102 var integer trx_nr := 0;
6103 var integer bts_nr := 0;
6104 var integer pcu_conn_id := -1;
6105
6106 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6107
6108 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006109 /* Send a second Chan Activ and expect it to be NACKed */
6110 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6111 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006112 setverdict(pass);
6113}
6114testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6115 var ConnHdlrPars pars;
6116 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006117 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006118
6119 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6120 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6121 vc_conn.done;
6122}
6123
6124/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006125private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006126 var PCUIF_Message first_info;
6127 var integer ts_nr := g_chan_nr.tn;
6128 var integer trx_nr := 0;
6129 var integer bts_nr := 0;
6130 var integer pcu_conn_id := -1;
6131 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6132
6133 /* register for the TCH/F channel number */
6134 f_rslem_register(0, chan_nr);
6135
6136 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6137
6138 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6139 "RSL CHAN ACT");
6140 setverdict(pass);
6141}
6142testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6143 var ConnHdlrPars pars;
6144 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006145 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006146
6147 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6148 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6149 vc_conn.done;
6150}
6151
6152/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006153private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006154 var PCUIF_Message first_info;
6155 var integer ts_nr := g_chan_nr.tn;
6156 var integer trx_nr := 0;
6157 var integer bts_nr := 0;
6158 var integer pcu_conn_id := -1;
6159 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6160 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6161
6162 /* register for the TCH/H channel numbers */
6163 f_rslem_register(0, chan_nr[0]);
6164 f_rslem_register(0, chan_nr[1]);
6165
6166 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6167
6168 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6169 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6170 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6171 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6172 setverdict(pass);
6173}
6174testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6175 var ConnHdlrPars pars;
6176 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006177 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006178
6179 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6180 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6181 vc_conn.done;
6182}
6183
Harald Welte9bbbfb52018-04-05 09:33:19 +02006184/***********************************************************************
6185 * IPA Style Dynamic Timeslot Support
6186 ***********************************************************************/
6187
6188private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6189runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006190 /* Expect BTS to immediately acknowledge activation as PDCH */
6191 PCU.clear;
6192 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6193 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006194 timer T_wait := 2.0;
6195 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006196 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006197 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006198 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006199 [] T_wait.timeout {
6200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6201 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6202 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006203 }
6204 /* try to activate this PDCH from the PCU point of view */
6205 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6206 /* FIXME: is there a response? */
6207
6208 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6209}
6210
6211private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6212runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006213 /* Send RSL CHAN REL (deactivate) */
6214 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6215 PCU.clear;
6216 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006217 timer T_wait := 2.0;
6218 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006219 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006220 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006221 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006222 [] T_wait.timeout {
6223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6224 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6225 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006226 }
6227 /* Emulate PCU asking BTS to deactivate PDCH */
6228 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6229 alt {
6230 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6231 setverdict(pass);
6232 }
6233 [] RSL.receive { repeat; }
6234 }
6235}
6236
6237/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006238private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006239 var PCUIF_Message first_info;
6240 var integer ts_nr := g_chan_nr.tn;
6241 var integer trx_nr := 0;
6242 var integer bts_nr := 0;
6243 var integer pcu_conn_id := -1;
6244
6245 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6246
6247 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6248 f_sleep(3.0);
6249 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6250
6251 setverdict(pass);
6252
6253}
6254testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6255 var ConnHdlrPars pars;
6256 var ConnHdlr vc_conn;
6257 f_init();
6258
6259 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6260 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6261 vc_conn.done;
6262}
6263
6264/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006265private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006266 var PCUIF_Message first_info;
6267 var integer ts_nr := g_chan_nr.tn;
6268 var integer trx_nr := 0;
6269 var integer bts_nr := 0;
6270 var integer pcu_conn_id := -1;
6271
6272 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6273
6274 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6275 "RSL CHAN ACT");
6276 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6277 "RF CHAN REL", true);
6278 setverdict(pass);
6279}
6280testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6281 var ConnHdlrPars pars;
6282 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006283 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006284
6285 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6286 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6287 vc_conn.done;
6288}
6289
6290/* 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 +07006291private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006292 var PCUIF_Message first_info;
6293 var integer ts_nr := g_chan_nr.tn;
6294 var integer trx_nr := 0;
6295 var integer bts_nr := 0;
6296 var integer pcu_conn_id := -1;
6297
6298 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6299
6300 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6301 "RSL CHAN ACT");
6302
6303 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6304 alt {
6305 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6306 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006308 }
6309 [] RSL.receive { repeat; }
6310 }
6311
6312 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6313 "RF CHAN REL", true);
6314 setverdict(pass);
6315}
6316testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6317 var ConnHdlrPars pars;
6318 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006319 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006320
6321 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6322 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6323 vc_conn.done;
6324}
6325
6326/* 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 +07006327private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006328 var PCUIF_Message first_info;
6329 var integer ts_nr := g_chan_nr.tn;
6330 var integer trx_nr := 0;
6331 var integer bts_nr := 0;
6332 var integer pcu_conn_id := -1;
6333
6334 /* register for the TCH/F channel number */
6335 f_rslem_register(0, g_chan_nr);
6336
6337 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6338
6339 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6340
6341 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6342 "RSL CHAN ACT");
6343
6344 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6345
6346 setverdict(pass);
6347}
6348testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6349 var ConnHdlrPars pars;
6350 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006351 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006352
6353 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6354 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6355 vc_conn.done;
6356}
6357
6358
Harald Welte0472ab42018-03-12 15:02:26 +01006359/***********************************************************************
6360 * LAPDm / RLL related
6361 ***********************************************************************/
6362
6363private function f_tx_lapdm(template (value) LapdmFrame l,
6364 template (value) RslLinkId link_id) runs on ConnHdlr {
6365 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006366 var template (value) SacchL1Header l1h;
6367
6368 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006369 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006370 /* Compose dummy L1 header */
6371 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6372 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 +02006373 } else {
6374 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006375 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 +01006376 }
Harald Welte0472ab42018-03-12 15:02:26 +01006377}
6378
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006379friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006380 uint3_t sapi,
6381 RslLinkId link_id,
6382 octetstring l3,
6383 boolean exp
6384}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006385friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006386friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6387 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006388 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006389 sapi := sapi,
6390 link_id := id,
6391 l3 := l3,
6392 exp := exp
6393}
6394
6395/* execute the same callback function with a set of different parameters (tcs) on a
6396 * variety of logical channels */
6397private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6398 var ConnHdlrPars pars;
6399 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006400 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006401
6402 /* test on each of the channels we have */
6403 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6404 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6405
6406 /* test each of the test cases on the current channel */
6407 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6408 pars.spec.rll := tcs[j];
6409 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6410 vc_conn := f_start_handler(fn, pars);
6411 vc_conn.done;
6412 }
6413 }
6414
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006416}
6417
6418/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6419private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6420 var RllTestCase tc := g_pars.spec.rll;
6421 timer T := 3.0;
6422
6423 f_l1_tune(L1CTL);
6424 RSL.clear;
6425
6426 /* activate the logical channel */
6427 f_est_dchan();
6428 L1CTL.clear;
6429
6430 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6431 T.start;
6432 alt {
6433 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6434 if (tc.exp) {
6435 setverdict(pass);
6436 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006438 }
6439 }
6440 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6441 if (tc.exp) {
6442 setverdict(pass);
6443 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006445 }
6446 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006447 /* We also expect to receive the measurements */
6448 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006449 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006451 }
6452 [not tc.exp] T.timeout {
6453 setverdict(pass);
6454 }
6455 }
6456
6457 f_rsl_chan_deact();
6458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6459 f_rslem_unregister(0, g_chan_nr);
6460}
6461testcase TC_rll_est_ind() runs on test_CT {
6462 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006463 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006464 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006465 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006466 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006467 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006468 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6469 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006470 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006471 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006472 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006473 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006474 };
6475 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6476}
6477
6478/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6479private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6480 var RllTestCase tc := g_pars.spec.rll;
6481 var L1ctlDlMessage dl;
6482 timer T := 3.0;
6483
6484 f_l1_tune(L1CTL);
6485 RSL.clear;
6486
6487 /* activate the logical channel */
6488 f_est_dchan();
6489 L1CTL.clear;
6490
6491 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6492 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6493 T.start;
6494 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006495 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006496 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006498 }
6499 }
6500
6501 f_rsl_chan_deact();
6502 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6503 f_rslem_unregister(0, g_chan_nr);
6504}
6505testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6506 var RllTestCases tcs := {
6507 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006508 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006509 };
6510 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6511}
6512testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6513 var RllTestCases tcs := {
6514 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006515 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006516 }
6517 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6518}
6519
6520/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006521friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006522 var L1ctlDlMessage dl;
6523 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6524 var LapdmFrame lapdm;
6525 var octetstring l2 := dl.payload.data_ind.payload;
6526 if (dl.dl_info.link_id.c == SACCH) {
6527 /* remove L1 header */
6528 l2 := substr(l2, 2, lengthof(l2)-2);
6529 }
6530 if (ischosen(exp.ab)) {
6531 lapdm.ab := dec_LapdmFrameAB(l2);
6532 } else if (ischosen(exp.b4)) {
6533 lapdm.b4 := dec_LapdmFrameB4(l2);
6534 } else if (ischosen(exp.bbis)) {
6535 lapdm.bbis := dec_LapdmFrameBbis(l2);
6536 }
6537 log("Rx LAPDm ", lapdm);
6538 if (match(lapdm, exp)) {
6539 setverdict(pass);
6540 } else {
6541 repeat;
6542 }
6543 }
6544 [] L1CTL.receive { repeat; }
6545}
6546private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6547 timer T := t;
6548 T.start;
6549 alt {
6550 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006552 }
6553 [] as_l1_exp_lapdm(exp);
6554 }
6555}
6556
6557/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6558private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6559 /* send SABM from MS -> BTS */
6560 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6561 /* expect RLL EST IND on Abis */
6562 alt {
6563 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6564 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6565 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006567 }
6568 [] RSL.receive { repeat; }
6569 }
6570 /* expect UA from BTS -> MS */
6571 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6572}
6573
6574/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6575private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6576 var RllTestCase tc := g_pars.spec.rll;
6577
6578 f_l1_tune(L1CTL);
6579 RSL.clear;
6580
6581 /* activate the logical channel */
6582 f_est_dchan();
6583 L1CTL.clear;
6584
6585 /* first establish the link-layer */
6586 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6587
6588 /* then send the DISC */
6589 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6590 /* ... and expect the REL IND on the RSL side */
6591 alt {
6592 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6593 setverdict(pass);
6594 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006595 /* We also expect to receive the measurements */
6596 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006597 }
6598
6599 /* release the channel */
6600 f_rsl_chan_deact();
6601 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6602 f_rslem_unregister(0, g_chan_nr);
6603}
6604testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6605 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006606 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006607 };
6608 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6609}
6610
6611testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6612 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006613 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006614 };
6615 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6616}
6617testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6618 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006619 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006620 };
6621 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6622}
6623testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6624 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006625 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006626 };
6627 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6628}
6629
6630/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6631private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6632 var RllTestCase tc := g_pars.spec.rll;
6633 f_l1_tune(L1CTL);
6634 RSL.clear;
6635
6636 /* activate the logical channel */
6637 f_est_dchan();
6638 L1CTL.clear;
6639
6640 /* first establish the link-layer */
6641 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6642
6643 /* then send the REL REQ via RSL */
6644 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6645 /* ... and expect the DISC on the Um side */
6646 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006647 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006648 /* FIXME: send a UA in resposne to the DISC */
6649 }
6650 }
6651
6652 /* release the channel */
6653 f_rsl_chan_deact();
6654 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6655 f_rslem_unregister(0, g_chan_nr);
6656}
6657testcase TC_rll_rel_req() runs on test_CT {
6658 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006659 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6660 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6661 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6662 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006663 };
6664 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6665}
6666
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006667/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006668testcase TC_rll_data_req() runs on test_CT {
6669}
6670
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006671/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006672testcase TC_rll_data_ind() runs on test_CT {
6673}
6674
6675/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6676private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6677 var RllTestCase tc := g_pars.spec.rll;
6678
6679 f_l1_tune(L1CTL);
6680 RSL.clear;
6681
6682 f_est_dchan();
6683 L1CTL.clear;
6684
6685 /* Send UNITDATA REQ on RSL side */
6686 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6687 /* Expect it to arrive on the other side */
6688 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006689 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006690 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006691 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006692 }
6693
6694 /* release the channel */
6695 f_rsl_chan_deact();
6696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6697 f_rslem_unregister(0, g_chan_nr);
6698}
6699testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6700 var octetstring l3 := f_rnd_octstring(15);
6701 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006702 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6703 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006704 };
6705 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6706}
6707testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6708 var octetstring l3 := f_rnd_octstring(19);
6709 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006710 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6711 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006712 };
6713 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6714}
6715
6716/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6717private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6718 var RllTestCase tc := g_pars.spec.rll;
6719
6720 f_l1_tune(L1CTL);
6721 RSL.clear;
6722
6723 f_est_dchan();
6724 L1CTL.clear;
6725
6726 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006727 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006728 /* Expdct RLL UNITDATA IND on RSL side */
6729 alt {
6730 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6731 setverdict(pass);
6732 }
6733 [] RSL.receive { repeat; }
6734 }
6735
6736 /* release the channel */
6737 f_rsl_chan_deact();
6738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6739 f_rslem_unregister(0, g_chan_nr);
6740}
6741testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006742 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006743 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006744 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6745 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006746 };
6747 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6748}
6749testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6750 var octetstring l3 := f_rnd_octstring(18);
6751 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006752 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6753 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006754 };
6755 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6756}
6757
Harald Weltee613f962018-04-18 22:38:16 +02006758/***********************************************************************
6759 * Encryption Related
6760 ***********************************************************************/
6761
6762/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006763private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006764 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6765 if (link_id.c == SACCH) {
6766 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6767 } else {
6768 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6769 }
6770}
6771
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006772/* Expect (or not expect) other kinds of messages */
6773private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6774 [exp_any] RSL.receive { repeat; }
6775 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006777 }
6778}
6779
Harald Weltee613f962018-04-18 22:38:16 +02006780/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006781private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006782 RslLinkId link_id,
6783 octetstring l3,
6784 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006785 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006786) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006787 timer T := 3.0;
6788 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6789 T.start;
6790 /* Expect RLL UNITDATA IND on RSL side */
6791 alt {
6792 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6793 setverdict(pass);
6794 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006795 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006796 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006797 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006799 }
Harald Weltee613f962018-04-18 22:38:16 +02006800 }
6801}
6802
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006803/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6804private function f_data_mo(
6805 RslLinkId link_id,
6806 boolean p, uint3_t nr, uint3_t ns,
6807 octetstring l3,
6808 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006809 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006810) runs on ConnHdlr {
6811 timer T := 3.0;
6812 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6813 T.start;
6814 /* Expect RLL DATA IND on RSL side */
6815 alt {
6816 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6817 setverdict(pass);
6818 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006819 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006820 [] as_rsl_any_ind(exp_any);
6821 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006823 }
6824 }
6825}
6826
Harald Weltee613f962018-04-18 22:38:16 +02006827/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006828private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006829 f_l1_tune(L1CTL);
6830 f_est_dchan(true);
6831
6832 /* now we actually need to transmit some data both ways to check if the encryption works */
6833 var L1ctlDlMessage dl;
6834
Stefan Sperling603d98e2018-07-25 16:47:28 +02006835 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006836 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6837
6838 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6839 f_unitdata_mt(link_id, l3);
6840
6841 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6842 f_unitdata_mo(link_id, l3);
6843
6844 /* release the channel */
6845 f_rsl_chan_deact();
6846 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6847 f_rslem_unregister(0, g_chan_nr);
6848}
6849testcase TC_chan_act_a51() runs on test_CT {
6850 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6851 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6852 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6853}
6854testcase TC_chan_act_a52() runs on test_CT {
6855 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6856 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6857 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6858}
6859testcase TC_chan_act_a53() runs on test_CT {
6860 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6861 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6862 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6863}
Eric Wildb9260392021-05-15 19:48:22 +02006864testcase TC_chan_act_a54() runs on test_CT {
6865 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6866 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6867 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6868}
Harald Weltee613f962018-04-18 22:38:16 +02006869
Eric Wildf1827a72019-05-28 17:37:35 +02006870/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6871 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 +07006872private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006873 f_l1_tune(L1CTL);
6874 f_est_dchan(true);
6875
6876 /* now we actually need to transmit some data both ways to check if the encryption works */
6877 var L1ctlDlMessage dl;
6878
6879 var octetstring l3 := f_rnd_octstring(20);
6880 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6881
6882 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6883 f_unitdata_mt(link_id, l3);
6884
6885 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6886 f_unitdata_mo(link_id, l3);
6887
6888 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006889 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006890
6891 /* modify key to break proper encryption */
6892 g_pars.encr.key := f_rnd_octstring(8);
6893 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6894 rsl.ies := rsl.ies & { ei };
6895 RSL.send(rsl);
6896
6897 timer T0 := 1.0;
6898 T0.start;
6899 /* Expect RSL MODIFY ACK */
6900 alt {
6901 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6902 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6904 }
6905 [] T0.timeout {
6906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6907 }
6908 }
6909
6910 var octetstring l3msg := f_rnd_octstring(15);
6911 timer T1 := 3.0;
6912 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6913 due to broken encryption */
6914 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6915 T1.start;
6916 alt {
6917 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6919 }
6920 [] T1.timeout {
6921 setverdict(pass);
6922 }
6923 }
6924
6925 /* release the channel */
6926 f_rsl_chan_deact();
6927 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6928 f_rslem_unregister(0, g_chan_nr);
6929}
6930testcase TC_rsl_modify_encr() runs on test_CT {
6931 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6932 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6933 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6934}
Harald Weltee613f962018-04-18 22:38:16 +02006935
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02006936/* Verify RF RESource INDication messages (periodically sent over the RSL) */
6937private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
6938runs on test_CT {
6939 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
6940 var ASP_RSL_Unitdata ud;
6941 timer T;
6942
6943 /* Intave is 6 SACCH periods by default */
6944 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
6945
6946 T.start(Tval);
6947 alt {
6948 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
6949 setverdict(pass);
6950 }
6951 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
6952 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
6953 }
6954 [] RSL_CCHAN.receive { repeat; }
6955 [] T.timeout {
6956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6957 "Timeout waiting for RF RESource INDication");
6958 }
6959 }
6960}
6961testcase TC_rsl_rf_resource_ind() runs on test_CT {
6962 var RSL_ResourceInfo info := { };
6963
6964 f_init(trx_nr := 0);
6965
6966 f_init_l1ctl();
6967 f_l1_tune(L1CTL);
6968
6969 /* g_AllChannels contains all logical channels */
6970 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
6971 var RslChannelNr chan_nr := g_AllChannels[i];
6972
6973 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
6974 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
6975 { continue; }
6976
6977 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
6978 }
6979
6980 /* Align to the first interference report */
6981 f_TC_rsl_rf_resource_ind(?);
6982
6983 /* Test 4 consecutive messages */
6984 for (var integer i := 0; i < 4; i := i + 1) {
6985 f_TC_rsl_rf_resource_ind(info);
6986 }
6987
6988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6989}
6990
Harald Weltee613f962018-04-18 22:38:16 +02006991/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006992private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006993 /* L3 payload doesn't matter, as it is passed transparently */
6994 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6995 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6996 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6997
6998 f_l1_tune(L1CTL);
6999
7000 /* first establish a dedicated channel in the clear */
7001 f_est_dchan(false);
7002
7003 /* Establish ABM */
7004 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7005
7006 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7007 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7008 /* expect the L3 to arrive still unencrypted on the MS side */
7009 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7010
7011 /* configure L1 to apply ciphering */
7012 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7013 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7014
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007015 /* send first ciphered I-frame in response and expect it on RSL */
7016 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007017
7018 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7019 * and hence enable encryption also on the downlink */
7020
7021 /* expect bi-directional communication work in encrypted mode */
7022 f_unitdata_mo(link_id, f_rnd_octstring(15));
7023 f_unitdata_mt(link_id, f_rnd_octstring(15));
7024
7025 /* release the channel */
7026 f_rsl_chan_deact();
7027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7028 f_rslem_unregister(0, g_chan_nr);
7029}
7030testcase TC_encr_cmd_a51() runs on test_CT {
7031 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7032 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7033 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7034}
7035testcase TC_encr_cmd_a52() runs on test_CT {
7036 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7037 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7038 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7039}
7040testcase TC_encr_cmd_a53() runs on test_CT {
7041 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7042 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7043 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7044}
Eric Wildb9260392021-05-15 19:48:22 +02007045testcase TC_encr_cmd_a54() runs on test_CT {
7046 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7047 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7048 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7049}
Harald Weltee613f962018-04-18 22:38:16 +02007050
7051private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7052 var LapdmFrame lf;
7053 var octetstring reenc;
7054
7055 /* decode the LAPDm frame */
7056 if (ischosen(exp_match.ab)) {
7057 lf.ab := dec_LapdmFrameAB(enc);
7058 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007060 }
7061
7062 /* check if decoder result matches expectation */
7063 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007065 } else {
7066 log(name, ": matched");
7067 setverdict(pass);
7068 }
7069
7070 /* test if re-encoded frame equals original input */
7071 reenc := enc_LapdmFrame(lf);
7072 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007074 } else {
7075 setverdict(pass);
7076 }
7077}
7078
7079testcase TC_lapdm_selftest() runs on test_CT {
7080 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7081 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7082 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7083 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7084 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7085 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7086 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7087}
7088
Stefan Sperling4880be42018-08-07 18:12:59 +02007089/***********************************************************************
7090 * DTX Related (see GSM 05.08, section 8.3)
7091 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007092private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007093 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007094 var GsmFrameNumber first_fn;
7095 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007096 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007097 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007098 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7099 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007100 const integer frame_dtx_tchf_mod := 104;
7101 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7102 * which operates in terms of blocks rather than frames. */
7103 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7104 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007105 timer T := 5.0;
7106
7107 f_l1_tune(L1CTL);
7108 RSL.clear;
7109 L1CTL.clear;
7110
7111 /* activate TCHF signalling channel */
7112 f_est_dchan(false);
7113
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007114 /* A template for matching dummy LAPDm func=UA frames */
7115 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7116 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7117 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7118
Stefan Sperling4880be42018-08-07 18:12:59 +02007119 T.start;
7120 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007121 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007122 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007123
7124 if (is_first_frame) {
7125 is_first_frame := false;
7126 first_fn := dl.dl_info.frame_nr;
7127 }
7128
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007129 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007130 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007131 T.stop;
7132 f_rsl_chan_deact();
7133 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007134
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007135 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7136 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007137
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007138 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007139 setverdict(fail, "Not enough fill frames received: ",
7140 nfill_frames, " out of ", expected_fill_frames);
7141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007142 } else {
7143 setverdict(pass);
7144 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007145 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007146 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7147 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7148 * we should only see the subset of frames numbers which correspond to a block boundary.
7149 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7150 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7151 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007152 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007153 repeat;
7154 }
7155 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007156 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7157 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7158 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007159 f_rsl_chan_deact();
7160 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007161 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007162 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007163 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007164 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007165 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007166
7167 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007168 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7169 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007170 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7171 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7172 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007173 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7174 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007175 case else {
7176 /* This shall not happen, just to be sure */
7177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7178 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007179 }
7180
7181 f_rsl_chan_deact();
7182 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007183
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007184 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007185 setverdict(pass);
7186 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007187 setverdict(fail, "Not enough fill frames received: ",
7188 nfill_frames, " out of ", expected_fill_frames);
7189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007190 }
7191 } else {
7192 repeat;
7193 }
7194 }
7195 }
7196 [] L1CTL.receive { repeat; }
7197 [] T.timeout {
7198 f_rsl_chan_deact();
7199 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007201 }
7202 }
7203}
7204
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007205private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007206 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007207 var ConnHdlr vc_conn;
7208 var ConnHdlrPars pars;
7209 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007210 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007211 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007212 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007213 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007214 if (dtxd) {
7215 if (i >= 4) { /* DTX is only allowed on TCH/F */
7216 break;
7217 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007218 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007219 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007220 vc_conn.done;
7221 }
7222}
7223
7224/* Verify that L2 fill frames are sent on TCH in signaling mode if
7225 * there is nothing to transmit while DTX is disabled on downlink. */
7226testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7227 f_tch_sign_l2_fill_frame(false);
7228}
7229
7230/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7231 * there is nothing to transmit while DTX is enabled on downlink. */
7232testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7233 f_tch_sign_l2_fill_frame(true);
7234}
Harald Welte0472ab42018-03-12 15:02:26 +01007235
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007236testcase TC_chopped_ipa_ping() runs on test_CT {
7237 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7238}
7239
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007240testcase TC_chopped_ipa_payload() runs on test_CT {
7241 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7242}
7243
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007244
7245/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7246 * Return value: Measurement Report to be sent (encoded octetstring). */
7247type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7248 runs on ConnHdlr return octetstring;
7249
7250private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7251runs on ConnHdlr {
7252 var L1ctlDlMessage l1_dl;
7253 var SacchL1Header l1h;
7254 var octetstring l2;
7255
7256 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7257 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7258 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7259 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7260
7261 /* Pass it to the user specified call-back function */
7262 l2 := cb.apply(l1h, num_blocks);
7263 /* Send a Measurement Report generated by the call-back */
7264 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7265 l1_dl.dl_info.link_id,
7266 l1h, l2));
7267
7268 /* Shall we keep going? */
7269 num_blocks := num_blocks - 1;
7270 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7271 if (num_blocks > 0) { repeat; }
7272 }
7273 [] L1CTL.receive { repeat; }
7274}
7275
7276private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7277runs on ConnHdlr return octetstring {
7278 /* Command the L1 to apply received parameters */
7279 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7280
7281 /* Dummy measurement report (the results are invalid) */
7282 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7283}
7284
7285private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7286runs on ConnHdlr return octetstring {
7287 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7288 setverdict(fail, "Unexpected MS Power level change: ",
7289 g_pars.l1_pars.ms_power_level, " -> ",
7290 l1h.ms_power_lvl);
7291 }
7292
7293 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7294}
7295
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007296private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7297runs on ConnHdlr return octetstring {
7298 /* UL RSSI oscillation driven by SACCH block number */
7299 if (num_blocks rem 2 == 0) {
7300 f_trxc_fake_rssi(-100);
7301 } else {
7302 f_trxc_fake_rssi(-50);
7303 }
7304
7305 /* Make sure that MS power level remains constant */
7306 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7307}
7308
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007309/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7310private function f_TC_ms_pwr_ctrl_constant(charstring id)
7311runs on ConnHdlr {
7312 var integer num_blocks := 8;
7313 timer T := int2float(num_blocks);
7314
7315 f_l1_tune(L1CTL);
7316 RSL.clear;
7317
7318 /* These IEs are needed for autonomous MS power control */
7319 var template (value) RSL_IE_List ies := {
7320 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7321 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7322 }),
7323 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7324 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7325 })
7326 };
7327
7328 /* Ensure that 'rx-current' equals 'rx-target' */
7329 f_trxc_fake_rssi(mp_uplink_power_target);
7330
7331 /* Establish a dedicated channel */
7332 f_est_dchan(more_ies := valueof(ies));
7333
7334 L1CTL.clear;
7335 T.start;
7336 alt {
7337 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7338 [] T.timeout {
7339 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7340 num_blocks, " were not handled");
7341 }
7342 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007343
7344 /* Release the channel */
7345 f_rsl_chan_deact();
7346 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007347}
7348testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7349 var ConnHdlr vc_conn;
7350 var ConnHdlrPars pars;
7351
7352 f_init();
7353
7354 /* Explicitly configure the Uplink power target (in dBm) */
7355 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7356
7357 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7358 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7359 log(testcasename(), ": starting on ", pars.chan_nr);
7360
7361 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7362 pars, trxc_comp := true);
7363 vc_conn.done;
7364 }
7365
7366 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7368}
7369
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007370/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7371private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7372runs on ConnHdlr {
7373 var integer num_blocks := 16;
7374 timer T := int2float(num_blocks);
7375
7376 f_l1_tune(L1CTL);
7377 RSL.clear;
7378
7379 /* These IEs are needed for autonomous MS power control */
7380 var template (value) RSL_IE_List ies := {
7381 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7382 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7383 }),
7384 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7385 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7386 })
7387 };
7388
7389 /* Ensure that 'rx-current' equals 'rx-target' */
7390 f_trxc_fake_rssi(mp_uplink_power_target);
7391
7392 /* Establish a dedicated channel */
7393 f_est_dchan(more_ies := valueof(ies));
7394
7395 L1CTL.clear;
7396 T.start;
7397 alt {
7398 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7399 [] T.timeout {
7400 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7401 num_blocks, " were not handled");
7402 }
7403 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007404
7405 /* Release the channel */
7406 f_rsl_chan_deact();
7407 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007408}
7409testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7410 var ConnHdlr vc_conn;
7411 var ConnHdlrPars pars;
7412
7413 f_init();
7414
7415 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7416 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7417 /* Explicitly configure the Uplink power range (target and delte) */
7418 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7419 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7420
7421 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7422 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7423 log(testcasename(), ": starting on ", pars.chan_nr);
7424
7425 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7426 pars, trxc_comp := true);
7427 vc_conn.done;
7428 }
7429
7430 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7432}
7433
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007434private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7435 var template L1ctlDlMessage tr_bad_frame;
7436 var L1ctlDlMessage l1_dl;
7437 timer T := 8.0;
7438
7439 f_l1_tune(L1CTL);
7440 RSL.clear;
7441
7442 f_est_dchan();
7443
7444 /* There may be a few errors right after the channel activation */
7445 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7446 L1CTL.clear;
7447
7448 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7449 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7450 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7451 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7452 tr_bad_frame.payload := ?;
7453
7454 T.start;
7455 alt {
7456 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7457 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7458 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7459 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7460 }
7461 [] as_l1_sacch();
7462 [] L1CTL.receive { repeat; }
7463 [] T.timeout {
7464 /* We're done, break the loop */
7465 setverdict(pass);
7466 }
7467 }
7468
7469 f_rsl_chan_deact();
7470 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7471}
7472testcase TC_speech_no_rtp_tchf() runs on test_CT {
7473 var ConnHdlr vc_conn;
7474 var ConnHdlrPars pars;
7475
7476 f_init();
7477
7478 /* TS1, TCH/F, V1 (FR codec) */
7479 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7480 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7481 vc_conn.done;
7482}
7483testcase TC_speech_no_rtp_tchh() runs on test_CT {
7484 var ConnHdlr vc_conn;
7485 var ConnHdlrPars pars;
7486
7487 f_init();
7488
7489 /* TS5, TCH/H, V1 (HR codec) */
7490 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7491 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7492 vc_conn.done;
7493}
7494
Harald Welte0472ab42018-03-12 15:02:26 +01007495/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7496/* protocol error as per 44.006 */
7497/* link layer failure (repetition of I-frame N200 times without ACK */
7498/* repetition of SABM or DISC N200 times without ACK */
7499/* receptiom of SABM in multi-frame established state */
7500
7501
Harald Welte68e495b2018-02-25 00:05:57 +01007502/* TODO Areas:
7503
7504* channel activation
7505** with BS_Power / MS_Power, bypassing power control loop
7506** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007507** with timing advance from initial activation on
7508* mode modify
7509** encryption
7510** multirate
7511* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007512** unsupported algorithm
7513* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007514* BS Power Control
7515* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007516* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007517* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007518** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007519* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007520** DATA_IND from BTS->PCU
7521** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007522
7523*/
Harald Welte70767382018-02-21 12:16:40 +01007524
7525control {
7526 execute( TC_chan_act_stress() );
7527 execute( TC_chan_act_react() );
7528 execute( TC_chan_deact_not_active() );
7529 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007530 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007531 execute( TC_sacch_filling() );
7532 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007533 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007534 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007535 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007536 execute( TC_sacch_chan_act_ho_async() );
7537 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007538 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007539 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007540 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007541 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007542 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007543 execute( TC_rach_load_idle_thresh0() );
7544 execute( TC_rach_load_idle_below_thresh() );
7545 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007546 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007547 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007548 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007549 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007550 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007551 execute( TC_meas_res_sign_tchf() );
7552 execute( TC_meas_res_sign_tchh() );
7553 execute( TC_meas_res_sign_sdcch4() );
7554 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007555 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007556 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007557 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007558 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007559 execute( TC_rsl_bs_pwr_static_ass() );
7560 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007561 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007562 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007563 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007564 execute( TC_rsl_ms_pwr_dyn_up() );
7565 execute( TC_rsl_ms_pwr_dyn_down() );
7566 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7567 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007568 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007569 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007570 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007571 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01007572 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007573 execute( TC_paging_imsi_80percent() );
7574 execute( TC_paging_tmsi_80percent() );
7575 execute( TC_paging_imsi_200percent() );
7576 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007577 execute( TC_rsl_protocol_error() );
7578 execute( TC_rsl_mand_ie_error() );
7579 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007580 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007581 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007582 execute( TC_si_sched_2bis() );
7583 execute( TC_si_sched_2ter() );
7584 execute( TC_si_sched_2ter_2bis() );
7585 execute( TC_si_sched_2quater() );
7586 execute( TC_si_sched_13() );
7587 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007588 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007589 execute( TC_ipa_crcx_twice_not_active() );
7590 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007591 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007592 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007593
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007594 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02007595 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007596 execute( TC_pcu_act_req() );
7597 execute( TC_pcu_act_req_wrong_ts() );
7598 execute( TC_pcu_act_req_wrong_bts() );
7599 execute( TC_pcu_act_req_wrong_trx() );
7600 execute( TC_pcu_deact_req() );
7601 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01007602 execute( TC_pcu_ver_si1() );
7603 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007604 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007605 if (mp_l1_supports_gprs) {
7606 execute( TC_pcu_data_req_pdtch() );
7607 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007608 execute( TC_pcu_data_req_wrong_bts() );
7609 execute( TC_pcu_data_req_wrong_trx() );
7610 execute( TC_pcu_data_req_wrong_ts() );
7611 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007612 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007613 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007614 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007615 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007616 execute( TC_pcu_data_req_imm_ass_pch() );
7617 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007618 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007619 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007620 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007621 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007622 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007623 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007624 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007625 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007626 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007627 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007628 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007629 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007630 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007631 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007632 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007633 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007634 execute( TC_dyn_osmo_pdch_act_deact() );
7635 execute( TC_dyn_osmo_pdch_double_act() );
7636 execute( TC_dyn_ipa_pdch_act_deact() );
7637 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01007638 execute( TC_pcu_info_ind_fh_params() );
7639 execute( TC_pcu_socket_nsvc_ipv4() );
7640 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01007641 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02007642 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007643 } else {
7644 log("PCU socket path not available, skipping PCU tests");
7645 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007646
Harald Welte3d04ae62018-04-04 20:29:05 +02007647 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007648 execute( TC_dyn_osmo_pdch_tchf_act() );
7649 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007650 execute( TC_dyn_ipa_pdch_tchf_act() );
7651 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007652
7653 execute( TC_rll_est_ind() );
7654 execute( TC_rll_est_req_DCCH_3() );
7655 execute( TC_rll_est_req_ACCH_3() );
7656 execute( TC_rll_rel_ind_DCCH_0() );
7657 execute( TC_rll_rel_ind_DCCH_3() );
7658 execute( TC_rll_rel_ind_ACCH_0() );
7659 execute( TC_rll_rel_ind_ACCH_3() );
7660 execute( TC_rll_rel_req() );
7661 execute( TC_rll_unit_data_req_DCCH() );
7662 execute( TC_rll_unit_data_req_ACCH() );
7663 execute( TC_rll_unit_data_ind_DCCH() );
7664 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007665
7666 execute( TC_chan_act_a51() );
7667 execute( TC_chan_act_a52() );
7668 execute( TC_chan_act_a53() );
7669 execute( TC_encr_cmd_a51() );
7670 execute( TC_encr_cmd_a52() );
7671 execute( TC_encr_cmd_a53() );
7672
Harald Welteee25aae2019-05-19 14:32:37 +02007673 execute( TC_err_rep_wrong_mdisc() );
7674 execute( TC_err_rep_wrong_msg_type() );
7675 execute( TC_err_rep_wrong_sequence() );
7676
Harald Weltee613f962018-04-18 22:38:16 +02007677 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007678
7679 execute( TC_tch_sign_l2_fill_frame() );
7680 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007681
7682 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007683 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007684
7685 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007686 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007687
7688 execute( TC_speech_no_rtp_tchf() );
7689 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007690}
7691
7692
7693}