blob: 5cf1900dcfef517413e3be3f1332ddf6073c297b [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) {
2982 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002983 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002984 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002985 T2.stop;
2986 }
2987 [] L1CTL.receive { repeat; }
2988 [] T2.timeout {
2989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2990 "Power Level in L1 header has not increased sufficiently");
2991 }
2992 }
2993
2994 /* set a low value to ensure L1 power control level decreases */
2995 f_trxc_fake_rssi(rxlev2dbm(0));
2996
2997 timer T4 := 6.0;
2998 T4.start;
2999 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003000 [] as_l1_sacch_l1h(l1h) {
3001 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003002 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01003003 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003004 T4.stop;
3005 setverdict(pass, "Power level in L1 decreased/increased as expected");
3006 }
3007 [] L1CTL.receive { repeat; }
3008 [] T4.timeout {
3009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3010 "Power Level in L1 header has not decreased sufficiently");
3011 }
3012 }
3013
3014 f_rsl_chan_deact();
3015 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3016
3017}
3018
3019/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003020private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02003021 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003022 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003023
3024 /* set a low value to ensure power increases */
3025 f_trxc_fake_rssi(rxlev2dbm(10));
3026 f_l1_tune(L1CTL);
3027 RSL.clear;
3028
3029 var RSL_IE_List addl_ies;
3030 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3031
3032 addl_ies := {
3033 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3034 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3035 };
3036
3037 /* establish with power parameters */
3038 f_est_dchan(more_ies := addl_ies);
3039
3040 timer T1 := 10.0;
3041 T1.start;
3042 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003043 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003044 [] L1CTL.receive { repeat; }
3045 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003046 if (not isbound(l1h)) {
3047 setverdict(fail, "No SACCH blocks were received");
3048 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003049 setverdict(fail, "Power level in L1 header should not have changed");
3050 }
3051 }
3052 }
3053
3054 f_rsl_chan_deact();
3055 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3056
3057}
3058
3059/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003060private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003061 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003062 var uint5_t pwr_var := 15;
3063 var uint5_t pwr_max_var := f_get_max_power_from_band();
3064
3065 /* set a low value to ensure power increases */
3066 f_trxc_fake_rssi(rxlev2dbm(10));
3067 f_l1_tune(L1CTL);
3068 RSL.clear;
3069
3070 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3071 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3072
3073 /* establish with fixed power level */
3074 f_est_dchan(more_ies :={valueof(pwr)});
3075
3076 /* check our initial power level */
3077 f_wait_for_l1_power_level(pwr_var);
3078
3079 /* update power param to enable power loop
3080 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3081 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3082
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003083 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3084 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3085 * Add an extra offset to avoid race conditions: +1.92s. */
3086 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003087 T1.start;
3088 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003089 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003090 [] L1CTL.receive { repeat; }
3091 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003092 if (not isbound(l1h)) {
3093 setverdict(fail, "No SACCH blocks were received");
3094 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003095 setverdict(pass, "Power level in L1 header reduced as expected");
3096 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003097 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3098 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003099 }
3100 }
3101 }
3102
3103 f_rsl_chan_deact();
3104 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3105
3106}
3107
3108/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003109private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003110 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003111
3112 /* set a high value to ensure power decreases */
3113 f_trxc_fake_rssi(rxlev2dbm(50));
3114 f_l1_tune(L1CTL);
3115 RSL.clear;
3116
3117 var uint5_t pwr_var := 5;
3118 var uint5_t pwr_target_val := 15;
3119
3120 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3121 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3122
3123 /* establish with fixed power level */
3124 f_est_dchan(more_ies :={valueof(pwr)});
3125
3126 /* check our initial power level */
3127 f_wait_for_l1_power_level(pwr_var);
3128
3129 /* update power param to enable power loop
3130 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003131 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003132
3133 /* wait, then check that our power level was increased */
3134 timer T1 := 10.0;
3135 T1.start;
3136 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003137 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003138 [] L1CTL.receive { repeat; }
3139 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003140 if (not isbound(l1h)) {
3141 setverdict(fail, "No SACCH blocks were received");
3142 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3143 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003144 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003145 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003146 }
3147 }
3148 }
3149
3150 f_rsl_chan_deact();
3151 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3152
3153}
3154
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003155/* See if the power level remains constant when MS Power Parameters IE
3156 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003157private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003158 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003159
3160 /* set a high value to ensure power decreases */
3161 f_trxc_fake_rssi(rxlev2dbm(50));
3162 f_l1_tune(L1CTL);
3163 RSL.clear;
3164
3165 var uint5_t pwr_var := 5;
3166
3167 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3168 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3169
3170 /* establish with fixed power level */
3171 f_est_dchan(more_ies :={valueof(pwr)});
3172
3173 /* check our initial power level */
3174 f_wait_for_l1_power_level(pwr_var);
3175
3176 /* wait, then check that our power level did not change */
3177 timer T1 := 10.0;
3178 T1.start;
3179 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003180 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3181 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3183 "BS power control should not be active unless we receive a power parameters IE!");
3184 }
3185 repeat;
3186 }
3187 [] L1CTL.receive { repeat; }
3188 [] T1.timeout { setverdict(pass); }
3189 }
3190
3191 f_rsl_chan_deact();
3192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3193
3194}
3195
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003196/* See if the power level remains constant when MS Power Parameters IE
3197 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003198private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003199 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003200
3201 /* set a high value to ensure power decreases */
3202 f_trxc_fake_rssi(rxlev2dbm(50));
3203 f_l1_tune(L1CTL);
3204 RSL.clear;
3205
3206 var uint5_t pwr_var := 5;
3207
3208 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3209 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3210
3211 /* establish with fixed power level */
3212 f_est_dchan(more_ies :={valueof(pwr)});
3213
3214 /* check our initial power level */
3215 f_wait_for_l1_power_level(pwr_var);
3216
3217 /* pwr control without power params IE, should NOT activate MS power control*/
3218 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3219
3220 /* wait, then check that our power level did not change */
3221 timer T1 := 10.0;
3222 T1.start;
3223 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003224 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3225 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3227 "BS power control should not be active unless we receive a power parameters IE!");
3228 }
3229 repeat;
3230 }
3231 [] L1CTL.receive { repeat; }
3232 [] T1.timeout { setverdict(pass); }
3233 }
3234
3235 f_rsl_chan_deact();
3236 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3237
3238}
3239
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003240private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003241 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003242 timer T0 := 10.0;
3243 T0.start;
3244 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003245 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3246 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3248 "Power level in L1 header != signaled (RSL) power level.");
3249 }
3250 }
3251 [] L1CTL.receive { repeat; }
3252 [] T0.timeout {
3253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3254 "Timeout waiting for initial power level");
3255 }
3256 }
3257 T0.stop;
3258}
3259
3260private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3261 var IntegerRecord min_dbm_level;
3262 var IntegerRecord max_dbm_level;
3263 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3264
3265 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3266 if (min_dbm_level[i] == level) {
3267 return true;
3268 }
3269 }
3270 return false;
3271}
3272
3273private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3274 var IntegerRecord min_dbm_level;
3275 var IntegerRecord max_dbm_level;
3276 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3277
3278 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3279 if (max_dbm_level[i] == level) {
3280 return true;
3281 }
3282 }
3283 return false;
3284}
3285
3286private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3287 var IntegerRecord min_dbm_level;
3288 var IntegerRecord max_dbm_level;
3289 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3290 return max_dbm_level[0];
3291}
3292
3293type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003294private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003295private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3296 // 45.005 4.1.1
3297 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3298 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3299 2, 1, 0};
3300 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3301 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3302 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3303 var IntegerRecord rv;
3304
3305 select(band){
3306 case (BtsBand_allGSM){
3307 rv := gsm_power;
3308 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3309 max_dbm_level := {2, 1, 0};
3310 }
3311 case("DCS1800"){
3312 rv := dcs_power;
3313 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3314 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3315 }
3316 case("PCS1900"){
3317 rv := pcs_power;
3318 min_dbm_level := {15};
3319 max_dbm_level := {30};
3320 }
Harald Welte194b6912020-10-11 21:01:55 +02003321 case else {
3322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3323 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003324 }
3325
3326 return rv;
3327}
3328
3329private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003330 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 +02003331}
3332
3333testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3334 var ConnHdlr vc_conn;
3335 var ConnHdlrPars pars;
3336 f_init();
3337 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3338 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3339 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3340 pars.bts0_band := f_vty_get_bts0_band();
3341 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3342 vc_conn.done;
3343 }
3344 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3346}
3347
3348testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3349 var ConnHdlr vc_conn;
3350 var ConnHdlrPars pars;
3351 f_init();
3352 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3353 for (var integer tn := 1; tn <= 1; tn := tn+1) {
Vadim Yanitskiyc78aeb72022-07-30 17:56:39 +07003354 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN, t_guard := 30.0));
Eric Wild61edb7e2019-06-03 12:38:31 +02003355 pars.bts0_band := f_vty_get_bts0_band();
3356 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3357 vc_conn.done;
3358 }
3359 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3361}
3362
3363testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3364 var ConnHdlr vc_conn;
3365 var ConnHdlrPars pars;
3366 f_init();
3367 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3368 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3369 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3370 pars.bts0_band := f_vty_get_bts0_band();
3371 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3372 vc_conn.done;
3373 }
3374 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3376}
3377
3378testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3379 var ConnHdlr vc_conn;
3380 var ConnHdlrPars pars;
3381 f_init();
3382 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3383 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3384 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3385 pars.bts0_band := f_vty_get_bts0_band();
3386 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3387 vc_conn.done;
3388 }
3389 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3391}
3392
Eric Wild280ccb82019-06-17 11:11:52 +02003393testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3394 var ConnHdlr vc_conn;
3395 var ConnHdlrPars pars;
3396 f_init();
3397 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3398 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3399 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3400 pars.bts0_band := f_vty_get_bts0_band();
3401 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3402 vc_conn.done;
3403 }
3404 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3406}
3407
Eric Wild095024b2019-06-17 15:08:57 +02003408testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3409 var ConnHdlr vc_conn;
3410 var ConnHdlrPars pars;
3411 f_init();
3412 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3413 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3414 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3415 pars.bts0_band := f_vty_get_bts0_band();
3416 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3417 vc_conn.done;
3418 }
3419 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3421}
3422
Philipp Maier149c3922020-10-22 17:29:36 +02003423function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003424 var template RSL_IE_ChannelMode ch_mode;
3425 var ConnHdlr vc_conn;
3426 var ConnHdlrPars pars;
3427 f_init();
3428 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3429 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3430 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003431 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003432 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3433 pcu_comp := false, trxc_comp := true);
3434 vc_conn.done;
3435 }
3436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3437}
Philipp Maier149c3922020-10-22 17:29:36 +02003438
3439testcase TC_meas_res_speech_tchf() runs on test_CT {
3440 f_TC_meas_res_speech_tchf(false);
3441}
3442
3443testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3444 f_TC_meas_res_speech_tchf(true);
3445}
3446
3447function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003448 var template RSL_IE_ChannelMode ch_mode;
3449 var ConnHdlr vc_conn;
3450 var ConnHdlrPars pars;
3451 f_init();
3452 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3453 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3454 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003455 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003456 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3457 pcu_comp := false, trxc_comp := true);
3458 vc_conn.done;
3459 }
3460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3461}
Philipp Maier149c3922020-10-22 17:29:36 +02003462
3463testcase TC_meas_res_speech_tchh() runs on test_CT {
3464 f_TC_meas_res_speech_tchh(false)
3465}
3466
3467testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3468 f_TC_meas_res_speech_tchh(true)
3469}
3470
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003471testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3472 var template RSL_IE_ChannelMode ch_mode;
3473 var ConnHdlr vc_conn;
3474 var ConnHdlrPars pars;
3475 f_init();
3476 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3477 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3478 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3479 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3480 pars.l1_pars.toa256_enabled := true;
3481 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3482 pcu_comp := false, trxc_comp := true);
3483 vc_conn.done;
3484 }
3485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3486}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003487
Harald Welte70767382018-02-21 12:16:40 +01003488testcase TC_meas_res_sign_tchf() runs on test_CT {
3489 var ConnHdlr vc_conn;
3490 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003491 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003492 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003493 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003494 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003495 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3496 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003497 vc_conn.done;
3498 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003500}
3501testcase TC_meas_res_sign_tchh() runs on test_CT {
3502 var ConnHdlr vc_conn;
3503 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003504 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003505 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003506 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003507 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003508 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3509 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003510 vc_conn.done;
3511 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003513}
3514testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3515 var ConnHdlr vc_conn;
3516 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003517 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003518 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003519 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3520 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003521 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3522 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003523 vc_conn.done;
3524 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003526}
3527testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3528 var ConnHdlr vc_conn;
3529 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003530 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003531 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003532 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3533 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003534 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3535 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003536 vc_conn.done;
3537 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003539}
Harald Welte685d5982018-02-27 20:42:05 +01003540testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3541 var ConnHdlr vc_conn;
3542 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003543 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003544 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3545 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003546 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003547 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003548 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3549 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003550 vc_conn.done;
3551 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003553}
3554
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003555/* Make sure that we always get RSL MEASurement RESult messages regardless
3556 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3557private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3558 timer Texec := 8.0;
3559 timer Timpf := 2.0;
3560 timer Tmr;
3561
3562 f_l1_tune(L1CTL);
3563 RSL.clear;
3564
3565 f_est_dchan();
3566 L1CTL.clear;
3567
3568 /* Establish the main SAPI=0 link on DCCH first */
3569 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3570
3571 /* Give more time for the first RSL MEASurement RESult */
3572 Tmr.start(0.480 * 2.0);
3573 Texec.start; /* EXECution timer */
3574 Timpf.start; /* IMPFung timer */
3575
3576 alt {
3577 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3578 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3579 /* Reschedule the MEAS RES timer */
3580 Tmr.start(0.480 + 0.120);
3581 repeat;
3582 }
3583 [] RSL.receive { repeat; }
3584 [] Tmr.timeout {
3585 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3586 }
3587 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3588 [] Timpf.timeout {
3589 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3590 log("Injected SAPI=3 traffic on SACCH");
3591 Timpf.start;
3592 repeat;
3593 }
3594 /* We're good if survived so far */
3595 [] Texec.timeout {
3596 setverdict(pass);
3597 }
3598 }
3599
3600 f_rsl_chan_deact();
3601 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3602 f_rslem_unregister(0, g_chan_nr);
3603}
3604testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3605 var template RSL_IE_ChannelMode ch_mode;
3606 var template ConnHdlrPars pars;
3607 var ConnHdlr vc_conn;
3608
3609 f_init();
3610
3611 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3612 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3613
3614 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3615 vc_conn.done;
3616
3617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3618}
3619testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3620 var template RSL_IE_ChannelMode ch_mode;
3621 var template ConnHdlrPars pars;
3622 var ConnHdlr vc_conn;
3623
3624 f_init();
3625
3626 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3627 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3628
3629 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3630 vc_conn.done;
3631
3632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3633}
3634
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003635/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3636 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003637private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003638 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003639 var RSL_IE_MS_Power ms_power;
3640 var RSL_Message rsl;
3641 var uint5_t power_level := 0;
3642
3643 f_l1_tune(L1CTL);
3644 RSL.clear;
3645
3646 f_est_dchan();
3647
3648 ms_power.reserved := 0;
3649 ms_power.fpc_epc := false;
3650
3651 /* Send the first power control command. This will disable any BTS/TRX
3652 * internal power control and switch the MS (which is not in scope of
3653 * this test) to a constant power level. We start with a power level
3654 * of 0 */
3655 ms_power.power_level := power_level;
3656 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3657 RSL.send(rsl);
3658
3659 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003660 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3661 if (l1h.ms_power_lvl != power_level) {
3662 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3663 "match the signaled (RSL) power level := ", power_level);
3664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003665 }
3666
3667 /* Signal a new power level via RSL for the next turn. */
3668 if (power_level < 31) {
3669 power_level := power_level + 1;
3670 ms_power.power_level := power_level;
3671 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3672 RSL.send(rsl);
3673 repeat;
3674 }
3675
3676 }
3677
3678 /* Ignore all other blocks */
3679 [] L1CTL.receive { repeat; }
3680
3681 }
3682
3683 f_rsl_chan_deact();
3684 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3685
3686 setverdict(pass);
3687}
3688
3689testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3690 var ConnHdlr vc_conn;
3691 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003692 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003693
3694 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3695 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3696 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3697 vc_conn.done;
3698 }
3699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3700}
Harald Welte70767382018-02-21 12:16:40 +01003701
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003702/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003703TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003704private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003705 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003706 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003707
3708 f_l1_tune(L1CTL);
3709 RSL.clear;
3710
3711 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003712 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003713
3714 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3715
3716
3717 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003718 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3719 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003720 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3721 }
3722
3723 }
3724
3725 /* Ignore all other blocks */
3726 [] L1CTL.receive { repeat; }
3727
3728 }
3729
3730 f_rsl_chan_deact();
3731 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3732
3733 setverdict(pass);
3734}
3735
3736testcase TC_rsl_chan_initial_ta() runs on test_CT {
3737 var ConnHdlr vc_conn;
3738 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003739 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003740 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003741 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3742 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003743 vc_conn.done;
3744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3745}
3746
Eric Wilde57e1a62019-05-28 13:30:55 +02003747/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003748private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003749 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003750 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003751
3752 var RSL_IE_MS_Power ms_power;
3753 ms_power.reserved := 0;
3754 ms_power.fpc_epc := false;
3755 ms_power.power_level := ms_power_level;
3756
3757 f_l1_tune(L1CTL);
3758 RSL.clear;
3759
3760 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3761
3762 timer T := 1.0;
3763 T.start;
3764 alt {
3765 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003766 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3767 if (l1h.ms_power_lvl != ms_power_level) {
3768 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3769 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003770 }
3771 }
3772 /* Ignore all other blocks */
3773 [] L1CTL.receive { repeat; }
3774 [] T.timeout {
3775 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3776 }
3777 }
3778
3779 f_rsl_chan_deact();
3780 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3781 setverdict(pass);
3782}
3783
3784testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3785 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3786 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3787}
3788
Harald Welte0472ab42018-03-12 15:02:26 +01003789/* 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 +01003790private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003791 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003792 RSL.clear;
3793
3794 f_est_dchan();
3795 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003796 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003797
3798 timer T := 40.0;
3799 T.start;
3800 alt {
3801 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3802 setverdict(pass)
3803 }
3804 [] RSL.receive { repeat };
3805 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003807 }
3808 }
3809 f_rsl_chan_deact();
3810}
3811testcase TC_conn_fail_crit() runs on test_CT {
3812 var ConnHdlr vc_conn;
3813 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003814 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003815 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3816 pars.t_guard := 60.0;
3817 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3818 vc_conn.done;
3819}
3820
Harald Welte93640c62018-02-25 16:59:33 +01003821/***********************************************************************
3822 * Paging
3823 ***********************************************************************/
3824
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003825private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003826 if (tmsi == 'FFFFFFFF'O) {
3827 return true;
3828 } else {
3829 return false;
3830 }
3831}
Harald Welte70767382018-02-21 12:16:40 +01003832
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003833private type record allowedFn { integer frame_nr }
3834private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3835private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3836private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3837private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3838private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3839private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3840private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3841private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3842private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003843{
3844 var integer frame_nr_51;
3845 frame_nr_51 := frame_nr mod 51
3846
3847 var allowedFn fn_check;
3848 fn_check.frame_nr := frame_nr_51;
3849
3850 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003852 return;
3853 }
3854
3855 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3856 return;
3857 }
3858 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3859 return;
3860 }
3861 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3862 return;
3863 }
3864 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3865 return;
3866 }
3867 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3868 return;
3869 }
3870 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3871 return;
3872 }
3873 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3874 return;
3875 }
3876 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3877 return;
3878 }
3879
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003881 return;
3882}
3883
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003884private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3885 inout integer num_paging_rcv_ids,
3886 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003887runs on test_CT {
3888 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003889 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003890 repeat;
3891 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003892 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003893 var octetstring without_plen :=
3894 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3895 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003896
3897 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3898
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003899 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3900 /* Ignore empty RR Paging Request (PCH filling) messages.
3901 * TODO: does it make sense to count them? */
3902 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003903 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3904 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003905 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003906 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3907 }
3908 } else if (match(rr, tr_PAGING_REQ2)) {
3909 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3910 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3911 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3912 }
3913 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3914 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3915 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003916 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003917 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3918 }
3919 } else if (match(rr, tr_PAGING_REQ3)) {
3920 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3921 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3922 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3923 }
3924 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3925 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3926 }
3927 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3928 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3929 }
3930 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3931 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3932 }
3933 }
3934 repeat;
3935 }
3936}
3937
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003938private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003939 boolean combined_ccch,
3940 integer bs_ag_blks_res,
3941 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003942 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3943 * paging command that is issued via RSL. */
3944 integer ps_load_modulus,
3945 /* Wait until the paging queue inside the BTS is congested before starting to add
3946 * pagings via the PCU socket (0 = disabled) */
3947 boolean ps_wait_cong,
3948 /* Maximum time to wait until the paging queue is drained at the end of the test.
3949 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3950 * to set this value to 18s, however the draining process may take significantly
3951 * longer when the queue contains paging requests for PS as those are implemented
3952 * as immediate assignments and require an entire MAC block alone. */
3953 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003954 boolean exp_load_ind,
3955 boolean exp_overload,
3956 boolean use_tmsi
3957}
3958
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003959private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003960 integer num_paging_sent,
3961 integer num_paging_rcv_msgs,
3962 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003963 integer num_overload,
3964 /* When free space inside the paging queue reaches more than 2 thirds
3965 * of its capacity cong_detected is set to true. */
3966 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003967}
3968
Harald Welte68e495b2018-02-25 00:05:57 +01003969/* Helper function for paging related testing */
3970private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003971 /* Using the PCU socket affects the timing of the paging processing. We only
3972 * activate the PCU socket if we do paging load tests that include additional
3973 * paging load that is introduced through the PCU socket. */
3974 if (cfg.ps_load_modulus > 0) {
3975 f_init_with_pcuif();
3976 } else {
3977 f_init();
3978 }
Harald Welte68e495b2018-02-25 00:05:57 +01003979 f_init_l1ctl();
3980 f_l1_tune(L1CTL);
3981
Philipp Maierca058272021-06-23 10:35:23 +02003982 var octetstring imm_ass := f_rnd_octstring(23);
3983 var ASP_RSL_Unitdata load_ind;
3984
Harald Welte68e495b2018-02-25 00:05:57 +01003985 var PagingTestState st := {
3986 num_paging_sent := 0,
3987 num_paging_rcv_msgs := 0,
3988 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003989 num_overload := 0,
3990 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003991 };
3992
3993 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3994 var float max_pch_imsi_per_sec;
3995 if (cfg.use_tmsi) {
3996 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3997 } else {
3998 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3999 }
4000 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
4001 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004002 var float time_total := 20.0;
4003 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
4004 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01004005
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004006 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
4007 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01004008
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004009 timer T_itv := 0.0;
4010 T_itv.start;
4011 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01004012 alt {
4013 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004014 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01004015 st.num_overload := st.num_overload + 1;
4016 repeat;
4017 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004018 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01004020 }
Philipp Maierca058272021-06-23 10:35:23 +02004021 [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 +01004022 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02004023
4024 /* Detect paging congestion: The logic inside the BTS will diagnose the
4025 * paging queue as congested when the fill state is more than 66% (which
4026 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4027 * paging congestion is detected pagings that are issued through the PCU
4028 * socket (PS) are dropped in order to prefer the CS related pagings. */
4029 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4030 st.cong_detected := true;
4031 }
4032
Harald Welte68e495b2018-02-25 00:05:57 +01004033 /* FIXME: analyze/verify interval + contents */
4034 repeat;
4035 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004036 /* ignore other RSL messages like RF RESource INDication */
4037 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004038 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004039 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004040 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004041 /* Only relevant when testing including with PCU sock connected */
4042 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004043 [] T_itv.timeout {
4044 /* Send paging cmds based on elapsed time */
4045 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4046 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004047 var MobileIdentityV mi;
4048
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004049 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004050 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004051 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004052 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004053 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004054 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004055
4056 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004057 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 +02004058
Philipp Maierca058272021-06-23 10:35:23 +02004059 /* Add additional pagings through the PCU socket interface. */
4060 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4061 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4062 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4063 }
4064 }
4065
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004066 st.num_paging_sent := st.num_paging_sent + 1;
4067 }
4068 if (st.num_paging_sent < pkt_total) {
4069 /* Wait for interval to next PAGING COMMAND */
4070 var float time_now := T_total.read;
4071 var float next_sched := int2float(st.num_paging_sent)*interval;
4072 if (next_sched > time_now) {
4073 T_itv.start(next_sched - time_now);
4074 } else {
4075 T_itv.start(0.0);
4076 }
4077 } else {
4078 /* We are done, no need to keep counting */
4079 T_total.stop;
4080 }
4081 }
4082 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004083 }
4084 }
4085
Philipp Maierca058272021-06-23 10:35:23 +02004086 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004087 T_wait.start;
4088 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004089 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004090 [] L1CTL.receive { repeat; }
4091 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004092 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004093 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004094 /* ignore other RSL messages like RF RESource INDication */
4095 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004096 /* Only relevant when testing including with PCU sock connected */
4097 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004098 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004099 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 +01004100 }
Harald Welte68e495b2018-02-25 00:05:57 +01004101 }
4102
4103 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4104 " rcvd_ids=", st.num_paging_rcv_ids);
4105 return st;
4106}
4107
4108/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4109 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4110 * - that CCCH LOAD IND (PCH) are being generated
4111 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4112testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004113 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004114 var PagingTestCfg cfg := {
4115 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004116 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004117 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004118 ps_load_modulus := 0,
4119 ps_wait_cong := false,
4120 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004121 exp_load_ind := true,
4122 exp_overload := false,
4123 use_tmsi := false
4124 };
4125 var PagingTestState st := f_TC_paging(cfg);
4126 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4128 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004129 } else {
4130 setverdict(pass);
4131 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004133}
4134
4135/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4136 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4137 * - that CCCH LOAD IND (PCH) are being generated
4138 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4139testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004140 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004141 var PagingTestCfg cfg := {
4142 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004143 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004144 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004145 ps_load_modulus := 0,
4146 ps_wait_cong := false,
4147 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004148 exp_load_ind := true,
4149 exp_overload := false,
4150 use_tmsi := true
4151 };
4152 var PagingTestState st := f_TC_paging(cfg);
4153 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4155 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004156 } else {
4157 setverdict(pass);
4158 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004160}
4161
4162/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4163 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4164 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4165 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4166testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004167 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004168 var PagingTestCfg cfg := {
4169 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004170 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004171 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004172 ps_load_modulus := 0,
4173 ps_wait_cong := false,
4174 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004175 exp_load_ind := true,
4176 exp_overload := true,
4177 use_tmsi := false
4178 };
4179 var PagingTestState st := f_TC_paging(cfg);
4180 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4181 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004182 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004183 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004184 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 +01004185 } else {
4186 setverdict(pass);
4187 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004189}
4190
4191/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4192 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4193 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4194 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4195testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004196 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004197 var PagingTestCfg cfg := {
4198 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004199 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004200 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004201 ps_load_modulus := 0,
4202 ps_wait_cong := false,
4203 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004204 exp_load_ind := true,
4205 exp_overload := true,
4206 use_tmsi := true
4207 };
4208 var PagingTestState st := f_TC_paging(cfg);
4209 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4210 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004211 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004212 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004213 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 +01004214 } else {
4215 setverdict(pass);
4216 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004218}
4219
Philipp Maierca058272021-06-23 10:35:23 +02004220/* Same as above, but with additional paging load created by PS pagings that
4221 * are issued through the PCU socket. The additional load is introduced when
4222 * the paging queue is already two thirds full. Since the BTS implements a
4223 * prioritization logic that drops the pagings from the PCU under in those
4224 * congestive sitautions the behaviour on the PS side is expected to be
4225 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4226testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4227 var SystemInformation si3 := valueof(ts_SI3_default);
4228 var PagingTestCfg cfg := {
4229 combined_ccch := true,
4230 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4231 load_factor := 2.0,
4232 ps_load_modulus := 16,
4233 ps_wait_cong := true,
4234 queue_drain_timeout := 18.0,
4235 exp_load_ind := true,
4236 exp_overload := true,
4237 use_tmsi := false
4238 };
4239 var PagingTestState st := f_TC_paging(cfg);
4240 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4241 * slots and will fully drain that buffer before returning */
4242 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4243 if (not match(st.num_paging_rcv_ids, tpl)) {
4244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4245 } else {
4246 setverdict(pass);
4247 }
4248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4249}
4250
4251
Harald Welte68e495b2018-02-25 00:05:57 +01004252
Harald Welte93640c62018-02-25 16:59:33 +01004253/***********************************************************************
4254 * Immediate Assignment / AGCH
4255 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004256private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004257 len := 0,
4258 ma := ''B
4259}
Harald Welte93640c62018-02-25 16:59:33 +01004260
Harald Weltee8d750e2018-06-10 21:41:35 +02004261private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4262 return int2str(num_tx) & " sent, "
4263 & int2str(num_rx) & " received, "
4264 & int2str(num_del) & " deleted";
4265}
4266
4267private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4268 var L1ctlDlMessage l1_dl;
4269 timer T := 10.0;
4270 var integer num_tx := 0;
4271 var integer num_rx := 0;
4272 var integer num_del := 0;
4273 var charstring res_str;
4274 var float rx_ratio;
4275
Harald Welte10474062019-05-30 16:48:17 +02004276 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004277 f_init_l1ctl();
4278 f_l1_tune(L1CTL);
4279
4280 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004281 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004282 mp_trx_pars[0].arfcn,
4283 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004284 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4285 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004286 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004287 num_tx := num_tx+1;
4288 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004289 }
4290 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004291 T.start;
4292 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004293 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004294 num_del := num_del+1;
4295 repeat;
4296 }
4297 [] RSL_CCHAN.receive {
4298 repeat;
4299 }
4300 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004301 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4302 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4303 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004304 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004305 } else {
4306 num_rx := num_rx+1;
4307 }
4308 repeat;
4309 }
4310 [] L1CTL.receive { repeat; }
4311 [] T.timeout { }
4312 }
4313 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4314 log("AGCH test: " & res_str);
4315 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004317 }
4318 rx_ratio := int2float(num_rx) / int2float(num_tx);
4319 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004320 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 +02004321 } else {
4322 setverdict(pass);
4323 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004325}
4326
Harald Weltee8d750e2018-06-10 21:41:35 +02004327/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4328testcase TC_imm_ass_1000_20ms() runs on test_CT {
4329 f_TC_imm_ass(1000, 0.02, 0.25);
4330}
4331
4332/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4333testcase TC_imm_ass_200_0ms() runs on test_CT {
4334 f_TC_imm_ass(200, 0.0, 0.05);
4335}
4336
4337/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4338testcase TC_imm_ass_200_76ms() runs on test_CT {
4339 f_TC_imm_ass(150, 0.076, 1.00);
4340}
4341
4342
4343
Harald Welte48494ca2018-02-25 16:59:50 +01004344/***********************************************************************
4345 * BCCH
4346 ***********************************************************************/
4347
4348/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004349private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004350 GsmFrameNumber frame_number,
4351 SystemInformation si
4352}
4353
4354/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004355private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004356
4357/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004358private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004359
4360/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004361private function f_si_vecslot_contains(SystemInformationVector arr,
4362 RrMessageType key,
4363 boolean bcch_ext := false)
4364return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004365 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4366 var integer fn_mod51 := arr[i].frame_number mod 51;
4367 if (not bcch_ext and fn_mod51 == 2 or
4368 bcch_ext and fn_mod51 == 6) {
4369 if (arr[i].si.header.message_type == key) {
4370 return true;
4371 }
4372 }
4373 }
4374 return false;
4375}
4376
4377/* 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 +07004378private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4379 integer tc, RrMessageType key,
4380 boolean ext_bcch := false)
4381{
Harald Welte48494ca2018-02-25 16:59:50 +01004382 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004384 }
4385}
4386
4387/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004388private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4389 RrMessageType key)
4390return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004391 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4392 if (f_si_vecslot_contains(arr[tc], key) or
4393 f_si_vecslot_contains(arr[tc], key, true)) {
4394 return true;
4395 }
4396 }
4397 return false;
4398}
4399
4400/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004401private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4402 RrMessageType key,
4403 boolean bcch_ext := false,
4404 integer n := 1, integer m := 4)
4405return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004406 var integer count := 0;
4407 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4409 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004410 }
4411 for (var integer i:= 0; i < m; i := i + 1) {
4412 var integer fn_mod51 := arr[i].frame_number mod 51;
4413 if (not bcch_ext and fn_mod51 == 2 or
4414 bcch_ext and fn_mod51 == 6) {
4415 if (arr[i].si.header.message_type == key) {
4416 count := count + 1;
4417 }
4418 }
4419 }
4420 if (count >= n) {
4421 return true;
4422 } else {
4423 return false;
4424 }
4425}
4426
4427/* 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 +07004428private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4429 integer tc, RrMessageType key,
4430 boolean ext_bcch := false,
4431 integer n, integer m)
4432{
Harald Welte48494ca2018-02-25 16:59:50 +01004433 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004435 }
4436}
4437
4438/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004439private function f_si_vecslot_contains_only(SystemInformationVector arr,
4440 RrMessageType key,
4441 boolean bcch_ext := false)
4442return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004443 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4444 var integer fn_mod51 := arr[i].frame_number mod 51;
4445 if (not bcch_ext and fn_mod51 == 2 or
4446 bcch_ext and fn_mod51 == 6) {
4447 if (arr[i].si.header.message_type != key) {
4448 return false;
4449 }
4450 }
4451 }
4452 return true;
4453}
4454
4455/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004456private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4457 integer tc, RrMessageType key,
4458 boolean ext_bcch := false)
4459{
Harald Welte48494ca2018-02-25 16:59:50 +01004460 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004462 }
4463}
4464
4465/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004466private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004467 boolean bcch_extended,
4468 boolean si1_present,
4469 boolean si2bis_present,
4470 boolean si2ter_present,
4471 boolean si2quater_present,
4472 boolean si7_present,
4473 boolean si8_present,
4474 boolean si9_present,
4475 boolean si13_present,
4476 boolean si13alt_present,
4477 boolean si15_present,
4478 boolean si16_present,
4479 boolean si17_present,
4480 boolean si2n_present,
4481 boolean si21_present,
4482 boolean si22_present
4483}
4484
4485/* 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 +07004486private function f_validate_si_scheduling(SystemInformationConfig cfg,
4487 SystemInformationVectorPerTc si_per_tc)
4488{
Harald Welte48494ca2018-02-25 16:59:50 +01004489 var integer i;
4490 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4491 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004493 }
4494 }
4495 if (cfg.si1_present) {
4496 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4497 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4498 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4499 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4500 /* make sure *ALL* contain SI1 */
4501 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4502 }
4503 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4504 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4505 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4506 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4507 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4508 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4509
4510 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4511 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4512 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4513 * consecutive occurrences of TC = 4. */
4514 if (cfg.si2bis_present and not cfg.si2ter_present) {
4515 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4516 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4517 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4518 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4519 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4520 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4521 }
4522
4523 if (cfg.si7_present or cfg.si8_present) {
4524 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4525 * if System Information type 4 does not contain all information needed for cell
4526 * selection and reselection. */
4527 if (not cfg.bcch_extended) {
4528 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4529 }
4530 if (cfg.si7_present) {
4531 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4532 }
4533 if (cfg.si8_present) {
4534 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4535 }
4536 }
4537
4538 if (cfg.si2quater_present) {
4539 /* iii) System information type 2 quater is sent if needed, as determined by the system
4540 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4541 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4542 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4543 * within any of 4 consecutive occurrences of TC = 5. */
4544 if (not (cfg.bcch_extended)) {
4545 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4546 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4547 } else {
4548 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4549 }
4550 } else {
4551 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4552 }
4553 }
4554 if (cfg.si9_present) {
4555 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4556 * in system information type 3 as defined in 3GPP TS 44.018. */
4557 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4558 }
4559 if (cfg.si13_present) {
4560 /* vii) System Information type 13 is only related to the GPRS service. System Information
4561 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4562 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4563 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4564 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4565 * within any of 4 consecutive occurrences of TC=4. */
4566 if (not cfg.bcch_extended) {
4567 log("not-bccch-extended");
4568 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4569 } else {
4570 log("bccch-extended");
4571 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4572 }
4573 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004575 }
4576 }
4577 if (cfg.si16_present or cfg.si17_present) {
4578 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4579 * should not be sent in a cell where network sharing is used (see rule xv). */
4580 if (cfg.si22_present) {
4581 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4582 }
4583 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004585 }
4586 if (not cfg.bcch_extended) {
4587 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4588 }
4589 if (cfg.si16_present) {
4590 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4591 }
4592 if (cfg.si17_present) {
4593 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4594 }
4595 }
4596
4597 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4598 * broadcast information. The frequency with which they are sent is determined by the
4599 * system operator. System Information type 9 identifies the scheduling of System
4600 * Information type 18 and 20 messages. */
4601
4602 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4603 * Information Type 19 is present, then its scheduling shall be indicated in System
4604 * Information Type 9. */
4605
4606 if (cfg.si15_present) {
4607 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4608 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4609 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4610 * 4 consecutive occurrences of TC = 1. */
4611 if (not cfg.bcch_extended) {
4612 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4613 } else {
4614 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4615 }
4616 }
4617 if (cfg.si13alt_present) {
4618 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4619 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4620 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4621 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4622 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4623 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4624 * of TC = 4. */
4625 if (cfg.si13_present) {
4626 testcase.stop("Error: Cannot have SI13alt and SI13");
4627 }
4628 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004630 }
4631 if (not cfg.bcch_extended) {
4632 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4633 } else {
4634 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4635 }
4636 }
4637 if (cfg.si2n_present) {
4638 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4639 * as determined by the system operator. In the case that the message is sent on the
4640 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4641 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4642 * consecutive occurrences of TC = 4. */
4643 if (not cfg.bcch_extended) {
4644 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4645 } else {
4646 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4647 }
4648 }
4649 if (cfg.si21_present) {
4650 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4651 * determined by the system operator. If Extended Access Barring is in use in the cell
4652 * then this message is sent at least once within any of 4 consecutive occurrences of
4653 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4654 * cell then this message shall only be sent on BCCH Ext. */
4655 if (not cfg.bcch_extended) {
4656 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4657 } else {
4658 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4659 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004661 }
4662 }
4663 }
4664 if (cfg.si22_present) {
4665 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4666 * should not be sent in a cell where SoLSA is used (see rule viii). System
4667 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4668 * =2 and TC=6. */
4669 if (cfg.si16_present or cfg.si17_present) {
4670 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4671 }
4672 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4673 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004675 }
4676 if (not cfg.bcch_extended) {
4677 testcase.stop("Error: SI22 requires BCCH Extd!");
4678 } else {
4679 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4680 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4681 }
4682 }
4683}
4684
4685/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004686private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4687return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004688 timer T := duration;
4689 var SystemInformationVectorPerTc si_per_tc;
4690 var L1ctlDlMessage l1_dl;
4691
4692 /* initialize all per-TC vectors empty */
4693 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4694 si_per_tc[i] := {};
4695 }
4696
4697 /* flush all previous L1 queued msgs */
4698 pt.clear;
4699
4700 T.start;
4701 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004702 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004703 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4704 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4705 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004706 repeat;
4707 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004708
Harald Welte48494ca2018-02-25 16:59:50 +01004709 var integer tc := f_gsm_compute_tc(sig.frame_number);
4710 log("SI received at TC=", tc, ": ", sig.si);
4711 /* append to the per-TC bucket */
4712 si_per_tc[tc] := si_per_tc[tc] & { sig };
4713 repeat;
4714 }
4715 [] pt.receive { repeat; }
4716 [] T.timeout { }
4717 }
4718
4719 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4720 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4721 }
4722 log("si_per_tc=", si_per_tc);
4723 return si_per_tc;
4724}
4725
4726/* helper function: Set given SI via RSL + validate scheduling.
4727 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004728private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004729 var SystemInformationVectorPerTc si_per_tc;
4730 f_init_l1ctl();
4731 f_l1_tune(L1CTL);
4732
4733 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004734 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004735 f_validate_si_scheduling(si_cfg, si_per_tc);
4736
4737 setverdict(pass);
4738}
4739
4740testcase TC_si_sched_default() runs on test_CT {
4741 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004742 /* 2+3+4 are mandatory and set in f_init() */
4743 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004745}
4746
4747testcase TC_si_sched_1() runs on test_CT {
4748 f_init();
4749 si_cfg.si1_present := true;
4750 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004751 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004753}
4754
4755testcase TC_si_sched_2bis() runs on test_CT {
4756 f_init();
4757 si_cfg.si2bis_present := true;
4758 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4759 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004761}
4762
4763testcase TC_si_sched_2ter() runs on test_CT {
4764 f_init();
4765 si_cfg.si2ter_present := true;
4766 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4767 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004769}
4770
4771testcase TC_si_sched_2ter_2bis() runs on test_CT {
4772 f_init();
4773 si_cfg.si2bis_present := true;
4774 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
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_2quater() runs on test_CT {
4782 f_init();
4783 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004784 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004785 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004787}
4788
4789testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004790 /* NOTE: PCUIF connection is not used in this test case, but
4791 * without it the IUT would not broadcast SI13 (see OS#3075). */
4792 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004793 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004794 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004795 f_TC_si_sched();
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_2bis_2ter_2quater() 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.si2bis_present := true;
4804 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4805 si_cfg.si2ter_present := true;
4806 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4807 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004808 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004809 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004810 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004811 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004813}
4814
4815
Harald Welte68e495b2018-02-25 00:05:57 +01004816testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004817 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004818 /* FIXME: enable / disable individual BCCH info */
4819 //ts_RSL_BCCH_INFO(si_type, info);
4820 /* expect no ERROR REPORT after either of them *
4821 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004823}
4824
Harald Welte93640c62018-02-25 16:59:33 +01004825/***********************************************************************
4826 * Low-Level Protocol Errors / ERROR REPORT
4827 ***********************************************************************/
4828
Harald Welte01d982c2018-02-25 01:31:40 +01004829private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4830 timer T := 5.0;
4831 T.start;
4832 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004833 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004834 setverdict(pass);
4835 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004836 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004838 }
4839 [] RSL_CCHAN.receive {
4840 repeat;
4841 }
4842 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004844 }
4845 }
4846}
4847
4848/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4849testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004850 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004851 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4852 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004853 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004854
4855 f_exp_err_rep(RSL_ERR_PROTO);
4856}
4857
4858/* Provoke a mandatory IE error and match on ERROR REPORT */
4859testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004860 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004861
4862 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4863 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004864 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004865
4866 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4867}
4868
4869/* Provoke an IE content error and match on ERROR REPORT */
4870testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004871 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004872 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4873 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
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_IE_CONTENT);
4877}
4878
Harald Welteee25aae2019-05-19 14:32:37 +02004879/* attempt to activate channel with wrong RSL Message Discriminator IE */
4880function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4881 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4882 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4883 RSL.send(rsl);
4884 f_rslem_unregister(0, g_chan_nr);
4885}
4886testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4887 var ConnHdlr vc_conn;
4888 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4889
Harald Welte10474062019-05-30 16:48:17 +02004890 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004891
4892 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4893 vc_conn.done;
4894 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4895
4896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4897}
4898
4899/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004900private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004901 var template (value) RSL_Message rsl_tx;
4902 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4903 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4904 RSL.send(rsl_tx);
4905 f_rslem_unregister(0, g_chan_nr);
4906}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004907private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004908 var template (value) RSL_Message rsl_tx;
4909 /* we first have to activate the dedicated channel */
4910 f_rsl_chan_act(g_pars.chan_mode);
4911 /* ... to then send an invalid RLL message */
4912 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4913 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4914 RSL.send(rsl_tx);
4915 f_rslem_unregister(0, g_chan_nr);
4916}
4917testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4918 var ConnHdlr vc_conn;
4919 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4920 var template (value) RSL_Message rsl_tx;
4921
Harald Welte10474062019-05-30 16:48:17 +02004922 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004923
4924 /* Common Channel with wrong message type */
4925 RSL_CCHAN.clear;
4926 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4927 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004928 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004929 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4930
4931 /* TRX Management */
4932 RSL_CCHAN.clear;
4933 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4934 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004935 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004936 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4937
4938 /* Dedicated Channel */
4939 RSL_CCHAN.clear;
4940 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4941 vc_conn.done;
4942 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4943
4944 /* RLL */
4945 RSL_CCHAN.clear;
4946 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4947 vc_conn.done;
4948 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4949}
4950
4951/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004952private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004953 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4954 f_rslem_unregister(0, g_chan_nr);
4955}
4956testcase TC_err_rep_wrong_sequence() runs on test_CT {
4957 var ConnHdlr vc_conn;
4958 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4959
Harald Welte10474062019-05-30 16:48:17 +02004960 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004961
4962 RSL_CCHAN.clear;
4963 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4964 vc_conn.done;
4965 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4966}
4967
Harald Welte93640c62018-02-25 16:59:33 +01004968/***********************************************************************
4969 * IPA CRCX/MDCX/DLCS media stream handling
4970 ***********************************************************************/
4971
Harald Weltea871a382018-02-25 02:03:14 +01004972/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004973private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004974 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4975 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004976}
4977testcase TC_ipa_dlcx_not_active() runs on test_CT {
4978 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004979 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004980 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4981 vc_conn.done;
4982}
Harald Welte68e495b2018-02-25 00:05:57 +01004983
Harald Weltea3f1df92018-02-25 12:49:55 +01004984/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004985private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004986 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4987 "IPA CRCX ACK");
4988 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4989 "IPA CRCX NACK");
4990}
4991testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4992 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004993 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004994 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4995 vc_conn.done;
4996}
4997
4998/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004999private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01005000 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5001 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005002 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01005003 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5004 var uint7_t rtp_pt2 := f_rnd_int(127);
5005 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5006 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5007 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5008 "IPA MDCX ACK");
5009 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5010 "IPA DLCX ACK");
5011}
5012testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
5013 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005014 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01005015 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
5016 vc_conn.done;
5017}
5018
Harald Welte3ae11da2018-02-25 13:36:06 +01005019/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005020private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01005021 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5022 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005023 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005024 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5025 var uint7_t rtp_pt2 := f_rnd_int(127);
5026 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5027 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5028 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5029 "IPA MDCX ACK");
5030 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005031 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005032 remote_port := f_rnd_int(c_UINT16_MAX);
5033 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5034 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5035 "IPA MDCX ACK");
5036 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5037 "IPA DLCX ACK");
5038}
5039testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5040 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005041 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005042 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5043 vc_conn.done;
5044}
5045
Harald Welte9912eb52018-02-25 13:30:15 +01005046/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005047private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005048 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5049 "IPA CRCX NACK");
5050}
5051testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5052 var ConnHdlrPars pars;
5053 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005054 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005055
5056 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5057 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5058 vc_conn.done;
5059
5060 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5061 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5062 vc_conn.done;
5063}
5064
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005065/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5066private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5067 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5068 var PortNumber bind_port := 16811;
5069 var RSL_Message crcx_ack;
5070
5071 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5072 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5073 "IPA CRCX ACK");
5074 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5075 if (match(bts_bind_ip, "0.0.0.0")) {
5076 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5077 }
5078
5079 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5080 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5081 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5082 "IPA DLCX ACK");
5083}
5084testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5085 var ConnHdlrPars pars;
5086 var ConnHdlr vc_conn;
5087 f_init();
5088
5089 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5090 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5091 vc_conn.done;
5092
5093 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5094 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5095 vc_conn.done;
5096}
5097
Harald Weltea3f1df92018-02-25 12:49:55 +01005098
Harald Welte883340c2018-02-28 18:59:29 +01005099/***********************************************************************
5100 * PCU Socket related tests
5101 ***********************************************************************/
5102
Harald Welte07bd2d22019-05-25 11:03:30 +02005103/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005104friend 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 +01005105runs on test_CT {
5106 timer T := 3.0;
5107
5108 /* we don't expect any RTS.req before PDCH are active */
5109 T.start;
5110 alt {
5111 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005113 }
5114 [] PCU.receive { repeat; }
5115 [] T.timeout { }
5116 }
5117
5118 /* Send PDCH activate request for known PDCH timeslot */
5119 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5120
5121 /* we now expect RTS.req for this timeslot (only) */
5122 T.start;
5123 alt {
5124 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5125 setverdict(pass);
5126 }
5127 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5128 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005130 }
5131 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005133 }
5134 [] PCU.receive { repeat; }
5135 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005137 }
5138 [not exp_success] T.timeout {
5139 setverdict(pass);
5140 }
5141 }
5142}
5143
Harald Welte07bd2d22019-05-25 11:03:30 +02005144/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005145friend 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 +01005146runs on test_CT {
5147 timer T := 3.0;
5148
5149 /* Send PDCH activate request for known PDCH timeslot */
5150 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 +02005151 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5152 * when it will actually have been executed in the BTS */
5153 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005154 PCU.clear;
5155 /* we now expect no RTS.req for this timeslot */
5156 T.start;
5157 alt {
5158 [] 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 +02005159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005160 }
5161 [] PCU.receive { repeat; }
5162 [] T.timeout {
5163 setverdict(pass);
5164 }
5165 }
5166}
5167
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005168friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005169 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005170 map(self:PCU, system:PCU);
5171 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005172 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5173}
5174
Harald Welte883340c2018-02-28 18:59:29 +01005175/* PDCH activation via PCU socket; check for presence of RTS.req */
5176testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005177 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005178
Harald Welte883340c2018-02-28 18:59:29 +01005179 f_TC_pcu_act_req(0, 0, 7, true);
5180}
5181
5182/* PDCH activation via PCU socket on non-PDCU timeslot */
5183testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005184 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005185
Harald Welte883340c2018-02-28 18:59:29 +01005186 f_TC_pcu_act_req(0, 0, 1, false);
5187}
5188
5189/* PDCH activation via PCU socket on wrong BTS */
5190testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005191 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005192
Harald Welte883340c2018-02-28 18:59:29 +01005193 f_TC_pcu_act_req(23, 0, 7, false);
5194}
5195
5196/* PDCH activation via PCU socket on wrong TRX */
5197testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005198 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005199
Harald Welte883340c2018-02-28 18:59:29 +01005200 f_TC_pcu_act_req(0, 23, 7, false);
5201}
5202
5203/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5204testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005205 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005206
Harald Welte883340c2018-02-28 18:59:29 +01005207 /* Activate PDCH */
5208 f_TC_pcu_act_req(0, 0, 7, true);
5209 f_sleep(1.0);
5210 /* and De-Activate again */
5211 f_TC_pcu_deact_req(0, 0, 7);
5212}
5213
5214/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5215testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005216 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005217
Harald Welte883340c2018-02-28 18:59:29 +01005218 f_TC_pcu_deact_req(0, 0, 1);
5219}
5220
5221/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005222function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005223 var PCUIF_send_data sd;
5224 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005225 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005226
5227 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005228 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005229
Harald Welte883340c2018-02-28 18:59:29 +01005230 T.start;
5231 alt {
5232 [] 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 +01005233 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005234 setverdict(pass);
5235 } else {
5236 repeat;
5237 }
5238 }
5239 [] PCU.receive { repeat; }
5240 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005242 }
5243 }
5244}
5245
Philipp Maier94c08482021-02-01 17:36:05 +01005246/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5247testcase TC_pcu_ver_si1() runs on test_CT {
5248 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5249 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5250}
5251
5252/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5253testcase TC_pcu_ver_si3() runs on test_CT {
5254 const octetstring si3 := '49012223242526272929AABBCC'O;
5255 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5256}
5257
5258/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5259testcase TC_pcu_ver_si13() runs on test_CT {
5260 const octetstring si13 := '01010203040506070909'O;
5261 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5262}
5263
Harald Welte883340c2018-02-28 18:59:29 +01005264private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5265
5266/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005267friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005268 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5269runs on test_CT
5270{
5271 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5272 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5273}
5274
5275/* 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 +02005276friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5277 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005278runs on test_CT
5279{
5280 var PCUIF_send_data sd;
5281
5282 timer T := 3.0;
5283 T.start;
5284 alt {
5285 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5286 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5287 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5288 sd.data.u.rts_req.fn, sapi, data);
5289 }
5290 [] PCU.receive { repeat; }
5291 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005293 }
5294 }
5295}
5296
5297/* Send DATA.req on invalid BTS */
5298testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005299 var TfiUsfArr tua := f_TfiUsfArrInit();
5300 var octetstring data := '0000'O & f_rnd_octstring(21);
5301
5302 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005303
Harald Welte883340c2018-02-28 18:59:29 +01005304 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005305 f_TfiUsfArrSet(tua, 7, 0);
5306 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5307 f_sleep(1.0);
5308
5309 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005310}
5311
5312/* Send DATA.req on invalid TRX */
5313testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005314 var TfiUsfArr tua := f_TfiUsfArrInit();
5315 var octetstring data := '0000'O & f_rnd_octstring(21);
5316
5317 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005318
Harald Welte883340c2018-02-28 18:59:29 +01005319 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005320 f_TfiUsfArrSet(tua, 7, 0);
5321 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5322 f_sleep(1.0);
5323
5324 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005325}
5326
5327/* Send DATA.req on invalid timeslot */
5328testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005329 var TfiUsfArr tua := f_TfiUsfArrInit();
5330 var octetstring data := '0000'O & f_rnd_octstring(21);
5331
5332 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005333
Harald Welte883340c2018-02-28 18:59:29 +01005334 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005335 f_TfiUsfArrSet(tua, 7, 0);
5336 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5337 f_sleep(1.0);
5338
5339 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005340}
5341
5342/* Send DATA.req on timeslot that hasn't been activated */
5343testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005344 var TfiUsfArr tua := f_TfiUsfArrInit();
5345 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005346
Harald Welte7162a612019-05-26 12:56:09 +02005347 f_virtphy_common();
5348
5349 f_TfiUsfArrSet(tua, 7, 0);
5350 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5351 f_sleep(1.0);
5352
5353 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005354}
5355
Harald Weltead033dc2019-05-25 17:28:16 +02005356private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005357 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5358 boolean wait_rts := true)
5359runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005360 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005361 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005362
5363 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005364 if (wait_rts) {
5365 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5366 } else {
5367 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5368 }
Harald Weltead033dc2019-05-25 17:28:16 +02005369
5370 T.start;
5371 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005372 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005373 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5374 setverdict(pass);
5375 }
Harald Welte7162a612019-05-26 12:56:09 +02005376 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5377 setverdict(fail, "Received unexpected ", rx_dl);
5378 }
Harald Weltead033dc2019-05-25 17:28:16 +02005379 [] L1CTL.receive {
5380 repeat;
5381 }
Harald Welte7162a612019-05-26 12:56:09 +02005382 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005383 setverdict(fail, "Timeout waiting for ", data);
5384 }
Harald Welte7162a612019-05-26 12:56:09 +02005385 [not expect_data] T.timeout {
5386 setverdict(pass);
5387 }
Harald Weltead033dc2019-05-25 17:28:16 +02005388 }
5389}
5390
5391private function f_disable_dynamic_ts() runs on test_CT
5392{
5393 f_init_vty_bsc();
5394 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5395 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5396 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5397 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005398 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005399}
5400
5401private function f_virtphy_common() runs on test_CT {
5402 f_disable_dynamic_ts();
5403 f_init_l1ctl();
5404 f_l1_tune(L1CTL);
5405}
5406
5407testcase TC_pcu_data_req_pdtch() runs on test_CT {
5408 var TfiUsfArr tua := f_TfiUsfArrInit();
5409 var octetstring data := '0000'O & f_rnd_octstring(21);
5410
5411 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005412
Harald Welte883340c2018-02-28 18:59:29 +01005413 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005414 f_TfiUsfArrSet(tua, 7, 0);
5415 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5416 f_sleep(1.0);
5417
5418 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005419}
5420
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005421/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005422testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005423 var TfiUsfArr tua := f_TfiUsfArrInit();
5424 var octetstring data := '0000'O & f_rnd_octstring(21);
5425
5426 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005427
Harald Welte883340c2018-02-28 18:59:29 +01005428 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005429 f_TfiUsfArrSet(tua, 7, 0);
5430 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5431 f_sleep(1.0);
5432
5433 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005434}
5435
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005436private function f_TC_pcu_ptcch_ul(uint16_t ra)
5437runs on test_CT {
5438 var template PCUIF_Message pcu_rach_ind;
5439 var PCUIF_send_data sd;
5440 var GsmFrameNumber fn;
5441 timer T;
5442
5443 /* Send an Access Burst on PTCCH/U over the Um-interface */
5444 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5445 chan_nr := ts_RslChanNr_PDCH(7),
5446 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5447
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005448 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5449 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005450
5451 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5452 T.start(52.0 * 4.615 / 1000.0);
5453 alt {
5454 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5455 log("Rx an Access Burst on the PCU interface: ", sd.data);
5456 setverdict(pass);
5457 T.stop;
5458 }
5459 [] PCU.receive { repeat; }
5460 [] T.timeout {
5461 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5462 /* Keep going, that's not the end of the world */
5463 }
5464 }
5465}
5466
5467testcase TC_pcu_ptcch() runs on test_CT {
5468 var L1ctlDlMessage dl;
5469 var octetstring data;
5470 timer T;
5471
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005472 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005473 f_init_l1ctl();
5474 f_l1_tune(L1CTL);
5475
5476 /* Activate PDCH channel on TS7 */
5477 f_TC_pcu_act_req(0, 0, 7, true);
5478
5479 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005480 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005481 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005482 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005483 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005484
5485 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5486 for (var integer i := 0; i < 16; i := i + 1) {
5487 log("Sending an Access Burst towards the L1CTL interface");
5488 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5489 }
5490
5491 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5492 data := f_rnd_octstring(23);
5493
5494 /* Verify PTCCH/D: send a random data block, make sure it's received */
5495 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5496 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5497
5498 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5499 * let's give it more time in case if we miss the beginning. */
5500 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5501 alt {
5502 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5503 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5504 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5505 frame := data)) -> value dl {
5506 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5507 setverdict(pass);
5508 T.stop;
5509 }
5510 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5511 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5512 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5513 l2_data := data)) -> value dl {
5514 log("Rx PTCCH/D data block on L1CTL: ", dl);
5515 setverdict(pass);
5516 T.stop;
5517 }
5518 [] L1CTL.receive { repeat; }
5519 [] T.timeout {
5520 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5521 }
5522 }
5523}
5524
Harald Welte883340c2018-02-28 18:59:29 +01005525/* Send AGCH from PCU; check it appears on Um side */
5526testcase TC_pcu_data_req_agch() runs on test_CT {
5527 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005528 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005529 f_init_l1ctl();
5530 f_l1_tune(L1CTL);
5531
5532 f_TC_pcu_act_req(0, 0, 7, true);
5533 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5534
5535 T.start;
5536 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005537 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005538 setverdict(pass);
5539 }
5540 [] L1CTL.receive { repeat; }
5541 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005543 }
5544 }
5545}
5546
Harald Welte928622b2019-05-26 13:22:59 +02005547/* Send AGCH from PCU; check it appears on Um side */
5548testcase TC_pcu_data_req_pch() runs on test_CT {
5549 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005550 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005551 f_init_l1ctl();
5552 f_l1_tune(L1CTL);
5553
5554 f_TC_pcu_act_req(0, 0, 7, true);
5555 /* three characters prefix: last 3 digits of IMSI as ASCII */
5556 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5557
5558 T.start;
5559 alt {
5560 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5561 setverdict(pass);
5562 }
5563 [] L1CTL.receive { repeat; }
5564 [] T.timeout {
5565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5566 }
5567 }
5568}
5569
Harald Welte883340c2018-02-28 18:59:29 +01005570/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5571testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5572 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005573 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005574 f_init_l1ctl();
5575 f_l1_tune(L1CTL);
5576
5577 /* append 3 last imsi digits so BTS can compute pagng group */
5578 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5579
5580 timer T := 0.5;
5581 T.start;
5582 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005583 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005584 /* TODO: verify paging group */
5585 setverdict(pass);
5586 }
5587 [] L1CTL.receive { repeat; }
5588 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005590 }
5591 }
5592}
5593
5594/* Send RACH from Um side, expect it to show up on PCU socket */
5595testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005596 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005597 f_init_l1ctl();
5598 f_l1_tune(L1CTL);
5599
5600 var GsmFrameNumber fn_last := 0;
5601 for (var integer i := 0; i < 1000; i := i+1) {
5602 var OCT1 ra := f_rnd_ra_ps();
5603 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5604 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005606 }
5607 fn_last := fn;
5608
5609 timer T := 2.0;
5610 T.start;
5611 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005612 [] 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 +01005613 T.stop;
5614 }
5615 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005617 }
5618 [] PCU.receive { repeat; }
5619 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005621 }
5622 }
5623 }
5624 setverdict(pass);
5625}
5626
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005627/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5628 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5629testcase TC_pcu_ext_rach_content() runs on test_CT {
5630 var template PCUIF_Message pcu_rach_ind;
5631 var GsmFrameNumber fn_last := 0;
5632 var L1ctlRachSynchSeq synch_seq;
5633 var PCUIF_BurstType pcu_bt;
5634 var GsmFrameNumber fn;
5635 var BIT11 ra11;
5636
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005637 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005638 f_init_l1ctl();
5639 f_l1_tune(L1CTL);
5640
5641 for (var integer i := 0; i < 1000; i := i+1) {
5642 /* We need to test both TS1 & TS2 */
5643 if (i rem 2 == 0) {
5644 synch_seq := RACH_SYNCH_SEQ_TS1;
5645 pcu_bt := BURST_TYPE_1;
5646 } else {
5647 synch_seq := RACH_SYNCH_SEQ_TS2;
5648 pcu_bt := BURST_TYPE_2;
5649 }
5650
5651 ra11 := f_rnd_ra11_ps();
5652 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5653 if (fn == fn_last) {
5654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5655 "Two RACH in same FN?!?");
5656 }
5657 fn_last := fn;
5658
5659 /* Compose the expected message */
5660 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005661 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005662 ra := bit2int(ra11),
5663 is_11bit := 1,
5664 burst_type := pcu_bt,
5665 fn := fn);
5666
5667 timer T := 2.0;
5668 T.start;
5669 alt {
5670 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5671 T.stop;
5672 }
5673 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5675 }
5676 [] PCU.receive { repeat; }
5677 [] T.timeout {
5678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5679 }
5680 }
5681 }
5682 setverdict(pass);
5683}
5684
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005685private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5686runs on test_CT {
5687 var template PCUIF_send_data sdt;
5688 var PCUIF_send_data sd;
5689 var int16_t lqual_cb;
5690 timer T := 1.0;
5691
5692 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5693 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5694
5695 /* Send a random PDTCH frame over Um */
5696 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5697 '0000'O & f_rnd_octstring(21)));
5698
5699 T.start;
5700 alt {
5701 /* If expected link quality is above the threshold */
5702 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5703 lqual_cb := sd.data.u.data_ind.lqual_cb;
5704 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5705
5706 /* Make sure the actual link quality matches the expected value */
5707 if (not match(lqual_cb, lqual_cb_exp)) {
5708 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5709 "expected value ", lqual_cb_exp));
5710 } else {
5711 setverdict(pass);
5712 }
5713 }
5714 /* If expected link quality is below the threshold */
5715 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5717 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5718 }
5719 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5720 [] PCU.receive { repeat; }
5721 [lqual_cb_exp < thresh] T.timeout {
5722 log("Rx nothing, as expected");
5723 setverdict(pass);
5724 }
5725 [lqual_cb_exp >= thresh] T.timeout {
5726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5727 "Timeout waiting for PCUIF_DATA.ind");
5728 }
5729 }
5730}
5731
5732/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5733testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005734 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005735 PCU.clear;
5736
5737 f_init_l1ctl();
5738 f_l1_tune(L1CTL);
5739
5740 /* Activate a PDCH channel on TS7 */
5741 f_TC_pcu_act_req(0, 0, 7, true);
5742
5743 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005744 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005745 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005746 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005747 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005748
5749 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5750 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5751 var TrxcMessage ret;
5752
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005753 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005754
5755 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5756 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5757 }
5758}
5759
Harald Welte883340c2018-02-28 18:59:29 +01005760/* Send PAGING via RSL, expect it to shw up on PCU socket */
5761testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005762 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005763
5764 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005765 var MobileIdentityLV mi_lv;
5766 var octetstring mi_lv_enc;
5767 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005768 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005769
Harald Welte883340c2018-02-28 18:59:29 +01005770 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005771 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005772 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005773 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005774 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005775
5776 /* Fancy encoding for PCUIF */
5777 mi_lv := valueof(ts_MI_LV(mi));
5778 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5779 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005780
5781 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005782 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005783 T.start;
5784 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005785 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005786 }
5787 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005788 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005789 }
5790 [] PCU.receive { repeat; }
5791 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005793 }
5794 }
5795 }
5796 setverdict(pass);
5797}
5798
Harald Welted66c9b82019-05-25 09:03:15 +02005799/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5800testcase TC_pcu_time_ind() runs on test_CT {
5801 var PCUIF_send_data pcu_sd;
5802 var integer num_time_ind := 0;
5803 var integer first_fn, last_fn;
5804 var float test_duration := 5.0;
5805 timer T;
5806
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005807 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005808 f_TC_pcu_act_req(0, 0, 7, true);
5809
5810 PCU.clear;
5811 T.start(test_duration);
5812 alt {
5813 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5814 num_time_ind := num_time_ind + 1;
5815 if (not isbound(first_fn)) {
5816 first_fn := pcu_sd.data.u.time_ind.fn;
5817 }
5818 last_fn := pcu_sd.data.u.time_ind.fn;
5819 repeat;
5820 }
5821 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5822 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5823 repeat;
5824 }
5825 [] PCU.receive {
5826 repeat;
5827 }
5828 [] T.timeout {}
5829 }
5830 var integer fn_expired := last_fn - first_fn;
5831 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5832
5833 /* verify the number of frames expired matches our expectation */
5834 const float c_GSM_FN_DURATION_MS := 4.61538;
5835 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005836 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005837 if (not match(fn_expired, t_fn_expected)) {
5838 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5839 }
5840
5841 /* There are three TIME.ind in every fn MOD 13 */
5842 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5843 /* Add some tolerance */
5844 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5845 if (not match(num_time_ind, t_time_ind_exp)) {
5846 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5847 }
5848
5849 setverdict(pass);
5850}
5851
Harald Welte4832c862019-05-25 14:57:18 +02005852/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5853testcase TC_pcu_rts_req() runs on test_CT {
5854 var PCUIF_send_data pcu_sd;
5855 var integer first_fn, last_fn;
5856 var integer num_rts_pdtch := 0;
5857 var integer num_rts_ptcch := 0;
5858 var float test_duration := 5.0;
5859 timer T;
5860
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005861 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005862 f_TC_pcu_act_req(0, 0, 7, true);
5863
5864 PCU.clear;
5865 T.start(test_duration);
5866 alt {
5867 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5868 -> value pcu_sd {
5869 num_rts_pdtch := num_rts_pdtch + 1;
5870 if (not isbound(first_fn)) {
5871 first_fn := pcu_sd.data.u.rts_req.fn;
5872 }
5873 last_fn := pcu_sd.data.u.rts_req.fn;
5874 repeat;
5875 }
5876 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5877 -> value pcu_sd {
5878 num_rts_ptcch := num_rts_ptcch + 1;
5879 if (not isbound(first_fn)) {
5880 first_fn := pcu_sd.data.u.rts_req.fn;
5881 }
5882 last_fn := pcu_sd.data.u.rts_req.fn;
5883 repeat;
5884 }
5885 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5886 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5887 repeat;
5888 }
5889 [] PCU.receive {
5890 repeat;
5891 }
5892 [] T.timeout {}
5893 }
5894 var integer fn_expired := last_fn - first_fn;
5895 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5896 ", num_rts_ptcch=", num_rts_ptcch);
5897
5898 /* verify the number of frames expired matches our expectation */
5899 const float c_GSM_FN_DURATION_MS := 4.61538;
5900 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005901 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005902 if (not match(fn_expired, t_fn_expected)) {
5903 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5904 }
5905
5906 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5907 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5908 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5909 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5910 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5911 t_ptcch_exp);
5912 }
5913
5914 /* We have 12 PDTCH blocks every 52-multiframe */
5915 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5916 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5917 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5918 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5919 t_pdtch_exp);
5920 }
5921
5922 setverdict(pass);
5923}
5924
Harald Welte07bd2d22019-05-25 11:03:30 +02005925/* test for generating Abis side OML ALERT from the PCU */
5926testcase TC_pcu_oml_alert() runs on test_CT {
5927 var PCUIF_send_data pcu_sd;
5928 var integer num_time_ind := 0;
5929 var integer first_fn, last_fn;
5930 var float test_duration := 5.0;
5931 timer T;
5932
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005933 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005934 f_TC_pcu_act_req(0, 0, 7, true);
5935
5936 /* re-connect CTRL port from BTS to BSC */
5937 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005938 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005939
5940 /* Send that OML Alert */
5941 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5942
5943 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5944 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5945 setverdict(pass);
5946}
5947
Harald Welteeaa9a862019-05-26 23:01:08 +02005948/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5949private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5950 var PCUIF_Message first_info;
5951 var integer pcu_conn_id := -1;
5952 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5953 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5954 var OCT4 tlli := '01020304'O;
5955 var OCT1 cause := '23'O;
5956 timer T := 5.0;
5957
5958 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5959
5960 f_l1_tune(L1CTL);
5961 RSL.clear;
5962
5963 f_est_dchan();
5964 L1CTL.clear;
5965
5966 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5967
5968 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5969 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5970 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5971
5972 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5973 T.start;
5974 alt {
5975 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5976 setverdict(pass);
5977 }
5978 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5979 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5980 }
5981 [] PCU.receive {
5982 repeat;
5983 }
5984 [] T.timeout {
5985 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5986 }
5987 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005988
5989 /* release the channel */
5990 f_rsl_chan_deact();
5991 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5992 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005993}
5994testcase TC_pcu_rr_suspend() runs on test_CT {
5995 var ConnHdlrPars pars;
5996 var ConnHdlr vc_conn;
5997
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005998 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005999
6000 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
6001 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
6002 vc_conn.done;
6003}
Harald Welte07bd2d22019-05-25 11:03:30 +02006004
Harald Weltea2e0e942019-05-27 18:12:53 +02006005/* Ensure that PCUIF socket can accept only a single connection */
6006testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006007 var boolean connected := false;
6008 var UD_connect_result cr;
6009 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02006010 timer T := 5.0;
6011
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006012 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
6013 var template UD_Result tr_err := { result_code := ERROR, err := ? };
6014
Harald Weltea2e0e942019-05-27 18:12:53 +02006015 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006016 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02006017
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006018 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02006019 PCU.send(UD_connect:{mp_pcu_socket, -1});
6020 T.start;
6021 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006022 /* the IUT will first accept() the new connection, and close() it immediately */
6023 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
6024 log("BTS has accept()ed connection");
6025 connected := true;
6026 cid := cr.id;
6027 repeat;
6028 }
6029 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6030 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006031 setverdict(pass);
6032 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006033 /* ignore other messages related to the first connection */
6034 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006035 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006036 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006037 }
6038 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006039
Harald Weltea2e0e942019-05-27 18:12:53 +02006040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6041}
6042
Harald Weltec8effb72019-05-27 18:23:04 +02006043/* Ensure that PCUIF socket can disconnect + reconnect */
6044testcase TC_pcu_socket_reconnect() runs on test_CT {
6045 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006046 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006047
6048 f_sleep(1.0);
6049
6050 f_pcuif_close(PCU, g_pcu_conn_id);
6051 g_pcu_conn_id := -1;
6052
6053 f_sleep(1.0);
6054
6055 /* re-connect */
6056 PCU.clear;
6057 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6058 setverdict(pass);
6059
6060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6061}
6062
Harald Weltebe030482019-05-27 22:29:35 +02006063/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006064private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6065runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006066 var L1ctlDlMessage l1_dl;
6067 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006068 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006069 timer T := 5.0;
6070 T.start;
6071 alt {
6072 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006073 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6074 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006075 repeat;
6076 }
6077 }
6078 [] pt.receive {
6079 repeat;
6080 }
6081 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6083 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006084 }
6085 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006086 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006087}
6088
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006089/* Check if GPRS Indicator is present in RR System Information of a given type */
6090private function f_si_has_gprs_indicator(RrMessageType si_type)
6091runs on test_CT return boolean {
6092 var SystemInformation si := f_get_si(L1CTL, si_type);
6093
6094 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006095 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006096 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006097 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006098 }
6099
6100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6101 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006102}
6103
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006104/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6105private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6106runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006107 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006108 f_init_l1ctl();
6109 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006110 f_sleep(2.0);
6111 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006112
6113 if (f_si_has_gprs_indicator(si_type)) {
6114 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006115 } else {
6116 setverdict(pass);
6117 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006118
Harald Weltebe030482019-05-27 22:29:35 +02006119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6120}
6121
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006122testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6123 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6124}
Harald Weltebe030482019-05-27 22:29:35 +02006125
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006126testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6127 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6128}
6129
6130/* Ensure that GPRS capability is advertised after PCU socket connect */
6131private function f_TC_pcu_socket_connect(RrMessageType si_type)
6132runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006133 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006134 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006135 f_init_l1ctl();
6136 f_l1_tune(L1CTL);
6137
6138 f_sleep(2.0);
6139 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006140
6141 if (not f_si_has_gprs_indicator(si_type)) {
6142 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006143 } else {
6144 setverdict(pass);
6145 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006146
Harald Weltebe030482019-05-27 22:29:35 +02006147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6148}
6149
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006150testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6151 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6152}
Harald Weltebe030482019-05-27 22:29:35 +02006153
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006154testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6155 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6156}
6157
6158/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6159private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6160runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006161 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006162 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006163 f_init_l1ctl();
6164 f_l1_tune(L1CTL);
6165
6166 f_pcuif_close(PCU, g_pcu_conn_id);
6167 g_pcu_conn_id := -1;
6168
6169 f_sleep(1.0);
6170
6171 /* re-connect */
6172 PCU.clear;
6173 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6174
6175 f_sleep(2.0);
6176 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006177
6178 if (f_si_has_gprs_indicator(si_type)) {
6179 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006180 } else {
6181 setverdict(pass);
6182 }
6183
6184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6185}
6186
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006187testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6188 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6189}
6190
6191testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6192 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6193}
6194
Oliver Smithf5239c72019-08-28 10:01:25 +02006195/* 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) */
6196testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6197 var SystemInformation si3 := valueof(ts_SI3_default);
6198
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006199 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006200
Harald Welte76220222020-10-11 20:32:44 +02006201 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6202 * information */
6203 timer T := 2.0;
6204 T.start;
6205 alt {
6206 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6207 [] T.timeout {}
6208 }
6209
Oliver Smithf5239c72019-08-28 10:01:25 +02006210 /* Verify cell_id */
6211 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6212 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6213 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006214 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6215 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6216 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006217 }
6218
6219 /* Verify LAC */
6220 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6221 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6222 if (lac_si3 != lac_pcu) {
6223 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6224 }
6225
6226 setverdict(pass);
6227}
Harald Welted66c9b82019-05-25 09:03:15 +02006228
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006229/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6230testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6231 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006232 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006233
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006234 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006235
6236 info_ind := g_pcu_last_info.u.info_ind;
6237
6238 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6239 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006240 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006241 /* Skip inactive timeslots */
6242 continue;
6243 }
6244
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006245 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006246 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006247 else
6248 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006249
6250 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006251 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006252 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006253 hsn := fhp.maio_hsn.hsn,
6254 maio := fhp.maio_hsn.maio,
6255 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006256 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006257 } else {
6258 tr_ts := tr_PCUIF_InfoTrxTsH0;
6259 }
6260
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006261 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006262 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6263 if (not match(ts, tr_ts)) {
6264 setverdict(fail, "Hopping parameters do not match: ",
6265 "received ", ts, " vs expected ", tr_ts);
6266 } else {
6267 setverdict(pass);
6268 }
6269 }
6270 }
6271}
6272
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006273/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006274testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6275 f_init_vty_bsc();
6276 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6277 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6278
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006279 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006280
6281 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006282 var template PCUIF_RemoteAddr tr_remote_addr := {
6283 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006284 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006285 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006286
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006287 if (not match(remote_addr, tr_remote_addr)) {
6288 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006289 }
6290
6291 setverdict(pass);
6292}
6293
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006294/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006295testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6296 f_init_vty_bsc();
6297 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6298
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006299 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006300
6301 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006302 var template PCUIF_RemoteAddr tr_remote_addr := {
6303 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6304 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6305 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006306
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006307 if (not match(remote_addr, tr_remote_addr)) {
6308 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006309 }
6310
6311 setverdict(pass);
6312}
6313
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006314/* Verify coding of two NSVCs in the INFO.ind message */
6315testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6316 f_init_vty_bsc();
6317
6318 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6319 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6320 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6321 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6322
6323 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6324 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6325 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6326 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6327
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006328 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006329
6330 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6331 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6332 var template PCUIF_RemoteAddr tr_remote_addr := {
6333 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006334 addr := {
6335 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6336 f_inet6_addr("fd00::ca:ff:ee")
6337 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006338 };
6339
6340 if (not match(info_ind.nsvci, { 1234, 5678 }))
6341 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6342 if (not match(remote_addr, tr_remote_addr))
6343 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6344 if (not match(info_ind.local_port, { 1234, 5678 }))
6345 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6346 if (not match(info_ind.remote_port, { 1234, 5678 }))
6347 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6348
6349 setverdict(pass);
6350}
6351
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006352/* Verify periodic interference reports on PDCH */
6353testcase TC_pcu_interf_ind() runs on test_CT {
6354 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006355 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006356 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006357 var PCUIF_send_data sd;
6358 timer T;
6359
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006360 /* Set the averaging/reporting period to 480ms */
6361 f_init_vty_bsc();
6362 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6363 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6364
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006365 f_init_with_pcuif();
6366 f_TC_pcu_act_req(0, 0, 7, true);
6367
6368 /* We need trxcon for NOPE indications */
6369 f_init_l1ctl();
6370 f_l1_tune(L1CTL);
6371
6372 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006373 tr_interf_ind := tr_PCUIF_INTERF_IND(
6374 bts_nr := 0,
6375 trx_nr := 0,
6376 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006377 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006378 );
6379
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006380 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006381 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006382 /* The first interference report may contain unreliable values, so we ignore it */
6383 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6384 /* 4 SACCH periods => 4 reports (plus some guard time) */
6385 T.start(0.480 * 4.0 + 0.480 / 2.0);
6386 first := false;
6387 repeat;
6388 }
6389 /* Subsequent interference reports shall match our expectations */
6390 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006391 /* Check TDMA frame number period */
6392 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6393 setverdict(fail, "Odd TDMA frame number := ",
6394 sd.data.u.interf_ind.fn);
6395 }
6396 interf_ind_num := interf_ind_num + 1;
6397 if (interf_ind_num < 4)
6398 { repeat; }
6399 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006400 [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 +02006401 setverdict(fail, "Received unexpected interference report: ", sd.data);
6402 }
6403 [] PCU.receive { repeat; }
6404 [] T.timeout {
6405 setverdict(fail, "Timeout waiting for interference reports");
6406 }
6407 }
6408
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006409 /* Reset the averaging/reporting period back to default */
6410 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6411
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6413}
6414
Harald Welte3d04ae62018-04-04 20:29:05 +02006415/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006416 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006417 ***********************************************************************/
6418
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006419private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6420 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006421runs on ConnHdlr {
6422 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006423
6424 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006425 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006426 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6427 repeat;
6428 }
6429 }
6430}
6431
6432private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6433runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006434 /* Expect BTS to immediately acknowledge activation as PDCH */
6435 PCU.clear;
6436 f_rsl_chan_act(g_pars.chan_mode);
6437 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006438 timer T_wait := 2.0;
6439 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006440 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006441 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006442 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006443 [] T_wait.timeout {
6444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6445 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6446 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006447 }
6448 /* try to activate this PDCH from the PCU point of view */
6449 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6450 /* FIXME: is there a response? */
6451}
6452
6453private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6454runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006455 /* Send RSL CHAN REL (deactivate) */
6456 PCU.clear;
6457 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6458 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006459 timer T_wait := 2.0;
6460 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006461 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006462 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006463 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006464 [] T_wait.timeout {
6465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6466 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6467 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006468 }
6469 /* Emulate PCU asking BTS to deactivate PDCH */
6470 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6471 alt {
6472 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6473 setverdict(pass);
6474 }
6475 [] RSL.receive { repeat; }
6476 }
6477}
6478
6479/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006480private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006481 var PCUIF_Message first_info;
6482 var integer ts_nr := g_chan_nr.tn;
6483 var integer trx_nr := 0;
6484 var integer bts_nr := 0;
6485 var integer pcu_conn_id := -1;
6486
6487 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6488
6489 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6490 f_sleep(3.0);
6491 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6492 setverdict(pass);
6493}
6494testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6495 var ConnHdlrPars pars;
6496 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006497 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006498
6499 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6500 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6501 vc_conn.done;
6502}
6503
6504/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006505private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006506 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006507 var integer pcu_conn_id := -1;
6508
6509 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6510
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006511 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6512 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6513 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006514 setverdict(pass);
6515}
6516testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6517 var ConnHdlrPars pars;
6518 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006519 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006520
6521 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6522 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6523 vc_conn.done;
6524}
6525
6526/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006527private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006528 var PCUIF_Message first_info;
6529 var integer ts_nr := g_chan_nr.tn;
6530 var integer trx_nr := 0;
6531 var integer bts_nr := 0;
6532 var integer pcu_conn_id := -1;
6533
6534 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6535
6536 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006537 /* Send a second Chan Activ and expect it to be NACKed */
6538 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6539 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006540 setverdict(pass);
6541}
6542testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6543 var ConnHdlrPars pars;
6544 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006545 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006546
6547 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6548 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6549 vc_conn.done;
6550}
6551
6552/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006553private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006554 var PCUIF_Message first_info;
6555 var integer ts_nr := g_chan_nr.tn;
6556 var integer trx_nr := 0;
6557 var integer bts_nr := 0;
6558 var integer pcu_conn_id := -1;
6559 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6560
6561 /* register for the TCH/F channel number */
6562 f_rslem_register(0, chan_nr);
6563
6564 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6565
6566 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6567 "RSL CHAN ACT");
6568 setverdict(pass);
6569}
6570testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6571 var ConnHdlrPars pars;
6572 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006573 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006574
6575 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6576 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6577 vc_conn.done;
6578}
6579
6580/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006581private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006582 var PCUIF_Message first_info;
6583 var integer ts_nr := g_chan_nr.tn;
6584 var integer trx_nr := 0;
6585 var integer bts_nr := 0;
6586 var integer pcu_conn_id := -1;
6587 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6588 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6589
6590 /* register for the TCH/H channel numbers */
6591 f_rslem_register(0, chan_nr[0]);
6592 f_rslem_register(0, chan_nr[1]);
6593
6594 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6595
6596 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6597 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6598 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6599 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6600 setverdict(pass);
6601}
6602testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6603 var ConnHdlrPars pars;
6604 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006605 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006606
6607 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6608 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6609 vc_conn.done;
6610}
6611
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006612/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6613private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6614 var PCUIF_Message first_info;
6615 var integer ts_nr := g_chan_nr.tn;
6616 var integer trx_nr := 0;
6617 var integer bts_nr := 0;
6618 var integer pcu_conn_id := -1;
6619 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6620 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6621 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6622 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6623 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6624 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6625 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6626 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6627
6628 /* register for the TCH/H channel numbers */
6629 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6630 f_rslem_register(0, chan_nr[i]);
6631 }
6632
6633 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6634
6635 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6636 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6637 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6638 }
6639 setverdict(pass);
6640}
6641testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6642 var ConnHdlrPars pars;
6643 var ConnHdlr vc_conn;
6644 f_init();
6645
6646 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6647 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6648 vc_conn.done;
6649}
6650
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006651/* Reproduce a race condition described in OS#5245 */
6652private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6653 f_rsl_chan_act(g_pars.chan_mode);
6654 f_sleep(1.0);
6655 f_rsl_chan_deact();
6656 setverdict(pass);
6657}
6658testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6659 var ConnHdlrPars pars[2];
6660 var ConnHdlr vc_conn[2];
6661 var TrxcMessage rsp;
6662
6663 f_init();
6664
6665 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6666 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6667 ts_TRXC_FAKE_TRXC_DELAY(200));
6668
6669 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6670 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6671 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6672 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6673 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6674 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6675 pars[i], l1ctl := false);
6676 }
6677
6678 /* Wait for all components to finish */
6679 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6680 vc_conn[i].done;
6681 }
6682
6683 /* Disable the artificial delay for TRXC RSP messages */
6684 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6685 ts_TRXC_FAKE_TRXC_DELAY(0));
6686}
6687testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6688 var ConnHdlrPars pars[8];
6689 var ConnHdlr vc_conn[8];
6690 var TrxcMessage rsp;
6691
6692 f_init();
6693
6694 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6695 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6696 ts_TRXC_FAKE_TRXC_DELAY(200));
6697
6698 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6699 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6700 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6701 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6702 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6703 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6704 pars[i], l1ctl := false);
6705 }
6706
6707 /* Wait for all components to finish */
6708 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6709 vc_conn[i].done;
6710 }
6711
6712 /* Disable the artificial delay for TRXC RSP messages */
6713 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6714 ts_TRXC_FAKE_TRXC_DELAY(0));
6715}
6716
Harald Welte9bbbfb52018-04-05 09:33:19 +02006717/***********************************************************************
6718 * IPA Style Dynamic Timeslot Support
6719 ***********************************************************************/
6720
6721private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6722runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006723 /* Expect BTS to immediately acknowledge activation as PDCH */
6724 PCU.clear;
6725 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6726 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006727 timer T_wait := 2.0;
6728 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006729 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006730 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006731 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006732 [] T_wait.timeout {
6733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6734 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6735 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006736 }
6737 /* try to activate this PDCH from the PCU point of view */
6738 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6739 /* FIXME: is there a response? */
6740
6741 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6742}
6743
6744private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6745runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006746 /* Send RSL CHAN REL (deactivate) */
6747 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6748 PCU.clear;
6749 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006750 timer T_wait := 2.0;
6751 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006752 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006753 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006754 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006755 [] T_wait.timeout {
6756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6757 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6758 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006759 }
6760 /* Emulate PCU asking BTS to deactivate PDCH */
6761 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6762 alt {
6763 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6764 setverdict(pass);
6765 }
6766 [] RSL.receive { repeat; }
6767 }
6768}
6769
6770/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006771private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006772 var PCUIF_Message first_info;
6773 var integer ts_nr := g_chan_nr.tn;
6774 var integer trx_nr := 0;
6775 var integer bts_nr := 0;
6776 var integer pcu_conn_id := -1;
6777
6778 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6779
6780 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6781 f_sleep(3.0);
6782 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6783
6784 setverdict(pass);
6785
6786}
6787testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6788 var ConnHdlrPars pars;
6789 var ConnHdlr vc_conn;
6790 f_init();
6791
6792 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6793 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6794 vc_conn.done;
6795}
6796
6797/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006798private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006799 var PCUIF_Message first_info;
6800 var integer ts_nr := g_chan_nr.tn;
6801 var integer trx_nr := 0;
6802 var integer bts_nr := 0;
6803 var integer pcu_conn_id := -1;
6804
6805 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6806
6807 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6808 "RSL CHAN ACT");
6809 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6810 "RF CHAN REL", true);
6811 setverdict(pass);
6812}
6813testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6814 var ConnHdlrPars pars;
6815 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006816 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006817
6818 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6819 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6820 vc_conn.done;
6821}
6822
6823/* 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 +07006824private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006825 var PCUIF_Message first_info;
6826 var integer ts_nr := g_chan_nr.tn;
6827 var integer trx_nr := 0;
6828 var integer bts_nr := 0;
6829 var integer pcu_conn_id := -1;
6830
6831 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6832
6833 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6834 "RSL CHAN ACT");
6835
6836 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6837 alt {
6838 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6839 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006841 }
6842 [] RSL.receive { repeat; }
6843 }
6844
6845 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6846 "RF CHAN REL", true);
6847 setverdict(pass);
6848}
6849testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6850 var ConnHdlrPars pars;
6851 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006852 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006853
6854 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6855 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6856 vc_conn.done;
6857}
6858
6859/* 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 +07006860private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006861 var PCUIF_Message first_info;
6862 var integer ts_nr := g_chan_nr.tn;
6863 var integer trx_nr := 0;
6864 var integer bts_nr := 0;
6865 var integer pcu_conn_id := -1;
6866
6867 /* register for the TCH/F channel number */
6868 f_rslem_register(0, g_chan_nr);
6869
6870 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6871
6872 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6873
6874 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6875 "RSL CHAN ACT");
6876
6877 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6878
6879 setverdict(pass);
6880}
6881testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6882 var ConnHdlrPars pars;
6883 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006884 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006885
6886 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6887 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6888 vc_conn.done;
6889}
6890
6891
Harald Welte0472ab42018-03-12 15:02:26 +01006892/***********************************************************************
6893 * LAPDm / RLL related
6894 ***********************************************************************/
6895
6896private function f_tx_lapdm(template (value) LapdmFrame l,
6897 template (value) RslLinkId link_id) runs on ConnHdlr {
6898 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006899 var template (value) SacchL1Header l1h;
6900
6901 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006902 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006903 /* Compose dummy L1 header */
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07006904 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006905 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 +02006906 } else {
6907 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006908 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 +01006909 }
Harald Welte0472ab42018-03-12 15:02:26 +01006910}
6911
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006912friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006913 uint3_t sapi,
6914 RslLinkId link_id,
6915 octetstring l3,
6916 boolean exp
6917}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006918friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006919friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6920 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006921 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006922 sapi := sapi,
6923 link_id := id,
6924 l3 := l3,
6925 exp := exp
6926}
6927
6928/* execute the same callback function with a set of different parameters (tcs) on a
6929 * variety of logical channels */
6930private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6931 var ConnHdlrPars pars;
6932 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006933 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006934
6935 /* test on each of the channels we have */
6936 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6937 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6938
6939 /* test each of the test cases on the current channel */
6940 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6941 pars.spec.rll := tcs[j];
6942 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6943 vc_conn := f_start_handler(fn, pars);
6944 vc_conn.done;
6945 }
6946 }
6947
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006949}
6950
6951/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6952private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6953 var RllTestCase tc := g_pars.spec.rll;
6954 timer T := 3.0;
6955
6956 f_l1_tune(L1CTL);
6957 RSL.clear;
6958
6959 /* activate the logical channel */
6960 f_est_dchan();
6961 L1CTL.clear;
6962
6963 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6964 T.start;
6965 alt {
6966 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6967 if (tc.exp) {
6968 setverdict(pass);
6969 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006971 }
6972 }
6973 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6974 if (tc.exp) {
6975 setverdict(pass);
6976 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006978 }
6979 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006980 /* We also expect to receive the measurements */
6981 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006982 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006984 }
6985 [not tc.exp] T.timeout {
6986 setverdict(pass);
6987 }
6988 }
6989
6990 f_rsl_chan_deact();
6991 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6992 f_rslem_unregister(0, g_chan_nr);
6993}
6994testcase TC_rll_est_ind() runs on test_CT {
6995 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006996 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006997 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006998 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006999 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007000 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007001 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
7002 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01007003 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007004 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007005 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007006 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007007 };
7008 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
7009}
7010
7011/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
7012private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
7013 var RllTestCase tc := g_pars.spec.rll;
7014 var L1ctlDlMessage dl;
7015 timer T := 3.0;
7016
7017 f_l1_tune(L1CTL);
7018 RSL.clear;
7019
7020 /* activate the logical channel */
7021 f_est_dchan();
7022 L1CTL.clear;
7023
7024 /* Send a RSL EST REQ for SAPI3 on main DCCH */
7025 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
7026 T.start;
7027 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007028 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007029 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007031 }
7032 }
7033
7034 f_rsl_chan_deact();
7035 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7036 f_rslem_unregister(0, g_chan_nr);
7037}
7038testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7039 var RllTestCases tcs := {
7040 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007041 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007042 };
7043 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7044}
7045testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7046 var RllTestCases tcs := {
7047 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007048 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007049 }
7050 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7051}
7052
7053/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007054friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007055 var L1ctlDlMessage dl;
7056 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7057 var LapdmFrame lapdm;
7058 var octetstring l2 := dl.payload.data_ind.payload;
7059 if (dl.dl_info.link_id.c == SACCH) {
7060 /* remove L1 header */
7061 l2 := substr(l2, 2, lengthof(l2)-2);
7062 }
7063 if (ischosen(exp.ab)) {
7064 lapdm.ab := dec_LapdmFrameAB(l2);
7065 } else if (ischosen(exp.b4)) {
7066 lapdm.b4 := dec_LapdmFrameB4(l2);
7067 } else if (ischosen(exp.bbis)) {
7068 lapdm.bbis := dec_LapdmFrameBbis(l2);
7069 }
7070 log("Rx LAPDm ", lapdm);
7071 if (match(lapdm, exp)) {
7072 setverdict(pass);
7073 } else {
7074 repeat;
7075 }
7076 }
7077 [] L1CTL.receive { repeat; }
7078}
7079private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7080 timer T := t;
7081 T.start;
7082 alt {
7083 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007085 }
7086 [] as_l1_exp_lapdm(exp);
7087 }
7088}
7089
7090/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7091private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007092 timer T := 2.0;
Harald Welte0472ab42018-03-12 15:02:26 +01007093 /* send SABM from MS -> BTS */
7094 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7095 /* expect RLL EST IND on Abis */
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007096 T.start;
Harald Welte0472ab42018-03-12 15:02:26 +01007097 alt {
7098 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7099 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7100 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007102 }
7103 [] RSL.receive { repeat; }
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007104 [] T.timeout {
7105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RLL EST IND");
7106 }
Harald Welte0472ab42018-03-12 15:02:26 +01007107 }
7108 /* expect UA from BTS -> MS */
7109 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7110}
7111
7112/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7113private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7114 var RllTestCase tc := g_pars.spec.rll;
7115
7116 f_l1_tune(L1CTL);
7117 RSL.clear;
7118
7119 /* activate the logical channel */
7120 f_est_dchan();
7121 L1CTL.clear;
7122
7123 /* first establish the link-layer */
7124 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7125
7126 /* then send the DISC */
7127 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7128 /* ... and expect the REL IND on the RSL side */
7129 alt {
7130 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7131 setverdict(pass);
7132 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007133 /* We also expect to receive the measurements */
7134 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007135 }
7136
7137 /* release the channel */
7138 f_rsl_chan_deact();
7139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7140 f_rslem_unregister(0, g_chan_nr);
7141}
7142testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7143 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007144 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007145 };
7146 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7147}
7148
7149testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7150 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007151 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007152 };
7153 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7154}
7155testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7156 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007157 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007158 };
7159 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7160}
7161testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7162 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007163 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007164 };
7165 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7166}
7167
7168/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7169private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7170 var RllTestCase tc := g_pars.spec.rll;
7171 f_l1_tune(L1CTL);
7172 RSL.clear;
7173
7174 /* activate the logical channel */
7175 f_est_dchan();
7176 L1CTL.clear;
7177
7178 /* first establish the link-layer */
7179 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7180
7181 /* then send the REL REQ via RSL */
7182 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7183 /* ... and expect the DISC on the Um side */
7184 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007185 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007186 /* FIXME: send a UA in resposne to the DISC */
7187 }
7188 }
7189
7190 /* release the channel */
7191 f_rsl_chan_deact();
7192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7193 f_rslem_unregister(0, g_chan_nr);
7194}
7195testcase TC_rll_rel_req() runs on test_CT {
7196 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007197 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7198 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7199 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7200 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007201 };
7202 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7203}
7204
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007205/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007206testcase TC_rll_data_req() runs on test_CT {
7207}
7208
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007209/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007210testcase TC_rll_data_ind() runs on test_CT {
7211}
7212
7213/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7214private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7215 var RllTestCase tc := g_pars.spec.rll;
7216
7217 f_l1_tune(L1CTL);
7218 RSL.clear;
7219
7220 f_est_dchan();
7221 L1CTL.clear;
7222
7223 /* Send UNITDATA REQ on RSL side */
7224 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7225 /* Expect it to arrive on the other side */
7226 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007227 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007228 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007229 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007230 }
7231
7232 /* release the channel */
7233 f_rsl_chan_deact();
7234 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7235 f_rslem_unregister(0, g_chan_nr);
7236}
7237testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7238 var octetstring l3 := f_rnd_octstring(15);
7239 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007240 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7241 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007242 };
7243 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7244}
7245testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7246 var octetstring l3 := f_rnd_octstring(19);
7247 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007248 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7249 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007250 };
7251 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7252}
7253
7254/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7255private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7256 var RllTestCase tc := g_pars.spec.rll;
7257
7258 f_l1_tune(L1CTL);
7259 RSL.clear;
7260
7261 f_est_dchan();
7262 L1CTL.clear;
7263
7264 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007265 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007266 /* Expdct RLL UNITDATA IND on RSL side */
7267 alt {
7268 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7269 setverdict(pass);
7270 }
7271 [] RSL.receive { repeat; }
7272 }
7273
7274 /* release the channel */
7275 f_rsl_chan_deact();
7276 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7277 f_rslem_unregister(0, g_chan_nr);
7278}
7279testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007280 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007281 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007282 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7283 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007284 };
7285 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7286}
7287testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7288 var octetstring l3 := f_rnd_octstring(18);
7289 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007290 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7291 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007292 };
7293 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7294}
7295
Harald Weltee613f962018-04-18 22:38:16 +02007296/***********************************************************************
7297 * Encryption Related
7298 ***********************************************************************/
7299
7300/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007301private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007302 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7303 if (link_id.c == SACCH) {
7304 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7305 } else {
7306 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7307 }
7308}
7309
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007310/* Expect (or not expect) other kinds of messages */
7311private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7312 [exp_any] RSL.receive { repeat; }
7313 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007315 }
7316}
7317
Harald Weltee613f962018-04-18 22:38:16 +02007318/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007319private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007320 RslLinkId link_id,
7321 octetstring l3,
7322 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007323 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007324) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007325 timer T := 3.0;
7326 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7327 T.start;
7328 /* Expect RLL UNITDATA IND on RSL side */
7329 alt {
7330 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7331 setverdict(pass);
7332 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007333 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007334 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007335 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007337 }
Harald Weltee613f962018-04-18 22:38:16 +02007338 }
7339}
7340
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007341/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7342private function f_data_mo(
7343 RslLinkId link_id,
7344 boolean p, uint3_t nr, uint3_t ns,
7345 octetstring l3,
7346 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007347 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007348) runs on ConnHdlr {
7349 timer T := 3.0;
7350 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7351 T.start;
7352 /* Expect RLL DATA IND on RSL side */
7353 alt {
7354 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7355 setverdict(pass);
7356 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007357 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007358 [] as_rsl_any_ind(exp_any);
7359 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007361 }
7362 }
7363}
7364
Harald Weltee613f962018-04-18 22:38:16 +02007365/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007366private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007367 f_l1_tune(L1CTL);
7368 f_est_dchan(true);
7369
7370 /* now we actually need to transmit some data both ways to check if the encryption works */
7371 var L1ctlDlMessage dl;
7372
Stefan Sperling603d98e2018-07-25 16:47:28 +02007373 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007374 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7375
7376 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7377 f_unitdata_mt(link_id, l3);
7378
7379 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7380 f_unitdata_mo(link_id, l3);
7381
7382 /* release the channel */
7383 f_rsl_chan_deact();
7384 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7385 f_rslem_unregister(0, g_chan_nr);
7386}
7387testcase TC_chan_act_a51() runs on test_CT {
7388 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7389 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7390 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7391}
7392testcase TC_chan_act_a52() runs on test_CT {
7393 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7394 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7395 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7396}
7397testcase TC_chan_act_a53() 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_3, f_rnd_octstring(8)));
7400 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7401}
Eric Wildb9260392021-05-15 19:48:22 +02007402testcase TC_chan_act_a54() 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_4, f_rnd_octstring(16)));
7405 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7406}
Harald Weltee613f962018-04-18 22:38:16 +02007407
Eric Wildf1827a72019-05-28 17:37:35 +02007408/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7409 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 +07007410private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007411 f_l1_tune(L1CTL);
7412 f_est_dchan(true);
7413
7414 /* now we actually need to transmit some data both ways to check if the encryption works */
7415 var L1ctlDlMessage dl;
7416
7417 var octetstring l3 := f_rnd_octstring(20);
7418 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7419
7420 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7421 f_unitdata_mt(link_id, l3);
7422
7423 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7424 f_unitdata_mo(link_id, l3);
7425
7426 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007427 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007428
7429 /* modify key to break proper encryption */
7430 g_pars.encr.key := f_rnd_octstring(8);
7431 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7432 rsl.ies := rsl.ies & { ei };
7433 RSL.send(rsl);
7434
7435 timer T0 := 1.0;
7436 T0.start;
7437 /* Expect RSL MODIFY ACK */
7438 alt {
7439 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7440 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7442 }
7443 [] T0.timeout {
7444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7445 }
7446 }
7447
7448 var octetstring l3msg := f_rnd_octstring(15);
7449 timer T1 := 3.0;
7450 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7451 due to broken encryption */
7452 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7453 T1.start;
7454 alt {
7455 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7457 }
7458 [] T1.timeout {
7459 setverdict(pass);
7460 }
7461 }
7462
7463 /* release the channel */
7464 f_rsl_chan_deact();
7465 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7466 f_rslem_unregister(0, g_chan_nr);
7467}
7468testcase TC_rsl_modify_encr() runs on test_CT {
7469 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7470 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7471 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7472}
Harald Weltee613f962018-04-18 22:38:16 +02007473
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007474/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007475private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007476runs on test_CT {
7477 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7478 var ASP_RSL_Unitdata ud;
7479 timer T;
7480
7481 /* Intave is 6 SACCH periods by default */
7482 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7483
7484 T.start(Tval);
7485 alt {
7486 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7487 setverdict(pass);
7488 }
7489 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7490 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7491 }
7492 [] RSL_CCHAN.receive { repeat; }
7493 [] T.timeout {
7494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7495 "Timeout waiting for RF RESource INDication");
7496 }
7497 }
7498}
7499testcase TC_rsl_rf_resource_ind() runs on test_CT {
7500 var RSL_ResourceInfo info := { };
7501
7502 f_init(trx_nr := 0);
7503
7504 f_init_l1ctl();
7505 f_l1_tune(L1CTL);
7506
7507 /* g_AllChannels contains all logical channels */
7508 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7509 var RslChannelNr chan_nr := g_AllChannels[i];
7510
7511 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7512 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7513 { continue; }
7514
7515 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7516 }
7517
7518 /* Align to the first interference report */
7519 f_TC_rsl_rf_resource_ind(?);
7520
7521 /* Test 4 consecutive messages */
7522 for (var integer i := 0; i < 4; i := i + 1) {
7523 f_TC_rsl_rf_resource_ind(info);
7524 }
7525
7526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7527}
7528
Harald Weltee613f962018-04-18 22:38:16 +02007529/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007530private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007531 /* L3 payload doesn't matter, as it is passed transparently */
7532 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7533 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7534 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7535
7536 f_l1_tune(L1CTL);
7537
7538 /* first establish a dedicated channel in the clear */
7539 f_est_dchan(false);
7540
7541 /* Establish ABM */
7542 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7543
7544 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7545 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7546 /* expect the L3 to arrive still unencrypted on the MS side */
7547 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7548
7549 /* configure L1 to apply ciphering */
7550 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7551 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7552
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007553 /* send first ciphered I-frame in response and expect it on RSL */
7554 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007555
7556 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7557 * and hence enable encryption also on the downlink */
7558
7559 /* expect bi-directional communication work in encrypted mode */
7560 f_unitdata_mo(link_id, f_rnd_octstring(15));
7561 f_unitdata_mt(link_id, f_rnd_octstring(15));
7562
7563 /* release the channel */
7564 f_rsl_chan_deact();
7565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7566 f_rslem_unregister(0, g_chan_nr);
7567}
7568testcase TC_encr_cmd_a51() runs on test_CT {
7569 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7570 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7571 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7572}
7573testcase TC_encr_cmd_a52() runs on test_CT {
7574 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7575 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7576 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7577}
7578testcase TC_encr_cmd_a53() 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_3, f_rnd_octstring(8)));
7581 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7582}
Eric Wildb9260392021-05-15 19:48:22 +02007583testcase TC_encr_cmd_a54() 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_4, f_rnd_octstring(16)));
7586 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7587}
Harald Weltee613f962018-04-18 22:38:16 +02007588
7589private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7590 var LapdmFrame lf;
7591 var octetstring reenc;
7592
7593 /* decode the LAPDm frame */
7594 if (ischosen(exp_match.ab)) {
7595 lf.ab := dec_LapdmFrameAB(enc);
7596 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007598 }
7599
7600 /* check if decoder result matches expectation */
7601 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007603 } else {
7604 log(name, ": matched");
7605 setverdict(pass);
7606 }
7607
7608 /* test if re-encoded frame equals original input */
7609 reenc := enc_LapdmFrame(lf);
7610 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007612 } else {
7613 setverdict(pass);
7614 }
7615}
7616
7617testcase TC_lapdm_selftest() runs on test_CT {
7618 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7619 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7620 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7621 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7622 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7623 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7624 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7625}
7626
Stefan Sperling4880be42018-08-07 18:12:59 +02007627/***********************************************************************
7628 * DTX Related (see GSM 05.08, section 8.3)
7629 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007630private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007631 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007632 var GsmFrameNumber first_fn;
7633 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007634 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007635 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007636 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7637 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007638 const integer frame_dtx_tchf_mod := 104;
7639 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7640 * which operates in terms of blocks rather than frames. */
7641 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7642 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007643 timer T := 5.0;
7644
7645 f_l1_tune(L1CTL);
7646 RSL.clear;
7647 L1CTL.clear;
7648
7649 /* activate TCHF signalling channel */
7650 f_est_dchan(false);
7651
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007652 /* A template for matching dummy LAPDm func=UA frames */
7653 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7654 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7655 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7656
Stefan Sperling4880be42018-08-07 18:12:59 +02007657 T.start;
7658 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007659 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007660 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007661
7662 if (is_first_frame) {
7663 is_first_frame := false;
7664 first_fn := dl.dl_info.frame_nr;
7665 }
7666
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007667 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007668 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007669 T.stop;
7670 f_rsl_chan_deact();
7671 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007672
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007673 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7674 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007675
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007676 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007677 setverdict(fail, "Not enough fill frames received: ",
7678 nfill_frames, " out of ", expected_fill_frames);
7679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007680 } else {
7681 setverdict(pass);
7682 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007683 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007684 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7685 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7686 * we should only see the subset of frames numbers which correspond to a block boundary.
7687 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7688 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7689 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007690 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007691 repeat;
7692 }
7693 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007694 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7695 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7696 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007697 f_rsl_chan_deact();
7698 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007699 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007700 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007701 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007702 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007703 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007704
7705 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007706 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7707 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007708 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7709 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7710 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007711 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7712 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007713 case else {
7714 /* This shall not happen, just to be sure */
7715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7716 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007717 }
7718
7719 f_rsl_chan_deact();
7720 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007721
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007722 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007723 setverdict(pass);
7724 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007725 setverdict(fail, "Not enough fill frames received: ",
7726 nfill_frames, " out of ", expected_fill_frames);
7727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007728 }
7729 } else {
7730 repeat;
7731 }
7732 }
7733 }
7734 [] L1CTL.receive { repeat; }
7735 [] T.timeout {
7736 f_rsl_chan_deact();
7737 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007739 }
7740 }
7741}
7742
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007743private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007744 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007745 var ConnHdlr vc_conn;
7746 var ConnHdlrPars pars;
7747 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007748 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007749 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007750 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007751 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007752 if (dtxd) {
7753 if (i >= 4) { /* DTX is only allowed on TCH/F */
7754 break;
7755 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007756 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007757 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007758 vc_conn.done;
7759 }
7760}
7761
7762/* Verify that L2 fill frames are sent on TCH in signaling mode if
7763 * there is nothing to transmit while DTX is disabled on downlink. */
7764testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7765 f_tch_sign_l2_fill_frame(false);
7766}
7767
7768/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7769 * there is nothing to transmit while DTX is enabled on downlink. */
7770testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7771 f_tch_sign_l2_fill_frame(true);
7772}
Harald Welte0472ab42018-03-12 15:02:26 +01007773
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007774testcase TC_chopped_ipa_ping() runs on test_CT {
7775 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7776}
7777
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007778testcase TC_chopped_ipa_payload() runs on test_CT {
7779 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7780}
7781
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007782
7783/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7784 * Return value: Measurement Report to be sent (encoded octetstring). */
7785type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7786 runs on ConnHdlr return octetstring;
7787
7788private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7789runs on ConnHdlr {
7790 var L1ctlDlMessage l1_dl;
7791 var SacchL1Header l1h;
7792 var octetstring l2;
7793
7794 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7795 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7796 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7797 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7798
7799 /* Pass it to the user specified call-back function */
7800 l2 := cb.apply(l1h, num_blocks);
7801 /* Send a Measurement Report generated by the call-back */
7802 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7803 l1_dl.dl_info.link_id,
7804 l1h, l2));
7805
7806 /* Shall we keep going? */
7807 num_blocks := num_blocks - 1;
7808 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7809 if (num_blocks > 0) { repeat; }
7810 }
7811 [] L1CTL.receive { repeat; }
7812}
7813
7814private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7815runs on ConnHdlr return octetstring {
7816 /* Command the L1 to apply received parameters */
7817 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7818
7819 /* Dummy measurement report (the results are invalid) */
7820 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7821}
7822
7823private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7824runs on ConnHdlr return octetstring {
7825 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7826 setverdict(fail, "Unexpected MS Power level change: ",
7827 g_pars.l1_pars.ms_power_level, " -> ",
7828 l1h.ms_power_lvl);
7829 }
7830
7831 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7832}
7833
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007834private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7835runs on ConnHdlr return octetstring {
7836 /* UL RSSI oscillation driven by SACCH block number */
7837 if (num_blocks rem 2 == 0) {
7838 f_trxc_fake_rssi(-100);
7839 } else {
7840 f_trxc_fake_rssi(-50);
7841 }
7842
7843 /* Make sure that MS power level remains constant */
7844 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7845}
7846
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007847/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7848private function f_TC_ms_pwr_ctrl_constant(charstring id)
7849runs on ConnHdlr {
7850 var integer num_blocks := 8;
7851 timer T := int2float(num_blocks);
7852
7853 f_l1_tune(L1CTL);
7854 RSL.clear;
7855
7856 /* These IEs are needed for autonomous MS power control */
7857 var template (value) RSL_IE_List ies := {
7858 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7859 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7860 }),
7861 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7862 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7863 })
7864 };
7865
7866 /* Ensure that 'rx-current' equals 'rx-target' */
7867 f_trxc_fake_rssi(mp_uplink_power_target);
7868
7869 /* Establish a dedicated channel */
7870 f_est_dchan(more_ies := valueof(ies));
7871
7872 L1CTL.clear;
7873 T.start;
7874 alt {
7875 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7876 [] T.timeout {
7877 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7878 num_blocks, " were not handled");
7879 }
7880 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007881
7882 /* Release the channel */
7883 f_rsl_chan_deact();
7884 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007885}
7886testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7887 var ConnHdlr vc_conn;
7888 var ConnHdlrPars pars;
7889
7890 f_init();
7891
7892 /* Explicitly configure the Uplink power target (in dBm) */
7893 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7894
7895 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7896 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7897 log(testcasename(), ": starting on ", pars.chan_nr);
7898
7899 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7900 pars, trxc_comp := true);
7901 vc_conn.done;
7902 }
7903
7904 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7906}
7907
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007908/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7909private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7910runs on ConnHdlr {
7911 var integer num_blocks := 16;
7912 timer T := int2float(num_blocks);
7913
7914 f_l1_tune(L1CTL);
7915 RSL.clear;
7916
7917 /* These IEs are needed for autonomous MS power control */
7918 var template (value) RSL_IE_List ies := {
7919 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7920 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7921 }),
7922 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7923 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7924 })
7925 };
7926
7927 /* Ensure that 'rx-current' equals 'rx-target' */
7928 f_trxc_fake_rssi(mp_uplink_power_target);
7929
7930 /* Establish a dedicated channel */
7931 f_est_dchan(more_ies := valueof(ies));
7932
7933 L1CTL.clear;
7934 T.start;
7935 alt {
7936 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7937 [] T.timeout {
7938 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7939 num_blocks, " were not handled");
7940 }
7941 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007942
7943 /* Release the channel */
7944 f_rsl_chan_deact();
7945 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007946}
7947testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7948 var ConnHdlr vc_conn;
7949 var ConnHdlrPars pars;
7950
7951 f_init();
7952
7953 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7954 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7955 /* Explicitly configure the Uplink power range (target and delte) */
7956 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7957 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7958
7959 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7960 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7961 log(testcasename(), ": starting on ", pars.chan_nr);
7962
7963 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7964 pars, trxc_comp := true);
7965 vc_conn.done;
7966 }
7967
7968 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7970}
7971
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007972private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7973 var template L1ctlDlMessage tr_bad_frame;
7974 var L1ctlDlMessage l1_dl;
7975 timer T := 8.0;
7976
7977 f_l1_tune(L1CTL);
7978 RSL.clear;
7979
7980 f_est_dchan();
7981
7982 /* There may be a few errors right after the channel activation */
7983 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7984 L1CTL.clear;
7985
7986 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7987 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7988 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7989 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7990 tr_bad_frame.payload := ?;
7991
7992 T.start;
7993 alt {
7994 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7995 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7996 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7997 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7998 }
7999 [] as_l1_sacch();
8000 [] L1CTL.receive { repeat; }
8001 [] T.timeout {
8002 /* We're done, break the loop */
8003 setverdict(pass);
8004 }
8005 }
8006
8007 f_rsl_chan_deact();
8008 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8009}
8010testcase TC_speech_no_rtp_tchf() runs on test_CT {
8011 var ConnHdlr vc_conn;
8012 var ConnHdlrPars pars;
8013
8014 f_init();
8015
8016 /* TS1, TCH/F, V1 (FR codec) */
8017 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8018 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8019 vc_conn.done;
8020}
8021testcase TC_speech_no_rtp_tchh() runs on test_CT {
8022 var ConnHdlr vc_conn;
8023 var ConnHdlrPars pars;
8024
8025 f_init();
8026
8027 /* TS5, TCH/H, V1 (HR codec) */
8028 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8029 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8030 vc_conn.done;
8031}
8032
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008033/* Verify handling of Downlink and Uplink speech frames */
8034private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8035 var L1ctlDlMessage l1_dl;
8036 var PDU_RTP rtp_pdu;
8037 var octetstring pl;
8038 timer Td, Tu;
8039
8040 f_l1_tune(L1CTL);
8041 f_est_dchan();
8042
8043 /* Activate the RTP emulation */
8044 pl := f_rnd_octstring(6);
8045 f_rtpem_activate(pl);
8046
8047 /* Give the scheduler some time to fill up the buffers */
8048 f_sleep(2.0);
8049 L1CTL.clear;
8050 RSL.clear;
8051
8052 /* Make sure that Downlink frames are received at the UE */
8053 Td.start(2.0);
8054 alt {
8055 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8056 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8057 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8058 l1_dl.payload.traffic_ind.data));
8059 setverdict(pass);
8060 }
8061 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8062 setverdict(fail, "Rx unexpected Downlink speech frame ",
8063 "(", l1_dl.payload.traffic_ind.data, ") ",
8064 "expected (", pl, ")");
8065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8066 }
8067 [] as_l1_sacch();
8068 [] L1CTL.receive { repeat; }
8069 [] Td.timeout {
8070 setverdict(fail, "Timeout waiting for Downlink speech frames");
8071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8072 }
8073 }
8074
8075 /* Make sure that Uplink frames are received at the BTS */
8076 RTPEM_DATA.clear;
8077 Tu.start(2.0);
8078 alt {
8079 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8080 if (rtp_pdu.data != pl)
8081 { repeat; }
8082 }
8083 [] RTPEM_DATA.receive { repeat; }
8084 [] Tu.timeout {
8085 setverdict(fail, "Timeout waiting for Uplink speech frames");
8086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8087 }
8088 }
8089
8090 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8091 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8092 f_rsl_chan_deact();
8093 f_rslem_unregister(0, g_chan_nr);
8094}
8095testcase TC_speech_rtp_tchf() runs on test_CT {
8096 var ConnHdlr vc_conn;
8097 var ConnHdlrPars pars;
8098
8099 f_init();
8100
8101 /* TS1, TCH/F, V1 (FR codec) */
8102 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8103 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8104 vc_conn.done;
8105
8106 /* TS1, TCH/F, V2 (EFR codec) */
8107 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8108 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8109 vc_conn.done;
8110
8111 /* TODO: also test V3 (AMR codec) */
8112
8113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8114}
8115testcase TC_speech_rtp_tchh() runs on test_CT {
8116 var ConnHdlr vc_conn;
8117 var ConnHdlrPars pars;
8118
8119 f_init();
8120
8121 /* TS5, TCH/H0, V1 (HR codec) */
8122 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8123 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8124 vc_conn.done;
8125
8126 /* TODO: also test V3 (AMR codec) */
8127
8128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8129}
8130
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008131private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8132 var GsmFrameNumber fn;
8133 var ChannelDescription ch_desc;
8134 var integer ra := 23;
8135
8136 f_l1_tune(L1CTL);
8137 RSL.clear;
8138
8139 /* Send RACH request and wait for ChanReq */
8140 fn := f_rach_req_wait_chan_rqd(ra);
8141
8142 /* The BSC already sends the Immediate Assignment, before the channel is active.
8143 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8144 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8145 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8146 if (g_pars.fhp.enabled) {
8147 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8148 } else {
8149 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8150 }
8151 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8152 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8153
8154 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8155 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8156 var L1ctlDlMessage dl;
8157 var GsmRrMessage rr;
8158
8159 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8160 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8161 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8162 rr_imm_ass.payload.imm_ass.chan_desc := *;
8163
8164 timer T := 1.0;
8165 T.start;
8166 alt {
8167 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8168 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8169 if (match(rr, rr_imm_ass)) {
8170 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8171 mtc.stop;
8172 } else {
8173 repeat;
8174 }
8175 }
8176 [] L1CTL.receive { repeat; }
8177 [] T.timeout;
8178 }
8179 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8180 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8181
8182 /* Now expect the IMM ASS on Um */
8183 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8184 setverdict(pass);
8185
8186 /* Release the channel */
8187 f_rsl_chan_deact();
8188 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8189}
8190
8191testcase TC_early_immediate_assignment() runs on test_CT {
8192 var ConnHdlr vc_conn;
8193 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8194 f_init();
8195 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8196 vc_conn.done;
8197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8198}
8199
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008200private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8201 var integer ra := oct2int(f_rnd_ra_cs());
8202 var ChannelDescription ch_desc;
8203
8204 /* Tune the MS to BCCH */
8205 f_l1_tune(L1CTL);
8206
8207 /* Send RACH request and wait for ChanReq */
8208 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8209
8210 /* Activate channel on the BTS side */
8211 f_rsl_chan_act(g_pars.chan_mode);
8212
8213 /* Craft channel description (with or without frequency hopping parameters) */
8214 if (g_pars.fhp.enabled) {
8215 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8216 } else {
8217 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8218 }
8219
8220 /* Send IMM.ASS via CCHAN */
8221 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8222 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8223
8224 /* Receive IMM.ASS on the MS side */
8225 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8226
8227 /* Match the Channel Description IE in received IMM.ASS */
8228 if (not match(imm_ass.chan_desc, ch_desc)) {
8229 setverdict(fail, "Channel Description IE does not match");
8230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8231 }
8232
8233 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8234 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8235
8236 /* Expect SACCH frames on Downlink */
8237 L1CTL.clear;
8238 f_exp_sacch(true);
8239
8240 /* We're done, deactivate and release */
8241 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8242 f_rsl_chan_deact();
8243}
8244testcase TC_est_dchan() runs on test_CT {
8245 var ConnHdlr vc_conn;
8246 var ConnHdlrPars pars;
8247
8248 f_init();
8249
8250 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8251 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8252 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8253 vc_conn.done;
8254 }
8255
8256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8257}
8258
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008259private type record TopTestCase {
8260 RSL_IE_BS_Power bs_power,
8261 RSL_IE_OSMO_TopAcchCap top_cap,
8262 record of TopTestStep steps
8263};
8264private type record TopTestStep {
8265 MeasurementResults meas_res optional,
8266 GsmRxLev overpower_sacch,
8267 GsmRxLev overpower_facch
8268};
8269
8270private function f_rxlev_match(template (present) RslLinkId link_id,
8271 template (present) GsmRxLev rxlev)
8272runs on ConnHdlr {
8273 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8274 if (not match(dl.dl_info.rx_level, rxlev)) {
8275 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8276 " does not match expected RxLev := ", rxlev);
8277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8278 }
8279}
8280
8281private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8282 var TopTestCase tc := g_pars.spec.top;
8283 var GsmRxLev rxlev_dcch;
8284 var L1ctlDlMessage dl;
8285
8286 /* Wait for Pau ramping to complete */
8287 f_sleep(6.0);
8288
8289 f_l1_tune(L1CTL);
8290 L1CTL.clear;
8291 RSL.clear;
8292
8293 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8294 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8295 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8296
8297 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8298 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8299
8300 /* Additional IEs for the CHANnel ACTIVation message */
8301 var template (value) RSL_IE_List ies := {
8302 /* Employ BS power control in static mode */
8303 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8304 bs_power := tc.bs_power
8305 }),
8306 /* Indicate the given Temporary Overpower capability */
8307 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8308 top_acch_cap := tc.top_cap
8309 })
8310 };
8311
8312 /* Establish a dedicated channel */
8313 f_est_dchan(more_ies := valueof(ies));
8314
8315 /* Give it some time to stabilize */
8316 f_sleep(0.480 * 2.0);
8317 L1CTL.clear;
8318 RSL.clear;
8319
8320 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8321 var TopTestStep step := tc.steps[i];
8322 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8323 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8324
8325 log("Executing step[", i, "] := ", step);
8326
8327 /* Send RR Measurement Report (if present) */
8328 if (ispresent(step.meas_res)) {
8329 f_transceive_meas_rep(step.meas_res);
8330 f_sleep(0.480 * 2.0);
8331 L1CTL.clear;
8332 }
8333
8334 /* Check RxLev on both FACCH and SACCH */
8335 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8336 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8337
8338 setverdict(pass);
8339 }
8340}
8341testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8342 var ConnHdlrPars pars;
8343 var ConnHdlr vc_conn;
8344
8345 f_init();
8346
8347 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008348 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008349 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8350 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8351 steps := {
8352 /* Channel established, no overpower */
8353 { meas_res := omit,
8354 overpower_sacch := 0, overpower_facch := 0 },
8355
8356 /* Worst possible RxQual value, overpower of 4dB */
8357 { meas_res := ts_MeasurementResults(rxq_f := 7),
8358 overpower_sacch := 4, overpower_facch := 4 },
8359 /* Worst possible RxQual value, disabling overpower */
8360 { meas_res := ts_MeasurementResults(rxq_f := 0),
8361 overpower_sacch := 0, overpower_facch := 0 },
8362
8363 /* Lower threshold not reached, no overpower */
8364 { meas_res := ts_MeasurementResults(rxq_f := 1),
8365 overpower_sacch := 0, overpower_facch := 0 },
8366 /* Lower threshold not reached, no overpower */
8367 { meas_res := ts_MeasurementResults(rxq_f := 2),
8368 overpower_sacch := 0, overpower_facch := 0 },
8369 /* Lower threshold reached, overpower of 4dB */
8370 { meas_res := ts_MeasurementResults(rxq_f := 4),
8371 overpower_sacch := 4, overpower_facch := 4 },
8372 /* Upper threshold not reached, keeping overpower */
8373 { meas_res := ts_MeasurementResults(rxq_f := 3),
8374 overpower_sacch := 4, overpower_facch := 4 },
8375 /* Upper threshold reached, disabling overpower */
8376 { meas_res := ts_MeasurementResults(rxq_f := 2),
8377 overpower_sacch := 0, overpower_facch := 0 }
8378 }
8379 };
8380
8381 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8382 spec := { top := top }, trx_nr := 1));
8383 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8384 vc_conn.done;
8385
8386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8387}
8388testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8389 var ConnHdlrPars pars;
8390 var ConnHdlr vc_conn;
8391
8392 f_init();
8393
8394 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008395 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008396 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8397 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8398 steps := {
8399 /* Channel established, no overpower */
8400 { meas_res := omit,
8401 overpower_sacch := 0, overpower_facch := 0 },
8402
8403 /* Invalid measurement results, no overpower */
8404 { meas_res := ts_MeasurementResults(rxq_f := 7,
8405 rxq_s := 7,
8406 valid := false),
8407 overpower_sacch := 0, overpower_facch := 0 },
8408
8409 /* DTXu was in use, no overpower */
8410 { meas_res := ts_MeasurementResults(rxq_f := 7,
8411 rxq_s := 0,
8412 dtx_used := true),
8413 overpower_sacch := 0, overpower_facch := 0 },
8414 /* DTXu was in use, overpower of 4 dB */
8415 { meas_res := ts_MeasurementResults(rxq_f := 0,
8416 rxq_s := 7,
8417 dtx_used := true),
8418 overpower_sacch := 4, overpower_facch := 4 }
8419 }
8420 };
8421
8422 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8423 spec := { top := top }, trx_nr := 1));
8424 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8425 vc_conn.done;
8426
8427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8428}
8429testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8430 var ConnHdlrPars pars;
8431 var ConnHdlr vc_conn;
8432
8433 f_init();
8434
8435 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008436 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008437 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8438 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8439 rxqual := 0, /* always on */
8440 sacch_enable := false),
8441 steps := {
8442 /* Channel established, FACCH overpower */
8443 { meas_res := omit,
8444 overpower_sacch := 0, overpower_facch := 4 },
8445 /* MS indicates good RxQual, no difference */
8446 { meas_res := ts_MeasurementResults(rxq_f := 0),
8447 overpower_sacch := 0, overpower_facch := 4 },
8448 /* MS indicates bad RxQual, no difference */
8449 { meas_res := ts_MeasurementResults(rxq_f := 7),
8450 overpower_sacch := 0, overpower_facch := 4 }
8451 }
8452 };
8453
8454 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8455 spec := { top := top }, trx_nr := 1));
8456 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8457 vc_conn.done;
8458
8459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8460}
8461testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8462 var ConnHdlrPars pars;
8463 var ConnHdlr vc_conn;
8464
8465 f_init();
8466
8467 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008468 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008469 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8470 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8471 rxqual := 0, /* always on */
8472 facch_enable := false),
8473 steps := {
8474 /* Channel established, SACCH overpower */
8475 { meas_res := omit,
8476 overpower_sacch := 4, overpower_facch := 0 },
8477 /* MS indicates good RxQual, no difference */
8478 { meas_res := ts_MeasurementResults(rxq_f := 0),
8479 overpower_sacch := 4, overpower_facch := 0 },
8480 /* MS indicates bad RxQual, no difference */
8481 { meas_res := ts_MeasurementResults(rxq_f := 7),
8482 overpower_sacch := 4, overpower_facch := 0 }
8483 }
8484 };
8485
8486 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8487 spec := { top := top }, trx_nr := 1));
8488 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8489 vc_conn.done;
8490
8491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8492}
8493testcase TC_acch_overpower_limit() runs on test_CT {
8494 var ConnHdlrPars pars;
8495 var ConnHdlr vc_conn;
8496
8497 f_init();
8498
8499 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008500 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008501 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8502 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8503 rxqual := 0 /* always on */),
8504 steps := {
8505 /* Channel established, ACCH overpower of 2dB */
8506 { meas_res := omit,
8507 overpower_sacch := 2, overpower_facch := 2 },
8508 /* MS indicates good RxQual, no difference */
8509 { meas_res := ts_MeasurementResults(rxq_f := 0),
8510 overpower_sacch := 2, overpower_facch := 2 },
8511 /* MS indicates bad RxQual, no difference */
8512 { meas_res := ts_MeasurementResults(rxq_f := 7),
8513 overpower_sacch := 2, overpower_facch := 2 }
8514 }
8515 };
8516
8517 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8518 spec := { top := top }, trx_nr := 1));
8519 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8520 vc_conn.done;
8521
8522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8523}
8524
Harald Welte0472ab42018-03-12 15:02:26 +01008525/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8526/* protocol error as per 44.006 */
8527/* link layer failure (repetition of I-frame N200 times without ACK */
8528/* repetition of SABM or DISC N200 times without ACK */
8529/* receptiom of SABM in multi-frame established state */
8530
8531
Harald Welte68e495b2018-02-25 00:05:57 +01008532/* TODO Areas:
8533
8534* channel activation
8535** with BS_Power / MS_Power, bypassing power control loop
8536** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008537** with timing advance from initial activation on
8538* mode modify
8539** encryption
8540** multirate
8541* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008542** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008543* BS Power Control
8544* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008545* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008546** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008547* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008548** DATA_IND from BTS->PCU
8549** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008550
8551*/
Harald Welte70767382018-02-21 12:16:40 +01008552
8553control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008554 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008555 execute( TC_chan_act_stress() );
8556 execute( TC_chan_act_react() );
8557 execute( TC_chan_deact_not_active() );
8558 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008559 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008560 execute( TC_sacch_filling() );
8561 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008562 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008563 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008564 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008565 execute( TC_sacch_chan_act_ho_async() );
8566 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008567 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008568 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008569 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008570 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008571 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008572 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008573 execute( TC_rach_load_idle_thresh0() );
8574 execute( TC_rach_load_idle_below_thresh() );
8575 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008576 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008577 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008578 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008579 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008580 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008581 execute( TC_meas_res_sign_tchf() );
8582 execute( TC_meas_res_sign_tchh() );
8583 execute( TC_meas_res_sign_sdcch4() );
8584 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008585 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008586 execute( TC_meas_res_speech_tchf_sapi3() );
8587 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008588 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008589 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008590 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008591 execute( TC_rsl_bs_pwr_static_ass() );
8592 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008593 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008594 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008595 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008596 execute( TC_rsl_ms_pwr_dyn_up() );
8597 execute( TC_rsl_ms_pwr_dyn_down() );
8598 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8599 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008600 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008601 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008602 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008603 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008604 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008605 execute( TC_paging_imsi_80percent() );
8606 execute( TC_paging_tmsi_80percent() );
8607 execute( TC_paging_imsi_200percent() );
8608 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008609 execute( TC_rsl_protocol_error() );
8610 execute( TC_rsl_mand_ie_error() );
8611 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008612 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008613 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008614 execute( TC_si_sched_2bis() );
8615 execute( TC_si_sched_2ter() );
8616 execute( TC_si_sched_2ter_2bis() );
8617 execute( TC_si_sched_2quater() );
8618 execute( TC_si_sched_13() );
8619 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008620 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008621 execute( TC_ipa_crcx_twice_not_active() );
8622 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008623 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008624 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008625 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008626
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008627 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008628 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008629 execute( TC_pcu_act_req() );
8630 execute( TC_pcu_act_req_wrong_ts() );
8631 execute( TC_pcu_act_req_wrong_bts() );
8632 execute( TC_pcu_act_req_wrong_trx() );
8633 execute( TC_pcu_deact_req() );
8634 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008635 execute( TC_pcu_ver_si1() );
8636 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008637 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008638 if (mp_l1_supports_gprs) {
8639 execute( TC_pcu_data_req_pdtch() );
8640 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008641 execute( TC_pcu_data_req_wrong_bts() );
8642 execute( TC_pcu_data_req_wrong_trx() );
8643 execute( TC_pcu_data_req_wrong_ts() );
8644 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008645 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008646 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008647 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008648 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008649 execute( TC_pcu_data_req_imm_ass_pch() );
8650 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008651 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008652 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008653 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008654 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008655 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008656 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008657 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008658 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008659 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008660 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008661 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008662 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008663 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008664 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008665 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008666 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008667 execute( TC_dyn_osmo_pdch_act_deact() );
8668 execute( TC_dyn_osmo_pdch_double_act() );
8669 execute( TC_dyn_ipa_pdch_act_deact() );
8670 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008671 execute( TC_pcu_info_ind_fh_params() );
8672 execute( TC_pcu_socket_nsvc_ipv4() );
8673 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008674 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008675 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008676 } else {
8677 log("PCU socket path not available, skipping PCU tests");
8678 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008679
Harald Welte3d04ae62018-04-04 20:29:05 +02008680 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008681 execute( TC_dyn_osmo_pdch_tchf_act() );
8682 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008683 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008684 execute( TC_dyn_ipa_pdch_tchf_act() );
8685 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008686
8687 execute( TC_rll_est_ind() );
8688 execute( TC_rll_est_req_DCCH_3() );
8689 execute( TC_rll_est_req_ACCH_3() );
8690 execute( TC_rll_rel_ind_DCCH_0() );
8691 execute( TC_rll_rel_ind_DCCH_3() );
8692 execute( TC_rll_rel_ind_ACCH_0() );
8693 execute( TC_rll_rel_ind_ACCH_3() );
8694 execute( TC_rll_rel_req() );
8695 execute( TC_rll_unit_data_req_DCCH() );
8696 execute( TC_rll_unit_data_req_ACCH() );
8697 execute( TC_rll_unit_data_ind_DCCH() );
8698 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008699
8700 execute( TC_chan_act_a51() );
8701 execute( TC_chan_act_a52() );
8702 execute( TC_chan_act_a53() );
8703 execute( TC_encr_cmd_a51() );
8704 execute( TC_encr_cmd_a52() );
8705 execute( TC_encr_cmd_a53() );
8706
Harald Welteee25aae2019-05-19 14:32:37 +02008707 execute( TC_err_rep_wrong_mdisc() );
8708 execute( TC_err_rep_wrong_msg_type() );
8709 execute( TC_err_rep_wrong_sequence() );
8710
Harald Weltee613f962018-04-18 22:38:16 +02008711 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008712
8713 execute( TC_tch_sign_l2_fill_frame() );
8714 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008715
8716 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008717 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008718
8719 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008720 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008721
8722 execute( TC_speech_no_rtp_tchf() );
8723 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008724 execute( TC_speech_rtp_tchf() );
8725 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008726
8727 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008728
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008729 execute( TC_acch_overpower_rxqual_thresh() );
8730 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8731 execute( TC_acch_overpower_always_on_facch() );
8732 execute( TC_acch_overpower_always_on_sacch() );
8733 execute( TC_acch_overpower_limit() );
8734
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008735 /* BEWARE: these test cases can potentially break the IUT or cause
8736 * weird/unexpected behavior. Ensure that they are executed last. */
8737 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8738 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008739}
8740
8741
8742}