blob: a322fde1568ba65303fa705019330d3ecb14658d [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 Yanitskiyf9e31d22021-11-06 18:43:28 +0300781/* Send the given measurement results to the IUT over the Um interface,
782 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
783friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
784runs on ConnHdlr {
785 var template (value) SacchL1Header l1h;
786 var octetstring l2, l3;
787 timer T;
788
789 /* RR Measurement Report to be sent */
790 var GsmRrL3Message meas_rep := {
791 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
792 payload := { meas_rep := { meas_res := valueof(meas_res) } }
793 };
794
795 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
796 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
797 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +0700798 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300799
800 /* Send RR Measurement Report over the Um interface */
801 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
802
803 /* Expect MEASurement RESult on the A-bis/RSL interface */
804 T.start(2.0);
805 alt {
806 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
807 setverdict(pass);
808 }
809 [] RSL.receive { repeat; }
810 [] T.timeout {
811 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
813 }
814 }
815}
816
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700817friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
818 boolean encr_enable := false,
819 RSL_IE_List more_ies := {},
820 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
821runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200822 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200823 if (encr_enable) {
824 /* append encryption related IEs, if requested */
825 var RSL_IE_EncryptionInfo encr_info;
826 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
827 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
828encr_info})) };
829 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200830 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200831 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100832}
833
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700834friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100835 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 +0100836 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100837}
838
Harald Welte2f2b2b72019-05-31 22:24:57 +0200839friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200840 template RSL_IE_ChannelMode chan_mode,
841 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700842 uint8_t trx_nr := 0, float t_guard := 20.0) := {
843 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100844 chan_nr := valueof(chan_nr),
845 chan_mode := valueof(chan_mode),
846 t_guard := t_guard,
847 l1_pars := {
848 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100849 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100850 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100851 meas_ul := {
852 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200853 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100854 rxqual := 0
855 },
856 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200857 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100858 rxqual := 0
859 }
860 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200861 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100862 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200863 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200864 ms_actual_ta := mp_ms_actual_ta_exp,
865 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100866 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200867 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200868 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700869 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700870 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700871 fhp := {
872 enabled := false,
873 maio_hsn := ts_HsnMaio(0, 0),
874 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700875 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700876 }
Harald Welte70767382018-02-21 12:16:40 +0100877}
878
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300879/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
880 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
881private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
882 template (present) octetstring tr_data := ?,
883 template (present) RslChannelNr chan_nr := ?,
884 template (present) RslLinkId link_id := ?)
885runs on ConnHdlr {
886 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
887}
888
889/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
890 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
891private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
892 template (present) RslLinkId link_id := ?,
893 template (present) LapdmSapi sapi := ?,
894 boolean do_repeat := true)
895runs on ConnHdlr {
896 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
897 var L1ctlDlMessage dl_msg;
898
899 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
900 if (do_repeat) {
901 repeat;
902 }
903 }
904}
905
906/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
907 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
908private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
909 template (present) LapdmFrameAB tr_frame := ?,
910 template (present) RslLinkId link_id := ?)
911runs on ConnHdlr {
912 var L1ctlDlMessage dl_msg;
913
914 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
915 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
916 }
917}
918
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300919/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
920 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
921private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
922 template (present) LapdmFrameAB tr_frame := ?,
923 template (present) SacchL1Header tr_l1h := ?,
924 template (present) GsmSapi sapi := ?)
925runs on ConnHdlr {
926 var L1ctlDlMessage dl_msg;
927 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
928 template (present) L1ctlDataReq tr_data := {
929 l1header := tr_l1h,
930 l2_payload := decmatch tr_frame
931 };
932
933 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
934 var octetstring data := dl_msg.payload.data_ind.payload;
935 l1h := dec_SacchL1Header(substr(data, 0, 2));
936 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
937 }
938}
939
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300940/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
941 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
942 * payload is treated as PDU_ML3_NW_MS. */
943private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
944 template (present) PDU_ML3_NW_MS tr_pdu := ?,
945 template (present) GsmSapi sapi := 0)
946runs on ConnHdlr {
947 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
948 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
949 var LapdmFrameAB lapdm_frame;
950
951 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
952 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
953 }
954}
955
Harald Welte93640c62018-02-25 16:59:33 +0100956/***********************************************************************
957 * Channel Activation / Deactivation
958 ***********************************************************************/
959
Harald Welte70767382018-02-21 12:16:40 +0100960/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700961private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100962 for (var integer i := 0; i < 500; i := i+1) {
963 f_rsl_chan_act(g_pars.chan_mode);
964 f_rsl_chan_deact();
965 }
966 setverdict(pass);
967}
968testcase TC_chan_act_stress() runs on test_CT {
969 var ConnHdlr vc_conn;
970 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200971 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100972 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
973 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100975}
976
977/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700978private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100979 f_rsl_chan_act(g_pars.chan_mode);
980 /* attempt to activate the same lchan again -> expect reject */
981 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
982 alt {
983 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100985 }
986 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
987 setverdict(pass);
988 }
989 }
990 f_rsl_chan_deact();
991}
992testcase TC_chan_act_react() runs on test_CT {
993 var ConnHdlr vc_conn;
994 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100995 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100996 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
997 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100999}
1000
1001/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001002private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001003 timer T := 3.0;
1004 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1005 T.start;
1006 alt {
1007 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1008 setverdict(pass);
1009 }
1010 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001012 }
1013 }
1014}
1015testcase TC_chan_deact_not_active() runs on test_CT {
1016 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001017 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001018 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1019 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001021}
1022
1023/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001024private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001025 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1026 alt {
1027 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001029 }
1030 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1031 setverdict(pass);
1032 }
1033 }
1034}
1035private type record WrongChanNrCase {
1036 RslChannelNr chan_nr,
1037 charstring description
1038}
1039private type record of WrongChanNrCase WrongChanNrCases;
1040private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1041 chan_nr := chan_nr,
1042 description := desc
1043}
1044
1045testcase TC_chan_act_wrong_nr() runs on test_CT {
1046 var ConnHdlr vc_conn;
1047 var ConnHdlrPars pars;
1048
Harald Welte294b0a22018-03-10 23:26:48 +01001049 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001050
1051 var WrongChanNrCases wrong := {
1052 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1053 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1054 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1055 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1056 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1057 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1058 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1059 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1060 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1061 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1062 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1063 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1064 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1065 };
1066
1067 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1068 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1069 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1070 vc_conn.done;
1071 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001073}
1074
Harald Weltee613f962018-04-18 22:38:16 +02001075/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001076friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001077 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001078 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001079
1080 /* test on each of the channels we have */
1081 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1082 pars.chan_nr := valueof(g_AllChanTypes[i]);
1083
1084 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1085 vc_conn := f_start_handler(fn, pars);
1086 vc_conn.done;
1087 }
1088
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001090}
1091
Harald Welte93640c62018-02-25 16:59:33 +01001092/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001093 * SACCH handling
1094 ***********************************************************************/
1095
1096private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1097 timer T_sacch := 3.0;
1098 T_sacch.start;
1099 alt {
1100 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001102 }
1103 [not exp] T_sacch.timeout {
1104 setverdict(pass);
1105 }
1106 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1107 setverdict(pass);
1108 }
1109 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001111 }
1112 [] L1CTL.receive { repeat; }
1113 [] RSL.receive { repeat; }
1114 }
1115}
1116
1117/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1118private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1119 f_l1_tune(L1CTL);
1120 RSL.clear;
1121
1122 /* activate the logical channel */
1123 f_est_dchan();
1124 L1CTL.clear;
1125
1126 /* check that SACCH actually are received as expected */
1127 f_exp_sacch(true);
1128
1129 /* deactivate SACCH on the logical channel */
1130 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1131 f_sleep(1.0);
1132 L1CTL.clear;
1133
1134 /* check that no SACCH are received anymore */
1135 f_exp_sacch(false);
1136
1137 /* release the channel */
1138 f_rsl_chan_deact();
1139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1140}
1141testcase TC_deact_sacch() runs on test_CT {
1142 var ConnHdlr vc_conn;
1143 var ConnHdlrPars pars;
1144 f_init();
1145 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1146 //for (var integer i := 0; i < 1; i := i+1) {
1147 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1148 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1149 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1150 vc_conn.done;
1151 }
1152 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001154}
1155
Harald Welte55700662018-03-12 13:15:43 +01001156/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001157private function f_sacch_present(template octetstring l3_exp,
1158 boolean do_fail := true)
1159runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001160 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001161 timer T_sacch := 3.0;
1162 L1CTL.clear;
1163 T_sacch.start;
1164 alt {
1165 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1166 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1167 if (match(l3, l3_exp)) {
1168 setverdict(pass);
1169 } else {
1170 repeat;
1171 }
1172 }
1173 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001174 [not do_fail] T_sacch.timeout {
1175 log("Timeout waiting for SACCH ", l3_exp);
1176 }
1177 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001178 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001180 }
1181 }
1182}
1183
Harald Welte55700662018-03-12 13:15:43 +01001184/* verify that given SACCH payload is not present */
1185private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1186 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001187 timer T_sacch := 3.0;
1188 L1CTL.clear;
1189 T_sacch.start;
1190 alt {
1191 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1192 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1193 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001194 setverdict(fail, "Received unexpected SACCH ", dl);
1195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001196 } else {
1197 repeat;
1198 }
1199 }
1200 [] L1CTL.receive { repeat; }
1201 [] T_sacch.timeout {
1202 setverdict(pass);
1203 }
1204 }
1205}
1206
Harald Welte629cc6b2018-03-11 17:19:05 +01001207/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001208private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1209 /* Set a known default SACCH filling for SI5 */
1210 var octetstring si5 := f_rnd_octstring(19);
1211 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1212
1213 f_l1_tune(L1CTL);
1214 RSL.clear;
1215
1216 /* activate the logical channel */
1217 f_est_dchan();
1218
1219 /* check that the specified SI5 value is actually sent */
1220 f_sacch_present(si5);
1221
1222 /* release the channel */
1223 RSL.clear;
1224 f_rsl_chan_deact();
1225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1226}
1227testcase TC_sacch_filling() runs on test_CT {
1228 var ConnHdlr vc_conn;
1229 var ConnHdlrPars pars;
1230 f_init();
1231 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1232 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1233 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1234 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1235 vc_conn.done;
1236 }
1237 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001239}
1240
Harald Welte629cc6b2018-03-11 17:19:05 +01001241/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001242private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1243 /* Set a known default SACCH filling for SI5 */
1244 var octetstring si5 := f_rnd_octstring(19);
1245 var octetstring si5_diff := f_rnd_octstring(19);
1246 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1247
1248 f_l1_tune(L1CTL);
1249 RSL.clear;
1250
1251 log("Activating channel, expecting standard SI5");
1252 /* activate the logical channel */
1253 f_est_dchan();
1254 /* check that the specified SI5 value is actually sent */
1255 f_sacch_present(si5);
1256
1257 /* set channel-specific different SI5 */
1258 log("Setting channel specific SACCH INFO, expecting it");
1259 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1260 /* check that the specified lchan-specific value is now used */
1261 f_sacch_present(si5_diff);
1262
1263 /* deactivate the channel and re-activate it, this should result in default SI5 */
1264 log("De-activating and re-activating channel, expecting standard SI5");
1265 f_rsl_chan_deact();
1266 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1267 /* Verify that the TRX-wide default SACCH filling is present again */
1268 f_sacch_present(si5);
1269
1270 /* release the channel */
1271 RSL.clear;
1272 f_rsl_chan_deact();
1273 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1274}
1275testcase TC_sacch_info_mod() runs on test_CT {
1276 var ConnHdlr vc_conn;
1277 var ConnHdlrPars pars;
1278 f_init();
1279 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1280 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1281 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1282 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1283 vc_conn.done;
1284 }
1285 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001287}
1288
Harald Welte075d84c2018-03-12 13:07:24 +01001289/* Test SACCH scheduling of multiple different SI message types */
1290private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1291 var octetstring si5 := f_rnd_octstring(19);
1292 var octetstring si5bis := f_rnd_octstring(19);
1293 var octetstring si5ter := f_rnd_octstring(19);
1294 var octetstring si6 := f_rnd_octstring(19);
1295
1296 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1297 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1298 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1300
1301 f_l1_tune(L1CTL);
1302 RSL.clear;
1303
1304 /* activate the logical channel */
1305 f_est_dchan();
1306 L1CTL.clear;
1307
1308 /* check that SACCH actually are received as expected */
1309 f_sacch_present(si5);
1310 f_sacch_present(si5bis);
1311 f_sacch_present(si5ter);
1312 f_sacch_present(si6);
1313
1314 /* release the channel */
1315 f_rsl_chan_deact();
1316 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1317}
1318testcase TC_sacch_multi() runs on test_CT {
1319 var ConnHdlr vc_conn;
1320 var ConnHdlrPars pars;
1321 f_init();
1322 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1323 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1324 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1325 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1326 vc_conn.done;
1327 }
1328 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001330}
1331
Harald Welte55700662018-03-12 13:15:43 +01001332/* Test if SACH information is modified as expected */
1333private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1334 var octetstring si5 := f_rnd_octstring(19);
1335 var octetstring si6 := f_rnd_octstring(19);
1336
1337 /* First, configure both SI5 and SI6 to be transmitted */
1338 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1339 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1340
1341 f_l1_tune(L1CTL);
1342 RSL.clear;
1343
1344 /* activate the logical channel */
1345 f_est_dchan();
1346 L1CTL.clear;
1347
1348 /* check that SACCH actually are received as expected */
1349 f_sacch_present(si5);
1350 f_sacch_present(si6);
1351
1352 /* disable SI6 */
1353 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1354
1355 /* check that SI5 is still transmitted */
1356 f_sacch_present(si5);
1357 /* check if SI6 is now gone */
1358 f_sacch_missing(si6);
1359
1360 /* release the channel */
1361 f_rsl_chan_deact();
1362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1363}
1364testcase TC_sacch_multi_chg() runs on test_CT {
1365 var ConnHdlr vc_conn;
1366 var ConnHdlrPars pars;
1367 f_init();
1368 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1369 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1370 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1371 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1372 vc_conn.done;
1373 }
1374 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001376}
1377
Harald Weltec8d363c2019-05-19 20:36:48 +02001378/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1379private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1380 var octetstring si5 := f_rnd_octstring(19);
1381 var octetstring si6 := f_rnd_octstring(19);
1382 var octetstring si5_specific := f_rnd_octstring(19);
1383 var octetstring si6_specific := f_rnd_octstring(19);
1384
1385 /* First, configure both SI5 and SI6 to be transmitted */
1386 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1387 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1388
1389 f_l1_tune(L1CTL);
1390 RSL.clear;
1391
1392 /* activate channel with different SACCH filling */
1393 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1394 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1395 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1396 }));
1397 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1398 RSL_IE_Body:{sacch_info := sacch_info})) };
1399 f_est_dchan(more_ies := addl_ies);
1400
1401 /* check that SACCH actually are received as expected */
1402 f_sacch_present(si5_specific);
1403 f_sacch_present(si6_specific);
1404
1405 /* release the channel */
1406 f_rsl_chan_deact();
1407 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1408}
1409testcase TC_sacch_chan_act() runs on test_CT {
1410 var ConnHdlr vc_conn;
1411 var ConnHdlrPars pars;
1412 f_init();
1413
1414 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1415 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1416 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1417 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1418 vc_conn.done;
1419 }
1420 /* TODO: do the above in parallel, rather than sequentially? */
1421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1422}
1423
Harald Welte8b01c792019-05-19 22:51:25 +02001424/* verify that SACCH DL transmission is started only if MS power IE present
1425 * see section 4.1.3 of 3GPP TS 48.058 */
1426private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1427 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001428 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001429
1430 f_l1_tune(L1CTL);
1431 RSL.clear;
1432
1433 /* Step 1: Activate ASYNC HO channel without MS power IE */
1434
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001435 var integer ho_ref := oct2int(f_rnd_octstring(1));
1436 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1437 RSL_IE_Body:{ handover_ref := ho_ref }));
1438 var RSL_IE_List addl_ies := {
1439 ho_ref_ie
1440 };
1441
Harald Welte8b01c792019-05-19 22:51:25 +02001442 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001443 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 +02001444 /* don't perform immediate assignment here, as we're testing non-IA case */
1445 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001446 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001447
1448 /* Verify that no DL SACCH is being received */
1449 f_sacch_missing(?);
1450
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001451 /* Send handover Access Burst and expect SACCH to start */
1452 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1453
1454 f_sacch_present(si5);
1455
Harald Welte8b01c792019-05-19 22:51:25 +02001456 f_rsl_chan_deact();
1457 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1458
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001459 /* Tune back to CCCH/BCCH */
1460 f_l1_tune(L1CTL);
1461
Harald Welte8b01c792019-05-19 22:51:25 +02001462
1463 /* Step 2: Activate ASYNC HO channel with MS power IE */
1464
1465 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001466 addl_ies := {
1467 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001468 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1469 };
1470 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1471 /* don't perform immediate assignment here, as we're testing non-IA case */
1472 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001473 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001474
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001475 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1476 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1477 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001478
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001479 /* Send handover Access Burst and expect SACCH to remain present */
1480 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1481
1482 f_sacch_present(si5);
1483
Harald Welte8b01c792019-05-19 22:51:25 +02001484 f_rsl_chan_deact();
1485 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1486}
1487testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1488 var ConnHdlr vc_conn;
1489 var ConnHdlrPars pars;
1490 f_init();
1491
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001492 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1493 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1494 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001495 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1496 vc_conn.done;
1497 }
1498 /* TODO: do the above in parallel, rather than sequentially? */
1499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1500}
1501
1502/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1503 * see section 4.1.4 of 3GPP TS 48.058 */
1504private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1505 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001506 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1507
Harald Welte8b01c792019-05-19 22:51:25 +02001508 var RSL_IE_List addl_ies;
1509
1510 f_l1_tune(L1CTL);
1511 RSL.clear;
1512
1513 /* Step 1: Activate SYNC HO channel without MS power IE */
1514
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001515 var integer ho_ref := oct2int(f_rnd_octstring(1));
1516 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1517 RSL_IE_Body:{ handover_ref := ho_ref }));
1518 addl_ies := {
1519 ho_ref_ie
1520 };
1521
Harald Welte8b01c792019-05-19 22:51:25 +02001522 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001523 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 +02001524 /* don't perform immediate assignment here, as we're testing non-IA case */
1525 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001526 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001527
1528 /* Verify that no DL SACCH is being received */
1529 f_sacch_missing(?);
1530
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001531 /* Send handover Access Burst and expect SACCH to start */
1532 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1533
1534 f_sacch_present(si5);
1535
Harald Welte8b01c792019-05-19 22:51:25 +02001536 f_rsl_chan_deact();
1537 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1538
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001539 /* Tune back to CCCH/BCCH */
1540 f_l1_tune(L1CTL);
1541
Harald Welte8b01c792019-05-19 22:51:25 +02001542
1543 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1544
1545 /* Activate channel on BTS side */
1546 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001547 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001548 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1549 };
1550 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1551 /* don't perform immediate assignment here, as we're testing non-IA case */
1552 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001553 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001554
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001555 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1556 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1557 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001558
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001559 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001560 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1561
1562 f_sacch_present(si5);
1563
Harald Welte8b01c792019-05-19 22:51:25 +02001564 f_rsl_chan_deact();
1565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1566
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001567 /* Tune back to CCCH/BCCH */
1568 f_l1_tune(L1CTL);
1569
Harald Welte8b01c792019-05-19 22:51:25 +02001570
1571 /* Step 2b: Activate SYNC HO channel with TA IE */
1572
1573 /* Activate channel on BTS side */
1574 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001575 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001576 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1577 };
1578 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1579 /* don't perform immediate assignment here, as we're testing non-IA case */
1580 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001581 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001582
1583 /* Verify that no DL SACCH is being received */
1584 f_sacch_missing(?);
1585
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001586 /* Send handover Access Burst and expect SACCH to start */
1587 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1588
1589 f_sacch_present(si5);
1590
Harald Welte8b01c792019-05-19 22:51:25 +02001591 f_rsl_chan_deact();
1592 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1593
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001594 /* Tune back to CCCH/BCCH */
1595 f_l1_tune(L1CTL);
1596
Harald Welte8b01c792019-05-19 22:51:25 +02001597
1598 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1599
1600 /* Activate channel on BTS side */
1601 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001602 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001603 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1604 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1605 };
1606 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1607 /* don't perform immediate assignment here, as we're testing non-IA case */
1608 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001609 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001610
1611 /* Verify that DL SACCH is being received */
1612 f_sacch_present(si5);
1613
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001614 /* Send handover Access Burst and expect SACCH to remain present */
1615 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1616
1617 f_sacch_present(si5);
1618
Harald Welte8b01c792019-05-19 22:51:25 +02001619 f_rsl_chan_deact();
1620 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1621}
1622testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1623 var ConnHdlr vc_conn;
1624 var ConnHdlrPars pars;
1625 f_init();
1626
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001627 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1628 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1629 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001630 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1631 vc_conn.done;
1632 }
1633 /* TODO: do the above in parallel, rather than sequentially? */
1634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1635}
Harald Welte629cc6b2018-03-11 17:19:05 +01001636
1637
1638/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001639 * RACH Handling
1640 ***********************************************************************/
1641
Harald Welte8c24c2b2018-02-26 08:31:31 +01001642/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001643private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001644 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001645 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001646 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001647
Harald Welte8c24c2b2018-02-26 08:31:31 +01001648 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001649 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001650 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001651 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001652 if (emerg == true) {
1653 ra := f_rnd_ra_emerg();
1654 } else {
1655 ra := f_rnd_ra_cs();
1656 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001657 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1658 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660 }
1661 fn_last := fn;
1662
1663 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001664 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001665 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001666 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001667 T.stop;
1668 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001669 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001671 }
1672 [] RSL_CCHAN.receive { repeat; }
1673 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001674 test_failed := true;
1675 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001676 }
1677 }
1678 }
Maxba06feb2019-03-05 10:52:46 +01001679 if (test_failed) {
1680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001681 }
Maxba06feb2019-03-05 10:52:46 +01001682 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001684}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685
Philipp Maier16ade782020-07-08 21:36:00 +02001686/* Normal variant */
1687testcase TC_rach_content() runs on test_CT {
1688 f_TC_rach_content(emerg := false);
1689}
1690
1691/* Emergency call variant */
1692testcase TC_rach_content_emerg() runs on test_CT {
1693 f_TC_rach_content(emerg := true);
1694}
1695
Harald Welte8c24c2b2018-02-26 08:31:31 +01001696/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1697testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001698 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001699 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001700 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001701 f_l1_tune(L1CTL);
1702
1703 var GsmFrameNumber fn_last := 0;
1704 for (var integer i := 0; i < 1000; i := i+1) {
1705 var OCT1 ra := f_rnd_ra_cs();
1706 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1707 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001709 }
1710 fn_last := fn;
1711 }
1712 var integer rsl_chrqd := 0;
1713 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001714 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001715 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001716 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001718 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001719 repeat;
1720 }
1721 [] RSL_CCHAN.receive { repeat; }
1722 [] T.timeout { }
1723 }
1724 if (rsl_chrqd == 1000) {
1725 setverdict(pass);
1726 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001728 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001730}
1731
Harald Welte3453ab42019-05-24 21:19:58 +02001732private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1733 var charstring bts_str := "bts " & int2str(bts_nr);
1734 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1735}
1736
1737/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1738private template integer tr_rach_slots_per_interval := (90 .. 130);
1739
1740/* Expect 0 RACH load on an idle BTS that has just started up */
1741testcase TC_rach_load_idle_thresh0() runs on test_CT {
1742 var ASP_RSL_Unitdata rx_ud;
1743
1744 f_init_vty_bsc();
1745 /* send load indications even at 0% load */
1746 f_vty_load_ind_thresh(0);
1747 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1748 f_sleep(2.0);
1749
1750 f_init();
1751
Harald Weltee37f9a52020-10-11 20:45:23 +02001752 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1753 alt {
1754 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1755 [] RSL_CCHAN.receive { repeat }
1756 }
1757
Harald Welte3453ab42019-05-24 21:19:58 +02001758 timer T := 5.0;
1759 T.start;
1760 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001761 [] 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 +02001762 setverdict(pass);
1763 repeat;
1764 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001765 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001766 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1767 repeat;
1768 }
1769 [] RSL_CCHAN.receive {
1770 repeat;
1771 }
1772 [] T.timeout { }
1773 }
1774
1775 f_vty_load_ind_thresh(10);
1776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1777}
1778
1779/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1780testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1781 var ASP_RSL_Unitdata rx_ud;
1782
1783 f_init_vty_bsc();
1784 f_init();
1785
1786 timer T := 5.0;
1787 T.start;
1788 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001789 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001790 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1791 repeat;
1792 }
1793 [] RSL_CCHAN.receive {
1794 repeat;
1795 }
1796 [] T.timeout {
1797 setverdict(pass);
1798 }
1799 }
1800
1801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1802}
1803
1804/* Expect 0 RACH load on an idle BTS that has just started up */
1805testcase TC_rach_load_count() runs on test_CT {
1806 var ASP_RSL_Unitdata rx_ud;
1807 var integer load_access_count := 0;
1808
1809 f_init_vty_bsc();
1810 /* send load indications even at 0% load */
1811 f_vty_load_ind_thresh(0);
1812 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1813 f_sleep(2.0);
1814 f_init();
1815
1816 f_init_l1ctl();
1817 f_sleep(1.0);
1818 f_l1_tune(L1CTL);
1819
Harald Welte52ae1682020-10-11 20:45:55 +02001820 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1821 alt {
1822 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1823 [] RSL_CCHAN.receive { repeat }
1824 }
1825
Harald Welte3453ab42019-05-24 21:19:58 +02001826 var GsmFrameNumber fn_last := 0;
1827 for (var integer i := 0; i < 1000; i := i+1) {
1828 var OCT1 ra := f_rnd_ra_cs();
1829 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1830 if (fn == fn_last) {
1831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1832 }
1833 fn_last := fn;
1834 }
1835
1836 timer T := 5.0;
1837 T.start;
1838 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001839 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001840 -> value rx_ud {
1841 var RSL_IE_Body ie;
1842 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1843 load_access_count := load_access_count + ie.rach_load.access_count;
1844 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1845 setverdict(fail, "Access count cannot be < Busy count");
1846 }
1847 repeat;
1848 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001849 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001850 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1851 repeat;
1852 }
1853 [] RSL_CCHAN.receive {
1854 repeat;
1855 }
1856 [] T.timeout { }
1857 }
1858 if (load_access_count == 1000) {
1859 setverdict(pass);
1860 } else {
1861 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1862 }
1863
1864 f_vty_load_ind_thresh(10);
1865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1866}
1867
Harald Welte54a2a2d2018-02-26 09:14:05 +01001868private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001869 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001870 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001871 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001872 f_sleep(0.5);
1873
1874 /* Transmit RACH request + wait for confirmation */
1875 var OCT1 ra := f_rnd_ra_cs();
1876 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1877
1878 /* Check for expected result */
1879 timer T := 1.5;
1880 T.start;
1881 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001882 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001883 setverdict(pass);
1884 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001885 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001887 }
1888 [] RSL_CCHAN.receive { repeat; }
1889 [not expect_pass] T.timeout {
1890 setverdict(pass);
1891 }
1892 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001894 }
1895 }
1896}
1897
1898/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1899testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001900 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001901 f_init_l1ctl();
1902 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001903 f_sleep(1.0);
1904
1905 /* default max-ta is 63 (full range of GSM timing advance */
1906
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001907 /* We allow early arrival up to 2 symbols */
1908 f_rach_toffs(-1*256, true);
1909 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001910 f_rach_toffs(-10*256, false);
1911
1912 /* 0 / 32 / 63 bits is legal / permitted */
1913 f_rach_toffs(0, true);
1914 f_rach_toffs(32*256, true);
1915 f_rach_toffs(63*256, true);
1916
1917 /* more than 63 bits is not legal / permitted */
1918 f_rach_toffs(64*256, false);
1919 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001921}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001922
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001923private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001924 var GsmFrameNumber fn;
1925 var RSL_Message rm;
1926
1927 f_l1_tune(L1CTL);
1928 RSL.clear;
1929
1930 /* Generate a random Handover Reference */
1931 var integer ho_ref := oct2int(f_rnd_octstring(1));
1932
1933 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1934 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1935 RSL_IE_Body:{ handover_ref := ho_ref }));
1936
1937 /* Activate a channel on the BTS side (no encryption) */
1938 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1939 act_type := t_RSL_IE_ActType_HO_SYNC);
1940
1941 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1942 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001943 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001944
1945 /* Send handover Access Burst */
1946 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1947
1948 /* TODO: test mismatching Handover Reference, and missing IE */
1949
1950 /* Wait for handover detection */
1951 timer T := 3.0;
1952 T.start;
1953 alt {
1954 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1955 log("Handover RACH has been detected: ", rm);
1956 setverdict(pass);
1957 }
1958 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1960 log2str("RSL_CHAN_RQD was not expected: ", rm));
1961 }
1962 [] RSL.receive { repeat; }
1963 [] T.timeout {
1964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1965 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1966 }
1967 }
1968
1969 /* Release the channel */
1970 f_rsl_chan_deact();
1971 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1972}
1973
1974/* Test handover RACH detection */
1975testcase TC_ho_rach() runs on test_CT {
1976 var ConnHdlrPars pars;
1977 var ConnHdlr vc_conn;
1978
1979 f_init();
1980
1981 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1982 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1983 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1984 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1985 vc_conn.done;
1986 }
1987
1988 /* TODO: do the above in parallel, rather than sequentially? */
1989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1990}
1991
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001992/* Test sending of the RR Physical Information message on DCCH */
1993private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1994 var PDU_ML3_NW_MS dcch_pdu;
1995 var integer count := 0;
1996 var L1ctlDlMessage dl;
1997 timer T;
1998
1999 f_l1_tune(L1CTL);
2000 RSL.clear;
2001
2002 /* Generate a random Handover Reference */
2003 var integer ho_ref := oct2int(f_rnd_octstring(1));
2004
2005 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
2006 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
2007 RSL_IE_Body:{ handover_ref := ho_ref }));
2008
2009 /* Activate a channel on the BTS side (no encryption) */
2010 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2011 act_type := t_RSL_IE_ActType_HO_SYNC);
2012
2013 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2014 * waiting for Immediate Assignment and sending of an Access Burst. */
2015 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2016
2017 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2018 * context means any L2 frames, not only the RR Physical Information. */
2019 T.start(2.0);
2020 L1CTL.clear;
2021 alt {
2022 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2023 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2024 T.stop;
2025 }
2026 [] L1CTL.receive { repeat; }
2027 [] T.timeout { setverdict(pass); }
2028 }
2029
2030 /* Send handover Access Burst */
2031 log("Sending handover Access Burst");
2032 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2033
2034 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2035 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2036 L1CTL.clear;
2037 alt {
2038 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2039 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2040 log("Rx RR Physical Information: ", dcch_pdu);
2041 /* Wait until the count reaches Ny1 */
2042 count := count + 1;
2043 if (count < mp_ho_ny1)
2044 { repeat; }
2045 setverdict(pass);
2046 }
2047 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2048 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2050 }
2051 [] L1CTL.receive { repeat; }
2052 [] T.timeout {
2053 setverdict(fail, "Timeout waiting for RR Physical Information");
2054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2055 }
2056 }
2057
2058 /* Release the channel */
2059 f_rsl_chan_deact();
2060 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2061}
2062testcase TC_ho_physical_info() runs on test_CT {
2063 var ConnHdlrPars pars;
2064 var ConnHdlr vc_conn;
2065
2066 f_init();
2067
2068 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2069 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2070 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2071 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2072 vc_conn.done;
2073 }
2074
2075 /* TODO: do the above in parallel, rather than sequentially? */
2076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2077}
2078
Harald Welte93640c62018-02-25 16:59:33 +01002079/***********************************************************************
2080 * Measurement Processing / Reporting
2081 ***********************************************************************/
2082
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002083private template (value) LapdmAddressField
2084ts_LapdmAddr(template (value) LapdmSapi sapi,
2085 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002086 spare := '0'B,
2087 lpd := 0,
2088 sapi := sapi,
2089 c_r := c_r,
2090 ea := true
2091}
2092
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002093private template (value) LapdmFrameAB
2094ts_LAPDm_AB(template (value) LapdmSapi sapi,
2095 template (value) GsmRrL3Message l3,
2096 template (value) boolean c_r := false,
2097 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002098 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002099 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002100 len := 0, /* overwritten */
2101 m := false,
2102 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002103 payload := enc_GsmRrL3Message(valueof(l3)),
2104 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002105}
2106
2107/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002108private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002109 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002110 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002111
Harald Weltef8df4cb2018-03-10 15:15:08 +01002112 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002113 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002114
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002115 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002116 g_pars.l1_pars.meas_ul.full.rxlev,
2117 g_pars.l1_pars.meas_ul.sub.rxlev,
2118 g_pars.l1_pars.meas_ul.full.rxqual,
2119 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002120 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002121
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002122 var template (value) SacchL1Header l1h := ts_SacchL1Header(
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07002123 g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002124
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002125 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2126 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002127
2128 log("Sending Measurement Report: ", l1h, l2);
2129 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002130 repeat;
2131 }
2132}
2133
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002134/* handle incoming downlink SACCH, decode the L1 header into the given record */
2135private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2136 boolean do_apply := true)
2137runs on ConnHdlr
2138{
2139 var L1ctlDlMessage l1_dl;
2140
2141 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2142 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2143 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2144 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2145
2146 if (do_apply) {
2147 /* Update TA and MS power to follow what BTS requests */
2148 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2149 }
2150 }
2151}
2152
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002153private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002154 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002155 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002156 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2157 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002158 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2159 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002160 repeat;
2161 }
2162}
2163
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002164private altstep as_l1_tch_loop() runs on ConnHdlr {
2165 var L1ctlDlMessage l1_dl;
2166 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2167 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002168
2169 /* occasionaly inject FACCH frames into the uplink */
2170 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2171 var octetstring pl := '010301'O;
2172 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2173 f_pad_oct(pl, 23, '2B'O)));
2174 } else {
2175 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2176 l1_dl.payload.traffic_ind.data));
2177 }
2178
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002179 repeat;
2180 }
2181}
2182
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002183private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002184 uint6_t rxlev,
2185 uint3_t rxqual
2186}
2187
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002188private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002189 MeasElem full,
2190 MeasElem sub
2191}
2192
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002193private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002194 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002195 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002196 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002197 MeasElemFS meas_ul,
2198 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002199 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002200 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002201 uint8_t ms_actual_ta,
2202 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002203}
2204
2205/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2206private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2207 return 63 + (toffs256s/256);
2208}
2209
Harald Welted5684392018-03-10 18:22:04 +01002210private function f_max(integer a, integer b) return integer {
2211 if (a > b) {
2212 return a;
2213 } else {
2214 return b;
2215 }
2216}
2217
2218private function f_min(integer a, integer b) return integer {
2219 if (a < b) {
2220 return a;
2221 } else {
2222 return b;
2223 }
2224}
2225
2226/* compute negative tolerance val-tolerance, ensure >= min */
2227private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2228 val := val - tolerance;
2229 return f_max(val, min);
2230}
2231
2232/* compute positive tolerance val+tolerance, ensure <= max */
2233private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2234 val := val + tolerance;
2235 return f_min(val, max);
2236}
2237
2238/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2239private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2240return template integer {
2241 var template integer ret;
2242 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2243 return ret;
2244}
2245
2246
Harald Welte70767382018-02-21 12:16:40 +01002247/* build a template for matching measurement results against */
2248private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2249 var ConnL1Pars l1p := g_pars.l1_pars;
2250 var template RSL_IE_UplinkMeas ul_meas := {
2251 len := 3,
2252 rfu := '0'B,
2253 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002254 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002255 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002256 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002257 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002258 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2259 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002260 supp_meas_info := omit
2261 };
Harald Welte685d5982018-02-27 20:42:05 +01002262 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002263 ul_meas.len := (3+8);
2264 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002265 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002266 toa256_min := ?,
2267 toa256_max := ?,
2268 toa256_std_dev := ?
2269 }
Harald Welte685d5982018-02-27 20:42:05 +01002270 }
Harald Welte70767382018-02-21 12:16:40 +01002271 var template RSL_IE_BS_Power bs_power := {
2272 reserved := 0,
2273 epc := false,
2274 fpc := false,
2275 power_level := l1p.bs_power_level
2276 };
2277 var template RSL_IE_L1Info l1_info := {
2278 ms_power_lvl := l1p.ms_power_level,
2279 fpc := false,
2280 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002281 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002282 };
2283 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002284 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002285 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2286 ?, t_toffs);
2287}
2288
Philipp Maierdd841d32019-12-17 14:44:54 +01002289/* build a template for matching measurement results that do not contain any
2290 * MS related measurement (l1_info, l3_info and ms timing offset). */
2291private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2292 var ConnL1Pars l1p := g_pars.l1_pars;
2293 var template RSL_IE_UplinkMeas ul_meas := {
2294 len := 3,
2295 rfu := '0'B,
2296 dtx_d := l1p.dtx_enabled,
2297 rxlev_f_u := ?,
2298 reserved1 := '00'B,
2299 rxlev_s_u := ?,
2300 reserved2 := '00'B,
2301 rxq_f_u := ?,
2302 rxq_s_u := ?,
2303 supp_meas_info := omit
2304 };
2305 if (l1p.toa256_enabled) {
2306 ul_meas.len := (3+8);
2307 ul_meas.supp_meas_info := {
2308 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2309 toa256_min := ?,
2310 toa256_max := ?,
2311 toa256_std_dev := ?
2312 }
2313 }
2314 var template RSL_IE_BS_Power bs_power := {
2315 reserved := 0,
2316 epc := false,
2317 fpc := false,
2318 power_level := l1p.bs_power_level
2319 };
2320
2321 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2322}
2323
Harald Welte70767382018-02-21 12:16:40 +01002324/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002325private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002326 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002327 var boolean chan_est := false;
2328
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002329 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002330
2331 /* Receive osmocom specific measurement reports. This is the normal
2332 * case. Here we verify that the measurement reports we sent are
2333 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002334 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2335 /* increment counter of next to-be-expected meas rep */
2336 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2337 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002338 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002339
2340 /* The following two cases may only happen in the beginning
2341 * of the channel establishment phase. Once we have received
2342 * the "our" measurement report the first time, the channel
2343 * is established and empty or hardcoded TRXCON reports must
2344 * not occur anymore. */
2345 chan_est := true;
2346
2347 repeat;
2348 }
2349
2350 /* When the BTS has established the channel, the MS might need slightly
2351 * more time to establish the channel and actually start sending. The
2352 * result is then a measurement report that just lacks the measurement
2353 * information of the MS. This is normal and we tolerate this behavior. */
2354 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2355 /* increment counter of next to-be-expected meas rep */
2356 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2357 /* Re-start the timer expecting the next MEAS RES */
2358 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002359 repeat;
2360 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002361
2362 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2363 * measurements if the TTCN3 side does not supply measurement input in
2364 * time. In those cases TRXCON will either use a cached measurement
2365 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2366 * report the templates above will not match. We tolerate this
2367 * behavior, but only once. */
2368 [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 +01002369 /* increment counter of next to-be-expected meas rep */
2370 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2371 if (g_first_meas_res) {
2372 g_first_meas_res := false;
2373 repeat;
2374 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002376 }
Harald Welte70767382018-02-21 12:16:40 +01002377 }
2378 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002380 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002381 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002383 }
2384}
2385
Harald Weltee613f962018-04-18 22:38:16 +02002386private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2387 select (rsl_alg_id) {
2388 case (RSL_ALG_ID_A5_0) { return 0; }
2389 case (RSL_ALG_ID_A5_1) { return 1; }
2390 case (RSL_ALG_ID_A5_2) { return 2; }
2391 case (RSL_ALG_ID_A5_3) { return 3; }
2392 case (RSL_ALG_ID_A5_4) { return 4; }
2393 case (RSL_ALG_ID_A5_5) { return 5; }
2394 case (RSL_ALG_ID_A5_6) { return 6; }
2395 case (RSL_ALG_ID_A5_7) { return 7; }
2396 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2398 /* Make compiler happy by calling mtc.stop here. It is already
2399 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002400 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002401 }
2402 }
2403}
2404
2405private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2406 select (rsl_alg_id) {
2407 case (RSL_ALG_ID_A5_1) { return '000'B; }
2408 case (RSL_ALG_ID_A5_2) { return '001'B; }
2409 case (RSL_ALG_ID_A5_3) { return '010'B; }
2410 case (RSL_ALG_ID_A5_4) { return '011'B; }
2411 case (RSL_ALG_ID_A5_5) { return '100'B; }
2412 case (RSL_ALG_ID_A5_6) { return '101'B; }
2413 case (RSL_ALG_ID_A5_7) { return '110'B; }
2414 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2416 /* Make compiler happy by calling mtc.stop here. It is already
2417 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002418 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002419 }
2420 }
2421}
2422
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002423/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2424private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2425 var GsmFrameNumber fn;
2426 timer T := 8.0;
2427
2428 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2429 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2430
2431 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2432 /* Send the actual RACH */
2433 fn := f_L1CTL_RACH(L1CTL, ra);
2434
2435 T.start;
2436 alt {
2437 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2438 [] T.timeout {
2439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2440 }
2441 }
2442 T.stop
2443 return fn;
2444}
Harald Weltee613f962018-04-18 22:38:16 +02002445
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002446/* Tune to a dedicated channel: L1CTL only */
2447private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002448 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002449 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002450 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002451 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002452 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002453 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002454 pars.fhp.maio_hsn.hsn,
2455 pars.fhp.maio_hsn.maio,
2456 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002457 }
2458}
2459
Harald Welte70767382018-02-21 12:16:40 +01002460/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002461private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002462 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002463
2464 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002465 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002466
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002467 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002468 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002469 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002470 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002471 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2472 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002473 }
2474
Harald Welte70767382018-02-21 12:16:40 +01002475 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002476 f_l1ctl_est_dchan(L1CTL, g_pars);
2477
Harald Weltee613f962018-04-18 22:38:16 +02002478 /* enable encryption, if requested */
2479 if (encr_enable) {
2480 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2481 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2482 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002483
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002484 /* Send TCH Mode Request to the L1 if needed */
2485 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2486 var L1ctlTchMode tch_mode;
2487
2488 select (g_pars.chan_mode.coding_alg_rate) {
2489 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2490 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2491 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2492 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2493 case else {
2494 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2495 " is not supported by the L1, falling back to signalling");
2496 tch_mode := L1CTL_CHAN_MODE_SIGN;
2497 }
2498 }
2499
2500 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2501 }
2502
Harald Weltefa45e9e2018-03-10 18:59:03 +01002503 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002504}
2505
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002506/* Initialize and start the RTP emulation component for a ConnHdlr */
2507friend function f_rtpem_activate(inout octetstring payload,
2508 RtpemConfig cfg := c_RtpemDefaultCfg,
2509 RtpemMode mode := RTPEM_MODE_BIDIR)
2510runs on ConnHdlr {
2511 /* Step 0: initialize, connect and start the emulation component */
2512 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2513 map(vc_RTPEM:RTP, system:RTP);
2514 map(vc_RTPEM:RTCP, system:RTCP);
2515 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2516 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2517 vc_RTPEM.start(RTP_Emulation.f_main());
2518
2519 /* Step 1: configure the RTP parameters */
2520 var integer payload_len := 0;
2521 var octetstring hdr := ''O;
2522
2523 select (g_pars.chan_mode) {
2524 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2525 { payload_len := 33; hdr := 'D0'O; }
2526 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2527 { payload_len := 15; hdr := '00'O; }
2528 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2529 { payload_len := 31; hdr := 'C0'O; }
2530 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2531 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2533 }
2534 }
2535
2536 /* Pad the payload to conform the expected length */
2537 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2538 cfg.tx_fixed_payload := payload;
2539 f_rtpem_configure(RTPEM_CTRL, cfg);
2540
2541 /* Step 2: bind the RTP emulation to the configured address */
2542 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2543 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2544
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002545 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2546 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2547 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2548 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2549 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002550 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2551 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002552 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002553
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002554 /* Step 3b: send MDCX with the configured address/port to the IUT */
2555 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2556 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2557 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2558 remote_port := rtpem_bind_port,
2559 rtp_pt2 := 0),
2560 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2561 "IPA MDCX ACK");
2562
2563 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2564 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2565 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2566 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002567
2568 /* Step 5: set the given RTP emulation mode */
2569 f_rtpem_mode(RTPEM_CTRL, mode);
2570}
2571
Harald Welte70767382018-02-21 12:16:40 +01002572/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002573private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002574 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002575 RSL.clear;
2576
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002577 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002578 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002579 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002580 }
Harald Welte70767382018-02-21 12:16:40 +01002581
2582 f_est_dchan();
2583
2584 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2585 * RSL measurement reports on Abis side */
2586 timer T := 8.0;
2587 T.start;
2588 alt {
2589 [] as_l1_sacch();
2590 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002591 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002592 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002593 [] L1CTL.receive { repeat; }
2594 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002595 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002596 * of any earlier errors, so if we reach this timeout, we're good */
2597 setverdict(pass);
2598 }
2599 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002601 }
2602 }
2603 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002604 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002605}
Harald Welte0472ab42018-03-12 15:02:26 +01002606
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002607/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2608private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002609 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002610 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2611 timer Tup := 10.0;
2612 Tup.start;
2613 alt {
2614 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2615 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2616 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002617
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002618 if (rx_lvl != max_rx_lvl) {
2619 repeat;
2620 }
2621 Tup.stop;
2622 }
2623 [] L1CTL.receive { repeat; }
2624 [] Tup.timeout {
2625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2626 log2str("Didn't reach full power ", max_rx_lvl));
2627 }
2628 }
2629 return max_rx_lvl;
2630}
2631
2632/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2633private function f_verify_ramp_up() runs on ConnHdlr {
2634 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002635 var integer initial_rx_lvl := -1;
2636 var integer last_rx_lvl := -1;
2637 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2638
2639 timer T := 2.0;
2640 alt {
2641 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2642 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2643 log("Received rx_level=", rx_lvl);
2644 if (initial_rx_lvl == -1) {
2645 initial_rx_lvl := rx_lvl;
2646 last_rx_lvl := rx_lvl;
2647
2648 /* Expect a somehow low value during first received messages */
2649 if (initial_rx_lvl >= max_rx_lvl / 2) {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 log2str("Detected high initial tx power during ramp up: ",
2652 initial_rx_lvl , ", full power is", max_rx_lvl));
2653 }
2654 }
2655
2656 /* received Rx level bigger than maximum allowed power by CN */
2657 if (rx_lvl > max_rx_lvl) {
2658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2659 log2str("Detected Tx power higher than full power: ",
2660 rx_lvl , " > ", max_rx_lvl));
2661 }
2662
2663 /* Make sure it never decreases, since we are rumping up */
2664 if (last_rx_lvl > rx_lvl) {
2665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2666 log2str("Detected Tx power decrease during ramp up: ",
2667 last_rx_lvl , " -> ", rx_lvl));
2668 }
2669
2670 if (rx_lvl == max_rx_lvl and not T.running) {
2671 /* We reached the maximum power, start timer and receive
2672 /* a few more to make sure we don't surpass it */
2673 log("Reached full power, wating a bit more until success");
2674 T.start;
2675 }
2676
2677 last_rx_lvl := rx_lvl;
2678 repeat;
2679 }
2680 [] L1CTL.receive { repeat; }
2681 [] T.timeout { }
2682 }
2683
2684 /* We didn't increase tx power during ramp up */
2685 if (initial_rx_lvl < last_rx_lvl) {
2686 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2687 } else {
2688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2689 log2str("No Tx power increase during whole ramp up: ",
2690 initial_rx_lvl , " -> ", last_rx_lvl));
2691 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002692}
2693
2694/* verify BTS ramps power down to rx_level 0 */
2695private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2696 var L1ctlDlMessage l1_dl;
2697 var integer last_rx_lvl := max_rx_lvl;
2698
2699 timer Tdown := 5.0;
2700 Tdown.start;
2701 alt {
2702 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2703 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2704 log("Received rx_level=", rx_lvl);
2705
2706 /* received Rx level bigger than maximum allowed power by CN */
2707 if (rx_lvl > max_rx_lvl) {
2708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2709 log2str("Detected Tx power higher than full power: ",
2710 rx_lvl , " > ", max_rx_lvl));
2711 }
2712
2713 /* Make sure it never increases, since we are rumping down */
2714 if (last_rx_lvl < rx_lvl) {
2715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2716 log2str("Detected Tx power increase during ramp up: ",
2717 last_rx_lvl , " -> ", rx_lvl));
2718 }
2719
2720 last_rx_lvl := rx_lvl;
2721 if (last_rx_lvl != 0) {
2722 repeat;
2723 }
2724 /* we reached power level 0, we are done */
2725 Tdown.stop;
2726 }
2727 [] L1CTL.receive { repeat; }
2728 [] Tdown.timeout { }
2729 }
2730
2731 /* We didn't increase tx power during ramp down */
2732 if (max_rx_lvl > last_rx_lvl) {
2733 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2734 } else {
2735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2736 log2str("No Tx power decrease during whole ramp down: ",
2737 max_rx_lvl , " -> ", last_rx_lvl));
2738 }
2739}
2740
2741/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002742private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002743 f_l1_tune(L1CTL);
2744 RSL.clear;
2745
2746 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002747
2748 setverdict(pass);
2749}
2750testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2751 var ConnHdlr vc_conn;
2752 var ConnHdlrPars pars;
2753 f_init();
2754 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2755 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2756 pcu_comp := false, trxc_comp := true);
2757 vc_conn.done;
2758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2759}
2760
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002761/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002762private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002763 f_connhdlr_init_vty_bsc();
2764
2765 f_l1_tune(L1CTL);
2766 RSL.clear;
2767
2768 /* Wait until BTS is started and at full power */
2769 var integer max_rx_lvl := f_wait_ramp_up();
2770 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2771
2772 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2773 f_verify_ramp_down(max_rx_lvl);
2774
2775 setverdict(pass);
2776}
2777testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2778 var ConnHdlr vc_conn;
2779 var ConnHdlrPars pars;
2780 f_init();
2781 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2782 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2783 pcu_comp := false, trxc_comp := true);
2784 vc_conn.done;
2785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2786}
2787
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002788/* Verify Tx power:
2789 * + ramping down during ADM state UNLOCKED->LOCKED
2790 * + ramping up during ADM state LOCKED->UNLOCKED
2791 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002792private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002793 var L1ctlDlMessage l1_dl;
2794 var integer last_rx_lvl;
2795
2796 f_connhdlr_init_vty_bsc();
2797
2798 f_l1_tune(L1CTL);
2799 RSL.clear;
2800
2801 /* Wait until BTS is started and at full power */
2802 var integer max_rx_lvl := f_wait_ramp_up();
2803 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2804
2805 log("ADM STATE UNLOCKED->LOCKED");
2806 f_vty_enter_cfg_trx(BSCVTY);
2807 f_vty_transceive(BSCVTY, "rf_locked 1");
2808 last_rx_lvl := max_rx_lvl;
2809 f_verify_ramp_down(max_rx_lvl);
2810
2811 /* Let some time after we received 0dBm, then check we don't receive BCCH
2812 * anymore because scheduler has stopped after ramping down */
2813 f_sleep(2.0);
2814 L1CTL.clear;
2815 timer Tlocked := 2.0;
2816 Tlocked.start;
2817 alt {
2818 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2820 log2str("Received data_ind during rf_locked: ", l1_dl));
2821 }
2822 [] L1CTL.receive { repeat; }
2823 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2824 }
2825
2826 log("ADM STATE LOCKED->UNLOCKED");
2827 f_vty_transceive(BSCVTY, "rf_locked 0");
2828 f_verify_ramp_up();
2829 setverdict(pass);
2830}
2831testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2832 var ConnHdlr vc_conn;
2833 var ConnHdlrPars pars;
2834 f_init();
2835 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2836 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2837 pcu_comp := false, trxc_comp := true);
2838 vc_conn.done;
2839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2840}
2841
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002842private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002843 timer T := 8.0;
2844 T.start;
2845 var RSL_Message rsl;
2846 alt {
2847 [] as_l1_sacch();
2848 [] L1CTL.receive { repeat; }
2849 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2850 if (rsl.ies[3].body.bs_power.power_level == level) {
2851 setverdict(pass)
2852 } else {
2853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2854 }
2855 }
2856 [] T.timeout {
2857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2858 }
2859 }
2860}
2861
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002862/* See if the RSL MEASurement RESult contains expeced BS power level
2863 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002864private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002865 f_l1_tune(L1CTL);
2866 RSL.clear;
2867
2868 if (mp_bts_trxc_port != -1) {
2869 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2870 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2871 }
2872
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002873 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002874 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2875 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2876
2877 f_est_dchan(more_ies :={valueof(pwr)});
2878
2879 f_check_meas_bs_power_level(pwr_var);
2880
2881 f_rsl_chan_deact();
2882 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2883}
2884
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002885/* See if the RSL MEASurement RESult contains expeced BS power level
2886 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002887private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002888 f_l1_tune(L1CTL);
2889 RSL.clear;
2890
2891 if (mp_bts_trxc_port != -1) {
2892 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2893 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2894 }
2895
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002896 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002897 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2898
2899 f_est_dchan();
2900
2901 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2902
2903 f_check_meas_bs_power_level(pwr_var);
2904
2905 f_rsl_chan_deact();
2906 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2907}
2908
2909testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2910 var ConnHdlr vc_conn;
2911 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002912
Eric Wildae8f2622019-06-18 17:05:11 +02002913 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002914
2915 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2916 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2917 pcu_comp := false, trxc_comp := true);
2918 vc_conn.done;
2919
Eric Wildae8f2622019-06-18 17:05:11 +02002920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2921}
2922
2923testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2924 var ConnHdlr vc_conn;
2925 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002926
Eric Wildae8f2622019-06-18 17:05:11 +02002927 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002928
2929 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2930 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2931 pcu_comp := false, trxc_comp := true);
2932 vc_conn.done;
2933
Eric Wildae8f2622019-06-18 17:05:11 +02002934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2935}
2936
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002937/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2938 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2939 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002940private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002941 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002942 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002943
2944 f_trxc_fake_rssi(rxlev2dbm(10));
2945 f_l1_tune(L1CTL);
2946 RSL.clear;
2947
2948 var RSL_IE_List addl_ies;
2949 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2950
2951 addl_ies := {
2952 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2953 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2954 };
2955
2956 /* establish with power parameters */
2957 f_est_dchan(more_ies := addl_ies);
2958
2959 /* set a high value to ensure L1 power control level increases */
2960 f_trxc_fake_rssi(rxlev2dbm(20));
2961
2962 timer T2 := 6.0;
2963 T2.start;
2964 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002965 [] as_l1_sacch_l1h(l1h) {
2966 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002967 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002968 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002969 T2.stop;
2970 }
2971 [] L1CTL.receive { repeat; }
2972 [] T2.timeout {
2973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2974 "Power Level in L1 header has not increased sufficiently");
2975 }
2976 }
2977
2978 /* set a low value to ensure L1 power control level decreases */
2979 f_trxc_fake_rssi(rxlev2dbm(0));
2980
2981 timer T4 := 6.0;
2982 T4.start;
2983 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 [] as_l1_sacch_l1h(l1h) {
2985 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002986 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002987 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002988 T4.stop;
2989 setverdict(pass, "Power level in L1 decreased/increased as expected");
2990 }
2991 [] L1CTL.receive { repeat; }
2992 [] T4.timeout {
2993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2994 "Power Level in L1 header has not decreased sufficiently");
2995 }
2996 }
2997
2998 f_rsl_chan_deact();
2999 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3000
3001}
3002
3003/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003004private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02003005 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003006 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003007
3008 /* set a low value to ensure power increases */
3009 f_trxc_fake_rssi(rxlev2dbm(10));
3010 f_l1_tune(L1CTL);
3011 RSL.clear;
3012
3013 var RSL_IE_List addl_ies;
3014 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3015
3016 addl_ies := {
3017 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3018 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3019 };
3020
3021 /* establish with power parameters */
3022 f_est_dchan(more_ies := addl_ies);
3023
3024 timer T1 := 10.0;
3025 T1.start;
3026 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003027 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003028 [] L1CTL.receive { repeat; }
3029 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003030 if (not isbound(l1h)) {
3031 setverdict(fail, "No SACCH blocks were received");
3032 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003033 setverdict(fail, "Power level in L1 header should not have changed");
3034 }
3035 }
3036 }
3037
3038 f_rsl_chan_deact();
3039 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3040
3041}
3042
3043/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003044private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003045 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003046 var uint5_t pwr_var := 15;
3047 var uint5_t pwr_max_var := f_get_max_power_from_band();
3048
3049 /* set a low value to ensure power increases */
3050 f_trxc_fake_rssi(rxlev2dbm(10));
3051 f_l1_tune(L1CTL);
3052 RSL.clear;
3053
3054 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3055 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3056
3057 /* establish with fixed power level */
3058 f_est_dchan(more_ies :={valueof(pwr)});
3059
3060 /* check our initial power level */
3061 f_wait_for_l1_power_level(pwr_var);
3062
3063 /* update power param to enable power loop
3064 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3065 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3066
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003067 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3068 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3069 * Add an extra offset to avoid race conditions: +1.92s. */
3070 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003071 T1.start;
3072 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003073 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003074 [] L1CTL.receive { repeat; }
3075 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003076 if (not isbound(l1h)) {
3077 setverdict(fail, "No SACCH blocks were received");
3078 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003079 setverdict(pass, "Power level in L1 header reduced as expected");
3080 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003081 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3082 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003083 }
3084 }
3085 }
3086
3087 f_rsl_chan_deact();
3088 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3089
3090}
3091
3092/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003093private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003094 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003095
3096 /* set a high value to ensure power decreases */
3097 f_trxc_fake_rssi(rxlev2dbm(50));
3098 f_l1_tune(L1CTL);
3099 RSL.clear;
3100
3101 var uint5_t pwr_var := 5;
3102 var uint5_t pwr_target_val := 15;
3103
3104 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3105 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3106
3107 /* establish with fixed power level */
3108 f_est_dchan(more_ies :={valueof(pwr)});
3109
3110 /* check our initial power level */
3111 f_wait_for_l1_power_level(pwr_var);
3112
3113 /* update power param to enable power loop
3114 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003115 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003116
3117 /* wait, then check that our power level was increased */
3118 timer T1 := 10.0;
3119 T1.start;
3120 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003121 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003122 [] L1CTL.receive { repeat; }
3123 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003124 if (not isbound(l1h)) {
3125 setverdict(fail, "No SACCH blocks were received");
3126 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3127 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003128 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003129 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003130 }
3131 }
3132 }
3133
3134 f_rsl_chan_deact();
3135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3136
3137}
3138
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003139/* See if the power level remains constant when MS Power Parameters IE
3140 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003141private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003142 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003143
3144 /* set a high value to ensure power decreases */
3145 f_trxc_fake_rssi(rxlev2dbm(50));
3146 f_l1_tune(L1CTL);
3147 RSL.clear;
3148
3149 var uint5_t pwr_var := 5;
3150
3151 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3152 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3153
3154 /* establish with fixed power level */
3155 f_est_dchan(more_ies :={valueof(pwr)});
3156
3157 /* check our initial power level */
3158 f_wait_for_l1_power_level(pwr_var);
3159
3160 /* wait, then check that our power level did not change */
3161 timer T1 := 10.0;
3162 T1.start;
3163 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003164 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3165 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3167 "BS power control should not be active unless we receive a power parameters IE!");
3168 }
3169 repeat;
3170 }
3171 [] L1CTL.receive { repeat; }
3172 [] T1.timeout { setverdict(pass); }
3173 }
3174
3175 f_rsl_chan_deact();
3176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3177
3178}
3179
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003180/* See if the power level remains constant when MS Power Parameters IE
3181 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003182private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003183 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003184
3185 /* set a high value to ensure power decreases */
3186 f_trxc_fake_rssi(rxlev2dbm(50));
3187 f_l1_tune(L1CTL);
3188 RSL.clear;
3189
3190 var uint5_t pwr_var := 5;
3191
3192 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3193 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3194
3195 /* establish with fixed power level */
3196 f_est_dchan(more_ies :={valueof(pwr)});
3197
3198 /* check our initial power level */
3199 f_wait_for_l1_power_level(pwr_var);
3200
3201 /* pwr control without power params IE, should NOT activate MS power control*/
3202 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3203
3204 /* wait, then check that our power level did not change */
3205 timer T1 := 10.0;
3206 T1.start;
3207 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003208 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3209 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3211 "BS power control should not be active unless we receive a power parameters IE!");
3212 }
3213 repeat;
3214 }
3215 [] L1CTL.receive { repeat; }
3216 [] T1.timeout { setverdict(pass); }
3217 }
3218
3219 f_rsl_chan_deact();
3220 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3221
3222}
3223
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003224private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003225 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003226 timer T0 := 10.0;
3227 T0.start;
3228 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003229 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3230 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3232 "Power level in L1 header != signaled (RSL) power level.");
3233 }
3234 }
3235 [] L1CTL.receive { repeat; }
3236 [] T0.timeout {
3237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3238 "Timeout waiting for initial power level");
3239 }
3240 }
3241 T0.stop;
3242}
3243
3244private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3245 var IntegerRecord min_dbm_level;
3246 var IntegerRecord max_dbm_level;
3247 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3248
3249 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3250 if (min_dbm_level[i] == level) {
3251 return true;
3252 }
3253 }
3254 return false;
3255}
3256
3257private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3258 var IntegerRecord min_dbm_level;
3259 var IntegerRecord max_dbm_level;
3260 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3261
3262 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3263 if (max_dbm_level[i] == level) {
3264 return true;
3265 }
3266 }
3267 return false;
3268}
3269
3270private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3271 var IntegerRecord min_dbm_level;
3272 var IntegerRecord max_dbm_level;
3273 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3274 return max_dbm_level[0];
3275}
3276
3277type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003278private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003279private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3280 // 45.005 4.1.1
3281 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3282 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3283 2, 1, 0};
3284 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3285 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3286 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3287 var IntegerRecord rv;
3288
3289 select(band){
3290 case (BtsBand_allGSM){
3291 rv := gsm_power;
3292 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3293 max_dbm_level := {2, 1, 0};
3294 }
3295 case("DCS1800"){
3296 rv := dcs_power;
3297 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3298 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3299 }
3300 case("PCS1900"){
3301 rv := pcs_power;
3302 min_dbm_level := {15};
3303 max_dbm_level := {30};
3304 }
Harald Welte194b6912020-10-11 21:01:55 +02003305 case else {
3306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3307 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003308 }
3309
3310 return rv;
3311}
3312
3313private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003314 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 +02003315}
3316
3317testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3318 var ConnHdlr vc_conn;
3319 var ConnHdlrPars pars;
3320 f_init();
3321 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3322 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3323 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3324 pars.bts0_band := f_vty_get_bts0_band();
3325 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3326 vc_conn.done;
3327 }
3328 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3330}
3331
3332testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3333 var ConnHdlr vc_conn;
3334 var ConnHdlrPars pars;
3335 f_init();
3336 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3337 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3338 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3339 pars.bts0_band := f_vty_get_bts0_band();
3340 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3341 vc_conn.done;
3342 }
3343 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3345}
3346
3347testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3348 var ConnHdlr vc_conn;
3349 var ConnHdlrPars pars;
3350 f_init();
3351 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3352 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3353 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3354 pars.bts0_band := f_vty_get_bts0_band();
3355 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3356 vc_conn.done;
3357 }
3358 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3360}
3361
3362testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3363 var ConnHdlr vc_conn;
3364 var ConnHdlrPars pars;
3365 f_init();
3366 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3367 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3368 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3369 pars.bts0_band := f_vty_get_bts0_band();
3370 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3371 vc_conn.done;
3372 }
3373 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3375}
3376
Eric Wild280ccb82019-06-17 11:11:52 +02003377testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3378 var ConnHdlr vc_conn;
3379 var ConnHdlrPars pars;
3380 f_init();
3381 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3382 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3383 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3384 pars.bts0_band := f_vty_get_bts0_band();
3385 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3386 vc_conn.done;
3387 }
3388 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3390}
3391
Eric Wild095024b2019-06-17 15:08:57 +02003392testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3393 var ConnHdlr vc_conn;
3394 var ConnHdlrPars pars;
3395 f_init();
3396 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3397 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3398 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3399 pars.bts0_band := f_vty_get_bts0_band();
3400 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3401 vc_conn.done;
3402 }
3403 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3405}
3406
Philipp Maier149c3922020-10-22 17:29:36 +02003407function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003408 var template RSL_IE_ChannelMode ch_mode;
3409 var ConnHdlr vc_conn;
3410 var ConnHdlrPars pars;
3411 f_init();
3412 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3413 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3414 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003415 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003416 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3417 pcu_comp := false, trxc_comp := true);
3418 vc_conn.done;
3419 }
3420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3421}
Philipp Maier149c3922020-10-22 17:29:36 +02003422
3423testcase TC_meas_res_speech_tchf() runs on test_CT {
3424 f_TC_meas_res_speech_tchf(false);
3425}
3426
3427testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3428 f_TC_meas_res_speech_tchf(true);
3429}
3430
3431function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003432 var template RSL_IE_ChannelMode ch_mode;
3433 var ConnHdlr vc_conn;
3434 var ConnHdlrPars pars;
3435 f_init();
3436 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3437 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3438 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003439 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003440 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3441 pcu_comp := false, trxc_comp := true);
3442 vc_conn.done;
3443 }
3444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3445}
Philipp Maier149c3922020-10-22 17:29:36 +02003446
3447testcase TC_meas_res_speech_tchh() runs on test_CT {
3448 f_TC_meas_res_speech_tchh(false)
3449}
3450
3451testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3452 f_TC_meas_res_speech_tchh(true)
3453}
3454
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003455testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3456 var template RSL_IE_ChannelMode ch_mode;
3457 var ConnHdlr vc_conn;
3458 var ConnHdlrPars pars;
3459 f_init();
3460 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3461 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3462 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3463 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3464 pars.l1_pars.toa256_enabled := true;
3465 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3466 pcu_comp := false, trxc_comp := true);
3467 vc_conn.done;
3468 }
3469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3470}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003471
Harald Welte70767382018-02-21 12:16:40 +01003472testcase TC_meas_res_sign_tchf() runs on test_CT {
3473 var ConnHdlr vc_conn;
3474 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003475 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003476 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003477 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003478 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003479 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3480 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003481 vc_conn.done;
3482 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003484}
3485testcase TC_meas_res_sign_tchh() runs on test_CT {
3486 var ConnHdlr vc_conn;
3487 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003488 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003489 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003490 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003491 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003492 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3493 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003494 vc_conn.done;
3495 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003497}
3498testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3499 var ConnHdlr vc_conn;
3500 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003501 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003502 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003503 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3504 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003505 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3506 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003507 vc_conn.done;
3508 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003509 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003510}
3511testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3512 var ConnHdlr vc_conn;
3513 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003514 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003515 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003516 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3517 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003518 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3519 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003520 vc_conn.done;
3521 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003523}
Harald Welte685d5982018-02-27 20:42:05 +01003524testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3525 var ConnHdlr vc_conn;
3526 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003527 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003528 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3529 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003530 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003531 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003532 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3533 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003534 vc_conn.done;
3535 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003537}
3538
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003539/* Make sure that we always get RSL MEASurement RESult messages regardless
3540 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3541private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3542 timer Texec := 8.0;
3543 timer Timpf := 2.0;
3544 timer Tmr;
3545
3546 f_l1_tune(L1CTL);
3547 RSL.clear;
3548
3549 f_est_dchan();
3550 L1CTL.clear;
3551
3552 /* Establish the main SAPI=0 link on DCCH first */
3553 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3554
3555 /* Give more time for the first RSL MEASurement RESult */
3556 Tmr.start(0.480 * 2.0);
3557 Texec.start; /* EXECution timer */
3558 Timpf.start; /* IMPFung timer */
3559
3560 alt {
3561 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3562 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3563 /* Reschedule the MEAS RES timer */
3564 Tmr.start(0.480 + 0.120);
3565 repeat;
3566 }
3567 [] RSL.receive { repeat; }
3568 [] Tmr.timeout {
3569 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3570 }
3571 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3572 [] Timpf.timeout {
3573 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3574 log("Injected SAPI=3 traffic on SACCH");
3575 Timpf.start;
3576 repeat;
3577 }
3578 /* We're good if survived so far */
3579 [] Texec.timeout {
3580 setverdict(pass);
3581 }
3582 }
3583
3584 f_rsl_chan_deact();
3585 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3586 f_rslem_unregister(0, g_chan_nr);
3587}
3588testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3589 var template RSL_IE_ChannelMode ch_mode;
3590 var template ConnHdlrPars pars;
3591 var ConnHdlr vc_conn;
3592
3593 f_init();
3594
3595 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3596 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3597
3598 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3599 vc_conn.done;
3600
3601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3602}
3603testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3604 var template RSL_IE_ChannelMode ch_mode;
3605 var template ConnHdlrPars pars;
3606 var ConnHdlr vc_conn;
3607
3608 f_init();
3609
3610 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3611 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3612
3613 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3614 vc_conn.done;
3615
3616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3617}
3618
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003619/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3620 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003621private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003622 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003623 var RSL_IE_MS_Power ms_power;
3624 var RSL_Message rsl;
3625 var uint5_t power_level := 0;
3626
3627 f_l1_tune(L1CTL);
3628 RSL.clear;
3629
3630 f_est_dchan();
3631
3632 ms_power.reserved := 0;
3633 ms_power.fpc_epc := false;
3634
3635 /* Send the first power control command. This will disable any BTS/TRX
3636 * internal power control and switch the MS (which is not in scope of
3637 * this test) to a constant power level. We start with a power level
3638 * of 0 */
3639 ms_power.power_level := power_level;
3640 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3641 RSL.send(rsl);
3642
3643 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003644 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3645 if (l1h.ms_power_lvl != power_level) {
3646 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3647 "match the signaled (RSL) power level := ", power_level);
3648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003649 }
3650
3651 /* Signal a new power level via RSL for the next turn. */
3652 if (power_level < 31) {
3653 power_level := power_level + 1;
3654 ms_power.power_level := power_level;
3655 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3656 RSL.send(rsl);
3657 repeat;
3658 }
3659
3660 }
3661
3662 /* Ignore all other blocks */
3663 [] L1CTL.receive { repeat; }
3664
3665 }
3666
3667 f_rsl_chan_deact();
3668 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3669
3670 setverdict(pass);
3671}
3672
3673testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3674 var ConnHdlr vc_conn;
3675 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003676 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003677
3678 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3679 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3680 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3681 vc_conn.done;
3682 }
3683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3684}
Harald Welte70767382018-02-21 12:16:40 +01003685
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003686/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003687TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003688private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003689 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003690 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003691
3692 f_l1_tune(L1CTL);
3693 RSL.clear;
3694
3695 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003696 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003697
3698 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3699
3700
3701 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003702 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3703 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003704 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3705 }
3706
3707 }
3708
3709 /* Ignore all other blocks */
3710 [] L1CTL.receive { repeat; }
3711
3712 }
3713
3714 f_rsl_chan_deact();
3715 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3716
3717 setverdict(pass);
3718}
3719
3720testcase TC_rsl_chan_initial_ta() runs on test_CT {
3721 var ConnHdlr vc_conn;
3722 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003723 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003724 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003725 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3726 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003727 vc_conn.done;
3728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3729}
3730
Eric Wilde57e1a62019-05-28 13:30:55 +02003731/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003732private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003733 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003734 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003735
3736 var RSL_IE_MS_Power ms_power;
3737 ms_power.reserved := 0;
3738 ms_power.fpc_epc := false;
3739 ms_power.power_level := ms_power_level;
3740
3741 f_l1_tune(L1CTL);
3742 RSL.clear;
3743
3744 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3745
3746 timer T := 1.0;
3747 T.start;
3748 alt {
3749 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003750 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3751 if (l1h.ms_power_lvl != ms_power_level) {
3752 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3753 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003754 }
3755 }
3756 /* Ignore all other blocks */
3757 [] L1CTL.receive { repeat; }
3758 [] T.timeout {
3759 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3760 }
3761 }
3762
3763 f_rsl_chan_deact();
3764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3765 setverdict(pass);
3766}
3767
3768testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3769 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3770 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3771}
3772
Harald Welte0472ab42018-03-12 15:02:26 +01003773/* 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 +01003774private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003775 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003776 RSL.clear;
3777
3778 f_est_dchan();
3779 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003780 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003781
3782 timer T := 40.0;
3783 T.start;
3784 alt {
3785 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3786 setverdict(pass)
3787 }
3788 [] RSL.receive { repeat };
3789 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003791 }
3792 }
3793 f_rsl_chan_deact();
3794}
3795testcase TC_conn_fail_crit() runs on test_CT {
3796 var ConnHdlr vc_conn;
3797 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003798 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003799 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3800 pars.t_guard := 60.0;
3801 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3802 vc_conn.done;
3803}
3804
Harald Welte93640c62018-02-25 16:59:33 +01003805/***********************************************************************
3806 * Paging
3807 ***********************************************************************/
3808
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003809private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003810 if (tmsi == 'FFFFFFFF'O) {
3811 return true;
3812 } else {
3813 return false;
3814 }
3815}
Harald Welte70767382018-02-21 12:16:40 +01003816
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003817private type record allowedFn { integer frame_nr }
3818private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3819private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3820private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3821private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3822private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3823private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3824private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3825private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3826private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003827{
3828 var integer frame_nr_51;
3829 frame_nr_51 := frame_nr mod 51
3830
3831 var allowedFn fn_check;
3832 fn_check.frame_nr := frame_nr_51;
3833
3834 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003836 return;
3837 }
3838
3839 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3840 return;
3841 }
3842 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3843 return;
3844 }
3845 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3846 return;
3847 }
3848 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3849 return;
3850 }
3851 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3852 return;
3853 }
3854 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3855 return;
3856 }
3857 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3858 return;
3859 }
3860 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3861 return;
3862 }
3863
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003865 return;
3866}
3867
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003868private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3869 inout integer num_paging_rcv_ids,
3870 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003871runs on test_CT {
3872 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003873 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003874 repeat;
3875 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003876 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003877 var octetstring without_plen :=
3878 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3879 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003880
3881 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3882
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003883 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3884 /* Ignore empty RR Paging Request (PCH filling) messages.
3885 * TODO: does it make sense to count them? */
3886 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003887 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003889 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003890 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3891 }
3892 } else if (match(rr, tr_PAGING_REQ2)) {
3893 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3894 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3895 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3896 }
3897 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3898 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3899 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003900 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003901 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3902 }
3903 } else if (match(rr, tr_PAGING_REQ3)) {
3904 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3905 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3906 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3907 }
3908 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3909 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3910 }
3911 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3912 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3913 }
3914 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3915 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3916 }
3917 }
3918 repeat;
3919 }
3920}
3921
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003922private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003923 boolean combined_ccch,
3924 integer bs_ag_blks_res,
3925 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003926 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3927 * paging command that is issued via RSL. */
3928 integer ps_load_modulus,
3929 /* Wait until the paging queue inside the BTS is congested before starting to add
3930 * pagings via the PCU socket (0 = disabled) */
3931 boolean ps_wait_cong,
3932 /* Maximum time to wait until the paging queue is drained at the end of the test.
3933 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3934 * to set this value to 18s, however the draining process may take significantly
3935 * longer when the queue contains paging requests for PS as those are implemented
3936 * as immediate assignments and require an entire MAC block alone. */
3937 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003938 boolean exp_load_ind,
3939 boolean exp_overload,
3940 boolean use_tmsi
3941}
3942
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003943private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003944 integer num_paging_sent,
3945 integer num_paging_rcv_msgs,
3946 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003947 integer num_overload,
3948 /* When free space inside the paging queue reaches more than 2 thirds
3949 * of its capacity cong_detected is set to true. */
3950 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003951}
3952
Harald Welte68e495b2018-02-25 00:05:57 +01003953/* Helper function for paging related testing */
3954private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003955 /* Using the PCU socket affects the timing of the paging processing. We only
3956 * activate the PCU socket if we do paging load tests that include additional
3957 * paging load that is introduced through the PCU socket. */
3958 if (cfg.ps_load_modulus > 0) {
3959 f_init_with_pcuif();
3960 } else {
3961 f_init();
3962 }
Harald Welte68e495b2018-02-25 00:05:57 +01003963 f_init_l1ctl();
3964 f_l1_tune(L1CTL);
3965
Philipp Maierca058272021-06-23 10:35:23 +02003966 var octetstring imm_ass := f_rnd_octstring(23);
3967 var ASP_RSL_Unitdata load_ind;
3968
Harald Welte68e495b2018-02-25 00:05:57 +01003969 var PagingTestState st := {
3970 num_paging_sent := 0,
3971 num_paging_rcv_msgs := 0,
3972 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003973 num_overload := 0,
3974 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003975 };
3976
3977 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3978 var float max_pch_imsi_per_sec;
3979 if (cfg.use_tmsi) {
3980 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3981 } else {
3982 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3983 }
3984 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3985 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003986 var float time_total := 20.0;
3987 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3988 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003989
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003990 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3991 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003992
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003993 timer T_itv := 0.0;
3994 T_itv.start;
3995 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003996 alt {
3997 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003998 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003999 st.num_overload := st.num_overload + 1;
4000 repeat;
4001 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004002 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01004004 }
Philipp Maierca058272021-06-23 10:35:23 +02004005 [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 +01004006 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02004007
4008 /* Detect paging congestion: The logic inside the BTS will diagnose the
4009 * paging queue as congested when the fill state is more than 66% (which
4010 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4011 * paging congestion is detected pagings that are issued through the PCU
4012 * socket (PS) are dropped in order to prefer the CS related pagings. */
4013 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4014 st.cong_detected := true;
4015 }
4016
Harald Welte68e495b2018-02-25 00:05:57 +01004017 /* FIXME: analyze/verify interval + contents */
4018 repeat;
4019 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004020 /* ignore other RSL messages like RF RESource INDication */
4021 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004022 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004023 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004024 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004025 /* Only relevant when testing including with PCU sock connected */
4026 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004027 [] T_itv.timeout {
4028 /* Send paging cmds based on elapsed time */
4029 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4030 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004031 var MobileIdentityV mi;
4032
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004033 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004034 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004035 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004036 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004037 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004038 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004039
4040 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004041 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 +02004042
Philipp Maierca058272021-06-23 10:35:23 +02004043 /* Add additional pagings through the PCU socket interface. */
4044 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4045 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4046 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4047 }
4048 }
4049
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004050 st.num_paging_sent := st.num_paging_sent + 1;
4051 }
4052 if (st.num_paging_sent < pkt_total) {
4053 /* Wait for interval to next PAGING COMMAND */
4054 var float time_now := T_total.read;
4055 var float next_sched := int2float(st.num_paging_sent)*interval;
4056 if (next_sched > time_now) {
4057 T_itv.start(next_sched - time_now);
4058 } else {
4059 T_itv.start(0.0);
4060 }
4061 } else {
4062 /* We are done, no need to keep counting */
4063 T_total.stop;
4064 }
4065 }
4066 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004067 }
4068 }
4069
Philipp Maierca058272021-06-23 10:35:23 +02004070 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004071 T_wait.start;
4072 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004073 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004074 [] L1CTL.receive { repeat; }
4075 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004076 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004077 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004078 /* ignore other RSL messages like RF RESource INDication */
4079 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004080 /* Only relevant when testing including with PCU sock connected */
4081 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004082 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004083 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 +01004084 }
Harald Welte68e495b2018-02-25 00:05:57 +01004085 }
4086
4087 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4088 " rcvd_ids=", st.num_paging_rcv_ids);
4089 return st;
4090}
4091
4092/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4093 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4094 * - that CCCH LOAD IND (PCH) are being generated
4095 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4096testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004097 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004098 var PagingTestCfg cfg := {
4099 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004100 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004101 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004102 ps_load_modulus := 0,
4103 ps_wait_cong := false,
4104 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004105 exp_load_ind := true,
4106 exp_overload := false,
4107 use_tmsi := false
4108 };
4109 var PagingTestState st := f_TC_paging(cfg);
4110 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4112 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004113 } else {
4114 setverdict(pass);
4115 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004117}
4118
4119/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4120 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4121 * - that CCCH LOAD IND (PCH) are being generated
4122 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4123testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004124 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004125 var PagingTestCfg cfg := {
4126 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004127 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004128 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004129 ps_load_modulus := 0,
4130 ps_wait_cong := false,
4131 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004132 exp_load_ind := true,
4133 exp_overload := false,
4134 use_tmsi := true
4135 };
4136 var PagingTestState st := f_TC_paging(cfg);
4137 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4139 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004140 } else {
4141 setverdict(pass);
4142 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004144}
4145
4146/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4147 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4148 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4149 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4150testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004151 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004152 var PagingTestCfg cfg := {
4153 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004154 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004155 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004156 ps_load_modulus := 0,
4157 ps_wait_cong := false,
4158 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004159 exp_load_ind := true,
4160 exp_overload := true,
4161 use_tmsi := false
4162 };
4163 var PagingTestState st := f_TC_paging(cfg);
4164 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4165 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004166 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004167 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004168 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 +01004169 } else {
4170 setverdict(pass);
4171 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004173}
4174
4175/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4176 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4177 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4178 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4179testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004180 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004181 var PagingTestCfg cfg := {
4182 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004183 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004184 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004185 ps_load_modulus := 0,
4186 ps_wait_cong := false,
4187 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004188 exp_load_ind := true,
4189 exp_overload := true,
4190 use_tmsi := true
4191 };
4192 var PagingTestState st := f_TC_paging(cfg);
4193 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4194 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004195 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004196 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004197 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 +01004198 } else {
4199 setverdict(pass);
4200 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004202}
4203
Philipp Maierca058272021-06-23 10:35:23 +02004204/* Same as above, but with additional paging load created by PS pagings that
4205 * are issued through the PCU socket. The additional load is introduced when
4206 * the paging queue is already two thirds full. Since the BTS implements a
4207 * prioritization logic that drops the pagings from the PCU under in those
4208 * congestive sitautions the behaviour on the PS side is expected to be
4209 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4210testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4211 var SystemInformation si3 := valueof(ts_SI3_default);
4212 var PagingTestCfg cfg := {
4213 combined_ccch := true,
4214 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4215 load_factor := 2.0,
4216 ps_load_modulus := 16,
4217 ps_wait_cong := true,
4218 queue_drain_timeout := 18.0,
4219 exp_load_ind := true,
4220 exp_overload := true,
4221 use_tmsi := false
4222 };
4223 var PagingTestState st := f_TC_paging(cfg);
4224 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4225 * slots and will fully drain that buffer before returning */
4226 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4227 if (not match(st.num_paging_rcv_ids, tpl)) {
4228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4229 } else {
4230 setverdict(pass);
4231 }
4232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4233}
4234
4235
Harald Welte68e495b2018-02-25 00:05:57 +01004236
Harald Welte93640c62018-02-25 16:59:33 +01004237/***********************************************************************
4238 * Immediate Assignment / AGCH
4239 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004240private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004241 len := 0,
4242 ma := ''B
4243}
Harald Welte93640c62018-02-25 16:59:33 +01004244
Harald Weltee8d750e2018-06-10 21:41:35 +02004245private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4246 return int2str(num_tx) & " sent, "
4247 & int2str(num_rx) & " received, "
4248 & int2str(num_del) & " deleted";
4249}
4250
4251private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4252 var L1ctlDlMessage l1_dl;
4253 timer T := 10.0;
4254 var integer num_tx := 0;
4255 var integer num_rx := 0;
4256 var integer num_del := 0;
4257 var charstring res_str;
4258 var float rx_ratio;
4259
Harald Welte10474062019-05-30 16:48:17 +02004260 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004261 f_init_l1ctl();
4262 f_l1_tune(L1CTL);
4263
4264 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004265 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004266 mp_trx_pars[0].arfcn,
4267 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004268 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4269 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004270 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004271 num_tx := num_tx+1;
4272 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004273 }
4274 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004275 T.start;
4276 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004277 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004278 num_del := num_del+1;
4279 repeat;
4280 }
4281 [] RSL_CCHAN.receive {
4282 repeat;
4283 }
4284 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004285 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4286 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4287 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004288 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004289 } else {
4290 num_rx := num_rx+1;
4291 }
4292 repeat;
4293 }
4294 [] L1CTL.receive { repeat; }
4295 [] T.timeout { }
4296 }
4297 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4298 log("AGCH test: " & res_str);
4299 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004301 }
4302 rx_ratio := int2float(num_rx) / int2float(num_tx);
4303 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004304 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 +02004305 } else {
4306 setverdict(pass);
4307 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004309}
4310
Harald Weltee8d750e2018-06-10 21:41:35 +02004311/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4312testcase TC_imm_ass_1000_20ms() runs on test_CT {
4313 f_TC_imm_ass(1000, 0.02, 0.25);
4314}
4315
4316/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4317testcase TC_imm_ass_200_0ms() runs on test_CT {
4318 f_TC_imm_ass(200, 0.0, 0.05);
4319}
4320
4321/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4322testcase TC_imm_ass_200_76ms() runs on test_CT {
4323 f_TC_imm_ass(150, 0.076, 1.00);
4324}
4325
4326
4327
Harald Welte48494ca2018-02-25 16:59:50 +01004328/***********************************************************************
4329 * BCCH
4330 ***********************************************************************/
4331
4332/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004333private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004334 GsmFrameNumber frame_number,
4335 SystemInformation si
4336}
4337
4338/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004339private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004340
4341/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004342private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004343
4344/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004345private function f_si_vecslot_contains(SystemInformationVector arr,
4346 RrMessageType key,
4347 boolean bcch_ext := false)
4348return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004349 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4350 var integer fn_mod51 := arr[i].frame_number mod 51;
4351 if (not bcch_ext and fn_mod51 == 2 or
4352 bcch_ext and fn_mod51 == 6) {
4353 if (arr[i].si.header.message_type == key) {
4354 return true;
4355 }
4356 }
4357 }
4358 return false;
4359}
4360
4361/* 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 +07004362private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4363 integer tc, RrMessageType key,
4364 boolean ext_bcch := false)
4365{
Harald Welte48494ca2018-02-25 16:59:50 +01004366 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004368 }
4369}
4370
4371/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004372private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4373 RrMessageType key)
4374return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004375 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4376 if (f_si_vecslot_contains(arr[tc], key) or
4377 f_si_vecslot_contains(arr[tc], key, true)) {
4378 return true;
4379 }
4380 }
4381 return false;
4382}
4383
4384/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004385private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4386 RrMessageType key,
4387 boolean bcch_ext := false,
4388 integer n := 1, integer m := 4)
4389return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004390 var integer count := 0;
4391 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4393 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004394 }
4395 for (var integer i:= 0; i < m; i := i + 1) {
4396 var integer fn_mod51 := arr[i].frame_number mod 51;
4397 if (not bcch_ext and fn_mod51 == 2 or
4398 bcch_ext and fn_mod51 == 6) {
4399 if (arr[i].si.header.message_type == key) {
4400 count := count + 1;
4401 }
4402 }
4403 }
4404 if (count >= n) {
4405 return true;
4406 } else {
4407 return false;
4408 }
4409}
4410
4411/* 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 +07004412private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4413 integer tc, RrMessageType key,
4414 boolean ext_bcch := false,
4415 integer n, integer m)
4416{
Harald Welte48494ca2018-02-25 16:59:50 +01004417 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004419 }
4420}
4421
4422/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004423private function f_si_vecslot_contains_only(SystemInformationVector arr,
4424 RrMessageType key,
4425 boolean bcch_ext := false)
4426return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004427 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4428 var integer fn_mod51 := arr[i].frame_number mod 51;
4429 if (not bcch_ext and fn_mod51 == 2 or
4430 bcch_ext and fn_mod51 == 6) {
4431 if (arr[i].si.header.message_type != key) {
4432 return false;
4433 }
4434 }
4435 }
4436 return true;
4437}
4438
4439/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004440private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4441 integer tc, RrMessageType key,
4442 boolean ext_bcch := false)
4443{
Harald Welte48494ca2018-02-25 16:59:50 +01004444 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004446 }
4447}
4448
4449/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004450private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004451 boolean bcch_extended,
4452 boolean si1_present,
4453 boolean si2bis_present,
4454 boolean si2ter_present,
4455 boolean si2quater_present,
4456 boolean si7_present,
4457 boolean si8_present,
4458 boolean si9_present,
4459 boolean si13_present,
4460 boolean si13alt_present,
4461 boolean si15_present,
4462 boolean si16_present,
4463 boolean si17_present,
4464 boolean si2n_present,
4465 boolean si21_present,
4466 boolean si22_present
4467}
4468
4469/* 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 +07004470private function f_validate_si_scheduling(SystemInformationConfig cfg,
4471 SystemInformationVectorPerTc si_per_tc)
4472{
Harald Welte48494ca2018-02-25 16:59:50 +01004473 var integer i;
4474 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4475 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004477 }
4478 }
4479 if (cfg.si1_present) {
4480 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4481 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4482 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4483 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4484 /* make sure *ALL* contain SI1 */
4485 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4486 }
4487 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4488 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4489 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4490 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4491 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4492 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4493
4494 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4495 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4496 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4497 * consecutive occurrences of TC = 4. */
4498 if (cfg.si2bis_present and not cfg.si2ter_present) {
4499 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4500 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4501 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4502 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4503 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4504 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4505 }
4506
4507 if (cfg.si7_present or cfg.si8_present) {
4508 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4509 * if System Information type 4 does not contain all information needed for cell
4510 * selection and reselection. */
4511 if (not cfg.bcch_extended) {
4512 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4513 }
4514 if (cfg.si7_present) {
4515 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4516 }
4517 if (cfg.si8_present) {
4518 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4519 }
4520 }
4521
4522 if (cfg.si2quater_present) {
4523 /* iii) System information type 2 quater is sent if needed, as determined by the system
4524 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4525 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4526 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4527 * within any of 4 consecutive occurrences of TC = 5. */
4528 if (not (cfg.bcch_extended)) {
4529 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4530 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4531 } else {
4532 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4533 }
4534 } else {
4535 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4536 }
4537 }
4538 if (cfg.si9_present) {
4539 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4540 * in system information type 3 as defined in 3GPP TS 44.018. */
4541 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4542 }
4543 if (cfg.si13_present) {
4544 /* vii) System Information type 13 is only related to the GPRS service. System Information
4545 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4546 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4547 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4548 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4549 * within any of 4 consecutive occurrences of TC=4. */
4550 if (not cfg.bcch_extended) {
4551 log("not-bccch-extended");
4552 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4553 } else {
4554 log("bccch-extended");
4555 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4556 }
4557 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004559 }
4560 }
4561 if (cfg.si16_present or cfg.si17_present) {
4562 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4563 * should not be sent in a cell where network sharing is used (see rule xv). */
4564 if (cfg.si22_present) {
4565 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4566 }
4567 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004569 }
4570 if (not cfg.bcch_extended) {
4571 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4572 }
4573 if (cfg.si16_present) {
4574 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4575 }
4576 if (cfg.si17_present) {
4577 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4578 }
4579 }
4580
4581 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4582 * broadcast information. The frequency with which they are sent is determined by the
4583 * system operator. System Information type 9 identifies the scheduling of System
4584 * Information type 18 and 20 messages. */
4585
4586 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4587 * Information Type 19 is present, then its scheduling shall be indicated in System
4588 * Information Type 9. */
4589
4590 if (cfg.si15_present) {
4591 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4592 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4593 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4594 * 4 consecutive occurrences of TC = 1. */
4595 if (not cfg.bcch_extended) {
4596 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4597 } else {
4598 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4599 }
4600 }
4601 if (cfg.si13alt_present) {
4602 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4603 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4604 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4605 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4606 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4607 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4608 * of TC = 4. */
4609 if (cfg.si13_present) {
4610 testcase.stop("Error: Cannot have SI13alt and SI13");
4611 }
4612 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004614 }
4615 if (not cfg.bcch_extended) {
4616 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4617 } else {
4618 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4619 }
4620 }
4621 if (cfg.si2n_present) {
4622 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4623 * as determined by the system operator. In the case that the message is sent on the
4624 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4625 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4626 * consecutive occurrences of TC = 4. */
4627 if (not cfg.bcch_extended) {
4628 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4629 } else {
4630 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4631 }
4632 }
4633 if (cfg.si21_present) {
4634 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4635 * determined by the system operator. If Extended Access Barring is in use in the cell
4636 * then this message is sent at least once within any of 4 consecutive occurrences of
4637 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4638 * cell then this message shall only be sent on BCCH Ext. */
4639 if (not cfg.bcch_extended) {
4640 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4641 } else {
4642 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4643 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004645 }
4646 }
4647 }
4648 if (cfg.si22_present) {
4649 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4650 * should not be sent in a cell where SoLSA is used (see rule viii). System
4651 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4652 * =2 and TC=6. */
4653 if (cfg.si16_present or cfg.si17_present) {
4654 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4655 }
4656 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4657 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004659 }
4660 if (not cfg.bcch_extended) {
4661 testcase.stop("Error: SI22 requires BCCH Extd!");
4662 } else {
4663 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4664 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4665 }
4666 }
4667}
4668
4669/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004670private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4671return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004672 timer T := duration;
4673 var SystemInformationVectorPerTc si_per_tc;
4674 var L1ctlDlMessage l1_dl;
4675
4676 /* initialize all per-TC vectors empty */
4677 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4678 si_per_tc[i] := {};
4679 }
4680
4681 /* flush all previous L1 queued msgs */
4682 pt.clear;
4683
4684 T.start;
4685 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004686 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004687 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4688 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4689 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004690 repeat;
4691 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004692
Harald Welte48494ca2018-02-25 16:59:50 +01004693 var integer tc := f_gsm_compute_tc(sig.frame_number);
4694 log("SI received at TC=", tc, ": ", sig.si);
4695 /* append to the per-TC bucket */
4696 si_per_tc[tc] := si_per_tc[tc] & { sig };
4697 repeat;
4698 }
4699 [] pt.receive { repeat; }
4700 [] T.timeout { }
4701 }
4702
4703 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4704 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4705 }
4706 log("si_per_tc=", si_per_tc);
4707 return si_per_tc;
4708}
4709
4710/* helper function: Set given SI via RSL + validate scheduling.
4711 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004712private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004713 var SystemInformationVectorPerTc si_per_tc;
4714 f_init_l1ctl();
4715 f_l1_tune(L1CTL);
4716
4717 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004718 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004719 f_validate_si_scheduling(si_cfg, si_per_tc);
4720
4721 setverdict(pass);
4722}
4723
4724testcase TC_si_sched_default() runs on test_CT {
4725 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004726 /* 2+3+4 are mandatory and set in f_init() */
4727 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004729}
4730
4731testcase TC_si_sched_1() runs on test_CT {
4732 f_init();
4733 si_cfg.si1_present := true;
4734 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004735 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004737}
4738
4739testcase TC_si_sched_2bis() runs on test_CT {
4740 f_init();
4741 si_cfg.si2bis_present := true;
4742 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4743 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004745}
4746
4747testcase TC_si_sched_2ter() runs on test_CT {
4748 f_init();
4749 si_cfg.si2ter_present := true;
4750 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4751 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_2ter_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 si_cfg.si2ter_present := true;
4760 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4761 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004763}
4764
4765testcase TC_si_sched_2quater() runs on test_CT {
4766 f_init();
4767 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004769 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004771}
4772
4773testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004774 /* NOTE: PCUIF connection is not used in this test case, but
4775 * without it the IUT would not broadcast SI13 (see OS#3075). */
4776 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004777 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004778 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004779 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004781}
4782
4783testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004784 /* NOTE: PCUIF connection is not used in this test case, but
4785 * without it the IUT would not broadcast SI13 (see OS#3075). */
4786 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004787 si_cfg.si2bis_present := true;
4788 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4789 si_cfg.si2ter_present := true;
4790 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4791 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004792 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
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 Welte9b965d52020-10-11 21:28:22 +02004795 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004797}
4798
4799
Harald Welte68e495b2018-02-25 00:05:57 +01004800testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004801 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004802 /* FIXME: enable / disable individual BCCH info */
4803 //ts_RSL_BCCH_INFO(si_type, info);
4804 /* expect no ERROR REPORT after either of them *
4805 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004807}
4808
Harald Welte93640c62018-02-25 16:59:33 +01004809/***********************************************************************
4810 * Low-Level Protocol Errors / ERROR REPORT
4811 ***********************************************************************/
4812
Harald Welte01d982c2018-02-25 01:31:40 +01004813private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4814 timer T := 5.0;
4815 T.start;
4816 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004817 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004818 setverdict(pass);
4819 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004820 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004822 }
4823 [] RSL_CCHAN.receive {
4824 repeat;
4825 }
4826 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004828 }
4829 }
4830}
4831
4832/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4833testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004834 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004835 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4836 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004837 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004838
4839 f_exp_err_rep(RSL_ERR_PROTO);
4840}
4841
4842/* Provoke a mandatory IE error and match on ERROR REPORT */
4843testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004844 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004845
4846 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4847 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004848 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004849
4850 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4851}
4852
4853/* Provoke an IE content error and match on ERROR REPORT */
4854testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004855 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004856 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4857 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004858 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004859
4860 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4861}
4862
Harald Welteee25aae2019-05-19 14:32:37 +02004863/* attempt to activate channel with wrong RSL Message Discriminator IE */
4864function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4865 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4866 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4867 RSL.send(rsl);
4868 f_rslem_unregister(0, g_chan_nr);
4869}
4870testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4871 var ConnHdlr vc_conn;
4872 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4873
Harald Welte10474062019-05-30 16:48:17 +02004874 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004875
4876 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4877 vc_conn.done;
4878 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4879
4880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4881}
4882
4883/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004884private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004885 var template (value) RSL_Message rsl_tx;
4886 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4887 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4888 RSL.send(rsl_tx);
4889 f_rslem_unregister(0, g_chan_nr);
4890}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004891private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004892 var template (value) RSL_Message rsl_tx;
4893 /* we first have to activate the dedicated channel */
4894 f_rsl_chan_act(g_pars.chan_mode);
4895 /* ... to then send an invalid RLL message */
4896 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4897 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4898 RSL.send(rsl_tx);
4899 f_rslem_unregister(0, g_chan_nr);
4900}
4901testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4902 var ConnHdlr vc_conn;
4903 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4904 var template (value) RSL_Message rsl_tx;
4905
Harald Welte10474062019-05-30 16:48:17 +02004906 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004907
4908 /* Common Channel with wrong message type */
4909 RSL_CCHAN.clear;
4910 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4911 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004912 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004913 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4914
4915 /* TRX Management */
4916 RSL_CCHAN.clear;
4917 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4918 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004919 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004920 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4921
4922 /* Dedicated Channel */
4923 RSL_CCHAN.clear;
4924 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4925 vc_conn.done;
4926 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4927
4928 /* RLL */
4929 RSL_CCHAN.clear;
4930 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4931 vc_conn.done;
4932 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4933}
4934
4935/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004936private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004937 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4938 f_rslem_unregister(0, g_chan_nr);
4939}
4940testcase TC_err_rep_wrong_sequence() runs on test_CT {
4941 var ConnHdlr vc_conn;
4942 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4943
Harald Welte10474062019-05-30 16:48:17 +02004944 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004945
4946 RSL_CCHAN.clear;
4947 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4948 vc_conn.done;
4949 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4950}
4951
Harald Welte93640c62018-02-25 16:59:33 +01004952/***********************************************************************
4953 * IPA CRCX/MDCX/DLCS media stream handling
4954 ***********************************************************************/
4955
Harald Weltea871a382018-02-25 02:03:14 +01004956/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004957private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004958 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4959 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004960}
4961testcase TC_ipa_dlcx_not_active() runs on test_CT {
4962 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004963 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004964 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4965 vc_conn.done;
4966}
Harald Welte68e495b2018-02-25 00:05:57 +01004967
Harald Weltea3f1df92018-02-25 12:49:55 +01004968/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004969private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004970 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4971 "IPA CRCX ACK");
4972 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4973 "IPA CRCX NACK");
4974}
4975testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4976 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004977 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004978 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4979 vc_conn.done;
4980}
4981
4982/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004983private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004984 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4985 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004986 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004987 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4988 var uint7_t rtp_pt2 := f_rnd_int(127);
4989 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4990 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4991 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4992 "IPA MDCX ACK");
4993 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4994 "IPA DLCX ACK");
4995}
4996testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4997 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004998 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004999 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
5000 vc_conn.done;
5001}
5002
Harald Welte3ae11da2018-02-25 13:36:06 +01005003/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005004private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01005005 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5006 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005007 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005008 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5009 var uint7_t rtp_pt2 := f_rnd_int(127);
5010 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5011 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5012 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5013 "IPA MDCX ACK");
5014 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005015 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005016 remote_port := f_rnd_int(c_UINT16_MAX);
5017 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5018 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5019 "IPA MDCX ACK");
5020 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5021 "IPA DLCX ACK");
5022}
5023testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5024 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005025 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005026 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5027 vc_conn.done;
5028}
5029
Harald Welte9912eb52018-02-25 13:30:15 +01005030/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005031private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005032 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5033 "IPA CRCX NACK");
5034}
5035testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5036 var ConnHdlrPars pars;
5037 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005038 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005039
5040 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5041 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5042 vc_conn.done;
5043
5044 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5045 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5046 vc_conn.done;
5047}
5048
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005049/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5050private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5051 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5052 var PortNumber bind_port := 16811;
5053 var RSL_Message crcx_ack;
5054
5055 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5056 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5057 "IPA CRCX ACK");
5058 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5059 if (match(bts_bind_ip, "0.0.0.0")) {
5060 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5061 }
5062
5063 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5064 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5065 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5066 "IPA DLCX ACK");
5067}
5068testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5069 var ConnHdlrPars pars;
5070 var ConnHdlr vc_conn;
5071 f_init();
5072
5073 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5074 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5075 vc_conn.done;
5076
5077 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5078 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5079 vc_conn.done;
5080}
5081
Harald Weltea3f1df92018-02-25 12:49:55 +01005082
Harald Welte883340c2018-02-28 18:59:29 +01005083/***********************************************************************
5084 * PCU Socket related tests
5085 ***********************************************************************/
5086
Harald Welte07bd2d22019-05-25 11:03:30 +02005087/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005088friend 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 +01005089runs on test_CT {
5090 timer T := 3.0;
5091
5092 /* we don't expect any RTS.req before PDCH are active */
5093 T.start;
5094 alt {
5095 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005097 }
5098 [] PCU.receive { repeat; }
5099 [] T.timeout { }
5100 }
5101
5102 /* Send PDCH activate request for known PDCH timeslot */
5103 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5104
5105 /* we now expect RTS.req for this timeslot (only) */
5106 T.start;
5107 alt {
5108 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5109 setverdict(pass);
5110 }
5111 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5112 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005114 }
5115 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005117 }
5118 [] PCU.receive { repeat; }
5119 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005121 }
5122 [not exp_success] T.timeout {
5123 setverdict(pass);
5124 }
5125 }
5126}
5127
Harald Welte07bd2d22019-05-25 11:03:30 +02005128/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005129friend 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 +01005130runs on test_CT {
5131 timer T := 3.0;
5132
5133 /* Send PDCH activate request for known PDCH timeslot */
5134 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 +02005135 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5136 * when it will actually have been executed in the BTS */
5137 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005138 PCU.clear;
5139 /* we now expect no RTS.req for this timeslot */
5140 T.start;
5141 alt {
5142 [] 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 +02005143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005144 }
5145 [] PCU.receive { repeat; }
5146 [] T.timeout {
5147 setverdict(pass);
5148 }
5149 }
5150}
5151
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005152friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005153 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005154 map(self:PCU, system:PCU);
5155 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005156 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5157}
5158
Harald Welte883340c2018-02-28 18:59:29 +01005159/* PDCH activation via PCU socket; check for presence of RTS.req */
5160testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005161 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005162
Harald Welte883340c2018-02-28 18:59:29 +01005163 f_TC_pcu_act_req(0, 0, 7, true);
5164}
5165
5166/* PDCH activation via PCU socket on non-PDCU timeslot */
5167testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005168 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005169
Harald Welte883340c2018-02-28 18:59:29 +01005170 f_TC_pcu_act_req(0, 0, 1, false);
5171}
5172
5173/* PDCH activation via PCU socket on wrong BTS */
5174testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005175 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005176
Harald Welte883340c2018-02-28 18:59:29 +01005177 f_TC_pcu_act_req(23, 0, 7, false);
5178}
5179
5180/* PDCH activation via PCU socket on wrong TRX */
5181testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005182 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005183
Harald Welte883340c2018-02-28 18:59:29 +01005184 f_TC_pcu_act_req(0, 23, 7, false);
5185}
5186
5187/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5188testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005189 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005190
Harald Welte883340c2018-02-28 18:59:29 +01005191 /* Activate PDCH */
5192 f_TC_pcu_act_req(0, 0, 7, true);
5193 f_sleep(1.0);
5194 /* and De-Activate again */
5195 f_TC_pcu_deact_req(0, 0, 7);
5196}
5197
5198/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5199testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005200 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005201
Harald Welte883340c2018-02-28 18:59:29 +01005202 f_TC_pcu_deact_req(0, 0, 1);
5203}
5204
5205/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005206function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005207 var PCUIF_send_data sd;
5208 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005209 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005210
5211 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005212 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005213
Harald Welte883340c2018-02-28 18:59:29 +01005214 T.start;
5215 alt {
5216 [] 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 +01005217 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005218 setverdict(pass);
5219 } else {
5220 repeat;
5221 }
5222 }
5223 [] PCU.receive { repeat; }
5224 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005226 }
5227 }
5228}
5229
Philipp Maier94c08482021-02-01 17:36:05 +01005230/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5231testcase TC_pcu_ver_si1() runs on test_CT {
5232 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5233 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5234}
5235
5236/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5237testcase TC_pcu_ver_si3() runs on test_CT {
5238 const octetstring si3 := '49012223242526272929AABBCC'O;
5239 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5240}
5241
5242/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5243testcase TC_pcu_ver_si13() runs on test_CT {
5244 const octetstring si13 := '01010203040506070909'O;
5245 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5246}
5247
Harald Welte883340c2018-02-28 18:59:29 +01005248private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5249
5250/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005251friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005252 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5253runs on test_CT
5254{
5255 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5256 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5257}
5258
5259/* 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 +02005260friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5261 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005262runs on test_CT
5263{
5264 var PCUIF_send_data sd;
5265
5266 timer T := 3.0;
5267 T.start;
5268 alt {
5269 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5270 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5271 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5272 sd.data.u.rts_req.fn, sapi, data);
5273 }
5274 [] PCU.receive { repeat; }
5275 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005277 }
5278 }
5279}
5280
5281/* Send DATA.req on invalid BTS */
5282testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005283 var TfiUsfArr tua := f_TfiUsfArrInit();
5284 var octetstring data := '0000'O & f_rnd_octstring(21);
5285
5286 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005287
Harald Welte883340c2018-02-28 18:59:29 +01005288 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005289 f_TfiUsfArrSet(tua, 7, 0);
5290 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5291 f_sleep(1.0);
5292
5293 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005294}
5295
5296/* Send DATA.req on invalid TRX */
5297testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005298 var TfiUsfArr tua := f_TfiUsfArrInit();
5299 var octetstring data := '0000'O & f_rnd_octstring(21);
5300
5301 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005302
Harald Welte883340c2018-02-28 18:59:29 +01005303 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005304 f_TfiUsfArrSet(tua, 7, 0);
5305 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5306 f_sleep(1.0);
5307
5308 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005309}
5310
5311/* Send DATA.req on invalid timeslot */
5312testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005313 var TfiUsfArr tua := f_TfiUsfArrInit();
5314 var octetstring data := '0000'O & f_rnd_octstring(21);
5315
5316 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005317
Harald Welte883340c2018-02-28 18:59:29 +01005318 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005319 f_TfiUsfArrSet(tua, 7, 0);
5320 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5321 f_sleep(1.0);
5322
5323 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005324}
5325
5326/* Send DATA.req on timeslot that hasn't been activated */
5327testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005328 var TfiUsfArr tua := f_TfiUsfArrInit();
5329 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005330
Harald Welte7162a612019-05-26 12:56:09 +02005331 f_virtphy_common();
5332
5333 f_TfiUsfArrSet(tua, 7, 0);
5334 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5335 f_sleep(1.0);
5336
5337 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005338}
5339
Harald Weltead033dc2019-05-25 17:28:16 +02005340private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005341 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5342 boolean wait_rts := true)
5343runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005344 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005345 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005346
5347 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005348 if (wait_rts) {
5349 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5350 } else {
5351 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5352 }
Harald Weltead033dc2019-05-25 17:28:16 +02005353
5354 T.start;
5355 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005356 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005357 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5358 setverdict(pass);
5359 }
Harald Welte7162a612019-05-26 12:56:09 +02005360 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5361 setverdict(fail, "Received unexpected ", rx_dl);
5362 }
Harald Weltead033dc2019-05-25 17:28:16 +02005363 [] L1CTL.receive {
5364 repeat;
5365 }
Harald Welte7162a612019-05-26 12:56:09 +02005366 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005367 setverdict(fail, "Timeout waiting for ", data);
5368 }
Harald Welte7162a612019-05-26 12:56:09 +02005369 [not expect_data] T.timeout {
5370 setverdict(pass);
5371 }
Harald Weltead033dc2019-05-25 17:28:16 +02005372 }
5373}
5374
5375private function f_disable_dynamic_ts() runs on test_CT
5376{
5377 f_init_vty_bsc();
5378 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5379 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5380 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5381 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005382 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005383}
5384
5385private function f_virtphy_common() runs on test_CT {
5386 f_disable_dynamic_ts();
5387 f_init_l1ctl();
5388 f_l1_tune(L1CTL);
5389}
5390
5391testcase TC_pcu_data_req_pdtch() runs on test_CT {
5392 var TfiUsfArr tua := f_TfiUsfArrInit();
5393 var octetstring data := '0000'O & f_rnd_octstring(21);
5394
5395 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005396
Harald Welte883340c2018-02-28 18:59:29 +01005397 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005398 f_TfiUsfArrSet(tua, 7, 0);
5399 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5400 f_sleep(1.0);
5401
5402 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005403}
5404
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005405/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005406testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005407 var TfiUsfArr tua := f_TfiUsfArrInit();
5408 var octetstring data := '0000'O & f_rnd_octstring(21);
5409
5410 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005411
Harald Welte883340c2018-02-28 18:59:29 +01005412 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005413 f_TfiUsfArrSet(tua, 7, 0);
5414 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5415 f_sleep(1.0);
5416
5417 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005418}
5419
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005420private function f_TC_pcu_ptcch_ul(uint16_t ra)
5421runs on test_CT {
5422 var template PCUIF_Message pcu_rach_ind;
5423 var PCUIF_send_data sd;
5424 var GsmFrameNumber fn;
5425 timer T;
5426
5427 /* Send an Access Burst on PTCCH/U over the Um-interface */
5428 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5429 chan_nr := ts_RslChanNr_PDCH(7),
5430 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5431
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005432 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5433 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005434
5435 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5436 T.start(52.0 * 4.615 / 1000.0);
5437 alt {
5438 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5439 log("Rx an Access Burst on the PCU interface: ", sd.data);
5440 setverdict(pass);
5441 T.stop;
5442 }
5443 [] PCU.receive { repeat; }
5444 [] T.timeout {
5445 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5446 /* Keep going, that's not the end of the world */
5447 }
5448 }
5449}
5450
5451testcase TC_pcu_ptcch() runs on test_CT {
5452 var L1ctlDlMessage dl;
5453 var octetstring data;
5454 timer T;
5455
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005456 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005457 f_init_l1ctl();
5458 f_l1_tune(L1CTL);
5459
5460 /* Activate PDCH channel on TS7 */
5461 f_TC_pcu_act_req(0, 0, 7, true);
5462
5463 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005464 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005465 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005466 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005467 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005468
5469 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5470 for (var integer i := 0; i < 16; i := i + 1) {
5471 log("Sending an Access Burst towards the L1CTL interface");
5472 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5473 }
5474
5475 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5476 data := f_rnd_octstring(23);
5477
5478 /* Verify PTCCH/D: send a random data block, make sure it's received */
5479 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5480 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5481
5482 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5483 * let's give it more time in case if we miss the beginning. */
5484 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5485 alt {
5486 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5487 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5488 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5489 frame := data)) -> value dl {
5490 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5491 setverdict(pass);
5492 T.stop;
5493 }
5494 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5495 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5496 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5497 l2_data := data)) -> value dl {
5498 log("Rx PTCCH/D data block on L1CTL: ", dl);
5499 setverdict(pass);
5500 T.stop;
5501 }
5502 [] L1CTL.receive { repeat; }
5503 [] T.timeout {
5504 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5505 }
5506 }
5507}
5508
Harald Welte883340c2018-02-28 18:59:29 +01005509/* Send AGCH from PCU; check it appears on Um side */
5510testcase TC_pcu_data_req_agch() runs on test_CT {
5511 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005512 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005513 f_init_l1ctl();
5514 f_l1_tune(L1CTL);
5515
5516 f_TC_pcu_act_req(0, 0, 7, true);
5517 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5518
5519 T.start;
5520 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005521 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005522 setverdict(pass);
5523 }
5524 [] L1CTL.receive { repeat; }
5525 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005527 }
5528 }
5529}
5530
Harald Welte928622b2019-05-26 13:22:59 +02005531/* Send AGCH from PCU; check it appears on Um side */
5532testcase TC_pcu_data_req_pch() runs on test_CT {
5533 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005534 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005535 f_init_l1ctl();
5536 f_l1_tune(L1CTL);
5537
5538 f_TC_pcu_act_req(0, 0, 7, true);
5539 /* three characters prefix: last 3 digits of IMSI as ASCII */
5540 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5541
5542 T.start;
5543 alt {
5544 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5545 setverdict(pass);
5546 }
5547 [] L1CTL.receive { repeat; }
5548 [] T.timeout {
5549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5550 }
5551 }
5552}
5553
Harald Welte883340c2018-02-28 18:59:29 +01005554/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5555testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5556 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005557 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005558 f_init_l1ctl();
5559 f_l1_tune(L1CTL);
5560
5561 /* append 3 last imsi digits so BTS can compute pagng group */
5562 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5563
5564 timer T := 0.5;
5565 T.start;
5566 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005567 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005568 /* TODO: verify paging group */
5569 setverdict(pass);
5570 }
5571 [] L1CTL.receive { repeat; }
5572 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005574 }
5575 }
5576}
5577
5578/* Send RACH from Um side, expect it to show up on PCU socket */
5579testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005580 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005581 f_init_l1ctl();
5582 f_l1_tune(L1CTL);
5583
5584 var GsmFrameNumber fn_last := 0;
5585 for (var integer i := 0; i < 1000; i := i+1) {
5586 var OCT1 ra := f_rnd_ra_ps();
5587 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5588 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005590 }
5591 fn_last := fn;
5592
5593 timer T := 2.0;
5594 T.start;
5595 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005596 [] 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 +01005597 T.stop;
5598 }
5599 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005601 }
5602 [] PCU.receive { repeat; }
5603 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005605 }
5606 }
5607 }
5608 setverdict(pass);
5609}
5610
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005611/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5612 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5613testcase TC_pcu_ext_rach_content() runs on test_CT {
5614 var template PCUIF_Message pcu_rach_ind;
5615 var GsmFrameNumber fn_last := 0;
5616 var L1ctlRachSynchSeq synch_seq;
5617 var PCUIF_BurstType pcu_bt;
5618 var GsmFrameNumber fn;
5619 var BIT11 ra11;
5620
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005621 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005622 f_init_l1ctl();
5623 f_l1_tune(L1CTL);
5624
5625 for (var integer i := 0; i < 1000; i := i+1) {
5626 /* We need to test both TS1 & TS2 */
5627 if (i rem 2 == 0) {
5628 synch_seq := RACH_SYNCH_SEQ_TS1;
5629 pcu_bt := BURST_TYPE_1;
5630 } else {
5631 synch_seq := RACH_SYNCH_SEQ_TS2;
5632 pcu_bt := BURST_TYPE_2;
5633 }
5634
5635 ra11 := f_rnd_ra11_ps();
5636 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5637 if (fn == fn_last) {
5638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5639 "Two RACH in same FN?!?");
5640 }
5641 fn_last := fn;
5642
5643 /* Compose the expected message */
5644 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005645 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005646 ra := bit2int(ra11),
5647 is_11bit := 1,
5648 burst_type := pcu_bt,
5649 fn := fn);
5650
5651 timer T := 2.0;
5652 T.start;
5653 alt {
5654 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5655 T.stop;
5656 }
5657 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5659 }
5660 [] PCU.receive { repeat; }
5661 [] T.timeout {
5662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5663 }
5664 }
5665 }
5666 setverdict(pass);
5667}
5668
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005669private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5670runs on test_CT {
5671 var template PCUIF_send_data sdt;
5672 var PCUIF_send_data sd;
5673 var int16_t lqual_cb;
5674 timer T := 1.0;
5675
5676 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5677 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5678
5679 /* Send a random PDTCH frame over Um */
5680 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5681 '0000'O & f_rnd_octstring(21)));
5682
5683 T.start;
5684 alt {
5685 /* If expected link quality is above the threshold */
5686 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5687 lqual_cb := sd.data.u.data_ind.lqual_cb;
5688 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5689
5690 /* Make sure the actual link quality matches the expected value */
5691 if (not match(lqual_cb, lqual_cb_exp)) {
5692 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5693 "expected value ", lqual_cb_exp));
5694 } else {
5695 setverdict(pass);
5696 }
5697 }
5698 /* If expected link quality is below the threshold */
5699 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5701 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5702 }
5703 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5704 [] PCU.receive { repeat; }
5705 [lqual_cb_exp < thresh] T.timeout {
5706 log("Rx nothing, as expected");
5707 setverdict(pass);
5708 }
5709 [lqual_cb_exp >= thresh] T.timeout {
5710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5711 "Timeout waiting for PCUIF_DATA.ind");
5712 }
5713 }
5714}
5715
5716/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5717testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005718 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005719 PCU.clear;
5720
5721 f_init_l1ctl();
5722 f_l1_tune(L1CTL);
5723
5724 /* Activate a PDCH channel on TS7 */
5725 f_TC_pcu_act_req(0, 0, 7, true);
5726
5727 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005728 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005729 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005730 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005731 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005732
5733 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5734 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5735 var TrxcMessage ret;
5736
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005737 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005738
5739 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5740 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5741 }
5742}
5743
Harald Welte883340c2018-02-28 18:59:29 +01005744/* Send PAGING via RSL, expect it to shw up on PCU socket */
5745testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005746 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005747
5748 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005749 var MobileIdentityLV mi_lv;
5750 var octetstring mi_lv_enc;
5751 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005752 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005753
Harald Welte883340c2018-02-28 18:59:29 +01005754 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005755 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005756 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005757 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005758 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005759
5760 /* Fancy encoding for PCUIF */
5761 mi_lv := valueof(ts_MI_LV(mi));
5762 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5763 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005764
5765 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005766 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005767 T.start;
5768 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005769 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005770 }
5771 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005773 }
5774 [] PCU.receive { repeat; }
5775 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005777 }
5778 }
5779 }
5780 setverdict(pass);
5781}
5782
Harald Welted66c9b82019-05-25 09:03:15 +02005783/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5784testcase TC_pcu_time_ind() runs on test_CT {
5785 var PCUIF_send_data pcu_sd;
5786 var integer num_time_ind := 0;
5787 var integer first_fn, last_fn;
5788 var float test_duration := 5.0;
5789 timer T;
5790
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005791 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005792 f_TC_pcu_act_req(0, 0, 7, true);
5793
5794 PCU.clear;
5795 T.start(test_duration);
5796 alt {
5797 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5798 num_time_ind := num_time_ind + 1;
5799 if (not isbound(first_fn)) {
5800 first_fn := pcu_sd.data.u.time_ind.fn;
5801 }
5802 last_fn := pcu_sd.data.u.time_ind.fn;
5803 repeat;
5804 }
5805 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5806 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5807 repeat;
5808 }
5809 [] PCU.receive {
5810 repeat;
5811 }
5812 [] T.timeout {}
5813 }
5814 var integer fn_expired := last_fn - first_fn;
5815 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5816
5817 /* verify the number of frames expired matches our expectation */
5818 const float c_GSM_FN_DURATION_MS := 4.61538;
5819 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005820 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005821 if (not match(fn_expired, t_fn_expected)) {
5822 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5823 }
5824
5825 /* There are three TIME.ind in every fn MOD 13 */
5826 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5827 /* Add some tolerance */
5828 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5829 if (not match(num_time_ind, t_time_ind_exp)) {
5830 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5831 }
5832
5833 setverdict(pass);
5834}
5835
Harald Welte4832c862019-05-25 14:57:18 +02005836/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5837testcase TC_pcu_rts_req() runs on test_CT {
5838 var PCUIF_send_data pcu_sd;
5839 var integer first_fn, last_fn;
5840 var integer num_rts_pdtch := 0;
5841 var integer num_rts_ptcch := 0;
5842 var float test_duration := 5.0;
5843 timer T;
5844
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005845 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005846 f_TC_pcu_act_req(0, 0, 7, true);
5847
5848 PCU.clear;
5849 T.start(test_duration);
5850 alt {
5851 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5852 -> value pcu_sd {
5853 num_rts_pdtch := num_rts_pdtch + 1;
5854 if (not isbound(first_fn)) {
5855 first_fn := pcu_sd.data.u.rts_req.fn;
5856 }
5857 last_fn := pcu_sd.data.u.rts_req.fn;
5858 repeat;
5859 }
5860 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5861 -> value pcu_sd {
5862 num_rts_ptcch := num_rts_ptcch + 1;
5863 if (not isbound(first_fn)) {
5864 first_fn := pcu_sd.data.u.rts_req.fn;
5865 }
5866 last_fn := pcu_sd.data.u.rts_req.fn;
5867 repeat;
5868 }
5869 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5870 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5871 repeat;
5872 }
5873 [] PCU.receive {
5874 repeat;
5875 }
5876 [] T.timeout {}
5877 }
5878 var integer fn_expired := last_fn - first_fn;
5879 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5880 ", num_rts_ptcch=", num_rts_ptcch);
5881
5882 /* verify the number of frames expired matches our expectation */
5883 const float c_GSM_FN_DURATION_MS := 4.61538;
5884 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005885 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005886 if (not match(fn_expired, t_fn_expected)) {
5887 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5888 }
5889
5890 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5891 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5892 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5893 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5894 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5895 t_ptcch_exp);
5896 }
5897
5898 /* We have 12 PDTCH blocks every 52-multiframe */
5899 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5900 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5901 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5902 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5903 t_pdtch_exp);
5904 }
5905
5906 setverdict(pass);
5907}
5908
Harald Welte07bd2d22019-05-25 11:03:30 +02005909/* test for generating Abis side OML ALERT from the PCU */
5910testcase TC_pcu_oml_alert() runs on test_CT {
5911 var PCUIF_send_data pcu_sd;
5912 var integer num_time_ind := 0;
5913 var integer first_fn, last_fn;
5914 var float test_duration := 5.0;
5915 timer T;
5916
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005917 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005918 f_TC_pcu_act_req(0, 0, 7, true);
5919
5920 /* re-connect CTRL port from BTS to BSC */
5921 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005922 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005923
5924 /* Send that OML Alert */
5925 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5926
5927 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5928 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5929 setverdict(pass);
5930}
5931
Harald Welteeaa9a862019-05-26 23:01:08 +02005932/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5933private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5934 var PCUIF_Message first_info;
5935 var integer pcu_conn_id := -1;
5936 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5937 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5938 var OCT4 tlli := '01020304'O;
5939 var OCT1 cause := '23'O;
5940 timer T := 5.0;
5941
5942 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5943
5944 f_l1_tune(L1CTL);
5945 RSL.clear;
5946
5947 f_est_dchan();
5948 L1CTL.clear;
5949
5950 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5951
5952 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5953 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5954 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5955
5956 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5957 T.start;
5958 alt {
5959 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5960 setverdict(pass);
5961 }
5962 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5963 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5964 }
5965 [] PCU.receive {
5966 repeat;
5967 }
5968 [] T.timeout {
5969 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5970 }
5971 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005972
5973 /* release the channel */
5974 f_rsl_chan_deact();
5975 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5976 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005977}
5978testcase TC_pcu_rr_suspend() runs on test_CT {
5979 var ConnHdlrPars pars;
5980 var ConnHdlr vc_conn;
5981
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005982 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005983
5984 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5985 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5986 vc_conn.done;
5987}
Harald Welte07bd2d22019-05-25 11:03:30 +02005988
Harald Weltea2e0e942019-05-27 18:12:53 +02005989/* Ensure that PCUIF socket can accept only a single connection */
5990testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005991 var boolean connected := false;
5992 var UD_connect_result cr;
5993 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005994 timer T := 5.0;
5995
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005996 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5997 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5998
Harald Weltea2e0e942019-05-27 18:12:53 +02005999 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006000 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02006001
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006002 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02006003 PCU.send(UD_connect:{mp_pcu_socket, -1});
6004 T.start;
6005 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006006 /* the IUT will first accept() the new connection, and close() it immediately */
6007 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
6008 log("BTS has accept()ed connection");
6009 connected := true;
6010 cid := cr.id;
6011 repeat;
6012 }
6013 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6014 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006015 setverdict(pass);
6016 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006017 /* ignore other messages related to the first connection */
6018 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006019 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006020 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006021 }
6022 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006023
Harald Weltea2e0e942019-05-27 18:12:53 +02006024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6025}
6026
Harald Weltec8effb72019-05-27 18:23:04 +02006027/* Ensure that PCUIF socket can disconnect + reconnect */
6028testcase TC_pcu_socket_reconnect() runs on test_CT {
6029 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006030 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006031
6032 f_sleep(1.0);
6033
6034 f_pcuif_close(PCU, g_pcu_conn_id);
6035 g_pcu_conn_id := -1;
6036
6037 f_sleep(1.0);
6038
6039 /* re-connect */
6040 PCU.clear;
6041 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6042 setverdict(pass);
6043
6044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6045}
6046
Harald Weltebe030482019-05-27 22:29:35 +02006047/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006048private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6049runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006050 var L1ctlDlMessage l1_dl;
6051 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006052 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006053 timer T := 5.0;
6054 T.start;
6055 alt {
6056 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006057 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6058 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006059 repeat;
6060 }
6061 }
6062 [] pt.receive {
6063 repeat;
6064 }
6065 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6067 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006068 }
6069 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006070 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006071}
6072
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006073/* Check if GPRS Indicator is present in RR System Information of a given type */
6074private function f_si_has_gprs_indicator(RrMessageType si_type)
6075runs on test_CT return boolean {
6076 var SystemInformation si := f_get_si(L1CTL, si_type);
6077
6078 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006079 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006080 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006081 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006082 }
6083
6084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6085 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006086}
6087
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006088/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6089private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6090runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006091 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006092 f_init_l1ctl();
6093 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006094 f_sleep(2.0);
6095 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006096
6097 if (f_si_has_gprs_indicator(si_type)) {
6098 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006099 } else {
6100 setverdict(pass);
6101 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006102
Harald Weltebe030482019-05-27 22:29:35 +02006103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6104}
6105
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006106testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6107 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6108}
Harald Weltebe030482019-05-27 22:29:35 +02006109
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006110testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6111 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6112}
6113
6114/* Ensure that GPRS capability is advertised after PCU socket connect */
6115private function f_TC_pcu_socket_connect(RrMessageType si_type)
6116runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006117 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006118 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006119 f_init_l1ctl();
6120 f_l1_tune(L1CTL);
6121
6122 f_sleep(2.0);
6123 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006124
6125 if (not f_si_has_gprs_indicator(si_type)) {
6126 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006127 } else {
6128 setverdict(pass);
6129 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006130
Harald Weltebe030482019-05-27 22:29:35 +02006131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6132}
6133
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006134testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6135 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6136}
Harald Weltebe030482019-05-27 22:29:35 +02006137
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006138testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6139 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6140}
6141
6142/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6143private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6144runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006145 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006146 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006147 f_init_l1ctl();
6148 f_l1_tune(L1CTL);
6149
6150 f_pcuif_close(PCU, g_pcu_conn_id);
6151 g_pcu_conn_id := -1;
6152
6153 f_sleep(1.0);
6154
6155 /* re-connect */
6156 PCU.clear;
6157 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6158
6159 f_sleep(2.0);
6160 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006161
6162 if (f_si_has_gprs_indicator(si_type)) {
6163 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006164 } else {
6165 setverdict(pass);
6166 }
6167
6168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6169}
6170
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006171testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6172 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6173}
6174
6175testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6176 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6177}
6178
Oliver Smithf5239c72019-08-28 10:01:25 +02006179/* 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) */
6180testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6181 var SystemInformation si3 := valueof(ts_SI3_default);
6182
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006183 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006184
Harald Welte76220222020-10-11 20:32:44 +02006185 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6186 * information */
6187 timer T := 2.0;
6188 T.start;
6189 alt {
6190 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6191 [] T.timeout {}
6192 }
6193
Oliver Smithf5239c72019-08-28 10:01:25 +02006194 /* Verify cell_id */
6195 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6196 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6197 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006198 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6199 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6200 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006201 }
6202
6203 /* Verify LAC */
6204 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6205 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6206 if (lac_si3 != lac_pcu) {
6207 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6208 }
6209
6210 setverdict(pass);
6211}
Harald Welted66c9b82019-05-25 09:03:15 +02006212
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006213/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6214testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6215 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006216 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006217
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006218 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006219
6220 info_ind := g_pcu_last_info.u.info_ind;
6221
6222 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6223 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006224 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006225 /* Skip inactive timeslots */
6226 continue;
6227 }
6228
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006229 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006230 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006231 else
6232 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006233
6234 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006235 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006236 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006237 hsn := fhp.maio_hsn.hsn,
6238 maio := fhp.maio_hsn.maio,
6239 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006240 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006241 } else {
6242 tr_ts := tr_PCUIF_InfoTrxTsH0;
6243 }
6244
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006245 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006246 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6247 if (not match(ts, tr_ts)) {
6248 setverdict(fail, "Hopping parameters do not match: ",
6249 "received ", ts, " vs expected ", tr_ts);
6250 } else {
6251 setverdict(pass);
6252 }
6253 }
6254 }
6255}
6256
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006257/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006258testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6259 f_init_vty_bsc();
6260 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6261 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6262
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006263 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006264
6265 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006266 var template PCUIF_RemoteAddr tr_remote_addr := {
6267 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006268 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006269 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006270
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006271 if (not match(remote_addr, tr_remote_addr)) {
6272 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006273 }
6274
6275 setverdict(pass);
6276}
6277
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006278/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006279testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6280 f_init_vty_bsc();
6281 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6282
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006283 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006284
6285 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006286 var template PCUIF_RemoteAddr tr_remote_addr := {
6287 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6288 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6289 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006290
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006291 if (not match(remote_addr, tr_remote_addr)) {
6292 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006293 }
6294
6295 setverdict(pass);
6296}
6297
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006298/* Verify coding of two NSVCs in the INFO.ind message */
6299testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6300 f_init_vty_bsc();
6301
6302 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6303 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6304 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6305 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6306
6307 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6308 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6309 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6310 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6311
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006312 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006313
6314 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6315 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6316 var template PCUIF_RemoteAddr tr_remote_addr := {
6317 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006318 addr := {
6319 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6320 f_inet6_addr("fd00::ca:ff:ee")
6321 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006322 };
6323
6324 if (not match(info_ind.nsvci, { 1234, 5678 }))
6325 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6326 if (not match(remote_addr, tr_remote_addr))
6327 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6328 if (not match(info_ind.local_port, { 1234, 5678 }))
6329 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6330 if (not match(info_ind.remote_port, { 1234, 5678 }))
6331 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6332
6333 setverdict(pass);
6334}
6335
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006336/* Verify periodic interference reports on PDCH */
6337testcase TC_pcu_interf_ind() runs on test_CT {
6338 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006339 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006340 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006341 var PCUIF_send_data sd;
6342 timer T;
6343
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006344 /* Set the averaging/reporting period to 480ms */
6345 f_init_vty_bsc();
6346 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6347 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6348
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006349 f_init_with_pcuif();
6350 f_TC_pcu_act_req(0, 0, 7, true);
6351
6352 /* We need trxcon for NOPE indications */
6353 f_init_l1ctl();
6354 f_l1_tune(L1CTL);
6355
6356 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006357 tr_interf_ind := tr_PCUIF_INTERF_IND(
6358 bts_nr := 0,
6359 trx_nr := 0,
6360 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006361 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006362 );
6363
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006364 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006365 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006366 /* The first interference report may contain unreliable values, so we ignore it */
6367 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6368 /* 4 SACCH periods => 4 reports (plus some guard time) */
6369 T.start(0.480 * 4.0 + 0.480 / 2.0);
6370 first := false;
6371 repeat;
6372 }
6373 /* Subsequent interference reports shall match our expectations */
6374 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006375 /* Check TDMA frame number period */
6376 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6377 setverdict(fail, "Odd TDMA frame number := ",
6378 sd.data.u.interf_ind.fn);
6379 }
6380 interf_ind_num := interf_ind_num + 1;
6381 if (interf_ind_num < 4)
6382 { repeat; }
6383 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006384 [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 +02006385 setverdict(fail, "Received unexpected interference report: ", sd.data);
6386 }
6387 [] PCU.receive { repeat; }
6388 [] T.timeout {
6389 setverdict(fail, "Timeout waiting for interference reports");
6390 }
6391 }
6392
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006393 /* Reset the averaging/reporting period back to default */
6394 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6395
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6397}
6398
Harald Welte3d04ae62018-04-04 20:29:05 +02006399/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006400 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006401 ***********************************************************************/
6402
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006403private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6404 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006405runs on ConnHdlr {
6406 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006407
6408 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006409 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006410 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6411 repeat;
6412 }
6413 }
6414}
6415
6416private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6417runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006418 /* Expect BTS to immediately acknowledge activation as PDCH */
6419 PCU.clear;
6420 f_rsl_chan_act(g_pars.chan_mode);
6421 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006422 timer T_wait := 2.0;
6423 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006424 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006425 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006426 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006427 [] T_wait.timeout {
6428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6429 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6430 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006431 }
6432 /* try to activate this PDCH from the PCU point of view */
6433 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6434 /* FIXME: is there a response? */
6435}
6436
6437private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6438runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006439 /* Send RSL CHAN REL (deactivate) */
6440 PCU.clear;
6441 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6442 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006443 timer T_wait := 2.0;
6444 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006445 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006446 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006447 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006448 [] T_wait.timeout {
6449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6450 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6451 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006452 }
6453 /* Emulate PCU asking BTS to deactivate PDCH */
6454 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6455 alt {
6456 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6457 setverdict(pass);
6458 }
6459 [] RSL.receive { repeat; }
6460 }
6461}
6462
6463/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006464private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006465 var PCUIF_Message first_info;
6466 var integer ts_nr := g_chan_nr.tn;
6467 var integer trx_nr := 0;
6468 var integer bts_nr := 0;
6469 var integer pcu_conn_id := -1;
6470
6471 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6472
6473 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6474 f_sleep(3.0);
6475 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6476 setverdict(pass);
6477}
6478testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6479 var ConnHdlrPars pars;
6480 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006481 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006482
6483 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6484 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6485 vc_conn.done;
6486}
6487
6488/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006489private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006490 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006491 var integer pcu_conn_id := -1;
6492
6493 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6494
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006495 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6496 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6497 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006498 setverdict(pass);
6499}
6500testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6501 var ConnHdlrPars pars;
6502 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006503 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006504
6505 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6506 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6507 vc_conn.done;
6508}
6509
6510/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006511private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006512 var PCUIF_Message first_info;
6513 var integer ts_nr := g_chan_nr.tn;
6514 var integer trx_nr := 0;
6515 var integer bts_nr := 0;
6516 var integer pcu_conn_id := -1;
6517
6518 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6519
6520 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006521 /* Send a second Chan Activ and expect it to be NACKed */
6522 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6523 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006524 setverdict(pass);
6525}
6526testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6527 var ConnHdlrPars pars;
6528 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006529 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006530
6531 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6532 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6533 vc_conn.done;
6534}
6535
6536/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006537private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006538 var PCUIF_Message first_info;
6539 var integer ts_nr := g_chan_nr.tn;
6540 var integer trx_nr := 0;
6541 var integer bts_nr := 0;
6542 var integer pcu_conn_id := -1;
6543 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6544
6545 /* register for the TCH/F channel number */
6546 f_rslem_register(0, chan_nr);
6547
6548 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6549
6550 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6551 "RSL CHAN ACT");
6552 setverdict(pass);
6553}
6554testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6555 var ConnHdlrPars pars;
6556 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006557 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006558
6559 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6560 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6561 vc_conn.done;
6562}
6563
6564/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006565private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006566 var PCUIF_Message first_info;
6567 var integer ts_nr := g_chan_nr.tn;
6568 var integer trx_nr := 0;
6569 var integer bts_nr := 0;
6570 var integer pcu_conn_id := -1;
6571 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6572 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6573
6574 /* register for the TCH/H channel numbers */
6575 f_rslem_register(0, chan_nr[0]);
6576 f_rslem_register(0, chan_nr[1]);
6577
6578 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6579
6580 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6581 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6582 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6583 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6584 setverdict(pass);
6585}
6586testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6587 var ConnHdlrPars pars;
6588 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006589 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006590
6591 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6592 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6593 vc_conn.done;
6594}
6595
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006596/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6597private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6598 var PCUIF_Message first_info;
6599 var integer ts_nr := g_chan_nr.tn;
6600 var integer trx_nr := 0;
6601 var integer bts_nr := 0;
6602 var integer pcu_conn_id := -1;
6603 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6604 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6605 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6606 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6607 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6608 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6609 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6610 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6611
6612 /* register for the TCH/H channel numbers */
6613 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6614 f_rslem_register(0, chan_nr[i]);
6615 }
6616
6617 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6618
6619 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6620 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6621 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6622 }
6623 setverdict(pass);
6624}
6625testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6626 var ConnHdlrPars pars;
6627 var ConnHdlr vc_conn;
6628 f_init();
6629
6630 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6631 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6632 vc_conn.done;
6633}
6634
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006635/* Reproduce a race condition described in OS#5245 */
6636private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6637 f_rsl_chan_act(g_pars.chan_mode);
6638 f_sleep(1.0);
6639 f_rsl_chan_deact();
6640 setverdict(pass);
6641}
6642testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6643 var ConnHdlrPars pars[2];
6644 var ConnHdlr vc_conn[2];
6645 var TrxcMessage rsp;
6646
6647 f_init();
6648
6649 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6650 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6651 ts_TRXC_FAKE_TRXC_DELAY(200));
6652
6653 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6654 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6655 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6656 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6657 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6658 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6659 pars[i], l1ctl := false);
6660 }
6661
6662 /* Wait for all components to finish */
6663 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6664 vc_conn[i].done;
6665 }
6666
6667 /* Disable the artificial delay for TRXC RSP messages */
6668 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6669 ts_TRXC_FAKE_TRXC_DELAY(0));
6670}
6671testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6672 var ConnHdlrPars pars[8];
6673 var ConnHdlr vc_conn[8];
6674 var TrxcMessage rsp;
6675
6676 f_init();
6677
6678 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6679 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6680 ts_TRXC_FAKE_TRXC_DELAY(200));
6681
6682 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6683 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6684 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6685 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6686 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6687 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6688 pars[i], l1ctl := false);
6689 }
6690
6691 /* Wait for all components to finish */
6692 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6693 vc_conn[i].done;
6694 }
6695
6696 /* Disable the artificial delay for TRXC RSP messages */
6697 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6698 ts_TRXC_FAKE_TRXC_DELAY(0));
6699}
6700
Harald Welte9bbbfb52018-04-05 09:33:19 +02006701/***********************************************************************
6702 * IPA Style Dynamic Timeslot Support
6703 ***********************************************************************/
6704
6705private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6706runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006707 /* Expect BTS to immediately acknowledge activation as PDCH */
6708 PCU.clear;
6709 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6710 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006711 timer T_wait := 2.0;
6712 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006713 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006714 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006715 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006716 [] T_wait.timeout {
6717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6718 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6719 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006720 }
6721 /* try to activate this PDCH from the PCU point of view */
6722 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6723 /* FIXME: is there a response? */
6724
6725 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6726}
6727
6728private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6729runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006730 /* Send RSL CHAN REL (deactivate) */
6731 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6732 PCU.clear;
6733 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006734 timer T_wait := 2.0;
6735 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006736 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006737 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006738 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006739 [] T_wait.timeout {
6740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6741 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6742 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006743 }
6744 /* Emulate PCU asking BTS to deactivate PDCH */
6745 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6746 alt {
6747 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6748 setverdict(pass);
6749 }
6750 [] RSL.receive { repeat; }
6751 }
6752}
6753
6754/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006755private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006756 var PCUIF_Message first_info;
6757 var integer ts_nr := g_chan_nr.tn;
6758 var integer trx_nr := 0;
6759 var integer bts_nr := 0;
6760 var integer pcu_conn_id := -1;
6761
6762 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6763
6764 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6765 f_sleep(3.0);
6766 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6767
6768 setverdict(pass);
6769
6770}
6771testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6772 var ConnHdlrPars pars;
6773 var ConnHdlr vc_conn;
6774 f_init();
6775
6776 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6777 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6778 vc_conn.done;
6779}
6780
6781/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006782private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006783 var PCUIF_Message first_info;
6784 var integer ts_nr := g_chan_nr.tn;
6785 var integer trx_nr := 0;
6786 var integer bts_nr := 0;
6787 var integer pcu_conn_id := -1;
6788
6789 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6790
6791 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6792 "RSL CHAN ACT");
6793 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6794 "RF CHAN REL", true);
6795 setverdict(pass);
6796}
6797testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6798 var ConnHdlrPars pars;
6799 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006800 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006801
6802 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6803 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6804 vc_conn.done;
6805}
6806
6807/* 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 +07006808private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006809 var PCUIF_Message first_info;
6810 var integer ts_nr := g_chan_nr.tn;
6811 var integer trx_nr := 0;
6812 var integer bts_nr := 0;
6813 var integer pcu_conn_id := -1;
6814
6815 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6816
6817 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6818 "RSL CHAN ACT");
6819
6820 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6821 alt {
6822 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6823 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006825 }
6826 [] RSL.receive { repeat; }
6827 }
6828
6829 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6830 "RF CHAN REL", true);
6831 setverdict(pass);
6832}
6833testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6834 var ConnHdlrPars pars;
6835 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006836 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006837
6838 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6839 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6840 vc_conn.done;
6841}
6842
6843/* 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 +07006844private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006845 var PCUIF_Message first_info;
6846 var integer ts_nr := g_chan_nr.tn;
6847 var integer trx_nr := 0;
6848 var integer bts_nr := 0;
6849 var integer pcu_conn_id := -1;
6850
6851 /* register for the TCH/F channel number */
6852 f_rslem_register(0, g_chan_nr);
6853
6854 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6855
6856 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6857
6858 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6859 "RSL CHAN ACT");
6860
6861 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6862
6863 setverdict(pass);
6864}
6865testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6866 var ConnHdlrPars pars;
6867 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006868 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006869
6870 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6871 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6872 vc_conn.done;
6873}
6874
6875
Harald Welte0472ab42018-03-12 15:02:26 +01006876/***********************************************************************
6877 * LAPDm / RLL related
6878 ***********************************************************************/
6879
6880private function f_tx_lapdm(template (value) LapdmFrame l,
6881 template (value) RslLinkId link_id) runs on ConnHdlr {
6882 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006883 var template (value) SacchL1Header l1h;
6884
6885 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006886 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006887 /* Compose dummy L1 header */
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07006888 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006889 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 +02006890 } else {
6891 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006892 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 +01006893 }
Harald Welte0472ab42018-03-12 15:02:26 +01006894}
6895
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006896friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006897 uint3_t sapi,
6898 RslLinkId link_id,
6899 octetstring l3,
6900 boolean exp
6901}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006902friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006903friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6904 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006905 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006906 sapi := sapi,
6907 link_id := id,
6908 l3 := l3,
6909 exp := exp
6910}
6911
6912/* execute the same callback function with a set of different parameters (tcs) on a
6913 * variety of logical channels */
6914private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6915 var ConnHdlrPars pars;
6916 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006917 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006918
6919 /* test on each of the channels we have */
6920 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6921 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6922
6923 /* test each of the test cases on the current channel */
6924 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6925 pars.spec.rll := tcs[j];
6926 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6927 vc_conn := f_start_handler(fn, pars);
6928 vc_conn.done;
6929 }
6930 }
6931
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006933}
6934
6935/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6936private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6937 var RllTestCase tc := g_pars.spec.rll;
6938 timer T := 3.0;
6939
6940 f_l1_tune(L1CTL);
6941 RSL.clear;
6942
6943 /* activate the logical channel */
6944 f_est_dchan();
6945 L1CTL.clear;
6946
6947 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6948 T.start;
6949 alt {
6950 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6951 if (tc.exp) {
6952 setverdict(pass);
6953 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006955 }
6956 }
6957 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6958 if (tc.exp) {
6959 setverdict(pass);
6960 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006962 }
6963 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006964 /* We also expect to receive the measurements */
6965 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006966 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006968 }
6969 [not tc.exp] T.timeout {
6970 setverdict(pass);
6971 }
6972 }
6973
6974 f_rsl_chan_deact();
6975 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6976 f_rslem_unregister(0, g_chan_nr);
6977}
6978testcase TC_rll_est_ind() runs on test_CT {
6979 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006980 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006981 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006982 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006983 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006984 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006985 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6986 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006987 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006988 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006989 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006990 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006991 };
6992 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6993}
6994
6995/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6996private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6997 var RllTestCase tc := g_pars.spec.rll;
6998 var L1ctlDlMessage dl;
6999 timer T := 3.0;
7000
7001 f_l1_tune(L1CTL);
7002 RSL.clear;
7003
7004 /* activate the logical channel */
7005 f_est_dchan();
7006 L1CTL.clear;
7007
7008 /* Send a RSL EST REQ for SAPI3 on main DCCH */
7009 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
7010 T.start;
7011 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007012 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007013 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007015 }
7016 }
7017
7018 f_rsl_chan_deact();
7019 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7020 f_rslem_unregister(0, g_chan_nr);
7021}
7022testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7023 var RllTestCases tcs := {
7024 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007025 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007026 };
7027 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7028}
7029testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7030 var RllTestCases tcs := {
7031 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007032 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007033 }
7034 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7035}
7036
7037/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007038friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007039 var L1ctlDlMessage dl;
7040 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7041 var LapdmFrame lapdm;
7042 var octetstring l2 := dl.payload.data_ind.payload;
7043 if (dl.dl_info.link_id.c == SACCH) {
7044 /* remove L1 header */
7045 l2 := substr(l2, 2, lengthof(l2)-2);
7046 }
7047 if (ischosen(exp.ab)) {
7048 lapdm.ab := dec_LapdmFrameAB(l2);
7049 } else if (ischosen(exp.b4)) {
7050 lapdm.b4 := dec_LapdmFrameB4(l2);
7051 } else if (ischosen(exp.bbis)) {
7052 lapdm.bbis := dec_LapdmFrameBbis(l2);
7053 }
7054 log("Rx LAPDm ", lapdm);
7055 if (match(lapdm, exp)) {
7056 setverdict(pass);
7057 } else {
7058 repeat;
7059 }
7060 }
7061 [] L1CTL.receive { repeat; }
7062}
7063private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7064 timer T := t;
7065 T.start;
7066 alt {
7067 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007069 }
7070 [] as_l1_exp_lapdm(exp);
7071 }
7072}
7073
7074/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7075private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007076 timer T := 2.0;
Harald Welte0472ab42018-03-12 15:02:26 +01007077 /* send SABM from MS -> BTS */
7078 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7079 /* expect RLL EST IND on Abis */
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007080 T.start;
Harald Welte0472ab42018-03-12 15:02:26 +01007081 alt {
7082 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7083 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7084 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007086 }
7087 [] RSL.receive { repeat; }
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007088 [] T.timeout {
7089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RLL EST IND");
7090 }
Harald Welte0472ab42018-03-12 15:02:26 +01007091 }
7092 /* expect UA from BTS -> MS */
7093 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7094}
7095
7096/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7097private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7098 var RllTestCase tc := g_pars.spec.rll;
7099
7100 f_l1_tune(L1CTL);
7101 RSL.clear;
7102
7103 /* activate the logical channel */
7104 f_est_dchan();
7105 L1CTL.clear;
7106
7107 /* first establish the link-layer */
7108 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7109
7110 /* then send the DISC */
7111 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7112 /* ... and expect the REL IND on the RSL side */
7113 alt {
7114 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7115 setverdict(pass);
7116 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007117 /* We also expect to receive the measurements */
7118 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007119 }
7120
7121 /* release the channel */
7122 f_rsl_chan_deact();
7123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7124 f_rslem_unregister(0, g_chan_nr);
7125}
7126testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7127 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007128 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007129 };
7130 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7131}
7132
7133testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7134 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007135 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007136 };
7137 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7138}
7139testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7140 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007141 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007142 };
7143 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7144}
7145testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7146 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007147 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007148 };
7149 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7150}
7151
7152/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7153private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7154 var RllTestCase tc := g_pars.spec.rll;
7155 f_l1_tune(L1CTL);
7156 RSL.clear;
7157
7158 /* activate the logical channel */
7159 f_est_dchan();
7160 L1CTL.clear;
7161
7162 /* first establish the link-layer */
7163 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7164
7165 /* then send the REL REQ via RSL */
7166 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7167 /* ... and expect the DISC on the Um side */
7168 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007169 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007170 /* FIXME: send a UA in resposne to the DISC */
7171 }
7172 }
7173
7174 /* release the channel */
7175 f_rsl_chan_deact();
7176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7177 f_rslem_unregister(0, g_chan_nr);
7178}
7179testcase TC_rll_rel_req() runs on test_CT {
7180 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007181 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7182 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7183 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7184 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007185 };
7186 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7187}
7188
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007189/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007190testcase TC_rll_data_req() runs on test_CT {
7191}
7192
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007193/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007194testcase TC_rll_data_ind() runs on test_CT {
7195}
7196
7197/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7198private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7199 var RllTestCase tc := g_pars.spec.rll;
7200
7201 f_l1_tune(L1CTL);
7202 RSL.clear;
7203
7204 f_est_dchan();
7205 L1CTL.clear;
7206
7207 /* Send UNITDATA REQ on RSL side */
7208 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7209 /* Expect it to arrive on the other side */
7210 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007211 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007212 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007213 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007214 }
7215
7216 /* release the channel */
7217 f_rsl_chan_deact();
7218 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7219 f_rslem_unregister(0, g_chan_nr);
7220}
7221testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7222 var octetstring l3 := f_rnd_octstring(15);
7223 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007224 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7225 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007226 };
7227 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7228}
7229testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7230 var octetstring l3 := f_rnd_octstring(19);
7231 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007232 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7233 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007234 };
7235 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7236}
7237
7238/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7239private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7240 var RllTestCase tc := g_pars.spec.rll;
7241
7242 f_l1_tune(L1CTL);
7243 RSL.clear;
7244
7245 f_est_dchan();
7246 L1CTL.clear;
7247
7248 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007249 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007250 /* Expdct RLL UNITDATA IND on RSL side */
7251 alt {
7252 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7253 setverdict(pass);
7254 }
7255 [] RSL.receive { repeat; }
7256 }
7257
7258 /* release the channel */
7259 f_rsl_chan_deact();
7260 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7261 f_rslem_unregister(0, g_chan_nr);
7262}
7263testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007264 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007265 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007266 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7267 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007268 };
7269 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7270}
7271testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7272 var octetstring l3 := f_rnd_octstring(18);
7273 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007274 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7275 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007276 };
7277 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7278}
7279
Harald Weltee613f962018-04-18 22:38:16 +02007280/***********************************************************************
7281 * Encryption Related
7282 ***********************************************************************/
7283
7284/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007285private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007286 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7287 if (link_id.c == SACCH) {
7288 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7289 } else {
7290 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7291 }
7292}
7293
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007294/* Expect (or not expect) other kinds of messages */
7295private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7296 [exp_any] RSL.receive { repeat; }
7297 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007299 }
7300}
7301
Harald Weltee613f962018-04-18 22:38:16 +02007302/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007303private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007304 RslLinkId link_id,
7305 octetstring l3,
7306 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007307 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007308) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007309 timer T := 3.0;
7310 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7311 T.start;
7312 /* Expect RLL UNITDATA IND on RSL side */
7313 alt {
7314 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7315 setverdict(pass);
7316 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007317 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007318 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007319 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007321 }
Harald Weltee613f962018-04-18 22:38:16 +02007322 }
7323}
7324
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007325/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7326private function f_data_mo(
7327 RslLinkId link_id,
7328 boolean p, uint3_t nr, uint3_t ns,
7329 octetstring l3,
7330 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007331 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007332) runs on ConnHdlr {
7333 timer T := 3.0;
7334 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7335 T.start;
7336 /* Expect RLL DATA IND on RSL side */
7337 alt {
7338 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7339 setverdict(pass);
7340 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007341 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007342 [] as_rsl_any_ind(exp_any);
7343 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007345 }
7346 }
7347}
7348
Harald Weltee613f962018-04-18 22:38:16 +02007349/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007350private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007351 f_l1_tune(L1CTL);
7352 f_est_dchan(true);
7353
7354 /* now we actually need to transmit some data both ways to check if the encryption works */
7355 var L1ctlDlMessage dl;
7356
Stefan Sperling603d98e2018-07-25 16:47:28 +02007357 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007358 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7359
7360 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7361 f_unitdata_mt(link_id, l3);
7362
7363 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7364 f_unitdata_mo(link_id, l3);
7365
7366 /* release the channel */
7367 f_rsl_chan_deact();
7368 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7369 f_rslem_unregister(0, g_chan_nr);
7370}
7371testcase TC_chan_act_a51() runs on test_CT {
7372 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7373 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7374 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7375}
7376testcase TC_chan_act_a52() runs on test_CT {
7377 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7378 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7379 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7380}
7381testcase TC_chan_act_a53() runs on test_CT {
7382 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7383 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7384 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7385}
Eric Wildb9260392021-05-15 19:48:22 +02007386testcase TC_chan_act_a54() runs on test_CT {
7387 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7388 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7389 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7390}
Harald Weltee613f962018-04-18 22:38:16 +02007391
Eric Wildf1827a72019-05-28 17:37:35 +02007392/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7393 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 +07007394private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007395 f_l1_tune(L1CTL);
7396 f_est_dchan(true);
7397
7398 /* now we actually need to transmit some data both ways to check if the encryption works */
7399 var L1ctlDlMessage dl;
7400
7401 var octetstring l3 := f_rnd_octstring(20);
7402 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7403
7404 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7405 f_unitdata_mt(link_id, l3);
7406
7407 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7408 f_unitdata_mo(link_id, l3);
7409
7410 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007411 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007412
7413 /* modify key to break proper encryption */
7414 g_pars.encr.key := f_rnd_octstring(8);
7415 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7416 rsl.ies := rsl.ies & { ei };
7417 RSL.send(rsl);
7418
7419 timer T0 := 1.0;
7420 T0.start;
7421 /* Expect RSL MODIFY ACK */
7422 alt {
7423 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7424 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7426 }
7427 [] T0.timeout {
7428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7429 }
7430 }
7431
7432 var octetstring l3msg := f_rnd_octstring(15);
7433 timer T1 := 3.0;
7434 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7435 due to broken encryption */
7436 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7437 T1.start;
7438 alt {
7439 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7441 }
7442 [] T1.timeout {
7443 setverdict(pass);
7444 }
7445 }
7446
7447 /* release the channel */
7448 f_rsl_chan_deact();
7449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7450 f_rslem_unregister(0, g_chan_nr);
7451}
7452testcase TC_rsl_modify_encr() runs on test_CT {
7453 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7454 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7455 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7456}
Harald Weltee613f962018-04-18 22:38:16 +02007457
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007458/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007459private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007460runs on test_CT {
7461 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7462 var ASP_RSL_Unitdata ud;
7463 timer T;
7464
7465 /* Intave is 6 SACCH periods by default */
7466 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7467
7468 T.start(Tval);
7469 alt {
7470 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7471 setverdict(pass);
7472 }
7473 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7474 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7475 }
7476 [] RSL_CCHAN.receive { repeat; }
7477 [] T.timeout {
7478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7479 "Timeout waiting for RF RESource INDication");
7480 }
7481 }
7482}
7483testcase TC_rsl_rf_resource_ind() runs on test_CT {
7484 var RSL_ResourceInfo info := { };
7485
7486 f_init(trx_nr := 0);
7487
7488 f_init_l1ctl();
7489 f_l1_tune(L1CTL);
7490
7491 /* g_AllChannels contains all logical channels */
7492 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7493 var RslChannelNr chan_nr := g_AllChannels[i];
7494
7495 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7496 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7497 { continue; }
7498
7499 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7500 }
7501
7502 /* Align to the first interference report */
7503 f_TC_rsl_rf_resource_ind(?);
7504
7505 /* Test 4 consecutive messages */
7506 for (var integer i := 0; i < 4; i := i + 1) {
7507 f_TC_rsl_rf_resource_ind(info);
7508 }
7509
7510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7511}
7512
Harald Weltee613f962018-04-18 22:38:16 +02007513/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007514private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007515 /* L3 payload doesn't matter, as it is passed transparently */
7516 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7517 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7518 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7519
7520 f_l1_tune(L1CTL);
7521
7522 /* first establish a dedicated channel in the clear */
7523 f_est_dchan(false);
7524
7525 /* Establish ABM */
7526 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7527
7528 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7529 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7530 /* expect the L3 to arrive still unencrypted on the MS side */
7531 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7532
7533 /* configure L1 to apply ciphering */
7534 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7535 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7536
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007537 /* send first ciphered I-frame in response and expect it on RSL */
7538 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007539
7540 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7541 * and hence enable encryption also on the downlink */
7542
7543 /* expect bi-directional communication work in encrypted mode */
7544 f_unitdata_mo(link_id, f_rnd_octstring(15));
7545 f_unitdata_mt(link_id, f_rnd_octstring(15));
7546
7547 /* release the channel */
7548 f_rsl_chan_deact();
7549 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7550 f_rslem_unregister(0, g_chan_nr);
7551}
7552testcase TC_encr_cmd_a51() runs on test_CT {
7553 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7554 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7555 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7556}
7557testcase TC_encr_cmd_a52() runs on test_CT {
7558 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7559 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7560 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7561}
7562testcase TC_encr_cmd_a53() runs on test_CT {
7563 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7564 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7565 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7566}
Eric Wildb9260392021-05-15 19:48:22 +02007567testcase TC_encr_cmd_a54() runs on test_CT {
7568 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7569 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7570 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7571}
Harald Weltee613f962018-04-18 22:38:16 +02007572
7573private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7574 var LapdmFrame lf;
7575 var octetstring reenc;
7576
7577 /* decode the LAPDm frame */
7578 if (ischosen(exp_match.ab)) {
7579 lf.ab := dec_LapdmFrameAB(enc);
7580 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007582 }
7583
7584 /* check if decoder result matches expectation */
7585 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007586 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007587 } else {
7588 log(name, ": matched");
7589 setverdict(pass);
7590 }
7591
7592 /* test if re-encoded frame equals original input */
7593 reenc := enc_LapdmFrame(lf);
7594 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007596 } else {
7597 setverdict(pass);
7598 }
7599}
7600
7601testcase TC_lapdm_selftest() runs on test_CT {
7602 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7603 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7604 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7605 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7606 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7607 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7608 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7609}
7610
Stefan Sperling4880be42018-08-07 18:12:59 +02007611/***********************************************************************
7612 * DTX Related (see GSM 05.08, section 8.3)
7613 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007614private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007615 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007616 var GsmFrameNumber first_fn;
7617 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007618 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007619 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007620 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7621 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007622 const integer frame_dtx_tchf_mod := 104;
7623 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7624 * which operates in terms of blocks rather than frames. */
7625 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7626 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007627 timer T := 5.0;
7628
7629 f_l1_tune(L1CTL);
7630 RSL.clear;
7631 L1CTL.clear;
7632
7633 /* activate TCHF signalling channel */
7634 f_est_dchan(false);
7635
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007636 /* A template for matching dummy LAPDm func=UA frames */
7637 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7638 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7639 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7640
Stefan Sperling4880be42018-08-07 18:12:59 +02007641 T.start;
7642 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007643 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007644 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007645
7646 if (is_first_frame) {
7647 is_first_frame := false;
7648 first_fn := dl.dl_info.frame_nr;
7649 }
7650
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007651 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007652 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007653 T.stop;
7654 f_rsl_chan_deact();
7655 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007656
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007657 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7658 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007659
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007660 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007661 setverdict(fail, "Not enough fill frames received: ",
7662 nfill_frames, " out of ", expected_fill_frames);
7663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007664 } else {
7665 setverdict(pass);
7666 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007667 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007668 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7669 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7670 * we should only see the subset of frames numbers which correspond to a block boundary.
7671 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7672 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7673 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007674 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007675 repeat;
7676 }
7677 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007678 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7679 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7680 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007681 f_rsl_chan_deact();
7682 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007683 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007684 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007685 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007686 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007687 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007688
7689 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007690 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7691 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007692 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7693 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7694 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007695 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7696 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007697 case else {
7698 /* This shall not happen, just to be sure */
7699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7700 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007701 }
7702
7703 f_rsl_chan_deact();
7704 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007705
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007706 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007707 setverdict(pass);
7708 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007709 setverdict(fail, "Not enough fill frames received: ",
7710 nfill_frames, " out of ", expected_fill_frames);
7711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007712 }
7713 } else {
7714 repeat;
7715 }
7716 }
7717 }
7718 [] L1CTL.receive { repeat; }
7719 [] T.timeout {
7720 f_rsl_chan_deact();
7721 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007723 }
7724 }
7725}
7726
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007727private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007728 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007729 var ConnHdlr vc_conn;
7730 var ConnHdlrPars pars;
7731 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007732 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007733 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007734 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007735 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007736 if (dtxd) {
7737 if (i >= 4) { /* DTX is only allowed on TCH/F */
7738 break;
7739 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007740 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007741 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007742 vc_conn.done;
7743 }
7744}
7745
7746/* Verify that L2 fill frames are sent on TCH in signaling mode if
7747 * there is nothing to transmit while DTX is disabled on downlink. */
7748testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7749 f_tch_sign_l2_fill_frame(false);
7750}
7751
7752/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7753 * there is nothing to transmit while DTX is enabled on downlink. */
7754testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7755 f_tch_sign_l2_fill_frame(true);
7756}
Harald Welte0472ab42018-03-12 15:02:26 +01007757
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007758testcase TC_chopped_ipa_ping() runs on test_CT {
7759 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7760}
7761
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007762testcase TC_chopped_ipa_payload() runs on test_CT {
7763 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7764}
7765
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007766
7767/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7768 * Return value: Measurement Report to be sent (encoded octetstring). */
7769type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7770 runs on ConnHdlr return octetstring;
7771
7772private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7773runs on ConnHdlr {
7774 var L1ctlDlMessage l1_dl;
7775 var SacchL1Header l1h;
7776 var octetstring l2;
7777
7778 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7779 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7780 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7781 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7782
7783 /* Pass it to the user specified call-back function */
7784 l2 := cb.apply(l1h, num_blocks);
7785 /* Send a Measurement Report generated by the call-back */
7786 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7787 l1_dl.dl_info.link_id,
7788 l1h, l2));
7789
7790 /* Shall we keep going? */
7791 num_blocks := num_blocks - 1;
7792 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7793 if (num_blocks > 0) { repeat; }
7794 }
7795 [] L1CTL.receive { repeat; }
7796}
7797
7798private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7799runs on ConnHdlr return octetstring {
7800 /* Command the L1 to apply received parameters */
7801 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7802
7803 /* Dummy measurement report (the results are invalid) */
7804 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7805}
7806
7807private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7808runs on ConnHdlr return octetstring {
7809 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7810 setverdict(fail, "Unexpected MS Power level change: ",
7811 g_pars.l1_pars.ms_power_level, " -> ",
7812 l1h.ms_power_lvl);
7813 }
7814
7815 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7816}
7817
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007818private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7819runs on ConnHdlr return octetstring {
7820 /* UL RSSI oscillation driven by SACCH block number */
7821 if (num_blocks rem 2 == 0) {
7822 f_trxc_fake_rssi(-100);
7823 } else {
7824 f_trxc_fake_rssi(-50);
7825 }
7826
7827 /* Make sure that MS power level remains constant */
7828 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7829}
7830
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007831/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7832private function f_TC_ms_pwr_ctrl_constant(charstring id)
7833runs on ConnHdlr {
7834 var integer num_blocks := 8;
7835 timer T := int2float(num_blocks);
7836
7837 f_l1_tune(L1CTL);
7838 RSL.clear;
7839
7840 /* These IEs are needed for autonomous MS power control */
7841 var template (value) RSL_IE_List ies := {
7842 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7843 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7844 }),
7845 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7846 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7847 })
7848 };
7849
7850 /* Ensure that 'rx-current' equals 'rx-target' */
7851 f_trxc_fake_rssi(mp_uplink_power_target);
7852
7853 /* Establish a dedicated channel */
7854 f_est_dchan(more_ies := valueof(ies));
7855
7856 L1CTL.clear;
7857 T.start;
7858 alt {
7859 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7860 [] T.timeout {
7861 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7862 num_blocks, " were not handled");
7863 }
7864 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007865
7866 /* Release the channel */
7867 f_rsl_chan_deact();
7868 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007869}
7870testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7871 var ConnHdlr vc_conn;
7872 var ConnHdlrPars pars;
7873
7874 f_init();
7875
7876 /* Explicitly configure the Uplink power target (in dBm) */
7877 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7878
7879 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7880 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7881 log(testcasename(), ": starting on ", pars.chan_nr);
7882
7883 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7884 pars, trxc_comp := true);
7885 vc_conn.done;
7886 }
7887
7888 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7890}
7891
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007892/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7893private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7894runs on ConnHdlr {
7895 var integer num_blocks := 16;
7896 timer T := int2float(num_blocks);
7897
7898 f_l1_tune(L1CTL);
7899 RSL.clear;
7900
7901 /* These IEs are needed for autonomous MS power control */
7902 var template (value) RSL_IE_List ies := {
7903 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7904 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7905 }),
7906 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7907 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7908 })
7909 };
7910
7911 /* Ensure that 'rx-current' equals 'rx-target' */
7912 f_trxc_fake_rssi(mp_uplink_power_target);
7913
7914 /* Establish a dedicated channel */
7915 f_est_dchan(more_ies := valueof(ies));
7916
7917 L1CTL.clear;
7918 T.start;
7919 alt {
7920 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7921 [] T.timeout {
7922 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7923 num_blocks, " were not handled");
7924 }
7925 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007926
7927 /* Release the channel */
7928 f_rsl_chan_deact();
7929 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007930}
7931testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7932 var ConnHdlr vc_conn;
7933 var ConnHdlrPars pars;
7934
7935 f_init();
7936
7937 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7938 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7939 /* Explicitly configure the Uplink power range (target and delte) */
7940 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7941 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7942
7943 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7944 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7945 log(testcasename(), ": starting on ", pars.chan_nr);
7946
7947 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7948 pars, trxc_comp := true);
7949 vc_conn.done;
7950 }
7951
7952 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7954}
7955
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007956private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7957 var template L1ctlDlMessage tr_bad_frame;
7958 var L1ctlDlMessage l1_dl;
7959 timer T := 8.0;
7960
7961 f_l1_tune(L1CTL);
7962 RSL.clear;
7963
7964 f_est_dchan();
7965
7966 /* There may be a few errors right after the channel activation */
7967 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7968 L1CTL.clear;
7969
7970 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7971 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7972 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7973 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7974 tr_bad_frame.payload := ?;
7975
7976 T.start;
7977 alt {
7978 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7979 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7980 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7981 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7982 }
7983 [] as_l1_sacch();
7984 [] L1CTL.receive { repeat; }
7985 [] T.timeout {
7986 /* We're done, break the loop */
7987 setverdict(pass);
7988 }
7989 }
7990
7991 f_rsl_chan_deact();
7992 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7993}
7994testcase TC_speech_no_rtp_tchf() runs on test_CT {
7995 var ConnHdlr vc_conn;
7996 var ConnHdlrPars pars;
7997
7998 f_init();
7999
8000 /* TS1, TCH/F, V1 (FR codec) */
8001 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8002 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8003 vc_conn.done;
8004}
8005testcase TC_speech_no_rtp_tchh() runs on test_CT {
8006 var ConnHdlr vc_conn;
8007 var ConnHdlrPars pars;
8008
8009 f_init();
8010
8011 /* TS5, TCH/H, V1 (HR codec) */
8012 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8013 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8014 vc_conn.done;
8015}
8016
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008017/* Verify handling of Downlink and Uplink speech frames */
8018private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8019 var L1ctlDlMessage l1_dl;
8020 var PDU_RTP rtp_pdu;
8021 var octetstring pl;
8022 timer Td, Tu;
8023
8024 f_l1_tune(L1CTL);
8025 f_est_dchan();
8026
8027 /* Activate the RTP emulation */
8028 pl := f_rnd_octstring(6);
8029 f_rtpem_activate(pl);
8030
8031 /* Give the scheduler some time to fill up the buffers */
8032 f_sleep(2.0);
8033 L1CTL.clear;
8034 RSL.clear;
8035
8036 /* Make sure that Downlink frames are received at the UE */
8037 Td.start(2.0);
8038 alt {
8039 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8040 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8041 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8042 l1_dl.payload.traffic_ind.data));
8043 setverdict(pass);
8044 }
8045 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8046 setverdict(fail, "Rx unexpected Downlink speech frame ",
8047 "(", l1_dl.payload.traffic_ind.data, ") ",
8048 "expected (", pl, ")");
8049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8050 }
8051 [] as_l1_sacch();
8052 [] L1CTL.receive { repeat; }
8053 [] Td.timeout {
8054 setverdict(fail, "Timeout waiting for Downlink speech frames");
8055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8056 }
8057 }
8058
8059 /* Make sure that Uplink frames are received at the BTS */
8060 RTPEM_DATA.clear;
8061 Tu.start(2.0);
8062 alt {
8063 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8064 if (rtp_pdu.data != pl)
8065 { repeat; }
8066 }
8067 [] RTPEM_DATA.receive { repeat; }
8068 [] Tu.timeout {
8069 setverdict(fail, "Timeout waiting for Uplink speech frames");
8070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8071 }
8072 }
8073
8074 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8075 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8076 f_rsl_chan_deact();
8077 f_rslem_unregister(0, g_chan_nr);
8078}
8079testcase TC_speech_rtp_tchf() runs on test_CT {
8080 var ConnHdlr vc_conn;
8081 var ConnHdlrPars pars;
8082
8083 f_init();
8084
8085 /* TS1, TCH/F, V1 (FR codec) */
8086 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8087 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8088 vc_conn.done;
8089
8090 /* TS1, TCH/F, V2 (EFR codec) */
8091 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8092 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8093 vc_conn.done;
8094
8095 /* TODO: also test V3 (AMR codec) */
8096
8097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8098}
8099testcase TC_speech_rtp_tchh() runs on test_CT {
8100 var ConnHdlr vc_conn;
8101 var ConnHdlrPars pars;
8102
8103 f_init();
8104
8105 /* TS5, TCH/H0, V1 (HR codec) */
8106 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8107 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8108 vc_conn.done;
8109
8110 /* TODO: also test V3 (AMR codec) */
8111
8112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8113}
8114
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008115private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8116 var GsmFrameNumber fn;
8117 var ChannelDescription ch_desc;
8118 var integer ra := 23;
8119
8120 f_l1_tune(L1CTL);
8121 RSL.clear;
8122
8123 /* Send RACH request and wait for ChanReq */
8124 fn := f_rach_req_wait_chan_rqd(ra);
8125
8126 /* The BSC already sends the Immediate Assignment, before the channel is active.
8127 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8128 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8129 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8130 if (g_pars.fhp.enabled) {
8131 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8132 } else {
8133 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8134 }
8135 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8136 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8137
8138 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8139 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8140 var L1ctlDlMessage dl;
8141 var GsmRrMessage rr;
8142
8143 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8144 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8145 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8146 rr_imm_ass.payload.imm_ass.chan_desc := *;
8147
8148 timer T := 1.0;
8149 T.start;
8150 alt {
8151 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8152 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8153 if (match(rr, rr_imm_ass)) {
8154 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8155 mtc.stop;
8156 } else {
8157 repeat;
8158 }
8159 }
8160 [] L1CTL.receive { repeat; }
8161 [] T.timeout;
8162 }
8163 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8164 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8165
8166 /* Now expect the IMM ASS on Um */
8167 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8168 setverdict(pass);
8169
8170 /* Release the channel */
8171 f_rsl_chan_deact();
8172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8173}
8174
8175testcase TC_early_immediate_assignment() runs on test_CT {
8176 var ConnHdlr vc_conn;
8177 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8178 f_init();
8179 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8180 vc_conn.done;
8181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8182}
8183
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008184private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8185 var integer ra := oct2int(f_rnd_ra_cs());
8186 var ChannelDescription ch_desc;
8187
8188 /* Tune the MS to BCCH */
8189 f_l1_tune(L1CTL);
8190
8191 /* Send RACH request and wait for ChanReq */
8192 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8193
8194 /* Activate channel on the BTS side */
8195 f_rsl_chan_act(g_pars.chan_mode);
8196
8197 /* Craft channel description (with or without frequency hopping parameters) */
8198 if (g_pars.fhp.enabled) {
8199 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8200 } else {
8201 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8202 }
8203
8204 /* Send IMM.ASS via CCHAN */
8205 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8206 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8207
8208 /* Receive IMM.ASS on the MS side */
8209 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8210
8211 /* Match the Channel Description IE in received IMM.ASS */
8212 if (not match(imm_ass.chan_desc, ch_desc)) {
8213 setverdict(fail, "Channel Description IE does not match");
8214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8215 }
8216
8217 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8218 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8219
8220 /* Expect SACCH frames on Downlink */
8221 L1CTL.clear;
8222 f_exp_sacch(true);
8223
8224 /* We're done, deactivate and release */
8225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8226 f_rsl_chan_deact();
8227}
8228testcase TC_est_dchan() runs on test_CT {
8229 var ConnHdlr vc_conn;
8230 var ConnHdlrPars pars;
8231
8232 f_init();
8233
8234 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8235 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8236 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8237 vc_conn.done;
8238 }
8239
8240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8241}
8242
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008243private type record TopTestCase {
8244 RSL_IE_BS_Power bs_power,
8245 RSL_IE_OSMO_TopAcchCap top_cap,
8246 record of TopTestStep steps
8247};
8248private type record TopTestStep {
8249 MeasurementResults meas_res optional,
8250 GsmRxLev overpower_sacch,
8251 GsmRxLev overpower_facch
8252};
8253
8254private function f_rxlev_match(template (present) RslLinkId link_id,
8255 template (present) GsmRxLev rxlev)
8256runs on ConnHdlr {
8257 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8258 if (not match(dl.dl_info.rx_level, rxlev)) {
8259 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8260 " does not match expected RxLev := ", rxlev);
8261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8262 }
8263}
8264
8265private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8266 var TopTestCase tc := g_pars.spec.top;
8267 var GsmRxLev rxlev_dcch;
8268 var L1ctlDlMessage dl;
8269
8270 /* Wait for Pau ramping to complete */
8271 f_sleep(6.0);
8272
8273 f_l1_tune(L1CTL);
8274 L1CTL.clear;
8275 RSL.clear;
8276
8277 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8278 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8279 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8280
8281 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8282 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8283
8284 /* Additional IEs for the CHANnel ACTIVation message */
8285 var template (value) RSL_IE_List ies := {
8286 /* Employ BS power control in static mode */
8287 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8288 bs_power := tc.bs_power
8289 }),
8290 /* Indicate the given Temporary Overpower capability */
8291 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8292 top_acch_cap := tc.top_cap
8293 })
8294 };
8295
8296 /* Establish a dedicated channel */
8297 f_est_dchan(more_ies := valueof(ies));
8298
8299 /* Give it some time to stabilize */
8300 f_sleep(0.480 * 2.0);
8301 L1CTL.clear;
8302 RSL.clear;
8303
8304 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8305 var TopTestStep step := tc.steps[i];
8306 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8307 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8308
8309 log("Executing step[", i, "] := ", step);
8310
8311 /* Send RR Measurement Report (if present) */
8312 if (ispresent(step.meas_res)) {
8313 f_transceive_meas_rep(step.meas_res);
8314 f_sleep(0.480 * 2.0);
8315 L1CTL.clear;
8316 }
8317
8318 /* Check RxLev on both FACCH and SACCH */
8319 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8320 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8321
8322 setverdict(pass);
8323 }
8324}
8325testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8326 var ConnHdlrPars pars;
8327 var ConnHdlr vc_conn;
8328
8329 f_init();
8330
8331 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008332 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008333 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8334 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8335 steps := {
8336 /* Channel established, no overpower */
8337 { meas_res := omit,
8338 overpower_sacch := 0, overpower_facch := 0 },
8339
8340 /* Worst possible RxQual value, overpower of 4dB */
8341 { meas_res := ts_MeasurementResults(rxq_f := 7),
8342 overpower_sacch := 4, overpower_facch := 4 },
8343 /* Worst possible RxQual value, disabling overpower */
8344 { meas_res := ts_MeasurementResults(rxq_f := 0),
8345 overpower_sacch := 0, overpower_facch := 0 },
8346
8347 /* Lower threshold not reached, no overpower */
8348 { meas_res := ts_MeasurementResults(rxq_f := 1),
8349 overpower_sacch := 0, overpower_facch := 0 },
8350 /* Lower threshold not reached, no overpower */
8351 { meas_res := ts_MeasurementResults(rxq_f := 2),
8352 overpower_sacch := 0, overpower_facch := 0 },
8353 /* Lower threshold reached, overpower of 4dB */
8354 { meas_res := ts_MeasurementResults(rxq_f := 4),
8355 overpower_sacch := 4, overpower_facch := 4 },
8356 /* Upper threshold not reached, keeping overpower */
8357 { meas_res := ts_MeasurementResults(rxq_f := 3),
8358 overpower_sacch := 4, overpower_facch := 4 },
8359 /* Upper threshold reached, disabling overpower */
8360 { meas_res := ts_MeasurementResults(rxq_f := 2),
8361 overpower_sacch := 0, overpower_facch := 0 }
8362 }
8363 };
8364
8365 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8366 spec := { top := top }, trx_nr := 1));
8367 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8368 vc_conn.done;
8369
8370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8371}
8372testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8373 var ConnHdlrPars pars;
8374 var ConnHdlr vc_conn;
8375
8376 f_init();
8377
8378 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008379 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008380 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8381 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8382 steps := {
8383 /* Channel established, no overpower */
8384 { meas_res := omit,
8385 overpower_sacch := 0, overpower_facch := 0 },
8386
8387 /* Invalid measurement results, no overpower */
8388 { meas_res := ts_MeasurementResults(rxq_f := 7,
8389 rxq_s := 7,
8390 valid := false),
8391 overpower_sacch := 0, overpower_facch := 0 },
8392
8393 /* DTXu was in use, no overpower */
8394 { meas_res := ts_MeasurementResults(rxq_f := 7,
8395 rxq_s := 0,
8396 dtx_used := true),
8397 overpower_sacch := 0, overpower_facch := 0 },
8398 /* DTXu was in use, overpower of 4 dB */
8399 { meas_res := ts_MeasurementResults(rxq_f := 0,
8400 rxq_s := 7,
8401 dtx_used := true),
8402 overpower_sacch := 4, overpower_facch := 4 }
8403 }
8404 };
8405
8406 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8407 spec := { top := top }, trx_nr := 1));
8408 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8409 vc_conn.done;
8410
8411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8412}
8413testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8414 var ConnHdlrPars pars;
8415 var ConnHdlr vc_conn;
8416
8417 f_init();
8418
8419 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008420 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008421 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8422 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8423 rxqual := 0, /* always on */
8424 sacch_enable := false),
8425 steps := {
8426 /* Channel established, FACCH overpower */
8427 { meas_res := omit,
8428 overpower_sacch := 0, overpower_facch := 4 },
8429 /* MS indicates good RxQual, no difference */
8430 { meas_res := ts_MeasurementResults(rxq_f := 0),
8431 overpower_sacch := 0, overpower_facch := 4 },
8432 /* MS indicates bad RxQual, no difference */
8433 { meas_res := ts_MeasurementResults(rxq_f := 7),
8434 overpower_sacch := 0, overpower_facch := 4 }
8435 }
8436 };
8437
8438 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8439 spec := { top := top }, trx_nr := 1));
8440 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8441 vc_conn.done;
8442
8443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8444}
8445testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8446 var ConnHdlrPars pars;
8447 var ConnHdlr vc_conn;
8448
8449 f_init();
8450
8451 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008452 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008453 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8454 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8455 rxqual := 0, /* always on */
8456 facch_enable := false),
8457 steps := {
8458 /* Channel established, SACCH overpower */
8459 { meas_res := omit,
8460 overpower_sacch := 4, overpower_facch := 0 },
8461 /* MS indicates good RxQual, no difference */
8462 { meas_res := ts_MeasurementResults(rxq_f := 0),
8463 overpower_sacch := 4, overpower_facch := 0 },
8464 /* MS indicates bad RxQual, no difference */
8465 { meas_res := ts_MeasurementResults(rxq_f := 7),
8466 overpower_sacch := 4, overpower_facch := 0 }
8467 }
8468 };
8469
8470 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8471 spec := { top := top }, trx_nr := 1));
8472 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8473 vc_conn.done;
8474
8475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8476}
8477testcase TC_acch_overpower_limit() runs on test_CT {
8478 var ConnHdlrPars pars;
8479 var ConnHdlr vc_conn;
8480
8481 f_init();
8482
8483 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008484 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008485 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8486 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8487 rxqual := 0 /* always on */),
8488 steps := {
8489 /* Channel established, ACCH overpower of 2dB */
8490 { meas_res := omit,
8491 overpower_sacch := 2, overpower_facch := 2 },
8492 /* MS indicates good RxQual, no difference */
8493 { meas_res := ts_MeasurementResults(rxq_f := 0),
8494 overpower_sacch := 2, overpower_facch := 2 },
8495 /* MS indicates bad RxQual, no difference */
8496 { meas_res := ts_MeasurementResults(rxq_f := 7),
8497 overpower_sacch := 2, overpower_facch := 2 }
8498 }
8499 };
8500
8501 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8502 spec := { top := top }, trx_nr := 1));
8503 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8504 vc_conn.done;
8505
8506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8507}
8508
Harald Welte0472ab42018-03-12 15:02:26 +01008509/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8510/* protocol error as per 44.006 */
8511/* link layer failure (repetition of I-frame N200 times without ACK */
8512/* repetition of SABM or DISC N200 times without ACK */
8513/* receptiom of SABM in multi-frame established state */
8514
8515
Harald Welte68e495b2018-02-25 00:05:57 +01008516/* TODO Areas:
8517
8518* channel activation
8519** with BS_Power / MS_Power, bypassing power control loop
8520** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008521** with timing advance from initial activation on
8522* mode modify
8523** encryption
8524** multirate
8525* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008526** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008527* BS Power Control
8528* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008529* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008530** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008531* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008532** DATA_IND from BTS->PCU
8533** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008534
8535*/
Harald Welte70767382018-02-21 12:16:40 +01008536
8537control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008538 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008539 execute( TC_chan_act_stress() );
8540 execute( TC_chan_act_react() );
8541 execute( TC_chan_deact_not_active() );
8542 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008543 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008544 execute( TC_sacch_filling() );
8545 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008546 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008547 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008548 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008549 execute( TC_sacch_chan_act_ho_async() );
8550 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008551 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008552 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008553 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008554 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008555 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008556 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008557 execute( TC_rach_load_idle_thresh0() );
8558 execute( TC_rach_load_idle_below_thresh() );
8559 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008560 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008561 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008562 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008563 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008564 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008565 execute( TC_meas_res_sign_tchf() );
8566 execute( TC_meas_res_sign_tchh() );
8567 execute( TC_meas_res_sign_sdcch4() );
8568 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008569 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008570 execute( TC_meas_res_speech_tchf_sapi3() );
8571 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008572 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008573 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008574 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008575 execute( TC_rsl_bs_pwr_static_ass() );
8576 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008577 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008578 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008579 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008580 execute( TC_rsl_ms_pwr_dyn_up() );
8581 execute( TC_rsl_ms_pwr_dyn_down() );
8582 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8583 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008584 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008585 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008586 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008587 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008588 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008589 execute( TC_paging_imsi_80percent() );
8590 execute( TC_paging_tmsi_80percent() );
8591 execute( TC_paging_imsi_200percent() );
8592 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008593 execute( TC_rsl_protocol_error() );
8594 execute( TC_rsl_mand_ie_error() );
8595 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008596 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008597 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008598 execute( TC_si_sched_2bis() );
8599 execute( TC_si_sched_2ter() );
8600 execute( TC_si_sched_2ter_2bis() );
8601 execute( TC_si_sched_2quater() );
8602 execute( TC_si_sched_13() );
8603 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008604 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008605 execute( TC_ipa_crcx_twice_not_active() );
8606 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008607 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008608 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008609 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008610
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008611 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008612 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008613 execute( TC_pcu_act_req() );
8614 execute( TC_pcu_act_req_wrong_ts() );
8615 execute( TC_pcu_act_req_wrong_bts() );
8616 execute( TC_pcu_act_req_wrong_trx() );
8617 execute( TC_pcu_deact_req() );
8618 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008619 execute( TC_pcu_ver_si1() );
8620 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008621 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008622 if (mp_l1_supports_gprs) {
8623 execute( TC_pcu_data_req_pdtch() );
8624 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008625 execute( TC_pcu_data_req_wrong_bts() );
8626 execute( TC_pcu_data_req_wrong_trx() );
8627 execute( TC_pcu_data_req_wrong_ts() );
8628 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008629 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008630 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008631 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008632 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008633 execute( TC_pcu_data_req_imm_ass_pch() );
8634 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008635 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008636 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008637 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008638 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008639 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008640 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008641 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008642 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008643 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008644 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008645 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008646 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008647 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008648 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008649 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008650 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008651 execute( TC_dyn_osmo_pdch_act_deact() );
8652 execute( TC_dyn_osmo_pdch_double_act() );
8653 execute( TC_dyn_ipa_pdch_act_deact() );
8654 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008655 execute( TC_pcu_info_ind_fh_params() );
8656 execute( TC_pcu_socket_nsvc_ipv4() );
8657 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008658 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008659 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008660 } else {
8661 log("PCU socket path not available, skipping PCU tests");
8662 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008663
Harald Welte3d04ae62018-04-04 20:29:05 +02008664 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008665 execute( TC_dyn_osmo_pdch_tchf_act() );
8666 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008667 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008668 execute( TC_dyn_ipa_pdch_tchf_act() );
8669 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008670
8671 execute( TC_rll_est_ind() );
8672 execute( TC_rll_est_req_DCCH_3() );
8673 execute( TC_rll_est_req_ACCH_3() );
8674 execute( TC_rll_rel_ind_DCCH_0() );
8675 execute( TC_rll_rel_ind_DCCH_3() );
8676 execute( TC_rll_rel_ind_ACCH_0() );
8677 execute( TC_rll_rel_ind_ACCH_3() );
8678 execute( TC_rll_rel_req() );
8679 execute( TC_rll_unit_data_req_DCCH() );
8680 execute( TC_rll_unit_data_req_ACCH() );
8681 execute( TC_rll_unit_data_ind_DCCH() );
8682 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008683
8684 execute( TC_chan_act_a51() );
8685 execute( TC_chan_act_a52() );
8686 execute( TC_chan_act_a53() );
8687 execute( TC_encr_cmd_a51() );
8688 execute( TC_encr_cmd_a52() );
8689 execute( TC_encr_cmd_a53() );
8690
Harald Welteee25aae2019-05-19 14:32:37 +02008691 execute( TC_err_rep_wrong_mdisc() );
8692 execute( TC_err_rep_wrong_msg_type() );
8693 execute( TC_err_rep_wrong_sequence() );
8694
Harald Weltee613f962018-04-18 22:38:16 +02008695 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008696
8697 execute( TC_tch_sign_l2_fill_frame() );
8698 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008699
8700 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008701 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008702
8703 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008704 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008705
8706 execute( TC_speech_no_rtp_tchf() );
8707 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008708 execute( TC_speech_rtp_tchf() );
8709 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008710
8711 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008712
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008713 execute( TC_acch_overpower_rxqual_thresh() );
8714 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8715 execute( TC_acch_overpower_always_on_facch() );
8716 execute( TC_acch_overpower_always_on_sacch() );
8717 execute( TC_acch_overpower_limit() );
8718
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008719 /* BEWARE: these test cases can potentially break the IUT or cause
8720 * weird/unexpected behavior. Ensure that they are executed last. */
8721 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8722 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008723}
8724
8725
8726}