blob: 06fe43b586a11a0257e6faba8454ffda80afb100 [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);
798 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
799 g_pars.l1_pars.ms_actual_ta);
800
801 /* Send RR Measurement Report over the Um interface */
802 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
803
804 /* Expect MEASurement RESult on the A-bis/RSL interface */
805 T.start(2.0);
806 alt {
807 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
808 setverdict(pass);
809 }
810 [] RSL.receive { repeat; }
811 [] T.timeout {
812 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
814 }
815 }
816}
817
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700818friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
819 boolean encr_enable := false,
820 RSL_IE_List more_ies := {},
821 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
822runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200823 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200824 if (encr_enable) {
825 /* append encryption related IEs, if requested */
826 var RSL_IE_EncryptionInfo encr_info;
827 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
828 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
829encr_info})) };
830 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200831 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200832 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100833}
834
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700835friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100836 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 +0100837 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100838}
839
Harald Welte2f2b2b72019-05-31 22:24:57 +0200840friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200841 template RSL_IE_ChannelMode chan_mode,
842 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700843 uint8_t trx_nr := 0, float t_guard := 20.0) := {
844 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100845 chan_nr := valueof(chan_nr),
846 chan_mode := valueof(chan_mode),
847 t_guard := t_guard,
848 l1_pars := {
849 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100850 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100851 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100852 meas_ul := {
853 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 },
857 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200858 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 rxqual := 0
860 }
861 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200862 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100863 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200864 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200865 ms_actual_ta := mp_ms_actual_ta_exp,
866 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100867 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200868 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200869 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700870 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700871 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700872 fhp := {
873 enabled := false,
874 maio_hsn := ts_HsnMaio(0, 0),
875 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700876 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700877 }
Harald Welte70767382018-02-21 12:16:40 +0100878}
879
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300880/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
881 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
882private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
883 template (present) octetstring tr_data := ?,
884 template (present) RslChannelNr chan_nr := ?,
885 template (present) RslLinkId link_id := ?)
886runs on ConnHdlr {
887 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
888}
889
890/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
891 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
892private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
893 template (present) RslLinkId link_id := ?,
894 template (present) LapdmSapi sapi := ?,
895 boolean do_repeat := true)
896runs on ConnHdlr {
897 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
898 var L1ctlDlMessage dl_msg;
899
900 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
901 if (do_repeat) {
902 repeat;
903 }
904 }
905}
906
907/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
908 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
909private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
910 template (present) LapdmFrameAB tr_frame := ?,
911 template (present) RslLinkId link_id := ?)
912runs on ConnHdlr {
913 var L1ctlDlMessage dl_msg;
914
915 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
916 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
917 }
918}
919
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300920/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
921 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
922private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
923 template (present) LapdmFrameAB tr_frame := ?,
924 template (present) SacchL1Header tr_l1h := ?,
925 template (present) GsmSapi sapi := ?)
926runs on ConnHdlr {
927 var L1ctlDlMessage dl_msg;
928 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
929 template (present) L1ctlDataReq tr_data := {
930 l1header := tr_l1h,
931 l2_payload := decmatch tr_frame
932 };
933
934 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
935 var octetstring data := dl_msg.payload.data_ind.payload;
936 l1h := dec_SacchL1Header(substr(data, 0, 2));
937 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
938 }
939}
940
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300941/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
942 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
943 * payload is treated as PDU_ML3_NW_MS. */
944private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
945 template (present) PDU_ML3_NW_MS tr_pdu := ?,
946 template (present) GsmSapi sapi := 0)
947runs on ConnHdlr {
948 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
949 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
950 var LapdmFrameAB lapdm_frame;
951
952 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
953 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
954 }
955}
956
Harald Welte93640c62018-02-25 16:59:33 +0100957/***********************************************************************
958 * Channel Activation / Deactivation
959 ***********************************************************************/
960
Harald Welte70767382018-02-21 12:16:40 +0100961/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700962private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100963 for (var integer i := 0; i < 500; i := i+1) {
964 f_rsl_chan_act(g_pars.chan_mode);
965 f_rsl_chan_deact();
966 }
967 setverdict(pass);
968}
969testcase TC_chan_act_stress() runs on test_CT {
970 var ConnHdlr vc_conn;
971 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200972 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100973 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
974 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100976}
977
978/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700979private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100980 f_rsl_chan_act(g_pars.chan_mode);
981 /* attempt to activate the same lchan again -> expect reject */
982 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
983 alt {
984 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100986 }
987 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
988 setverdict(pass);
989 }
990 }
991 f_rsl_chan_deact();
992}
993testcase TC_chan_act_react() runs on test_CT {
994 var ConnHdlr vc_conn;
995 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100996 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100997 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
998 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001000}
1001
1002/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001003private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001004 timer T := 3.0;
1005 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1006 T.start;
1007 alt {
1008 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1009 setverdict(pass);
1010 }
1011 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001013 }
1014 }
1015}
1016testcase TC_chan_deact_not_active() runs on test_CT {
1017 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001019 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1020 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001022}
1023
1024/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001025private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001026 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1027 alt {
1028 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001030 }
1031 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1032 setverdict(pass);
1033 }
1034 }
1035}
1036private type record WrongChanNrCase {
1037 RslChannelNr chan_nr,
1038 charstring description
1039}
1040private type record of WrongChanNrCase WrongChanNrCases;
1041private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1042 chan_nr := chan_nr,
1043 description := desc
1044}
1045
1046testcase TC_chan_act_wrong_nr() runs on test_CT {
1047 var ConnHdlr vc_conn;
1048 var ConnHdlrPars pars;
1049
Harald Welte294b0a22018-03-10 23:26:48 +01001050 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001051
1052 var WrongChanNrCases wrong := {
1053 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1054 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1055 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1056 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1057 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1058 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1059 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1060 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1061 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1062 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1063 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1064 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1065 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1066 };
1067
1068 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1069 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1070 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1071 vc_conn.done;
1072 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001074}
1075
Harald Weltee613f962018-04-18 22:38:16 +02001076/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001077friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001078 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001079 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001080
1081 /* test on each of the channels we have */
1082 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1083 pars.chan_nr := valueof(g_AllChanTypes[i]);
1084
1085 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1086 vc_conn := f_start_handler(fn, pars);
1087 vc_conn.done;
1088 }
1089
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001091}
1092
Harald Welte93640c62018-02-25 16:59:33 +01001093/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001094 * SACCH handling
1095 ***********************************************************************/
1096
1097private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1098 timer T_sacch := 3.0;
1099 T_sacch.start;
1100 alt {
1101 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001103 }
1104 [not exp] T_sacch.timeout {
1105 setverdict(pass);
1106 }
1107 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1108 setverdict(pass);
1109 }
1110 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001112 }
1113 [] L1CTL.receive { repeat; }
1114 [] RSL.receive { repeat; }
1115 }
1116}
1117
1118/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1119private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1120 f_l1_tune(L1CTL);
1121 RSL.clear;
1122
1123 /* activate the logical channel */
1124 f_est_dchan();
1125 L1CTL.clear;
1126
1127 /* check that SACCH actually are received as expected */
1128 f_exp_sacch(true);
1129
1130 /* deactivate SACCH on the logical channel */
1131 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1132 f_sleep(1.0);
1133 L1CTL.clear;
1134
1135 /* check that no SACCH are received anymore */
1136 f_exp_sacch(false);
1137
1138 /* release the channel */
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_deact_sacch() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 //for (var integer i := 0; i < 1; i := i+1) {
1148 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1149 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1150 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1151 vc_conn.done;
1152 }
1153 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001155}
1156
Harald Welte55700662018-03-12 13:15:43 +01001157/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001158private function f_sacch_present(template octetstring l3_exp,
1159 boolean do_fail := true)
1160runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001161 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001162 timer T_sacch := 3.0;
1163 L1CTL.clear;
1164 T_sacch.start;
1165 alt {
1166 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1167 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1168 if (match(l3, l3_exp)) {
1169 setverdict(pass);
1170 } else {
1171 repeat;
1172 }
1173 }
1174 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001175 [not do_fail] T_sacch.timeout {
1176 log("Timeout waiting for SACCH ", l3_exp);
1177 }
1178 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001179 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001181 }
1182 }
1183}
1184
Harald Welte55700662018-03-12 13:15:43 +01001185/* verify that given SACCH payload is not present */
1186private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1187 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001188 timer T_sacch := 3.0;
1189 L1CTL.clear;
1190 T_sacch.start;
1191 alt {
1192 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1193 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1194 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001195 setverdict(fail, "Received unexpected SACCH ", dl);
1196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001197 } else {
1198 repeat;
1199 }
1200 }
1201 [] L1CTL.receive { repeat; }
1202 [] T_sacch.timeout {
1203 setverdict(pass);
1204 }
1205 }
1206}
1207
Harald Welte629cc6b2018-03-11 17:19:05 +01001208/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001209private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1210 /* Set a known default SACCH filling for SI5 */
1211 var octetstring si5 := f_rnd_octstring(19);
1212 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1213
1214 f_l1_tune(L1CTL);
1215 RSL.clear;
1216
1217 /* activate the logical channel */
1218 f_est_dchan();
1219
1220 /* check that the specified SI5 value is actually sent */
1221 f_sacch_present(si5);
1222
1223 /* release the channel */
1224 RSL.clear;
1225 f_rsl_chan_deact();
1226 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1227}
1228testcase TC_sacch_filling() runs on test_CT {
1229 var ConnHdlr vc_conn;
1230 var ConnHdlrPars pars;
1231 f_init();
1232 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1233 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1234 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1235 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1236 vc_conn.done;
1237 }
1238 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001240}
1241
Harald Welte629cc6b2018-03-11 17:19:05 +01001242/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001243private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1244 /* Set a known default SACCH filling for SI5 */
1245 var octetstring si5 := f_rnd_octstring(19);
1246 var octetstring si5_diff := f_rnd_octstring(19);
1247 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1248
1249 f_l1_tune(L1CTL);
1250 RSL.clear;
1251
1252 log("Activating channel, expecting standard SI5");
1253 /* activate the logical channel */
1254 f_est_dchan();
1255 /* check that the specified SI5 value is actually sent */
1256 f_sacch_present(si5);
1257
1258 /* set channel-specific different SI5 */
1259 log("Setting channel specific SACCH INFO, expecting it");
1260 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1261 /* check that the specified lchan-specific value is now used */
1262 f_sacch_present(si5_diff);
1263
1264 /* deactivate the channel and re-activate it, this should result in default SI5 */
1265 log("De-activating and re-activating channel, expecting standard SI5");
1266 f_rsl_chan_deact();
1267 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1268 /* Verify that the TRX-wide default SACCH filling is present again */
1269 f_sacch_present(si5);
1270
1271 /* release the channel */
1272 RSL.clear;
1273 f_rsl_chan_deact();
1274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1275}
1276testcase TC_sacch_info_mod() runs on test_CT {
1277 var ConnHdlr vc_conn;
1278 var ConnHdlrPars pars;
1279 f_init();
1280 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1281 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1282 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1283 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1284 vc_conn.done;
1285 }
1286 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001288}
1289
Harald Welte075d84c2018-03-12 13:07:24 +01001290/* Test SACCH scheduling of multiple different SI message types */
1291private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1292 var octetstring si5 := f_rnd_octstring(19);
1293 var octetstring si5bis := f_rnd_octstring(19);
1294 var octetstring si5ter := f_rnd_octstring(19);
1295 var octetstring si6 := f_rnd_octstring(19);
1296
1297 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1298 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1300 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1301
1302 f_l1_tune(L1CTL);
1303 RSL.clear;
1304
1305 /* activate the logical channel */
1306 f_est_dchan();
1307 L1CTL.clear;
1308
1309 /* check that SACCH actually are received as expected */
1310 f_sacch_present(si5);
1311 f_sacch_present(si5bis);
1312 f_sacch_present(si5ter);
1313 f_sacch_present(si6);
1314
1315 /* release the channel */
1316 f_rsl_chan_deact();
1317 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1318}
1319testcase TC_sacch_multi() runs on test_CT {
1320 var ConnHdlr vc_conn;
1321 var ConnHdlrPars pars;
1322 f_init();
1323 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1324 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1325 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1326 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1327 vc_conn.done;
1328 }
1329 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001331}
1332
Harald Welte55700662018-03-12 13:15:43 +01001333/* Test if SACH information is modified as expected */
1334private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1335 var octetstring si5 := f_rnd_octstring(19);
1336 var octetstring si6 := f_rnd_octstring(19);
1337
1338 /* First, configure both SI5 and SI6 to be transmitted */
1339 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1340 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1341
1342 f_l1_tune(L1CTL);
1343 RSL.clear;
1344
1345 /* activate the logical channel */
1346 f_est_dchan();
1347 L1CTL.clear;
1348
1349 /* check that SACCH actually are received as expected */
1350 f_sacch_present(si5);
1351 f_sacch_present(si6);
1352
1353 /* disable SI6 */
1354 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1355
1356 /* check that SI5 is still transmitted */
1357 f_sacch_present(si5);
1358 /* check if SI6 is now gone */
1359 f_sacch_missing(si6);
1360
1361 /* release the channel */
1362 f_rsl_chan_deact();
1363 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1364}
1365testcase TC_sacch_multi_chg() runs on test_CT {
1366 var ConnHdlr vc_conn;
1367 var ConnHdlrPars pars;
1368 f_init();
1369 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1370 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1371 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1372 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1373 vc_conn.done;
1374 }
1375 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001377}
1378
Harald Weltec8d363c2019-05-19 20:36:48 +02001379/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1380private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1381 var octetstring si5 := f_rnd_octstring(19);
1382 var octetstring si6 := f_rnd_octstring(19);
1383 var octetstring si5_specific := f_rnd_octstring(19);
1384 var octetstring si6_specific := f_rnd_octstring(19);
1385
1386 /* First, configure both SI5 and SI6 to be transmitted */
1387 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1388 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1389
1390 f_l1_tune(L1CTL);
1391 RSL.clear;
1392
1393 /* activate channel with different SACCH filling */
1394 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1395 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1396 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1397 }));
1398 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1399 RSL_IE_Body:{sacch_info := sacch_info})) };
1400 f_est_dchan(more_ies := addl_ies);
1401
1402 /* check that SACCH actually are received as expected */
1403 f_sacch_present(si5_specific);
1404 f_sacch_present(si6_specific);
1405
1406 /* release the channel */
1407 f_rsl_chan_deact();
1408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1409}
1410testcase TC_sacch_chan_act() runs on test_CT {
1411 var ConnHdlr vc_conn;
1412 var ConnHdlrPars pars;
1413 f_init();
1414
1415 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1416 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1417 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1418 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1419 vc_conn.done;
1420 }
1421 /* TODO: do the above in parallel, rather than sequentially? */
1422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1423}
1424
Harald Welte8b01c792019-05-19 22:51:25 +02001425/* verify that SACCH DL transmission is started only if MS power IE present
1426 * see section 4.1.3 of 3GPP TS 48.058 */
1427private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1428 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001429 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001430
1431 f_l1_tune(L1CTL);
1432 RSL.clear;
1433
1434 /* Step 1: Activate ASYNC HO channel without MS power IE */
1435
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001436 var integer ho_ref := oct2int(f_rnd_octstring(1));
1437 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1438 RSL_IE_Body:{ handover_ref := ho_ref }));
1439 var RSL_IE_List addl_ies := {
1440 ho_ref_ie
1441 };
1442
Harald Welte8b01c792019-05-19 22:51:25 +02001443 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001444 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 +02001445 /* don't perform immediate assignment here, as we're testing non-IA case */
1446 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001447 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001448
1449 /* Verify that no DL SACCH is being received */
1450 f_sacch_missing(?);
1451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to start */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459
1460
1461 /* Step 2: Activate ASYNC HO channel with MS power IE */
1462
1463 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001464 addl_ies := {
1465 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001466 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1467 };
1468 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1469 /* don't perform immediate assignment here, as we're testing non-IA case */
1470 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001471 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001472
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001473 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1474 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1475 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001476
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001477 /* Send handover Access Burst and expect SACCH to remain present */
1478 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1479
1480 f_sacch_present(si5);
1481
Harald Welte8b01c792019-05-19 22:51:25 +02001482 f_rsl_chan_deact();
1483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1484}
1485testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init();
1489
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001490 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1491 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1492 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001493 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1494 vc_conn.done;
1495 }
1496 /* TODO: do the above in parallel, rather than sequentially? */
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
1499
1500/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1501 * see section 4.1.4 of 3GPP TS 48.058 */
1502private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1503 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001504 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1505
Harald Welte8b01c792019-05-19 22:51:25 +02001506 var RSL_IE_List addl_ies;
1507
1508 f_l1_tune(L1CTL);
1509 RSL.clear;
1510
1511 /* Step 1: Activate SYNC HO channel without MS power IE */
1512
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001513 var integer ho_ref := oct2int(f_rnd_octstring(1));
1514 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1515 RSL_IE_Body:{ handover_ref := ho_ref }));
1516 addl_ies := {
1517 ho_ref_ie
1518 };
1519
Harald Welte8b01c792019-05-19 22:51:25 +02001520 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001521 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 +02001522 /* don't perform immediate assignment here, as we're testing non-IA case */
1523 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001524 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001525
1526 /* Verify that no DL SACCH is being received */
1527 f_sacch_missing(?);
1528
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001529 /* Send handover Access Burst and expect SACCH to start */
1530 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1531
1532 f_sacch_present(si5);
1533
Harald Welte8b01c792019-05-19 22:51:25 +02001534 f_rsl_chan_deact();
1535 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1536
1537
1538 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1539
1540 /* Activate channel on BTS side */
1541 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001542 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001543 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1544 };
1545 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1546 /* don't perform immediate assignment here, as we're testing non-IA case */
1547 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001548 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001549
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001550 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1551 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1552 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001553
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001554 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001555 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1556
1557 f_sacch_present(si5);
1558
Harald Welte8b01c792019-05-19 22:51:25 +02001559 f_rsl_chan_deact();
1560 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1561
1562
1563 /* Step 2b: Activate SYNC HO channel with TA IE */
1564
1565 /* Activate channel on BTS side */
1566 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001567 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001568 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1569 };
1570 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1571 /* don't perform immediate assignment here, as we're testing non-IA case */
1572 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001573 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001574
1575 /* Verify that no DL SACCH is being received */
1576 f_sacch_missing(?);
1577
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001578 /* Send handover Access Burst and expect SACCH to start */
1579 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1580
1581 f_sacch_present(si5);
1582
Harald Welte8b01c792019-05-19 22:51:25 +02001583 f_rsl_chan_deact();
1584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1585
1586
1587 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1588
1589 /* Activate channel on BTS side */
1590 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001591 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001592 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1593 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1594 };
1595 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1596 /* don't perform immediate assignment here, as we're testing non-IA case */
1597 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001598 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001599
1600 /* Verify that DL SACCH is being received */
1601 f_sacch_present(si5);
1602
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001603 /* Send handover Access Burst and expect SACCH to remain present */
1604 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1605
1606 f_sacch_present(si5);
1607
Harald Welte8b01c792019-05-19 22:51:25 +02001608 f_rsl_chan_deact();
1609 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1610}
1611testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1612 var ConnHdlr vc_conn;
1613 var ConnHdlrPars pars;
1614 f_init();
1615
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001616 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1617 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1618 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001619 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1620 vc_conn.done;
1621 }
1622 /* TODO: do the above in parallel, rather than sequentially? */
1623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1624}
Harald Welte629cc6b2018-03-11 17:19:05 +01001625
1626
1627/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001628 * RACH Handling
1629 ***********************************************************************/
1630
Harald Welte8c24c2b2018-02-26 08:31:31 +01001631/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001632private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001633 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001634 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001635 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001636
Harald Welte8c24c2b2018-02-26 08:31:31 +01001637 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001638 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001639 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001640 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001641 if (emerg == true) {
1642 ra := f_rnd_ra_emerg();
1643 } else {
1644 ra := f_rnd_ra_cs();
1645 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001646 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1647 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001649 }
1650 fn_last := fn;
1651
1652 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001653 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001654 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001655 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001656 T.stop;
1657 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001658 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660 }
1661 [] RSL_CCHAN.receive { repeat; }
1662 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001663 test_failed := true;
1664 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001665 }
1666 }
1667 }
Maxba06feb2019-03-05 10:52:46 +01001668 if (test_failed) {
1669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001670 }
Maxba06feb2019-03-05 10:52:46 +01001671 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001673}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001674
Philipp Maier16ade782020-07-08 21:36:00 +02001675/* Normal variant */
1676testcase TC_rach_content() runs on test_CT {
1677 f_TC_rach_content(emerg := false);
1678}
1679
1680/* Emergency call variant */
1681testcase TC_rach_content_emerg() runs on test_CT {
1682 f_TC_rach_content(emerg := true);
1683}
1684
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1686testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001687 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001688 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001689 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001690 f_l1_tune(L1CTL);
1691
1692 var GsmFrameNumber fn_last := 0;
1693 for (var integer i := 0; i < 1000; i := i+1) {
1694 var OCT1 ra := f_rnd_ra_cs();
1695 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1696 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001698 }
1699 fn_last := fn;
1700 }
1701 var integer rsl_chrqd := 0;
1702 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001703 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001704 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001705 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001706 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001707 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001708 repeat;
1709 }
1710 [] RSL_CCHAN.receive { repeat; }
1711 [] T.timeout { }
1712 }
1713 if (rsl_chrqd == 1000) {
1714 setverdict(pass);
1715 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001719}
1720
Harald Welte3453ab42019-05-24 21:19:58 +02001721private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1722 var charstring bts_str := "bts " & int2str(bts_nr);
1723 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1724}
1725
1726/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1727private template integer tr_rach_slots_per_interval := (90 .. 130);
1728
1729/* Expect 0 RACH load on an idle BTS that has just started up */
1730testcase TC_rach_load_idle_thresh0() runs on test_CT {
1731 var ASP_RSL_Unitdata rx_ud;
1732
1733 f_init_vty_bsc();
1734 /* send load indications even at 0% load */
1735 f_vty_load_ind_thresh(0);
1736 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1737 f_sleep(2.0);
1738
1739 f_init();
1740
Harald Weltee37f9a52020-10-11 20:45:23 +02001741 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1742 alt {
1743 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1744 [] RSL_CCHAN.receive { repeat }
1745 }
1746
Harald Welte3453ab42019-05-24 21:19:58 +02001747 timer T := 5.0;
1748 T.start;
1749 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001750 [] 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 +02001751 setverdict(pass);
1752 repeat;
1753 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001754 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001755 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1756 repeat;
1757 }
1758 [] RSL_CCHAN.receive {
1759 repeat;
1760 }
1761 [] T.timeout { }
1762 }
1763
1764 f_vty_load_ind_thresh(10);
1765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1766}
1767
1768/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1769testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1770 var ASP_RSL_Unitdata rx_ud;
1771
1772 f_init_vty_bsc();
1773 f_init();
1774
1775 timer T := 5.0;
1776 T.start;
1777 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001778 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001779 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1780 repeat;
1781 }
1782 [] RSL_CCHAN.receive {
1783 repeat;
1784 }
1785 [] T.timeout {
1786 setverdict(pass);
1787 }
1788 }
1789
1790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1791}
1792
1793/* Expect 0 RACH load on an idle BTS that has just started up */
1794testcase TC_rach_load_count() runs on test_CT {
1795 var ASP_RSL_Unitdata rx_ud;
1796 var integer load_access_count := 0;
1797
1798 f_init_vty_bsc();
1799 /* send load indications even at 0% load */
1800 f_vty_load_ind_thresh(0);
1801 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1802 f_sleep(2.0);
1803 f_init();
1804
1805 f_init_l1ctl();
1806 f_sleep(1.0);
1807 f_l1_tune(L1CTL);
1808
Harald Welte52ae1682020-10-11 20:45:55 +02001809 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1810 alt {
1811 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1812 [] RSL_CCHAN.receive { repeat }
1813 }
1814
Harald Welte3453ab42019-05-24 21:19:58 +02001815 var GsmFrameNumber fn_last := 0;
1816 for (var integer i := 0; i < 1000; i := i+1) {
1817 var OCT1 ra := f_rnd_ra_cs();
1818 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1819 if (fn == fn_last) {
1820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1821 }
1822 fn_last := fn;
1823 }
1824
1825 timer T := 5.0;
1826 T.start;
1827 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001828 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001829 -> value rx_ud {
1830 var RSL_IE_Body ie;
1831 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1832 load_access_count := load_access_count + ie.rach_load.access_count;
1833 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1834 setverdict(fail, "Access count cannot be < Busy count");
1835 }
1836 repeat;
1837 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001838 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001839 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1840 repeat;
1841 }
1842 [] RSL_CCHAN.receive {
1843 repeat;
1844 }
1845 [] T.timeout { }
1846 }
1847 if (load_access_count == 1000) {
1848 setverdict(pass);
1849 } else {
1850 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1851 }
1852
1853 f_vty_load_ind_thresh(10);
1854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1855}
1856
Harald Welte54a2a2d2018-02-26 09:14:05 +01001857private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001858 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001859 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001860 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001861 f_sleep(0.5);
1862
1863 /* Transmit RACH request + wait for confirmation */
1864 var OCT1 ra := f_rnd_ra_cs();
1865 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1866
1867 /* Check for expected result */
1868 timer T := 1.5;
1869 T.start;
1870 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001871 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001872 setverdict(pass);
1873 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001874 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001876 }
1877 [] RSL_CCHAN.receive { repeat; }
1878 [not expect_pass] T.timeout {
1879 setverdict(pass);
1880 }
1881 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001883 }
1884 }
1885}
1886
1887/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1888testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001889 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001890 f_init_l1ctl();
1891 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001892 f_sleep(1.0);
1893
1894 /* default max-ta is 63 (full range of GSM timing advance */
1895
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001896 /* We allow early arrival up to 2 symbols */
1897 f_rach_toffs(-1*256, true);
1898 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001899 f_rach_toffs(-10*256, false);
1900
1901 /* 0 / 32 / 63 bits is legal / permitted */
1902 f_rach_toffs(0, true);
1903 f_rach_toffs(32*256, true);
1904 f_rach_toffs(63*256, true);
1905
1906 /* more than 63 bits is not legal / permitted */
1907 f_rach_toffs(64*256, false);
1908 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001910}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001911
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001912private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001913 var GsmFrameNumber fn;
1914 var RSL_Message rm;
1915
1916 f_l1_tune(L1CTL);
1917 RSL.clear;
1918
1919 /* Generate a random Handover Reference */
1920 var integer ho_ref := oct2int(f_rnd_octstring(1));
1921
1922 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1923 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1924 RSL_IE_Body:{ handover_ref := ho_ref }));
1925
1926 /* Activate a channel on the BTS side (no encryption) */
1927 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1928 act_type := t_RSL_IE_ActType_HO_SYNC);
1929
1930 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1931 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001932 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001933
1934 /* Send handover Access Burst */
1935 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1936
1937 /* TODO: test mismatching Handover Reference, and missing IE */
1938
1939 /* Wait for handover detection */
1940 timer T := 3.0;
1941 T.start;
1942 alt {
1943 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1944 log("Handover RACH has been detected: ", rm);
1945 setverdict(pass);
1946 }
1947 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1949 log2str("RSL_CHAN_RQD was not expected: ", rm));
1950 }
1951 [] RSL.receive { repeat; }
1952 [] T.timeout {
1953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1954 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1955 }
1956 }
1957
1958 /* Release the channel */
1959 f_rsl_chan_deact();
1960 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1961}
1962
1963/* Test handover RACH detection */
1964testcase TC_ho_rach() runs on test_CT {
1965 var ConnHdlrPars pars;
1966 var ConnHdlr vc_conn;
1967
1968 f_init();
1969
1970 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1971 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1972 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1973 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1974 vc_conn.done;
1975 }
1976
1977 /* TODO: do the above in parallel, rather than sequentially? */
1978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1979}
1980
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001981/* Test sending of the RR Physical Information message on DCCH */
1982private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1983 var PDU_ML3_NW_MS dcch_pdu;
1984 var integer count := 0;
1985 var L1ctlDlMessage dl;
1986 timer T;
1987
1988 f_l1_tune(L1CTL);
1989 RSL.clear;
1990
1991 /* Generate a random Handover Reference */
1992 var integer ho_ref := oct2int(f_rnd_octstring(1));
1993
1994 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1995 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1996 RSL_IE_Body:{ handover_ref := ho_ref }));
1997
1998 /* Activate a channel on the BTS side (no encryption) */
1999 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2000 act_type := t_RSL_IE_ActType_HO_SYNC);
2001
2002 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2003 * waiting for Immediate Assignment and sending of an Access Burst. */
2004 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2005
2006 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2007 * context means any L2 frames, not only the RR Physical Information. */
2008 T.start(2.0);
2009 L1CTL.clear;
2010 alt {
2011 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2012 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2013 T.stop;
2014 }
2015 [] L1CTL.receive { repeat; }
2016 [] T.timeout { setverdict(pass); }
2017 }
2018
2019 /* Send handover Access Burst */
2020 log("Sending handover Access Burst");
2021 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2022
2023 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2024 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2025 L1CTL.clear;
2026 alt {
2027 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2028 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2029 log("Rx RR Physical Information: ", dcch_pdu);
2030 /* Wait until the count reaches Ny1 */
2031 count := count + 1;
2032 if (count < mp_ho_ny1)
2033 { repeat; }
2034 setverdict(pass);
2035 }
2036 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2037 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2039 }
2040 [] L1CTL.receive { repeat; }
2041 [] T.timeout {
2042 setverdict(fail, "Timeout waiting for RR Physical Information");
2043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2044 }
2045 }
2046
2047 /* Release the channel */
2048 f_rsl_chan_deact();
2049 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2050}
2051testcase TC_ho_physical_info() runs on test_CT {
2052 var ConnHdlrPars pars;
2053 var ConnHdlr vc_conn;
2054
2055 f_init();
2056
2057 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2058 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2059 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2060 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2061 vc_conn.done;
2062 }
2063
2064 /* TODO: do the above in parallel, rather than sequentially? */
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066}
2067
Harald Welte93640c62018-02-25 16:59:33 +01002068/***********************************************************************
2069 * Measurement Processing / Reporting
2070 ***********************************************************************/
2071
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002072private template (value) LapdmAddressField
2073ts_LapdmAddr(template (value) LapdmSapi sapi,
2074 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002075 spare := '0'B,
2076 lpd := 0,
2077 sapi := sapi,
2078 c_r := c_r,
2079 ea := true
2080}
2081
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002082private template (value) LapdmFrameAB
2083ts_LAPDm_AB(template (value) LapdmSapi sapi,
2084 template (value) GsmRrL3Message l3,
2085 template (value) boolean c_r := false,
2086 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002087 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002088 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002089 len := 0, /* overwritten */
2090 m := false,
2091 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002092 payload := enc_GsmRrL3Message(valueof(l3)),
2093 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002094}
2095
2096/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002097private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002098 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002099 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002100
Harald Weltef8df4cb2018-03-10 15:15:08 +01002101 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002102 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002103
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002104 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002105 g_pars.l1_pars.meas_ul.full.rxlev,
2106 g_pars.l1_pars.meas_ul.sub.rxlev,
2107 g_pars.l1_pars.meas_ul.full.rxqual,
2108 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002109 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002110
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002111 var template (value) SacchL1Header l1h := ts_SacchL1Header(
2112 g_pars.l1_pars.ms_power_level, false,
2113 g_pars.l1_pars.ms_actual_ta);
2114
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002115 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2116 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002117
2118 log("Sending Measurement Report: ", l1h, l2);
2119 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002120 repeat;
2121 }
2122}
2123
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002124/* handle incoming downlink SACCH, decode the L1 header into the given record */
2125private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2126 boolean do_apply := true)
2127runs on ConnHdlr
2128{
2129 var L1ctlDlMessage l1_dl;
2130
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2132 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2133 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2134 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2135
2136 if (do_apply) {
2137 /* Update TA and MS power to follow what BTS requests */
2138 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2139 }
2140 }
2141}
2142
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002143private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002144 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002146 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2147 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002148 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2149 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002150 repeat;
2151 }
2152}
2153
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002154private altstep as_l1_tch_loop() runs on ConnHdlr {
2155 var L1ctlDlMessage l1_dl;
2156 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2157 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002158
2159 /* occasionaly inject FACCH frames into the uplink */
2160 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2161 var octetstring pl := '010301'O;
2162 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2163 f_pad_oct(pl, 23, '2B'O)));
2164 } else {
2165 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2166 l1_dl.payload.traffic_ind.data));
2167 }
2168
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002169 repeat;
2170 }
2171}
2172
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002173private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002174 uint6_t rxlev,
2175 uint3_t rxqual
2176}
2177
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002178private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002179 MeasElem full,
2180 MeasElem sub
2181}
2182
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002183private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002184 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002185 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002186 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002187 MeasElemFS meas_ul,
2188 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002189 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002190 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002191 uint8_t ms_actual_ta,
2192 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002193}
2194
2195/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2196private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2197 return 63 + (toffs256s/256);
2198}
2199
Harald Welted5684392018-03-10 18:22:04 +01002200private function f_max(integer a, integer b) return integer {
2201 if (a > b) {
2202 return a;
2203 } else {
2204 return b;
2205 }
2206}
2207
2208private function f_min(integer a, integer b) return integer {
2209 if (a < b) {
2210 return a;
2211 } else {
2212 return b;
2213 }
2214}
2215
2216/* compute negative tolerance val-tolerance, ensure >= min */
2217private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2218 val := val - tolerance;
2219 return f_max(val, min);
2220}
2221
2222/* compute positive tolerance val+tolerance, ensure <= max */
2223private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2224 val := val + tolerance;
2225 return f_min(val, max);
2226}
2227
2228/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2229private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2230return template integer {
2231 var template integer ret;
2232 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2233 return ret;
2234}
2235
2236
Harald Welte70767382018-02-21 12:16:40 +01002237/* build a template for matching measurement results against */
2238private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2239 var ConnL1Pars l1p := g_pars.l1_pars;
2240 var template RSL_IE_UplinkMeas ul_meas := {
2241 len := 3,
2242 rfu := '0'B,
2243 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002244 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002245 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002246 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002247 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002248 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2249 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002250 supp_meas_info := omit
2251 };
Harald Welte685d5982018-02-27 20:42:05 +01002252 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002253 ul_meas.len := (3+8);
2254 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002255 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002256 toa256_min := ?,
2257 toa256_max := ?,
2258 toa256_std_dev := ?
2259 }
Harald Welte685d5982018-02-27 20:42:05 +01002260 }
Harald Welte70767382018-02-21 12:16:40 +01002261 var template RSL_IE_BS_Power bs_power := {
2262 reserved := 0,
2263 epc := false,
2264 fpc := false,
2265 power_level := l1p.bs_power_level
2266 };
2267 var template RSL_IE_L1Info l1_info := {
2268 ms_power_lvl := l1p.ms_power_level,
2269 fpc := false,
2270 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002271 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002272 };
2273 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002274 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002275 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2276 ?, t_toffs);
2277}
2278
Philipp Maierdd841d32019-12-17 14:44:54 +01002279/* build a template for matching measurement results that do not contain any
2280 * MS related measurement (l1_info, l3_info and ms timing offset). */
2281private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2282 var ConnL1Pars l1p := g_pars.l1_pars;
2283 var template RSL_IE_UplinkMeas ul_meas := {
2284 len := 3,
2285 rfu := '0'B,
2286 dtx_d := l1p.dtx_enabled,
2287 rxlev_f_u := ?,
2288 reserved1 := '00'B,
2289 rxlev_s_u := ?,
2290 reserved2 := '00'B,
2291 rxq_f_u := ?,
2292 rxq_s_u := ?,
2293 supp_meas_info := omit
2294 };
2295 if (l1p.toa256_enabled) {
2296 ul_meas.len := (3+8);
2297 ul_meas.supp_meas_info := {
2298 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2299 toa256_min := ?,
2300 toa256_max := ?,
2301 toa256_std_dev := ?
2302 }
2303 }
2304 var template RSL_IE_BS_Power bs_power := {
2305 reserved := 0,
2306 epc := false,
2307 fpc := false,
2308 power_level := l1p.bs_power_level
2309 };
2310
2311 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2312}
2313
Harald Welte70767382018-02-21 12:16:40 +01002314/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002315private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002316 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002317 var boolean chan_est := false;
2318
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002319 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002320
2321 /* Receive osmocom specific measurement reports. This is the normal
2322 * case. Here we verify that the measurement reports we sent are
2323 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002324 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2325 /* increment counter of next to-be-expected meas rep */
2326 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2327 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002328 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002329
2330 /* The following two cases may only happen in the beginning
2331 * of the channel establishment phase. Once we have received
2332 * the "our" measurement report the first time, the channel
2333 * is established and empty or hardcoded TRXCON reports must
2334 * not occur anymore. */
2335 chan_est := true;
2336
2337 repeat;
2338 }
2339
2340 /* When the BTS has established the channel, the MS might need slightly
2341 * more time to establish the channel and actually start sending. The
2342 * result is then a measurement report that just lacks the measurement
2343 * information of the MS. This is normal and we tolerate this behavior. */
2344 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2345 /* increment counter of next to-be-expected meas rep */
2346 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2347 /* Re-start the timer expecting the next MEAS RES */
2348 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002349 repeat;
2350 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002351
2352 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2353 * measurements if the TTCN3 side does not supply measurement input in
2354 * time. In those cases TRXCON will either use a cached measurement
2355 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2356 * report the templates above will not match. We tolerate this
2357 * behavior, but only once. */
2358 [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 +01002359 /* increment counter of next to-be-expected meas rep */
2360 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2361 if (g_first_meas_res) {
2362 g_first_meas_res := false;
2363 repeat;
2364 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002366 }
Harald Welte70767382018-02-21 12:16:40 +01002367 }
2368 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002370 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002371 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002373 }
2374}
2375
Harald Weltee613f962018-04-18 22:38:16 +02002376private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2377 select (rsl_alg_id) {
2378 case (RSL_ALG_ID_A5_0) { return 0; }
2379 case (RSL_ALG_ID_A5_1) { return 1; }
2380 case (RSL_ALG_ID_A5_2) { return 2; }
2381 case (RSL_ALG_ID_A5_3) { return 3; }
2382 case (RSL_ALG_ID_A5_4) { return 4; }
2383 case (RSL_ALG_ID_A5_5) { return 5; }
2384 case (RSL_ALG_ID_A5_6) { return 6; }
2385 case (RSL_ALG_ID_A5_7) { return 7; }
2386 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2388 /* Make compiler happy by calling mtc.stop here. It is already
2389 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002390 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002391 }
2392 }
2393}
2394
2395private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2396 select (rsl_alg_id) {
2397 case (RSL_ALG_ID_A5_1) { return '000'B; }
2398 case (RSL_ALG_ID_A5_2) { return '001'B; }
2399 case (RSL_ALG_ID_A5_3) { return '010'B; }
2400 case (RSL_ALG_ID_A5_4) { return '011'B; }
2401 case (RSL_ALG_ID_A5_5) { return '100'B; }
2402 case (RSL_ALG_ID_A5_6) { return '101'B; }
2403 case (RSL_ALG_ID_A5_7) { return '110'B; }
2404 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2406 /* Make compiler happy by calling mtc.stop here. It is already
2407 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002408 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002409 }
2410 }
2411}
2412
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002413/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2414private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2415 var GsmFrameNumber fn;
2416 timer T := 8.0;
2417
2418 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2419 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2420
2421 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2422 /* Send the actual RACH */
2423 fn := f_L1CTL_RACH(L1CTL, ra);
2424
2425 T.start;
2426 alt {
2427 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2428 [] T.timeout {
2429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2430 }
2431 }
2432 T.stop
2433 return fn;
2434}
Harald Weltee613f962018-04-18 22:38:16 +02002435
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002436/* Tune to a dedicated channel: L1CTL only */
2437private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002438 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002439 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002440 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002441 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002442 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002443 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002444 pars.fhp.maio_hsn.hsn,
2445 pars.fhp.maio_hsn.maio,
2446 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002447 }
2448}
2449
Harald Welte70767382018-02-21 12:16:40 +01002450/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002451private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002452 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002453
2454 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002455 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002456
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002457 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002458 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002459 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002460 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002461 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2462 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002463 }
2464
Harald Welte70767382018-02-21 12:16:40 +01002465 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002466 f_l1ctl_est_dchan(L1CTL, g_pars);
2467
Harald Weltee613f962018-04-18 22:38:16 +02002468 /* enable encryption, if requested */
2469 if (encr_enable) {
2470 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2471 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2472 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002473
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002474 /* Send TCH Mode Request to the L1 if needed */
2475 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2476 var L1ctlTchMode tch_mode;
2477
2478 select (g_pars.chan_mode.coding_alg_rate) {
2479 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2480 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2481 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2482 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2483 case else {
2484 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2485 " is not supported by the L1, falling back to signalling");
2486 tch_mode := L1CTL_CHAN_MODE_SIGN;
2487 }
2488 }
2489
2490 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2491 }
2492
Harald Weltefa45e9e2018-03-10 18:59:03 +01002493 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002494}
2495
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002496/* Initialize and start the RTP emulation component for a ConnHdlr */
2497friend function f_rtpem_activate(inout octetstring payload,
2498 RtpemConfig cfg := c_RtpemDefaultCfg,
2499 RtpemMode mode := RTPEM_MODE_BIDIR)
2500runs on ConnHdlr {
2501 /* Step 0: initialize, connect and start the emulation component */
2502 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2503 map(vc_RTPEM:RTP, system:RTP);
2504 map(vc_RTPEM:RTCP, system:RTCP);
2505 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2506 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2507 vc_RTPEM.start(RTP_Emulation.f_main());
2508
2509 /* Step 1: configure the RTP parameters */
2510 var integer payload_len := 0;
2511 var octetstring hdr := ''O;
2512
2513 select (g_pars.chan_mode) {
2514 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2515 { payload_len := 33; hdr := 'D0'O; }
2516 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2517 { payload_len := 15; hdr := '00'O; }
2518 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2519 { payload_len := 31; hdr := 'C0'O; }
2520 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2521 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2523 }
2524 }
2525
2526 /* Pad the payload to conform the expected length */
2527 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2528 cfg.tx_fixed_payload := payload;
2529 f_rtpem_configure(RTPEM_CTRL, cfg);
2530
2531 /* Step 2: bind the RTP emulation to the configured address */
2532 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2533 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2534
2535 /* Step 3: send CRCX with the configured address/port to the IUT */
2536 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2537 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2538 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2539 "IPA CRCX ACK");
2540
2541 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2542 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2543 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2544 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2545
2546 /* Step 5: set the given RTP emulation mode */
2547 f_rtpem_mode(RTPEM_CTRL, mode);
2548}
2549
Harald Welte70767382018-02-21 12:16:40 +01002550/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002551private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002552 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002553 RSL.clear;
2554
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002555 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002556 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002557 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002558 }
Harald Welte70767382018-02-21 12:16:40 +01002559
2560 f_est_dchan();
2561
2562 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2563 * RSL measurement reports on Abis side */
2564 timer T := 8.0;
2565 T.start;
2566 alt {
2567 [] as_l1_sacch();
2568 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002569 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002570 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002571 [] L1CTL.receive { repeat; }
2572 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002573 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002574 * of any earlier errors, so if we reach this timeout, we're good */
2575 setverdict(pass);
2576 }
2577 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002579 }
2580 }
2581 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002582 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002583}
Harald Welte0472ab42018-03-12 15:02:26 +01002584
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002585/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2586private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002587 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002588 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2589 timer Tup := 10.0;
2590 Tup.start;
2591 alt {
2592 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2593 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2594 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002595
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002596 if (rx_lvl != max_rx_lvl) {
2597 repeat;
2598 }
2599 Tup.stop;
2600 }
2601 [] L1CTL.receive { repeat; }
2602 [] Tup.timeout {
2603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2604 log2str("Didn't reach full power ", max_rx_lvl));
2605 }
2606 }
2607 return max_rx_lvl;
2608}
2609
2610/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2611private function f_verify_ramp_up() runs on ConnHdlr {
2612 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002613 var integer initial_rx_lvl := -1;
2614 var integer last_rx_lvl := -1;
2615 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2616
2617 timer T := 2.0;
2618 alt {
2619 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2620 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2621 log("Received rx_level=", rx_lvl);
2622 if (initial_rx_lvl == -1) {
2623 initial_rx_lvl := rx_lvl;
2624 last_rx_lvl := rx_lvl;
2625
2626 /* Expect a somehow low value during first received messages */
2627 if (initial_rx_lvl >= max_rx_lvl / 2) {
2628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2629 log2str("Detected high initial tx power during ramp up: ",
2630 initial_rx_lvl , ", full power is", max_rx_lvl));
2631 }
2632 }
2633
2634 /* received Rx level bigger than maximum allowed power by CN */
2635 if (rx_lvl > max_rx_lvl) {
2636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2637 log2str("Detected Tx power higher than full power: ",
2638 rx_lvl , " > ", max_rx_lvl));
2639 }
2640
2641 /* Make sure it never decreases, since we are rumping up */
2642 if (last_rx_lvl > rx_lvl) {
2643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2644 log2str("Detected Tx power decrease during ramp up: ",
2645 last_rx_lvl , " -> ", rx_lvl));
2646 }
2647
2648 if (rx_lvl == max_rx_lvl and not T.running) {
2649 /* We reached the maximum power, start timer and receive
2650 /* a few more to make sure we don't surpass it */
2651 log("Reached full power, wating a bit more until success");
2652 T.start;
2653 }
2654
2655 last_rx_lvl := rx_lvl;
2656 repeat;
2657 }
2658 [] L1CTL.receive { repeat; }
2659 [] T.timeout { }
2660 }
2661
2662 /* We didn't increase tx power during ramp up */
2663 if (initial_rx_lvl < last_rx_lvl) {
2664 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2665 } else {
2666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2667 log2str("No Tx power increase during whole ramp up: ",
2668 initial_rx_lvl , " -> ", last_rx_lvl));
2669 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002670}
2671
2672/* verify BTS ramps power down to rx_level 0 */
2673private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2674 var L1ctlDlMessage l1_dl;
2675 var integer last_rx_lvl := max_rx_lvl;
2676
2677 timer Tdown := 5.0;
2678 Tdown.start;
2679 alt {
2680 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2681 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2682 log("Received rx_level=", rx_lvl);
2683
2684 /* received Rx level bigger than maximum allowed power by CN */
2685 if (rx_lvl > max_rx_lvl) {
2686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2687 log2str("Detected Tx power higher than full power: ",
2688 rx_lvl , " > ", max_rx_lvl));
2689 }
2690
2691 /* Make sure it never increases, since we are rumping down */
2692 if (last_rx_lvl < rx_lvl) {
2693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2694 log2str("Detected Tx power increase during ramp up: ",
2695 last_rx_lvl , " -> ", rx_lvl));
2696 }
2697
2698 last_rx_lvl := rx_lvl;
2699 if (last_rx_lvl != 0) {
2700 repeat;
2701 }
2702 /* we reached power level 0, we are done */
2703 Tdown.stop;
2704 }
2705 [] L1CTL.receive { repeat; }
2706 [] Tdown.timeout { }
2707 }
2708
2709 /* We didn't increase tx power during ramp down */
2710 if (max_rx_lvl > last_rx_lvl) {
2711 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2712 } else {
2713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2714 log2str("No Tx power decrease during whole ramp down: ",
2715 max_rx_lvl , " -> ", last_rx_lvl));
2716 }
2717}
2718
2719/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002720private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002721 f_l1_tune(L1CTL);
2722 RSL.clear;
2723
2724 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002725
2726 setverdict(pass);
2727}
2728testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2729 var ConnHdlr vc_conn;
2730 var ConnHdlrPars pars;
2731 f_init();
2732 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2733 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2734 pcu_comp := false, trxc_comp := true);
2735 vc_conn.done;
2736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2737}
2738
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002739/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002740private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002741 f_connhdlr_init_vty_bsc();
2742
2743 f_l1_tune(L1CTL);
2744 RSL.clear;
2745
2746 /* Wait until BTS is started and at full power */
2747 var integer max_rx_lvl := f_wait_ramp_up();
2748 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2749
2750 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2751 f_verify_ramp_down(max_rx_lvl);
2752
2753 setverdict(pass);
2754}
2755testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2756 var ConnHdlr vc_conn;
2757 var ConnHdlrPars pars;
2758 f_init();
2759 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2760 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2761 pcu_comp := false, trxc_comp := true);
2762 vc_conn.done;
2763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2764}
2765
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002766/* Verify Tx power:
2767 * + ramping down during ADM state UNLOCKED->LOCKED
2768 * + ramping up during ADM state LOCKED->UNLOCKED
2769 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002770private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002771 var L1ctlDlMessage l1_dl;
2772 var integer last_rx_lvl;
2773
2774 f_connhdlr_init_vty_bsc();
2775
2776 f_l1_tune(L1CTL);
2777 RSL.clear;
2778
2779 /* Wait until BTS is started and at full power */
2780 var integer max_rx_lvl := f_wait_ramp_up();
2781 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2782
2783 log("ADM STATE UNLOCKED->LOCKED");
2784 f_vty_enter_cfg_trx(BSCVTY);
2785 f_vty_transceive(BSCVTY, "rf_locked 1");
2786 last_rx_lvl := max_rx_lvl;
2787 f_verify_ramp_down(max_rx_lvl);
2788
2789 /* Let some time after we received 0dBm, then check we don't receive BCCH
2790 * anymore because scheduler has stopped after ramping down */
2791 f_sleep(2.0);
2792 L1CTL.clear;
2793 timer Tlocked := 2.0;
2794 Tlocked.start;
2795 alt {
2796 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2798 log2str("Received data_ind during rf_locked: ", l1_dl));
2799 }
2800 [] L1CTL.receive { repeat; }
2801 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2802 }
2803
2804 log("ADM STATE LOCKED->UNLOCKED");
2805 f_vty_transceive(BSCVTY, "rf_locked 0");
2806 f_verify_ramp_up();
2807 setverdict(pass);
2808}
2809testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2810 var ConnHdlr vc_conn;
2811 var ConnHdlrPars pars;
2812 f_init();
2813 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2814 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2815 pcu_comp := false, trxc_comp := true);
2816 vc_conn.done;
2817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2818}
2819
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002820private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002821 timer T := 8.0;
2822 T.start;
2823 var RSL_Message rsl;
2824 alt {
2825 [] as_l1_sacch();
2826 [] L1CTL.receive { repeat; }
2827 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2828 if (rsl.ies[3].body.bs_power.power_level == level) {
2829 setverdict(pass)
2830 } else {
2831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2832 }
2833 }
2834 [] T.timeout {
2835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2836 }
2837 }
2838}
2839
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002840/* See if the RSL MEASurement RESult contains expeced BS power level
2841 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002842private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002843 f_l1_tune(L1CTL);
2844 RSL.clear;
2845
2846 if (mp_bts_trxc_port != -1) {
2847 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2848 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2849 }
2850
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002851 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002852 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2853 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2854
2855 f_est_dchan(more_ies :={valueof(pwr)});
2856
2857 f_check_meas_bs_power_level(pwr_var);
2858
2859 f_rsl_chan_deact();
2860 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2861}
2862
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002863/* See if the RSL MEASurement RESult contains expeced BS power level
2864 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002865private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002866 f_l1_tune(L1CTL);
2867 RSL.clear;
2868
2869 if (mp_bts_trxc_port != -1) {
2870 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2871 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2872 }
2873
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002874 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002875 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2876
2877 f_est_dchan();
2878
2879 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2880
2881 f_check_meas_bs_power_level(pwr_var);
2882
2883 f_rsl_chan_deact();
2884 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2885}
2886
2887testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2888 var ConnHdlr vc_conn;
2889 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002890
Eric Wildae8f2622019-06-18 17:05:11 +02002891 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002892
2893 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2894 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2895 pcu_comp := false, trxc_comp := true);
2896 vc_conn.done;
2897
Eric Wildae8f2622019-06-18 17:05:11 +02002898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2899}
2900
2901testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2902 var ConnHdlr vc_conn;
2903 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002904
Eric Wildae8f2622019-06-18 17:05:11 +02002905 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002906
2907 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2908 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2909 pcu_comp := false, trxc_comp := true);
2910 vc_conn.done;
2911
Eric Wildae8f2622019-06-18 17:05:11 +02002912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2913}
2914
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002915/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2916 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2917 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002918private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002919 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002920 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002921
2922 f_trxc_fake_rssi(rxlev2dbm(10));
2923 f_l1_tune(L1CTL);
2924 RSL.clear;
2925
2926 var RSL_IE_List addl_ies;
2927 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2928
2929 addl_ies := {
2930 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2931 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2932 };
2933
2934 /* establish with power parameters */
2935 f_est_dchan(more_ies := addl_ies);
2936
2937 /* set a high value to ensure L1 power control level increases */
2938 f_trxc_fake_rssi(rxlev2dbm(20));
2939
2940 timer T2 := 6.0;
2941 T2.start;
2942 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002943 [] as_l1_sacch_l1h(l1h) {
2944 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002945 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002946 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002947 T2.stop;
2948 }
2949 [] L1CTL.receive { repeat; }
2950 [] T2.timeout {
2951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2952 "Power Level in L1 header has not increased sufficiently");
2953 }
2954 }
2955
2956 /* set a low value to ensure L1 power control level decreases */
2957 f_trxc_fake_rssi(rxlev2dbm(0));
2958
2959 timer T4 := 6.0;
2960 T4.start;
2961 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002962 [] as_l1_sacch_l1h(l1h) {
2963 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002964 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002965 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002966 T4.stop;
2967 setverdict(pass, "Power level in L1 decreased/increased as expected");
2968 }
2969 [] L1CTL.receive { repeat; }
2970 [] T4.timeout {
2971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2972 "Power Level in L1 header has not decreased sufficiently");
2973 }
2974 }
2975
2976 f_rsl_chan_deact();
2977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2978
2979}
2980
2981/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002982private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002983 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002985
2986 /* set a low value to ensure power increases */
2987 f_trxc_fake_rssi(rxlev2dbm(10));
2988 f_l1_tune(L1CTL);
2989 RSL.clear;
2990
2991 var RSL_IE_List addl_ies;
2992 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2993
2994 addl_ies := {
2995 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2996 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2997 };
2998
2999 /* establish with power parameters */
3000 f_est_dchan(more_ies := addl_ies);
3001
3002 timer T1 := 10.0;
3003 T1.start;
3004 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003005 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003006 [] L1CTL.receive { repeat; }
3007 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003008 if (not isbound(l1h)) {
3009 setverdict(fail, "No SACCH blocks were received");
3010 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003011 setverdict(fail, "Power level in L1 header should not have changed");
3012 }
3013 }
3014 }
3015
3016 f_rsl_chan_deact();
3017 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3018
3019}
3020
3021/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003022private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003023 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003024 var uint5_t pwr_var := 15;
3025 var uint5_t pwr_max_var := f_get_max_power_from_band();
3026
3027 /* set a low value to ensure power increases */
3028 f_trxc_fake_rssi(rxlev2dbm(10));
3029 f_l1_tune(L1CTL);
3030 RSL.clear;
3031
3032 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3033 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3034
3035 /* establish with fixed power level */
3036 f_est_dchan(more_ies :={valueof(pwr)});
3037
3038 /* check our initial power level */
3039 f_wait_for_l1_power_level(pwr_var);
3040
3041 /* update power param to enable power loop
3042 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3043 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3044
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003045 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3046 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3047 * Add an extra offset to avoid race conditions: +1.92s. */
3048 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003049 T1.start;
3050 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003051 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003052 [] L1CTL.receive { repeat; }
3053 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003054 if (not isbound(l1h)) {
3055 setverdict(fail, "No SACCH blocks were received");
3056 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003057 setverdict(pass, "Power level in L1 header reduced as expected");
3058 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003059 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3060 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003061 }
3062 }
3063 }
3064
3065 f_rsl_chan_deact();
3066 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3067
3068}
3069
3070/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003071private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003072 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003073
3074 /* set a high value to ensure power decreases */
3075 f_trxc_fake_rssi(rxlev2dbm(50));
3076 f_l1_tune(L1CTL);
3077 RSL.clear;
3078
3079 var uint5_t pwr_var := 5;
3080 var uint5_t pwr_target_val := 15;
3081
3082 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3083 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3084
3085 /* establish with fixed power level */
3086 f_est_dchan(more_ies :={valueof(pwr)});
3087
3088 /* check our initial power level */
3089 f_wait_for_l1_power_level(pwr_var);
3090
3091 /* update power param to enable power loop
3092 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003093 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003094
3095 /* wait, then check that our power level was increased */
3096 timer T1 := 10.0;
3097 T1.start;
3098 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003099 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003100 [] L1CTL.receive { repeat; }
3101 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003102 if (not isbound(l1h)) {
3103 setverdict(fail, "No SACCH blocks were received");
3104 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3105 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003106 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003107 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003108 }
3109 }
3110 }
3111
3112 f_rsl_chan_deact();
3113 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3114
3115}
3116
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003117/* See if the power level remains constant when MS Power Parameters IE
3118 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003119private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003120 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003121
3122 /* set a high value to ensure power decreases */
3123 f_trxc_fake_rssi(rxlev2dbm(50));
3124 f_l1_tune(L1CTL);
3125 RSL.clear;
3126
3127 var uint5_t pwr_var := 5;
3128
3129 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3130 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3131
3132 /* establish with fixed power level */
3133 f_est_dchan(more_ies :={valueof(pwr)});
3134
3135 /* check our initial power level */
3136 f_wait_for_l1_power_level(pwr_var);
3137
3138 /* wait, then check that our power level did not change */
3139 timer T1 := 10.0;
3140 T1.start;
3141 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003142 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3143 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3145 "BS power control should not be active unless we receive a power parameters IE!");
3146 }
3147 repeat;
3148 }
3149 [] L1CTL.receive { repeat; }
3150 [] T1.timeout { setverdict(pass); }
3151 }
3152
3153 f_rsl_chan_deact();
3154 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3155
3156}
3157
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003158/* See if the power level remains constant when MS Power Parameters IE
3159 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003160private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003161 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003162
3163 /* set a high value to ensure power decreases */
3164 f_trxc_fake_rssi(rxlev2dbm(50));
3165 f_l1_tune(L1CTL);
3166 RSL.clear;
3167
3168 var uint5_t pwr_var := 5;
3169
3170 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3171 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3172
3173 /* establish with fixed power level */
3174 f_est_dchan(more_ies :={valueof(pwr)});
3175
3176 /* check our initial power level */
3177 f_wait_for_l1_power_level(pwr_var);
3178
3179 /* pwr control without power params IE, should NOT activate MS power control*/
3180 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3181
3182 /* wait, then check that our power level did not change */
3183 timer T1 := 10.0;
3184 T1.start;
3185 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003186 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3187 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3189 "BS power control should not be active unless we receive a power parameters IE!");
3190 }
3191 repeat;
3192 }
3193 [] L1CTL.receive { repeat; }
3194 [] T1.timeout { setverdict(pass); }
3195 }
3196
3197 f_rsl_chan_deact();
3198 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3199
3200}
3201
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003202private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003203 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003204 timer T0 := 10.0;
3205 T0.start;
3206 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003207 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3208 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3210 "Power level in L1 header != signaled (RSL) power level.");
3211 }
3212 }
3213 [] L1CTL.receive { repeat; }
3214 [] T0.timeout {
3215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3216 "Timeout waiting for initial power level");
3217 }
3218 }
3219 T0.stop;
3220}
3221
3222private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3223 var IntegerRecord min_dbm_level;
3224 var IntegerRecord max_dbm_level;
3225 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3226
3227 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3228 if (min_dbm_level[i] == level) {
3229 return true;
3230 }
3231 }
3232 return false;
3233}
3234
3235private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3236 var IntegerRecord min_dbm_level;
3237 var IntegerRecord max_dbm_level;
3238 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3239
3240 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3241 if (max_dbm_level[i] == level) {
3242 return true;
3243 }
3244 }
3245 return false;
3246}
3247
3248private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3249 var IntegerRecord min_dbm_level;
3250 var IntegerRecord max_dbm_level;
3251 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3252 return max_dbm_level[0];
3253}
3254
3255type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003256private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003257private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3258 // 45.005 4.1.1
3259 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3260 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3261 2, 1, 0};
3262 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3263 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3264 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3265 var IntegerRecord rv;
3266
3267 select(band){
3268 case (BtsBand_allGSM){
3269 rv := gsm_power;
3270 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3271 max_dbm_level := {2, 1, 0};
3272 }
3273 case("DCS1800"){
3274 rv := dcs_power;
3275 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3276 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3277 }
3278 case("PCS1900"){
3279 rv := pcs_power;
3280 min_dbm_level := {15};
3281 max_dbm_level := {30};
3282 }
Harald Welte194b6912020-10-11 21:01:55 +02003283 case else {
3284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3285 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003286 }
3287
3288 return rv;
3289}
3290
3291private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003292 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 +02003293}
3294
3295testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3296 var ConnHdlr vc_conn;
3297 var ConnHdlrPars pars;
3298 f_init();
3299 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3300 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3301 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3302 pars.bts0_band := f_vty_get_bts0_band();
3303 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3304 vc_conn.done;
3305 }
3306 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3308}
3309
3310testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3311 var ConnHdlr vc_conn;
3312 var ConnHdlrPars pars;
3313 f_init();
3314 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3315 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3316 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3317 pars.bts0_band := f_vty_get_bts0_band();
3318 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3319 vc_conn.done;
3320 }
3321 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3323}
3324
3325testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3326 var ConnHdlr vc_conn;
3327 var ConnHdlrPars pars;
3328 f_init();
3329 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3330 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3331 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3332 pars.bts0_band := f_vty_get_bts0_band();
3333 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3334 vc_conn.done;
3335 }
3336 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3338}
3339
3340testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3341 var ConnHdlr vc_conn;
3342 var ConnHdlrPars pars;
3343 f_init();
3344 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3345 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3346 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3347 pars.bts0_band := f_vty_get_bts0_band();
3348 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3349 vc_conn.done;
3350 }
3351 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3353}
3354
Eric Wild280ccb82019-06-17 11:11:52 +02003355testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3356 var ConnHdlr vc_conn;
3357 var ConnHdlrPars pars;
3358 f_init();
3359 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3360 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3361 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3362 pars.bts0_band := f_vty_get_bts0_band();
3363 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3364 vc_conn.done;
3365 }
3366 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3368}
3369
Eric Wild095024b2019-06-17 15:08:57 +02003370testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3371 var ConnHdlr vc_conn;
3372 var ConnHdlrPars pars;
3373 f_init();
3374 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3375 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3376 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3377 pars.bts0_band := f_vty_get_bts0_band();
3378 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3379 vc_conn.done;
3380 }
3381 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3383}
3384
Philipp Maier149c3922020-10-22 17:29:36 +02003385function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003386 var template RSL_IE_ChannelMode ch_mode;
3387 var ConnHdlr vc_conn;
3388 var ConnHdlrPars pars;
3389 f_init();
3390 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3391 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3392 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003393 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003394 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3395 pcu_comp := false, trxc_comp := true);
3396 vc_conn.done;
3397 }
3398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3399}
Philipp Maier149c3922020-10-22 17:29:36 +02003400
3401testcase TC_meas_res_speech_tchf() runs on test_CT {
3402 f_TC_meas_res_speech_tchf(false);
3403}
3404
3405testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3406 f_TC_meas_res_speech_tchf(true);
3407}
3408
3409function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003410 var template RSL_IE_ChannelMode ch_mode;
3411 var ConnHdlr vc_conn;
3412 var ConnHdlrPars pars;
3413 f_init();
3414 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3415 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3416 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003417 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003418 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3419 pcu_comp := false, trxc_comp := true);
3420 vc_conn.done;
3421 }
3422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3423}
Philipp Maier149c3922020-10-22 17:29:36 +02003424
3425testcase TC_meas_res_speech_tchh() runs on test_CT {
3426 f_TC_meas_res_speech_tchh(false)
3427}
3428
3429testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3430 f_TC_meas_res_speech_tchh(true)
3431}
3432
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003433testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3434 var template RSL_IE_ChannelMode ch_mode;
3435 var ConnHdlr vc_conn;
3436 var ConnHdlrPars pars;
3437 f_init();
3438 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3439 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3440 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3441 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3442 pars.l1_pars.toa256_enabled := true;
3443 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3444 pcu_comp := false, trxc_comp := true);
3445 vc_conn.done;
3446 }
3447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3448}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003449
Harald Welte70767382018-02-21 12:16:40 +01003450testcase TC_meas_res_sign_tchf() runs on test_CT {
3451 var ConnHdlr vc_conn;
3452 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003453 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003454 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003455 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003456 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003457 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3458 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003459 vc_conn.done;
3460 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003462}
3463testcase TC_meas_res_sign_tchh() runs on test_CT {
3464 var ConnHdlr vc_conn;
3465 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003466 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003467 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003468 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003469 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003470 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3471 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003472 vc_conn.done;
3473 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003475}
3476testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3477 var ConnHdlr vc_conn;
3478 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003479 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003480 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003481 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3482 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003483 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3484 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003485 vc_conn.done;
3486 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003488}
3489testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3490 var ConnHdlr vc_conn;
3491 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003492 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003493 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003494 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3495 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003496 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3497 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003498 vc_conn.done;
3499 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003501}
Harald Welte685d5982018-02-27 20:42:05 +01003502testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3503 var ConnHdlr vc_conn;
3504 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003505 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003506 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3507 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003508 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003509 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003510 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3511 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003512 vc_conn.done;
3513 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003515}
3516
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003517/* Make sure that we always get RSL MEASurement RESult messages regardless
3518 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3519private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3520 timer Texec := 8.0;
3521 timer Timpf := 2.0;
3522 timer Tmr;
3523
3524 f_l1_tune(L1CTL);
3525 RSL.clear;
3526
3527 f_est_dchan();
3528 L1CTL.clear;
3529
3530 /* Establish the main SAPI=0 link on DCCH first */
3531 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3532
3533 /* Give more time for the first RSL MEASurement RESult */
3534 Tmr.start(0.480 * 2.0);
3535 Texec.start; /* EXECution timer */
3536 Timpf.start; /* IMPFung timer */
3537
3538 alt {
3539 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3540 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3541 /* Reschedule the MEAS RES timer */
3542 Tmr.start(0.480 + 0.120);
3543 repeat;
3544 }
3545 [] RSL.receive { repeat; }
3546 [] Tmr.timeout {
3547 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3548 }
3549 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3550 [] Timpf.timeout {
3551 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3552 log("Injected SAPI=3 traffic on SACCH");
3553 Timpf.start;
3554 repeat;
3555 }
3556 /* We're good if survived so far */
3557 [] Texec.timeout {
3558 setverdict(pass);
3559 }
3560 }
3561
3562 f_rsl_chan_deact();
3563 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3564 f_rslem_unregister(0, g_chan_nr);
3565}
3566testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3567 var template RSL_IE_ChannelMode ch_mode;
3568 var template ConnHdlrPars pars;
3569 var ConnHdlr vc_conn;
3570
3571 f_init();
3572
3573 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3574 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3575
3576 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3577 vc_conn.done;
3578
3579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3580}
3581testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3582 var template RSL_IE_ChannelMode ch_mode;
3583 var template ConnHdlrPars pars;
3584 var ConnHdlr vc_conn;
3585
3586 f_init();
3587
3588 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3589 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3590
3591 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3592 vc_conn.done;
3593
3594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3595}
3596
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003597/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3598 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003599private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003600 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003601 var RSL_IE_MS_Power ms_power;
3602 var RSL_Message rsl;
3603 var uint5_t power_level := 0;
3604
3605 f_l1_tune(L1CTL);
3606 RSL.clear;
3607
3608 f_est_dchan();
3609
3610 ms_power.reserved := 0;
3611 ms_power.fpc_epc := false;
3612
3613 /* Send the first power control command. This will disable any BTS/TRX
3614 * internal power control and switch the MS (which is not in scope of
3615 * this test) to a constant power level. We start with a power level
3616 * of 0 */
3617 ms_power.power_level := power_level;
3618 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3619 RSL.send(rsl);
3620
3621 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003622 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3623 if (l1h.ms_power_lvl != power_level) {
3624 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3625 "match the signaled (RSL) power level := ", power_level);
3626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003627 }
3628
3629 /* Signal a new power level via RSL for the next turn. */
3630 if (power_level < 31) {
3631 power_level := power_level + 1;
3632 ms_power.power_level := power_level;
3633 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3634 RSL.send(rsl);
3635 repeat;
3636 }
3637
3638 }
3639
3640 /* Ignore all other blocks */
3641 [] L1CTL.receive { repeat; }
3642
3643 }
3644
3645 f_rsl_chan_deact();
3646 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3647
3648 setverdict(pass);
3649}
3650
3651testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3652 var ConnHdlr vc_conn;
3653 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003654 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003655
3656 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3657 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3658 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3659 vc_conn.done;
3660 }
3661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3662}
Harald Welte70767382018-02-21 12:16:40 +01003663
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003664/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003665TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003666private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003667 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003668 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003669
3670 f_l1_tune(L1CTL);
3671 RSL.clear;
3672
3673 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003674 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003675
3676 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3677
3678
3679 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003680 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3681 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003682 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3683 }
3684
3685 }
3686
3687 /* Ignore all other blocks */
3688 [] L1CTL.receive { repeat; }
3689
3690 }
3691
3692 f_rsl_chan_deact();
3693 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3694
3695 setverdict(pass);
3696}
3697
3698testcase TC_rsl_chan_initial_ta() runs on test_CT {
3699 var ConnHdlr vc_conn;
3700 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003701 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003702 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003703 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3704 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003705 vc_conn.done;
3706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3707}
3708
Eric Wilde57e1a62019-05-28 13:30:55 +02003709/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003710private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003711 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003712 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003713
3714 var RSL_IE_MS_Power ms_power;
3715 ms_power.reserved := 0;
3716 ms_power.fpc_epc := false;
3717 ms_power.power_level := ms_power_level;
3718
3719 f_l1_tune(L1CTL);
3720 RSL.clear;
3721
3722 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3723
3724 timer T := 1.0;
3725 T.start;
3726 alt {
3727 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003728 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3729 if (l1h.ms_power_lvl != ms_power_level) {
3730 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3731 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003732 }
3733 }
3734 /* Ignore all other blocks */
3735 [] L1CTL.receive { repeat; }
3736 [] T.timeout {
3737 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3738 }
3739 }
3740
3741 f_rsl_chan_deact();
3742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3743 setverdict(pass);
3744}
3745
3746testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3747 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3748 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3749}
3750
Harald Welte0472ab42018-03-12 15:02:26 +01003751/* 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 +01003752private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003753 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003754 RSL.clear;
3755
3756 f_est_dchan();
3757 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003758 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003759
3760 timer T := 40.0;
3761 T.start;
3762 alt {
3763 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3764 setverdict(pass)
3765 }
3766 [] RSL.receive { repeat };
3767 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003769 }
3770 }
3771 f_rsl_chan_deact();
3772}
3773testcase TC_conn_fail_crit() runs on test_CT {
3774 var ConnHdlr vc_conn;
3775 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003776 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003777 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3778 pars.t_guard := 60.0;
3779 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3780 vc_conn.done;
3781}
3782
Harald Welte93640c62018-02-25 16:59:33 +01003783/***********************************************************************
3784 * Paging
3785 ***********************************************************************/
3786
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003787private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003788 if (tmsi == 'FFFFFFFF'O) {
3789 return true;
3790 } else {
3791 return false;
3792 }
3793}
Harald Welte70767382018-02-21 12:16:40 +01003794
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003795private type record allowedFn { integer frame_nr }
3796private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3797private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3798private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3799private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3800private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3801private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3802private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3803private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3804private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003805{
3806 var integer frame_nr_51;
3807 frame_nr_51 := frame_nr mod 51
3808
3809 var allowedFn fn_check;
3810 fn_check.frame_nr := frame_nr_51;
3811
3812 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003814 return;
3815 }
3816
3817 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3818 return;
3819 }
3820 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3821 return;
3822 }
3823 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3824 return;
3825 }
3826 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3827 return;
3828 }
3829 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3830 return;
3831 }
3832 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3833 return;
3834 }
3835 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3836 return;
3837 }
3838 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3839 return;
3840 }
3841
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003843 return;
3844}
3845
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003846private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3847 inout integer num_paging_rcv_ids,
3848 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003849runs on test_CT {
3850 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003851 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003852 repeat;
3853 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003854 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003855 var octetstring without_plen :=
3856 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3857 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003858
3859 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3860
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003861 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3862 /* Ignore empty RR Paging Request (PCH filling) messages.
3863 * TODO: does it make sense to count them? */
3864 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003865 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3866 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003867 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003868 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3869 }
3870 } else if (match(rr, tr_PAGING_REQ2)) {
3871 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3872 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3873 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3874 }
3875 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3876 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3877 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003878 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003879 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3880 }
3881 } else if (match(rr, tr_PAGING_REQ3)) {
3882 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3883 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3884 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3885 }
3886 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3887 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3888 }
3889 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3890 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3891 }
3892 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3893 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3894 }
3895 }
3896 repeat;
3897 }
3898}
3899
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003900private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003901 boolean combined_ccch,
3902 integer bs_ag_blks_res,
3903 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003904 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3905 * paging command that is issued via RSL. */
3906 integer ps_load_modulus,
3907 /* Wait until the paging queue inside the BTS is congested before starting to add
3908 * pagings via the PCU socket (0 = disabled) */
3909 boolean ps_wait_cong,
3910 /* Maximum time to wait until the paging queue is drained at the end of the test.
3911 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3912 * to set this value to 18s, however the draining process may take significantly
3913 * longer when the queue contains paging requests for PS as those are implemented
3914 * as immediate assignments and require an entire MAC block alone. */
3915 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003916 boolean exp_load_ind,
3917 boolean exp_overload,
3918 boolean use_tmsi
3919}
3920
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003921private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003922 integer num_paging_sent,
3923 integer num_paging_rcv_msgs,
3924 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003925 integer num_overload,
3926 /* When free space inside the paging queue reaches more than 2 thirds
3927 * of its capacity cong_detected is set to true. */
3928 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003929}
3930
Harald Welte68e495b2018-02-25 00:05:57 +01003931/* Helper function for paging related testing */
3932private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003933 /* Using the PCU socket affects the timing of the paging processing. We only
3934 * activate the PCU socket if we do paging load tests that include additional
3935 * paging load that is introduced through the PCU socket. */
3936 if (cfg.ps_load_modulus > 0) {
3937 f_init_with_pcuif();
3938 } else {
3939 f_init();
3940 }
Harald Welte68e495b2018-02-25 00:05:57 +01003941 f_init_l1ctl();
3942 f_l1_tune(L1CTL);
3943
Philipp Maierca058272021-06-23 10:35:23 +02003944 var octetstring imm_ass := f_rnd_octstring(23);
3945 var ASP_RSL_Unitdata load_ind;
3946
Harald Welte68e495b2018-02-25 00:05:57 +01003947 var PagingTestState st := {
3948 num_paging_sent := 0,
3949 num_paging_rcv_msgs := 0,
3950 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003951 num_overload := 0,
3952 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003953 };
3954
3955 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3956 var float max_pch_imsi_per_sec;
3957 if (cfg.use_tmsi) {
3958 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3959 } else {
3960 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3961 }
3962 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3963 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003964 var float time_total := 20.0;
3965 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3966 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003967
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003968 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3969 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003970
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003971 timer T_itv := 0.0;
3972 T_itv.start;
3973 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003974 alt {
3975 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003976 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003977 st.num_overload := st.num_overload + 1;
3978 repeat;
3979 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003980 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003982 }
Philipp Maierca058272021-06-23 10:35:23 +02003983 [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 +01003984 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003985
3986 /* Detect paging congestion: The logic inside the BTS will diagnose the
3987 * paging queue as congested when the fill state is more than 66% (which
3988 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3989 * paging congestion is detected pagings that are issued through the PCU
3990 * socket (PS) are dropped in order to prefer the CS related pagings. */
3991 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3992 st.cong_detected := true;
3993 }
3994
Harald Welte68e495b2018-02-25 00:05:57 +01003995 /* FIXME: analyze/verify interval + contents */
3996 repeat;
3997 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003998 /* ignore other RSL messages like RF RESource INDication */
3999 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004000 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004001 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004002 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004003 /* Only relevant when testing including with PCU sock connected */
4004 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004005 [] T_itv.timeout {
4006 /* Send paging cmds based on elapsed time */
4007 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4008 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004009 var MobileIdentityV mi;
4010
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004011 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004012 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004013 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004014 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004015 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004016 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004017
4018 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004019 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 +02004020
Philipp Maierca058272021-06-23 10:35:23 +02004021 /* Add additional pagings through the PCU socket interface. */
4022 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4023 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4024 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4025 }
4026 }
4027
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004028 st.num_paging_sent := st.num_paging_sent + 1;
4029 }
4030 if (st.num_paging_sent < pkt_total) {
4031 /* Wait for interval to next PAGING COMMAND */
4032 var float time_now := T_total.read;
4033 var float next_sched := int2float(st.num_paging_sent)*interval;
4034 if (next_sched > time_now) {
4035 T_itv.start(next_sched - time_now);
4036 } else {
4037 T_itv.start(0.0);
4038 }
4039 } else {
4040 /* We are done, no need to keep counting */
4041 T_total.stop;
4042 }
4043 }
4044 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004045 }
4046 }
4047
Philipp Maierca058272021-06-23 10:35:23 +02004048 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004049 T_wait.start;
4050 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004051 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004052 [] L1CTL.receive { repeat; }
4053 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004054 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004055 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004056 /* ignore other RSL messages like RF RESource INDication */
4057 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004058 /* Only relevant when testing including with PCU sock connected */
4059 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004060 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004061 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 +01004062 }
Harald Welte68e495b2018-02-25 00:05:57 +01004063 }
4064
4065 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4066 " rcvd_ids=", st.num_paging_rcv_ids);
4067 return st;
4068}
4069
4070/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4071 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4072 * - that CCCH LOAD IND (PCH) are being generated
4073 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4074testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004075 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004076 var PagingTestCfg cfg := {
4077 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004078 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004079 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004080 ps_load_modulus := 0,
4081 ps_wait_cong := false,
4082 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004083 exp_load_ind := true,
4084 exp_overload := false,
4085 use_tmsi := false
4086 };
4087 var PagingTestState st := f_TC_paging(cfg);
4088 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4090 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004091 } else {
4092 setverdict(pass);
4093 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004095}
4096
4097/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4098 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4099 * - that CCCH LOAD IND (PCH) are being generated
4100 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4101testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004102 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004103 var PagingTestCfg cfg := {
4104 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004105 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004106 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004107 ps_load_modulus := 0,
4108 ps_wait_cong := false,
4109 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004110 exp_load_ind := true,
4111 exp_overload := false,
4112 use_tmsi := true
4113 };
4114 var PagingTestState st := f_TC_paging(cfg);
4115 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4117 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004118 } else {
4119 setverdict(pass);
4120 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004122}
4123
4124/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4125 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4126 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4127 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4128testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004129 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004130 var PagingTestCfg cfg := {
4131 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004132 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004133 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004134 ps_load_modulus := 0,
4135 ps_wait_cong := false,
4136 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004137 exp_load_ind := true,
4138 exp_overload := true,
4139 use_tmsi := false
4140 };
4141 var PagingTestState st := f_TC_paging(cfg);
4142 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4143 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004144 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004145 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004146 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 +01004147 } else {
4148 setverdict(pass);
4149 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004151}
4152
4153/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4154 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4155 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4156 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4157testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004158 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004159 var PagingTestCfg cfg := {
4160 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004161 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004162 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004163 ps_load_modulus := 0,
4164 ps_wait_cong := false,
4165 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004166 exp_load_ind := true,
4167 exp_overload := true,
4168 use_tmsi := true
4169 };
4170 var PagingTestState st := f_TC_paging(cfg);
4171 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4172 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004173 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004174 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004175 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 +01004176 } else {
4177 setverdict(pass);
4178 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004180}
4181
Philipp Maierca058272021-06-23 10:35:23 +02004182/* Same as above, but with additional paging load created by PS pagings that
4183 * are issued through the PCU socket. The additional load is introduced when
4184 * the paging queue is already two thirds full. Since the BTS implements a
4185 * prioritization logic that drops the pagings from the PCU under in those
4186 * congestive sitautions the behaviour on the PS side is expected to be
4187 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4188testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4189 var SystemInformation si3 := valueof(ts_SI3_default);
4190 var PagingTestCfg cfg := {
4191 combined_ccch := true,
4192 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4193 load_factor := 2.0,
4194 ps_load_modulus := 16,
4195 ps_wait_cong := true,
4196 queue_drain_timeout := 18.0,
4197 exp_load_ind := true,
4198 exp_overload := true,
4199 use_tmsi := false
4200 };
4201 var PagingTestState st := f_TC_paging(cfg);
4202 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4203 * slots and will fully drain that buffer before returning */
4204 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4205 if (not match(st.num_paging_rcv_ids, tpl)) {
4206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4207 } else {
4208 setverdict(pass);
4209 }
4210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4211}
4212
4213
Harald Welte68e495b2018-02-25 00:05:57 +01004214
Harald Welte93640c62018-02-25 16:59:33 +01004215/***********************************************************************
4216 * Immediate Assignment / AGCH
4217 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004218private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004219 len := 0,
4220 ma := ''B
4221}
Harald Welte93640c62018-02-25 16:59:33 +01004222
Harald Weltee8d750e2018-06-10 21:41:35 +02004223private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4224 return int2str(num_tx) & " sent, "
4225 & int2str(num_rx) & " received, "
4226 & int2str(num_del) & " deleted";
4227}
4228
4229private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4230 var L1ctlDlMessage l1_dl;
4231 timer T := 10.0;
4232 var integer num_tx := 0;
4233 var integer num_rx := 0;
4234 var integer num_del := 0;
4235 var charstring res_str;
4236 var float rx_ratio;
4237
Harald Welte10474062019-05-30 16:48:17 +02004238 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004239 f_init_l1ctl();
4240 f_l1_tune(L1CTL);
4241
4242 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004243 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004244 mp_trx_pars[0].arfcn,
4245 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004246 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4247 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004248 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004249 num_tx := num_tx+1;
4250 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004251 }
4252 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004253 T.start;
4254 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004255 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004256 num_del := num_del+1;
4257 repeat;
4258 }
4259 [] RSL_CCHAN.receive {
4260 repeat;
4261 }
4262 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004263 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4264 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4265 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004266 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004267 } else {
4268 num_rx := num_rx+1;
4269 }
4270 repeat;
4271 }
4272 [] L1CTL.receive { repeat; }
4273 [] T.timeout { }
4274 }
4275 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4276 log("AGCH test: " & res_str);
4277 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004279 }
4280 rx_ratio := int2float(num_rx) / int2float(num_tx);
4281 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004282 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 +02004283 } else {
4284 setverdict(pass);
4285 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004287}
4288
Harald Weltee8d750e2018-06-10 21:41:35 +02004289/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4290testcase TC_imm_ass_1000_20ms() runs on test_CT {
4291 f_TC_imm_ass(1000, 0.02, 0.25);
4292}
4293
4294/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4295testcase TC_imm_ass_200_0ms() runs on test_CT {
4296 f_TC_imm_ass(200, 0.0, 0.05);
4297}
4298
4299/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4300testcase TC_imm_ass_200_76ms() runs on test_CT {
4301 f_TC_imm_ass(150, 0.076, 1.00);
4302}
4303
4304
4305
Harald Welte48494ca2018-02-25 16:59:50 +01004306/***********************************************************************
4307 * BCCH
4308 ***********************************************************************/
4309
4310/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004311private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004312 GsmFrameNumber frame_number,
4313 SystemInformation si
4314}
4315
4316/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004317private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004318
4319/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004320private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004321
4322/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004323private function f_si_vecslot_contains(SystemInformationVector arr,
4324 RrMessageType key,
4325 boolean bcch_ext := false)
4326return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004327 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4328 var integer fn_mod51 := arr[i].frame_number mod 51;
4329 if (not bcch_ext and fn_mod51 == 2 or
4330 bcch_ext and fn_mod51 == 6) {
4331 if (arr[i].si.header.message_type == key) {
4332 return true;
4333 }
4334 }
4335 }
4336 return false;
4337}
4338
4339/* 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 +07004340private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4341 integer tc, RrMessageType key,
4342 boolean ext_bcch := false)
4343{
Harald Welte48494ca2018-02-25 16:59:50 +01004344 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004346 }
4347}
4348
4349/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004350private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4351 RrMessageType key)
4352return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004353 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4354 if (f_si_vecslot_contains(arr[tc], key) or
4355 f_si_vecslot_contains(arr[tc], key, true)) {
4356 return true;
4357 }
4358 }
4359 return false;
4360}
4361
4362/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004363private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4364 RrMessageType key,
4365 boolean bcch_ext := false,
4366 integer n := 1, integer m := 4)
4367return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004368 var integer count := 0;
4369 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4371 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004372 }
4373 for (var integer i:= 0; i < m; i := i + 1) {
4374 var integer fn_mod51 := arr[i].frame_number mod 51;
4375 if (not bcch_ext and fn_mod51 == 2 or
4376 bcch_ext and fn_mod51 == 6) {
4377 if (arr[i].si.header.message_type == key) {
4378 count := count + 1;
4379 }
4380 }
4381 }
4382 if (count >= n) {
4383 return true;
4384 } else {
4385 return false;
4386 }
4387}
4388
4389/* 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 +07004390private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4391 integer tc, RrMessageType key,
4392 boolean ext_bcch := false,
4393 integer n, integer m)
4394{
Harald Welte48494ca2018-02-25 16:59:50 +01004395 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004397 }
4398}
4399
4400/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004401private function f_si_vecslot_contains_only(SystemInformationVector arr,
4402 RrMessageType key,
4403 boolean bcch_ext := false)
4404return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004405 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4406 var integer fn_mod51 := arr[i].frame_number mod 51;
4407 if (not bcch_ext and fn_mod51 == 2 or
4408 bcch_ext and fn_mod51 == 6) {
4409 if (arr[i].si.header.message_type != key) {
4410 return false;
4411 }
4412 }
4413 }
4414 return true;
4415}
4416
4417/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004418private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4419 integer tc, RrMessageType key,
4420 boolean ext_bcch := false)
4421{
Harald Welte48494ca2018-02-25 16:59:50 +01004422 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004424 }
4425}
4426
4427/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004428private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004429 boolean bcch_extended,
4430 boolean si1_present,
4431 boolean si2bis_present,
4432 boolean si2ter_present,
4433 boolean si2quater_present,
4434 boolean si7_present,
4435 boolean si8_present,
4436 boolean si9_present,
4437 boolean si13_present,
4438 boolean si13alt_present,
4439 boolean si15_present,
4440 boolean si16_present,
4441 boolean si17_present,
4442 boolean si2n_present,
4443 boolean si21_present,
4444 boolean si22_present
4445}
4446
4447/* 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 +07004448private function f_validate_si_scheduling(SystemInformationConfig cfg,
4449 SystemInformationVectorPerTc si_per_tc)
4450{
Harald Welte48494ca2018-02-25 16:59:50 +01004451 var integer i;
4452 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4453 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004455 }
4456 }
4457 if (cfg.si1_present) {
4458 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4459 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4460 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4461 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4462 /* make sure *ALL* contain SI1 */
4463 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4464 }
4465 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4466 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4467 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4468 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4469 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4470 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4471
4472 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4473 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4474 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4475 * consecutive occurrences of TC = 4. */
4476 if (cfg.si2bis_present and not cfg.si2ter_present) {
4477 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4478 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4479 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4480 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4481 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4482 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4483 }
4484
4485 if (cfg.si7_present or cfg.si8_present) {
4486 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4487 * if System Information type 4 does not contain all information needed for cell
4488 * selection and reselection. */
4489 if (not cfg.bcch_extended) {
4490 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4491 }
4492 if (cfg.si7_present) {
4493 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4494 }
4495 if (cfg.si8_present) {
4496 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4497 }
4498 }
4499
4500 if (cfg.si2quater_present) {
4501 /* iii) System information type 2 quater is sent if needed, as determined by the system
4502 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4503 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4504 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4505 * within any of 4 consecutive occurrences of TC = 5. */
4506 if (not (cfg.bcch_extended)) {
4507 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4508 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4509 } else {
4510 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4511 }
4512 } else {
4513 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4514 }
4515 }
4516 if (cfg.si9_present) {
4517 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4518 * in system information type 3 as defined in 3GPP TS 44.018. */
4519 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4520 }
4521 if (cfg.si13_present) {
4522 /* vii) System Information type 13 is only related to the GPRS service. System Information
4523 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4524 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4525 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4526 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4527 * within any of 4 consecutive occurrences of TC=4. */
4528 if (not cfg.bcch_extended) {
4529 log("not-bccch-extended");
4530 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4531 } else {
4532 log("bccch-extended");
4533 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4534 }
4535 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004537 }
4538 }
4539 if (cfg.si16_present or cfg.si17_present) {
4540 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4541 * should not be sent in a cell where network sharing is used (see rule xv). */
4542 if (cfg.si22_present) {
4543 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4544 }
4545 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004547 }
4548 if (not cfg.bcch_extended) {
4549 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4550 }
4551 if (cfg.si16_present) {
4552 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4553 }
4554 if (cfg.si17_present) {
4555 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4556 }
4557 }
4558
4559 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4560 * broadcast information. The frequency with which they are sent is determined by the
4561 * system operator. System Information type 9 identifies the scheduling of System
4562 * Information type 18 and 20 messages. */
4563
4564 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4565 * Information Type 19 is present, then its scheduling shall be indicated in System
4566 * Information Type 9. */
4567
4568 if (cfg.si15_present) {
4569 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4570 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4571 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4572 * 4 consecutive occurrences of TC = 1. */
4573 if (not cfg.bcch_extended) {
4574 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4575 } else {
4576 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4577 }
4578 }
4579 if (cfg.si13alt_present) {
4580 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4581 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4582 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4583 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4584 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4585 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4586 * of TC = 4. */
4587 if (cfg.si13_present) {
4588 testcase.stop("Error: Cannot have SI13alt and SI13");
4589 }
4590 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004592 }
4593 if (not cfg.bcch_extended) {
4594 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4595 } else {
4596 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4597 }
4598 }
4599 if (cfg.si2n_present) {
4600 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4601 * as determined by the system operator. In the case that the message is sent on the
4602 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4603 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4604 * consecutive occurrences of TC = 4. */
4605 if (not cfg.bcch_extended) {
4606 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4607 } else {
4608 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4609 }
4610 }
4611 if (cfg.si21_present) {
4612 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4613 * determined by the system operator. If Extended Access Barring is in use in the cell
4614 * then this message is sent at least once within any of 4 consecutive occurrences of
4615 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4616 * cell then this message shall only be sent on BCCH Ext. */
4617 if (not cfg.bcch_extended) {
4618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4619 } else {
4620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4621 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004623 }
4624 }
4625 }
4626 if (cfg.si22_present) {
4627 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4628 * should not be sent in a cell where SoLSA is used (see rule viii). System
4629 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4630 * =2 and TC=6. */
4631 if (cfg.si16_present or cfg.si17_present) {
4632 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4633 }
4634 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4635 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004637 }
4638 if (not cfg.bcch_extended) {
4639 testcase.stop("Error: SI22 requires BCCH Extd!");
4640 } else {
4641 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4642 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4643 }
4644 }
4645}
4646
4647/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004648private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4649return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004650 timer T := duration;
4651 var SystemInformationVectorPerTc si_per_tc;
4652 var L1ctlDlMessage l1_dl;
4653
4654 /* initialize all per-TC vectors empty */
4655 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4656 si_per_tc[i] := {};
4657 }
4658
4659 /* flush all previous L1 queued msgs */
4660 pt.clear;
4661
4662 T.start;
4663 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004664 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004665 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4666 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4667 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004668 repeat;
4669 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004670
Harald Welte48494ca2018-02-25 16:59:50 +01004671 var integer tc := f_gsm_compute_tc(sig.frame_number);
4672 log("SI received at TC=", tc, ": ", sig.si);
4673 /* append to the per-TC bucket */
4674 si_per_tc[tc] := si_per_tc[tc] & { sig };
4675 repeat;
4676 }
4677 [] pt.receive { repeat; }
4678 [] T.timeout { }
4679 }
4680
4681 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4682 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4683 }
4684 log("si_per_tc=", si_per_tc);
4685 return si_per_tc;
4686}
4687
4688/* helper function: Set given SI via RSL + validate scheduling.
4689 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004690private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004691 var SystemInformationVectorPerTc si_per_tc;
4692 f_init_l1ctl();
4693 f_l1_tune(L1CTL);
4694
4695 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004696 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004697 f_validate_si_scheduling(si_cfg, si_per_tc);
4698
4699 setverdict(pass);
4700}
4701
4702testcase TC_si_sched_default() runs on test_CT {
4703 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004704 /* 2+3+4 are mandatory and set in f_init() */
4705 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004707}
4708
4709testcase TC_si_sched_1() runs on test_CT {
4710 f_init();
4711 si_cfg.si1_present := true;
4712 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004713 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004715}
4716
4717testcase TC_si_sched_2bis() runs on test_CT {
4718 f_init();
4719 si_cfg.si2bis_present := true;
4720 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4721 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004723}
4724
4725testcase TC_si_sched_2ter() runs on test_CT {
4726 f_init();
4727 si_cfg.si2ter_present := true;
4728 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4729 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004731}
4732
4733testcase TC_si_sched_2ter_2bis() runs on test_CT {
4734 f_init();
4735 si_cfg.si2bis_present := true;
4736 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4737 si_cfg.si2ter_present := true;
4738 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4739 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004741}
4742
4743testcase TC_si_sched_2quater() runs on test_CT {
4744 f_init();
4745 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004746 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004747 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004749}
4750
4751testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004752 /* NOTE: PCUIF connection is not used in this test case, but
4753 * without it the IUT would not broadcast SI13 (see OS#3075). */
4754 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004755 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004756 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004757 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004759}
4760
4761testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004762 /* NOTE: PCUIF connection is not used in this test case, but
4763 * without it the IUT would not broadcast SI13 (see OS#3075). */
4764 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004765 si_cfg.si2bis_present := true;
4766 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4767 si_cfg.si2ter_present := true;
4768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4769 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004770 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004771 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004772 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004773 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004775}
4776
4777
Harald Welte68e495b2018-02-25 00:05:57 +01004778testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004779 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004780 /* FIXME: enable / disable individual BCCH info */
4781 //ts_RSL_BCCH_INFO(si_type, info);
4782 /* expect no ERROR REPORT after either of them *
4783 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004785}
4786
Harald Welte93640c62018-02-25 16:59:33 +01004787/***********************************************************************
4788 * Low-Level Protocol Errors / ERROR REPORT
4789 ***********************************************************************/
4790
Harald Welte01d982c2018-02-25 01:31:40 +01004791private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4792 timer T := 5.0;
4793 T.start;
4794 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004795 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004796 setverdict(pass);
4797 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004798 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004800 }
4801 [] RSL_CCHAN.receive {
4802 repeat;
4803 }
4804 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004806 }
4807 }
4808}
4809
4810/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4811testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004812 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004813 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4814 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004815 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004816
4817 f_exp_err_rep(RSL_ERR_PROTO);
4818}
4819
4820/* Provoke a mandatory IE error and match on ERROR REPORT */
4821testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004822 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004823
4824 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4825 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004826 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004827
4828 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4829}
4830
4831/* Provoke an IE content error and match on ERROR REPORT */
4832testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004833 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004834 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4835 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004836 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004837
4838 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4839}
4840
Harald Welteee25aae2019-05-19 14:32:37 +02004841/* attempt to activate channel with wrong RSL Message Discriminator IE */
4842function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4843 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4844 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4845 RSL.send(rsl);
4846 f_rslem_unregister(0, g_chan_nr);
4847}
4848testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4849 var ConnHdlr vc_conn;
4850 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4851
Harald Welte10474062019-05-30 16:48:17 +02004852 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004853
4854 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4855 vc_conn.done;
4856 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4857
4858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4859}
4860
4861/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004862private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004863 var template (value) RSL_Message rsl_tx;
4864 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4865 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4866 RSL.send(rsl_tx);
4867 f_rslem_unregister(0, g_chan_nr);
4868}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004869private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004870 var template (value) RSL_Message rsl_tx;
4871 /* we first have to activate the dedicated channel */
4872 f_rsl_chan_act(g_pars.chan_mode);
4873 /* ... to then send an invalid RLL message */
4874 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4875 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4876 RSL.send(rsl_tx);
4877 f_rslem_unregister(0, g_chan_nr);
4878}
4879testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4880 var ConnHdlr vc_conn;
4881 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4882 var template (value) RSL_Message rsl_tx;
4883
Harald Welte10474062019-05-30 16:48:17 +02004884 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004885
4886 /* Common Channel with wrong message type */
4887 RSL_CCHAN.clear;
4888 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4889 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004890 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004891 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4892
4893 /* TRX Management */
4894 RSL_CCHAN.clear;
4895 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4896 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004897 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004898 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4899
4900 /* Dedicated Channel */
4901 RSL_CCHAN.clear;
4902 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4903 vc_conn.done;
4904 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4905
4906 /* RLL */
4907 RSL_CCHAN.clear;
4908 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4909 vc_conn.done;
4910 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4911}
4912
4913/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004914private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004915 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4916 f_rslem_unregister(0, g_chan_nr);
4917}
4918testcase TC_err_rep_wrong_sequence() runs on test_CT {
4919 var ConnHdlr vc_conn;
4920 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4921
Harald Welte10474062019-05-30 16:48:17 +02004922 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004923
4924 RSL_CCHAN.clear;
4925 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4926 vc_conn.done;
4927 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4928}
4929
Harald Welte93640c62018-02-25 16:59:33 +01004930/***********************************************************************
4931 * IPA CRCX/MDCX/DLCS media stream handling
4932 ***********************************************************************/
4933
Harald Weltea871a382018-02-25 02:03:14 +01004934/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004935private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004936 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4937 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004938}
4939testcase TC_ipa_dlcx_not_active() runs on test_CT {
4940 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004941 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004942 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4943 vc_conn.done;
4944}
Harald Welte68e495b2018-02-25 00:05:57 +01004945
Harald Weltea3f1df92018-02-25 12:49:55 +01004946/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004947private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004948 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4949 "IPA CRCX ACK");
4950 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4951 "IPA CRCX NACK");
4952}
4953testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4954 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004955 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004956 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4957 vc_conn.done;
4958}
4959
4960/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004961private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004962 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4963 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004964 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004965 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4966 var uint7_t rtp_pt2 := f_rnd_int(127);
4967 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4968 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4969 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4970 "IPA MDCX ACK");
4971 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4972 "IPA DLCX ACK");
4973}
4974testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4975 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004976 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004977 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4978 vc_conn.done;
4979}
4980
Harald Welte3ae11da2018-02-25 13:36:06 +01004981/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004982private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004983 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4984 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004985 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004986 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4987 var uint7_t rtp_pt2 := f_rnd_int(127);
4988 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4989 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4990 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4991 "IPA MDCX ACK");
4992 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004993 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004994 remote_port := f_rnd_int(c_UINT16_MAX);
4995 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4996 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4997 "IPA MDCX ACK");
4998 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4999 "IPA DLCX ACK");
5000}
5001testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5002 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005003 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005004 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5005 vc_conn.done;
5006}
5007
Harald Welte9912eb52018-02-25 13:30:15 +01005008/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005009private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005010 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5011 "IPA CRCX NACK");
5012}
5013testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5014 var ConnHdlrPars pars;
5015 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005016 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005017
5018 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5019 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5020 vc_conn.done;
5021
5022 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5023 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5024 vc_conn.done;
5025}
5026
Harald Weltea3f1df92018-02-25 12:49:55 +01005027
Harald Welte883340c2018-02-28 18:59:29 +01005028/***********************************************************************
5029 * PCU Socket related tests
5030 ***********************************************************************/
5031
Harald Welte07bd2d22019-05-25 11:03:30 +02005032/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005033friend 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 +01005034runs on test_CT {
5035 timer T := 3.0;
5036
5037 /* we don't expect any RTS.req before PDCH are active */
5038 T.start;
5039 alt {
5040 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005042 }
5043 [] PCU.receive { repeat; }
5044 [] T.timeout { }
5045 }
5046
5047 /* Send PDCH activate request for known PDCH timeslot */
5048 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5049
5050 /* we now expect RTS.req for this timeslot (only) */
5051 T.start;
5052 alt {
5053 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5054 setverdict(pass);
5055 }
5056 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5057 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005059 }
5060 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005062 }
5063 [] PCU.receive { repeat; }
5064 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005066 }
5067 [not exp_success] T.timeout {
5068 setverdict(pass);
5069 }
5070 }
5071}
5072
Harald Welte07bd2d22019-05-25 11:03:30 +02005073/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005074friend 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 +01005075runs on test_CT {
5076 timer T := 3.0;
5077
5078 /* Send PDCH activate request for known PDCH timeslot */
5079 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 +02005080 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5081 * when it will actually have been executed in the BTS */
5082 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005083 PCU.clear;
5084 /* we now expect no RTS.req for this timeslot */
5085 T.start;
5086 alt {
5087 [] 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 +02005088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005089 }
5090 [] PCU.receive { repeat; }
5091 [] T.timeout {
5092 setverdict(pass);
5093 }
5094 }
5095}
5096
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005097friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005098 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005099 map(self:PCU, system:PCU);
5100 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005101 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5102}
5103
Harald Welte883340c2018-02-28 18:59:29 +01005104/* PDCH activation via PCU socket; check for presence of RTS.req */
5105testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005106 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005107
Harald Welte883340c2018-02-28 18:59:29 +01005108 f_TC_pcu_act_req(0, 0, 7, true);
5109}
5110
5111/* PDCH activation via PCU socket on non-PDCU timeslot */
5112testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005113 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005114
Harald Welte883340c2018-02-28 18:59:29 +01005115 f_TC_pcu_act_req(0, 0, 1, false);
5116}
5117
5118/* PDCH activation via PCU socket on wrong BTS */
5119testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005120 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005121
Harald Welte883340c2018-02-28 18:59:29 +01005122 f_TC_pcu_act_req(23, 0, 7, false);
5123}
5124
5125/* PDCH activation via PCU socket on wrong TRX */
5126testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005127 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005128
Harald Welte883340c2018-02-28 18:59:29 +01005129 f_TC_pcu_act_req(0, 23, 7, false);
5130}
5131
5132/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5133testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005134 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005135
Harald Welte883340c2018-02-28 18:59:29 +01005136 /* Activate PDCH */
5137 f_TC_pcu_act_req(0, 0, 7, true);
5138 f_sleep(1.0);
5139 /* and De-Activate again */
5140 f_TC_pcu_deact_req(0, 0, 7);
5141}
5142
5143/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5144testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005145 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005146
Harald Welte883340c2018-02-28 18:59:29 +01005147 f_TC_pcu_deact_req(0, 0, 1);
5148}
5149
5150/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005151function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005152 var PCUIF_send_data sd;
5153 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005154 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005155
5156 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005157 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005158
Harald Welte883340c2018-02-28 18:59:29 +01005159 T.start;
5160 alt {
5161 [] 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 +01005162 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005163 setverdict(pass);
5164 } else {
5165 repeat;
5166 }
5167 }
5168 [] PCU.receive { repeat; }
5169 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005170 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005171 }
5172 }
5173}
5174
Philipp Maier94c08482021-02-01 17:36:05 +01005175/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5176testcase TC_pcu_ver_si1() runs on test_CT {
5177 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5178 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5179}
5180
5181/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5182testcase TC_pcu_ver_si3() runs on test_CT {
5183 const octetstring si3 := '49012223242526272929AABBCC'O;
5184 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5185}
5186
5187/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5188testcase TC_pcu_ver_si13() runs on test_CT {
5189 const octetstring si13 := '01010203040506070909'O;
5190 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5191}
5192
Harald Welte883340c2018-02-28 18:59:29 +01005193private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5194
5195/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005196friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005197 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5198runs on test_CT
5199{
5200 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5201 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5202}
5203
5204/* 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 +02005205friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5206 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005207runs on test_CT
5208{
5209 var PCUIF_send_data sd;
5210
5211 timer T := 3.0;
5212 T.start;
5213 alt {
5214 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5215 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5216 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5217 sd.data.u.rts_req.fn, sapi, data);
5218 }
5219 [] PCU.receive { repeat; }
5220 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005222 }
5223 }
5224}
5225
5226/* Send DATA.req on invalid BTS */
5227testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005228 var TfiUsfArr tua := f_TfiUsfArrInit();
5229 var octetstring data := '0000'O & f_rnd_octstring(21);
5230
5231 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005232
Harald Welte883340c2018-02-28 18:59:29 +01005233 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005234 f_TfiUsfArrSet(tua, 7, 0);
5235 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5236 f_sleep(1.0);
5237
5238 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005239}
5240
5241/* Send DATA.req on invalid TRX */
5242testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005243 var TfiUsfArr tua := f_TfiUsfArrInit();
5244 var octetstring data := '0000'O & f_rnd_octstring(21);
5245
5246 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005247
Harald Welte883340c2018-02-28 18:59:29 +01005248 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005249 f_TfiUsfArrSet(tua, 7, 0);
5250 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5251 f_sleep(1.0);
5252
5253 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005254}
5255
5256/* Send DATA.req on invalid timeslot */
5257testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005258 var TfiUsfArr tua := f_TfiUsfArrInit();
5259 var octetstring data := '0000'O & f_rnd_octstring(21);
5260
5261 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005262
Harald Welte883340c2018-02-28 18:59:29 +01005263 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005264 f_TfiUsfArrSet(tua, 7, 0);
5265 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5266 f_sleep(1.0);
5267
5268 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005269}
5270
5271/* Send DATA.req on timeslot that hasn't been activated */
5272testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005273 var TfiUsfArr tua := f_TfiUsfArrInit();
5274 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005275
Harald Welte7162a612019-05-26 12:56:09 +02005276 f_virtphy_common();
5277
5278 f_TfiUsfArrSet(tua, 7, 0);
5279 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5280 f_sleep(1.0);
5281
5282 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005283}
5284
Harald Weltead033dc2019-05-25 17:28:16 +02005285private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005286 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5287 boolean wait_rts := true)
5288runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005289 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005290 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005291
5292 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005293 if (wait_rts) {
5294 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5295 } else {
5296 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5297 }
Harald Weltead033dc2019-05-25 17:28:16 +02005298
5299 T.start;
5300 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005301 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005302 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5303 setverdict(pass);
5304 }
Harald Welte7162a612019-05-26 12:56:09 +02005305 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5306 setverdict(fail, "Received unexpected ", rx_dl);
5307 }
Harald Weltead033dc2019-05-25 17:28:16 +02005308 [] L1CTL.receive {
5309 repeat;
5310 }
Harald Welte7162a612019-05-26 12:56:09 +02005311 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005312 setverdict(fail, "Timeout waiting for ", data);
5313 }
Harald Welte7162a612019-05-26 12:56:09 +02005314 [not expect_data] T.timeout {
5315 setverdict(pass);
5316 }
Harald Weltead033dc2019-05-25 17:28:16 +02005317 }
5318}
5319
5320private function f_disable_dynamic_ts() runs on test_CT
5321{
5322 f_init_vty_bsc();
5323 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5324 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5325 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5326 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005327 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005328}
5329
5330private function f_virtphy_common() runs on test_CT {
5331 f_disable_dynamic_ts();
5332 f_init_l1ctl();
5333 f_l1_tune(L1CTL);
5334}
5335
5336testcase TC_pcu_data_req_pdtch() runs on test_CT {
5337 var TfiUsfArr tua := f_TfiUsfArrInit();
5338 var octetstring data := '0000'O & f_rnd_octstring(21);
5339
5340 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005341
Harald Welte883340c2018-02-28 18:59:29 +01005342 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005343 f_TfiUsfArrSet(tua, 7, 0);
5344 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5345 f_sleep(1.0);
5346
5347 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005348}
5349
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005350/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005351testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005352 var TfiUsfArr tua := f_TfiUsfArrInit();
5353 var octetstring data := '0000'O & f_rnd_octstring(21);
5354
5355 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005356
Harald Welte883340c2018-02-28 18:59:29 +01005357 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005358 f_TfiUsfArrSet(tua, 7, 0);
5359 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5360 f_sleep(1.0);
5361
5362 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005363}
5364
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005365private function f_TC_pcu_ptcch_ul(uint16_t ra)
5366runs on test_CT {
5367 var template PCUIF_Message pcu_rach_ind;
5368 var PCUIF_send_data sd;
5369 var GsmFrameNumber fn;
5370 timer T;
5371
5372 /* Send an Access Burst on PTCCH/U over the Um-interface */
5373 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5374 chan_nr := ts_RslChanNr_PDCH(7),
5375 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5376
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005377 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5378 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005379
5380 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5381 T.start(52.0 * 4.615 / 1000.0);
5382 alt {
5383 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5384 log("Rx an Access Burst on the PCU interface: ", sd.data);
5385 setverdict(pass);
5386 T.stop;
5387 }
5388 [] PCU.receive { repeat; }
5389 [] T.timeout {
5390 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5391 /* Keep going, that's not the end of the world */
5392 }
5393 }
5394}
5395
5396testcase TC_pcu_ptcch() runs on test_CT {
5397 var L1ctlDlMessage dl;
5398 var octetstring data;
5399 timer T;
5400
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005401 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005402 f_init_l1ctl();
5403 f_l1_tune(L1CTL);
5404
5405 /* Activate PDCH channel on TS7 */
5406 f_TC_pcu_act_req(0, 0, 7, true);
5407
5408 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005409 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005410 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005411 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005412 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005413
5414 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5415 for (var integer i := 0; i < 16; i := i + 1) {
5416 log("Sending an Access Burst towards the L1CTL interface");
5417 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5418 }
5419
5420 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5421 data := f_rnd_octstring(23);
5422
5423 /* Verify PTCCH/D: send a random data block, make sure it's received */
5424 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5425 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5426
5427 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5428 * let's give it more time in case if we miss the beginning. */
5429 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5430 alt {
5431 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5432 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5433 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5434 frame := data)) -> value dl {
5435 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5436 setverdict(pass);
5437 T.stop;
5438 }
5439 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5440 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5441 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5442 l2_data := data)) -> value dl {
5443 log("Rx PTCCH/D data block on L1CTL: ", dl);
5444 setverdict(pass);
5445 T.stop;
5446 }
5447 [] L1CTL.receive { repeat; }
5448 [] T.timeout {
5449 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5450 }
5451 }
5452}
5453
Harald Welte883340c2018-02-28 18:59:29 +01005454/* Send AGCH from PCU; check it appears on Um side */
5455testcase TC_pcu_data_req_agch() runs on test_CT {
5456 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005457 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005458 f_init_l1ctl();
5459 f_l1_tune(L1CTL);
5460
5461 f_TC_pcu_act_req(0, 0, 7, true);
5462 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5463
5464 T.start;
5465 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005466 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005467 setverdict(pass);
5468 }
5469 [] L1CTL.receive { repeat; }
5470 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005472 }
5473 }
5474}
5475
Harald Welte928622b2019-05-26 13:22:59 +02005476/* Send AGCH from PCU; check it appears on Um side */
5477testcase TC_pcu_data_req_pch() runs on test_CT {
5478 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005479 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005480 f_init_l1ctl();
5481 f_l1_tune(L1CTL);
5482
5483 f_TC_pcu_act_req(0, 0, 7, true);
5484 /* three characters prefix: last 3 digits of IMSI as ASCII */
5485 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5486
5487 T.start;
5488 alt {
5489 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5490 setverdict(pass);
5491 }
5492 [] L1CTL.receive { repeat; }
5493 [] T.timeout {
5494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5495 }
5496 }
5497}
5498
Harald Welte883340c2018-02-28 18:59:29 +01005499/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5500testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5501 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005502 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005503 f_init_l1ctl();
5504 f_l1_tune(L1CTL);
5505
5506 /* append 3 last imsi digits so BTS can compute pagng group */
5507 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5508
5509 timer T := 0.5;
5510 T.start;
5511 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005512 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005513 /* TODO: verify paging group */
5514 setverdict(pass);
5515 }
5516 [] L1CTL.receive { repeat; }
5517 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005519 }
5520 }
5521}
5522
5523/* Send RACH from Um side, expect it to show up on PCU socket */
5524testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005525 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005526 f_init_l1ctl();
5527 f_l1_tune(L1CTL);
5528
5529 var GsmFrameNumber fn_last := 0;
5530 for (var integer i := 0; i < 1000; i := i+1) {
5531 var OCT1 ra := f_rnd_ra_ps();
5532 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5533 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005535 }
5536 fn_last := fn;
5537
5538 timer T := 2.0;
5539 T.start;
5540 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005541 [] 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 +01005542 T.stop;
5543 }
5544 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005546 }
5547 [] PCU.receive { repeat; }
5548 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005550 }
5551 }
5552 }
5553 setverdict(pass);
5554}
5555
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005556/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5557 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5558testcase TC_pcu_ext_rach_content() runs on test_CT {
5559 var template PCUIF_Message pcu_rach_ind;
5560 var GsmFrameNumber fn_last := 0;
5561 var L1ctlRachSynchSeq synch_seq;
5562 var PCUIF_BurstType pcu_bt;
5563 var GsmFrameNumber fn;
5564 var BIT11 ra11;
5565
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005566 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005567 f_init_l1ctl();
5568 f_l1_tune(L1CTL);
5569
5570 for (var integer i := 0; i < 1000; i := i+1) {
5571 /* We need to test both TS1 & TS2 */
5572 if (i rem 2 == 0) {
5573 synch_seq := RACH_SYNCH_SEQ_TS1;
5574 pcu_bt := BURST_TYPE_1;
5575 } else {
5576 synch_seq := RACH_SYNCH_SEQ_TS2;
5577 pcu_bt := BURST_TYPE_2;
5578 }
5579
5580 ra11 := f_rnd_ra11_ps();
5581 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5582 if (fn == fn_last) {
5583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5584 "Two RACH in same FN?!?");
5585 }
5586 fn_last := fn;
5587
5588 /* Compose the expected message */
5589 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005590 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005591 ra := bit2int(ra11),
5592 is_11bit := 1,
5593 burst_type := pcu_bt,
5594 fn := fn);
5595
5596 timer T := 2.0;
5597 T.start;
5598 alt {
5599 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5600 T.stop;
5601 }
5602 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5604 }
5605 [] PCU.receive { repeat; }
5606 [] T.timeout {
5607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5608 }
5609 }
5610 }
5611 setverdict(pass);
5612}
5613
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005614private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5615runs on test_CT {
5616 var template PCUIF_send_data sdt;
5617 var PCUIF_send_data sd;
5618 var int16_t lqual_cb;
5619 timer T := 1.0;
5620
5621 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5622 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5623
5624 /* Send a random PDTCH frame over Um */
5625 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5626 '0000'O & f_rnd_octstring(21)));
5627
5628 T.start;
5629 alt {
5630 /* If expected link quality is above the threshold */
5631 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5632 lqual_cb := sd.data.u.data_ind.lqual_cb;
5633 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5634
5635 /* Make sure the actual link quality matches the expected value */
5636 if (not match(lqual_cb, lqual_cb_exp)) {
5637 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5638 "expected value ", lqual_cb_exp));
5639 } else {
5640 setverdict(pass);
5641 }
5642 }
5643 /* If expected link quality is below the threshold */
5644 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5646 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5647 }
5648 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5649 [] PCU.receive { repeat; }
5650 [lqual_cb_exp < thresh] T.timeout {
5651 log("Rx nothing, as expected");
5652 setverdict(pass);
5653 }
5654 [lqual_cb_exp >= thresh] T.timeout {
5655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5656 "Timeout waiting for PCUIF_DATA.ind");
5657 }
5658 }
5659}
5660
5661/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5662testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005663 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005664 PCU.clear;
5665
5666 f_init_l1ctl();
5667 f_l1_tune(L1CTL);
5668
5669 /* Activate a PDCH channel on TS7 */
5670 f_TC_pcu_act_req(0, 0, 7, true);
5671
5672 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005673 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005674 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005675 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005676 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005677
5678 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5679 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5680 var TrxcMessage ret;
5681
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005682 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005683
5684 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5685 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5686 }
5687}
5688
Harald Welte883340c2018-02-28 18:59:29 +01005689/* Send PAGING via RSL, expect it to shw up on PCU socket */
5690testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005691 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005692
5693 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005694 var MobileIdentityLV mi_lv;
5695 var octetstring mi_lv_enc;
5696 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005697 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005698
Harald Welte883340c2018-02-28 18:59:29 +01005699 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005700 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005701 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005702 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005703 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005704
5705 /* Fancy encoding for PCUIF */
5706 mi_lv := valueof(ts_MI_LV(mi));
5707 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5708 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005709
5710 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005711 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005712 T.start;
5713 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005714 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005715 }
5716 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005718 }
5719 [] PCU.receive { repeat; }
5720 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005721 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005722 }
5723 }
5724 }
5725 setverdict(pass);
5726}
5727
Harald Welted66c9b82019-05-25 09:03:15 +02005728/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5729testcase TC_pcu_time_ind() runs on test_CT {
5730 var PCUIF_send_data pcu_sd;
5731 var integer num_time_ind := 0;
5732 var integer first_fn, last_fn;
5733 var float test_duration := 5.0;
5734 timer T;
5735
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005736 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005737 f_TC_pcu_act_req(0, 0, 7, true);
5738
5739 PCU.clear;
5740 T.start(test_duration);
5741 alt {
5742 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5743 num_time_ind := num_time_ind + 1;
5744 if (not isbound(first_fn)) {
5745 first_fn := pcu_sd.data.u.time_ind.fn;
5746 }
5747 last_fn := pcu_sd.data.u.time_ind.fn;
5748 repeat;
5749 }
5750 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5751 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5752 repeat;
5753 }
5754 [] PCU.receive {
5755 repeat;
5756 }
5757 [] T.timeout {}
5758 }
5759 var integer fn_expired := last_fn - first_fn;
5760 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5761
5762 /* verify the number of frames expired matches our expectation */
5763 const float c_GSM_FN_DURATION_MS := 4.61538;
5764 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005765 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005766 if (not match(fn_expired, t_fn_expected)) {
5767 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5768 }
5769
5770 /* There are three TIME.ind in every fn MOD 13 */
5771 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5772 /* Add some tolerance */
5773 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5774 if (not match(num_time_ind, t_time_ind_exp)) {
5775 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5776 }
5777
5778 setverdict(pass);
5779}
5780
Harald Welte4832c862019-05-25 14:57:18 +02005781/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5782testcase TC_pcu_rts_req() runs on test_CT {
5783 var PCUIF_send_data pcu_sd;
5784 var integer first_fn, last_fn;
5785 var integer num_rts_pdtch := 0;
5786 var integer num_rts_ptcch := 0;
5787 var float test_duration := 5.0;
5788 timer T;
5789
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005790 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005791 f_TC_pcu_act_req(0, 0, 7, true);
5792
5793 PCU.clear;
5794 T.start(test_duration);
5795 alt {
5796 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5797 -> value pcu_sd {
5798 num_rts_pdtch := num_rts_pdtch + 1;
5799 if (not isbound(first_fn)) {
5800 first_fn := pcu_sd.data.u.rts_req.fn;
5801 }
5802 last_fn := pcu_sd.data.u.rts_req.fn;
5803 repeat;
5804 }
5805 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5806 -> value pcu_sd {
5807 num_rts_ptcch := num_rts_ptcch + 1;
5808 if (not isbound(first_fn)) {
5809 first_fn := pcu_sd.data.u.rts_req.fn;
5810 }
5811 last_fn := pcu_sd.data.u.rts_req.fn;
5812 repeat;
5813 }
5814 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5815 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5816 repeat;
5817 }
5818 [] PCU.receive {
5819 repeat;
5820 }
5821 [] T.timeout {}
5822 }
5823 var integer fn_expired := last_fn - first_fn;
5824 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5825 ", num_rts_ptcch=", num_rts_ptcch);
5826
5827 /* verify the number of frames expired matches our expectation */
5828 const float c_GSM_FN_DURATION_MS := 4.61538;
5829 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005830 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005831 if (not match(fn_expired, t_fn_expected)) {
5832 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5833 }
5834
5835 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5836 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5837 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5838 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5839 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5840 t_ptcch_exp);
5841 }
5842
5843 /* We have 12 PDTCH blocks every 52-multiframe */
5844 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5845 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5846 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5847 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5848 t_pdtch_exp);
5849 }
5850
5851 setverdict(pass);
5852}
5853
Harald Welte07bd2d22019-05-25 11:03:30 +02005854/* test for generating Abis side OML ALERT from the PCU */
5855testcase TC_pcu_oml_alert() runs on test_CT {
5856 var PCUIF_send_data pcu_sd;
5857 var integer num_time_ind := 0;
5858 var integer first_fn, last_fn;
5859 var float test_duration := 5.0;
5860 timer T;
5861
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005862 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005863 f_TC_pcu_act_req(0, 0, 7, true);
5864
5865 /* re-connect CTRL port from BTS to BSC */
5866 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005867 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005868
5869 /* Send that OML Alert */
5870 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5871
5872 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5873 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5874 setverdict(pass);
5875}
5876
Harald Welteeaa9a862019-05-26 23:01:08 +02005877/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5878private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5879 var PCUIF_Message first_info;
5880 var integer pcu_conn_id := -1;
5881 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5882 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5883 var OCT4 tlli := '01020304'O;
5884 var OCT1 cause := '23'O;
5885 timer T := 5.0;
5886
5887 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5888
5889 f_l1_tune(L1CTL);
5890 RSL.clear;
5891
5892 f_est_dchan();
5893 L1CTL.clear;
5894
5895 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5896
5897 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5898 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5899 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5900
5901 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5902 T.start;
5903 alt {
5904 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5905 setverdict(pass);
5906 }
5907 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5908 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5909 }
5910 [] PCU.receive {
5911 repeat;
5912 }
5913 [] T.timeout {
5914 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5915 }
5916 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005917
5918 /* release the channel */
5919 f_rsl_chan_deact();
5920 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5921 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005922}
5923testcase TC_pcu_rr_suspend() runs on test_CT {
5924 var ConnHdlrPars pars;
5925 var ConnHdlr vc_conn;
5926
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005927 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005928
5929 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5930 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5931 vc_conn.done;
5932}
Harald Welte07bd2d22019-05-25 11:03:30 +02005933
Harald Weltea2e0e942019-05-27 18:12:53 +02005934/* Ensure that PCUIF socket can accept only a single connection */
5935testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005936 var boolean connected := false;
5937 var UD_connect_result cr;
5938 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005939 timer T := 5.0;
5940
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005941 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5942 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5943
Harald Weltea2e0e942019-05-27 18:12:53 +02005944 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005945 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005946
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005947 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005948 PCU.send(UD_connect:{mp_pcu_socket, -1});
5949 T.start;
5950 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005951 /* the IUT will first accept() the new connection, and close() it immediately */
5952 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5953 log("BTS has accept()ed connection");
5954 connected := true;
5955 cid := cr.id;
5956 repeat;
5957 }
5958 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5959 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005960 setverdict(pass);
5961 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005962 /* ignore other messages related to the first connection */
5963 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005964 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005965 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005966 }
5967 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005968
Harald Weltea2e0e942019-05-27 18:12:53 +02005969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5970}
5971
Harald Weltec8effb72019-05-27 18:23:04 +02005972/* Ensure that PCUIF socket can disconnect + reconnect */
5973testcase TC_pcu_socket_reconnect() runs on test_CT {
5974 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005975 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005976
5977 f_sleep(1.0);
5978
5979 f_pcuif_close(PCU, g_pcu_conn_id);
5980 g_pcu_conn_id := -1;
5981
5982 f_sleep(1.0);
5983
5984 /* re-connect */
5985 PCU.clear;
5986 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5987 setverdict(pass);
5988
5989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5990}
5991
Harald Weltebe030482019-05-27 22:29:35 +02005992/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005993private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5994runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005995 var L1ctlDlMessage l1_dl;
5996 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005997 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005998 timer T := 5.0;
5999 T.start;
6000 alt {
6001 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006002 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6003 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006004 repeat;
6005 }
6006 }
6007 [] pt.receive {
6008 repeat;
6009 }
6010 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6012 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006013 }
6014 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006015 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006016}
6017
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006018/* Check if GPRS Indicator is present in RR System Information of a given type */
6019private function f_si_has_gprs_indicator(RrMessageType si_type)
6020runs on test_CT return boolean {
6021 var SystemInformation si := f_get_si(L1CTL, si_type);
6022
6023 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006024 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006025 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006026 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006027 }
6028
6029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6030 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006031}
6032
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006033/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6034private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6035runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006036 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006037 f_init_l1ctl();
6038 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006039 f_sleep(2.0);
6040 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006041
6042 if (f_si_has_gprs_indicator(si_type)) {
6043 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006044 } else {
6045 setverdict(pass);
6046 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006047
Harald Weltebe030482019-05-27 22:29:35 +02006048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6049}
6050
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006051testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6052 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6053}
Harald Weltebe030482019-05-27 22:29:35 +02006054
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006055testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6056 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6057}
6058
6059/* Ensure that GPRS capability is advertised after PCU socket connect */
6060private function f_TC_pcu_socket_connect(RrMessageType si_type)
6061runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006062 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006063 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006064 f_init_l1ctl();
6065 f_l1_tune(L1CTL);
6066
6067 f_sleep(2.0);
6068 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006069
6070 if (not f_si_has_gprs_indicator(si_type)) {
6071 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006072 } else {
6073 setverdict(pass);
6074 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006075
Harald Weltebe030482019-05-27 22:29:35 +02006076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6077}
6078
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006079testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6080 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6081}
Harald Weltebe030482019-05-27 22:29:35 +02006082
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006083testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6084 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6085}
6086
6087/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6088private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6089runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006090 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006091 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006092 f_init_l1ctl();
6093 f_l1_tune(L1CTL);
6094
6095 f_pcuif_close(PCU, g_pcu_conn_id);
6096 g_pcu_conn_id := -1;
6097
6098 f_sleep(1.0);
6099
6100 /* re-connect */
6101 PCU.clear;
6102 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6103
6104 f_sleep(2.0);
6105 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006106
6107 if (f_si_has_gprs_indicator(si_type)) {
6108 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006109 } else {
6110 setverdict(pass);
6111 }
6112
6113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6114}
6115
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006116testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6117 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6118}
6119
6120testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6121 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6122}
6123
Oliver Smithf5239c72019-08-28 10:01:25 +02006124/* 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) */
6125testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6126 var SystemInformation si3 := valueof(ts_SI3_default);
6127
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006128 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006129
Harald Welte76220222020-10-11 20:32:44 +02006130 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6131 * information */
6132 timer T := 2.0;
6133 T.start;
6134 alt {
6135 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6136 [] T.timeout {}
6137 }
6138
Oliver Smithf5239c72019-08-28 10:01:25 +02006139 /* Verify cell_id */
6140 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6141 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6142 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006143 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6144 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6145 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006146 }
6147
6148 /* Verify LAC */
6149 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6150 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6151 if (lac_si3 != lac_pcu) {
6152 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6153 }
6154
6155 setverdict(pass);
6156}
Harald Welted66c9b82019-05-25 09:03:15 +02006157
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006158/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6159testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6160 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006161 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006162
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006163 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006164
6165 info_ind := g_pcu_last_info.u.info_ind;
6166
6167 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6168 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006169 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006170 /* Skip inactive timeslots */
6171 continue;
6172 }
6173
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006174 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006175 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006176 else
6177 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006178
6179 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006180 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006181 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006182 hsn := fhp.maio_hsn.hsn,
6183 maio := fhp.maio_hsn.maio,
6184 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006185 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006186 } else {
6187 tr_ts := tr_PCUIF_InfoTrxTsH0;
6188 }
6189
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006190 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006191 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6192 if (not match(ts, tr_ts)) {
6193 setverdict(fail, "Hopping parameters do not match: ",
6194 "received ", ts, " vs expected ", tr_ts);
6195 } else {
6196 setverdict(pass);
6197 }
6198 }
6199 }
6200}
6201
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006202/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006203testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6204 f_init_vty_bsc();
6205 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6206 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6207
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006208 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006209
6210 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006211 var template PCUIF_RemoteAddr tr_remote_addr := {
6212 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006213 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006214 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006215
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006216 if (not match(remote_addr, tr_remote_addr)) {
6217 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006218 }
6219
6220 setverdict(pass);
6221}
6222
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006223/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006224testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6225 f_init_vty_bsc();
6226 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6227
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006228 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006229
6230 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006231 var template PCUIF_RemoteAddr tr_remote_addr := {
6232 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6233 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6234 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006235
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006236 if (not match(remote_addr, tr_remote_addr)) {
6237 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006238 }
6239
6240 setverdict(pass);
6241}
6242
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006243/* Verify coding of two NSVCs in the INFO.ind message */
6244testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6245 f_init_vty_bsc();
6246
6247 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6248 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6249 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6250 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6251
6252 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6253 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6254 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6255 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6256
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006257 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006258
6259 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6260 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6261 var template PCUIF_RemoteAddr tr_remote_addr := {
6262 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006263 addr := {
6264 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6265 f_inet6_addr("fd00::ca:ff:ee")
6266 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006267 };
6268
6269 if (not match(info_ind.nsvci, { 1234, 5678 }))
6270 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6271 if (not match(remote_addr, tr_remote_addr))
6272 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6273 if (not match(info_ind.local_port, { 1234, 5678 }))
6274 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6275 if (not match(info_ind.remote_port, { 1234, 5678 }))
6276 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6277
6278 setverdict(pass);
6279}
6280
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006281/* Verify periodic interference reports on PDCH */
6282testcase TC_pcu_interf_ind() runs on test_CT {
6283 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006284 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006285 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006286 var PCUIF_send_data sd;
6287 timer T;
6288
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006289 /* Set the averaging/reporting period to 480ms */
6290 f_init_vty_bsc();
6291 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6292 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6293
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006294 f_init_with_pcuif();
6295 f_TC_pcu_act_req(0, 0, 7, true);
6296
6297 /* We need trxcon for NOPE indications */
6298 f_init_l1ctl();
6299 f_l1_tune(L1CTL);
6300
6301 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006302 tr_interf_ind := tr_PCUIF_INTERF_IND(
6303 bts_nr := 0,
6304 trx_nr := 0,
6305 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006306 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006307 );
6308
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006309 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006310 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006311 /* The first interference report may contain unreliable values, so we ignore it */
6312 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6313 /* 4 SACCH periods => 4 reports (plus some guard time) */
6314 T.start(0.480 * 4.0 + 0.480 / 2.0);
6315 first := false;
6316 repeat;
6317 }
6318 /* Subsequent interference reports shall match our expectations */
6319 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006320 /* Check TDMA frame number period */
6321 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6322 setverdict(fail, "Odd TDMA frame number := ",
6323 sd.data.u.interf_ind.fn);
6324 }
6325 interf_ind_num := interf_ind_num + 1;
6326 if (interf_ind_num < 4)
6327 { repeat; }
6328 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006329 [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 +02006330 setverdict(fail, "Received unexpected interference report: ", sd.data);
6331 }
6332 [] PCU.receive { repeat; }
6333 [] T.timeout {
6334 setverdict(fail, "Timeout waiting for interference reports");
6335 }
6336 }
6337
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006338 /* Reset the averaging/reporting period back to default */
6339 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6340
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6342}
6343
Harald Welte3d04ae62018-04-04 20:29:05 +02006344/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006345 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006346 ***********************************************************************/
6347
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006348private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6349 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006350runs on ConnHdlr {
6351 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006352
6353 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006354 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006355 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6356 repeat;
6357 }
6358 }
6359}
6360
6361private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6362runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006363 /* Expect BTS to immediately acknowledge activation as PDCH */
6364 PCU.clear;
6365 f_rsl_chan_act(g_pars.chan_mode);
6366 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006367 timer T_wait := 2.0;
6368 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006369 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006370 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006371 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006372 [] T_wait.timeout {
6373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6374 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6375 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006376 }
6377 /* try to activate this PDCH from the PCU point of view */
6378 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6379 /* FIXME: is there a response? */
6380}
6381
6382private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6383runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006384 /* Send RSL CHAN REL (deactivate) */
6385 PCU.clear;
6386 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6387 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006388 timer T_wait := 2.0;
6389 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006390 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006391 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006392 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006393 [] T_wait.timeout {
6394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6395 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6396 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006397 }
6398 /* Emulate PCU asking BTS to deactivate PDCH */
6399 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6400 alt {
6401 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6402 setverdict(pass);
6403 }
6404 [] RSL.receive { repeat; }
6405 }
6406}
6407
6408/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006409private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006410 var PCUIF_Message first_info;
6411 var integer ts_nr := g_chan_nr.tn;
6412 var integer trx_nr := 0;
6413 var integer bts_nr := 0;
6414 var integer pcu_conn_id := -1;
6415
6416 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6417
6418 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6419 f_sleep(3.0);
6420 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6421 setverdict(pass);
6422}
6423testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6424 var ConnHdlrPars pars;
6425 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006426 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006427
6428 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6429 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6430 vc_conn.done;
6431}
6432
6433/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006434private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006435 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006436 var integer pcu_conn_id := -1;
6437
6438 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6439
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006440 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6441 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6442 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006443 setverdict(pass);
6444}
6445testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6446 var ConnHdlrPars pars;
6447 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006448 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006449
6450 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6451 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6452 vc_conn.done;
6453}
6454
6455/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006456private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006457 var PCUIF_Message first_info;
6458 var integer ts_nr := g_chan_nr.tn;
6459 var integer trx_nr := 0;
6460 var integer bts_nr := 0;
6461 var integer pcu_conn_id := -1;
6462
6463 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6464
6465 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006466 /* Send a second Chan Activ and expect it to be NACKed */
6467 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6468 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006469 setverdict(pass);
6470}
6471testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6472 var ConnHdlrPars pars;
6473 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006474 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006475
6476 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6477 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6478 vc_conn.done;
6479}
6480
6481/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006482private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006483 var PCUIF_Message first_info;
6484 var integer ts_nr := g_chan_nr.tn;
6485 var integer trx_nr := 0;
6486 var integer bts_nr := 0;
6487 var integer pcu_conn_id := -1;
6488 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6489
6490 /* register for the TCH/F channel number */
6491 f_rslem_register(0, chan_nr);
6492
6493 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6494
6495 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6496 "RSL CHAN ACT");
6497 setverdict(pass);
6498}
6499testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6500 var ConnHdlrPars pars;
6501 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006502 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006503
6504 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6505 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6506 vc_conn.done;
6507}
6508
6509/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006510private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006511 var PCUIF_Message first_info;
6512 var integer ts_nr := g_chan_nr.tn;
6513 var integer trx_nr := 0;
6514 var integer bts_nr := 0;
6515 var integer pcu_conn_id := -1;
6516 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6517 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6518
6519 /* register for the TCH/H channel numbers */
6520 f_rslem_register(0, chan_nr[0]);
6521 f_rslem_register(0, chan_nr[1]);
6522
6523 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6524
6525 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6526 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6527 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6528 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6529 setverdict(pass);
6530}
6531testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6532 var ConnHdlrPars pars;
6533 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006534 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006535
6536 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6537 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6538 vc_conn.done;
6539}
6540
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006541/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6542private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6543 var PCUIF_Message first_info;
6544 var integer ts_nr := g_chan_nr.tn;
6545 var integer trx_nr := 0;
6546 var integer bts_nr := 0;
6547 var integer pcu_conn_id := -1;
6548 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6549 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6550 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6551 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6552 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6553 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6554 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6555 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6556
6557 /* register for the TCH/H channel numbers */
6558 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6559 f_rslem_register(0, chan_nr[i]);
6560 }
6561
6562 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6563
6564 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6565 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6566 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6567 }
6568 setverdict(pass);
6569}
6570testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6571 var ConnHdlrPars pars;
6572 var ConnHdlr vc_conn;
6573 f_init();
6574
6575 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6576 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6577 vc_conn.done;
6578}
6579
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006580/* Reproduce a race condition described in OS#5245 */
6581private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6582 f_rsl_chan_act(g_pars.chan_mode);
6583 f_sleep(1.0);
6584 f_rsl_chan_deact();
6585 setverdict(pass);
6586}
6587testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6588 var ConnHdlrPars pars[2];
6589 var ConnHdlr vc_conn[2];
6590 var TrxcMessage rsp;
6591
6592 f_init();
6593
6594 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6595 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6596 ts_TRXC_FAKE_TRXC_DELAY(200));
6597
6598 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6599 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6600 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6601 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6602 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6603 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6604 pars[i], l1ctl := false);
6605 }
6606
6607 /* Wait for all components to finish */
6608 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6609 vc_conn[i].done;
6610 }
6611
6612 /* Disable the artificial delay for TRXC RSP messages */
6613 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6614 ts_TRXC_FAKE_TRXC_DELAY(0));
6615}
6616testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6617 var ConnHdlrPars pars[8];
6618 var ConnHdlr vc_conn[8];
6619 var TrxcMessage rsp;
6620
6621 f_init();
6622
6623 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6624 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6625 ts_TRXC_FAKE_TRXC_DELAY(200));
6626
6627 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6628 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6629 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6630 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6631 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6632 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6633 pars[i], l1ctl := false);
6634 }
6635
6636 /* Wait for all components to finish */
6637 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6638 vc_conn[i].done;
6639 }
6640
6641 /* Disable the artificial delay for TRXC RSP messages */
6642 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6643 ts_TRXC_FAKE_TRXC_DELAY(0));
6644}
6645
Harald Welte9bbbfb52018-04-05 09:33:19 +02006646/***********************************************************************
6647 * IPA Style Dynamic Timeslot Support
6648 ***********************************************************************/
6649
6650private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6651runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006652 /* Expect BTS to immediately acknowledge activation as PDCH */
6653 PCU.clear;
6654 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6655 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006656 timer T_wait := 2.0;
6657 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006658 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006659 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006660 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006661 [] T_wait.timeout {
6662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6663 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6664 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006665 }
6666 /* try to activate this PDCH from the PCU point of view */
6667 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6668 /* FIXME: is there a response? */
6669
6670 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6671}
6672
6673private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6674runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006675 /* Send RSL CHAN REL (deactivate) */
6676 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6677 PCU.clear;
6678 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006679 timer T_wait := 2.0;
6680 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006681 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006682 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006683 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006684 [] T_wait.timeout {
6685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6686 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6687 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006688 }
6689 /* Emulate PCU asking BTS to deactivate PDCH */
6690 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6691 alt {
6692 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6693 setverdict(pass);
6694 }
6695 [] RSL.receive { repeat; }
6696 }
6697}
6698
6699/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006700private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006701 var PCUIF_Message first_info;
6702 var integer ts_nr := g_chan_nr.tn;
6703 var integer trx_nr := 0;
6704 var integer bts_nr := 0;
6705 var integer pcu_conn_id := -1;
6706
6707 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6708
6709 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6710 f_sleep(3.0);
6711 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6712
6713 setverdict(pass);
6714
6715}
6716testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6717 var ConnHdlrPars pars;
6718 var ConnHdlr vc_conn;
6719 f_init();
6720
6721 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6722 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6723 vc_conn.done;
6724}
6725
6726/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006727private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006728 var PCUIF_Message first_info;
6729 var integer ts_nr := g_chan_nr.tn;
6730 var integer trx_nr := 0;
6731 var integer bts_nr := 0;
6732 var integer pcu_conn_id := -1;
6733
6734 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6735
6736 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6737 "RSL CHAN ACT");
6738 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6739 "RF CHAN REL", true);
6740 setverdict(pass);
6741}
6742testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6743 var ConnHdlrPars pars;
6744 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006745 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006746
6747 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6748 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6749 vc_conn.done;
6750}
6751
6752/* 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 +07006753private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006754 var PCUIF_Message first_info;
6755 var integer ts_nr := g_chan_nr.tn;
6756 var integer trx_nr := 0;
6757 var integer bts_nr := 0;
6758 var integer pcu_conn_id := -1;
6759
6760 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6761
6762 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6763 "RSL CHAN ACT");
6764
6765 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6766 alt {
6767 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6768 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006770 }
6771 [] RSL.receive { repeat; }
6772 }
6773
6774 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6775 "RF CHAN REL", true);
6776 setverdict(pass);
6777}
6778testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6779 var ConnHdlrPars pars;
6780 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006781 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006782
6783 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6784 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6785 vc_conn.done;
6786}
6787
6788/* 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 +07006789private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006790 var PCUIF_Message first_info;
6791 var integer ts_nr := g_chan_nr.tn;
6792 var integer trx_nr := 0;
6793 var integer bts_nr := 0;
6794 var integer pcu_conn_id := -1;
6795
6796 /* register for the TCH/F channel number */
6797 f_rslem_register(0, g_chan_nr);
6798
6799 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6800
6801 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6802
6803 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6804 "RSL CHAN ACT");
6805
6806 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6807
6808 setverdict(pass);
6809}
6810testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6811 var ConnHdlrPars pars;
6812 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006813 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006814
6815 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6816 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6817 vc_conn.done;
6818}
6819
6820
Harald Welte0472ab42018-03-12 15:02:26 +01006821/***********************************************************************
6822 * LAPDm / RLL related
6823 ***********************************************************************/
6824
6825private function f_tx_lapdm(template (value) LapdmFrame l,
6826 template (value) RslLinkId link_id) runs on ConnHdlr {
6827 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006828 var template (value) SacchL1Header l1h;
6829
6830 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006831 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006832 /* Compose dummy L1 header */
6833 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6834 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 +02006835 } else {
6836 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006837 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 +01006838 }
Harald Welte0472ab42018-03-12 15:02:26 +01006839}
6840
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006841friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006842 uint3_t sapi,
6843 RslLinkId link_id,
6844 octetstring l3,
6845 boolean exp
6846}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006847friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006848friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6849 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006850 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006851 sapi := sapi,
6852 link_id := id,
6853 l3 := l3,
6854 exp := exp
6855}
6856
6857/* execute the same callback function with a set of different parameters (tcs) on a
6858 * variety of logical channels */
6859private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6860 var ConnHdlrPars pars;
6861 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006862 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006863
6864 /* test on each of the channels we have */
6865 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6866 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6867
6868 /* test each of the test cases on the current channel */
6869 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6870 pars.spec.rll := tcs[j];
6871 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6872 vc_conn := f_start_handler(fn, pars);
6873 vc_conn.done;
6874 }
6875 }
6876
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006878}
6879
6880/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6881private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6882 var RllTestCase tc := g_pars.spec.rll;
6883 timer T := 3.0;
6884
6885 f_l1_tune(L1CTL);
6886 RSL.clear;
6887
6888 /* activate the logical channel */
6889 f_est_dchan();
6890 L1CTL.clear;
6891
6892 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6893 T.start;
6894 alt {
6895 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6896 if (tc.exp) {
6897 setverdict(pass);
6898 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006900 }
6901 }
6902 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6903 if (tc.exp) {
6904 setverdict(pass);
6905 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006907 }
6908 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006909 /* We also expect to receive the measurements */
6910 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006911 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006913 }
6914 [not tc.exp] T.timeout {
6915 setverdict(pass);
6916 }
6917 }
6918
6919 f_rsl_chan_deact();
6920 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6921 f_rslem_unregister(0, g_chan_nr);
6922}
6923testcase TC_rll_est_ind() runs on test_CT {
6924 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006925 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006926 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006927 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006928 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006929 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006930 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6931 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006932 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006933 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006934 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006935 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006936 };
6937 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6938}
6939
6940/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6941private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6942 var RllTestCase tc := g_pars.spec.rll;
6943 var L1ctlDlMessage dl;
6944 timer T := 3.0;
6945
6946 f_l1_tune(L1CTL);
6947 RSL.clear;
6948
6949 /* activate the logical channel */
6950 f_est_dchan();
6951 L1CTL.clear;
6952
6953 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6954 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6955 T.start;
6956 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006957 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006958 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006960 }
6961 }
6962
6963 f_rsl_chan_deact();
6964 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6965 f_rslem_unregister(0, g_chan_nr);
6966}
6967testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6968 var RllTestCases tcs := {
6969 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006970 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006971 };
6972 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6973}
6974testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6975 var RllTestCases tcs := {
6976 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006977 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006978 }
6979 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6980}
6981
6982/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006983friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006984 var L1ctlDlMessage dl;
6985 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6986 var LapdmFrame lapdm;
6987 var octetstring l2 := dl.payload.data_ind.payload;
6988 if (dl.dl_info.link_id.c == SACCH) {
6989 /* remove L1 header */
6990 l2 := substr(l2, 2, lengthof(l2)-2);
6991 }
6992 if (ischosen(exp.ab)) {
6993 lapdm.ab := dec_LapdmFrameAB(l2);
6994 } else if (ischosen(exp.b4)) {
6995 lapdm.b4 := dec_LapdmFrameB4(l2);
6996 } else if (ischosen(exp.bbis)) {
6997 lapdm.bbis := dec_LapdmFrameBbis(l2);
6998 }
6999 log("Rx LAPDm ", lapdm);
7000 if (match(lapdm, exp)) {
7001 setverdict(pass);
7002 } else {
7003 repeat;
7004 }
7005 }
7006 [] L1CTL.receive { repeat; }
7007}
7008private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7009 timer T := t;
7010 T.start;
7011 alt {
7012 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007014 }
7015 [] as_l1_exp_lapdm(exp);
7016 }
7017}
7018
7019/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7020private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
7021 /* send SABM from MS -> BTS */
7022 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7023 /* expect RLL EST IND on Abis */
7024 alt {
7025 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7026 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7027 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007029 }
7030 [] RSL.receive { repeat; }
7031 }
7032 /* expect UA from BTS -> MS */
7033 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7034}
7035
7036/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7037private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7038 var RllTestCase tc := g_pars.spec.rll;
7039
7040 f_l1_tune(L1CTL);
7041 RSL.clear;
7042
7043 /* activate the logical channel */
7044 f_est_dchan();
7045 L1CTL.clear;
7046
7047 /* first establish the link-layer */
7048 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7049
7050 /* then send the DISC */
7051 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7052 /* ... and expect the REL IND on the RSL side */
7053 alt {
7054 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7055 setverdict(pass);
7056 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007057 /* We also expect to receive the measurements */
7058 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007059 }
7060
7061 /* release the channel */
7062 f_rsl_chan_deact();
7063 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7064 f_rslem_unregister(0, g_chan_nr);
7065}
7066testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7067 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007068 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007069 };
7070 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7071}
7072
7073testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7074 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007075 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007076 };
7077 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7078}
7079testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7080 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007081 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007082 };
7083 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7084}
7085testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7086 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007087 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007088 };
7089 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7090}
7091
7092/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7093private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7094 var RllTestCase tc := g_pars.spec.rll;
7095 f_l1_tune(L1CTL);
7096 RSL.clear;
7097
7098 /* activate the logical channel */
7099 f_est_dchan();
7100 L1CTL.clear;
7101
7102 /* first establish the link-layer */
7103 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7104
7105 /* then send the REL REQ via RSL */
7106 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7107 /* ... and expect the DISC on the Um side */
7108 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007109 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007110 /* FIXME: send a UA in resposne to the DISC */
7111 }
7112 }
7113
7114 /* release the channel */
7115 f_rsl_chan_deact();
7116 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7117 f_rslem_unregister(0, g_chan_nr);
7118}
7119testcase TC_rll_rel_req() runs on test_CT {
7120 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007121 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7122 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7123 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7124 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007125 };
7126 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7127}
7128
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007129/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007130testcase TC_rll_data_req() runs on test_CT {
7131}
7132
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007133/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007134testcase TC_rll_data_ind() runs on test_CT {
7135}
7136
7137/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7138private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7139 var RllTestCase tc := g_pars.spec.rll;
7140
7141 f_l1_tune(L1CTL);
7142 RSL.clear;
7143
7144 f_est_dchan();
7145 L1CTL.clear;
7146
7147 /* Send UNITDATA REQ on RSL side */
7148 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7149 /* Expect it to arrive on the other side */
7150 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007151 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007152 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007153 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007154 }
7155
7156 /* release the channel */
7157 f_rsl_chan_deact();
7158 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7159 f_rslem_unregister(0, g_chan_nr);
7160}
7161testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7162 var octetstring l3 := f_rnd_octstring(15);
7163 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007164 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7165 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007166 };
7167 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7168}
7169testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7170 var octetstring l3 := f_rnd_octstring(19);
7171 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007172 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7173 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007174 };
7175 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7176}
7177
7178/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7179private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7180 var RllTestCase tc := g_pars.spec.rll;
7181
7182 f_l1_tune(L1CTL);
7183 RSL.clear;
7184
7185 f_est_dchan();
7186 L1CTL.clear;
7187
7188 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007189 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007190 /* Expdct RLL UNITDATA IND on RSL side */
7191 alt {
7192 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7193 setverdict(pass);
7194 }
7195 [] RSL.receive { repeat; }
7196 }
7197
7198 /* release the channel */
7199 f_rsl_chan_deact();
7200 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7201 f_rslem_unregister(0, g_chan_nr);
7202}
7203testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007204 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007205 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007206 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7207 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007208 };
7209 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7210}
7211testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7212 var octetstring l3 := f_rnd_octstring(18);
7213 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007214 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7215 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007216 };
7217 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7218}
7219
Harald Weltee613f962018-04-18 22:38:16 +02007220/***********************************************************************
7221 * Encryption Related
7222 ***********************************************************************/
7223
7224/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007225private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007226 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7227 if (link_id.c == SACCH) {
7228 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7229 } else {
7230 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7231 }
7232}
7233
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007234/* Expect (or not expect) other kinds of messages */
7235private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7236 [exp_any] RSL.receive { repeat; }
7237 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007239 }
7240}
7241
Harald Weltee613f962018-04-18 22:38:16 +02007242/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007243private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007244 RslLinkId link_id,
7245 octetstring l3,
7246 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007247 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007248) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007249 timer T := 3.0;
7250 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7251 T.start;
7252 /* Expect RLL UNITDATA IND on RSL side */
7253 alt {
7254 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7255 setverdict(pass);
7256 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007257 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007258 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007259 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007261 }
Harald Weltee613f962018-04-18 22:38:16 +02007262 }
7263}
7264
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007265/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7266private function f_data_mo(
7267 RslLinkId link_id,
7268 boolean p, uint3_t nr, uint3_t ns,
7269 octetstring l3,
7270 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007271 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007272) runs on ConnHdlr {
7273 timer T := 3.0;
7274 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7275 T.start;
7276 /* Expect RLL DATA IND on RSL side */
7277 alt {
7278 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7279 setverdict(pass);
7280 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007281 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007282 [] as_rsl_any_ind(exp_any);
7283 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007285 }
7286 }
7287}
7288
Harald Weltee613f962018-04-18 22:38:16 +02007289/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007290private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007291 f_l1_tune(L1CTL);
7292 f_est_dchan(true);
7293
7294 /* now we actually need to transmit some data both ways to check if the encryption works */
7295 var L1ctlDlMessage dl;
7296
Stefan Sperling603d98e2018-07-25 16:47:28 +02007297 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007298 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7299
7300 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7301 f_unitdata_mt(link_id, l3);
7302
7303 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7304 f_unitdata_mo(link_id, l3);
7305
7306 /* release the channel */
7307 f_rsl_chan_deact();
7308 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7309 f_rslem_unregister(0, g_chan_nr);
7310}
7311testcase TC_chan_act_a51() runs on test_CT {
7312 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7313 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7314 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7315}
7316testcase TC_chan_act_a52() runs on test_CT {
7317 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7318 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7319 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7320}
7321testcase TC_chan_act_a53() runs on test_CT {
7322 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7323 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7324 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7325}
Eric Wildb9260392021-05-15 19:48:22 +02007326testcase TC_chan_act_a54() runs on test_CT {
7327 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7328 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7329 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7330}
Harald Weltee613f962018-04-18 22:38:16 +02007331
Eric Wildf1827a72019-05-28 17:37:35 +02007332/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7333 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 +07007334private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007335 f_l1_tune(L1CTL);
7336 f_est_dchan(true);
7337
7338 /* now we actually need to transmit some data both ways to check if the encryption works */
7339 var L1ctlDlMessage dl;
7340
7341 var octetstring l3 := f_rnd_octstring(20);
7342 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7343
7344 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7345 f_unitdata_mt(link_id, l3);
7346
7347 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7348 f_unitdata_mo(link_id, l3);
7349
7350 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007351 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007352
7353 /* modify key to break proper encryption */
7354 g_pars.encr.key := f_rnd_octstring(8);
7355 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7356 rsl.ies := rsl.ies & { ei };
7357 RSL.send(rsl);
7358
7359 timer T0 := 1.0;
7360 T0.start;
7361 /* Expect RSL MODIFY ACK */
7362 alt {
7363 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7364 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7366 }
7367 [] T0.timeout {
7368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7369 }
7370 }
7371
7372 var octetstring l3msg := f_rnd_octstring(15);
7373 timer T1 := 3.0;
7374 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7375 due to broken encryption */
7376 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7377 T1.start;
7378 alt {
7379 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7381 }
7382 [] T1.timeout {
7383 setverdict(pass);
7384 }
7385 }
7386
7387 /* release the channel */
7388 f_rsl_chan_deact();
7389 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7390 f_rslem_unregister(0, g_chan_nr);
7391}
7392testcase TC_rsl_modify_encr() runs on test_CT {
7393 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7394 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7395 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7396}
Harald Weltee613f962018-04-18 22:38:16 +02007397
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007398/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007399private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007400runs on test_CT {
7401 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7402 var ASP_RSL_Unitdata ud;
7403 timer T;
7404
7405 /* Intave is 6 SACCH periods by default */
7406 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7407
7408 T.start(Tval);
7409 alt {
7410 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7411 setverdict(pass);
7412 }
7413 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7414 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7415 }
7416 [] RSL_CCHAN.receive { repeat; }
7417 [] T.timeout {
7418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7419 "Timeout waiting for RF RESource INDication");
7420 }
7421 }
7422}
7423testcase TC_rsl_rf_resource_ind() runs on test_CT {
7424 var RSL_ResourceInfo info := { };
7425
7426 f_init(trx_nr := 0);
7427
7428 f_init_l1ctl();
7429 f_l1_tune(L1CTL);
7430
7431 /* g_AllChannels contains all logical channels */
7432 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7433 var RslChannelNr chan_nr := g_AllChannels[i];
7434
7435 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7436 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7437 { continue; }
7438
7439 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7440 }
7441
7442 /* Align to the first interference report */
7443 f_TC_rsl_rf_resource_ind(?);
7444
7445 /* Test 4 consecutive messages */
7446 for (var integer i := 0; i < 4; i := i + 1) {
7447 f_TC_rsl_rf_resource_ind(info);
7448 }
7449
7450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7451}
7452
Harald Weltee613f962018-04-18 22:38:16 +02007453/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007454private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007455 /* L3 payload doesn't matter, as it is passed transparently */
7456 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7457 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7458 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7459
7460 f_l1_tune(L1CTL);
7461
7462 /* first establish a dedicated channel in the clear */
7463 f_est_dchan(false);
7464
7465 /* Establish ABM */
7466 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7467
7468 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7469 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7470 /* expect the L3 to arrive still unencrypted on the MS side */
7471 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7472
7473 /* configure L1 to apply ciphering */
7474 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7475 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7476
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007477 /* send first ciphered I-frame in response and expect it on RSL */
7478 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007479
7480 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7481 * and hence enable encryption also on the downlink */
7482
7483 /* expect bi-directional communication work in encrypted mode */
7484 f_unitdata_mo(link_id, f_rnd_octstring(15));
7485 f_unitdata_mt(link_id, f_rnd_octstring(15));
7486
7487 /* release the channel */
7488 f_rsl_chan_deact();
7489 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7490 f_rslem_unregister(0, g_chan_nr);
7491}
7492testcase TC_encr_cmd_a51() runs on test_CT {
7493 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7494 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7495 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7496}
7497testcase TC_encr_cmd_a52() runs on test_CT {
7498 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7499 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7500 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7501}
7502testcase TC_encr_cmd_a53() runs on test_CT {
7503 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7504 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7505 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7506}
Eric Wildb9260392021-05-15 19:48:22 +02007507testcase TC_encr_cmd_a54() runs on test_CT {
7508 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7509 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7510 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7511}
Harald Weltee613f962018-04-18 22:38:16 +02007512
7513private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7514 var LapdmFrame lf;
7515 var octetstring reenc;
7516
7517 /* decode the LAPDm frame */
7518 if (ischosen(exp_match.ab)) {
7519 lf.ab := dec_LapdmFrameAB(enc);
7520 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007522 }
7523
7524 /* check if decoder result matches expectation */
7525 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007527 } else {
7528 log(name, ": matched");
7529 setverdict(pass);
7530 }
7531
7532 /* test if re-encoded frame equals original input */
7533 reenc := enc_LapdmFrame(lf);
7534 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007536 } else {
7537 setverdict(pass);
7538 }
7539}
7540
7541testcase TC_lapdm_selftest() runs on test_CT {
7542 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7543 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7544 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7545 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7546 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7547 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7548 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7549}
7550
Stefan Sperling4880be42018-08-07 18:12:59 +02007551/***********************************************************************
7552 * DTX Related (see GSM 05.08, section 8.3)
7553 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007554private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007555 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007556 var GsmFrameNumber first_fn;
7557 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007558 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007559 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007560 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7561 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007562 const integer frame_dtx_tchf_mod := 104;
7563 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7564 * which operates in terms of blocks rather than frames. */
7565 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7566 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007567 timer T := 5.0;
7568
7569 f_l1_tune(L1CTL);
7570 RSL.clear;
7571 L1CTL.clear;
7572
7573 /* activate TCHF signalling channel */
7574 f_est_dchan(false);
7575
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007576 /* A template for matching dummy LAPDm func=UA frames */
7577 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7578 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7579 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7580
Stefan Sperling4880be42018-08-07 18:12:59 +02007581 T.start;
7582 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007583 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007584 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007585
7586 if (is_first_frame) {
7587 is_first_frame := false;
7588 first_fn := dl.dl_info.frame_nr;
7589 }
7590
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007591 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007592 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007593 T.stop;
7594 f_rsl_chan_deact();
7595 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007596
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007597 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7598 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007599
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007600 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007601 setverdict(fail, "Not enough fill frames received: ",
7602 nfill_frames, " out of ", expected_fill_frames);
7603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007604 } else {
7605 setverdict(pass);
7606 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007607 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007608 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7609 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7610 * we should only see the subset of frames numbers which correspond to a block boundary.
7611 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7612 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7613 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007614 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007615 repeat;
7616 }
7617 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007618 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7619 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7620 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007621 f_rsl_chan_deact();
7622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007623 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007624 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007625 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007626 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007627 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007628
7629 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007630 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7631 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007632 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7633 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7634 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007635 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7636 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007637 case else {
7638 /* This shall not happen, just to be sure */
7639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7640 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007641 }
7642
7643 f_rsl_chan_deact();
7644 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007645
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007646 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007647 setverdict(pass);
7648 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007649 setverdict(fail, "Not enough fill frames received: ",
7650 nfill_frames, " out of ", expected_fill_frames);
7651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007652 }
7653 } else {
7654 repeat;
7655 }
7656 }
7657 }
7658 [] L1CTL.receive { repeat; }
7659 [] T.timeout {
7660 f_rsl_chan_deact();
7661 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007663 }
7664 }
7665}
7666
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007667private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007668 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007669 var ConnHdlr vc_conn;
7670 var ConnHdlrPars pars;
7671 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007672 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007673 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007674 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007675 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007676 if (dtxd) {
7677 if (i >= 4) { /* DTX is only allowed on TCH/F */
7678 break;
7679 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007680 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007681 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007682 vc_conn.done;
7683 }
7684}
7685
7686/* Verify that L2 fill frames are sent on TCH in signaling mode if
7687 * there is nothing to transmit while DTX is disabled on downlink. */
7688testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7689 f_tch_sign_l2_fill_frame(false);
7690}
7691
7692/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7693 * there is nothing to transmit while DTX is enabled on downlink. */
7694testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7695 f_tch_sign_l2_fill_frame(true);
7696}
Harald Welte0472ab42018-03-12 15:02:26 +01007697
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007698testcase TC_chopped_ipa_ping() runs on test_CT {
7699 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7700}
7701
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007702testcase TC_chopped_ipa_payload() runs on test_CT {
7703 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7704}
7705
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007706
7707/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7708 * Return value: Measurement Report to be sent (encoded octetstring). */
7709type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7710 runs on ConnHdlr return octetstring;
7711
7712private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7713runs on ConnHdlr {
7714 var L1ctlDlMessage l1_dl;
7715 var SacchL1Header l1h;
7716 var octetstring l2;
7717
7718 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7719 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7720 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7721 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7722
7723 /* Pass it to the user specified call-back function */
7724 l2 := cb.apply(l1h, num_blocks);
7725 /* Send a Measurement Report generated by the call-back */
7726 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7727 l1_dl.dl_info.link_id,
7728 l1h, l2));
7729
7730 /* Shall we keep going? */
7731 num_blocks := num_blocks - 1;
7732 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7733 if (num_blocks > 0) { repeat; }
7734 }
7735 [] L1CTL.receive { repeat; }
7736}
7737
7738private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7739runs on ConnHdlr return octetstring {
7740 /* Command the L1 to apply received parameters */
7741 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7742
7743 /* Dummy measurement report (the results are invalid) */
7744 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7745}
7746
7747private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7748runs on ConnHdlr return octetstring {
7749 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7750 setverdict(fail, "Unexpected MS Power level change: ",
7751 g_pars.l1_pars.ms_power_level, " -> ",
7752 l1h.ms_power_lvl);
7753 }
7754
7755 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7756}
7757
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007758private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7759runs on ConnHdlr return octetstring {
7760 /* UL RSSI oscillation driven by SACCH block number */
7761 if (num_blocks rem 2 == 0) {
7762 f_trxc_fake_rssi(-100);
7763 } else {
7764 f_trxc_fake_rssi(-50);
7765 }
7766
7767 /* Make sure that MS power level remains constant */
7768 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7769}
7770
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007771/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7772private function f_TC_ms_pwr_ctrl_constant(charstring id)
7773runs on ConnHdlr {
7774 var integer num_blocks := 8;
7775 timer T := int2float(num_blocks);
7776
7777 f_l1_tune(L1CTL);
7778 RSL.clear;
7779
7780 /* These IEs are needed for autonomous MS power control */
7781 var template (value) RSL_IE_List ies := {
7782 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7783 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7784 }),
7785 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7786 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7787 })
7788 };
7789
7790 /* Ensure that 'rx-current' equals 'rx-target' */
7791 f_trxc_fake_rssi(mp_uplink_power_target);
7792
7793 /* Establish a dedicated channel */
7794 f_est_dchan(more_ies := valueof(ies));
7795
7796 L1CTL.clear;
7797 T.start;
7798 alt {
7799 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7800 [] T.timeout {
7801 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7802 num_blocks, " were not handled");
7803 }
7804 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007805
7806 /* Release the channel */
7807 f_rsl_chan_deact();
7808 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007809}
7810testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7811 var ConnHdlr vc_conn;
7812 var ConnHdlrPars pars;
7813
7814 f_init();
7815
7816 /* Explicitly configure the Uplink power target (in dBm) */
7817 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7818
7819 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7820 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7821 log(testcasename(), ": starting on ", pars.chan_nr);
7822
7823 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7824 pars, trxc_comp := true);
7825 vc_conn.done;
7826 }
7827
7828 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7830}
7831
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007832/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7833private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7834runs on ConnHdlr {
7835 var integer num_blocks := 16;
7836 timer T := int2float(num_blocks);
7837
7838 f_l1_tune(L1CTL);
7839 RSL.clear;
7840
7841 /* These IEs are needed for autonomous MS power control */
7842 var template (value) RSL_IE_List ies := {
7843 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7844 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7845 }),
7846 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7847 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7848 })
7849 };
7850
7851 /* Ensure that 'rx-current' equals 'rx-target' */
7852 f_trxc_fake_rssi(mp_uplink_power_target);
7853
7854 /* Establish a dedicated channel */
7855 f_est_dchan(more_ies := valueof(ies));
7856
7857 L1CTL.clear;
7858 T.start;
7859 alt {
7860 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7861 [] T.timeout {
7862 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7863 num_blocks, " were not handled");
7864 }
7865 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007866
7867 /* Release the channel */
7868 f_rsl_chan_deact();
7869 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007870}
7871testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7872 var ConnHdlr vc_conn;
7873 var ConnHdlrPars pars;
7874
7875 f_init();
7876
7877 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7878 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7879 /* Explicitly configure the Uplink power range (target and delte) */
7880 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7881 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7882
7883 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7884 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7885 log(testcasename(), ": starting on ", pars.chan_nr);
7886
7887 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7888 pars, trxc_comp := true);
7889 vc_conn.done;
7890 }
7891
7892 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7894}
7895
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007896private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7897 var template L1ctlDlMessage tr_bad_frame;
7898 var L1ctlDlMessage l1_dl;
7899 timer T := 8.0;
7900
7901 f_l1_tune(L1CTL);
7902 RSL.clear;
7903
7904 f_est_dchan();
7905
7906 /* There may be a few errors right after the channel activation */
7907 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7908 L1CTL.clear;
7909
7910 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7911 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7912 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7913 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7914 tr_bad_frame.payload := ?;
7915
7916 T.start;
7917 alt {
7918 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7919 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7920 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7921 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7922 }
7923 [] as_l1_sacch();
7924 [] L1CTL.receive { repeat; }
7925 [] T.timeout {
7926 /* We're done, break the loop */
7927 setverdict(pass);
7928 }
7929 }
7930
7931 f_rsl_chan_deact();
7932 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7933}
7934testcase TC_speech_no_rtp_tchf() runs on test_CT {
7935 var ConnHdlr vc_conn;
7936 var ConnHdlrPars pars;
7937
7938 f_init();
7939
7940 /* TS1, TCH/F, V1 (FR codec) */
7941 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7942 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7943 vc_conn.done;
7944}
7945testcase TC_speech_no_rtp_tchh() runs on test_CT {
7946 var ConnHdlr vc_conn;
7947 var ConnHdlrPars pars;
7948
7949 f_init();
7950
7951 /* TS5, TCH/H, V1 (HR codec) */
7952 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7953 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7954 vc_conn.done;
7955}
7956
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007957/* Verify handling of Downlink and Uplink speech frames */
7958private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7959 var L1ctlDlMessage l1_dl;
7960 var PDU_RTP rtp_pdu;
7961 var octetstring pl;
7962 timer Td, Tu;
7963
7964 f_l1_tune(L1CTL);
7965 f_est_dchan();
7966
7967 /* Activate the RTP emulation */
7968 pl := f_rnd_octstring(6);
7969 f_rtpem_activate(pl);
7970
7971 /* Give the scheduler some time to fill up the buffers */
7972 f_sleep(2.0);
7973 L1CTL.clear;
7974 RSL.clear;
7975
7976 /* Make sure that Downlink frames are received at the UE */
7977 Td.start(2.0);
7978 alt {
7979 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7980 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7981 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7982 l1_dl.payload.traffic_ind.data));
7983 setverdict(pass);
7984 }
7985 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7986 setverdict(fail, "Rx unexpected Downlink speech frame ",
7987 "(", l1_dl.payload.traffic_ind.data, ") ",
7988 "expected (", pl, ")");
7989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7990 }
7991 [] as_l1_sacch();
7992 [] L1CTL.receive { repeat; }
7993 [] Td.timeout {
7994 setverdict(fail, "Timeout waiting for Downlink speech frames");
7995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7996 }
7997 }
7998
7999 /* Make sure that Uplink frames are received at the BTS */
8000 RTPEM_DATA.clear;
8001 Tu.start(2.0);
8002 alt {
8003 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8004 if (rtp_pdu.data != pl)
8005 { repeat; }
8006 }
8007 [] RTPEM_DATA.receive { repeat; }
8008 [] Tu.timeout {
8009 setverdict(fail, "Timeout waiting for Uplink speech frames");
8010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8011 }
8012 }
8013
8014 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8015 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8016 f_rsl_chan_deact();
8017 f_rslem_unregister(0, g_chan_nr);
8018}
8019testcase TC_speech_rtp_tchf() runs on test_CT {
8020 var ConnHdlr vc_conn;
8021 var ConnHdlrPars pars;
8022
8023 f_init();
8024
8025 /* TS1, TCH/F, V1 (FR codec) */
8026 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8027 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8028 vc_conn.done;
8029
8030 /* TS1, TCH/F, V2 (EFR codec) */
8031 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8032 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8033 vc_conn.done;
8034
8035 /* TODO: also test V3 (AMR codec) */
8036
8037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8038}
8039testcase TC_speech_rtp_tchh() runs on test_CT {
8040 var ConnHdlr vc_conn;
8041 var ConnHdlrPars pars;
8042
8043 f_init();
8044
8045 /* TS5, TCH/H0, V1 (HR codec) */
8046 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8047 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8048 vc_conn.done;
8049
8050 /* TODO: also test V3 (AMR codec) */
8051
8052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8053}
8054
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008055private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8056 var GsmFrameNumber fn;
8057 var ChannelDescription ch_desc;
8058 var integer ra := 23;
8059
8060 f_l1_tune(L1CTL);
8061 RSL.clear;
8062
8063 /* Send RACH request and wait for ChanReq */
8064 fn := f_rach_req_wait_chan_rqd(ra);
8065
8066 /* The BSC already sends the Immediate Assignment, before the channel is active.
8067 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8068 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8069 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8070 if (g_pars.fhp.enabled) {
8071 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8072 } else {
8073 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8074 }
8075 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8076 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8077
8078 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8079 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8080 var L1ctlDlMessage dl;
8081 var GsmRrMessage rr;
8082
8083 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8084 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8085 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8086 rr_imm_ass.payload.imm_ass.chan_desc := *;
8087
8088 timer T := 1.0;
8089 T.start;
8090 alt {
8091 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8092 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8093 if (match(rr, rr_imm_ass)) {
8094 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8095 mtc.stop;
8096 } else {
8097 repeat;
8098 }
8099 }
8100 [] L1CTL.receive { repeat; }
8101 [] T.timeout;
8102 }
8103 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8104 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8105
8106 /* Now expect the IMM ASS on Um */
8107 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8108 setverdict(pass);
8109
8110 /* Release the channel */
8111 f_rsl_chan_deact();
8112 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8113}
8114
8115testcase TC_early_immediate_assignment() runs on test_CT {
8116 var ConnHdlr vc_conn;
8117 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8118 f_init();
8119 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8120 vc_conn.done;
8121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8122}
8123
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008124private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8125 var integer ra := oct2int(f_rnd_ra_cs());
8126 var ChannelDescription ch_desc;
8127
8128 /* Tune the MS to BCCH */
8129 f_l1_tune(L1CTL);
8130
8131 /* Send RACH request and wait for ChanReq */
8132 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8133
8134 /* Activate channel on the BTS side */
8135 f_rsl_chan_act(g_pars.chan_mode);
8136
8137 /* Craft channel description (with or without frequency hopping parameters) */
8138 if (g_pars.fhp.enabled) {
8139 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8140 } else {
8141 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8142 }
8143
8144 /* Send IMM.ASS via CCHAN */
8145 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8146 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8147
8148 /* Receive IMM.ASS on the MS side */
8149 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8150
8151 /* Match the Channel Description IE in received IMM.ASS */
8152 if (not match(imm_ass.chan_desc, ch_desc)) {
8153 setverdict(fail, "Channel Description IE does not match");
8154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8155 }
8156
8157 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8158 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8159
8160 /* Expect SACCH frames on Downlink */
8161 L1CTL.clear;
8162 f_exp_sacch(true);
8163
8164 /* We're done, deactivate and release */
8165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8166 f_rsl_chan_deact();
8167}
8168testcase TC_est_dchan() runs on test_CT {
8169 var ConnHdlr vc_conn;
8170 var ConnHdlrPars pars;
8171
8172 f_init();
8173
8174 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8175 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8176 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8177 vc_conn.done;
8178 }
8179
8180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8181}
8182
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008183private type record TopTestCase {
8184 RSL_IE_BS_Power bs_power,
8185 RSL_IE_OSMO_TopAcchCap top_cap,
8186 record of TopTestStep steps
8187};
8188private type record TopTestStep {
8189 MeasurementResults meas_res optional,
8190 GsmRxLev overpower_sacch,
8191 GsmRxLev overpower_facch
8192};
8193
8194private function f_rxlev_match(template (present) RslLinkId link_id,
8195 template (present) GsmRxLev rxlev)
8196runs on ConnHdlr {
8197 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8198 if (not match(dl.dl_info.rx_level, rxlev)) {
8199 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8200 " does not match expected RxLev := ", rxlev);
8201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8202 }
8203}
8204
8205private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8206 var TopTestCase tc := g_pars.spec.top;
8207 var GsmRxLev rxlev_dcch;
8208 var L1ctlDlMessage dl;
8209
8210 /* Wait for Pau ramping to complete */
8211 f_sleep(6.0);
8212
8213 f_l1_tune(L1CTL);
8214 L1CTL.clear;
8215 RSL.clear;
8216
8217 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8218 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8219 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8220
8221 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8222 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8223
8224 /* Additional IEs for the CHANnel ACTIVation message */
8225 var template (value) RSL_IE_List ies := {
8226 /* Employ BS power control in static mode */
8227 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8228 bs_power := tc.bs_power
8229 }),
8230 /* Indicate the given Temporary Overpower capability */
8231 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8232 top_acch_cap := tc.top_cap
8233 })
8234 };
8235
8236 /* Establish a dedicated channel */
8237 f_est_dchan(more_ies := valueof(ies));
8238
8239 /* Give it some time to stabilize */
8240 f_sleep(0.480 * 2.0);
8241 L1CTL.clear;
8242 RSL.clear;
8243
8244 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8245 var TopTestStep step := tc.steps[i];
8246 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8247 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8248
8249 log("Executing step[", i, "] := ", step);
8250
8251 /* Send RR Measurement Report (if present) */
8252 if (ispresent(step.meas_res)) {
8253 f_transceive_meas_rep(step.meas_res);
8254 f_sleep(0.480 * 2.0);
8255 L1CTL.clear;
8256 }
8257
8258 /* Check RxLev on both FACCH and SACCH */
8259 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8260 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8261
8262 setverdict(pass);
8263 }
8264}
8265testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8266 var ConnHdlrPars pars;
8267 var ConnHdlr vc_conn;
8268
8269 f_init();
8270
8271 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008272 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008273 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8274 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8275 steps := {
8276 /* Channel established, no overpower */
8277 { meas_res := omit,
8278 overpower_sacch := 0, overpower_facch := 0 },
8279
8280 /* Worst possible RxQual value, overpower of 4dB */
8281 { meas_res := ts_MeasurementResults(rxq_f := 7),
8282 overpower_sacch := 4, overpower_facch := 4 },
8283 /* Worst possible RxQual value, disabling overpower */
8284 { meas_res := ts_MeasurementResults(rxq_f := 0),
8285 overpower_sacch := 0, overpower_facch := 0 },
8286
8287 /* Lower threshold not reached, no overpower */
8288 { meas_res := ts_MeasurementResults(rxq_f := 1),
8289 overpower_sacch := 0, overpower_facch := 0 },
8290 /* Lower threshold not reached, no overpower */
8291 { meas_res := ts_MeasurementResults(rxq_f := 2),
8292 overpower_sacch := 0, overpower_facch := 0 },
8293 /* Lower threshold reached, overpower of 4dB */
8294 { meas_res := ts_MeasurementResults(rxq_f := 4),
8295 overpower_sacch := 4, overpower_facch := 4 },
8296 /* Upper threshold not reached, keeping overpower */
8297 { meas_res := ts_MeasurementResults(rxq_f := 3),
8298 overpower_sacch := 4, overpower_facch := 4 },
8299 /* Upper threshold reached, disabling overpower */
8300 { meas_res := ts_MeasurementResults(rxq_f := 2),
8301 overpower_sacch := 0, overpower_facch := 0 }
8302 }
8303 };
8304
8305 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8306 spec := { top := top }, trx_nr := 1));
8307 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8308 vc_conn.done;
8309
8310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8311}
8312testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8313 var ConnHdlrPars pars;
8314 var ConnHdlr vc_conn;
8315
8316 f_init();
8317
8318 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008319 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008320 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8321 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8322 steps := {
8323 /* Channel established, no overpower */
8324 { meas_res := omit,
8325 overpower_sacch := 0, overpower_facch := 0 },
8326
8327 /* Invalid measurement results, no overpower */
8328 { meas_res := ts_MeasurementResults(rxq_f := 7,
8329 rxq_s := 7,
8330 valid := false),
8331 overpower_sacch := 0, overpower_facch := 0 },
8332
8333 /* DTXu was in use, no overpower */
8334 { meas_res := ts_MeasurementResults(rxq_f := 7,
8335 rxq_s := 0,
8336 dtx_used := true),
8337 overpower_sacch := 0, overpower_facch := 0 },
8338 /* DTXu was in use, overpower of 4 dB */
8339 { meas_res := ts_MeasurementResults(rxq_f := 0,
8340 rxq_s := 7,
8341 dtx_used := true),
8342 overpower_sacch := 4, overpower_facch := 4 }
8343 }
8344 };
8345
8346 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8347 spec := { top := top }, trx_nr := 1));
8348 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8349 vc_conn.done;
8350
8351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8352}
8353testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8354 var ConnHdlrPars pars;
8355 var ConnHdlr vc_conn;
8356
8357 f_init();
8358
8359 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008360 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008361 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8362 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8363 rxqual := 0, /* always on */
8364 sacch_enable := false),
8365 steps := {
8366 /* Channel established, FACCH overpower */
8367 { meas_res := omit,
8368 overpower_sacch := 0, overpower_facch := 4 },
8369 /* MS indicates good RxQual, no difference */
8370 { meas_res := ts_MeasurementResults(rxq_f := 0),
8371 overpower_sacch := 0, overpower_facch := 4 },
8372 /* MS indicates bad RxQual, no difference */
8373 { meas_res := ts_MeasurementResults(rxq_f := 7),
8374 overpower_sacch := 0, overpower_facch := 4 }
8375 }
8376 };
8377
8378 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8379 spec := { top := top }, trx_nr := 1));
8380 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8381 vc_conn.done;
8382
8383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8384}
8385testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8386 var ConnHdlrPars pars;
8387 var ConnHdlr vc_conn;
8388
8389 f_init();
8390
8391 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008392 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008393 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8394 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8395 rxqual := 0, /* always on */
8396 facch_enable := false),
8397 steps := {
8398 /* Channel established, SACCH overpower */
8399 { meas_res := omit,
8400 overpower_sacch := 4, overpower_facch := 0 },
8401 /* MS indicates good RxQual, no difference */
8402 { meas_res := ts_MeasurementResults(rxq_f := 0),
8403 overpower_sacch := 4, overpower_facch := 0 },
8404 /* MS indicates bad RxQual, no difference */
8405 { meas_res := ts_MeasurementResults(rxq_f := 7),
8406 overpower_sacch := 4, overpower_facch := 0 }
8407 }
8408 };
8409
8410 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8411 spec := { top := top }, trx_nr := 1));
8412 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8413 vc_conn.done;
8414
8415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8416}
8417testcase TC_acch_overpower_limit() runs on test_CT {
8418 var ConnHdlrPars pars;
8419 var ConnHdlr vc_conn;
8420
8421 f_init();
8422
8423 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008424 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008425 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8426 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8427 rxqual := 0 /* always on */),
8428 steps := {
8429 /* Channel established, ACCH overpower of 2dB */
8430 { meas_res := omit,
8431 overpower_sacch := 2, overpower_facch := 2 },
8432 /* MS indicates good RxQual, no difference */
8433 { meas_res := ts_MeasurementResults(rxq_f := 0),
8434 overpower_sacch := 2, overpower_facch := 2 },
8435 /* MS indicates bad RxQual, no difference */
8436 { meas_res := ts_MeasurementResults(rxq_f := 7),
8437 overpower_sacch := 2, overpower_facch := 2 }
8438 }
8439 };
8440
8441 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8442 spec := { top := top }, trx_nr := 1));
8443 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8444 vc_conn.done;
8445
8446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8447}
8448
Harald Welte0472ab42018-03-12 15:02:26 +01008449/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8450/* protocol error as per 44.006 */
8451/* link layer failure (repetition of I-frame N200 times without ACK */
8452/* repetition of SABM or DISC N200 times without ACK */
8453/* receptiom of SABM in multi-frame established state */
8454
8455
Harald Welte68e495b2018-02-25 00:05:57 +01008456/* TODO Areas:
8457
8458* channel activation
8459** with BS_Power / MS_Power, bypassing power control loop
8460** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008461** with timing advance from initial activation on
8462* mode modify
8463** encryption
8464** multirate
8465* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008466** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008467* BS Power Control
8468* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008469* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008470** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008471* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008472** DATA_IND from BTS->PCU
8473** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008474
8475*/
Harald Welte70767382018-02-21 12:16:40 +01008476
8477control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008478 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008479 execute( TC_chan_act_stress() );
8480 execute( TC_chan_act_react() );
8481 execute( TC_chan_deact_not_active() );
8482 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008483 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008484 execute( TC_sacch_filling() );
8485 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008486 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008487 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008488 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008489 execute( TC_sacch_chan_act_ho_async() );
8490 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008491 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008492 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008493 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008494 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008495 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008496 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008497 execute( TC_rach_load_idle_thresh0() );
8498 execute( TC_rach_load_idle_below_thresh() );
8499 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008500 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008501 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008502 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008503 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008504 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008505 execute( TC_meas_res_sign_tchf() );
8506 execute( TC_meas_res_sign_tchh() );
8507 execute( TC_meas_res_sign_sdcch4() );
8508 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008509 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008510 execute( TC_meas_res_speech_tchf_sapi3() );
8511 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008512 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008513 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008514 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008515 execute( TC_rsl_bs_pwr_static_ass() );
8516 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008517 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008518 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008519 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008520 execute( TC_rsl_ms_pwr_dyn_up() );
8521 execute( TC_rsl_ms_pwr_dyn_down() );
8522 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8523 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008524 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008525 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008526 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008527 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008528 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008529 execute( TC_paging_imsi_80percent() );
8530 execute( TC_paging_tmsi_80percent() );
8531 execute( TC_paging_imsi_200percent() );
8532 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008533 execute( TC_rsl_protocol_error() );
8534 execute( TC_rsl_mand_ie_error() );
8535 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008536 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008537 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008538 execute( TC_si_sched_2bis() );
8539 execute( TC_si_sched_2ter() );
8540 execute( TC_si_sched_2ter_2bis() );
8541 execute( TC_si_sched_2quater() );
8542 execute( TC_si_sched_13() );
8543 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008544 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008545 execute( TC_ipa_crcx_twice_not_active() );
8546 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008547 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008548 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008549
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008550 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008551 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008552 execute( TC_pcu_act_req() );
8553 execute( TC_pcu_act_req_wrong_ts() );
8554 execute( TC_pcu_act_req_wrong_bts() );
8555 execute( TC_pcu_act_req_wrong_trx() );
8556 execute( TC_pcu_deact_req() );
8557 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008558 execute( TC_pcu_ver_si1() );
8559 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008560 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008561 if (mp_l1_supports_gprs) {
8562 execute( TC_pcu_data_req_pdtch() );
8563 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008564 execute( TC_pcu_data_req_wrong_bts() );
8565 execute( TC_pcu_data_req_wrong_trx() );
8566 execute( TC_pcu_data_req_wrong_ts() );
8567 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008568 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008569 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008570 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008571 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008572 execute( TC_pcu_data_req_imm_ass_pch() );
8573 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008574 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008575 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008576 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008577 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008578 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008579 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008580 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008581 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008582 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008583 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008584 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008585 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008586 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008587 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008588 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008589 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008590 execute( TC_dyn_osmo_pdch_act_deact() );
8591 execute( TC_dyn_osmo_pdch_double_act() );
8592 execute( TC_dyn_ipa_pdch_act_deact() );
8593 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008594 execute( TC_pcu_info_ind_fh_params() );
8595 execute( TC_pcu_socket_nsvc_ipv4() );
8596 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008597 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008598 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008599 } else {
8600 log("PCU socket path not available, skipping PCU tests");
8601 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008602
Harald Welte3d04ae62018-04-04 20:29:05 +02008603 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008604 execute( TC_dyn_osmo_pdch_tchf_act() );
8605 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008606 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008607 execute( TC_dyn_ipa_pdch_tchf_act() );
8608 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008609
8610 execute( TC_rll_est_ind() );
8611 execute( TC_rll_est_req_DCCH_3() );
8612 execute( TC_rll_est_req_ACCH_3() );
8613 execute( TC_rll_rel_ind_DCCH_0() );
8614 execute( TC_rll_rel_ind_DCCH_3() );
8615 execute( TC_rll_rel_ind_ACCH_0() );
8616 execute( TC_rll_rel_ind_ACCH_3() );
8617 execute( TC_rll_rel_req() );
8618 execute( TC_rll_unit_data_req_DCCH() );
8619 execute( TC_rll_unit_data_req_ACCH() );
8620 execute( TC_rll_unit_data_ind_DCCH() );
8621 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008622
8623 execute( TC_chan_act_a51() );
8624 execute( TC_chan_act_a52() );
8625 execute( TC_chan_act_a53() );
8626 execute( TC_encr_cmd_a51() );
8627 execute( TC_encr_cmd_a52() );
8628 execute( TC_encr_cmd_a53() );
8629
Harald Welteee25aae2019-05-19 14:32:37 +02008630 execute( TC_err_rep_wrong_mdisc() );
8631 execute( TC_err_rep_wrong_msg_type() );
8632 execute( TC_err_rep_wrong_sequence() );
8633
Harald Weltee613f962018-04-18 22:38:16 +02008634 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008635
8636 execute( TC_tch_sign_l2_fill_frame() );
8637 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008638
8639 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008640 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008641
8642 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008643 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008644
8645 execute( TC_speech_no_rtp_tchf() );
8646 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008647 execute( TC_speech_rtp_tchf() );
8648 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008649
8650 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008651
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008652 execute( TC_acch_overpower_rxqual_thresh() );
8653 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8654 execute( TC_acch_overpower_always_on_facch() );
8655 execute( TC_acch_overpower_always_on_sacch() );
8656 execute( TC_acch_overpower_limit() );
8657
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008658 /* BEWARE: these test cases can potentially break the IUT or cause
8659 * weird/unexpected behavior. Ensure that they are executed last. */
8660 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8661 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008662}
8663
8664
8665}