blob: cbbb297a438b447c06510b5d78faad2d4e0bb454 [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;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 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 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +0300138 /* T3105 timer (see 3GPP TS 44.018, section 11.1.2) */
139 integer mp_ho_t3105_ms := 100;
140 /* Ny1 counter (see 3GPP TS 44.018, section 11.1.3) */
141 integer mp_ho_ny1 := 10;
Harald Welte70767382018-02-21 12:16:40 +0100142}
143
Harald Welte629cc6b2018-03-11 17:19:05 +0100144type record of RslChannelNr ChannelNrs;
145
Harald Welte70767382018-02-21 12:16:40 +0100146type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100148 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100149 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100150 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100151 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100152 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100153
154 /* L1CTL port (for classic tests) */
155 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100156
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700157 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700158 port TRXC_CODEC_PT BTS_TRXC;
159 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100160
Harald Weltef50e3ae2018-09-10 10:27:56 +0200161 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100162 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200163 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100164
Harald Welte883340c2018-02-28 18:59:29 +0100165 /* PCU Interface of BTS */
166 port PCUIF_CODEC_PT PCU;
167 var integer g_pcu_conn_id;
168 /* Last PCU INFO IND we received */
169 var PCUIF_Message g_pcu_last_info;
170
Harald Welte48494ca2018-02-25 16:59:50 +0100171 /* SI configuration */
172 var SystemInformationConfig si_cfg := {
173 bcch_extended := false,
174 si1_present := false,
175 si2bis_present := false,
176 si2ter_present := false,
177 si2quater_present := false,
178 si7_present := false,
179 si8_present := false,
180 si9_present := false,
181 si13_present := false,
182 si13alt_present := false,
183 si15_present := false,
184 si16_present := false,
185 si17_present := false,
186 si2n_present := false,
187 si21_present := false,
188 si22_present := false
189 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100190
191 /* all logical channels available on the BTS */
192 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100193 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
196/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200197type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100198 port L1CTL_PT L1CTL;
199
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700200 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700201 port TRXC_CODEC_PT BTS_TRXC;
202 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100203
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200204 /* port to be initialized optionally to access BSC VTY */
205 port TELNETasp_PT BSCVTY;
206
Harald Welte70767382018-02-21 12:16:40 +0100207 timer g_Tguard;
208 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
209
210 var ConnHdlrPars g_pars;
211 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100212 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200213
214 /* PCU Interface of BTS */
215 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200216
217 var RTP_Emulation_CT vc_RTPEM;
218 port RTPEM_CTRL_PT RTPEM_CTRL;
219 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100220}
221
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700222private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200226 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200228 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700229 timer T;
230
Harald Welte70767382018-02-21 12:16:40 +0100231 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
232 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
233
234 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
235 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
236 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
237
238 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
239 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700240
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700241 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700242 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700243 T.start(mp_ipa_up_timeout);
244 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700245 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700246 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
247 /* Make sure that all transceivers use unique stream ID */
248 if (trx_mask[enum2int(ev.sid)] == '1'B) {
249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
250 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
251 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700252
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700253 trx_mask[enum2int(ev.sid)] := '1'B;
254 trx_count := trx_count + 1;
255
256 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200257 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700258 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200259 /* This message (RF RESource INDication) is sent by the IUT itself */
260 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
261 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
264 }
265 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
267 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
268 }
269
270 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
271 rfind_count := rfind_count + 1;
272 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
273 if (rfind_count < mp_transceiver_num) { repeat; }
274 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700275 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
276 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
277 [] T.timeout {
278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
279 "Timeout waiting for RSL bring up");
280 }
281 }
Harald Welte70767382018-02-21 12:16:40 +0100282}
283
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700284friend type record length(1 .. 256) of TrxParsItem TrxPars;
285friend type record TrxParsItem {
286 GsmArfcn arfcn,
287 TrxTsPars ts
288};
289
290friend type record length(8) of TrxTsParsItem TrxTsPars;
291friend type record TrxTsParsItem {
292 PchanConfig config
293};
294
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700295friend type record FreqHopPars {
296 /* Whether frequency hopping is in use */
297 boolean enabled,
298 /* Mobile Allocation Index Offset / Hopping Sequence Number */
299 MaioHsn maio_hsn,
300 /* MA bitmap to be indicated in RR Immediate Assignment */
301 MobileAllocationLV ma_map,
302 /* The actual Mobile Allocation (ARFCN list) to be used */
303 L1ctlMA ma
304};
305
Harald Welte70767382018-02-21 12:16:40 +0100306type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700307 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100308 RslChannelNr chan_nr,
309 RSL_IE_ChannelMode chan_mode,
310 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100311 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200312 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200313 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700314 BtsBand bts0_band optional,
315
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700316 /* Training Sequence Code */
317 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700318 /* Frequency hopping parameters */
319 FreqHopPars fhp
320};
Harald Welte0472ab42018-03-12 15:02:26 +0100321
322/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200323friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300324 RllTestCase rll,
325 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100326}
327
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700328private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100329 max_retrans := RACH_MAX_RETRANS_7,
330 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100331 cell_barr_access := false,
332 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100333 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100334};
335
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700336private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100337 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200338 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100339 acs := '0'B,
340 neci := true,
341 rxlev_access_min := 0
342}
343
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700344private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100345 mcc_mnc := '262F42'H,
346 lac := 42
347}
348
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700349private template (value) GPRSIndicator ts_GPRSIndicator_def := {
350 ra_colour := 0,
351 si13_pos := '0'B
352}
353
354private template (value) SI3RestOctets ts_SI3RestOctets_def
355modifies ts_SI3RestOctets := {
356 gprs_ind := {
357 presence := CSN1_H,
358 ind := ts_GPRSIndicator_def
359 }
360}
361
362private template (value) SI4RestOctets ts_SI4RestOctets_def
363modifies ts_SI4RestOctets := {
364 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700365 presence := CSN1_H,
366 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700367 }
368}
369
Harald Welte7484fc42018-02-24 14:09:45 +0100370/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100373 payload := {
374 si3 := {
375 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100376 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100377 ctrl_chan_desc := {
378 msc_r99 := true,
379 att := true,
380 bs_ag_blks_res := 1,
381 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100382 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100383 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
384 spare := '00'B,
385 bs_pa_mfrms := 0, /* 2 multiframes */
386 t3212 := 1 /* 6 minutes */
387 },
Harald Welte82ccef72018-02-25 16:17:33 +0100388 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100389 dn_ind := false,
390 pwrc := false,
391 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100392 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100393 },
Harald Weltef10153f2018-02-25 16:34:05 +0100394 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100395 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200396 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100397 }
398 }
399}
Harald Welte70767382018-02-21 12:16:40 +0100400
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700401private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100402 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100403 payload := {
404 si2 := {
405 bcch_freq_list := '00000000000000000000000000000000'O,
406 ncc_permitted := '11111111'B,
407 rach_control := ts_RachCtrl_default
408 }
409 }
410}
411
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700412private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100413 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100414 payload := {
415 si4 := {
416 lai := ts_LAI_default,
417 cell_sel_par := ts_CellSelPar_default,
418 rach_control := ts_RachCtrl_default,
419 cbch_chan_desc := omit,
420 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200421 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100422 }
423 }
424}
425
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700426private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100427runs on test_CT {
428 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700429 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100430}
431
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700432private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100433runs on test_CT {
434 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
435 log("Setting ", rsl_si_type, ": ", si_dec);
436 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
437}
438
Harald Welte505cf9b2018-09-15 17:47:23 +0300439friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100440 map(self:BTSVTY, system:BTSVTY);
441 f_vty_set_prompts(BTSVTY);
442 f_vty_transceive(BTSVTY, "enable");
443}
444
Harald Welte505cf9b2018-09-15 17:47:23 +0300445friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200446 map(self:BSCVTY, system:BSCVTY);
447 f_vty_set_prompts(BSCVTY, "OsmoBSC");
448 f_vty_transceive(BSCVTY, "enable");
449}
450
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200451friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
452 map(self:BSCVTY, system:BSCVTY);
453 f_vty_set_prompts(BSCVTY, "OsmoBSC");
454 f_vty_transceive(BSCVTY, "enable");
455}
456
Harald Welte883340c2018-02-28 18:59:29 +0100457/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200458friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100460 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200461 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
462 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100463 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200464 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100466 }
467}
468
Harald Weltef26de0b2018-04-04 20:28:05 +0200469private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
470 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100471 timer T := 2.0;
472 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100473 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200474 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100475 return;
476 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100478
479 T.start;
480 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200481 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100484 }
485 }
486}
487
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
489 out integer trxc_conn_id) {
490 var Result res;
491
492 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
493 "", -1, -1, { udp := {} }, {});
494 if (not ispresent(res.connId)) {
495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
496 "Could not connect to the control (TRXC) interface " &
497 "of FakeTRX, check your configuration");
498 }
499 trxc_conn_id := res.connId;
500}
501
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100502/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700503friend function f_init(uint8_t trx_nr := 0)
504runs on test_CT
505{
506 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200507 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100508
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700509 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
510 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700511 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200512 g_AllChanTypes := {
513 /* TS 1..4: TCH/F */
514 valueof(ts_RslChanNr_Bm(1)),
515 /* TS 5: TCH/H */
516 valueof(ts_RslChanNr_Lm(5,1)),
517 /* TS 0: SDCCH/4 */
518 valueof(ts_RslChanNr_SDCCH4(0,2)),
519 /* TS 6: SDCCH/8 */
520 valueof(ts_RslChanNr_SDCCH8(6,4))
521 };
522 } else {
523 g_AllChanTypes := {
524 /* TS 1..4: TCH/F */
525 valueof(ts_RslChanNr_Bm(1)),
526 /* TS 0: SDCCH/4 */
527 valueof(ts_RslChanNr_SDCCH4(0,2)),
528 /* TS 6: SDCCH/8 */
529 valueof(ts_RslChanNr_SDCCH8(6,4))
530 };
531 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700532
533 g_AllChannels := { };
534
535 /* Generate list of all logical channels from module parameters */
536 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
537 select (trx_pars.ts[tn].config) {
538 case (GSM_PCHAN_CCCH_SDCCH4) {
539 g_AllChannels := g_AllChannels &
540 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
541 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
542 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
543 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
544 }
545 case (GSM_PCHAN_SDCCH8) {
546 g_AllChannels := g_AllChannels &
547 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
551 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
552 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
553 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
554 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
555 }
556 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
557 g_AllChannels := g_AllChannels &
558 { valueof(ts_RslChanNr_Lm(tn, 0)),
559 valueof(ts_RslChanNr_Lm(tn, 1)),
560 valueof(ts_RslChanNr_Bm(tn)) };
561 }
562 case (GSM_PCHAN_TCHH) {
563 g_AllChannels := g_AllChannels &
564 { valueof(ts_RslChanNr_Lm(tn, 0)),
565 valueof(ts_RslChanNr_Lm(tn, 1)) };
566 }
567 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
568 g_AllChannels := g_AllChannels &
569 { valueof(ts_RslChanNr_Bm(tn)) };
570 }
571 }
572 }
573
Harald Welte70767382018-02-21 12:16:40 +0100574 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100575 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100576 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100577 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100578
579 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100580 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
581 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
582 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
583 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100584
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700585 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100586 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700587
588 /* Init TRXC interface to FakeTRX */
589 map(self:BTS_TRXC, system:BTS_TRXC);
590 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
591
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700592 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600593 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
594 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700595 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600596 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100597 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200598
599 /* Wait some extra time to make sure the BTS emits a stable carrier.
600 * (this is only relevant when running the tests with a physical BTS.) */
601 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Harald Welte68e495b2018-02-25 00:05:57 +0100604/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700605friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100606 map(self:L1CTL, system:L1CTL);
607 f_connect_reset(L1CTL);
608}
609
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200610friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100611
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700612private type record length(8) of FreqHopGroups FreqHopConfig;
613
614private type record of FreqHopGroup FreqHopGroups;
615private type record FreqHopGroup {
616 uint6_t hsn,
617 FreqHopGroupItems trx_maio
618};
619
620private type record of FreqHopGroupItem FreqHopGroupItems;
621private type record FreqHopGroupItem {
622 uint8_t trx_nr,
623 uint6_t maio
624};
625
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700626friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
627 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700628{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700629 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 var integer i, j;
631
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700632 fhp.enabled := false;
633
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700634 for (i := 0; i < lengthof(groups); i := i + 1) {
635 var FreqHopGroup g := groups[i];
636 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
637 var FreqHopGroupItem gi := g.trx_maio[j];
638 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700639 fhp.maio_hsn.maio := gi.maio;
640 fhp.maio_hsn.hsn := g.hsn;
641 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700642 break;
643 }
644 }
645
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700646 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700648 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
649 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
650 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700651
652 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700653 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
654 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700655 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700656 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700657 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700658 }
659
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700660 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700661 break; /* We're done */
662 }
663 }
664}
665
Harald Welte70767382018-02-21 12:16:40 +0100666/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700667friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
668 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200669 boolean trxc_comp := false,
670 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100671runs on test_CT return ConnHdlr {
672 var charstring id := testcasename();
673 var ConnHdlr vc_conn;
674
675 vc_conn := ConnHdlr.create(id);
676 /* connect to RSL Emulation main component */
677 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
678 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700679
680 /* The ConnHdlr component may want to talk to some ports directly,
681 * so we disconnect it from the test_CT and connect it to the component.
682 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200683 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200684 unmap(self:PCU, system:PCU);
685 map(vc_conn:PCU, system:PCU);
686 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700687 if (trxc_comp) {
688 unmap(self:BTS_TRXC, system:BTS_TRXC);
689 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
690 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200691 if (l1ctl) {
692 map(vc_conn:L1CTL, system:L1CTL);
693 }
Harald Welte70767382018-02-21 12:16:40 +0100694
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700695 /* Obtain frequency hopping parameters for a given timeslot */
696 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700697 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700698 }
699
Harald Welte70767382018-02-21 12:16:40 +0100700 vc_conn.start(f_handler_init(fn, id, pars));
701 return vc_conn;
702}
703
Harald Welte70767382018-02-21 12:16:40 +0100704private altstep as_Tguard() runs on ConnHdlr {
705 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100707 }
708}
709
Harald Welte990a3612019-05-27 14:02:13 +0200710friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700711 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700712 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100713}
714
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700715private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100716 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600717 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700720private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100721 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600722 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100723}
724
725/* first function started in ConnHdlr component */
726private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
727runs on ConnHdlr {
728 g_pars := pars;
729 g_chan_nr := pars.chan_nr;
730
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200731 if (L1CTL.checkstate("Mapped")) {
732 f_connect_reset(L1CTL);
733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
Harald Welted48c0c72019-06-05 10:01:15 +0200735 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700736 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100737 }
Harald Welte70767382018-02-21 12:16:40 +0100738
739 g_Tguard.start(pars.t_guard);
740 activate(as_Tguard());
741
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700742 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100743
744 /* call the user-supplied test case function */
745 fn.apply(id);
746}
747
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700748private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
749 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200750runs on ConnHdlr return RSL_Message {
751 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100752 timer T := 3.0;
753 RSL.send(tx);
754 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100755 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200756 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100757 T.stop;
758 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100759 }
Harald Welte1eba3742018-02-25 12:48:14 +0100760 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100762 }
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] as_l1_sacch();
764 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700765 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700766 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100767 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100769 }
Harald Welte21240e62018-03-11 21:43:35 +0100770 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100771 }
Harald Welteb1726c92018-03-30 11:56:38 +0200772 return rx;
773}
774
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700775friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
776 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200777runs on ConnHdlr {
778 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100779}
780
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700781/* Send the given measurement results to the IUT over the Um interface */
782friend function f_send_meas_rep(template (value) MeasurementResults meas_res)
783runs on ConnHdlr {
784 var template (value) SacchL1Header l1h;
785 var octetstring l2;
786
787 /* RR Measurement Report to be sent */
788 var GsmRrL3Message meas_rep := {
789 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
790 payload := { meas_rep := { meas_res := valueof(meas_res) } }
791 };
792
793 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
794 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
795 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
796
797 /* Send RR Measurement Report over the Um interface */
798 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
799}
800
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300801/* Send the given measurement results to the IUT over the Um interface,
802 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
803friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
804runs on ConnHdlr {
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700805 var octetstring l3;
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300806 timer T;
807
808 /* RR Measurement Report to be sent */
809 var GsmRrL3Message meas_rep := {
810 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
811 payload := { meas_rep := { meas_res := valueof(meas_res) } }
812 };
813
814 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
815 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300816
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700817 f_send_meas_rep(meas_res);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300818
819 /* Expect MEASurement RESult on the A-bis/RSL interface */
820 T.start(2.0);
821 alt {
822 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
823 setverdict(pass);
824 }
825 [] RSL.receive { repeat; }
826 [] T.timeout {
827 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
829 }
830 }
831}
832
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700833friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
834 boolean encr_enable := false,
835 RSL_IE_List more_ies := {},
836 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
837runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200838 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200839 if (encr_enable) {
840 /* append encryption related IEs, if requested */
841 var RSL_IE_EncryptionInfo encr_info;
842 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
843 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
844encr_info})) };
845 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200846 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200847 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100848}
849
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700850friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100851 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 +0100852 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100853}
854
Harald Welte2f2b2b72019-05-31 22:24:57 +0200855friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200856 template RSL_IE_ChannelMode chan_mode,
857 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700858 uint8_t trx_nr := 0, float t_guard := 20.0) := {
859 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100860 chan_nr := valueof(chan_nr),
861 chan_mode := valueof(chan_mode),
862 t_guard := t_guard,
863 l1_pars := {
864 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100865 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100866 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100867 meas_ul := {
868 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200869 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100870 rxqual := 0
871 },
872 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200873 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100874 rxqual := 0
875 }
876 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200877 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100878 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200879 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200880 ms_actual_ta := mp_ms_actual_ta_exp,
881 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100882 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200883 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200884 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700885 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700886 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700887 fhp := {
888 enabled := false,
889 maio_hsn := ts_HsnMaio(0, 0),
890 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700891 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700892 }
Harald Welte70767382018-02-21 12:16:40 +0100893}
894
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300895/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
896 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
897private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
898 template (present) octetstring tr_data := ?,
899 template (present) RslChannelNr chan_nr := ?,
900 template (present) RslLinkId link_id := ?)
901runs on ConnHdlr {
902 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
903}
904
905/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
906 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
907private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
908 template (present) RslLinkId link_id := ?,
909 template (present) LapdmSapi sapi := ?,
910 boolean do_repeat := true)
911runs on ConnHdlr {
912 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
913 var L1ctlDlMessage dl_msg;
914
915 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
916 if (do_repeat) {
917 repeat;
918 }
919 }
920}
921
922/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
923 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
924private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
925 template (present) LapdmFrameAB tr_frame := ?,
926 template (present) RslLinkId link_id := ?)
927runs on ConnHdlr {
928 var L1ctlDlMessage dl_msg;
929
930 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
931 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
932 }
933}
934
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300935/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
936 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
937private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
938 template (present) LapdmFrameAB tr_frame := ?,
939 template (present) SacchL1Header tr_l1h := ?,
940 template (present) GsmSapi sapi := ?)
941runs on ConnHdlr {
942 var L1ctlDlMessage dl_msg;
943 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
944 template (present) L1ctlDataReq tr_data := {
945 l1header := tr_l1h,
946 l2_payload := decmatch tr_frame
947 };
948
949 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
950 var octetstring data := dl_msg.payload.data_ind.payload;
951 l1h := dec_SacchL1Header(substr(data, 0, 2));
952 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
953 }
954}
955
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300956/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
957 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
958 * payload is treated as PDU_ML3_NW_MS. */
959private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
960 template (present) PDU_ML3_NW_MS tr_pdu := ?,
961 template (present) GsmSapi sapi := 0)
962runs on ConnHdlr {
963 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
964 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
965 var LapdmFrameAB lapdm_frame;
966
967 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
968 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
969 }
970}
971
Harald Welte93640c62018-02-25 16:59:33 +0100972/***********************************************************************
973 * Channel Activation / Deactivation
974 ***********************************************************************/
975
Harald Welte70767382018-02-21 12:16:40 +0100976/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700977private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100978 for (var integer i := 0; i < 500; i := i+1) {
979 f_rsl_chan_act(g_pars.chan_mode);
980 f_rsl_chan_deact();
981 }
982 setverdict(pass);
983}
984testcase TC_chan_act_stress() runs on test_CT {
985 var ConnHdlr vc_conn;
986 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200987 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100988 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
989 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100991}
992
993/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700994private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100995 f_rsl_chan_act(g_pars.chan_mode);
996 /* attempt to activate the same lchan again -> expect reject */
997 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
998 alt {
999 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +01001001 }
1002 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1003 setverdict(pass);
1004 }
1005 }
1006 f_rsl_chan_deact();
1007}
1008testcase TC_chan_act_react() runs on test_CT {
1009 var ConnHdlr vc_conn;
1010 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001011 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001012 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
1013 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001015}
1016
1017/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001018private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001019 timer T := 3.0;
1020 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1021 T.start;
1022 alt {
1023 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1024 setverdict(pass);
1025 }
1026 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001028 }
1029 }
1030}
1031testcase TC_chan_deact_not_active() runs on test_CT {
1032 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001033 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001034 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1035 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001037}
1038
1039/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001040private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001041 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1042 alt {
1043 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001045 }
1046 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1047 setverdict(pass);
1048 }
1049 }
1050}
1051private type record WrongChanNrCase {
1052 RslChannelNr chan_nr,
1053 charstring description
1054}
1055private type record of WrongChanNrCase WrongChanNrCases;
1056private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1057 chan_nr := chan_nr,
1058 description := desc
1059}
1060
1061testcase TC_chan_act_wrong_nr() runs on test_CT {
1062 var ConnHdlr vc_conn;
1063 var ConnHdlrPars pars;
1064
Harald Welte294b0a22018-03-10 23:26:48 +01001065 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001066
1067 var WrongChanNrCases wrong := {
1068 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1069 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1070 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1071 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1072 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1073 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1074 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1075 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1076 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1077 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1078 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1079 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1080 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1081 };
1082
1083 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1084 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1085 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1086 vc_conn.done;
1087 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001089}
1090
Harald Weltee613f962018-04-18 22:38:16 +02001091/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001092friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001093 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001094 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001095
1096 /* test on each of the channels we have */
1097 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1098 pars.chan_nr := valueof(g_AllChanTypes[i]);
1099
1100 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1101 vc_conn := f_start_handler(fn, pars);
1102 vc_conn.done;
1103 }
1104
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001106}
1107
Harald Welte93640c62018-02-25 16:59:33 +01001108/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001109 * SACCH handling
1110 ***********************************************************************/
1111
1112private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1113 timer T_sacch := 3.0;
1114 T_sacch.start;
1115 alt {
1116 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001118 }
1119 [not exp] T_sacch.timeout {
1120 setverdict(pass);
1121 }
1122 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1123 setverdict(pass);
1124 }
1125 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001127 }
1128 [] L1CTL.receive { repeat; }
1129 [] RSL.receive { repeat; }
1130 }
1131}
1132
1133/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1134private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1135 f_l1_tune(L1CTL);
1136 RSL.clear;
1137
1138 /* activate the logical channel */
1139 f_est_dchan();
1140 L1CTL.clear;
1141
1142 /* check that SACCH actually are received as expected */
1143 f_exp_sacch(true);
1144
1145 /* deactivate SACCH on the logical channel */
1146 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1147 f_sleep(1.0);
1148 L1CTL.clear;
1149
1150 /* check that no SACCH are received anymore */
1151 f_exp_sacch(false);
1152
1153 /* release the channel */
1154 f_rsl_chan_deact();
1155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1156}
1157testcase TC_deact_sacch() runs on test_CT {
1158 var ConnHdlr vc_conn;
1159 var ConnHdlrPars pars;
1160 f_init();
1161 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1162 //for (var integer i := 0; i < 1; i := i+1) {
1163 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1164 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1165 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1166 vc_conn.done;
1167 }
1168 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001170}
1171
Harald Welte55700662018-03-12 13:15:43 +01001172/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001173private function f_sacch_present(template octetstring l3_exp,
1174 boolean do_fail := true)
1175runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001176 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001177 timer T_sacch := 3.0;
1178 L1CTL.clear;
1179 T_sacch.start;
1180 alt {
1181 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1182 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1183 if (match(l3, l3_exp)) {
1184 setverdict(pass);
1185 } else {
1186 repeat;
1187 }
1188 }
1189 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001190 [not do_fail] T_sacch.timeout {
1191 log("Timeout waiting for SACCH ", l3_exp);
1192 }
1193 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001194 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001196 }
1197 }
1198}
1199
Harald Welte55700662018-03-12 13:15:43 +01001200/* verify that given SACCH payload is not present */
1201private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1202 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001203 timer T_sacch := 3.0;
1204 L1CTL.clear;
1205 T_sacch.start;
1206 alt {
1207 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1208 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1209 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001210 setverdict(fail, "Received unexpected SACCH ", dl);
1211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001212 } else {
1213 repeat;
1214 }
1215 }
1216 [] L1CTL.receive { repeat; }
1217 [] T_sacch.timeout {
1218 setverdict(pass);
1219 }
1220 }
1221}
1222
Harald Welte629cc6b2018-03-11 17:19:05 +01001223/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001224private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1225 /* Set a known default SACCH filling for SI5 */
1226 var octetstring si5 := f_rnd_octstring(19);
1227 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1228
1229 f_l1_tune(L1CTL);
1230 RSL.clear;
1231
1232 /* activate the logical channel */
1233 f_est_dchan();
1234
1235 /* check that the specified SI5 value is actually sent */
1236 f_sacch_present(si5);
1237
1238 /* release the channel */
1239 RSL.clear;
1240 f_rsl_chan_deact();
1241 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1242}
1243testcase TC_sacch_filling() runs on test_CT {
1244 var ConnHdlr vc_conn;
1245 var ConnHdlrPars pars;
1246 f_init();
1247 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1248 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1249 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1250 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1251 vc_conn.done;
1252 }
1253 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001255}
1256
Harald Welte629cc6b2018-03-11 17:19:05 +01001257/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001258private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1259 /* Set a known default SACCH filling for SI5 */
1260 var octetstring si5 := f_rnd_octstring(19);
1261 var octetstring si5_diff := f_rnd_octstring(19);
1262 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1263
1264 f_l1_tune(L1CTL);
1265 RSL.clear;
1266
1267 log("Activating channel, expecting standard SI5");
1268 /* activate the logical channel */
1269 f_est_dchan();
1270 /* check that the specified SI5 value is actually sent */
1271 f_sacch_present(si5);
1272
1273 /* set channel-specific different SI5 */
1274 log("Setting channel specific SACCH INFO, expecting it");
1275 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1276 /* check that the specified lchan-specific value is now used */
1277 f_sacch_present(si5_diff);
1278
1279 /* deactivate the channel and re-activate it, this should result in default SI5 */
1280 log("De-activating and re-activating channel, expecting standard SI5");
1281 f_rsl_chan_deact();
1282 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1283 /* Verify that the TRX-wide default SACCH filling is present again */
1284 f_sacch_present(si5);
1285
1286 /* release the channel */
1287 RSL.clear;
1288 f_rsl_chan_deact();
1289 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1290}
1291testcase TC_sacch_info_mod() runs on test_CT {
1292 var ConnHdlr vc_conn;
1293 var ConnHdlrPars pars;
1294 f_init();
1295 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1296 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1297 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1298 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1299 vc_conn.done;
1300 }
1301 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001303}
1304
Harald Welte075d84c2018-03-12 13:07:24 +01001305/* Test SACCH scheduling of multiple different SI message types */
1306private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1307 var octetstring si5 := f_rnd_octstring(19);
1308 var octetstring si5bis := f_rnd_octstring(19);
1309 var octetstring si5ter := f_rnd_octstring(19);
1310 var octetstring si6 := f_rnd_octstring(19);
1311
1312 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1313 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1314 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1315 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1316
1317 f_l1_tune(L1CTL);
1318 RSL.clear;
1319
1320 /* activate the logical channel */
1321 f_est_dchan();
1322 L1CTL.clear;
1323
1324 /* check that SACCH actually are received as expected */
1325 f_sacch_present(si5);
1326 f_sacch_present(si5bis);
1327 f_sacch_present(si5ter);
1328 f_sacch_present(si6);
1329
1330 /* release the channel */
1331 f_rsl_chan_deact();
1332 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1333}
1334testcase TC_sacch_multi() runs on test_CT {
1335 var ConnHdlr vc_conn;
1336 var ConnHdlrPars pars;
1337 f_init();
1338 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1339 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1340 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1341 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1342 vc_conn.done;
1343 }
1344 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001346}
1347
Harald Welte55700662018-03-12 13:15:43 +01001348/* Test if SACH information is modified as expected */
1349private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1350 var octetstring si5 := f_rnd_octstring(19);
1351 var octetstring si6 := f_rnd_octstring(19);
1352
1353 /* First, configure both SI5 and SI6 to be transmitted */
1354 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1355 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1356
1357 f_l1_tune(L1CTL);
1358 RSL.clear;
1359
1360 /* activate the logical channel */
1361 f_est_dchan();
1362 L1CTL.clear;
1363
1364 /* check that SACCH actually are received as expected */
1365 f_sacch_present(si5);
1366 f_sacch_present(si6);
1367
1368 /* disable SI6 */
1369 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1370
1371 /* check that SI5 is still transmitted */
1372 f_sacch_present(si5);
1373 /* check if SI6 is now gone */
1374 f_sacch_missing(si6);
1375
1376 /* release the channel */
1377 f_rsl_chan_deact();
1378 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1379}
1380testcase TC_sacch_multi_chg() runs on test_CT {
1381 var ConnHdlr vc_conn;
1382 var ConnHdlrPars pars;
1383 f_init();
1384 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1385 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1386 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1387 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1388 vc_conn.done;
1389 }
1390 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001392}
1393
Harald Weltec8d363c2019-05-19 20:36:48 +02001394/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1395private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1396 var octetstring si5 := f_rnd_octstring(19);
1397 var octetstring si6 := f_rnd_octstring(19);
1398 var octetstring si5_specific := f_rnd_octstring(19);
1399 var octetstring si6_specific := f_rnd_octstring(19);
1400
1401 /* First, configure both SI5 and SI6 to be transmitted */
1402 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1403 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1404
1405 f_l1_tune(L1CTL);
1406 RSL.clear;
1407
1408 /* activate channel with different SACCH filling */
1409 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1410 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1411 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1412 }));
1413 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1414 RSL_IE_Body:{sacch_info := sacch_info})) };
1415 f_est_dchan(more_ies := addl_ies);
1416
1417 /* check that SACCH actually are received as expected */
1418 f_sacch_present(si5_specific);
1419 f_sacch_present(si6_specific);
1420
1421 /* release the channel */
1422 f_rsl_chan_deact();
1423 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1424}
1425testcase TC_sacch_chan_act() runs on test_CT {
1426 var ConnHdlr vc_conn;
1427 var ConnHdlrPars pars;
1428 f_init();
1429
1430 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1431 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1432 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1433 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1434 vc_conn.done;
1435 }
1436 /* TODO: do the above in parallel, rather than sequentially? */
1437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1438}
1439
Harald Welte8b01c792019-05-19 22:51:25 +02001440/* verify that SACCH DL transmission is started only if MS power IE present
1441 * see section 4.1.3 of 3GPP TS 48.058 */
1442private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1443 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001444 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001445
1446 f_l1_tune(L1CTL);
1447 RSL.clear;
1448
1449 /* Step 1: Activate ASYNC HO channel without MS power IE */
1450
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001451 var integer ho_ref := oct2int(f_rnd_octstring(1));
1452 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1453 RSL_IE_Body:{ handover_ref := ho_ref }));
1454 var RSL_IE_List addl_ies := {
1455 ho_ref_ie
1456 };
1457
Harald Welte8b01c792019-05-19 22:51:25 +02001458 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001459 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 +02001460 /* 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 no DL SACCH is being received */
1465 f_sacch_missing(?);
1466
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001467 /* Send handover Access Burst and expect SACCH to start */
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
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001475 /* Tune back to CCCH/BCCH */
1476 f_l1_tune(L1CTL);
1477
Harald Welte8b01c792019-05-19 22:51:25 +02001478
1479 /* Step 2: Activate ASYNC HO channel with MS power IE */
1480
1481 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001482 addl_ies := {
1483 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001484 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1485 };
1486 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1487 /* don't perform immediate assignment here, as we're testing non-IA case */
1488 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001489 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001490
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001491 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1492 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1493 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001494
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001495 /* Send handover Access Burst and expect SACCH to remain present */
1496 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1497
1498 f_sacch_present(si5);
1499
Harald Welte8b01c792019-05-19 22:51:25 +02001500 f_rsl_chan_deact();
1501 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1502}
1503testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1504 var ConnHdlr vc_conn;
1505 var ConnHdlrPars pars;
1506 f_init();
1507
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001508 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1509 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1510 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001511 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1512 vc_conn.done;
1513 }
1514 /* TODO: do the above in parallel, rather than sequentially? */
1515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1516}
1517
1518/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1519 * see section 4.1.4 of 3GPP TS 48.058 */
1520private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1521 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001522 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1523
Harald Welte8b01c792019-05-19 22:51:25 +02001524 var RSL_IE_List addl_ies;
1525
1526 f_l1_tune(L1CTL);
1527 RSL.clear;
1528
1529 /* Step 1: Activate SYNC HO channel without MS power IE */
1530
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001531 var integer ho_ref := oct2int(f_rnd_octstring(1));
1532 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1533 RSL_IE_Body:{ handover_ref := ho_ref }));
1534 addl_ies := {
1535 ho_ref_ie
1536 };
1537
Harald Welte8b01c792019-05-19 22:51:25 +02001538 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001539 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 +02001540 /* don't perform immediate assignment here, as we're testing non-IA case */
1541 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001542 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001543
1544 /* Verify that no DL SACCH is being received */
1545 f_sacch_missing(?);
1546
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001547 /* Send handover Access Burst and expect SACCH to start */
1548 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1549
1550 f_sacch_present(si5);
1551
Harald Welte8b01c792019-05-19 22:51:25 +02001552 f_rsl_chan_deact();
1553 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1554
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001555 /* Tune back to CCCH/BCCH */
1556 f_l1_tune(L1CTL);
1557
Harald Welte8b01c792019-05-19 22:51:25 +02001558
1559 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1560
1561 /* Activate channel on BTS side */
1562 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001563 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001564 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1565 };
1566 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1567 /* don't perform immediate assignment here, as we're testing non-IA case */
1568 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001569 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001570
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001571 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1572 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1573 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001574
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001575 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001576 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1577
1578 f_sacch_present(si5);
1579
Harald Welte8b01c792019-05-19 22:51:25 +02001580 f_rsl_chan_deact();
1581 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1582
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001583 /* Tune back to CCCH/BCCH */
1584 f_l1_tune(L1CTL);
1585
Harald Welte8b01c792019-05-19 22:51:25 +02001586
1587 /* Step 2b: Activate SYNC HO channel with TA IE */
1588
1589 /* Activate channel on BTS side */
1590 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001591 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001592 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1593 };
1594 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1595 /* don't perform immediate assignment here, as we're testing non-IA case */
1596 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001597 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001598
1599 /* Verify that no DL SACCH is being received */
1600 f_sacch_missing(?);
1601
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001602 /* Send handover Access Burst and expect SACCH to start */
1603 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1604
1605 f_sacch_present(si5);
1606
Harald Welte8b01c792019-05-19 22:51:25 +02001607 f_rsl_chan_deact();
1608 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1609
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001610 /* Tune back to CCCH/BCCH */
1611 f_l1_tune(L1CTL);
1612
Harald Welte8b01c792019-05-19 22:51:25 +02001613
1614 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1615
1616 /* Activate channel on BTS side */
1617 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001618 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001619 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1620 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1621 };
1622 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1623 /* don't perform immediate assignment here, as we're testing non-IA case */
1624 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001625 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001626
1627 /* Verify that DL SACCH is being received */
1628 f_sacch_present(si5);
1629
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001630 /* Send handover Access Burst and expect SACCH to remain present */
1631 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1632
1633 f_sacch_present(si5);
1634
Harald Welte8b01c792019-05-19 22:51:25 +02001635 f_rsl_chan_deact();
1636 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1637}
1638testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1639 var ConnHdlr vc_conn;
1640 var ConnHdlrPars pars;
1641 f_init();
1642
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001643 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1644 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1645 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001646 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1647 vc_conn.done;
1648 }
1649 /* TODO: do the above in parallel, rather than sequentially? */
1650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1651}
Harald Welte629cc6b2018-03-11 17:19:05 +01001652
1653
1654/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001655 * RACH Handling
1656 ***********************************************************************/
1657
Harald Welte8c24c2b2018-02-26 08:31:31 +01001658/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001659private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001660 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001661 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001662 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001663
Harald Welte8c24c2b2018-02-26 08:31:31 +01001664 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001665 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001666 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001667 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001668 if (emerg == true) {
1669 ra := f_rnd_ra_emerg();
1670 } else {
1671 ra := f_rnd_ra_cs();
1672 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001673 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1674 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001676 }
1677 fn_last := fn;
1678
1679 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001680 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001681 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001682 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001683 T.stop;
1684 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001685 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001687 }
1688 [] RSL_CCHAN.receive { repeat; }
1689 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001690 test_failed := true;
1691 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001692 }
1693 }
1694 }
Maxba06feb2019-03-05 10:52:46 +01001695 if (test_failed) {
1696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001697 }
Maxba06feb2019-03-05 10:52:46 +01001698 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001700}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001701
Philipp Maier16ade782020-07-08 21:36:00 +02001702/* Normal variant */
1703testcase TC_rach_content() runs on test_CT {
1704 f_TC_rach_content(emerg := false);
1705}
1706
1707/* Emergency call variant */
1708testcase TC_rach_content_emerg() runs on test_CT {
1709 f_TC_rach_content(emerg := true);
1710}
1711
Harald Welte8c24c2b2018-02-26 08:31:31 +01001712/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1713testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001714 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001715 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001716 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717 f_l1_tune(L1CTL);
1718
1719 var GsmFrameNumber fn_last := 0;
1720 for (var integer i := 0; i < 1000; i := i+1) {
1721 var OCT1 ra := f_rnd_ra_cs();
1722 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1723 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001725 }
1726 fn_last := fn;
1727 }
1728 var integer rsl_chrqd := 0;
1729 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001730 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001731 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001732 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001733 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001734 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001735 repeat;
1736 }
1737 [] RSL_CCHAN.receive { repeat; }
1738 [] T.timeout { }
1739 }
1740 if (rsl_chrqd == 1000) {
1741 setverdict(pass);
1742 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001744 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001746}
1747
Harald Welte3453ab42019-05-24 21:19:58 +02001748private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1749 var charstring bts_str := "bts " & int2str(bts_nr);
1750 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1751}
1752
1753/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1754private template integer tr_rach_slots_per_interval := (90 .. 130);
1755
1756/* Expect 0 RACH load on an idle BTS that has just started up */
1757testcase TC_rach_load_idle_thresh0() runs on test_CT {
1758 var ASP_RSL_Unitdata rx_ud;
1759
1760 f_init_vty_bsc();
1761 /* send load indications even at 0% load */
1762 f_vty_load_ind_thresh(0);
1763 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1764 f_sleep(2.0);
1765
1766 f_init();
1767
Harald Weltee37f9a52020-10-11 20:45:23 +02001768 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1769 alt {
1770 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1771 [] RSL_CCHAN.receive { repeat }
1772 }
1773
Harald Welte3453ab42019-05-24 21:19:58 +02001774 timer T := 5.0;
1775 T.start;
1776 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001777 [] 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 +02001778 setverdict(pass);
1779 repeat;
1780 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001781 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001782 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1783 repeat;
1784 }
1785 [] RSL_CCHAN.receive {
1786 repeat;
1787 }
1788 [] T.timeout { }
1789 }
1790
1791 f_vty_load_ind_thresh(10);
1792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1793}
1794
1795/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1796testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1797 var ASP_RSL_Unitdata rx_ud;
1798
1799 f_init_vty_bsc();
1800 f_init();
1801
1802 timer T := 5.0;
1803 T.start;
1804 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001805 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001806 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1807 repeat;
1808 }
1809 [] RSL_CCHAN.receive {
1810 repeat;
1811 }
1812 [] T.timeout {
1813 setverdict(pass);
1814 }
1815 }
1816
1817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1818}
1819
1820/* Expect 0 RACH load on an idle BTS that has just started up */
1821testcase TC_rach_load_count() runs on test_CT {
1822 var ASP_RSL_Unitdata rx_ud;
1823 var integer load_access_count := 0;
1824
1825 f_init_vty_bsc();
1826 /* send load indications even at 0% load */
1827 f_vty_load_ind_thresh(0);
1828 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1829 f_sleep(2.0);
1830 f_init();
1831
1832 f_init_l1ctl();
1833 f_sleep(1.0);
1834 f_l1_tune(L1CTL);
1835
Harald Welte52ae1682020-10-11 20:45:55 +02001836 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1837 alt {
1838 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1839 [] RSL_CCHAN.receive { repeat }
1840 }
1841
Harald Welte3453ab42019-05-24 21:19:58 +02001842 var GsmFrameNumber fn_last := 0;
1843 for (var integer i := 0; i < 1000; i := i+1) {
1844 var OCT1 ra := f_rnd_ra_cs();
1845 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1846 if (fn == fn_last) {
1847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1848 }
1849 fn_last := fn;
1850 }
1851
1852 timer T := 5.0;
1853 T.start;
1854 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001855 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001856 -> value rx_ud {
1857 var RSL_IE_Body ie;
1858 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1859 load_access_count := load_access_count + ie.rach_load.access_count;
1860 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1861 setverdict(fail, "Access count cannot be < Busy count");
1862 }
1863 repeat;
1864 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001865 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001866 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1867 repeat;
1868 }
1869 [] RSL_CCHAN.receive {
1870 repeat;
1871 }
1872 [] T.timeout { }
1873 }
1874 if (load_access_count == 1000) {
1875 setverdict(pass);
1876 } else {
1877 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1878 }
1879
1880 f_vty_load_ind_thresh(10);
1881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1882}
1883
Harald Welte54a2a2d2018-02-26 09:14:05 +01001884private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001885 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001886 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001887 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001888 f_sleep(0.5);
1889
1890 /* Transmit RACH request + wait for confirmation */
1891 var OCT1 ra := f_rnd_ra_cs();
1892 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1893
1894 /* Check for expected result */
1895 timer T := 1.5;
1896 T.start;
1897 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001898 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001899 setverdict(pass);
1900 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001901 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001903 }
1904 [] RSL_CCHAN.receive { repeat; }
1905 [not expect_pass] T.timeout {
1906 setverdict(pass);
1907 }
1908 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001910 }
1911 }
1912}
1913
1914/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1915testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001916 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001917 f_init_l1ctl();
1918 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001919 f_sleep(1.0);
1920
1921 /* default max-ta is 63 (full range of GSM timing advance */
1922
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001923 /* We allow early arrival up to 2 symbols */
1924 f_rach_toffs(-1*256, true);
1925 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001926 f_rach_toffs(-10*256, false);
1927
1928 /* 0 / 32 / 63 bits is legal / permitted */
1929 f_rach_toffs(0, true);
1930 f_rach_toffs(32*256, true);
1931 f_rach_toffs(63*256, true);
1932
1933 /* more than 63 bits is not legal / permitted */
1934 f_rach_toffs(64*256, false);
1935 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001937}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001938
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001939private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001940 var GsmFrameNumber fn;
1941 var RSL_Message rm;
1942
1943 f_l1_tune(L1CTL);
1944 RSL.clear;
1945
1946 /* Generate a random Handover Reference */
1947 var integer ho_ref := oct2int(f_rnd_octstring(1));
1948
1949 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1950 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1951 RSL_IE_Body:{ handover_ref := ho_ref }));
1952
1953 /* Activate a channel on the BTS side (no encryption) */
1954 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1955 act_type := t_RSL_IE_ActType_HO_SYNC);
1956
1957 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1958 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001959 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001960
1961 /* Send handover Access Burst */
1962 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1963
1964 /* TODO: test mismatching Handover Reference, and missing IE */
1965
1966 /* Wait for handover detection */
1967 timer T := 3.0;
1968 T.start;
1969 alt {
1970 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1971 log("Handover RACH has been detected: ", rm);
1972 setverdict(pass);
1973 }
1974 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1976 log2str("RSL_CHAN_RQD was not expected: ", rm));
1977 }
1978 [] RSL.receive { repeat; }
1979 [] T.timeout {
1980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1981 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1982 }
1983 }
1984
1985 /* Release the channel */
1986 f_rsl_chan_deact();
1987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1988}
1989
1990/* Test handover RACH detection */
1991testcase TC_ho_rach() runs on test_CT {
1992 var ConnHdlrPars pars;
1993 var ConnHdlr vc_conn;
1994
1995 f_init();
1996
1997 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1998 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1999 log(testcasename(), ": Starting for ", g_AllChannels[i]);
2000 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
2001 vc_conn.done;
2002 }
2003
2004 /* TODO: do the above in parallel, rather than sequentially? */
2005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2006}
2007
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03002008/* Test sending of the RR Physical Information message on DCCH */
2009private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
2010 var PDU_ML3_NW_MS dcch_pdu;
2011 var integer count := 0;
2012 var L1ctlDlMessage dl;
2013 timer T;
2014
2015 f_l1_tune(L1CTL);
2016 RSL.clear;
2017
2018 /* Generate a random Handover Reference */
2019 var integer ho_ref := oct2int(f_rnd_octstring(1));
2020
2021 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
2022 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
2023 RSL_IE_Body:{ handover_ref := ho_ref }));
2024
2025 /* Activate a channel on the BTS side (no encryption) */
2026 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2027 act_type := t_RSL_IE_ActType_HO_SYNC);
2028
2029 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2030 * waiting for Immediate Assignment and sending of an Access Burst. */
2031 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2032
2033 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2034 * context means any L2 frames, not only the RR Physical Information. */
2035 T.start(2.0);
2036 L1CTL.clear;
2037 alt {
2038 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2039 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2040 T.stop;
2041 }
2042 [] L1CTL.receive { repeat; }
2043 [] T.timeout { setverdict(pass); }
2044 }
2045
2046 /* Send handover Access Burst */
2047 log("Sending handover Access Burst");
2048 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2049
2050 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2051 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2052 L1CTL.clear;
2053 alt {
2054 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2055 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2056 log("Rx RR Physical Information: ", dcch_pdu);
2057 /* Wait until the count reaches Ny1 */
2058 count := count + 1;
2059 if (count < mp_ho_ny1)
2060 { repeat; }
2061 setverdict(pass);
2062 }
2063 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2064 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066 }
2067 [] L1CTL.receive { repeat; }
2068 [] T.timeout {
2069 setverdict(fail, "Timeout waiting for RR Physical Information");
2070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2071 }
2072 }
2073
2074 /* Release the channel */
2075 f_rsl_chan_deact();
2076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2077}
2078testcase TC_ho_physical_info() runs on test_CT {
2079 var ConnHdlrPars pars;
2080 var ConnHdlr vc_conn;
2081
2082 f_init();
2083
2084 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2085 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2086 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2087 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2088 vc_conn.done;
2089 }
2090
2091 /* TODO: do the above in parallel, rather than sequentially? */
2092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2093}
2094
Harald Welte93640c62018-02-25 16:59:33 +01002095/***********************************************************************
2096 * Measurement Processing / Reporting
2097 ***********************************************************************/
2098
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002099private template (value) LapdmAddressField
2100ts_LapdmAddr(template (value) LapdmSapi sapi,
2101 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002102 spare := '0'B,
2103 lpd := 0,
2104 sapi := sapi,
2105 c_r := c_r,
2106 ea := true
2107}
2108
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002109private template (value) LapdmFrameAB
2110ts_LAPDm_AB(template (value) LapdmSapi sapi,
2111 template (value) GsmRrL3Message l3,
2112 template (value) boolean c_r := false,
2113 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002114 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002115 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002116 len := 0, /* overwritten */
2117 m := false,
2118 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002119 payload := enc_GsmRrL3Message(valueof(l3)),
2120 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002121}
2122
2123/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002124private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002125 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002126 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002127
Harald Weltef8df4cb2018-03-10 15:15:08 +01002128 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002129 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002130
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002131 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002132 g_pars.l1_pars.meas_ul.full.rxlev,
2133 g_pars.l1_pars.meas_ul.sub.rxlev,
2134 g_pars.l1_pars.meas_ul.full.rxqual,
2135 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002136 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002137
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002138 var template (value) SacchL1Header l1h := ts_SacchL1Header(
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07002139 g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002140
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002141 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2142 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002143
2144 log("Sending Measurement Report: ", l1h, l2);
2145 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002146 repeat;
2147 }
2148}
2149
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002150/* handle incoming downlink SACCH, decode the L1 header into the given record */
2151private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2152 boolean do_apply := true)
2153runs on ConnHdlr
2154{
2155 var L1ctlDlMessage l1_dl;
2156
2157 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2158 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2159 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2160 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2161
2162 if (do_apply) {
2163 /* Update TA and MS power to follow what BTS requests */
2164 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2165 }
2166 }
2167}
2168
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002169private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002170 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002171 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002172 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2173 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002174 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2175 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002176 repeat;
2177 }
2178}
2179
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002180private altstep as_l1_tch_loop() runs on ConnHdlr {
2181 var L1ctlDlMessage l1_dl;
2182 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2183 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002184
2185 /* occasionaly inject FACCH frames into the uplink */
2186 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2187 var octetstring pl := '010301'O;
2188 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2189 f_pad_oct(pl, 23, '2B'O)));
2190 } else {
2191 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2192 l1_dl.payload.traffic_ind.data));
2193 }
2194
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002195 repeat;
2196 }
2197}
2198
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002199private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002200 uint6_t rxlev,
2201 uint3_t rxqual
2202}
2203
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002204private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002205 MeasElem full,
2206 MeasElem sub
2207}
2208
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002209private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002210 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002211 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002212 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002213 MeasElemFS meas_ul,
2214 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002215 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002216 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002217 uint8_t ms_actual_ta,
2218 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002219}
2220
2221/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2222private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2223 return 63 + (toffs256s/256);
2224}
2225
Harald Welted5684392018-03-10 18:22:04 +01002226private function f_max(integer a, integer b) return integer {
2227 if (a > b) {
2228 return a;
2229 } else {
2230 return b;
2231 }
2232}
2233
2234private function f_min(integer a, integer b) return integer {
2235 if (a < b) {
2236 return a;
2237 } else {
2238 return b;
2239 }
2240}
2241
2242/* compute negative tolerance val-tolerance, ensure >= min */
2243private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2244 val := val - tolerance;
2245 return f_max(val, min);
2246}
2247
2248/* compute positive tolerance val+tolerance, ensure <= max */
2249private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2250 val := val + tolerance;
2251 return f_min(val, max);
2252}
2253
2254/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2255private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2256return template integer {
2257 var template integer ret;
2258 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2259 return ret;
2260}
2261
2262
Harald Welte70767382018-02-21 12:16:40 +01002263/* build a template for matching measurement results against */
2264private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2265 var ConnL1Pars l1p := g_pars.l1_pars;
2266 var template RSL_IE_UplinkMeas ul_meas := {
2267 len := 3,
2268 rfu := '0'B,
2269 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002270 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002271 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002272 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002273 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002274 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2275 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002276 supp_meas_info := omit
2277 };
Harald Welte685d5982018-02-27 20:42:05 +01002278 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002279 ul_meas.len := (3+8);
2280 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002281 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002282 toa256_min := ?,
2283 toa256_max := ?,
2284 toa256_std_dev := ?
2285 }
Harald Welte685d5982018-02-27 20:42:05 +01002286 }
Harald Welte70767382018-02-21 12:16:40 +01002287 var template RSL_IE_BS_Power bs_power := {
2288 reserved := 0,
2289 epc := false,
2290 fpc := false,
2291 power_level := l1p.bs_power_level
2292 };
2293 var template RSL_IE_L1Info l1_info := {
2294 ms_power_lvl := l1p.ms_power_level,
2295 fpc := false,
2296 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002297 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002298 };
2299 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002300 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002301 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2302 ?, t_toffs);
2303}
2304
Philipp Maierdd841d32019-12-17 14:44:54 +01002305/* build a template for matching measurement results that do not contain any
2306 * MS related measurement (l1_info, l3_info and ms timing offset). */
2307private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2308 var ConnL1Pars l1p := g_pars.l1_pars;
2309 var template RSL_IE_UplinkMeas ul_meas := {
2310 len := 3,
2311 rfu := '0'B,
2312 dtx_d := l1p.dtx_enabled,
2313 rxlev_f_u := ?,
2314 reserved1 := '00'B,
2315 rxlev_s_u := ?,
2316 reserved2 := '00'B,
2317 rxq_f_u := ?,
2318 rxq_s_u := ?,
2319 supp_meas_info := omit
2320 };
2321 if (l1p.toa256_enabled) {
2322 ul_meas.len := (3+8);
2323 ul_meas.supp_meas_info := {
2324 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2325 toa256_min := ?,
2326 toa256_max := ?,
2327 toa256_std_dev := ?
2328 }
2329 }
2330 var template RSL_IE_BS_Power bs_power := {
2331 reserved := 0,
2332 epc := false,
2333 fpc := false,
2334 power_level := l1p.bs_power_level
2335 };
2336
2337 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2338}
2339
Harald Welte70767382018-02-21 12:16:40 +01002340/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002341private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002342 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002343 var boolean chan_est := false;
2344
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002345 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002346
2347 /* Receive osmocom specific measurement reports. This is the normal
2348 * case. Here we verify that the measurement reports we sent are
2349 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002350 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2351 /* increment counter of next to-be-expected meas rep */
2352 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2353 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002354 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002355
2356 /* The following two cases may only happen in the beginning
2357 * of the channel establishment phase. Once we have received
2358 * the "our" measurement report the first time, the channel
2359 * is established and empty or hardcoded TRXCON reports must
2360 * not occur anymore. */
2361 chan_est := true;
2362
2363 repeat;
2364 }
2365
2366 /* When the BTS has established the channel, the MS might need slightly
2367 * more time to establish the channel and actually start sending. The
2368 * result is then a measurement report that just lacks the measurement
2369 * information of the MS. This is normal and we tolerate this behavior. */
2370 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2371 /* increment counter of next to-be-expected meas rep */
2372 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2373 /* Re-start the timer expecting the next MEAS RES */
2374 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002375 repeat;
2376 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002377
2378 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2379 * measurements if the TTCN3 side does not supply measurement input in
2380 * time. In those cases TRXCON will either use a cached measurement
2381 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2382 * report the templates above will not match. We tolerate this
2383 * behavior, but only once. */
2384 [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 +01002385 /* increment counter of next to-be-expected meas rep */
2386 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2387 if (g_first_meas_res) {
2388 g_first_meas_res := false;
2389 repeat;
2390 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002392 }
Harald Welte70767382018-02-21 12:16:40 +01002393 }
2394 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002396 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002397 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002399 }
2400}
2401
Harald Weltee613f962018-04-18 22:38:16 +02002402private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2403 select (rsl_alg_id) {
2404 case (RSL_ALG_ID_A5_0) { return 0; }
2405 case (RSL_ALG_ID_A5_1) { return 1; }
2406 case (RSL_ALG_ID_A5_2) { return 2; }
2407 case (RSL_ALG_ID_A5_3) { return 3; }
2408 case (RSL_ALG_ID_A5_4) { return 4; }
2409 case (RSL_ALG_ID_A5_5) { return 5; }
2410 case (RSL_ALG_ID_A5_6) { return 6; }
2411 case (RSL_ALG_ID_A5_7) { return 7; }
2412 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2414 /* Make compiler happy by calling mtc.stop here. It is already
2415 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002416 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002417 }
2418 }
2419}
2420
2421private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2422 select (rsl_alg_id) {
2423 case (RSL_ALG_ID_A5_1) { return '000'B; }
2424 case (RSL_ALG_ID_A5_2) { return '001'B; }
2425 case (RSL_ALG_ID_A5_3) { return '010'B; }
2426 case (RSL_ALG_ID_A5_4) { return '011'B; }
2427 case (RSL_ALG_ID_A5_5) { return '100'B; }
2428 case (RSL_ALG_ID_A5_6) { return '101'B; }
2429 case (RSL_ALG_ID_A5_7) { return '110'B; }
2430 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2432 /* Make compiler happy by calling mtc.stop here. It is already
2433 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002434 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002435 }
2436 }
2437}
2438
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002439/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2440private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2441 var GsmFrameNumber fn;
2442 timer T := 8.0;
2443
2444 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2445 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2446
2447 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2448 /* Send the actual RACH */
2449 fn := f_L1CTL_RACH(L1CTL, ra);
2450
2451 T.start;
2452 alt {
2453 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2454 [] T.timeout {
2455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2456 }
2457 }
2458 T.stop
2459 return fn;
2460}
Harald Weltee613f962018-04-18 22:38:16 +02002461
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002462/* Tune to a dedicated channel: L1CTL only */
2463private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002464 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002465 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002466 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002467 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002468 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002469 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002470 pars.fhp.maio_hsn.hsn,
2471 pars.fhp.maio_hsn.maio,
2472 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002473 }
2474}
2475
Harald Welte70767382018-02-21 12:16:40 +01002476/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002477private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002478 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002479
2480 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002481 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002482
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002483 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002484 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002485 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002486 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002487 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2488 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002489 }
2490
Harald Welte70767382018-02-21 12:16:40 +01002491 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002492 f_l1ctl_est_dchan(L1CTL, g_pars);
2493
Harald Weltee613f962018-04-18 22:38:16 +02002494 /* enable encryption, if requested */
2495 if (encr_enable) {
2496 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2497 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2498 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002499
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002500 /* Send TCH Mode Request to the L1 if needed */
2501 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2502 var L1ctlTchMode tch_mode;
2503
2504 select (g_pars.chan_mode.coding_alg_rate) {
2505 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2506 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2507 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2508 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2509 case else {
2510 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2511 " is not supported by the L1, falling back to signalling");
2512 tch_mode := L1CTL_CHAN_MODE_SIGN;
2513 }
2514 }
2515
2516 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2517 }
2518
Harald Weltefa45e9e2018-03-10 18:59:03 +01002519 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002520}
2521
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002522/* Initialize and start the RTP emulation component for a ConnHdlr */
2523friend function f_rtpem_activate(inout octetstring payload,
2524 RtpemConfig cfg := c_RtpemDefaultCfg,
2525 RtpemMode mode := RTPEM_MODE_BIDIR)
2526runs on ConnHdlr {
2527 /* Step 0: initialize, connect and start the emulation component */
2528 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2529 map(vc_RTPEM:RTP, system:RTP);
2530 map(vc_RTPEM:RTCP, system:RTCP);
2531 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2532 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2533 vc_RTPEM.start(RTP_Emulation.f_main());
2534
2535 /* Step 1: configure the RTP parameters */
2536 var integer payload_len := 0;
2537 var octetstring hdr := ''O;
2538
2539 select (g_pars.chan_mode) {
2540 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2541 { payload_len := 33; hdr := 'D0'O; }
2542 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2543 { payload_len := 15; hdr := '00'O; }
2544 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2545 { payload_len := 31; hdr := 'C0'O; }
2546 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2547 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2549 }
2550 }
2551
2552 /* Pad the payload to conform the expected length */
2553 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2554 cfg.tx_fixed_payload := payload;
2555 f_rtpem_configure(RTPEM_CTRL, cfg);
2556
2557 /* Step 2: bind the RTP emulation to the configured address */
2558 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2559 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2560
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002561 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2562 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2563 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2564 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2565 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002566 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2567 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002568 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002569
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002570 /* Step 3b: send MDCX with the configured address/port to the IUT */
2571 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2572 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2573 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2574 remote_port := rtpem_bind_port,
2575 rtp_pt2 := 0),
2576 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2577 "IPA MDCX ACK");
2578
2579 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2580 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2581 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2582 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002583
2584 /* Step 5: set the given RTP emulation mode */
2585 f_rtpem_mode(RTPEM_CTRL, mode);
2586}
2587
Harald Welte70767382018-02-21 12:16:40 +01002588/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002589private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002590 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002591 RSL.clear;
2592
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002593 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002594 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002595 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002596 }
Harald Welte70767382018-02-21 12:16:40 +01002597
2598 f_est_dchan();
2599
2600 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2601 * RSL measurement reports on Abis side */
2602 timer T := 8.0;
2603 T.start;
2604 alt {
2605 [] as_l1_sacch();
2606 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002607 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002608 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002609 [] L1CTL.receive { repeat; }
2610 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002611 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002612 * of any earlier errors, so if we reach this timeout, we're good */
2613 setverdict(pass);
2614 }
2615 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002617 }
2618 }
2619 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002620 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002621}
Harald Welte0472ab42018-03-12 15:02:26 +01002622
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002623/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2624private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002625 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002626 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2627 timer Tup := 10.0;
2628 Tup.start;
2629 alt {
2630 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2631 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2632 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002633
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002634 if (rx_lvl != max_rx_lvl) {
2635 repeat;
2636 }
2637 Tup.stop;
2638 }
2639 [] L1CTL.receive { repeat; }
2640 [] Tup.timeout {
2641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2642 log2str("Didn't reach full power ", max_rx_lvl));
2643 }
2644 }
2645 return max_rx_lvl;
2646}
2647
2648/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2649private function f_verify_ramp_up() runs on ConnHdlr {
2650 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002651 var integer initial_rx_lvl := -1;
2652 var integer last_rx_lvl := -1;
2653 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2654
2655 timer T := 2.0;
2656 alt {
2657 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2658 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2659 log("Received rx_level=", rx_lvl);
2660 if (initial_rx_lvl == -1) {
2661 initial_rx_lvl := rx_lvl;
2662 last_rx_lvl := rx_lvl;
2663
2664 /* Expect a somehow low value during first received messages */
2665 if (initial_rx_lvl >= max_rx_lvl / 2) {
2666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2667 log2str("Detected high initial tx power during ramp up: ",
2668 initial_rx_lvl , ", full power is", max_rx_lvl));
2669 }
2670 }
2671
2672 /* received Rx level bigger than maximum allowed power by CN */
2673 if (rx_lvl > max_rx_lvl) {
2674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2675 log2str("Detected Tx power higher than full power: ",
2676 rx_lvl , " > ", max_rx_lvl));
2677 }
2678
2679 /* Make sure it never decreases, since we are rumping up */
2680 if (last_rx_lvl > rx_lvl) {
2681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2682 log2str("Detected Tx power decrease during ramp up: ",
2683 last_rx_lvl , " -> ", rx_lvl));
2684 }
2685
2686 if (rx_lvl == max_rx_lvl and not T.running) {
2687 /* We reached the maximum power, start timer and receive
2688 /* a few more to make sure we don't surpass it */
2689 log("Reached full power, wating a bit more until success");
2690 T.start;
2691 }
2692
2693 last_rx_lvl := rx_lvl;
2694 repeat;
2695 }
2696 [] L1CTL.receive { repeat; }
2697 [] T.timeout { }
2698 }
2699
2700 /* We didn't increase tx power during ramp up */
2701 if (initial_rx_lvl < last_rx_lvl) {
2702 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2703 } else {
2704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2705 log2str("No Tx power increase during whole ramp up: ",
2706 initial_rx_lvl , " -> ", last_rx_lvl));
2707 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002708}
2709
2710/* verify BTS ramps power down to rx_level 0 */
2711private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2712 var L1ctlDlMessage l1_dl;
2713 var integer last_rx_lvl := max_rx_lvl;
2714
2715 timer Tdown := 5.0;
2716 Tdown.start;
2717 alt {
2718 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2719 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2720 log("Received rx_level=", rx_lvl);
2721
2722 /* received Rx level bigger than maximum allowed power by CN */
2723 if (rx_lvl > max_rx_lvl) {
2724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2725 log2str("Detected Tx power higher than full power: ",
2726 rx_lvl , " > ", max_rx_lvl));
2727 }
2728
2729 /* Make sure it never increases, since we are rumping down */
2730 if (last_rx_lvl < rx_lvl) {
2731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2732 log2str("Detected Tx power increase during ramp up: ",
2733 last_rx_lvl , " -> ", rx_lvl));
2734 }
2735
2736 last_rx_lvl := rx_lvl;
2737 if (last_rx_lvl != 0) {
2738 repeat;
2739 }
2740 /* we reached power level 0, we are done */
2741 Tdown.stop;
2742 }
2743 [] L1CTL.receive { repeat; }
2744 [] Tdown.timeout { }
2745 }
2746
2747 /* We didn't increase tx power during ramp down */
2748 if (max_rx_lvl > last_rx_lvl) {
2749 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2750 } else {
2751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2752 log2str("No Tx power decrease during whole ramp down: ",
2753 max_rx_lvl , " -> ", last_rx_lvl));
2754 }
2755}
2756
2757/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002758private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002759 f_l1_tune(L1CTL);
2760 RSL.clear;
2761
2762 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002763
2764 setverdict(pass);
2765}
2766testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2767 var ConnHdlr vc_conn;
2768 var ConnHdlrPars pars;
2769 f_init();
2770 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2771 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2772 pcu_comp := false, trxc_comp := true);
2773 vc_conn.done;
2774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2775}
2776
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002777/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002778private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002779 f_connhdlr_init_vty_bsc();
2780
2781 f_l1_tune(L1CTL);
2782 RSL.clear;
2783
2784 /* Wait until BTS is started and at full power */
2785 var integer max_rx_lvl := f_wait_ramp_up();
2786 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2787
2788 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2789 f_verify_ramp_down(max_rx_lvl);
2790
2791 setverdict(pass);
2792}
2793testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2794 var ConnHdlr vc_conn;
2795 var ConnHdlrPars pars;
2796 f_init();
2797 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2798 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2799 pcu_comp := false, trxc_comp := true);
2800 vc_conn.done;
2801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2802}
2803
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002804/* Verify Tx power:
2805 * + ramping down during ADM state UNLOCKED->LOCKED
2806 * + ramping up during ADM state LOCKED->UNLOCKED
2807 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002808private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002809 var L1ctlDlMessage l1_dl;
2810 var integer last_rx_lvl;
2811
2812 f_connhdlr_init_vty_bsc();
2813
2814 f_l1_tune(L1CTL);
2815 RSL.clear;
2816
2817 /* Wait until BTS is started and at full power */
2818 var integer max_rx_lvl := f_wait_ramp_up();
2819 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2820
2821 log("ADM STATE UNLOCKED->LOCKED");
2822 f_vty_enter_cfg_trx(BSCVTY);
2823 f_vty_transceive(BSCVTY, "rf_locked 1");
2824 last_rx_lvl := max_rx_lvl;
2825 f_verify_ramp_down(max_rx_lvl);
2826
2827 /* Let some time after we received 0dBm, then check we don't receive BCCH
2828 * anymore because scheduler has stopped after ramping down */
2829 f_sleep(2.0);
2830 L1CTL.clear;
2831 timer Tlocked := 2.0;
2832 Tlocked.start;
2833 alt {
2834 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2836 log2str("Received data_ind during rf_locked: ", l1_dl));
2837 }
2838 [] L1CTL.receive { repeat; }
2839 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2840 }
2841
2842 log("ADM STATE LOCKED->UNLOCKED");
2843 f_vty_transceive(BSCVTY, "rf_locked 0");
2844 f_verify_ramp_up();
2845 setverdict(pass);
2846}
2847testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2848 var ConnHdlr vc_conn;
2849 var ConnHdlrPars pars;
2850 f_init();
2851 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2852 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2853 pcu_comp := false, trxc_comp := true);
2854 vc_conn.done;
2855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2856}
2857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002858private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002859 timer T := 8.0;
2860 T.start;
2861 var RSL_Message rsl;
2862 alt {
2863 [] as_l1_sacch();
2864 [] L1CTL.receive { repeat; }
2865 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2866 if (rsl.ies[3].body.bs_power.power_level == level) {
2867 setverdict(pass)
2868 } else {
2869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2870 }
2871 }
2872 [] T.timeout {
2873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2874 }
2875 }
2876}
2877
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002878/* See if the RSL MEASurement RESult contains expeced BS power level
2879 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002880private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002881 f_l1_tune(L1CTL);
2882 RSL.clear;
2883
2884 if (mp_bts_trxc_port != -1) {
2885 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2886 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2887 }
2888
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002889 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002890 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2891 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2892
2893 f_est_dchan(more_ies :={valueof(pwr)});
2894
2895 f_check_meas_bs_power_level(pwr_var);
2896
2897 f_rsl_chan_deact();
2898 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2899}
2900
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002901/* See if the RSL MEASurement RESult contains expeced BS power level
2902 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002903private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002904 f_l1_tune(L1CTL);
2905 RSL.clear;
2906
2907 if (mp_bts_trxc_port != -1) {
2908 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2909 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2910 }
2911
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002912 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002913 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2914
2915 f_est_dchan();
2916
2917 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2918
2919 f_check_meas_bs_power_level(pwr_var);
2920
2921 f_rsl_chan_deact();
2922 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2923}
2924
2925testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2926 var ConnHdlr vc_conn;
2927 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002928
Eric Wildae8f2622019-06-18 17:05:11 +02002929 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002930
2931 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2932 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2933 pcu_comp := false, trxc_comp := true);
2934 vc_conn.done;
2935
Eric Wildae8f2622019-06-18 17:05:11 +02002936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2937}
2938
2939testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2940 var ConnHdlr vc_conn;
2941 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002942
Eric Wildae8f2622019-06-18 17:05:11 +02002943 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002944
2945 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2946 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2947 pcu_comp := false, trxc_comp := true);
2948 vc_conn.done;
2949
Eric Wildae8f2622019-06-18 17:05:11 +02002950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2951}
2952
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002953/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2954 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2955 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002956private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002957 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002958 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002959
2960 f_trxc_fake_rssi(rxlev2dbm(10));
2961 f_l1_tune(L1CTL);
2962 RSL.clear;
2963
2964 var RSL_IE_List addl_ies;
2965 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2966
2967 addl_ies := {
2968 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2969 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2970 };
2971
2972 /* establish with power parameters */
2973 f_est_dchan(more_ies := addl_ies);
2974
2975 /* set a high value to ensure L1 power control level increases */
2976 f_trxc_fake_rssi(rxlev2dbm(20));
2977
2978 timer T2 := 6.0;
2979 T2.start;
2980 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002981 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07002982 f_send_meas_rep(ts_MeasurementResults);
2983
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002985 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002986 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002987 T2.stop;
2988 }
2989 [] L1CTL.receive { repeat; }
2990 [] T2.timeout {
2991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2992 "Power Level in L1 header has not increased sufficiently");
2993 }
2994 }
2995
2996 /* set a low value to ensure L1 power control level decreases */
2997 f_trxc_fake_rssi(rxlev2dbm(0));
2998
2999 timer T4 := 6.0;
3000 T4.start;
3001 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003002 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003003 f_send_meas_rep(ts_MeasurementResults);
3004
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003005 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003006 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01003007 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003008 T4.stop;
3009 setverdict(pass, "Power level in L1 decreased/increased as expected");
3010 }
3011 [] L1CTL.receive { repeat; }
3012 [] T4.timeout {
3013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3014 "Power Level in L1 header has not decreased sufficiently");
3015 }
3016 }
3017
3018 f_rsl_chan_deact();
3019 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3020
3021}
3022
3023/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003024private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02003025 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003026 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003027
3028 /* set a low value to ensure power increases */
3029 f_trxc_fake_rssi(rxlev2dbm(10));
3030 f_l1_tune(L1CTL);
3031 RSL.clear;
3032
3033 var RSL_IE_List addl_ies;
3034 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3035
3036 addl_ies := {
3037 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3038 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3039 };
3040
3041 /* establish with power parameters */
3042 f_est_dchan(more_ies := addl_ies);
3043
3044 timer T1 := 10.0;
3045 T1.start;
3046 alt {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003047 [] as_l1_sacch_l1h(l1h) {
3048 f_send_meas_rep(ts_MeasurementResults);
3049 repeat;
3050 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003051 [] L1CTL.receive { repeat; }
3052 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003053 if (not isbound(l1h)) {
3054 setverdict(fail, "No SACCH blocks were received");
3055 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003056 setverdict(fail, "Power level in L1 header should not have changed");
3057 }
3058 }
3059 }
3060
3061 f_rsl_chan_deact();
3062 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3063
3064}
3065
3066/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003067private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003068 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003069 var uint5_t pwr_var := 15;
3070 var uint5_t pwr_max_var := f_get_max_power_from_band();
3071
3072 /* set a low value to ensure power increases */
3073 f_trxc_fake_rssi(rxlev2dbm(10));
3074 f_l1_tune(L1CTL);
3075 RSL.clear;
3076
3077 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3078 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3079
3080 /* establish with fixed power level */
3081 f_est_dchan(more_ies :={valueof(pwr)});
3082
3083 /* check our initial power level */
3084 f_wait_for_l1_power_level(pwr_var);
3085
3086 /* update power param to enable power loop
3087 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3088 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3089
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003090 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3091 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3092 * Add an extra offset to avoid race conditions: +1.92s. */
3093 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003094 T1.start;
3095 alt {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003096 [] as_l1_sacch_l1h(l1h) {
3097 f_send_meas_rep(ts_MeasurementResults);
3098 repeat;
3099 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003100 [] L1CTL.receive { repeat; }
3101 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003102 if (not isbound(l1h)) {
3103 setverdict(fail, "No SACCH blocks were received");
3104 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003105 setverdict(pass, "Power level in L1 header reduced as expected");
3106 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003107 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3108 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003109 }
3110 }
3111 }
3112
3113 f_rsl_chan_deact();
3114 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3115
3116}
3117
3118/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003119private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003120 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003121
3122 /* set a high value to ensure power decreases */
3123 f_trxc_fake_rssi(rxlev2dbm(50));
3124 f_l1_tune(L1CTL);
3125 RSL.clear;
3126
3127 var uint5_t pwr_var := 5;
3128 var uint5_t pwr_target_val := 15;
3129
3130 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3131 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3132
3133 /* establish with fixed power level */
3134 f_est_dchan(more_ies :={valueof(pwr)});
3135
3136 /* check our initial power level */
3137 f_wait_for_l1_power_level(pwr_var);
3138
3139 /* update power param to enable power loop
3140 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003141 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003142
3143 /* wait, then check that our power level was increased */
3144 timer T1 := 10.0;
3145 T1.start;
3146 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003147 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003148 [] L1CTL.receive { repeat; }
3149 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003150 if (not isbound(l1h)) {
3151 setverdict(fail, "No SACCH blocks were received");
3152 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3153 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003154 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003155 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003156 }
3157 }
3158 }
3159
3160 f_rsl_chan_deact();
3161 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3162
3163}
3164
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003165/* See if the power level remains constant when MS Power Parameters IE
3166 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003167private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003168 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003169
3170 /* set a high value to ensure power decreases */
3171 f_trxc_fake_rssi(rxlev2dbm(50));
3172 f_l1_tune(L1CTL);
3173 RSL.clear;
3174
3175 var uint5_t pwr_var := 5;
3176
3177 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3178 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3179
3180 /* establish with fixed power level */
3181 f_est_dchan(more_ies :={valueof(pwr)});
3182
3183 /* check our initial power level */
3184 f_wait_for_l1_power_level(pwr_var);
3185
3186 /* wait, then check that our power level did not change */
3187 timer T1 := 10.0;
3188 T1.start;
3189 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003190 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3191 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3193 "BS power control should not be active unless we receive a power parameters IE!");
3194 }
3195 repeat;
3196 }
3197 [] L1CTL.receive { repeat; }
3198 [] T1.timeout { setverdict(pass); }
3199 }
3200
3201 f_rsl_chan_deact();
3202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3203
3204}
3205
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003206/* See if the power level remains constant when MS Power Parameters IE
3207 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003208private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003209 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003210
3211 /* set a high value to ensure power decreases */
3212 f_trxc_fake_rssi(rxlev2dbm(50));
3213 f_l1_tune(L1CTL);
3214 RSL.clear;
3215
3216 var uint5_t pwr_var := 5;
3217
3218 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3219 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3220
3221 /* establish with fixed power level */
3222 f_est_dchan(more_ies :={valueof(pwr)});
3223
3224 /* check our initial power level */
3225 f_wait_for_l1_power_level(pwr_var);
3226
3227 /* pwr control without power params IE, should NOT activate MS power control*/
3228 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3229
3230 /* wait, then check that our power level did not change */
3231 timer T1 := 10.0;
3232 T1.start;
3233 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003234 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3235 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3237 "BS power control should not be active unless we receive a power parameters IE!");
3238 }
3239 repeat;
3240 }
3241 [] L1CTL.receive { repeat; }
3242 [] T1.timeout { setverdict(pass); }
3243 }
3244
3245 f_rsl_chan_deact();
3246 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3247
3248}
3249
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003250private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003251 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003252 timer T0 := 10.0;
3253 T0.start;
3254 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003255 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3256 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3258 "Power level in L1 header != signaled (RSL) power level.");
3259 }
3260 }
3261 [] L1CTL.receive { repeat; }
3262 [] T0.timeout {
3263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3264 "Timeout waiting for initial power level");
3265 }
3266 }
3267 T0.stop;
3268}
3269
3270private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3271 var IntegerRecord min_dbm_level;
3272 var IntegerRecord max_dbm_level;
3273 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3274
3275 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3276 if (min_dbm_level[i] == level) {
3277 return true;
3278 }
3279 }
3280 return false;
3281}
3282
3283private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3284 var IntegerRecord min_dbm_level;
3285 var IntegerRecord max_dbm_level;
3286 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3287
3288 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3289 if (max_dbm_level[i] == level) {
3290 return true;
3291 }
3292 }
3293 return false;
3294}
3295
3296private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3297 var IntegerRecord min_dbm_level;
3298 var IntegerRecord max_dbm_level;
3299 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3300 return max_dbm_level[0];
3301}
3302
3303type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003304private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003305private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3306 // 45.005 4.1.1
3307 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3308 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3309 2, 1, 0};
3310 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3311 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3312 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3313 var IntegerRecord rv;
3314
3315 select(band){
3316 case (BtsBand_allGSM){
3317 rv := gsm_power;
3318 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3319 max_dbm_level := {2, 1, 0};
3320 }
3321 case("DCS1800"){
3322 rv := dcs_power;
3323 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3324 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3325 }
3326 case("PCS1900"){
3327 rv := pcs_power;
3328 min_dbm_level := {15};
3329 max_dbm_level := {30};
3330 }
Harald Welte194b6912020-10-11 21:01:55 +02003331 case else {
3332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3333 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003334 }
3335
3336 return rv;
3337}
3338
3339private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003340 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 +02003341}
3342
3343testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3344 var ConnHdlr vc_conn;
3345 var ConnHdlrPars pars;
3346 f_init();
3347 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3348 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3349 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3350 pars.bts0_band := f_vty_get_bts0_band();
3351 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3352 vc_conn.done;
3353 }
3354 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3356}
3357
3358testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3359 var ConnHdlr vc_conn;
3360 var ConnHdlrPars pars;
3361 f_init();
3362 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3363 for (var integer tn := 1; tn <= 1; tn := tn+1) {
Vadim Yanitskiyc78aeb72022-07-30 17:56:39 +07003364 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN, t_guard := 30.0));
Eric Wild61edb7e2019-06-03 12:38:31 +02003365 pars.bts0_band := f_vty_get_bts0_band();
3366 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3367 vc_conn.done;
3368 }
3369 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3371}
3372
3373testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3374 var ConnHdlr vc_conn;
3375 var ConnHdlrPars pars;
3376 f_init();
3377 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3378 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3379 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3380 pars.bts0_band := f_vty_get_bts0_band();
3381 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3382 vc_conn.done;
3383 }
3384 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3386}
3387
3388testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3389 var ConnHdlr vc_conn;
3390 var ConnHdlrPars pars;
3391 f_init();
3392 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3393 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3394 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3395 pars.bts0_band := f_vty_get_bts0_band();
3396 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3397 vc_conn.done;
3398 }
3399 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3401}
3402
Eric Wild280ccb82019-06-17 11:11:52 +02003403testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3404 var ConnHdlr vc_conn;
3405 var ConnHdlrPars pars;
3406 f_init();
3407 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3408 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3409 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3410 pars.bts0_band := f_vty_get_bts0_band();
3411 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3412 vc_conn.done;
3413 }
3414 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3416}
3417
Eric Wild095024b2019-06-17 15:08:57 +02003418testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3419 var ConnHdlr vc_conn;
3420 var ConnHdlrPars pars;
3421 f_init();
3422 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3423 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3424 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3425 pars.bts0_band := f_vty_get_bts0_band();
3426 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3427 vc_conn.done;
3428 }
3429 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3431}
3432
Philipp Maier149c3922020-10-22 17:29:36 +02003433function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003434 var template RSL_IE_ChannelMode ch_mode;
3435 var ConnHdlr vc_conn;
3436 var ConnHdlrPars pars;
3437 f_init();
3438 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3439 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3440 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003441 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003442 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3443 pcu_comp := false, trxc_comp := true);
3444 vc_conn.done;
3445 }
3446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3447}
Philipp Maier149c3922020-10-22 17:29:36 +02003448
3449testcase TC_meas_res_speech_tchf() runs on test_CT {
3450 f_TC_meas_res_speech_tchf(false);
3451}
3452
3453testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3454 f_TC_meas_res_speech_tchf(true);
3455}
3456
3457function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003458 var template RSL_IE_ChannelMode ch_mode;
3459 var ConnHdlr vc_conn;
3460 var ConnHdlrPars pars;
3461 f_init();
3462 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3463 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3464 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003465 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003466 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3467 pcu_comp := false, trxc_comp := true);
3468 vc_conn.done;
3469 }
3470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3471}
Philipp Maier149c3922020-10-22 17:29:36 +02003472
3473testcase TC_meas_res_speech_tchh() runs on test_CT {
3474 f_TC_meas_res_speech_tchh(false)
3475}
3476
3477testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3478 f_TC_meas_res_speech_tchh(true)
3479}
3480
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003481testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3482 var template RSL_IE_ChannelMode ch_mode;
3483 var ConnHdlr vc_conn;
3484 var ConnHdlrPars pars;
3485 f_init();
3486 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3487 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3488 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3489 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3490 pars.l1_pars.toa256_enabled := true;
3491 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3492 pcu_comp := false, trxc_comp := true);
3493 vc_conn.done;
3494 }
3495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3496}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003497
Harald Welte70767382018-02-21 12:16:40 +01003498testcase TC_meas_res_sign_tchf() runs on test_CT {
3499 var ConnHdlr vc_conn;
3500 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003501 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003502 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003503 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003504 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003505 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3506 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003507 vc_conn.done;
3508 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003510}
3511testcase TC_meas_res_sign_tchh() runs on test_CT {
3512 var ConnHdlr vc_conn;
3513 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003514 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003515 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003516 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003517 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003518 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3519 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003520 vc_conn.done;
3521 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003523}
3524testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3525 var ConnHdlr vc_conn;
3526 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003527 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003528 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003529 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3530 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003531 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3532 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003533 vc_conn.done;
3534 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003536}
3537testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3538 var ConnHdlr vc_conn;
3539 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003540 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003541 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003542 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3543 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003544 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3545 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003546 vc_conn.done;
3547 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003549}
Harald Welte685d5982018-02-27 20:42:05 +01003550testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3551 var ConnHdlr vc_conn;
3552 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003553 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003554 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3555 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003556 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003557 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003558 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3559 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003560 vc_conn.done;
3561 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003563}
3564
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003565/* Make sure that we always get RSL MEASurement RESult messages regardless
3566 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3567private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3568 timer Texec := 8.0;
3569 timer Timpf := 2.0;
3570 timer Tmr;
3571
3572 f_l1_tune(L1CTL);
3573 RSL.clear;
3574
3575 f_est_dchan();
3576 L1CTL.clear;
3577
3578 /* Establish the main SAPI=0 link on DCCH first */
3579 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3580
3581 /* Give more time for the first RSL MEASurement RESult */
3582 Tmr.start(0.480 * 2.0);
3583 Texec.start; /* EXECution timer */
3584 Timpf.start; /* IMPFung timer */
3585
3586 alt {
3587 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3588 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3589 /* Reschedule the MEAS RES timer */
3590 Tmr.start(0.480 + 0.120);
3591 repeat;
3592 }
3593 [] RSL.receive { repeat; }
3594 [] Tmr.timeout {
3595 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3596 }
3597 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3598 [] Timpf.timeout {
3599 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3600 log("Injected SAPI=3 traffic on SACCH");
3601 Timpf.start;
3602 repeat;
3603 }
3604 /* We're good if survived so far */
3605 [] Texec.timeout {
3606 setverdict(pass);
3607 }
3608 }
3609
3610 f_rsl_chan_deact();
3611 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3612 f_rslem_unregister(0, g_chan_nr);
3613}
3614testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3615 var template RSL_IE_ChannelMode ch_mode;
3616 var template ConnHdlrPars pars;
3617 var ConnHdlr vc_conn;
3618
3619 f_init();
3620
3621 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3622 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3623
3624 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3625 vc_conn.done;
3626
3627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3628}
3629testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3630 var template RSL_IE_ChannelMode ch_mode;
3631 var template ConnHdlrPars pars;
3632 var ConnHdlr vc_conn;
3633
3634 f_init();
3635
3636 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3637 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3638
3639 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3640 vc_conn.done;
3641
3642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3643}
3644
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003645/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3646 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003647private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003648 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003649 var RSL_IE_MS_Power ms_power;
3650 var RSL_Message rsl;
3651 var uint5_t power_level := 0;
3652
3653 f_l1_tune(L1CTL);
3654 RSL.clear;
3655
3656 f_est_dchan();
3657
3658 ms_power.reserved := 0;
3659 ms_power.fpc_epc := false;
3660
3661 /* Send the first power control command. This will disable any BTS/TRX
3662 * internal power control and switch the MS (which is not in scope of
3663 * this test) to a constant power level. We start with a power level
3664 * of 0 */
3665 ms_power.power_level := power_level;
3666 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3667 RSL.send(rsl);
3668
3669 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003670 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3671 if (l1h.ms_power_lvl != power_level) {
3672 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3673 "match the signaled (RSL) power level := ", power_level);
3674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003675 }
3676
3677 /* Signal a new power level via RSL for the next turn. */
3678 if (power_level < 31) {
3679 power_level := power_level + 1;
3680 ms_power.power_level := power_level;
3681 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3682 RSL.send(rsl);
3683 repeat;
3684 }
3685
3686 }
3687
3688 /* Ignore all other blocks */
3689 [] L1CTL.receive { repeat; }
3690
3691 }
3692
3693 f_rsl_chan_deact();
3694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3695
3696 setverdict(pass);
3697}
3698
3699testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3700 var ConnHdlr vc_conn;
3701 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003702 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003703
3704 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3705 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3706 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3707 vc_conn.done;
3708 }
3709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3710}
Harald Welte70767382018-02-21 12:16:40 +01003711
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003712/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003713TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003714private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003715 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003716 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003717
3718 f_l1_tune(L1CTL);
3719 RSL.clear;
3720
3721 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003722 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003723
3724 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3725
3726
3727 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003728 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3729 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003730 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3731 }
3732
3733 }
3734
3735 /* Ignore all other blocks */
3736 [] L1CTL.receive { repeat; }
3737
3738 }
3739
3740 f_rsl_chan_deact();
3741 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3742
3743 setverdict(pass);
3744}
3745
3746testcase TC_rsl_chan_initial_ta() runs on test_CT {
3747 var ConnHdlr vc_conn;
3748 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003749 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003750 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003751 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3752 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003753 vc_conn.done;
3754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3755}
3756
Eric Wilde57e1a62019-05-28 13:30:55 +02003757/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003758private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003759 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003760 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003761
3762 var RSL_IE_MS_Power ms_power;
3763 ms_power.reserved := 0;
3764 ms_power.fpc_epc := false;
3765 ms_power.power_level := ms_power_level;
3766
3767 f_l1_tune(L1CTL);
3768 RSL.clear;
3769
3770 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3771
3772 timer T := 1.0;
3773 T.start;
3774 alt {
3775 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003776 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3777 if (l1h.ms_power_lvl != ms_power_level) {
3778 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3779 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003780 }
3781 }
3782 /* Ignore all other blocks */
3783 [] L1CTL.receive { repeat; }
3784 [] T.timeout {
3785 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3786 }
3787 }
3788
3789 f_rsl_chan_deact();
3790 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3791 setverdict(pass);
3792}
3793
3794testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3795 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3796 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3797}
3798
Harald Welte0472ab42018-03-12 15:02:26 +01003799/* 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 +01003800private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003801 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003802 RSL.clear;
3803
3804 f_est_dchan();
3805 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003806 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003807
3808 timer T := 40.0;
3809 T.start;
3810 alt {
3811 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3812 setverdict(pass)
3813 }
3814 [] RSL.receive { repeat };
3815 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003817 }
3818 }
3819 f_rsl_chan_deact();
3820}
3821testcase TC_conn_fail_crit() runs on test_CT {
3822 var ConnHdlr vc_conn;
3823 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003824 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003825 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3826 pars.t_guard := 60.0;
3827 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3828 vc_conn.done;
3829}
3830
Harald Welte93640c62018-02-25 16:59:33 +01003831/***********************************************************************
3832 * Paging
3833 ***********************************************************************/
3834
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003835private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003836 if (tmsi == 'FFFFFFFF'O) {
3837 return true;
3838 } else {
3839 return false;
3840 }
3841}
Harald Welte70767382018-02-21 12:16:40 +01003842
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003843private type record allowedFn { integer frame_nr }
3844private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3845private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3846private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3847private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3848private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3849private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3850private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3851private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3852private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003853{
3854 var integer frame_nr_51;
3855 frame_nr_51 := frame_nr mod 51
3856
3857 var allowedFn fn_check;
3858 fn_check.frame_nr := frame_nr_51;
3859
3860 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003862 return;
3863 }
3864
3865 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3866 return;
3867 }
3868 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3869 return;
3870 }
3871 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3872 return;
3873 }
3874 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3875 return;
3876 }
3877 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3878 return;
3879 }
3880 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3881 return;
3882 }
3883 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3884 return;
3885 }
3886 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3887 return;
3888 }
3889
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003891 return;
3892}
3893
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003894private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3895 inout integer num_paging_rcv_ids,
3896 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003897runs on test_CT {
3898 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003899 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003900 repeat;
3901 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003902 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003903 var octetstring without_plen :=
3904 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3905 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003906
3907 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3908
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003909 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3910 /* Ignore empty RR Paging Request (PCH filling) messages.
3911 * TODO: does it make sense to count them? */
3912 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003913 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3914 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003915 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003916 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3917 }
3918 } else if (match(rr, tr_PAGING_REQ2)) {
3919 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3920 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3921 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3922 }
3923 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3924 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3925 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003926 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003927 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3928 }
3929 } else if (match(rr, tr_PAGING_REQ3)) {
3930 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3931 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3932 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3933 }
3934 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3935 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3936 }
3937 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3938 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3939 }
3940 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3941 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3942 }
3943 }
3944 repeat;
3945 }
3946}
3947
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003948private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003949 boolean combined_ccch,
3950 integer bs_ag_blks_res,
3951 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003952 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3953 * paging command that is issued via RSL. */
3954 integer ps_load_modulus,
3955 /* Wait until the paging queue inside the BTS is congested before starting to add
3956 * pagings via the PCU socket (0 = disabled) */
3957 boolean ps_wait_cong,
3958 /* Maximum time to wait until the paging queue is drained at the end of the test.
3959 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3960 * to set this value to 18s, however the draining process may take significantly
3961 * longer when the queue contains paging requests for PS as those are implemented
3962 * as immediate assignments and require an entire MAC block alone. */
3963 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003964 boolean exp_load_ind,
3965 boolean exp_overload,
3966 boolean use_tmsi
3967}
3968
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003969private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003970 integer num_paging_sent,
3971 integer num_paging_rcv_msgs,
3972 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003973 integer num_overload,
3974 /* When free space inside the paging queue reaches more than 2 thirds
3975 * of its capacity cong_detected is set to true. */
3976 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003977}
3978
Harald Welte68e495b2018-02-25 00:05:57 +01003979/* Helper function for paging related testing */
3980private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003981 /* Using the PCU socket affects the timing of the paging processing. We only
3982 * activate the PCU socket if we do paging load tests that include additional
3983 * paging load that is introduced through the PCU socket. */
3984 if (cfg.ps_load_modulus > 0) {
3985 f_init_with_pcuif();
3986 } else {
3987 f_init();
3988 }
Harald Welte68e495b2018-02-25 00:05:57 +01003989 f_init_l1ctl();
3990 f_l1_tune(L1CTL);
3991
Philipp Maierca058272021-06-23 10:35:23 +02003992 var octetstring imm_ass := f_rnd_octstring(23);
3993 var ASP_RSL_Unitdata load_ind;
3994
Harald Welte68e495b2018-02-25 00:05:57 +01003995 var PagingTestState st := {
3996 num_paging_sent := 0,
3997 num_paging_rcv_msgs := 0,
3998 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003999 num_overload := 0,
4000 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01004001 };
4002
4003 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
4004 var float max_pch_imsi_per_sec;
4005 if (cfg.use_tmsi) {
4006 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
4007 } else {
4008 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
4009 }
4010 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
4011 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004012 var float time_total := 20.0;
4013 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
4014 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01004015
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004016 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
4017 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01004018
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004019 timer T_itv := 0.0;
4020 T_itv.start;
4021 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01004022 alt {
4023 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004024 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01004025 st.num_overload := st.num_overload + 1;
4026 repeat;
4027 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004028 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01004030 }
Philipp Maierca058272021-06-23 10:35:23 +02004031 [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 +01004032 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02004033
4034 /* Detect paging congestion: The logic inside the BTS will diagnose the
4035 * paging queue as congested when the fill state is more than 66% (which
4036 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4037 * paging congestion is detected pagings that are issued through the PCU
4038 * socket (PS) are dropped in order to prefer the CS related pagings. */
4039 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4040 st.cong_detected := true;
4041 }
4042
Harald Welte68e495b2018-02-25 00:05:57 +01004043 /* FIXME: analyze/verify interval + contents */
4044 repeat;
4045 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004046 /* ignore other RSL messages like RF RESource INDication */
4047 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004048 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004049 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004050 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004051 /* Only relevant when testing including with PCU sock connected */
4052 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004053 [] T_itv.timeout {
4054 /* Send paging cmds based on elapsed time */
4055 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4056 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004057 var MobileIdentityV mi;
4058
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004059 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004060 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004061 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004062 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004063 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004064 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004065
4066 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004067 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 +02004068
Philipp Maierca058272021-06-23 10:35:23 +02004069 /* Add additional pagings through the PCU socket interface. */
4070 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4071 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4072 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4073 }
4074 }
4075
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004076 st.num_paging_sent := st.num_paging_sent + 1;
4077 }
4078 if (st.num_paging_sent < pkt_total) {
4079 /* Wait for interval to next PAGING COMMAND */
4080 var float time_now := T_total.read;
4081 var float next_sched := int2float(st.num_paging_sent)*interval;
4082 if (next_sched > time_now) {
4083 T_itv.start(next_sched - time_now);
4084 } else {
4085 T_itv.start(0.0);
4086 }
4087 } else {
4088 /* We are done, no need to keep counting */
4089 T_total.stop;
4090 }
4091 }
4092 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004093 }
4094 }
4095
Philipp Maierca058272021-06-23 10:35:23 +02004096 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004097 T_wait.start;
4098 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004099 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004100 [] L1CTL.receive { repeat; }
4101 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004102 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004103 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004104 /* ignore other RSL messages like RF RESource INDication */
4105 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004106 /* Only relevant when testing including with PCU sock connected */
4107 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004108 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004109 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 +01004110 }
Harald Welte68e495b2018-02-25 00:05:57 +01004111 }
4112
4113 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4114 " rcvd_ids=", st.num_paging_rcv_ids);
4115 return st;
4116}
4117
4118/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4119 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4120 * - that CCCH LOAD IND (PCH) are being generated
4121 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4122testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004123 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004124 var PagingTestCfg cfg := {
4125 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004126 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004127 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004128 ps_load_modulus := 0,
4129 ps_wait_cong := false,
4130 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004131 exp_load_ind := true,
4132 exp_overload := false,
4133 use_tmsi := false
4134 };
4135 var PagingTestState st := f_TC_paging(cfg);
4136 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4138 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004139 } else {
4140 setverdict(pass);
4141 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004143}
4144
4145/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4146 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4147 * - that CCCH LOAD IND (PCH) are being generated
4148 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4149testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004150 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004151 var PagingTestCfg cfg := {
4152 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004153 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004154 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004155 ps_load_modulus := 0,
4156 ps_wait_cong := false,
4157 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004158 exp_load_ind := true,
4159 exp_overload := false,
4160 use_tmsi := true
4161 };
4162 var PagingTestState st := f_TC_paging(cfg);
4163 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4165 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004166 } else {
4167 setverdict(pass);
4168 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004170}
4171
4172/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4173 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4174 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4175 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4176testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004177 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004178 var PagingTestCfg cfg := {
4179 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004180 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004181 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004182 ps_load_modulus := 0,
4183 ps_wait_cong := false,
4184 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004185 exp_load_ind := true,
4186 exp_overload := true,
4187 use_tmsi := false
4188 };
4189 var PagingTestState st := f_TC_paging(cfg);
4190 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4191 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004192 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004193 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004194 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 +01004195 } else {
4196 setverdict(pass);
4197 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004199}
4200
4201/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4202 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4203 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4204 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4205testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004206 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004207 var PagingTestCfg cfg := {
4208 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004209 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004210 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004211 ps_load_modulus := 0,
4212 ps_wait_cong := false,
4213 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004214 exp_load_ind := true,
4215 exp_overload := true,
4216 use_tmsi := true
4217 };
4218 var PagingTestState st := f_TC_paging(cfg);
4219 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4220 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004221 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004222 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004223 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 +01004224 } else {
4225 setverdict(pass);
4226 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004228}
4229
Philipp Maierca058272021-06-23 10:35:23 +02004230/* Same as above, but with additional paging load created by PS pagings that
4231 * are issued through the PCU socket. The additional load is introduced when
4232 * the paging queue is already two thirds full. Since the BTS implements a
4233 * prioritization logic that drops the pagings from the PCU under in those
4234 * congestive sitautions the behaviour on the PS side is expected to be
4235 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4236testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4237 var SystemInformation si3 := valueof(ts_SI3_default);
4238 var PagingTestCfg cfg := {
4239 combined_ccch := true,
4240 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4241 load_factor := 2.0,
4242 ps_load_modulus := 16,
4243 ps_wait_cong := true,
4244 queue_drain_timeout := 18.0,
4245 exp_load_ind := true,
4246 exp_overload := true,
4247 use_tmsi := false
4248 };
4249 var PagingTestState st := f_TC_paging(cfg);
4250 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4251 * slots and will fully drain that buffer before returning */
4252 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4253 if (not match(st.num_paging_rcv_ids, tpl)) {
4254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4255 } else {
4256 setverdict(pass);
4257 }
4258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4259}
4260
4261
Harald Welte68e495b2018-02-25 00:05:57 +01004262
Harald Welte93640c62018-02-25 16:59:33 +01004263/***********************************************************************
4264 * Immediate Assignment / AGCH
4265 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004266private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004267 len := 0,
4268 ma := ''B
4269}
Harald Welte93640c62018-02-25 16:59:33 +01004270
Harald Weltee8d750e2018-06-10 21:41:35 +02004271private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4272 return int2str(num_tx) & " sent, "
4273 & int2str(num_rx) & " received, "
4274 & int2str(num_del) & " deleted";
4275}
4276
4277private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4278 var L1ctlDlMessage l1_dl;
4279 timer T := 10.0;
4280 var integer num_tx := 0;
4281 var integer num_rx := 0;
4282 var integer num_del := 0;
4283 var charstring res_str;
4284 var float rx_ratio;
4285
Harald Welte10474062019-05-30 16:48:17 +02004286 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004287 f_init_l1ctl();
4288 f_l1_tune(L1CTL);
4289
4290 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004291 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004292 mp_trx_pars[0].arfcn,
4293 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004294 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4295 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004296 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004297 num_tx := num_tx+1;
4298 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004299 }
4300 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004301 T.start;
4302 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004303 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004304 num_del := num_del+1;
4305 repeat;
4306 }
4307 [] RSL_CCHAN.receive {
4308 repeat;
4309 }
4310 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004311 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4312 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4313 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004314 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004315 } else {
4316 num_rx := num_rx+1;
4317 }
4318 repeat;
4319 }
4320 [] L1CTL.receive { repeat; }
4321 [] T.timeout { }
4322 }
4323 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4324 log("AGCH test: " & res_str);
4325 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004327 }
4328 rx_ratio := int2float(num_rx) / int2float(num_tx);
4329 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004330 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 +02004331 } else {
4332 setverdict(pass);
4333 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004335}
4336
Harald Weltee8d750e2018-06-10 21:41:35 +02004337/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4338testcase TC_imm_ass_1000_20ms() runs on test_CT {
4339 f_TC_imm_ass(1000, 0.02, 0.25);
4340}
4341
4342/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4343testcase TC_imm_ass_200_0ms() runs on test_CT {
4344 f_TC_imm_ass(200, 0.0, 0.05);
4345}
4346
4347/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4348testcase TC_imm_ass_200_76ms() runs on test_CT {
4349 f_TC_imm_ass(150, 0.076, 1.00);
4350}
4351
4352
4353
Harald Welte48494ca2018-02-25 16:59:50 +01004354/***********************************************************************
4355 * BCCH
4356 ***********************************************************************/
4357
4358/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004359private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004360 GsmFrameNumber frame_number,
4361 SystemInformation si
4362}
4363
4364/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004365private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004366
4367/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004368private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004369
4370/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004371private function f_si_vecslot_contains(SystemInformationVector arr,
4372 RrMessageType key,
4373 boolean bcch_ext := false)
4374return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004375 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4376 var integer fn_mod51 := arr[i].frame_number mod 51;
4377 if (not bcch_ext and fn_mod51 == 2 or
4378 bcch_ext and fn_mod51 == 6) {
4379 if (arr[i].si.header.message_type == key) {
4380 return true;
4381 }
4382 }
4383 }
4384 return false;
4385}
4386
4387/* 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 +07004388private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4389 integer tc, RrMessageType key,
4390 boolean ext_bcch := false)
4391{
Harald Welte48494ca2018-02-25 16:59:50 +01004392 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004394 }
4395}
4396
4397/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004398private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4399 RrMessageType key)
4400return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004401 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4402 if (f_si_vecslot_contains(arr[tc], key) or
4403 f_si_vecslot_contains(arr[tc], key, true)) {
4404 return true;
4405 }
4406 }
4407 return false;
4408}
4409
4410/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004411private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4412 RrMessageType key,
4413 boolean bcch_ext := false,
4414 integer n := 1, integer m := 4)
4415return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004416 var integer count := 0;
4417 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4419 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004420 }
4421 for (var integer i:= 0; i < m; i := i + 1) {
4422 var integer fn_mod51 := arr[i].frame_number mod 51;
4423 if (not bcch_ext and fn_mod51 == 2 or
4424 bcch_ext and fn_mod51 == 6) {
4425 if (arr[i].si.header.message_type == key) {
4426 count := count + 1;
4427 }
4428 }
4429 }
4430 if (count >= n) {
4431 return true;
4432 } else {
4433 return false;
4434 }
4435}
4436
4437/* 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 +07004438private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4439 integer tc, RrMessageType key,
4440 boolean ext_bcch := false,
4441 integer n, integer m)
4442{
Harald Welte48494ca2018-02-25 16:59:50 +01004443 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004445 }
4446}
4447
4448/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004449private function f_si_vecslot_contains_only(SystemInformationVector arr,
4450 RrMessageType key,
4451 boolean bcch_ext := false)
4452return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004453 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4454 var integer fn_mod51 := arr[i].frame_number mod 51;
4455 if (not bcch_ext and fn_mod51 == 2 or
4456 bcch_ext and fn_mod51 == 6) {
4457 if (arr[i].si.header.message_type != key) {
4458 return false;
4459 }
4460 }
4461 }
4462 return true;
4463}
4464
4465/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004466private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4467 integer tc, RrMessageType key,
4468 boolean ext_bcch := false)
4469{
Harald Welte48494ca2018-02-25 16:59:50 +01004470 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004472 }
4473}
4474
4475/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004476private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004477 boolean bcch_extended,
4478 boolean si1_present,
4479 boolean si2bis_present,
4480 boolean si2ter_present,
4481 boolean si2quater_present,
4482 boolean si7_present,
4483 boolean si8_present,
4484 boolean si9_present,
4485 boolean si13_present,
4486 boolean si13alt_present,
4487 boolean si15_present,
4488 boolean si16_present,
4489 boolean si17_present,
4490 boolean si2n_present,
4491 boolean si21_present,
4492 boolean si22_present
4493}
4494
4495/* 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 +07004496private function f_validate_si_scheduling(SystemInformationConfig cfg,
4497 SystemInformationVectorPerTc si_per_tc)
4498{
Harald Welte48494ca2018-02-25 16:59:50 +01004499 var integer i;
4500 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4501 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004503 }
4504 }
4505 if (cfg.si1_present) {
4506 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4507 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4508 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4509 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4510 /* make sure *ALL* contain SI1 */
4511 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4512 }
4513 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4514 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4515 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4516 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4517 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4518 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4519
4520 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4521 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4522 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4523 * consecutive occurrences of TC = 4. */
4524 if (cfg.si2bis_present and not cfg.si2ter_present) {
4525 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4526 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4527 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4528 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4529 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4530 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4531 }
4532
4533 if (cfg.si7_present or cfg.si8_present) {
4534 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4535 * if System Information type 4 does not contain all information needed for cell
4536 * selection and reselection. */
4537 if (not cfg.bcch_extended) {
4538 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4539 }
4540 if (cfg.si7_present) {
4541 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4542 }
4543 if (cfg.si8_present) {
4544 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4545 }
4546 }
4547
4548 if (cfg.si2quater_present) {
4549 /* iii) System information type 2 quater is sent if needed, as determined by the system
4550 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4551 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4552 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4553 * within any of 4 consecutive occurrences of TC = 5. */
4554 if (not (cfg.bcch_extended)) {
4555 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4556 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4557 } else {
4558 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4559 }
4560 } else {
4561 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4562 }
4563 }
4564 if (cfg.si9_present) {
4565 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4566 * in system information type 3 as defined in 3GPP TS 44.018. */
4567 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4568 }
4569 if (cfg.si13_present) {
4570 /* vii) System Information type 13 is only related to the GPRS service. System Information
4571 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4572 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4573 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4574 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4575 * within any of 4 consecutive occurrences of TC=4. */
4576 if (not cfg.bcch_extended) {
4577 log("not-bccch-extended");
4578 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4579 } else {
4580 log("bccch-extended");
4581 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4582 }
4583 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004585 }
4586 }
4587 if (cfg.si16_present or cfg.si17_present) {
4588 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4589 * should not be sent in a cell where network sharing is used (see rule xv). */
4590 if (cfg.si22_present) {
4591 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4592 }
4593 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004595 }
4596 if (not cfg.bcch_extended) {
4597 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4598 }
4599 if (cfg.si16_present) {
4600 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4601 }
4602 if (cfg.si17_present) {
4603 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4604 }
4605 }
4606
4607 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4608 * broadcast information. The frequency with which they are sent is determined by the
4609 * system operator. System Information type 9 identifies the scheduling of System
4610 * Information type 18 and 20 messages. */
4611
4612 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4613 * Information Type 19 is present, then its scheduling shall be indicated in System
4614 * Information Type 9. */
4615
4616 if (cfg.si15_present) {
4617 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4618 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4619 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4620 * 4 consecutive occurrences of TC = 1. */
4621 if (not cfg.bcch_extended) {
4622 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4623 } else {
4624 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4625 }
4626 }
4627 if (cfg.si13alt_present) {
4628 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4629 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4630 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4631 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4632 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4633 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4634 * of TC = 4. */
4635 if (cfg.si13_present) {
4636 testcase.stop("Error: Cannot have SI13alt and SI13");
4637 }
4638 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004640 }
4641 if (not cfg.bcch_extended) {
4642 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4643 } else {
4644 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4645 }
4646 }
4647 if (cfg.si2n_present) {
4648 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4649 * as determined by the system operator. In the case that the message is sent on the
4650 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4651 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4652 * consecutive occurrences of TC = 4. */
4653 if (not cfg.bcch_extended) {
4654 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4655 } else {
4656 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4657 }
4658 }
4659 if (cfg.si21_present) {
4660 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4661 * determined by the system operator. If Extended Access Barring is in use in the cell
4662 * then this message is sent at least once within any of 4 consecutive occurrences of
4663 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4664 * cell then this message shall only be sent on BCCH Ext. */
4665 if (not cfg.bcch_extended) {
4666 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4667 } else {
4668 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4669 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004671 }
4672 }
4673 }
4674 if (cfg.si22_present) {
4675 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4676 * should not be sent in a cell where SoLSA is used (see rule viii). System
4677 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4678 * =2 and TC=6. */
4679 if (cfg.si16_present or cfg.si17_present) {
4680 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4681 }
4682 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4683 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004685 }
4686 if (not cfg.bcch_extended) {
4687 testcase.stop("Error: SI22 requires BCCH Extd!");
4688 } else {
4689 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4690 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4691 }
4692 }
4693}
4694
4695/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004696private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4697return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004698 timer T := duration;
4699 var SystemInformationVectorPerTc si_per_tc;
4700 var L1ctlDlMessage l1_dl;
4701
4702 /* initialize all per-TC vectors empty */
4703 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4704 si_per_tc[i] := {};
4705 }
4706
4707 /* flush all previous L1 queued msgs */
4708 pt.clear;
4709
4710 T.start;
4711 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004712 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004713 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4714 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4715 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004716 repeat;
4717 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004718
Harald Welte48494ca2018-02-25 16:59:50 +01004719 var integer tc := f_gsm_compute_tc(sig.frame_number);
4720 log("SI received at TC=", tc, ": ", sig.si);
4721 /* append to the per-TC bucket */
4722 si_per_tc[tc] := si_per_tc[tc] & { sig };
4723 repeat;
4724 }
4725 [] pt.receive { repeat; }
4726 [] T.timeout { }
4727 }
4728
4729 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4730 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4731 }
4732 log("si_per_tc=", si_per_tc);
4733 return si_per_tc;
4734}
4735
4736/* helper function: Set given SI via RSL + validate scheduling.
4737 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004738private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004739 var SystemInformationVectorPerTc si_per_tc;
4740 f_init_l1ctl();
4741 f_l1_tune(L1CTL);
4742
4743 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004744 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004745 f_validate_si_scheduling(si_cfg, si_per_tc);
4746
4747 setverdict(pass);
4748}
4749
4750testcase TC_si_sched_default() runs on test_CT {
4751 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004752 /* 2+3+4 are mandatory and set in f_init() */
4753 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004755}
4756
4757testcase TC_si_sched_1() runs on test_CT {
4758 f_init();
4759 si_cfg.si1_present := true;
4760 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004761 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004763}
4764
4765testcase TC_si_sched_2bis() runs on test_CT {
4766 f_init();
4767 si_cfg.si2bis_present := true;
4768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4769 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004771}
4772
4773testcase TC_si_sched_2ter() runs on test_CT {
4774 f_init();
4775 si_cfg.si2ter_present := true;
4776 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4777 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004779}
4780
4781testcase TC_si_sched_2ter_2bis() runs on test_CT {
4782 f_init();
4783 si_cfg.si2bis_present := true;
4784 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4785 si_cfg.si2ter_present := true;
4786 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4787 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004789}
4790
4791testcase TC_si_sched_2quater() runs on test_CT {
4792 f_init();
4793 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004794 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004795 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004797}
4798
4799testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004800 /* NOTE: PCUIF connection is not used in this test case, but
4801 * without it the IUT would not broadcast SI13 (see OS#3075). */
4802 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004803 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004804 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004805 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004807}
4808
4809testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004810 /* NOTE: PCUIF connection is not used in this test case, but
4811 * without it the IUT would not broadcast SI13 (see OS#3075). */
4812 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004813 si_cfg.si2bis_present := true;
4814 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4815 si_cfg.si2ter_present := true;
4816 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4817 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004818 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004819 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004820 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004821 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004823}
4824
4825
Harald Welte68e495b2018-02-25 00:05:57 +01004826testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004827 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004828 /* FIXME: enable / disable individual BCCH info */
4829 //ts_RSL_BCCH_INFO(si_type, info);
4830 /* expect no ERROR REPORT after either of them *
4831 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004833}
4834
Harald Welte93640c62018-02-25 16:59:33 +01004835/***********************************************************************
4836 * Low-Level Protocol Errors / ERROR REPORT
4837 ***********************************************************************/
4838
Harald Welte01d982c2018-02-25 01:31:40 +01004839private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4840 timer T := 5.0;
4841 T.start;
4842 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004843 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004844 setverdict(pass);
4845 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004846 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004848 }
4849 [] RSL_CCHAN.receive {
4850 repeat;
4851 }
4852 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004854 }
4855 }
4856}
4857
4858/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4859testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004860 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004861 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4862 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004863 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004864
4865 f_exp_err_rep(RSL_ERR_PROTO);
4866}
4867
4868/* Provoke a mandatory IE error and match on ERROR REPORT */
4869testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004870 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004871
4872 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4873 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004874 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004875
4876 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4877}
4878
4879/* Provoke an IE content error and match on ERROR REPORT */
4880testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004881 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004882 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4883 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004884 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004885
4886 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4887}
4888
Harald Welteee25aae2019-05-19 14:32:37 +02004889/* attempt to activate channel with wrong RSL Message Discriminator IE */
4890function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4891 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4892 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4893 RSL.send(rsl);
4894 f_rslem_unregister(0, g_chan_nr);
4895}
4896testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4897 var ConnHdlr vc_conn;
4898 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4899
Harald Welte10474062019-05-30 16:48:17 +02004900 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004901
4902 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4903 vc_conn.done;
4904 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4905
4906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4907}
4908
4909/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004910private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004911 var template (value) RSL_Message rsl_tx;
4912 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4913 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4914 RSL.send(rsl_tx);
4915 f_rslem_unregister(0, g_chan_nr);
4916}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004917private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004918 var template (value) RSL_Message rsl_tx;
4919 /* we first have to activate the dedicated channel */
4920 f_rsl_chan_act(g_pars.chan_mode);
4921 /* ... to then send an invalid RLL message */
4922 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4923 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4924 RSL.send(rsl_tx);
4925 f_rslem_unregister(0, g_chan_nr);
4926}
4927testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4928 var ConnHdlr vc_conn;
4929 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4930 var template (value) RSL_Message rsl_tx;
4931
Harald Welte10474062019-05-30 16:48:17 +02004932 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004933
4934 /* Common Channel with wrong message type */
4935 RSL_CCHAN.clear;
4936 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4937 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004938 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004939 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4940
4941 /* TRX Management */
4942 RSL_CCHAN.clear;
4943 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4944 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004945 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004946 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4947
4948 /* Dedicated Channel */
4949 RSL_CCHAN.clear;
4950 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4951 vc_conn.done;
4952 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4953
4954 /* RLL */
4955 RSL_CCHAN.clear;
4956 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4957 vc_conn.done;
4958 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4959}
4960
4961/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004962private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004963 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4964 f_rslem_unregister(0, g_chan_nr);
4965}
4966testcase TC_err_rep_wrong_sequence() runs on test_CT {
4967 var ConnHdlr vc_conn;
4968 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4969
Harald Welte10474062019-05-30 16:48:17 +02004970 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004971
4972 RSL_CCHAN.clear;
4973 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4974 vc_conn.done;
4975 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4976}
4977
Harald Welte93640c62018-02-25 16:59:33 +01004978/***********************************************************************
4979 * IPA CRCX/MDCX/DLCS media stream handling
4980 ***********************************************************************/
4981
Harald Weltea871a382018-02-25 02:03:14 +01004982/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004983private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004984 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4985 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004986}
4987testcase TC_ipa_dlcx_not_active() runs on test_CT {
4988 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004989 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004990 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4991 vc_conn.done;
4992}
Harald Welte68e495b2018-02-25 00:05:57 +01004993
Harald Weltea3f1df92018-02-25 12:49:55 +01004994/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004995private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004996 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4997 "IPA CRCX ACK");
4998 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4999 "IPA CRCX NACK");
5000}
5001testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
5002 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005003 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01005004 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
5005 vc_conn.done;
5006}
5007
5008/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005009private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01005010 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5011 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005012 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01005013 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5014 var uint7_t rtp_pt2 := f_rnd_int(127);
5015 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5016 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5017 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5018 "IPA MDCX ACK");
5019 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5020 "IPA DLCX ACK");
5021}
5022testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
5023 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005024 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01005025 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
5026 vc_conn.done;
5027}
5028
Harald Welte3ae11da2018-02-25 13:36:06 +01005029/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005030private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01005031 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5032 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005033 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005034 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5035 var uint7_t rtp_pt2 := f_rnd_int(127);
5036 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5037 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5038 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5039 "IPA MDCX ACK");
5040 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005041 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005042 remote_port := f_rnd_int(c_UINT16_MAX);
5043 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5044 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5045 "IPA MDCX ACK");
5046 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5047 "IPA DLCX ACK");
5048}
5049testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5050 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005051 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005052 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5053 vc_conn.done;
5054}
5055
Harald Welte9912eb52018-02-25 13:30:15 +01005056/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005057private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005058 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5059 "IPA CRCX NACK");
5060}
5061testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5062 var ConnHdlrPars pars;
5063 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005064 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005065
5066 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5067 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5068 vc_conn.done;
5069
5070 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5071 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5072 vc_conn.done;
5073}
5074
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005075/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5076private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5077 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5078 var PortNumber bind_port := 16811;
5079 var RSL_Message crcx_ack;
5080
5081 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5082 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5083 "IPA CRCX ACK");
5084 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5085 if (match(bts_bind_ip, "0.0.0.0")) {
5086 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5087 }
5088
5089 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5090 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5091 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5092 "IPA DLCX ACK");
5093}
5094testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5095 var ConnHdlrPars pars;
5096 var ConnHdlr vc_conn;
5097 f_init();
5098
5099 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5100 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5101 vc_conn.done;
5102
5103 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5104 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5105 vc_conn.done;
5106}
5107
Harald Weltea3f1df92018-02-25 12:49:55 +01005108
Harald Welte883340c2018-02-28 18:59:29 +01005109/***********************************************************************
5110 * PCU Socket related tests
5111 ***********************************************************************/
5112
Harald Welte07bd2d22019-05-25 11:03:30 +02005113/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005114friend 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 +01005115runs on test_CT {
5116 timer T := 3.0;
5117
5118 /* we don't expect any RTS.req before PDCH are active */
5119 T.start;
5120 alt {
5121 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005123 }
5124 [] PCU.receive { repeat; }
5125 [] T.timeout { }
5126 }
5127
5128 /* Send PDCH activate request for known PDCH timeslot */
5129 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5130
5131 /* we now expect RTS.req for this timeslot (only) */
5132 T.start;
5133 alt {
5134 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5135 setverdict(pass);
5136 }
5137 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5138 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005140 }
5141 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005143 }
5144 [] PCU.receive { repeat; }
5145 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005147 }
5148 [not exp_success] T.timeout {
5149 setverdict(pass);
5150 }
5151 }
5152}
5153
Harald Welte07bd2d22019-05-25 11:03:30 +02005154/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005155friend 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 +01005156runs on test_CT {
5157 timer T := 3.0;
5158
5159 /* Send PDCH activate request for known PDCH timeslot */
5160 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 +02005161 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5162 * when it will actually have been executed in the BTS */
5163 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005164 PCU.clear;
5165 /* we now expect no RTS.req for this timeslot */
5166 T.start;
5167 alt {
5168 [] 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 +02005169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005170 }
5171 [] PCU.receive { repeat; }
5172 [] T.timeout {
5173 setverdict(pass);
5174 }
5175 }
5176}
5177
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005178friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005179 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005180 map(self:PCU, system:PCU);
5181 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005182 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5183}
5184
Harald Welte883340c2018-02-28 18:59:29 +01005185/* PDCH activation via PCU socket; check for presence of RTS.req */
5186testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005187 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005188
Harald Welte883340c2018-02-28 18:59:29 +01005189 f_TC_pcu_act_req(0, 0, 7, true);
5190}
5191
5192/* PDCH activation via PCU socket on non-PDCU timeslot */
5193testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005194 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005195
Harald Welte883340c2018-02-28 18:59:29 +01005196 f_TC_pcu_act_req(0, 0, 1, false);
5197}
5198
5199/* PDCH activation via PCU socket on wrong BTS */
5200testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005201 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005202
Harald Welte883340c2018-02-28 18:59:29 +01005203 f_TC_pcu_act_req(23, 0, 7, false);
5204}
5205
5206/* PDCH activation via PCU socket on wrong TRX */
5207testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005208 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005209
Harald Welte883340c2018-02-28 18:59:29 +01005210 f_TC_pcu_act_req(0, 23, 7, false);
5211}
5212
5213/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5214testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005215 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005216
Harald Welte883340c2018-02-28 18:59:29 +01005217 /* Activate PDCH */
5218 f_TC_pcu_act_req(0, 0, 7, true);
5219 f_sleep(1.0);
5220 /* and De-Activate again */
5221 f_TC_pcu_deact_req(0, 0, 7);
5222}
5223
5224/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5225testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005226 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005227
Harald Welte883340c2018-02-28 18:59:29 +01005228 f_TC_pcu_deact_req(0, 0, 1);
5229}
5230
5231/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005232function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005233 var PCUIF_send_data sd;
5234 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005235 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005236
5237 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005238 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005239
Harald Welte883340c2018-02-28 18:59:29 +01005240 T.start;
5241 alt {
5242 [] 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 +01005243 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005244 setverdict(pass);
5245 } else {
5246 repeat;
5247 }
5248 }
5249 [] PCU.receive { repeat; }
5250 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005252 }
5253 }
5254}
5255
Philipp Maier94c08482021-02-01 17:36:05 +01005256/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5257testcase TC_pcu_ver_si1() runs on test_CT {
5258 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5259 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5260}
5261
5262/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5263testcase TC_pcu_ver_si3() runs on test_CT {
5264 const octetstring si3 := '49012223242526272929AABBCC'O;
5265 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5266}
5267
5268/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5269testcase TC_pcu_ver_si13() runs on test_CT {
5270 const octetstring si13 := '01010203040506070909'O;
5271 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5272}
5273
Harald Welte883340c2018-02-28 18:59:29 +01005274private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5275
5276/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005277friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005278 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5279runs on test_CT
5280{
5281 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5282 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5283}
5284
5285/* 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 +02005286friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5287 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005288runs on test_CT
5289{
5290 var PCUIF_send_data sd;
5291
5292 timer T := 3.0;
5293 T.start;
5294 alt {
5295 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5296 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5297 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5298 sd.data.u.rts_req.fn, sapi, data);
5299 }
5300 [] PCU.receive { repeat; }
5301 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005303 }
5304 }
5305}
5306
5307/* Send DATA.req on invalid BTS */
5308testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005309 var TfiUsfArr tua := f_TfiUsfArrInit();
5310 var octetstring data := '0000'O & f_rnd_octstring(21);
5311
5312 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005313
Harald Welte883340c2018-02-28 18:59:29 +01005314 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005315 f_TfiUsfArrSet(tua, 7, 0);
5316 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5317 f_sleep(1.0);
5318
5319 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005320}
5321
5322/* Send DATA.req on invalid TRX */
5323testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005324 var TfiUsfArr tua := f_TfiUsfArrInit();
5325 var octetstring data := '0000'O & f_rnd_octstring(21);
5326
5327 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005328
Harald Welte883340c2018-02-28 18:59:29 +01005329 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005330 f_TfiUsfArrSet(tua, 7, 0);
5331 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5332 f_sleep(1.0);
5333
5334 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005335}
5336
5337/* Send DATA.req on invalid timeslot */
5338testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005339 var TfiUsfArr tua := f_TfiUsfArrInit();
5340 var octetstring data := '0000'O & f_rnd_octstring(21);
5341
5342 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005343
Harald Welte883340c2018-02-28 18:59:29 +01005344 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005345 f_TfiUsfArrSet(tua, 7, 0);
5346 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5347 f_sleep(1.0);
5348
5349 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005350}
5351
5352/* Send DATA.req on timeslot that hasn't been activated */
5353testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005354 var TfiUsfArr tua := f_TfiUsfArrInit();
5355 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005356
Harald Welte7162a612019-05-26 12:56:09 +02005357 f_virtphy_common();
5358
5359 f_TfiUsfArrSet(tua, 7, 0);
5360 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5361 f_sleep(1.0);
5362
5363 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005364}
5365
Harald Weltead033dc2019-05-25 17:28:16 +02005366private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005367 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5368 boolean wait_rts := true)
5369runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005370 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005371 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005372
5373 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005374 if (wait_rts) {
5375 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5376 } else {
5377 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5378 }
Harald Weltead033dc2019-05-25 17:28:16 +02005379
5380 T.start;
5381 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005382 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005383 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5384 setverdict(pass);
5385 }
Harald Welte7162a612019-05-26 12:56:09 +02005386 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5387 setverdict(fail, "Received unexpected ", rx_dl);
5388 }
Harald Weltead033dc2019-05-25 17:28:16 +02005389 [] L1CTL.receive {
5390 repeat;
5391 }
Harald Welte7162a612019-05-26 12:56:09 +02005392 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005393 setverdict(fail, "Timeout waiting for ", data);
5394 }
Harald Welte7162a612019-05-26 12:56:09 +02005395 [not expect_data] T.timeout {
5396 setverdict(pass);
5397 }
Harald Weltead033dc2019-05-25 17:28:16 +02005398 }
5399}
5400
5401private function f_disable_dynamic_ts() runs on test_CT
5402{
5403 f_init_vty_bsc();
5404 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5405 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5406 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5407 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005408 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005409}
5410
5411private function f_virtphy_common() runs on test_CT {
5412 f_disable_dynamic_ts();
5413 f_init_l1ctl();
5414 f_l1_tune(L1CTL);
5415}
5416
5417testcase TC_pcu_data_req_pdtch() runs on test_CT {
5418 var TfiUsfArr tua := f_TfiUsfArrInit();
5419 var octetstring data := '0000'O & f_rnd_octstring(21);
5420
5421 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005422
Harald Welte883340c2018-02-28 18:59:29 +01005423 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005424 f_TfiUsfArrSet(tua, 7, 0);
5425 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5426 f_sleep(1.0);
5427
5428 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005429}
5430
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005431/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005432testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005433 var TfiUsfArr tua := f_TfiUsfArrInit();
5434 var octetstring data := '0000'O & f_rnd_octstring(21);
5435
5436 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005437
Harald Welte883340c2018-02-28 18:59:29 +01005438 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005439 f_TfiUsfArrSet(tua, 7, 0);
5440 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5441 f_sleep(1.0);
5442
5443 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005444}
5445
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005446private function f_TC_pcu_ptcch_ul(uint16_t ra)
5447runs on test_CT {
5448 var template PCUIF_Message pcu_rach_ind;
5449 var PCUIF_send_data sd;
5450 var GsmFrameNumber fn;
5451 timer T;
5452
5453 /* Send an Access Burst on PTCCH/U over the Um-interface */
5454 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5455 chan_nr := ts_RslChanNr_PDCH(7),
5456 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5457
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005458 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5459 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005460
5461 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5462 T.start(52.0 * 4.615 / 1000.0);
5463 alt {
5464 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5465 log("Rx an Access Burst on the PCU interface: ", sd.data);
5466 setverdict(pass);
5467 T.stop;
5468 }
5469 [] PCU.receive { repeat; }
5470 [] T.timeout {
5471 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5472 /* Keep going, that's not the end of the world */
5473 }
5474 }
5475}
5476
5477testcase TC_pcu_ptcch() runs on test_CT {
5478 var L1ctlDlMessage dl;
5479 var octetstring data;
5480 timer T;
5481
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005482 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005483 f_init_l1ctl();
5484 f_l1_tune(L1CTL);
5485
5486 /* Activate PDCH channel on TS7 */
5487 f_TC_pcu_act_req(0, 0, 7, true);
5488
5489 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005490 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005491 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005492 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005493 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005494
5495 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5496 for (var integer i := 0; i < 16; i := i + 1) {
5497 log("Sending an Access Burst towards the L1CTL interface");
5498 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5499 }
5500
5501 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5502 data := f_rnd_octstring(23);
5503
5504 /* Verify PTCCH/D: send a random data block, make sure it's received */
5505 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5506 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5507
5508 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5509 * let's give it more time in case if we miss the beginning. */
5510 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5511 alt {
5512 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5513 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5514 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5515 frame := data)) -> value dl {
5516 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5517 setverdict(pass);
5518 T.stop;
5519 }
5520 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5521 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5522 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5523 l2_data := data)) -> value dl {
5524 log("Rx PTCCH/D data block on L1CTL: ", dl);
5525 setverdict(pass);
5526 T.stop;
5527 }
5528 [] L1CTL.receive { repeat; }
5529 [] T.timeout {
5530 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5531 }
5532 }
5533}
5534
Harald Welte883340c2018-02-28 18:59:29 +01005535/* Send AGCH from PCU; check it appears on Um side */
5536testcase TC_pcu_data_req_agch() runs on test_CT {
5537 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005538 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005539 f_init_l1ctl();
5540 f_l1_tune(L1CTL);
5541
5542 f_TC_pcu_act_req(0, 0, 7, true);
5543 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5544
5545 T.start;
5546 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005547 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005548 setverdict(pass);
5549 }
5550 [] L1CTL.receive { repeat; }
5551 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005553 }
5554 }
5555}
5556
Harald Welte928622b2019-05-26 13:22:59 +02005557/* Send AGCH from PCU; check it appears on Um side */
5558testcase TC_pcu_data_req_pch() runs on test_CT {
5559 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005560 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005561 f_init_l1ctl();
5562 f_l1_tune(L1CTL);
5563
5564 f_TC_pcu_act_req(0, 0, 7, true);
5565 /* three characters prefix: last 3 digits of IMSI as ASCII */
5566 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5567
5568 T.start;
5569 alt {
5570 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5571 setverdict(pass);
5572 }
5573 [] L1CTL.receive { repeat; }
5574 [] T.timeout {
5575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5576 }
5577 }
5578}
5579
Harald Welte883340c2018-02-28 18:59:29 +01005580/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5581testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5582 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005583 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005584 f_init_l1ctl();
5585 f_l1_tune(L1CTL);
5586
5587 /* append 3 last imsi digits so BTS can compute pagng group */
5588 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5589
5590 timer T := 0.5;
5591 T.start;
5592 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005593 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005594 /* TODO: verify paging group */
5595 setverdict(pass);
5596 }
5597 [] L1CTL.receive { repeat; }
5598 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005600 }
5601 }
5602}
5603
5604/* Send RACH from Um side, expect it to show up on PCU socket */
5605testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005606 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005607 f_init_l1ctl();
5608 f_l1_tune(L1CTL);
5609
5610 var GsmFrameNumber fn_last := 0;
5611 for (var integer i := 0; i < 1000; i := i+1) {
5612 var OCT1 ra := f_rnd_ra_ps();
5613 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5614 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005616 }
5617 fn_last := fn;
5618
5619 timer T := 2.0;
5620 T.start;
5621 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005622 [] 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 +01005623 T.stop;
5624 }
5625 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005627 }
5628 [] PCU.receive { repeat; }
5629 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005631 }
5632 }
5633 }
5634 setverdict(pass);
5635}
5636
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005637/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5638 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5639testcase TC_pcu_ext_rach_content() runs on test_CT {
5640 var template PCUIF_Message pcu_rach_ind;
5641 var GsmFrameNumber fn_last := 0;
5642 var L1ctlRachSynchSeq synch_seq;
5643 var PCUIF_BurstType pcu_bt;
5644 var GsmFrameNumber fn;
5645 var BIT11 ra11;
5646
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005647 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005648 f_init_l1ctl();
5649 f_l1_tune(L1CTL);
5650
5651 for (var integer i := 0; i < 1000; i := i+1) {
5652 /* We need to test both TS1 & TS2 */
5653 if (i rem 2 == 0) {
5654 synch_seq := RACH_SYNCH_SEQ_TS1;
5655 pcu_bt := BURST_TYPE_1;
5656 } else {
5657 synch_seq := RACH_SYNCH_SEQ_TS2;
5658 pcu_bt := BURST_TYPE_2;
5659 }
5660
5661 ra11 := f_rnd_ra11_ps();
5662 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5663 if (fn == fn_last) {
5664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5665 "Two RACH in same FN?!?");
5666 }
5667 fn_last := fn;
5668
5669 /* Compose the expected message */
5670 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005671 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005672 ra := bit2int(ra11),
5673 is_11bit := 1,
5674 burst_type := pcu_bt,
5675 fn := fn);
5676
5677 timer T := 2.0;
5678 T.start;
5679 alt {
5680 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5681 T.stop;
5682 }
5683 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5685 }
5686 [] PCU.receive { repeat; }
5687 [] T.timeout {
5688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5689 }
5690 }
5691 }
5692 setverdict(pass);
5693}
5694
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005695private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5696runs on test_CT {
5697 var template PCUIF_send_data sdt;
5698 var PCUIF_send_data sd;
5699 var int16_t lqual_cb;
5700 timer T := 1.0;
5701
5702 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5703 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5704
5705 /* Send a random PDTCH frame over Um */
5706 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5707 '0000'O & f_rnd_octstring(21)));
5708
5709 T.start;
5710 alt {
5711 /* If expected link quality is above the threshold */
5712 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5713 lqual_cb := sd.data.u.data_ind.lqual_cb;
5714 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5715
5716 /* Make sure the actual link quality matches the expected value */
5717 if (not match(lqual_cb, lqual_cb_exp)) {
5718 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5719 "expected value ", lqual_cb_exp));
5720 } else {
5721 setverdict(pass);
5722 }
5723 }
5724 /* If expected link quality is below the threshold */
5725 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5727 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5728 }
5729 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5730 [] PCU.receive { repeat; }
5731 [lqual_cb_exp < thresh] T.timeout {
5732 log("Rx nothing, as expected");
5733 setverdict(pass);
5734 }
5735 [lqual_cb_exp >= thresh] T.timeout {
5736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5737 "Timeout waiting for PCUIF_DATA.ind");
5738 }
5739 }
5740}
5741
5742/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5743testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005744 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005745 PCU.clear;
5746
5747 f_init_l1ctl();
5748 f_l1_tune(L1CTL);
5749
5750 /* Activate a PDCH channel on TS7 */
5751 f_TC_pcu_act_req(0, 0, 7, true);
5752
5753 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005754 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005755 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005756 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005757 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005758
5759 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5760 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5761 var TrxcMessage ret;
5762
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005763 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005764
5765 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5766 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5767 }
5768}
5769
Harald Welte883340c2018-02-28 18:59:29 +01005770/* Send PAGING via RSL, expect it to shw up on PCU socket */
5771testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005772 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005773
5774 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005775 var MobileIdentityLV mi_lv;
5776 var octetstring mi_lv_enc;
5777 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005778 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005779
Harald Welte883340c2018-02-28 18:59:29 +01005780 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005781 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005782 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005783 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005784 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005785
5786 /* Fancy encoding for PCUIF */
5787 mi_lv := valueof(ts_MI_LV(mi));
5788 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5789 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005790
5791 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005792 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005793 T.start;
5794 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005795 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005796 }
5797 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005799 }
5800 [] PCU.receive { repeat; }
5801 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005803 }
5804 }
5805 }
5806 setverdict(pass);
5807}
5808
Harald Welted66c9b82019-05-25 09:03:15 +02005809/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5810testcase TC_pcu_time_ind() runs on test_CT {
5811 var PCUIF_send_data pcu_sd;
5812 var integer num_time_ind := 0;
5813 var integer first_fn, last_fn;
5814 var float test_duration := 5.0;
5815 timer T;
5816
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005817 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005818 f_TC_pcu_act_req(0, 0, 7, true);
5819
5820 PCU.clear;
5821 T.start(test_duration);
5822 alt {
5823 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5824 num_time_ind := num_time_ind + 1;
5825 if (not isbound(first_fn)) {
5826 first_fn := pcu_sd.data.u.time_ind.fn;
5827 }
5828 last_fn := pcu_sd.data.u.time_ind.fn;
5829 repeat;
5830 }
5831 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5832 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5833 repeat;
5834 }
5835 [] PCU.receive {
5836 repeat;
5837 }
5838 [] T.timeout {}
5839 }
5840 var integer fn_expired := last_fn - first_fn;
5841 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5842
5843 /* verify the number of frames expired matches our expectation */
5844 const float c_GSM_FN_DURATION_MS := 4.61538;
5845 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005846 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005847 if (not match(fn_expired, t_fn_expected)) {
5848 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5849 }
5850
5851 /* There are three TIME.ind in every fn MOD 13 */
5852 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5853 /* Add some tolerance */
5854 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5855 if (not match(num_time_ind, t_time_ind_exp)) {
5856 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5857 }
5858
5859 setverdict(pass);
5860}
5861
Harald Welte4832c862019-05-25 14:57:18 +02005862/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5863testcase TC_pcu_rts_req() runs on test_CT {
5864 var PCUIF_send_data pcu_sd;
5865 var integer first_fn, last_fn;
5866 var integer num_rts_pdtch := 0;
5867 var integer num_rts_ptcch := 0;
5868 var float test_duration := 5.0;
5869 timer T;
5870
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005871 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005872 f_TC_pcu_act_req(0, 0, 7, true);
5873
5874 PCU.clear;
5875 T.start(test_duration);
5876 alt {
5877 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5878 -> value pcu_sd {
5879 num_rts_pdtch := num_rts_pdtch + 1;
5880 if (not isbound(first_fn)) {
5881 first_fn := pcu_sd.data.u.rts_req.fn;
5882 }
5883 last_fn := pcu_sd.data.u.rts_req.fn;
5884 repeat;
5885 }
5886 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5887 -> value pcu_sd {
5888 num_rts_ptcch := num_rts_ptcch + 1;
5889 if (not isbound(first_fn)) {
5890 first_fn := pcu_sd.data.u.rts_req.fn;
5891 }
5892 last_fn := pcu_sd.data.u.rts_req.fn;
5893 repeat;
5894 }
5895 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5896 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5897 repeat;
5898 }
5899 [] PCU.receive {
5900 repeat;
5901 }
5902 [] T.timeout {}
5903 }
5904 var integer fn_expired := last_fn - first_fn;
5905 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5906 ", num_rts_ptcch=", num_rts_ptcch);
5907
5908 /* verify the number of frames expired matches our expectation */
5909 const float c_GSM_FN_DURATION_MS := 4.61538;
5910 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005911 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005912 if (not match(fn_expired, t_fn_expected)) {
5913 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5914 }
5915
5916 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5917 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5918 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5919 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5920 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5921 t_ptcch_exp);
5922 }
5923
5924 /* We have 12 PDTCH blocks every 52-multiframe */
5925 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5926 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5927 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5928 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5929 t_pdtch_exp);
5930 }
5931
5932 setverdict(pass);
5933}
5934
Harald Welte07bd2d22019-05-25 11:03:30 +02005935/* test for generating Abis side OML ALERT from the PCU */
5936testcase TC_pcu_oml_alert() runs on test_CT {
5937 var PCUIF_send_data pcu_sd;
5938 var integer num_time_ind := 0;
5939 var integer first_fn, last_fn;
5940 var float test_duration := 5.0;
5941 timer T;
5942
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005943 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005944 f_TC_pcu_act_req(0, 0, 7, true);
5945
5946 /* re-connect CTRL port from BTS to BSC */
5947 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005948 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005949
5950 /* Send that OML Alert */
5951 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5952
5953 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5954 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5955 setverdict(pass);
5956}
5957
Harald Welteeaa9a862019-05-26 23:01:08 +02005958/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5959private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5960 var PCUIF_Message first_info;
5961 var integer pcu_conn_id := -1;
5962 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5963 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5964 var OCT4 tlli := '01020304'O;
5965 var OCT1 cause := '23'O;
5966 timer T := 5.0;
5967
5968 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5969
5970 f_l1_tune(L1CTL);
5971 RSL.clear;
5972
5973 f_est_dchan();
5974 L1CTL.clear;
5975
5976 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5977
5978 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5979 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5980 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5981
5982 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5983 T.start;
5984 alt {
5985 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5986 setverdict(pass);
5987 }
5988 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5989 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5990 }
5991 [] PCU.receive {
5992 repeat;
5993 }
5994 [] T.timeout {
5995 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5996 }
5997 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005998
5999 /* release the channel */
6000 f_rsl_chan_deact();
6001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6002 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02006003}
6004testcase TC_pcu_rr_suspend() runs on test_CT {
6005 var ConnHdlrPars pars;
6006 var ConnHdlr vc_conn;
6007
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006008 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02006009
6010 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
6011 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
6012 vc_conn.done;
6013}
Harald Welte07bd2d22019-05-25 11:03:30 +02006014
Harald Weltea2e0e942019-05-27 18:12:53 +02006015/* Ensure that PCUIF socket can accept only a single connection */
6016testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006017 var boolean connected := false;
6018 var UD_connect_result cr;
6019 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02006020 timer T := 5.0;
6021
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006022 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
6023 var template UD_Result tr_err := { result_code := ERROR, err := ? };
6024
Harald Weltea2e0e942019-05-27 18:12:53 +02006025 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006026 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02006027
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006028 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02006029 PCU.send(UD_connect:{mp_pcu_socket, -1});
6030 T.start;
6031 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006032 /* the IUT will first accept() the new connection, and close() it immediately */
6033 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
6034 log("BTS has accept()ed connection");
6035 connected := true;
6036 cid := cr.id;
6037 repeat;
6038 }
6039 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6040 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006041 setverdict(pass);
6042 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006043 /* ignore other messages related to the first connection */
6044 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006045 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006046 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006047 }
6048 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006049
Harald Weltea2e0e942019-05-27 18:12:53 +02006050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6051}
6052
Harald Weltec8effb72019-05-27 18:23:04 +02006053/* Ensure that PCUIF socket can disconnect + reconnect */
6054testcase TC_pcu_socket_reconnect() runs on test_CT {
6055 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006056 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006057
6058 f_sleep(1.0);
6059
6060 f_pcuif_close(PCU, g_pcu_conn_id);
6061 g_pcu_conn_id := -1;
6062
6063 f_sleep(1.0);
6064
6065 /* re-connect */
6066 PCU.clear;
6067 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6068 setverdict(pass);
6069
6070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6071}
6072
Harald Weltebe030482019-05-27 22:29:35 +02006073/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006074private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6075runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006076 var L1ctlDlMessage l1_dl;
6077 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006078 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006079 timer T := 5.0;
6080 T.start;
6081 alt {
6082 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006083 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6084 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006085 repeat;
6086 }
6087 }
6088 [] pt.receive {
6089 repeat;
6090 }
6091 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6093 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006094 }
6095 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006096 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006097}
6098
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006099/* Check if GPRS Indicator is present in RR System Information of a given type */
6100private function f_si_has_gprs_indicator(RrMessageType si_type)
6101runs on test_CT return boolean {
6102 var SystemInformation si := f_get_si(L1CTL, si_type);
6103
6104 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006105 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006106 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006107 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006108 }
6109
6110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6111 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006112}
6113
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006114/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6115private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6116runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006117 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006118 f_init_l1ctl();
6119 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006120 f_sleep(2.0);
6121 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006122
6123 if (f_si_has_gprs_indicator(si_type)) {
6124 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006125 } else {
6126 setverdict(pass);
6127 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006128
Harald Weltebe030482019-05-27 22:29:35 +02006129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6130}
6131
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006132testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6133 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6134}
Harald Weltebe030482019-05-27 22:29:35 +02006135
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006136testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6137 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6138}
6139
6140/* Ensure that GPRS capability is advertised after PCU socket connect */
6141private function f_TC_pcu_socket_connect(RrMessageType si_type)
6142runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006143 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006144 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006145 f_init_l1ctl();
6146 f_l1_tune(L1CTL);
6147
6148 f_sleep(2.0);
6149 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006150
6151 if (not f_si_has_gprs_indicator(si_type)) {
6152 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006153 } else {
6154 setverdict(pass);
6155 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006156
Harald Weltebe030482019-05-27 22:29:35 +02006157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6158}
6159
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006160testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6161 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6162}
Harald Weltebe030482019-05-27 22:29:35 +02006163
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006164testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6165 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6166}
6167
6168/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6169private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6170runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006171 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006172 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006173 f_init_l1ctl();
6174 f_l1_tune(L1CTL);
6175
6176 f_pcuif_close(PCU, g_pcu_conn_id);
6177 g_pcu_conn_id := -1;
6178
6179 f_sleep(1.0);
6180
6181 /* re-connect */
6182 PCU.clear;
6183 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6184
6185 f_sleep(2.0);
6186 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006187
6188 if (f_si_has_gprs_indicator(si_type)) {
6189 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006190 } else {
6191 setverdict(pass);
6192 }
6193
6194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6195}
6196
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006197testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6198 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6199}
6200
6201testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6202 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6203}
6204
Oliver Smithf5239c72019-08-28 10:01:25 +02006205/* 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) */
6206testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6207 var SystemInformation si3 := valueof(ts_SI3_default);
6208
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006209 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006210
Harald Welte76220222020-10-11 20:32:44 +02006211 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6212 * information */
6213 timer T := 2.0;
6214 T.start;
6215 alt {
6216 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6217 [] T.timeout {}
6218 }
6219
Oliver Smithf5239c72019-08-28 10:01:25 +02006220 /* Verify cell_id */
6221 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6222 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6223 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006224 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6225 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6226 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006227 }
6228
6229 /* Verify LAC */
6230 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6231 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6232 if (lac_si3 != lac_pcu) {
6233 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6234 }
6235
6236 setverdict(pass);
6237}
Harald Welted66c9b82019-05-25 09:03:15 +02006238
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006239/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6240testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6241 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006242 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006243
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006244 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006245
6246 info_ind := g_pcu_last_info.u.info_ind;
6247
6248 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6249 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006250 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006251 /* Skip inactive timeslots */
6252 continue;
6253 }
6254
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006255 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006256 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006257 else
6258 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006259
6260 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006261 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006262 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006263 hsn := fhp.maio_hsn.hsn,
6264 maio := fhp.maio_hsn.maio,
6265 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006266 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006267 } else {
6268 tr_ts := tr_PCUIF_InfoTrxTsH0;
6269 }
6270
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006271 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006272 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6273 if (not match(ts, tr_ts)) {
6274 setverdict(fail, "Hopping parameters do not match: ",
6275 "received ", ts, " vs expected ", tr_ts);
6276 } else {
6277 setverdict(pass);
6278 }
6279 }
6280 }
6281}
6282
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006283/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006284testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6285 f_init_vty_bsc();
6286 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6287 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6288
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006289 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006290
6291 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006292 var template PCUIF_RemoteAddr tr_remote_addr := {
6293 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006294 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006295 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006296
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006297 if (not match(remote_addr, tr_remote_addr)) {
6298 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006299 }
6300
6301 setverdict(pass);
6302}
6303
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006304/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006305testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6306 f_init_vty_bsc();
6307 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6308
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006309 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006310
6311 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006312 var template PCUIF_RemoteAddr tr_remote_addr := {
6313 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6314 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6315 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006316
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006317 if (not match(remote_addr, tr_remote_addr)) {
6318 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006319 }
6320
6321 setverdict(pass);
6322}
6323
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006324/* Verify coding of two NSVCs in the INFO.ind message */
6325testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6326 f_init_vty_bsc();
6327
6328 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6329 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6330 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6331 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6332
6333 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6334 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6335 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6336 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6337
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006338 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006339
6340 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6341 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6342 var template PCUIF_RemoteAddr tr_remote_addr := {
6343 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006344 addr := {
6345 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6346 f_inet6_addr("fd00::ca:ff:ee")
6347 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006348 };
6349
6350 if (not match(info_ind.nsvci, { 1234, 5678 }))
6351 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6352 if (not match(remote_addr, tr_remote_addr))
6353 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6354 if (not match(info_ind.local_port, { 1234, 5678 }))
6355 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6356 if (not match(info_ind.remote_port, { 1234, 5678 }))
6357 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6358
6359 setverdict(pass);
6360}
6361
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006362/* Verify periodic interference reports on PDCH */
6363testcase TC_pcu_interf_ind() runs on test_CT {
6364 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006365 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006366 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006367 var PCUIF_send_data sd;
6368 timer T;
6369
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006370 /* Set the averaging/reporting period to 480ms */
6371 f_init_vty_bsc();
6372 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6373 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6374
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006375 f_init_with_pcuif();
6376 f_TC_pcu_act_req(0, 0, 7, true);
6377
6378 /* We need trxcon for NOPE indications */
6379 f_init_l1ctl();
6380 f_l1_tune(L1CTL);
6381
6382 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006383 tr_interf_ind := tr_PCUIF_INTERF_IND(
6384 bts_nr := 0,
6385 trx_nr := 0,
6386 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006387 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006388 );
6389
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006390 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006391 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006392 /* The first interference report may contain unreliable values, so we ignore it */
6393 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6394 /* 4 SACCH periods => 4 reports (plus some guard time) */
6395 T.start(0.480 * 4.0 + 0.480 / 2.0);
6396 first := false;
6397 repeat;
6398 }
6399 /* Subsequent interference reports shall match our expectations */
6400 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006401 /* Check TDMA frame number period */
6402 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6403 setverdict(fail, "Odd TDMA frame number := ",
6404 sd.data.u.interf_ind.fn);
6405 }
6406 interf_ind_num := interf_ind_num + 1;
6407 if (interf_ind_num < 4)
6408 { repeat; }
6409 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006410 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006411 setverdict(fail, "Received unexpected interference report: ", sd.data);
6412 }
6413 [] PCU.receive { repeat; }
6414 [] T.timeout {
6415 setverdict(fail, "Timeout waiting for interference reports");
6416 }
6417 }
6418
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006419 /* Reset the averaging/reporting period back to default */
6420 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6421
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6423}
6424
Harald Welte3d04ae62018-04-04 20:29:05 +02006425/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006426 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006427 ***********************************************************************/
6428
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006429private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6430 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006431runs on ConnHdlr {
6432 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006433
6434 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006435 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006436 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6437 repeat;
6438 }
6439 }
6440}
6441
6442private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6443runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006444 /* Expect BTS to immediately acknowledge activation as PDCH */
6445 PCU.clear;
6446 f_rsl_chan_act(g_pars.chan_mode);
6447 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006448 timer T_wait := 2.0;
6449 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006450 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006451 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006452 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006453 [] T_wait.timeout {
6454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6455 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6456 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006457 }
6458 /* try to activate this PDCH from the PCU point of view */
6459 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6460 /* FIXME: is there a response? */
6461}
6462
6463private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6464runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006465 /* Send RSL CHAN REL (deactivate) */
6466 PCU.clear;
6467 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6468 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006469 timer T_wait := 2.0;
6470 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006471 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006472 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006473 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006474 [] T_wait.timeout {
6475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6476 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6477 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006478 }
6479 /* Emulate PCU asking BTS to deactivate PDCH */
6480 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6481 alt {
6482 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6483 setverdict(pass);
6484 }
6485 [] RSL.receive { repeat; }
6486 }
6487}
6488
6489/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006490private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006491 var PCUIF_Message first_info;
6492 var integer ts_nr := g_chan_nr.tn;
6493 var integer trx_nr := 0;
6494 var integer bts_nr := 0;
6495 var integer pcu_conn_id := -1;
6496
6497 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6498
6499 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6500 f_sleep(3.0);
6501 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6502 setverdict(pass);
6503}
6504testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6505 var ConnHdlrPars pars;
6506 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006507 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006508
6509 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6510 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6511 vc_conn.done;
6512}
6513
6514/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006515private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006516 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006517 var integer pcu_conn_id := -1;
6518
6519 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6520
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006521 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6522 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6523 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006524 setverdict(pass);
6525}
6526testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6527 var ConnHdlrPars pars;
6528 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006529 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006530
6531 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6532 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6533 vc_conn.done;
6534}
6535
6536/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006537private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006538 var PCUIF_Message first_info;
6539 var integer ts_nr := g_chan_nr.tn;
6540 var integer trx_nr := 0;
6541 var integer bts_nr := 0;
6542 var integer pcu_conn_id := -1;
6543
6544 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6545
6546 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006547 /* Send a second Chan Activ and expect it to be NACKed */
6548 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6549 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006550 setverdict(pass);
6551}
6552testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6553 var ConnHdlrPars pars;
6554 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006555 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006556
6557 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6558 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6559 vc_conn.done;
6560}
6561
6562/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006563private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006564 var PCUIF_Message first_info;
6565 var integer ts_nr := g_chan_nr.tn;
6566 var integer trx_nr := 0;
6567 var integer bts_nr := 0;
6568 var integer pcu_conn_id := -1;
6569 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6570
6571 /* register for the TCH/F channel number */
6572 f_rslem_register(0, chan_nr);
6573
6574 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6575
6576 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6577 "RSL CHAN ACT");
6578 setverdict(pass);
6579}
6580testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6581 var ConnHdlrPars pars;
6582 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006583 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006584
6585 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6586 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6587 vc_conn.done;
6588}
6589
6590/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006591private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006592 var PCUIF_Message first_info;
6593 var integer ts_nr := g_chan_nr.tn;
6594 var integer trx_nr := 0;
6595 var integer bts_nr := 0;
6596 var integer pcu_conn_id := -1;
6597 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6598 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6599
6600 /* register for the TCH/H channel numbers */
6601 f_rslem_register(0, chan_nr[0]);
6602 f_rslem_register(0, chan_nr[1]);
6603
6604 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6605
6606 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6607 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6608 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6609 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6610 setverdict(pass);
6611}
6612testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6613 var ConnHdlrPars pars;
6614 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006615 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006616
6617 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6618 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6619 vc_conn.done;
6620}
6621
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006622/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6623private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6624 var PCUIF_Message first_info;
6625 var integer ts_nr := g_chan_nr.tn;
6626 var integer trx_nr := 0;
6627 var integer bts_nr := 0;
6628 var integer pcu_conn_id := -1;
6629 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6630 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6631 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6632 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6633 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6634 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6635 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6636 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6637
6638 /* register for the TCH/H channel numbers */
6639 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6640 f_rslem_register(0, chan_nr[i]);
6641 }
6642
6643 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6644
6645 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6646 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6647 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6648 }
6649 setverdict(pass);
6650}
6651testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6652 var ConnHdlrPars pars;
6653 var ConnHdlr vc_conn;
6654 f_init();
6655
6656 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6657 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6658 vc_conn.done;
6659}
6660
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006661/* Reproduce a race condition described in OS#5245 */
6662private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6663 f_rsl_chan_act(g_pars.chan_mode);
6664 f_sleep(1.0);
6665 f_rsl_chan_deact();
6666 setverdict(pass);
6667}
6668testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6669 var ConnHdlrPars pars[2];
6670 var ConnHdlr vc_conn[2];
6671 var TrxcMessage rsp;
6672
6673 f_init();
6674
6675 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6676 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6677 ts_TRXC_FAKE_TRXC_DELAY(200));
6678
6679 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6680 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6681 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6682 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6683 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6684 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6685 pars[i], l1ctl := false);
6686 }
6687
6688 /* Wait for all components to finish */
6689 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6690 vc_conn[i].done;
6691 }
6692
6693 /* Disable the artificial delay for TRXC RSP messages */
6694 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6695 ts_TRXC_FAKE_TRXC_DELAY(0));
6696}
6697testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6698 var ConnHdlrPars pars[8];
6699 var ConnHdlr vc_conn[8];
6700 var TrxcMessage rsp;
6701
6702 f_init();
6703
6704 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6705 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6706 ts_TRXC_FAKE_TRXC_DELAY(200));
6707
6708 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6709 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6710 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6711 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6712 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6713 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6714 pars[i], l1ctl := false);
6715 }
6716
6717 /* Wait for all components to finish */
6718 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6719 vc_conn[i].done;
6720 }
6721
6722 /* Disable the artificial delay for TRXC RSP messages */
6723 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6724 ts_TRXC_FAKE_TRXC_DELAY(0));
6725}
6726
Harald Welte9bbbfb52018-04-05 09:33:19 +02006727/***********************************************************************
6728 * IPA Style Dynamic Timeslot Support
6729 ***********************************************************************/
6730
6731private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6732runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006733 /* Expect BTS to immediately acknowledge activation as PDCH */
6734 PCU.clear;
6735 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6736 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006737 timer T_wait := 2.0;
6738 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006739 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006740 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006741 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006742 [] T_wait.timeout {
6743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6744 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6745 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006746 }
6747 /* try to activate this PDCH from the PCU point of view */
6748 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6749 /* FIXME: is there a response? */
6750
6751 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6752}
6753
6754private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6755runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006756 /* Send RSL CHAN REL (deactivate) */
6757 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6758 PCU.clear;
6759 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006760 timer T_wait := 2.0;
6761 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006762 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006763 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006764 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006765 [] T_wait.timeout {
6766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6767 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6768 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006769 }
6770 /* Emulate PCU asking BTS to deactivate PDCH */
6771 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6772 alt {
6773 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6774 setverdict(pass);
6775 }
6776 [] RSL.receive { repeat; }
6777 }
6778}
6779
6780/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006781private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006782 var PCUIF_Message first_info;
6783 var integer ts_nr := g_chan_nr.tn;
6784 var integer trx_nr := 0;
6785 var integer bts_nr := 0;
6786 var integer pcu_conn_id := -1;
6787
6788 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6789
6790 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6791 f_sleep(3.0);
6792 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6793
6794 setverdict(pass);
6795
6796}
6797testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6798 var ConnHdlrPars pars;
6799 var ConnHdlr vc_conn;
6800 f_init();
6801
6802 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6803 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6804 vc_conn.done;
6805}
6806
6807/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006808private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006809 var PCUIF_Message first_info;
6810 var integer ts_nr := g_chan_nr.tn;
6811 var integer trx_nr := 0;
6812 var integer bts_nr := 0;
6813 var integer pcu_conn_id := -1;
6814
6815 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6816
6817 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6818 "RSL CHAN ACT");
6819 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6820 "RF CHAN REL", true);
6821 setverdict(pass);
6822}
6823testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6824 var ConnHdlrPars pars;
6825 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006826 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006827
6828 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6829 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6830 vc_conn.done;
6831}
6832
6833/* 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 +07006834private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006835 var PCUIF_Message first_info;
6836 var integer ts_nr := g_chan_nr.tn;
6837 var integer trx_nr := 0;
6838 var integer bts_nr := 0;
6839 var integer pcu_conn_id := -1;
6840
6841 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6842
6843 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6844 "RSL CHAN ACT");
6845
6846 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6847 alt {
6848 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6849 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006851 }
6852 [] RSL.receive { repeat; }
6853 }
6854
6855 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6856 "RF CHAN REL", true);
6857 setverdict(pass);
6858}
6859testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6860 var ConnHdlrPars pars;
6861 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006862 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006863
6864 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6865 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6866 vc_conn.done;
6867}
6868
6869/* 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 +07006870private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006871 var PCUIF_Message first_info;
6872 var integer ts_nr := g_chan_nr.tn;
6873 var integer trx_nr := 0;
6874 var integer bts_nr := 0;
6875 var integer pcu_conn_id := -1;
6876
6877 /* register for the TCH/F channel number */
6878 f_rslem_register(0, g_chan_nr);
6879
6880 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6881
6882 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6883
6884 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6885 "RSL CHAN ACT");
6886
6887 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6888
6889 setverdict(pass);
6890}
6891testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6892 var ConnHdlrPars pars;
6893 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006894 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006895
6896 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6897 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6898 vc_conn.done;
6899}
6900
6901
Harald Welte0472ab42018-03-12 15:02:26 +01006902/***********************************************************************
6903 * LAPDm / RLL related
6904 ***********************************************************************/
6905
6906private function f_tx_lapdm(template (value) LapdmFrame l,
6907 template (value) RslLinkId link_id) runs on ConnHdlr {
6908 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006909 var template (value) SacchL1Header l1h;
6910
6911 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006912 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006913 /* Compose dummy L1 header */
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07006914 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006915 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 +02006916 } else {
6917 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006918 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 +01006919 }
Harald Welte0472ab42018-03-12 15:02:26 +01006920}
6921
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006922friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006923 uint3_t sapi,
6924 RslLinkId link_id,
6925 octetstring l3,
6926 boolean exp
6927}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006928friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006929friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6930 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006931 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006932 sapi := sapi,
6933 link_id := id,
6934 l3 := l3,
6935 exp := exp
6936}
6937
6938/* execute the same callback function with a set of different parameters (tcs) on a
6939 * variety of logical channels */
6940private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6941 var ConnHdlrPars pars;
6942 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006943 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006944
6945 /* test on each of the channels we have */
6946 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6947 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6948
6949 /* test each of the test cases on the current channel */
6950 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6951 pars.spec.rll := tcs[j];
6952 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6953 vc_conn := f_start_handler(fn, pars);
6954 vc_conn.done;
6955 }
6956 }
6957
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006959}
6960
6961/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6962private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6963 var RllTestCase tc := g_pars.spec.rll;
6964 timer T := 3.0;
6965
6966 f_l1_tune(L1CTL);
6967 RSL.clear;
6968
6969 /* activate the logical channel */
6970 f_est_dchan();
6971 L1CTL.clear;
6972
6973 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6974 T.start;
6975 alt {
6976 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6977 if (tc.exp) {
6978 setverdict(pass);
6979 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006981 }
6982 }
6983 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6984 if (tc.exp) {
6985 setverdict(pass);
6986 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006988 }
6989 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006990 /* We also expect to receive the measurements */
6991 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006992 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006994 }
6995 [not tc.exp] T.timeout {
6996 setverdict(pass);
6997 }
6998 }
6999
7000 f_rsl_chan_deact();
7001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7002 f_rslem_unregister(0, g_chan_nr);
7003}
7004testcase TC_rll_est_ind() runs on test_CT {
7005 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02007006 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007007 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02007008 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007009 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007010 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007011 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
7012 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01007013 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007014 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007015 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007016 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007017 };
7018 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
7019}
7020
7021/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
7022private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
7023 var RllTestCase tc := g_pars.spec.rll;
7024 var L1ctlDlMessage dl;
7025 timer T := 3.0;
7026
7027 f_l1_tune(L1CTL);
7028 RSL.clear;
7029
7030 /* activate the logical channel */
7031 f_est_dchan();
7032 L1CTL.clear;
7033
7034 /* Send a RSL EST REQ for SAPI3 on main DCCH */
7035 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
7036 T.start;
7037 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007038 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007039 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007041 }
7042 }
7043
7044 f_rsl_chan_deact();
7045 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7046 f_rslem_unregister(0, g_chan_nr);
7047}
7048testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7049 var RllTestCases tcs := {
7050 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007051 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007052 };
7053 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7054}
7055testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7056 var RllTestCases tcs := {
7057 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007058 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007059 }
7060 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7061}
7062
7063/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007064friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007065 var L1ctlDlMessage dl;
7066 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7067 var LapdmFrame lapdm;
7068 var octetstring l2 := dl.payload.data_ind.payload;
7069 if (dl.dl_info.link_id.c == SACCH) {
7070 /* remove L1 header */
7071 l2 := substr(l2, 2, lengthof(l2)-2);
7072 }
7073 if (ischosen(exp.ab)) {
7074 lapdm.ab := dec_LapdmFrameAB(l2);
7075 } else if (ischosen(exp.b4)) {
7076 lapdm.b4 := dec_LapdmFrameB4(l2);
7077 } else if (ischosen(exp.bbis)) {
7078 lapdm.bbis := dec_LapdmFrameBbis(l2);
7079 }
7080 log("Rx LAPDm ", lapdm);
7081 if (match(lapdm, exp)) {
7082 setverdict(pass);
7083 } else {
7084 repeat;
7085 }
7086 }
7087 [] L1CTL.receive { repeat; }
7088}
7089private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7090 timer T := t;
7091 T.start;
7092 alt {
7093 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007095 }
7096 [] as_l1_exp_lapdm(exp);
7097 }
7098}
7099
7100/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7101private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007102 timer T := 2.0;
Harald Welte0472ab42018-03-12 15:02:26 +01007103 /* send SABM from MS -> BTS */
7104 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7105 /* expect RLL EST IND on Abis */
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007106 T.start;
Harald Welte0472ab42018-03-12 15:02:26 +01007107 alt {
7108 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7109 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7110 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007112 }
7113 [] RSL.receive { repeat; }
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007114 [] T.timeout {
7115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RLL EST IND");
7116 }
Harald Welte0472ab42018-03-12 15:02:26 +01007117 }
7118 /* expect UA from BTS -> MS */
7119 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7120}
7121
7122/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7123private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7124 var RllTestCase tc := g_pars.spec.rll;
7125
7126 f_l1_tune(L1CTL);
7127 RSL.clear;
7128
7129 /* activate the logical channel */
7130 f_est_dchan();
7131 L1CTL.clear;
7132
7133 /* first establish the link-layer */
7134 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7135
7136 /* then send the DISC */
7137 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7138 /* ... and expect the REL IND on the RSL side */
7139 alt {
7140 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7141 setverdict(pass);
7142 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007143 /* We also expect to receive the measurements */
7144 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007145 }
7146
7147 /* release the channel */
7148 f_rsl_chan_deact();
7149 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7150 f_rslem_unregister(0, g_chan_nr);
7151}
7152testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7153 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007154 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007155 };
7156 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7157}
7158
7159testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7160 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007161 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007162 };
7163 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7164}
7165testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7166 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007167 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007168 };
7169 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7170}
7171testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7172 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007173 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007174 };
7175 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7176}
7177
7178/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7179private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7180 var RllTestCase tc := g_pars.spec.rll;
7181 f_l1_tune(L1CTL);
7182 RSL.clear;
7183
7184 /* activate the logical channel */
7185 f_est_dchan();
7186 L1CTL.clear;
7187
7188 /* first establish the link-layer */
7189 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7190
7191 /* then send the REL REQ via RSL */
7192 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7193 /* ... and expect the DISC on the Um side */
7194 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007195 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007196 /* FIXME: send a UA in resposne to the DISC */
7197 }
7198 }
7199
7200 /* release the channel */
7201 f_rsl_chan_deact();
7202 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7203 f_rslem_unregister(0, g_chan_nr);
7204}
7205testcase TC_rll_rel_req() runs on test_CT {
7206 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007207 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7208 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7209 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7210 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007211 };
7212 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7213}
7214
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007215/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007216testcase TC_rll_data_req() runs on test_CT {
7217}
7218
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007219/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007220testcase TC_rll_data_ind() runs on test_CT {
7221}
7222
7223/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7224private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7225 var RllTestCase tc := g_pars.spec.rll;
7226
7227 f_l1_tune(L1CTL);
7228 RSL.clear;
7229
7230 f_est_dchan();
7231 L1CTL.clear;
7232
7233 /* Send UNITDATA REQ on RSL side */
7234 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7235 /* Expect it to arrive on the other side */
7236 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007237 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007238 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007239 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007240 }
7241
7242 /* release the channel */
7243 f_rsl_chan_deact();
7244 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7245 f_rslem_unregister(0, g_chan_nr);
7246}
7247testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7248 var octetstring l3 := f_rnd_octstring(15);
7249 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007250 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7251 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007252 };
7253 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7254}
7255testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7256 var octetstring l3 := f_rnd_octstring(19);
7257 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007258 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7259 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007260 };
7261 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7262}
7263
7264/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7265private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7266 var RllTestCase tc := g_pars.spec.rll;
7267
7268 f_l1_tune(L1CTL);
7269 RSL.clear;
7270
7271 f_est_dchan();
7272 L1CTL.clear;
7273
7274 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007275 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007276 /* Expdct RLL UNITDATA IND on RSL side */
7277 alt {
7278 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7279 setverdict(pass);
7280 }
7281 [] RSL.receive { repeat; }
7282 }
7283
7284 /* release the channel */
7285 f_rsl_chan_deact();
7286 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7287 f_rslem_unregister(0, g_chan_nr);
7288}
7289testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007290 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007291 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007292 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7293 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007294 };
7295 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7296}
7297testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7298 var octetstring l3 := f_rnd_octstring(18);
7299 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007300 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7301 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007302 };
7303 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7304}
7305
Harald Weltee613f962018-04-18 22:38:16 +02007306/***********************************************************************
7307 * Encryption Related
7308 ***********************************************************************/
7309
7310/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007311private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007312 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7313 if (link_id.c == SACCH) {
7314 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7315 } else {
7316 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7317 }
7318}
7319
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007320/* Expect (or not expect) other kinds of messages */
7321private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7322 [exp_any] RSL.receive { repeat; }
7323 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007325 }
7326}
7327
Harald Weltee613f962018-04-18 22:38:16 +02007328/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007329private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007330 RslLinkId link_id,
7331 octetstring l3,
7332 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007333 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007334) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007335 timer T := 3.0;
7336 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7337 T.start;
7338 /* Expect RLL UNITDATA IND on RSL side */
7339 alt {
7340 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7341 setverdict(pass);
7342 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007343 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007344 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007345 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007347 }
Harald Weltee613f962018-04-18 22:38:16 +02007348 }
7349}
7350
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007351/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7352private function f_data_mo(
7353 RslLinkId link_id,
7354 boolean p, uint3_t nr, uint3_t ns,
7355 octetstring l3,
7356 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007357 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007358) runs on ConnHdlr {
7359 timer T := 3.0;
7360 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7361 T.start;
7362 /* Expect RLL DATA IND on RSL side */
7363 alt {
7364 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7365 setverdict(pass);
7366 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007367 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007368 [] as_rsl_any_ind(exp_any);
7369 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007371 }
7372 }
7373}
7374
Harald Weltee613f962018-04-18 22:38:16 +02007375/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007376private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007377 f_l1_tune(L1CTL);
7378 f_est_dchan(true);
7379
7380 /* now we actually need to transmit some data both ways to check if the encryption works */
7381 var L1ctlDlMessage dl;
7382
Stefan Sperling603d98e2018-07-25 16:47:28 +02007383 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007384 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7385
7386 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7387 f_unitdata_mt(link_id, l3);
7388
7389 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7390 f_unitdata_mo(link_id, l3);
7391
7392 /* release the channel */
7393 f_rsl_chan_deact();
7394 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7395 f_rslem_unregister(0, g_chan_nr);
7396}
7397testcase TC_chan_act_a51() runs on test_CT {
7398 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7399 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7400 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7401}
7402testcase TC_chan_act_a52() runs on test_CT {
7403 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7404 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7405 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7406}
7407testcase TC_chan_act_a53() runs on test_CT {
7408 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7409 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7410 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7411}
Eric Wildb9260392021-05-15 19:48:22 +02007412testcase TC_chan_act_a54() runs on test_CT {
7413 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7414 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7415 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7416}
Harald Weltee613f962018-04-18 22:38:16 +02007417
Eric Wildf1827a72019-05-28 17:37:35 +02007418/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7419 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 +07007420private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007421 f_l1_tune(L1CTL);
7422 f_est_dchan(true);
7423
7424 /* now we actually need to transmit some data both ways to check if the encryption works */
7425 var L1ctlDlMessage dl;
7426
7427 var octetstring l3 := f_rnd_octstring(20);
7428 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7429
7430 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7431 f_unitdata_mt(link_id, l3);
7432
7433 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7434 f_unitdata_mo(link_id, l3);
7435
7436 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007437 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007438
7439 /* modify key to break proper encryption */
7440 g_pars.encr.key := f_rnd_octstring(8);
7441 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7442 rsl.ies := rsl.ies & { ei };
7443 RSL.send(rsl);
7444
7445 timer T0 := 1.0;
7446 T0.start;
7447 /* Expect RSL MODIFY ACK */
7448 alt {
7449 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7450 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7452 }
7453 [] T0.timeout {
7454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7455 }
7456 }
7457
7458 var octetstring l3msg := f_rnd_octstring(15);
7459 timer T1 := 3.0;
7460 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7461 due to broken encryption */
7462 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7463 T1.start;
7464 alt {
7465 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7467 }
7468 [] T1.timeout {
7469 setverdict(pass);
7470 }
7471 }
7472
7473 /* release the channel */
7474 f_rsl_chan_deact();
7475 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7476 f_rslem_unregister(0, g_chan_nr);
7477}
7478testcase TC_rsl_modify_encr() runs on test_CT {
7479 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7480 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7481 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7482}
Harald Weltee613f962018-04-18 22:38:16 +02007483
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007484/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007485private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007486runs on test_CT {
7487 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7488 var ASP_RSL_Unitdata ud;
7489 timer T;
7490
7491 /* Intave is 6 SACCH periods by default */
7492 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7493
7494 T.start(Tval);
7495 alt {
7496 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7497 setverdict(pass);
7498 }
7499 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7500 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7501 }
7502 [] RSL_CCHAN.receive { repeat; }
7503 [] T.timeout {
7504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7505 "Timeout waiting for RF RESource INDication");
7506 }
7507 }
7508}
7509testcase TC_rsl_rf_resource_ind() runs on test_CT {
7510 var RSL_ResourceInfo info := { };
7511
7512 f_init(trx_nr := 0);
7513
7514 f_init_l1ctl();
7515 f_l1_tune(L1CTL);
7516
7517 /* g_AllChannels contains all logical channels */
7518 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7519 var RslChannelNr chan_nr := g_AllChannels[i];
7520
7521 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7522 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7523 { continue; }
7524
7525 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7526 }
7527
7528 /* Align to the first interference report */
7529 f_TC_rsl_rf_resource_ind(?);
7530
7531 /* Test 4 consecutive messages */
7532 for (var integer i := 0; i < 4; i := i + 1) {
7533 f_TC_rsl_rf_resource_ind(info);
7534 }
7535
7536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7537}
7538
Harald Weltee613f962018-04-18 22:38:16 +02007539/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007540private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007541 /* L3 payload doesn't matter, as it is passed transparently */
7542 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7543 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7544 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7545
7546 f_l1_tune(L1CTL);
7547
7548 /* first establish a dedicated channel in the clear */
7549 f_est_dchan(false);
7550
7551 /* Establish ABM */
7552 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7553
7554 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7555 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7556 /* expect the L3 to arrive still unencrypted on the MS side */
7557 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7558
7559 /* configure L1 to apply ciphering */
7560 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7561 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7562
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007563 /* send first ciphered I-frame in response and expect it on RSL */
7564 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007565
7566 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7567 * and hence enable encryption also on the downlink */
7568
7569 /* expect bi-directional communication work in encrypted mode */
7570 f_unitdata_mo(link_id, f_rnd_octstring(15));
7571 f_unitdata_mt(link_id, f_rnd_octstring(15));
7572
7573 /* release the channel */
7574 f_rsl_chan_deact();
7575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7576 f_rslem_unregister(0, g_chan_nr);
7577}
7578testcase TC_encr_cmd_a51() runs on test_CT {
7579 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7580 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7581 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7582}
7583testcase TC_encr_cmd_a52() runs on test_CT {
7584 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7585 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7586 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7587}
7588testcase TC_encr_cmd_a53() runs on test_CT {
7589 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7590 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7591 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7592}
Eric Wildb9260392021-05-15 19:48:22 +02007593testcase TC_encr_cmd_a54() runs on test_CT {
7594 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7595 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7596 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7597}
Harald Weltee613f962018-04-18 22:38:16 +02007598
7599private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7600 var LapdmFrame lf;
7601 var octetstring reenc;
7602
7603 /* decode the LAPDm frame */
7604 if (ischosen(exp_match.ab)) {
7605 lf.ab := dec_LapdmFrameAB(enc);
7606 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007608 }
7609
7610 /* check if decoder result matches expectation */
7611 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007612 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007613 } else {
7614 log(name, ": matched");
7615 setverdict(pass);
7616 }
7617
7618 /* test if re-encoded frame equals original input */
7619 reenc := enc_LapdmFrame(lf);
7620 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007622 } else {
7623 setverdict(pass);
7624 }
7625}
7626
7627testcase TC_lapdm_selftest() runs on test_CT {
7628 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7629 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7630 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7631 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7632 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7633 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7634 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7635}
7636
Stefan Sperling4880be42018-08-07 18:12:59 +02007637/***********************************************************************
7638 * DTX Related (see GSM 05.08, section 8.3)
7639 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007640private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007641 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007642 var GsmFrameNumber first_fn;
7643 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007644 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007645 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007646 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7647 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007648 const integer frame_dtx_tchf_mod := 104;
7649 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7650 * which operates in terms of blocks rather than frames. */
7651 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7652 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007653 timer T := 5.0;
7654
7655 f_l1_tune(L1CTL);
7656 RSL.clear;
7657 L1CTL.clear;
7658
7659 /* activate TCHF signalling channel */
7660 f_est_dchan(false);
7661
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007662 /* A template for matching dummy LAPDm func=UA frames */
7663 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7664 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7665 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7666
Stefan Sperling4880be42018-08-07 18:12:59 +02007667 T.start;
7668 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007669 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007670 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007671
7672 if (is_first_frame) {
7673 is_first_frame := false;
7674 first_fn := dl.dl_info.frame_nr;
7675 }
7676
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007677 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007678 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007679 T.stop;
7680 f_rsl_chan_deact();
7681 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007682
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007683 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7684 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007685
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007686 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007687 setverdict(fail, "Not enough fill frames received: ",
7688 nfill_frames, " out of ", expected_fill_frames);
7689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007690 } else {
7691 setverdict(pass);
7692 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007693 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007694 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7695 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7696 * we should only see the subset of frames numbers which correspond to a block boundary.
7697 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7698 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7699 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007700 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007701 repeat;
7702 }
7703 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007704 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7705 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7706 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007707 f_rsl_chan_deact();
7708 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007709 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007710 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007711 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007712 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007713 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007714
7715 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007716 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7717 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007718 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7719 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7720 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007721 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7722 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007723 case else {
7724 /* This shall not happen, just to be sure */
7725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7726 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007727 }
7728
7729 f_rsl_chan_deact();
7730 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007731
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007732 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007733 setverdict(pass);
7734 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007735 setverdict(fail, "Not enough fill frames received: ",
7736 nfill_frames, " out of ", expected_fill_frames);
7737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007738 }
7739 } else {
7740 repeat;
7741 }
7742 }
7743 }
7744 [] L1CTL.receive { repeat; }
7745 [] T.timeout {
7746 f_rsl_chan_deact();
7747 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007749 }
7750 }
7751}
7752
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007753private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007754 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007755 var ConnHdlr vc_conn;
7756 var ConnHdlrPars pars;
7757 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007758 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007759 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007760 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007761 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007762 if (dtxd) {
7763 if (i >= 4) { /* DTX is only allowed on TCH/F */
7764 break;
7765 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007766 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007767 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007768 vc_conn.done;
7769 }
7770}
7771
7772/* Verify that L2 fill frames are sent on TCH in signaling mode if
7773 * there is nothing to transmit while DTX is disabled on downlink. */
7774testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7775 f_tch_sign_l2_fill_frame(false);
7776}
7777
7778/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7779 * there is nothing to transmit while DTX is enabled on downlink. */
7780testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7781 f_tch_sign_l2_fill_frame(true);
7782}
Harald Welte0472ab42018-03-12 15:02:26 +01007783
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007784testcase TC_chopped_ipa_ping() runs on test_CT {
7785 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7786}
7787
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007788testcase TC_chopped_ipa_payload() runs on test_CT {
7789 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7790}
7791
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007792
7793/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7794 * Return value: Measurement Report to be sent (encoded octetstring). */
7795type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7796 runs on ConnHdlr return octetstring;
7797
7798private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7799runs on ConnHdlr {
7800 var L1ctlDlMessage l1_dl;
7801 var SacchL1Header l1h;
7802 var octetstring l2;
7803
7804 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7805 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7806 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7807 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7808
7809 /* Pass it to the user specified call-back function */
7810 l2 := cb.apply(l1h, num_blocks);
7811 /* Send a Measurement Report generated by the call-back */
7812 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7813 l1_dl.dl_info.link_id,
7814 l1h, l2));
7815
7816 /* Shall we keep going? */
7817 num_blocks := num_blocks - 1;
7818 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7819 if (num_blocks > 0) { repeat; }
7820 }
7821 [] L1CTL.receive { repeat; }
7822}
7823
7824private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7825runs on ConnHdlr return octetstring {
7826 /* Command the L1 to apply received parameters */
7827 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7828
7829 /* Dummy measurement report (the results are invalid) */
7830 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7831}
7832
7833private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7834runs on ConnHdlr return octetstring {
7835 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7836 setverdict(fail, "Unexpected MS Power level change: ",
7837 g_pars.l1_pars.ms_power_level, " -> ",
7838 l1h.ms_power_lvl);
7839 }
7840
7841 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7842}
7843
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007844private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7845runs on ConnHdlr return octetstring {
7846 /* UL RSSI oscillation driven by SACCH block number */
7847 if (num_blocks rem 2 == 0) {
7848 f_trxc_fake_rssi(-100);
7849 } else {
7850 f_trxc_fake_rssi(-50);
7851 }
7852
7853 /* Make sure that MS power level remains constant */
7854 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7855}
7856
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007857/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7858private function f_TC_ms_pwr_ctrl_constant(charstring id)
7859runs on ConnHdlr {
7860 var integer num_blocks := 8;
7861 timer T := int2float(num_blocks);
7862
7863 f_l1_tune(L1CTL);
7864 RSL.clear;
7865
7866 /* These IEs are needed for autonomous MS power control */
7867 var template (value) RSL_IE_List ies := {
7868 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7869 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7870 }),
7871 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7872 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7873 })
7874 };
7875
7876 /* Ensure that 'rx-current' equals 'rx-target' */
7877 f_trxc_fake_rssi(mp_uplink_power_target);
7878
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007879 /* Populate SACCH cache with a Measurement Report */
7880 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0),
7881 ts_SacchL1Header(g_pars.l1_pars.ms_power_level,
7882 g_pars.l1_pars.ms_actual_ta),
7883 f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O)));
7884
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007885 /* Establish a dedicated channel */
7886 f_est_dchan(more_ies := valueof(ies));
7887
7888 L1CTL.clear;
7889 T.start;
7890 alt {
7891 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7892 [] T.timeout {
7893 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7894 num_blocks, " were not handled");
7895 }
7896 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007897
7898 /* Release the channel */
7899 f_rsl_chan_deact();
7900 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007901}
7902testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7903 var ConnHdlr vc_conn;
7904 var ConnHdlrPars pars;
7905
7906 f_init();
7907
7908 /* Explicitly configure the Uplink power target (in dBm) */
7909 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7910
7911 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7912 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7913 log(testcasename(), ": starting on ", pars.chan_nr);
7914
7915 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7916 pars, trxc_comp := true);
7917 vc_conn.done;
7918 }
7919
7920 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7922}
7923
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007924/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7925private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7926runs on ConnHdlr {
7927 var integer num_blocks := 16;
7928 timer T := int2float(num_blocks);
7929
7930 f_l1_tune(L1CTL);
7931 RSL.clear;
7932
7933 /* These IEs are needed for autonomous MS power control */
7934 var template (value) RSL_IE_List ies := {
7935 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7936 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7937 }),
7938 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7939 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7940 })
7941 };
7942
7943 /* Ensure that 'rx-current' equals 'rx-target' */
7944 f_trxc_fake_rssi(mp_uplink_power_target);
7945
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007946 /* Populate SACCH cache with a Measurement Report */
7947 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0),
7948 ts_SacchL1Header(g_pars.l1_pars.ms_power_level,
7949 g_pars.l1_pars.ms_actual_ta),
7950 f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O)));
7951
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007952 /* Establish a dedicated channel */
7953 f_est_dchan(more_ies := valueof(ies));
7954
7955 L1CTL.clear;
7956 T.start;
7957 alt {
7958 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7959 [] T.timeout {
7960 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7961 num_blocks, " were not handled");
7962 }
7963 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007964
7965 /* Release the channel */
7966 f_rsl_chan_deact();
7967 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007968}
7969testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7970 var ConnHdlr vc_conn;
7971 var ConnHdlrPars pars;
7972
7973 f_init();
7974
7975 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7976 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7977 /* Explicitly configure the Uplink power range (target and delte) */
7978 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7979 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7980
7981 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7982 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7983 log(testcasename(), ": starting on ", pars.chan_nr);
7984
7985 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7986 pars, trxc_comp := true);
7987 vc_conn.done;
7988 }
7989
7990 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7992}
7993
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007994private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7995 var template L1ctlDlMessage tr_bad_frame;
7996 var L1ctlDlMessage l1_dl;
7997 timer T := 8.0;
7998
7999 f_l1_tune(L1CTL);
8000 RSL.clear;
8001
8002 f_est_dchan();
8003
8004 /* There may be a few errors right after the channel activation */
8005 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
8006 L1CTL.clear;
8007
8008 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
8009 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
8010 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
8011 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
8012 tr_bad_frame.payload := ?;
8013
8014 T.start;
8015 alt {
8016 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
8017 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
8018 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
8019 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
8020 }
8021 [] as_l1_sacch();
8022 [] L1CTL.receive { repeat; }
8023 [] T.timeout {
8024 /* We're done, break the loop */
8025 setverdict(pass);
8026 }
8027 }
8028
8029 f_rsl_chan_deact();
8030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8031}
8032testcase TC_speech_no_rtp_tchf() runs on test_CT {
8033 var ConnHdlr vc_conn;
8034 var ConnHdlrPars pars;
8035
8036 f_init();
8037
8038 /* TS1, TCH/F, V1 (FR codec) */
8039 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8040 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8041 vc_conn.done;
8042}
8043testcase TC_speech_no_rtp_tchh() runs on test_CT {
8044 var ConnHdlr vc_conn;
8045 var ConnHdlrPars pars;
8046
8047 f_init();
8048
8049 /* TS5, TCH/H, V1 (HR codec) */
8050 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8051 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8052 vc_conn.done;
8053}
8054
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008055/* Verify handling of Downlink and Uplink speech frames */
8056private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8057 var L1ctlDlMessage l1_dl;
8058 var PDU_RTP rtp_pdu;
8059 var octetstring pl;
8060 timer Td, Tu;
8061
8062 f_l1_tune(L1CTL);
8063 f_est_dchan();
8064
8065 /* Activate the RTP emulation */
8066 pl := f_rnd_octstring(6);
8067 f_rtpem_activate(pl);
8068
8069 /* Give the scheduler some time to fill up the buffers */
8070 f_sleep(2.0);
8071 L1CTL.clear;
8072 RSL.clear;
8073
8074 /* Make sure that Downlink frames are received at the UE */
8075 Td.start(2.0);
8076 alt {
8077 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8078 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8079 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8080 l1_dl.payload.traffic_ind.data));
8081 setverdict(pass);
8082 }
8083 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8084 setverdict(fail, "Rx unexpected Downlink speech frame ",
8085 "(", l1_dl.payload.traffic_ind.data, ") ",
8086 "expected (", pl, ")");
8087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8088 }
8089 [] as_l1_sacch();
8090 [] L1CTL.receive { repeat; }
8091 [] Td.timeout {
8092 setverdict(fail, "Timeout waiting for Downlink speech frames");
8093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8094 }
8095 }
8096
8097 /* Make sure that Uplink frames are received at the BTS */
8098 RTPEM_DATA.clear;
8099 Tu.start(2.0);
8100 alt {
8101 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8102 if (rtp_pdu.data != pl)
8103 { repeat; }
8104 }
8105 [] RTPEM_DATA.receive { repeat; }
8106 [] Tu.timeout {
8107 setverdict(fail, "Timeout waiting for Uplink speech frames");
8108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8109 }
8110 }
8111
8112 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8113 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8114 f_rsl_chan_deact();
8115 f_rslem_unregister(0, g_chan_nr);
8116}
8117testcase TC_speech_rtp_tchf() runs on test_CT {
8118 var ConnHdlr vc_conn;
8119 var ConnHdlrPars pars;
8120
8121 f_init();
8122
8123 /* TS1, TCH/F, V1 (FR codec) */
8124 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8125 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8126 vc_conn.done;
8127
8128 /* TS1, TCH/F, V2 (EFR codec) */
8129 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8130 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8131 vc_conn.done;
8132
8133 /* TODO: also test V3 (AMR codec) */
8134
8135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8136}
8137testcase TC_speech_rtp_tchh() runs on test_CT {
8138 var ConnHdlr vc_conn;
8139 var ConnHdlrPars pars;
8140
8141 f_init();
8142
8143 /* TS5, TCH/H0, V1 (HR codec) */
8144 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8145 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8146 vc_conn.done;
8147
8148 /* TODO: also test V3 (AMR codec) */
8149
8150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8151}
8152
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008153private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8154 var GsmFrameNumber fn;
8155 var ChannelDescription ch_desc;
8156 var integer ra := 23;
8157
8158 f_l1_tune(L1CTL);
8159 RSL.clear;
8160
8161 /* Send RACH request and wait for ChanReq */
8162 fn := f_rach_req_wait_chan_rqd(ra);
8163
8164 /* The BSC already sends the Immediate Assignment, before the channel is active.
8165 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8166 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8167 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8168 if (g_pars.fhp.enabled) {
8169 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8170 } else {
8171 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8172 }
8173 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8174 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8175
8176 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8177 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8178 var L1ctlDlMessage dl;
8179 var GsmRrMessage rr;
8180
8181 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8182 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8183 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8184 rr_imm_ass.payload.imm_ass.chan_desc := *;
8185
8186 timer T := 1.0;
8187 T.start;
8188 alt {
8189 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8190 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8191 if (match(rr, rr_imm_ass)) {
8192 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8193 mtc.stop;
8194 } else {
8195 repeat;
8196 }
8197 }
8198 [] L1CTL.receive { repeat; }
8199 [] T.timeout;
8200 }
8201 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8202 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8203
8204 /* Now expect the IMM ASS on Um */
8205 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8206 setverdict(pass);
8207
8208 /* Release the channel */
8209 f_rsl_chan_deact();
8210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8211}
8212
8213testcase TC_early_immediate_assignment() runs on test_CT {
8214 var ConnHdlr vc_conn;
8215 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8216 f_init();
8217 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8218 vc_conn.done;
8219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8220}
8221
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008222private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8223 var integer ra := oct2int(f_rnd_ra_cs());
8224 var ChannelDescription ch_desc;
8225
8226 /* Tune the MS to BCCH */
8227 f_l1_tune(L1CTL);
8228
8229 /* Send RACH request and wait for ChanReq */
8230 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8231
8232 /* Activate channel on the BTS side */
8233 f_rsl_chan_act(g_pars.chan_mode);
8234
8235 /* Craft channel description (with or without frequency hopping parameters) */
8236 if (g_pars.fhp.enabled) {
8237 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8238 } else {
8239 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8240 }
8241
8242 /* Send IMM.ASS via CCHAN */
8243 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8244 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8245
8246 /* Receive IMM.ASS on the MS side */
8247 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8248
8249 /* Match the Channel Description IE in received IMM.ASS */
8250 if (not match(imm_ass.chan_desc, ch_desc)) {
8251 setverdict(fail, "Channel Description IE does not match");
8252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8253 }
8254
8255 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8256 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8257
8258 /* Expect SACCH frames on Downlink */
8259 L1CTL.clear;
8260 f_exp_sacch(true);
8261
8262 /* We're done, deactivate and release */
8263 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8264 f_rsl_chan_deact();
8265}
8266testcase TC_est_dchan() runs on test_CT {
8267 var ConnHdlr vc_conn;
8268 var ConnHdlrPars pars;
8269
8270 f_init();
8271
8272 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8273 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8274 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8275 vc_conn.done;
8276 }
8277
8278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8279}
8280
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008281private type record TopTestCase {
8282 RSL_IE_BS_Power bs_power,
8283 RSL_IE_OSMO_TopAcchCap top_cap,
8284 record of TopTestStep steps
8285};
8286private type record TopTestStep {
8287 MeasurementResults meas_res optional,
8288 GsmRxLev overpower_sacch,
8289 GsmRxLev overpower_facch
8290};
8291
8292private function f_rxlev_match(template (present) RslLinkId link_id,
8293 template (present) GsmRxLev rxlev)
8294runs on ConnHdlr {
8295 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8296 if (not match(dl.dl_info.rx_level, rxlev)) {
8297 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8298 " does not match expected RxLev := ", rxlev);
8299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8300 }
8301}
8302
8303private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8304 var TopTestCase tc := g_pars.spec.top;
8305 var GsmRxLev rxlev_dcch;
8306 var L1ctlDlMessage dl;
8307
8308 /* Wait for Pau ramping to complete */
8309 f_sleep(6.0);
8310
8311 f_l1_tune(L1CTL);
8312 L1CTL.clear;
8313 RSL.clear;
8314
8315 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8316 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8317 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8318
8319 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8320 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8321
8322 /* Additional IEs for the CHANnel ACTIVation message */
8323 var template (value) RSL_IE_List ies := {
8324 /* Employ BS power control in static mode */
8325 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8326 bs_power := tc.bs_power
8327 }),
8328 /* Indicate the given Temporary Overpower capability */
8329 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8330 top_acch_cap := tc.top_cap
8331 })
8332 };
8333
8334 /* Establish a dedicated channel */
8335 f_est_dchan(more_ies := valueof(ies));
8336
8337 /* Give it some time to stabilize */
8338 f_sleep(0.480 * 2.0);
8339 L1CTL.clear;
8340 RSL.clear;
8341
8342 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8343 var TopTestStep step := tc.steps[i];
8344 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8345 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8346
8347 log("Executing step[", i, "] := ", step);
8348
8349 /* Send RR Measurement Report (if present) */
8350 if (ispresent(step.meas_res)) {
8351 f_transceive_meas_rep(step.meas_res);
8352 f_sleep(0.480 * 2.0);
8353 L1CTL.clear;
8354 }
8355
8356 /* Check RxLev on both FACCH and SACCH */
8357 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8358 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8359
8360 setverdict(pass);
8361 }
8362}
8363testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8364 var ConnHdlrPars pars;
8365 var ConnHdlr vc_conn;
8366
8367 f_init();
8368
8369 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008370 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008371 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8372 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8373 steps := {
8374 /* Channel established, no overpower */
8375 { meas_res := omit,
8376 overpower_sacch := 0, overpower_facch := 0 },
8377
8378 /* Worst possible RxQual value, overpower of 4dB */
8379 { meas_res := ts_MeasurementResults(rxq_f := 7),
8380 overpower_sacch := 4, overpower_facch := 4 },
8381 /* Worst possible RxQual value, disabling overpower */
8382 { meas_res := ts_MeasurementResults(rxq_f := 0),
8383 overpower_sacch := 0, overpower_facch := 0 },
8384
8385 /* Lower threshold not reached, no overpower */
8386 { meas_res := ts_MeasurementResults(rxq_f := 1),
8387 overpower_sacch := 0, overpower_facch := 0 },
8388 /* Lower threshold not reached, no overpower */
8389 { meas_res := ts_MeasurementResults(rxq_f := 2),
8390 overpower_sacch := 0, overpower_facch := 0 },
8391 /* Lower threshold reached, overpower of 4dB */
8392 { meas_res := ts_MeasurementResults(rxq_f := 4),
8393 overpower_sacch := 4, overpower_facch := 4 },
8394 /* Upper threshold not reached, keeping overpower */
8395 { meas_res := ts_MeasurementResults(rxq_f := 3),
8396 overpower_sacch := 4, overpower_facch := 4 },
8397 /* Upper threshold reached, disabling overpower */
8398 { meas_res := ts_MeasurementResults(rxq_f := 2),
8399 overpower_sacch := 0, overpower_facch := 0 }
8400 }
8401 };
8402
8403 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8404 spec := { top := top }, trx_nr := 1));
8405 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8406 vc_conn.done;
8407
8408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8409}
8410testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8411 var ConnHdlrPars pars;
8412 var ConnHdlr vc_conn;
8413
8414 f_init();
8415
8416 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008417 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008418 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8419 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8420 steps := {
8421 /* Channel established, no overpower */
8422 { meas_res := omit,
8423 overpower_sacch := 0, overpower_facch := 0 },
8424
8425 /* Invalid measurement results, no overpower */
8426 { meas_res := ts_MeasurementResults(rxq_f := 7,
8427 rxq_s := 7,
8428 valid := false),
8429 overpower_sacch := 0, overpower_facch := 0 },
8430
8431 /* DTXu was in use, no overpower */
8432 { meas_res := ts_MeasurementResults(rxq_f := 7,
8433 rxq_s := 0,
8434 dtx_used := true),
8435 overpower_sacch := 0, overpower_facch := 0 },
8436 /* DTXu was in use, overpower of 4 dB */
8437 { meas_res := ts_MeasurementResults(rxq_f := 0,
8438 rxq_s := 7,
8439 dtx_used := true),
8440 overpower_sacch := 4, overpower_facch := 4 }
8441 }
8442 };
8443
8444 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8445 spec := { top := top }, trx_nr := 1));
8446 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8447 vc_conn.done;
8448
8449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8450}
8451testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8452 var ConnHdlrPars pars;
8453 var ConnHdlr vc_conn;
8454
8455 f_init();
8456
8457 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008458 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008459 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8460 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8461 rxqual := 0, /* always on */
8462 sacch_enable := false),
8463 steps := {
8464 /* Channel established, FACCH overpower */
8465 { meas_res := omit,
8466 overpower_sacch := 0, overpower_facch := 4 },
8467 /* MS indicates good RxQual, no difference */
8468 { meas_res := ts_MeasurementResults(rxq_f := 0),
8469 overpower_sacch := 0, overpower_facch := 4 },
8470 /* MS indicates bad RxQual, no difference */
8471 { meas_res := ts_MeasurementResults(rxq_f := 7),
8472 overpower_sacch := 0, overpower_facch := 4 }
8473 }
8474 };
8475
8476 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8477 spec := { top := top }, trx_nr := 1));
8478 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8479 vc_conn.done;
8480
8481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8482}
8483testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8484 var ConnHdlrPars pars;
8485 var ConnHdlr vc_conn;
8486
8487 f_init();
8488
8489 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008490 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008491 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8492 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8493 rxqual := 0, /* always on */
8494 facch_enable := false),
8495 steps := {
8496 /* Channel established, SACCH overpower */
8497 { meas_res := omit,
8498 overpower_sacch := 4, overpower_facch := 0 },
8499 /* MS indicates good RxQual, no difference */
8500 { meas_res := ts_MeasurementResults(rxq_f := 0),
8501 overpower_sacch := 4, overpower_facch := 0 },
8502 /* MS indicates bad RxQual, no difference */
8503 { meas_res := ts_MeasurementResults(rxq_f := 7),
8504 overpower_sacch := 4, overpower_facch := 0 }
8505 }
8506 };
8507
8508 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8509 spec := { top := top }, trx_nr := 1));
8510 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8511 vc_conn.done;
8512
8513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8514}
8515testcase TC_acch_overpower_limit() runs on test_CT {
8516 var ConnHdlrPars pars;
8517 var ConnHdlr vc_conn;
8518
8519 f_init();
8520
8521 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008522 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008523 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8524 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8525 rxqual := 0 /* always on */),
8526 steps := {
8527 /* Channel established, ACCH overpower of 2dB */
8528 { meas_res := omit,
8529 overpower_sacch := 2, overpower_facch := 2 },
8530 /* MS indicates good RxQual, no difference */
8531 { meas_res := ts_MeasurementResults(rxq_f := 0),
8532 overpower_sacch := 2, overpower_facch := 2 },
8533 /* MS indicates bad RxQual, no difference */
8534 { meas_res := ts_MeasurementResults(rxq_f := 7),
8535 overpower_sacch := 2, overpower_facch := 2 }
8536 }
8537 };
8538
8539 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8540 spec := { top := top }, trx_nr := 1));
8541 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8542 vc_conn.done;
8543
8544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8545}
8546
Harald Welte0472ab42018-03-12 15:02:26 +01008547/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8548/* protocol error as per 44.006 */
8549/* link layer failure (repetition of I-frame N200 times without ACK */
8550/* repetition of SABM or DISC N200 times without ACK */
8551/* receptiom of SABM in multi-frame established state */
8552
8553
Harald Welte68e495b2018-02-25 00:05:57 +01008554/* TODO Areas:
8555
8556* channel activation
8557** with BS_Power / MS_Power, bypassing power control loop
8558** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008559** with timing advance from initial activation on
8560* mode modify
8561** encryption
8562** multirate
8563* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008564** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008565* BS Power Control
8566* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008567* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008568** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008569* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008570** DATA_IND from BTS->PCU
8571** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008572
8573*/
Harald Welte70767382018-02-21 12:16:40 +01008574
8575control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008576 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008577 execute( TC_chan_act_stress() );
8578 execute( TC_chan_act_react() );
8579 execute( TC_chan_deact_not_active() );
8580 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008581 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008582 execute( TC_sacch_filling() );
8583 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008584 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008585 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008586 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008587 execute( TC_sacch_chan_act_ho_async() );
8588 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008589 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008590 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008591 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008592 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008593 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008594 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008595 execute( TC_rach_load_idle_thresh0() );
8596 execute( TC_rach_load_idle_below_thresh() );
8597 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008598 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008599 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008600 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008601 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008602 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008603 execute( TC_meas_res_sign_tchf() );
8604 execute( TC_meas_res_sign_tchh() );
8605 execute( TC_meas_res_sign_sdcch4() );
8606 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008607 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008608 execute( TC_meas_res_speech_tchf_sapi3() );
8609 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008610 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008611 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008612 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008613 execute( TC_rsl_bs_pwr_static_ass() );
8614 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008615 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008616 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008617 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008618 execute( TC_rsl_ms_pwr_dyn_up() );
8619 execute( TC_rsl_ms_pwr_dyn_down() );
8620 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8621 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008622 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008623 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008624 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008625 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008626 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008627 execute( TC_paging_imsi_80percent() );
8628 execute( TC_paging_tmsi_80percent() );
8629 execute( TC_paging_imsi_200percent() );
8630 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008631 execute( TC_rsl_protocol_error() );
8632 execute( TC_rsl_mand_ie_error() );
8633 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008634 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008635 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008636 execute( TC_si_sched_2bis() );
8637 execute( TC_si_sched_2ter() );
8638 execute( TC_si_sched_2ter_2bis() );
8639 execute( TC_si_sched_2quater() );
8640 execute( TC_si_sched_13() );
8641 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008642 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008643 execute( TC_ipa_crcx_twice_not_active() );
8644 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008645 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008646 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008647 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008648
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008649 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008650 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008651 execute( TC_pcu_act_req() );
8652 execute( TC_pcu_act_req_wrong_ts() );
8653 execute( TC_pcu_act_req_wrong_bts() );
8654 execute( TC_pcu_act_req_wrong_trx() );
8655 execute( TC_pcu_deact_req() );
8656 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008657 execute( TC_pcu_ver_si1() );
8658 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008659 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008660 if (mp_l1_supports_gprs) {
8661 execute( TC_pcu_data_req_pdtch() );
8662 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008663 execute( TC_pcu_data_req_wrong_bts() );
8664 execute( TC_pcu_data_req_wrong_trx() );
8665 execute( TC_pcu_data_req_wrong_ts() );
8666 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008667 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008668 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008669 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008670 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008671 execute( TC_pcu_data_req_imm_ass_pch() );
8672 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008673 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008674 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008675 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008676 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008677 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008678 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008679 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008680 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008681 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008682 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008683 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008684 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008685 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008686 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008687 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008688 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008689 execute( TC_dyn_osmo_pdch_act_deact() );
8690 execute( TC_dyn_osmo_pdch_double_act() );
8691 execute( TC_dyn_ipa_pdch_act_deact() );
8692 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008693 execute( TC_pcu_info_ind_fh_params() );
8694 execute( TC_pcu_socket_nsvc_ipv4() );
8695 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008696 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008697 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008698 } else {
8699 log("PCU socket path not available, skipping PCU tests");
8700 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008701
Harald Welte3d04ae62018-04-04 20:29:05 +02008702 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008703 execute( TC_dyn_osmo_pdch_tchf_act() );
8704 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008705 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008706 execute( TC_dyn_ipa_pdch_tchf_act() );
8707 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008708
8709 execute( TC_rll_est_ind() );
8710 execute( TC_rll_est_req_DCCH_3() );
8711 execute( TC_rll_est_req_ACCH_3() );
8712 execute( TC_rll_rel_ind_DCCH_0() );
8713 execute( TC_rll_rel_ind_DCCH_3() );
8714 execute( TC_rll_rel_ind_ACCH_0() );
8715 execute( TC_rll_rel_ind_ACCH_3() );
8716 execute( TC_rll_rel_req() );
8717 execute( TC_rll_unit_data_req_DCCH() );
8718 execute( TC_rll_unit_data_req_ACCH() );
8719 execute( TC_rll_unit_data_ind_DCCH() );
8720 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008721
8722 execute( TC_chan_act_a51() );
8723 execute( TC_chan_act_a52() );
8724 execute( TC_chan_act_a53() );
8725 execute( TC_encr_cmd_a51() );
8726 execute( TC_encr_cmd_a52() );
8727 execute( TC_encr_cmd_a53() );
8728
Harald Welteee25aae2019-05-19 14:32:37 +02008729 execute( TC_err_rep_wrong_mdisc() );
8730 execute( TC_err_rep_wrong_msg_type() );
8731 execute( TC_err_rep_wrong_sequence() );
8732
Harald Weltee613f962018-04-18 22:38:16 +02008733 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008734
8735 execute( TC_tch_sign_l2_fill_frame() );
8736 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008737
8738 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008739 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008740
8741 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008742 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008743
8744 execute( TC_speech_no_rtp_tchf() );
8745 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008746 execute( TC_speech_rtp_tchf() );
8747 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008748
8749 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008750
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008751 execute( TC_acch_overpower_rxqual_thresh() );
8752 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8753 execute( TC_acch_overpower_always_on_facch() );
8754 execute( TC_acch_overpower_always_on_sacch() );
8755 execute( TC_acch_overpower_limit() );
8756
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008757 /* BEWARE: these test cases can potentially break the IUT or cause
8758 * weird/unexpected behavior. Ensure that they are executed last. */
8759 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8760 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008761}
8762
8763
8764}