blob: c2de53834739d3c9e93d8795a8b5cad9faea8d7e [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
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002535 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2536 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2537 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2538 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2539 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002540 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2541 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002542 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002543
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002544 /* Step 3b: send MDCX with the configured address/port to the IUT */
2545 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2546 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2547 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2548 remote_port := rtpem_bind_port,
2549 rtp_pt2 := 0),
2550 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2551 "IPA MDCX ACK");
2552
2553 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2554 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2555 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2556 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002557
2558 /* Step 5: set the given RTP emulation mode */
2559 f_rtpem_mode(RTPEM_CTRL, mode);
2560}
2561
Harald Welte70767382018-02-21 12:16:40 +01002562/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002563private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002564 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002565 RSL.clear;
2566
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002567 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002568 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002569 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002570 }
Harald Welte70767382018-02-21 12:16:40 +01002571
2572 f_est_dchan();
2573
2574 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2575 * RSL measurement reports on Abis side */
2576 timer T := 8.0;
2577 T.start;
2578 alt {
2579 [] as_l1_sacch();
2580 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002581 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002582 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002583 [] L1CTL.receive { repeat; }
2584 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002585 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002586 * of any earlier errors, so if we reach this timeout, we're good */
2587 setverdict(pass);
2588 }
2589 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002591 }
2592 }
2593 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002594 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002595}
Harald Welte0472ab42018-03-12 15:02:26 +01002596
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002597/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2598private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002599 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002600 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2601 timer Tup := 10.0;
2602 Tup.start;
2603 alt {
2604 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2605 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2606 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002607
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002608 if (rx_lvl != max_rx_lvl) {
2609 repeat;
2610 }
2611 Tup.stop;
2612 }
2613 [] L1CTL.receive { repeat; }
2614 [] Tup.timeout {
2615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2616 log2str("Didn't reach full power ", max_rx_lvl));
2617 }
2618 }
2619 return max_rx_lvl;
2620}
2621
2622/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2623private function f_verify_ramp_up() runs on ConnHdlr {
2624 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002625 var integer initial_rx_lvl := -1;
2626 var integer last_rx_lvl := -1;
2627 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2628
2629 timer T := 2.0;
2630 alt {
2631 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2632 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2633 log("Received rx_level=", rx_lvl);
2634 if (initial_rx_lvl == -1) {
2635 initial_rx_lvl := rx_lvl;
2636 last_rx_lvl := rx_lvl;
2637
2638 /* Expect a somehow low value during first received messages */
2639 if (initial_rx_lvl >= max_rx_lvl / 2) {
2640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2641 log2str("Detected high initial tx power during ramp up: ",
2642 initial_rx_lvl , ", full power is", max_rx_lvl));
2643 }
2644 }
2645
2646 /* received Rx level bigger than maximum allowed power by CN */
2647 if (rx_lvl > max_rx_lvl) {
2648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2649 log2str("Detected Tx power higher than full power: ",
2650 rx_lvl , " > ", max_rx_lvl));
2651 }
2652
2653 /* Make sure it never decreases, since we are rumping up */
2654 if (last_rx_lvl > rx_lvl) {
2655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2656 log2str("Detected Tx power decrease during ramp up: ",
2657 last_rx_lvl , " -> ", rx_lvl));
2658 }
2659
2660 if (rx_lvl == max_rx_lvl and not T.running) {
2661 /* We reached the maximum power, start timer and receive
2662 /* a few more to make sure we don't surpass it */
2663 log("Reached full power, wating a bit more until success");
2664 T.start;
2665 }
2666
2667 last_rx_lvl := rx_lvl;
2668 repeat;
2669 }
2670 [] L1CTL.receive { repeat; }
2671 [] T.timeout { }
2672 }
2673
2674 /* We didn't increase tx power during ramp up */
2675 if (initial_rx_lvl < last_rx_lvl) {
2676 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2677 } else {
2678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2679 log2str("No Tx power increase during whole ramp up: ",
2680 initial_rx_lvl , " -> ", last_rx_lvl));
2681 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002682}
2683
2684/* verify BTS ramps power down to rx_level 0 */
2685private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2686 var L1ctlDlMessage l1_dl;
2687 var integer last_rx_lvl := max_rx_lvl;
2688
2689 timer Tdown := 5.0;
2690 Tdown.start;
2691 alt {
2692 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2693 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2694 log("Received rx_level=", rx_lvl);
2695
2696 /* received Rx level bigger than maximum allowed power by CN */
2697 if (rx_lvl > max_rx_lvl) {
2698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2699 log2str("Detected Tx power higher than full power: ",
2700 rx_lvl , " > ", max_rx_lvl));
2701 }
2702
2703 /* Make sure it never increases, since we are rumping down */
2704 if (last_rx_lvl < rx_lvl) {
2705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2706 log2str("Detected Tx power increase during ramp up: ",
2707 last_rx_lvl , " -> ", rx_lvl));
2708 }
2709
2710 last_rx_lvl := rx_lvl;
2711 if (last_rx_lvl != 0) {
2712 repeat;
2713 }
2714 /* we reached power level 0, we are done */
2715 Tdown.stop;
2716 }
2717 [] L1CTL.receive { repeat; }
2718 [] Tdown.timeout { }
2719 }
2720
2721 /* We didn't increase tx power during ramp down */
2722 if (max_rx_lvl > last_rx_lvl) {
2723 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2724 } else {
2725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2726 log2str("No Tx power decrease during whole ramp down: ",
2727 max_rx_lvl , " -> ", last_rx_lvl));
2728 }
2729}
2730
2731/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002732private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002733 f_l1_tune(L1CTL);
2734 RSL.clear;
2735
2736 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002737
2738 setverdict(pass);
2739}
2740testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2741 var ConnHdlr vc_conn;
2742 var ConnHdlrPars pars;
2743 f_init();
2744 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2745 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2746 pcu_comp := false, trxc_comp := true);
2747 vc_conn.done;
2748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2749}
2750
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002751/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002752private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002753 f_connhdlr_init_vty_bsc();
2754
2755 f_l1_tune(L1CTL);
2756 RSL.clear;
2757
2758 /* Wait until BTS is started and at full power */
2759 var integer max_rx_lvl := f_wait_ramp_up();
2760 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2761
2762 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2763 f_verify_ramp_down(max_rx_lvl);
2764
2765 setverdict(pass);
2766}
2767testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2768 var ConnHdlr vc_conn;
2769 var ConnHdlrPars pars;
2770 f_init();
2771 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2772 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2773 pcu_comp := false, trxc_comp := true);
2774 vc_conn.done;
2775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2776}
2777
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002778/* Verify Tx power:
2779 * + ramping down during ADM state UNLOCKED->LOCKED
2780 * + ramping up during ADM state LOCKED->UNLOCKED
2781 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002782private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002783 var L1ctlDlMessage l1_dl;
2784 var integer last_rx_lvl;
2785
2786 f_connhdlr_init_vty_bsc();
2787
2788 f_l1_tune(L1CTL);
2789 RSL.clear;
2790
2791 /* Wait until BTS is started and at full power */
2792 var integer max_rx_lvl := f_wait_ramp_up();
2793 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2794
2795 log("ADM STATE UNLOCKED->LOCKED");
2796 f_vty_enter_cfg_trx(BSCVTY);
2797 f_vty_transceive(BSCVTY, "rf_locked 1");
2798 last_rx_lvl := max_rx_lvl;
2799 f_verify_ramp_down(max_rx_lvl);
2800
2801 /* Let some time after we received 0dBm, then check we don't receive BCCH
2802 * anymore because scheduler has stopped after ramping down */
2803 f_sleep(2.0);
2804 L1CTL.clear;
2805 timer Tlocked := 2.0;
2806 Tlocked.start;
2807 alt {
2808 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2810 log2str("Received data_ind during rf_locked: ", l1_dl));
2811 }
2812 [] L1CTL.receive { repeat; }
2813 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2814 }
2815
2816 log("ADM STATE LOCKED->UNLOCKED");
2817 f_vty_transceive(BSCVTY, "rf_locked 0");
2818 f_verify_ramp_up();
2819 setverdict(pass);
2820}
2821testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2822 var ConnHdlr vc_conn;
2823 var ConnHdlrPars pars;
2824 f_init();
2825 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2826 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2827 pcu_comp := false, trxc_comp := true);
2828 vc_conn.done;
2829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2830}
2831
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002832private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002833 timer T := 8.0;
2834 T.start;
2835 var RSL_Message rsl;
2836 alt {
2837 [] as_l1_sacch();
2838 [] L1CTL.receive { repeat; }
2839 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2840 if (rsl.ies[3].body.bs_power.power_level == level) {
2841 setverdict(pass)
2842 } else {
2843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2844 }
2845 }
2846 [] T.timeout {
2847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2848 }
2849 }
2850}
2851
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002852/* See if the RSL MEASurement RESult contains expeced BS power level
2853 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002854private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002855 f_l1_tune(L1CTL);
2856 RSL.clear;
2857
2858 if (mp_bts_trxc_port != -1) {
2859 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2860 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2861 }
2862
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002863 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002864 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2865 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2866
2867 f_est_dchan(more_ies :={valueof(pwr)});
2868
2869 f_check_meas_bs_power_level(pwr_var);
2870
2871 f_rsl_chan_deact();
2872 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2873}
2874
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002875/* See if the RSL MEASurement RESult contains expeced BS power level
2876 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002877private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002878 f_l1_tune(L1CTL);
2879 RSL.clear;
2880
2881 if (mp_bts_trxc_port != -1) {
2882 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2883 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2884 }
2885
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002886 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002887 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2888
2889 f_est_dchan();
2890
2891 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2892
2893 f_check_meas_bs_power_level(pwr_var);
2894
2895 f_rsl_chan_deact();
2896 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2897}
2898
2899testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2900 var ConnHdlr vc_conn;
2901 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002902
Eric Wildae8f2622019-06-18 17:05:11 +02002903 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002904
2905 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2906 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2907 pcu_comp := false, trxc_comp := true);
2908 vc_conn.done;
2909
Eric Wildae8f2622019-06-18 17:05:11 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2911}
2912
2913testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2914 var ConnHdlr vc_conn;
2915 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002916
Eric Wildae8f2622019-06-18 17:05:11 +02002917 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002918
2919 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2920 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2921 pcu_comp := false, trxc_comp := true);
2922 vc_conn.done;
2923
Eric Wildae8f2622019-06-18 17:05:11 +02002924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2925}
2926
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002927/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2928 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2929 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002930private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002931 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002932 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002933
2934 f_trxc_fake_rssi(rxlev2dbm(10));
2935 f_l1_tune(L1CTL);
2936 RSL.clear;
2937
2938 var RSL_IE_List addl_ies;
2939 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2940
2941 addl_ies := {
2942 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2943 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2944 };
2945
2946 /* establish with power parameters */
2947 f_est_dchan(more_ies := addl_ies);
2948
2949 /* set a high value to ensure L1 power control level increases */
2950 f_trxc_fake_rssi(rxlev2dbm(20));
2951
2952 timer T2 := 6.0;
2953 T2.start;
2954 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002955 [] as_l1_sacch_l1h(l1h) {
2956 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002957 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002958 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002959 T2.stop;
2960 }
2961 [] L1CTL.receive { repeat; }
2962 [] T2.timeout {
2963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2964 "Power Level in L1 header has not increased sufficiently");
2965 }
2966 }
2967
2968 /* set a low value to ensure L1 power control level decreases */
2969 f_trxc_fake_rssi(rxlev2dbm(0));
2970
2971 timer T4 := 6.0;
2972 T4.start;
2973 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002974 [] as_l1_sacch_l1h(l1h) {
2975 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002976 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002977 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002978 T4.stop;
2979 setverdict(pass, "Power level in L1 decreased/increased as expected");
2980 }
2981 [] L1CTL.receive { repeat; }
2982 [] T4.timeout {
2983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2984 "Power Level in L1 header has not decreased sufficiently");
2985 }
2986 }
2987
2988 f_rsl_chan_deact();
2989 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2990
2991}
2992
2993/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002994private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002995 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002996 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002997
2998 /* set a low value to ensure power increases */
2999 f_trxc_fake_rssi(rxlev2dbm(10));
3000 f_l1_tune(L1CTL);
3001 RSL.clear;
3002
3003 var RSL_IE_List addl_ies;
3004 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3005
3006 addl_ies := {
3007 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3008 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3009 };
3010
3011 /* establish with power parameters */
3012 f_est_dchan(more_ies := addl_ies);
3013
3014 timer T1 := 10.0;
3015 T1.start;
3016 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003017 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003018 [] L1CTL.receive { repeat; }
3019 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003020 if (not isbound(l1h)) {
3021 setverdict(fail, "No SACCH blocks were received");
3022 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003023 setverdict(fail, "Power level in L1 header should not have changed");
3024 }
3025 }
3026 }
3027
3028 f_rsl_chan_deact();
3029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3030
3031}
3032
3033/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003034private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003035 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003036 var uint5_t pwr_var := 15;
3037 var uint5_t pwr_max_var := f_get_max_power_from_band();
3038
3039 /* set a low value to ensure power increases */
3040 f_trxc_fake_rssi(rxlev2dbm(10));
3041 f_l1_tune(L1CTL);
3042 RSL.clear;
3043
3044 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3045 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3046
3047 /* establish with fixed power level */
3048 f_est_dchan(more_ies :={valueof(pwr)});
3049
3050 /* check our initial power level */
3051 f_wait_for_l1_power_level(pwr_var);
3052
3053 /* update power param to enable power loop
3054 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3055 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3056
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003057 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3058 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3059 * Add an extra offset to avoid race conditions: +1.92s. */
3060 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003061 T1.start;
3062 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003063 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003064 [] L1CTL.receive { repeat; }
3065 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003066 if (not isbound(l1h)) {
3067 setverdict(fail, "No SACCH blocks were received");
3068 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003069 setverdict(pass, "Power level in L1 header reduced as expected");
3070 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003071 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3072 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003073 }
3074 }
3075 }
3076
3077 f_rsl_chan_deact();
3078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3079
3080}
3081
3082/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003083private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003084 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003085
3086 /* set a high value to ensure power decreases */
3087 f_trxc_fake_rssi(rxlev2dbm(50));
3088 f_l1_tune(L1CTL);
3089 RSL.clear;
3090
3091 var uint5_t pwr_var := 5;
3092 var uint5_t pwr_target_val := 15;
3093
3094 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3095 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3096
3097 /* establish with fixed power level */
3098 f_est_dchan(more_ies :={valueof(pwr)});
3099
3100 /* check our initial power level */
3101 f_wait_for_l1_power_level(pwr_var);
3102
3103 /* update power param to enable power loop
3104 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003105 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003106
3107 /* wait, then check that our power level was increased */
3108 timer T1 := 10.0;
3109 T1.start;
3110 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003111 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003112 [] L1CTL.receive { repeat; }
3113 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003114 if (not isbound(l1h)) {
3115 setverdict(fail, "No SACCH blocks were received");
3116 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3117 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003118 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003119 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003120 }
3121 }
3122 }
3123
3124 f_rsl_chan_deact();
3125 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3126
3127}
3128
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003129/* See if the power level remains constant when MS Power Parameters IE
3130 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003131private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003132 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003133
3134 /* set a high value to ensure power decreases */
3135 f_trxc_fake_rssi(rxlev2dbm(50));
3136 f_l1_tune(L1CTL);
3137 RSL.clear;
3138
3139 var uint5_t pwr_var := 5;
3140
3141 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3142 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3143
3144 /* establish with fixed power level */
3145 f_est_dchan(more_ies :={valueof(pwr)});
3146
3147 /* check our initial power level */
3148 f_wait_for_l1_power_level(pwr_var);
3149
3150 /* wait, then check that our power level did not change */
3151 timer T1 := 10.0;
3152 T1.start;
3153 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003154 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3155 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3157 "BS power control should not be active unless we receive a power parameters IE!");
3158 }
3159 repeat;
3160 }
3161 [] L1CTL.receive { repeat; }
3162 [] T1.timeout { setverdict(pass); }
3163 }
3164
3165 f_rsl_chan_deact();
3166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3167
3168}
3169
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003170/* See if the power level remains constant when MS Power Parameters IE
3171 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003172private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003173 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003174
3175 /* set a high value to ensure power decreases */
3176 f_trxc_fake_rssi(rxlev2dbm(50));
3177 f_l1_tune(L1CTL);
3178 RSL.clear;
3179
3180 var uint5_t pwr_var := 5;
3181
3182 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3183 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3184
3185 /* establish with fixed power level */
3186 f_est_dchan(more_ies :={valueof(pwr)});
3187
3188 /* check our initial power level */
3189 f_wait_for_l1_power_level(pwr_var);
3190
3191 /* pwr control without power params IE, should NOT activate MS power control*/
3192 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3193
3194 /* wait, then check that our power level did not change */
3195 timer T1 := 10.0;
3196 T1.start;
3197 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003198 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3199 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3201 "BS power control should not be active unless we receive a power parameters IE!");
3202 }
3203 repeat;
3204 }
3205 [] L1CTL.receive { repeat; }
3206 [] T1.timeout { setverdict(pass); }
3207 }
3208
3209 f_rsl_chan_deact();
3210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3211
3212}
3213
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003214private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003215 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003216 timer T0 := 10.0;
3217 T0.start;
3218 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003219 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3220 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3222 "Power level in L1 header != signaled (RSL) power level.");
3223 }
3224 }
3225 [] L1CTL.receive { repeat; }
3226 [] T0.timeout {
3227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3228 "Timeout waiting for initial power level");
3229 }
3230 }
3231 T0.stop;
3232}
3233
3234private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3235 var IntegerRecord min_dbm_level;
3236 var IntegerRecord max_dbm_level;
3237 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3238
3239 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3240 if (min_dbm_level[i] == level) {
3241 return true;
3242 }
3243 }
3244 return false;
3245}
3246
3247private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3248 var IntegerRecord min_dbm_level;
3249 var IntegerRecord max_dbm_level;
3250 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3251
3252 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3253 if (max_dbm_level[i] == level) {
3254 return true;
3255 }
3256 }
3257 return false;
3258}
3259
3260private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3261 var IntegerRecord min_dbm_level;
3262 var IntegerRecord max_dbm_level;
3263 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3264 return max_dbm_level[0];
3265}
3266
3267type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003268private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003269private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3270 // 45.005 4.1.1
3271 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3272 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3273 2, 1, 0};
3274 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3275 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3276 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3277 var IntegerRecord rv;
3278
3279 select(band){
3280 case (BtsBand_allGSM){
3281 rv := gsm_power;
3282 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3283 max_dbm_level := {2, 1, 0};
3284 }
3285 case("DCS1800"){
3286 rv := dcs_power;
3287 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3288 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3289 }
3290 case("PCS1900"){
3291 rv := pcs_power;
3292 min_dbm_level := {15};
3293 max_dbm_level := {30};
3294 }
Harald Welte194b6912020-10-11 21:01:55 +02003295 case else {
3296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3297 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003298 }
3299
3300 return rv;
3301}
3302
3303private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003304 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 +02003305}
3306
3307testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3308 var ConnHdlr vc_conn;
3309 var ConnHdlrPars pars;
3310 f_init();
3311 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3312 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3313 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3314 pars.bts0_band := f_vty_get_bts0_band();
3315 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3316 vc_conn.done;
3317 }
3318 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3320}
3321
3322testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3323 var ConnHdlr vc_conn;
3324 var ConnHdlrPars pars;
3325 f_init();
3326 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3327 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3328 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3329 pars.bts0_band := f_vty_get_bts0_band();
3330 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3331 vc_conn.done;
3332 }
3333 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3335}
3336
3337testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3338 var ConnHdlr vc_conn;
3339 var ConnHdlrPars pars;
3340 f_init();
3341 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3342 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3343 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3344 pars.bts0_band := f_vty_get_bts0_band();
3345 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3346 vc_conn.done;
3347 }
3348 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3350}
3351
3352testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3353 var ConnHdlr vc_conn;
3354 var ConnHdlrPars pars;
3355 f_init();
3356 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3357 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3358 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3359 pars.bts0_band := f_vty_get_bts0_band();
3360 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3361 vc_conn.done;
3362 }
3363 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3365}
3366
Eric Wild280ccb82019-06-17 11:11:52 +02003367testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3368 var ConnHdlr vc_conn;
3369 var ConnHdlrPars pars;
3370 f_init();
3371 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3372 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3373 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3374 pars.bts0_band := f_vty_get_bts0_band();
3375 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3376 vc_conn.done;
3377 }
3378 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3380}
3381
Eric Wild095024b2019-06-17 15:08:57 +02003382testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3383 var ConnHdlr vc_conn;
3384 var ConnHdlrPars pars;
3385 f_init();
3386 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3387 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3388 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3389 pars.bts0_band := f_vty_get_bts0_band();
3390 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3391 vc_conn.done;
3392 }
3393 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3395}
3396
Philipp Maier149c3922020-10-22 17:29:36 +02003397function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003398 var template RSL_IE_ChannelMode ch_mode;
3399 var ConnHdlr vc_conn;
3400 var ConnHdlrPars pars;
3401 f_init();
3402 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3403 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3404 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003405 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003406 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3407 pcu_comp := false, trxc_comp := true);
3408 vc_conn.done;
3409 }
3410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3411}
Philipp Maier149c3922020-10-22 17:29:36 +02003412
3413testcase TC_meas_res_speech_tchf() runs on test_CT {
3414 f_TC_meas_res_speech_tchf(false);
3415}
3416
3417testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3418 f_TC_meas_res_speech_tchf(true);
3419}
3420
3421function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003422 var template RSL_IE_ChannelMode ch_mode;
3423 var ConnHdlr vc_conn;
3424 var ConnHdlrPars pars;
3425 f_init();
3426 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3427 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3428 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003429 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003430 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3431 pcu_comp := false, trxc_comp := true);
3432 vc_conn.done;
3433 }
3434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3435}
Philipp Maier149c3922020-10-22 17:29:36 +02003436
3437testcase TC_meas_res_speech_tchh() runs on test_CT {
3438 f_TC_meas_res_speech_tchh(false)
3439}
3440
3441testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3442 f_TC_meas_res_speech_tchh(true)
3443}
3444
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003445testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3446 var template RSL_IE_ChannelMode ch_mode;
3447 var ConnHdlr vc_conn;
3448 var ConnHdlrPars pars;
3449 f_init();
3450 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3451 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3452 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3453 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3454 pars.l1_pars.toa256_enabled := true;
3455 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3456 pcu_comp := false, trxc_comp := true);
3457 vc_conn.done;
3458 }
3459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3460}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003461
Harald Welte70767382018-02-21 12:16:40 +01003462testcase TC_meas_res_sign_tchf() runs on test_CT {
3463 var ConnHdlr vc_conn;
3464 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003465 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003466 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003467 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003468 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003469 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3470 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003471 vc_conn.done;
3472 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003474}
3475testcase TC_meas_res_sign_tchh() runs on test_CT {
3476 var ConnHdlr vc_conn;
3477 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003478 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003479 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003480 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003481 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003482 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3483 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003484 vc_conn.done;
3485 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003487}
3488testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3489 var ConnHdlr vc_conn;
3490 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003491 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003492 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003493 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3494 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003495 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3496 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003497 vc_conn.done;
3498 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003500}
3501testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3502 var ConnHdlr vc_conn;
3503 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003504 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003505 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003506 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3507 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003508 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3509 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003510 vc_conn.done;
3511 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003513}
Harald Welte685d5982018-02-27 20:42:05 +01003514testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3515 var ConnHdlr vc_conn;
3516 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003517 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003518 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3519 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003520 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003521 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003522 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3523 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003524 vc_conn.done;
3525 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003527}
3528
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003529/* Make sure that we always get RSL MEASurement RESult messages regardless
3530 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3531private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3532 timer Texec := 8.0;
3533 timer Timpf := 2.0;
3534 timer Tmr;
3535
3536 f_l1_tune(L1CTL);
3537 RSL.clear;
3538
3539 f_est_dchan();
3540 L1CTL.clear;
3541
3542 /* Establish the main SAPI=0 link on DCCH first */
3543 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3544
3545 /* Give more time for the first RSL MEASurement RESult */
3546 Tmr.start(0.480 * 2.0);
3547 Texec.start; /* EXECution timer */
3548 Timpf.start; /* IMPFung timer */
3549
3550 alt {
3551 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3552 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3553 /* Reschedule the MEAS RES timer */
3554 Tmr.start(0.480 + 0.120);
3555 repeat;
3556 }
3557 [] RSL.receive { repeat; }
3558 [] Tmr.timeout {
3559 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3560 }
3561 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3562 [] Timpf.timeout {
3563 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3564 log("Injected SAPI=3 traffic on SACCH");
3565 Timpf.start;
3566 repeat;
3567 }
3568 /* We're good if survived so far */
3569 [] Texec.timeout {
3570 setverdict(pass);
3571 }
3572 }
3573
3574 f_rsl_chan_deact();
3575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3576 f_rslem_unregister(0, g_chan_nr);
3577}
3578testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3579 var template RSL_IE_ChannelMode ch_mode;
3580 var template ConnHdlrPars pars;
3581 var ConnHdlr vc_conn;
3582
3583 f_init();
3584
3585 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3586 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3587
3588 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3589 vc_conn.done;
3590
3591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3592}
3593testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3594 var template RSL_IE_ChannelMode ch_mode;
3595 var template ConnHdlrPars pars;
3596 var ConnHdlr vc_conn;
3597
3598 f_init();
3599
3600 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3601 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3602
3603 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3604 vc_conn.done;
3605
3606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3607}
3608
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003609/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3610 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003611private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003612 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003613 var RSL_IE_MS_Power ms_power;
3614 var RSL_Message rsl;
3615 var uint5_t power_level := 0;
3616
3617 f_l1_tune(L1CTL);
3618 RSL.clear;
3619
3620 f_est_dchan();
3621
3622 ms_power.reserved := 0;
3623 ms_power.fpc_epc := false;
3624
3625 /* Send the first power control command. This will disable any BTS/TRX
3626 * internal power control and switch the MS (which is not in scope of
3627 * this test) to a constant power level. We start with a power level
3628 * of 0 */
3629 ms_power.power_level := power_level;
3630 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3631 RSL.send(rsl);
3632
3633 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003634 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3635 if (l1h.ms_power_lvl != power_level) {
3636 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3637 "match the signaled (RSL) power level := ", power_level);
3638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003639 }
3640
3641 /* Signal a new power level via RSL for the next turn. */
3642 if (power_level < 31) {
3643 power_level := power_level + 1;
3644 ms_power.power_level := power_level;
3645 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3646 RSL.send(rsl);
3647 repeat;
3648 }
3649
3650 }
3651
3652 /* Ignore all other blocks */
3653 [] L1CTL.receive { repeat; }
3654
3655 }
3656
3657 f_rsl_chan_deact();
3658 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3659
3660 setverdict(pass);
3661}
3662
3663testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3664 var ConnHdlr vc_conn;
3665 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003666 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003667
3668 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3669 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3670 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3671 vc_conn.done;
3672 }
3673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3674}
Harald Welte70767382018-02-21 12:16:40 +01003675
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003676/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003677TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003678private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003679 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003680 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003681
3682 f_l1_tune(L1CTL);
3683 RSL.clear;
3684
3685 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003686 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003687
3688 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3689
3690
3691 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003692 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3693 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003694 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3695 }
3696
3697 }
3698
3699 /* Ignore all other blocks */
3700 [] L1CTL.receive { repeat; }
3701
3702 }
3703
3704 f_rsl_chan_deact();
3705 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3706
3707 setverdict(pass);
3708}
3709
3710testcase TC_rsl_chan_initial_ta() runs on test_CT {
3711 var ConnHdlr vc_conn;
3712 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003713 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003714 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003715 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3716 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003717 vc_conn.done;
3718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3719}
3720
Eric Wilde57e1a62019-05-28 13:30:55 +02003721/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003722private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003723 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003724 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003725
3726 var RSL_IE_MS_Power ms_power;
3727 ms_power.reserved := 0;
3728 ms_power.fpc_epc := false;
3729 ms_power.power_level := ms_power_level;
3730
3731 f_l1_tune(L1CTL);
3732 RSL.clear;
3733
3734 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3735
3736 timer T := 1.0;
3737 T.start;
3738 alt {
3739 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003740 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3741 if (l1h.ms_power_lvl != ms_power_level) {
3742 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3743 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003744 }
3745 }
3746 /* Ignore all other blocks */
3747 [] L1CTL.receive { repeat; }
3748 [] T.timeout {
3749 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3750 }
3751 }
3752
3753 f_rsl_chan_deact();
3754 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3755 setverdict(pass);
3756}
3757
3758testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3759 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3760 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3761}
3762
Harald Welte0472ab42018-03-12 15:02:26 +01003763/* 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 +01003764private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003765 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003766 RSL.clear;
3767
3768 f_est_dchan();
3769 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003770 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003771
3772 timer T := 40.0;
3773 T.start;
3774 alt {
3775 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3776 setverdict(pass)
3777 }
3778 [] RSL.receive { repeat };
3779 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003781 }
3782 }
3783 f_rsl_chan_deact();
3784}
3785testcase TC_conn_fail_crit() runs on test_CT {
3786 var ConnHdlr vc_conn;
3787 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003788 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003789 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3790 pars.t_guard := 60.0;
3791 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3792 vc_conn.done;
3793}
3794
Harald Welte93640c62018-02-25 16:59:33 +01003795/***********************************************************************
3796 * Paging
3797 ***********************************************************************/
3798
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003799private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003800 if (tmsi == 'FFFFFFFF'O) {
3801 return true;
3802 } else {
3803 return false;
3804 }
3805}
Harald Welte70767382018-02-21 12:16:40 +01003806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003807private type record allowedFn { integer frame_nr }
3808private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3809private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3810private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3811private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3812private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3813private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3814private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3815private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3816private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003817{
3818 var integer frame_nr_51;
3819 frame_nr_51 := frame_nr mod 51
3820
3821 var allowedFn fn_check;
3822 fn_check.frame_nr := frame_nr_51;
3823
3824 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003826 return;
3827 }
3828
3829 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3830 return;
3831 }
3832 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3833 return;
3834 }
3835 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3836 return;
3837 }
3838 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3839 return;
3840 }
3841 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3842 return;
3843 }
3844 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3845 return;
3846 }
3847 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3848 return;
3849 }
3850 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3851 return;
3852 }
3853
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003855 return;
3856}
3857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003858private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3859 inout integer num_paging_rcv_ids,
3860 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003861runs on test_CT {
3862 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003863 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003864 repeat;
3865 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003866 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003867 var octetstring without_plen :=
3868 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3869 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003870
3871 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3872
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003873 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3874 /* Ignore empty RR Paging Request (PCH filling) messages.
3875 * TODO: does it make sense to count them? */
3876 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003877 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3878 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003879 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003880 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3881 }
3882 } else if (match(rr, tr_PAGING_REQ2)) {
3883 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3884 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3885 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3886 }
3887 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3889 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003890 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003891 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3892 }
3893 } else if (match(rr, tr_PAGING_REQ3)) {
3894 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3895 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3896 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3897 }
3898 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3899 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3900 }
3901 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3902 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3903 }
3904 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3905 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3906 }
3907 }
3908 repeat;
3909 }
3910}
3911
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003912private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003913 boolean combined_ccch,
3914 integer bs_ag_blks_res,
3915 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003916 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3917 * paging command that is issued via RSL. */
3918 integer ps_load_modulus,
3919 /* Wait until the paging queue inside the BTS is congested before starting to add
3920 * pagings via the PCU socket (0 = disabled) */
3921 boolean ps_wait_cong,
3922 /* Maximum time to wait until the paging queue is drained at the end of the test.
3923 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3924 * to set this value to 18s, however the draining process may take significantly
3925 * longer when the queue contains paging requests for PS as those are implemented
3926 * as immediate assignments and require an entire MAC block alone. */
3927 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003928 boolean exp_load_ind,
3929 boolean exp_overload,
3930 boolean use_tmsi
3931}
3932
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003933private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003934 integer num_paging_sent,
3935 integer num_paging_rcv_msgs,
3936 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003937 integer num_overload,
3938 /* When free space inside the paging queue reaches more than 2 thirds
3939 * of its capacity cong_detected is set to true. */
3940 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003941}
3942
Harald Welte68e495b2018-02-25 00:05:57 +01003943/* Helper function for paging related testing */
3944private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003945 /* Using the PCU socket affects the timing of the paging processing. We only
3946 * activate the PCU socket if we do paging load tests that include additional
3947 * paging load that is introduced through the PCU socket. */
3948 if (cfg.ps_load_modulus > 0) {
3949 f_init_with_pcuif();
3950 } else {
3951 f_init();
3952 }
Harald Welte68e495b2018-02-25 00:05:57 +01003953 f_init_l1ctl();
3954 f_l1_tune(L1CTL);
3955
Philipp Maierca058272021-06-23 10:35:23 +02003956 var octetstring imm_ass := f_rnd_octstring(23);
3957 var ASP_RSL_Unitdata load_ind;
3958
Harald Welte68e495b2018-02-25 00:05:57 +01003959 var PagingTestState st := {
3960 num_paging_sent := 0,
3961 num_paging_rcv_msgs := 0,
3962 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003963 num_overload := 0,
3964 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003965 };
3966
3967 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3968 var float max_pch_imsi_per_sec;
3969 if (cfg.use_tmsi) {
3970 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3971 } else {
3972 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3973 }
3974 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3975 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003976 var float time_total := 20.0;
3977 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3978 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003979
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003980 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3981 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003982
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003983 timer T_itv := 0.0;
3984 T_itv.start;
3985 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003986 alt {
3987 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003988 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003989 st.num_overload := st.num_overload + 1;
3990 repeat;
3991 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003992 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003994 }
Philipp Maierca058272021-06-23 10:35:23 +02003995 [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 +01003996 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003997
3998 /* Detect paging congestion: The logic inside the BTS will diagnose the
3999 * paging queue as congested when the fill state is more than 66% (which
4000 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4001 * paging congestion is detected pagings that are issued through the PCU
4002 * socket (PS) are dropped in order to prefer the CS related pagings. */
4003 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4004 st.cong_detected := true;
4005 }
4006
Harald Welte68e495b2018-02-25 00:05:57 +01004007 /* FIXME: analyze/verify interval + contents */
4008 repeat;
4009 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004010 /* ignore other RSL messages like RF RESource INDication */
4011 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004012 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004013 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004014 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004015 /* Only relevant when testing including with PCU sock connected */
4016 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004017 [] T_itv.timeout {
4018 /* Send paging cmds based on elapsed time */
4019 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4020 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004021 var MobileIdentityV mi;
4022
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004023 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004024 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004025 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004026 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004027 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004028 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004029
4030 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004031 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 +02004032
Philipp Maierca058272021-06-23 10:35:23 +02004033 /* Add additional pagings through the PCU socket interface. */
4034 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4035 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4036 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4037 }
4038 }
4039
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004040 st.num_paging_sent := st.num_paging_sent + 1;
4041 }
4042 if (st.num_paging_sent < pkt_total) {
4043 /* Wait for interval to next PAGING COMMAND */
4044 var float time_now := T_total.read;
4045 var float next_sched := int2float(st.num_paging_sent)*interval;
4046 if (next_sched > time_now) {
4047 T_itv.start(next_sched - time_now);
4048 } else {
4049 T_itv.start(0.0);
4050 }
4051 } else {
4052 /* We are done, no need to keep counting */
4053 T_total.stop;
4054 }
4055 }
4056 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004057 }
4058 }
4059
Philipp Maierca058272021-06-23 10:35:23 +02004060 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004061 T_wait.start;
4062 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004063 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004064 [] L1CTL.receive { repeat; }
4065 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004066 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004067 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004068 /* ignore other RSL messages like RF RESource INDication */
4069 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004070 /* Only relevant when testing including with PCU sock connected */
4071 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004072 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004073 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 +01004074 }
Harald Welte68e495b2018-02-25 00:05:57 +01004075 }
4076
4077 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4078 " rcvd_ids=", st.num_paging_rcv_ids);
4079 return st;
4080}
4081
4082/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4083 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4084 * - that CCCH LOAD IND (PCH) are being generated
4085 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4086testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004087 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004088 var PagingTestCfg cfg := {
4089 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004090 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004091 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004092 ps_load_modulus := 0,
4093 ps_wait_cong := false,
4094 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004095 exp_load_ind := true,
4096 exp_overload := false,
4097 use_tmsi := false
4098 };
4099 var PagingTestState st := f_TC_paging(cfg);
4100 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4102 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004103 } else {
4104 setverdict(pass);
4105 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004107}
4108
4109/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4110 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4111 * - that CCCH LOAD IND (PCH) are being generated
4112 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4113testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004114 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004115 var PagingTestCfg cfg := {
4116 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004117 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004118 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004119 ps_load_modulus := 0,
4120 ps_wait_cong := false,
4121 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004122 exp_load_ind := true,
4123 exp_overload := false,
4124 use_tmsi := true
4125 };
4126 var PagingTestState st := f_TC_paging(cfg);
4127 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4129 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004130 } else {
4131 setverdict(pass);
4132 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004134}
4135
4136/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4137 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4138 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4139 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4140testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004141 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004142 var PagingTestCfg cfg := {
4143 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004144 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004145 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004146 ps_load_modulus := 0,
4147 ps_wait_cong := false,
4148 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004149 exp_load_ind := true,
4150 exp_overload := true,
4151 use_tmsi := false
4152 };
4153 var PagingTestState st := f_TC_paging(cfg);
4154 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4155 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004156 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004157 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004158 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 +01004159 } else {
4160 setverdict(pass);
4161 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004163}
4164
4165/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4166 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4167 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4168 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4169testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004170 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004171 var PagingTestCfg cfg := {
4172 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004173 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004174 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004175 ps_load_modulus := 0,
4176 ps_wait_cong := false,
4177 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004178 exp_load_ind := true,
4179 exp_overload := true,
4180 use_tmsi := true
4181 };
4182 var PagingTestState st := f_TC_paging(cfg);
4183 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4184 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004185 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004186 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004187 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 +01004188 } else {
4189 setverdict(pass);
4190 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004192}
4193
Philipp Maierca058272021-06-23 10:35:23 +02004194/* Same as above, but with additional paging load created by PS pagings that
4195 * are issued through the PCU socket. The additional load is introduced when
4196 * the paging queue is already two thirds full. Since the BTS implements a
4197 * prioritization logic that drops the pagings from the PCU under in those
4198 * congestive sitautions the behaviour on the PS side is expected to be
4199 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4200testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4201 var SystemInformation si3 := valueof(ts_SI3_default);
4202 var PagingTestCfg cfg := {
4203 combined_ccch := true,
4204 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4205 load_factor := 2.0,
4206 ps_load_modulus := 16,
4207 ps_wait_cong := true,
4208 queue_drain_timeout := 18.0,
4209 exp_load_ind := true,
4210 exp_overload := true,
4211 use_tmsi := false
4212 };
4213 var PagingTestState st := f_TC_paging(cfg);
4214 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4215 * slots and will fully drain that buffer before returning */
4216 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4217 if (not match(st.num_paging_rcv_ids, tpl)) {
4218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4219 } else {
4220 setverdict(pass);
4221 }
4222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4223}
4224
4225
Harald Welte68e495b2018-02-25 00:05:57 +01004226
Harald Welte93640c62018-02-25 16:59:33 +01004227/***********************************************************************
4228 * Immediate Assignment / AGCH
4229 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004230private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004231 len := 0,
4232 ma := ''B
4233}
Harald Welte93640c62018-02-25 16:59:33 +01004234
Harald Weltee8d750e2018-06-10 21:41:35 +02004235private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4236 return int2str(num_tx) & " sent, "
4237 & int2str(num_rx) & " received, "
4238 & int2str(num_del) & " deleted";
4239}
4240
4241private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4242 var L1ctlDlMessage l1_dl;
4243 timer T := 10.0;
4244 var integer num_tx := 0;
4245 var integer num_rx := 0;
4246 var integer num_del := 0;
4247 var charstring res_str;
4248 var float rx_ratio;
4249
Harald Welte10474062019-05-30 16:48:17 +02004250 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004251 f_init_l1ctl();
4252 f_l1_tune(L1CTL);
4253
4254 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004255 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004256 mp_trx_pars[0].arfcn,
4257 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004258 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4259 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004260 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004261 num_tx := num_tx+1;
4262 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004263 }
4264 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004265 T.start;
4266 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004267 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004268 num_del := num_del+1;
4269 repeat;
4270 }
4271 [] RSL_CCHAN.receive {
4272 repeat;
4273 }
4274 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004275 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4276 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4277 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004278 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004279 } else {
4280 num_rx := num_rx+1;
4281 }
4282 repeat;
4283 }
4284 [] L1CTL.receive { repeat; }
4285 [] T.timeout { }
4286 }
4287 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4288 log("AGCH test: " & res_str);
4289 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004291 }
4292 rx_ratio := int2float(num_rx) / int2float(num_tx);
4293 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004294 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 +02004295 } else {
4296 setverdict(pass);
4297 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004299}
4300
Harald Weltee8d750e2018-06-10 21:41:35 +02004301/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4302testcase TC_imm_ass_1000_20ms() runs on test_CT {
4303 f_TC_imm_ass(1000, 0.02, 0.25);
4304}
4305
4306/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4307testcase TC_imm_ass_200_0ms() runs on test_CT {
4308 f_TC_imm_ass(200, 0.0, 0.05);
4309}
4310
4311/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4312testcase TC_imm_ass_200_76ms() runs on test_CT {
4313 f_TC_imm_ass(150, 0.076, 1.00);
4314}
4315
4316
4317
Harald Welte48494ca2018-02-25 16:59:50 +01004318/***********************************************************************
4319 * BCCH
4320 ***********************************************************************/
4321
4322/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004323private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004324 GsmFrameNumber frame_number,
4325 SystemInformation si
4326}
4327
4328/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004329private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004330
4331/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004332private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004333
4334/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004335private function f_si_vecslot_contains(SystemInformationVector arr,
4336 RrMessageType key,
4337 boolean bcch_ext := false)
4338return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004339 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4340 var integer fn_mod51 := arr[i].frame_number mod 51;
4341 if (not bcch_ext and fn_mod51 == 2 or
4342 bcch_ext and fn_mod51 == 6) {
4343 if (arr[i].si.header.message_type == key) {
4344 return true;
4345 }
4346 }
4347 }
4348 return false;
4349}
4350
4351/* 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 +07004352private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4353 integer tc, RrMessageType key,
4354 boolean ext_bcch := false)
4355{
Harald Welte48494ca2018-02-25 16:59:50 +01004356 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004358 }
4359}
4360
4361/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004362private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4363 RrMessageType key)
4364return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004365 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4366 if (f_si_vecslot_contains(arr[tc], key) or
4367 f_si_vecslot_contains(arr[tc], key, true)) {
4368 return true;
4369 }
4370 }
4371 return false;
4372}
4373
4374/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004375private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4376 RrMessageType key,
4377 boolean bcch_ext := false,
4378 integer n := 1, integer m := 4)
4379return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004380 var integer count := 0;
4381 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4383 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004384 }
4385 for (var integer i:= 0; i < m; i := i + 1) {
4386 var integer fn_mod51 := arr[i].frame_number mod 51;
4387 if (not bcch_ext and fn_mod51 == 2 or
4388 bcch_ext and fn_mod51 == 6) {
4389 if (arr[i].si.header.message_type == key) {
4390 count := count + 1;
4391 }
4392 }
4393 }
4394 if (count >= n) {
4395 return true;
4396 } else {
4397 return false;
4398 }
4399}
4400
4401/* 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 +07004402private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4403 integer tc, RrMessageType key,
4404 boolean ext_bcch := false,
4405 integer n, integer m)
4406{
Harald Welte48494ca2018-02-25 16:59:50 +01004407 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004409 }
4410}
4411
4412/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004413private function f_si_vecslot_contains_only(SystemInformationVector arr,
4414 RrMessageType key,
4415 boolean bcch_ext := false)
4416return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004417 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4418 var integer fn_mod51 := arr[i].frame_number mod 51;
4419 if (not bcch_ext and fn_mod51 == 2 or
4420 bcch_ext and fn_mod51 == 6) {
4421 if (arr[i].si.header.message_type != key) {
4422 return false;
4423 }
4424 }
4425 }
4426 return true;
4427}
4428
4429/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004430private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4431 integer tc, RrMessageType key,
4432 boolean ext_bcch := false)
4433{
Harald Welte48494ca2018-02-25 16:59:50 +01004434 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004436 }
4437}
4438
4439/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004440private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004441 boolean bcch_extended,
4442 boolean si1_present,
4443 boolean si2bis_present,
4444 boolean si2ter_present,
4445 boolean si2quater_present,
4446 boolean si7_present,
4447 boolean si8_present,
4448 boolean si9_present,
4449 boolean si13_present,
4450 boolean si13alt_present,
4451 boolean si15_present,
4452 boolean si16_present,
4453 boolean si17_present,
4454 boolean si2n_present,
4455 boolean si21_present,
4456 boolean si22_present
4457}
4458
4459/* 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 +07004460private function f_validate_si_scheduling(SystemInformationConfig cfg,
4461 SystemInformationVectorPerTc si_per_tc)
4462{
Harald Welte48494ca2018-02-25 16:59:50 +01004463 var integer i;
4464 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4465 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004467 }
4468 }
4469 if (cfg.si1_present) {
4470 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4471 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4472 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4473 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4474 /* make sure *ALL* contain SI1 */
4475 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4476 }
4477 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4478 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4479 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4480 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4481 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4482 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4483
4484 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4485 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4486 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4487 * consecutive occurrences of TC = 4. */
4488 if (cfg.si2bis_present and not cfg.si2ter_present) {
4489 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4490 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4491 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4492 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4493 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4494 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4495 }
4496
4497 if (cfg.si7_present or cfg.si8_present) {
4498 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4499 * if System Information type 4 does not contain all information needed for cell
4500 * selection and reselection. */
4501 if (not cfg.bcch_extended) {
4502 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4503 }
4504 if (cfg.si7_present) {
4505 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4506 }
4507 if (cfg.si8_present) {
4508 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4509 }
4510 }
4511
4512 if (cfg.si2quater_present) {
4513 /* iii) System information type 2 quater is sent if needed, as determined by the system
4514 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4515 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4516 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4517 * within any of 4 consecutive occurrences of TC = 5. */
4518 if (not (cfg.bcch_extended)) {
4519 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4520 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4521 } else {
4522 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4523 }
4524 } else {
4525 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4526 }
4527 }
4528 if (cfg.si9_present) {
4529 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4530 * in system information type 3 as defined in 3GPP TS 44.018. */
4531 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4532 }
4533 if (cfg.si13_present) {
4534 /* vii) System Information type 13 is only related to the GPRS service. System Information
4535 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4536 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4537 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4538 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4539 * within any of 4 consecutive occurrences of TC=4. */
4540 if (not cfg.bcch_extended) {
4541 log("not-bccch-extended");
4542 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4543 } else {
4544 log("bccch-extended");
4545 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4546 }
4547 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004549 }
4550 }
4551 if (cfg.si16_present or cfg.si17_present) {
4552 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4553 * should not be sent in a cell where network sharing is used (see rule xv). */
4554 if (cfg.si22_present) {
4555 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4556 }
4557 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004559 }
4560 if (not cfg.bcch_extended) {
4561 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4562 }
4563 if (cfg.si16_present) {
4564 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4565 }
4566 if (cfg.si17_present) {
4567 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4568 }
4569 }
4570
4571 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4572 * broadcast information. The frequency with which they are sent is determined by the
4573 * system operator. System Information type 9 identifies the scheduling of System
4574 * Information type 18 and 20 messages. */
4575
4576 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4577 * Information Type 19 is present, then its scheduling shall be indicated in System
4578 * Information Type 9. */
4579
4580 if (cfg.si15_present) {
4581 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4582 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4583 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4584 * 4 consecutive occurrences of TC = 1. */
4585 if (not cfg.bcch_extended) {
4586 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4587 } else {
4588 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4589 }
4590 }
4591 if (cfg.si13alt_present) {
4592 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4593 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4594 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4595 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4596 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4597 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4598 * of TC = 4. */
4599 if (cfg.si13_present) {
4600 testcase.stop("Error: Cannot have SI13alt and SI13");
4601 }
4602 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004604 }
4605 if (not cfg.bcch_extended) {
4606 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4607 } else {
4608 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4609 }
4610 }
4611 if (cfg.si2n_present) {
4612 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4613 * as determined by the system operator. In the case that the message is sent on the
4614 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4615 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4616 * consecutive occurrences of TC = 4. */
4617 if (not cfg.bcch_extended) {
4618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4619 } else {
4620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4621 }
4622 }
4623 if (cfg.si21_present) {
4624 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4625 * determined by the system operator. If Extended Access Barring is in use in the cell
4626 * then this message is sent at least once within any of 4 consecutive occurrences of
4627 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4628 * cell then this message shall only be sent on BCCH Ext. */
4629 if (not cfg.bcch_extended) {
4630 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4631 } else {
4632 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4633 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004635 }
4636 }
4637 }
4638 if (cfg.si22_present) {
4639 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4640 * should not be sent in a cell where SoLSA is used (see rule viii). System
4641 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4642 * =2 and TC=6. */
4643 if (cfg.si16_present or cfg.si17_present) {
4644 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4645 }
4646 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4647 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004649 }
4650 if (not cfg.bcch_extended) {
4651 testcase.stop("Error: SI22 requires BCCH Extd!");
4652 } else {
4653 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4654 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4655 }
4656 }
4657}
4658
4659/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004660private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4661return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004662 timer T := duration;
4663 var SystemInformationVectorPerTc si_per_tc;
4664 var L1ctlDlMessage l1_dl;
4665
4666 /* initialize all per-TC vectors empty */
4667 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4668 si_per_tc[i] := {};
4669 }
4670
4671 /* flush all previous L1 queued msgs */
4672 pt.clear;
4673
4674 T.start;
4675 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004676 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004677 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4678 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4679 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004680 repeat;
4681 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004682
Harald Welte48494ca2018-02-25 16:59:50 +01004683 var integer tc := f_gsm_compute_tc(sig.frame_number);
4684 log("SI received at TC=", tc, ": ", sig.si);
4685 /* append to the per-TC bucket */
4686 si_per_tc[tc] := si_per_tc[tc] & { sig };
4687 repeat;
4688 }
4689 [] pt.receive { repeat; }
4690 [] T.timeout { }
4691 }
4692
4693 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4694 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4695 }
4696 log("si_per_tc=", si_per_tc);
4697 return si_per_tc;
4698}
4699
4700/* helper function: Set given SI via RSL + validate scheduling.
4701 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004702private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004703 var SystemInformationVectorPerTc si_per_tc;
4704 f_init_l1ctl();
4705 f_l1_tune(L1CTL);
4706
4707 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004708 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004709 f_validate_si_scheduling(si_cfg, si_per_tc);
4710
4711 setverdict(pass);
4712}
4713
4714testcase TC_si_sched_default() runs on test_CT {
4715 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004716 /* 2+3+4 are mandatory and set in f_init() */
4717 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004719}
4720
4721testcase TC_si_sched_1() runs on test_CT {
4722 f_init();
4723 si_cfg.si1_present := true;
4724 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004725 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004727}
4728
4729testcase TC_si_sched_2bis() runs on test_CT {
4730 f_init();
4731 si_cfg.si2bis_present := true;
4732 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4733 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004735}
4736
4737testcase TC_si_sched_2ter() runs on test_CT {
4738 f_init();
4739 si_cfg.si2ter_present := true;
4740 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4741 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004743}
4744
4745testcase TC_si_sched_2ter_2bis() runs on test_CT {
4746 f_init();
4747 si_cfg.si2bis_present := true;
4748 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4749 si_cfg.si2ter_present := true;
4750 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4751 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004753}
4754
4755testcase TC_si_sched_2quater() runs on test_CT {
4756 f_init();
4757 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004758 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004759 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004761}
4762
4763testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004764 /* NOTE: PCUIF connection is not used in this test case, but
4765 * without it the IUT would not broadcast SI13 (see OS#3075). */
4766 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004767 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004769 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004771}
4772
4773testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004774 /* NOTE: PCUIF connection is not used in this test case, but
4775 * without it the IUT would not broadcast SI13 (see OS#3075). */
4776 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004777 si_cfg.si2bis_present := true;
4778 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4779 si_cfg.si2ter_present := true;
4780 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4781 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004782 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004783 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004784 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004785 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004787}
4788
4789
Harald Welte68e495b2018-02-25 00:05:57 +01004790testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004791 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004792 /* FIXME: enable / disable individual BCCH info */
4793 //ts_RSL_BCCH_INFO(si_type, info);
4794 /* expect no ERROR REPORT after either of them *
4795 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004797}
4798
Harald Welte93640c62018-02-25 16:59:33 +01004799/***********************************************************************
4800 * Low-Level Protocol Errors / ERROR REPORT
4801 ***********************************************************************/
4802
Harald Welte01d982c2018-02-25 01:31:40 +01004803private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4804 timer T := 5.0;
4805 T.start;
4806 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004807 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004808 setverdict(pass);
4809 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004810 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004812 }
4813 [] RSL_CCHAN.receive {
4814 repeat;
4815 }
4816 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004818 }
4819 }
4820}
4821
4822/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4823testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004824 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004825 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4826 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004827 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004828
4829 f_exp_err_rep(RSL_ERR_PROTO);
4830}
4831
4832/* Provoke a mandatory IE error and match on ERROR REPORT */
4833testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004834 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004835
4836 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4837 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004838 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004839
4840 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4841}
4842
4843/* Provoke an IE content error and match on ERROR REPORT */
4844testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004845 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004846 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4847 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004848 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004849
4850 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4851}
4852
Harald Welteee25aae2019-05-19 14:32:37 +02004853/* attempt to activate channel with wrong RSL Message Discriminator IE */
4854function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4855 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4856 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4857 RSL.send(rsl);
4858 f_rslem_unregister(0, g_chan_nr);
4859}
4860testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4861 var ConnHdlr vc_conn;
4862 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4863
Harald Welte10474062019-05-30 16:48:17 +02004864 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004865
4866 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4867 vc_conn.done;
4868 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4869
4870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4871}
4872
4873/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004874private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004875 var template (value) RSL_Message rsl_tx;
4876 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4877 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4878 RSL.send(rsl_tx);
4879 f_rslem_unregister(0, g_chan_nr);
4880}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004881private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004882 var template (value) RSL_Message rsl_tx;
4883 /* we first have to activate the dedicated channel */
4884 f_rsl_chan_act(g_pars.chan_mode);
4885 /* ... to then send an invalid RLL message */
4886 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4887 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4888 RSL.send(rsl_tx);
4889 f_rslem_unregister(0, g_chan_nr);
4890}
4891testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4892 var ConnHdlr vc_conn;
4893 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4894 var template (value) RSL_Message rsl_tx;
4895
Harald Welte10474062019-05-30 16:48:17 +02004896 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004897
4898 /* Common Channel with wrong message type */
4899 RSL_CCHAN.clear;
4900 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4901 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004902 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004903 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4904
4905 /* TRX Management */
4906 RSL_CCHAN.clear;
4907 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4908 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004909 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004910 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4911
4912 /* Dedicated Channel */
4913 RSL_CCHAN.clear;
4914 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4915 vc_conn.done;
4916 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4917
4918 /* RLL */
4919 RSL_CCHAN.clear;
4920 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4921 vc_conn.done;
4922 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4923}
4924
4925/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004926private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004927 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4928 f_rslem_unregister(0, g_chan_nr);
4929}
4930testcase TC_err_rep_wrong_sequence() runs on test_CT {
4931 var ConnHdlr vc_conn;
4932 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4933
Harald Welte10474062019-05-30 16:48:17 +02004934 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004935
4936 RSL_CCHAN.clear;
4937 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4938 vc_conn.done;
4939 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4940}
4941
Harald Welte93640c62018-02-25 16:59:33 +01004942/***********************************************************************
4943 * IPA CRCX/MDCX/DLCS media stream handling
4944 ***********************************************************************/
4945
Harald Weltea871a382018-02-25 02:03:14 +01004946/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004947private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004948 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4949 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004950}
4951testcase TC_ipa_dlcx_not_active() runs on test_CT {
4952 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004953 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004954 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4955 vc_conn.done;
4956}
Harald Welte68e495b2018-02-25 00:05:57 +01004957
Harald Weltea3f1df92018-02-25 12:49:55 +01004958/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004959private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004960 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4961 "IPA CRCX ACK");
4962 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4963 "IPA CRCX NACK");
4964}
4965testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4966 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004967 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004968 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4969 vc_conn.done;
4970}
4971
4972/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004973private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004974 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4975 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004976 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004977 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4978 var uint7_t rtp_pt2 := f_rnd_int(127);
4979 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4980 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4981 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4982 "IPA MDCX ACK");
4983 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4984 "IPA DLCX ACK");
4985}
4986testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4987 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004988 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004989 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4990 vc_conn.done;
4991}
4992
Harald Welte3ae11da2018-02-25 13:36:06 +01004993/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004994private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004995 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4996 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004997 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004998 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4999 var uint7_t rtp_pt2 := f_rnd_int(127);
5000 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5001 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5002 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5003 "IPA MDCX ACK");
5004 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005005 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005006 remote_port := f_rnd_int(c_UINT16_MAX);
5007 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5008 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5009 "IPA MDCX ACK");
5010 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5011 "IPA DLCX ACK");
5012}
5013testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5014 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005015 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005016 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5017 vc_conn.done;
5018}
5019
Harald Welte9912eb52018-02-25 13:30:15 +01005020/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005021private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005022 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5023 "IPA CRCX NACK");
5024}
5025testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5026 var ConnHdlrPars pars;
5027 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005028 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005029
5030 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5031 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5032 vc_conn.done;
5033
5034 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5035 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5036 vc_conn.done;
5037}
5038
Harald Weltea3f1df92018-02-25 12:49:55 +01005039
Harald Welte883340c2018-02-28 18:59:29 +01005040/***********************************************************************
5041 * PCU Socket related tests
5042 ***********************************************************************/
5043
Harald Welte07bd2d22019-05-25 11:03:30 +02005044/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005045friend 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 +01005046runs on test_CT {
5047 timer T := 3.0;
5048
5049 /* we don't expect any RTS.req before PDCH are active */
5050 T.start;
5051 alt {
5052 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005054 }
5055 [] PCU.receive { repeat; }
5056 [] T.timeout { }
5057 }
5058
5059 /* Send PDCH activate request for known PDCH timeslot */
5060 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5061
5062 /* we now expect RTS.req for this timeslot (only) */
5063 T.start;
5064 alt {
5065 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5066 setverdict(pass);
5067 }
5068 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5069 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005071 }
5072 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005074 }
5075 [] PCU.receive { repeat; }
5076 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005078 }
5079 [not exp_success] T.timeout {
5080 setverdict(pass);
5081 }
5082 }
5083}
5084
Harald Welte07bd2d22019-05-25 11:03:30 +02005085/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005086friend 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 +01005087runs on test_CT {
5088 timer T := 3.0;
5089
5090 /* Send PDCH activate request for known PDCH timeslot */
5091 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 +02005092 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5093 * when it will actually have been executed in the BTS */
5094 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005095 PCU.clear;
5096 /* we now expect no RTS.req for this timeslot */
5097 T.start;
5098 alt {
5099 [] 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 +02005100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005101 }
5102 [] PCU.receive { repeat; }
5103 [] T.timeout {
5104 setverdict(pass);
5105 }
5106 }
5107}
5108
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005109friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005110 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005111 map(self:PCU, system:PCU);
5112 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005113 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5114}
5115
Harald Welte883340c2018-02-28 18:59:29 +01005116/* PDCH activation via PCU socket; check for presence of RTS.req */
5117testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005118 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005119
Harald Welte883340c2018-02-28 18:59:29 +01005120 f_TC_pcu_act_req(0, 0, 7, true);
5121}
5122
5123/* PDCH activation via PCU socket on non-PDCU timeslot */
5124testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005125 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005126
Harald Welte883340c2018-02-28 18:59:29 +01005127 f_TC_pcu_act_req(0, 0, 1, false);
5128}
5129
5130/* PDCH activation via PCU socket on wrong BTS */
5131testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005132 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005133
Harald Welte883340c2018-02-28 18:59:29 +01005134 f_TC_pcu_act_req(23, 0, 7, false);
5135}
5136
5137/* PDCH activation via PCU socket on wrong TRX */
5138testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005139 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005140
Harald Welte883340c2018-02-28 18:59:29 +01005141 f_TC_pcu_act_req(0, 23, 7, false);
5142}
5143
5144/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5145testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005146 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005147
Harald Welte883340c2018-02-28 18:59:29 +01005148 /* Activate PDCH */
5149 f_TC_pcu_act_req(0, 0, 7, true);
5150 f_sleep(1.0);
5151 /* and De-Activate again */
5152 f_TC_pcu_deact_req(0, 0, 7);
5153}
5154
5155/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5156testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005157 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005158
Harald Welte883340c2018-02-28 18:59:29 +01005159 f_TC_pcu_deact_req(0, 0, 1);
5160}
5161
5162/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005163function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005164 var PCUIF_send_data sd;
5165 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005166 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005167
5168 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005169 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005170
Harald Welte883340c2018-02-28 18:59:29 +01005171 T.start;
5172 alt {
5173 [] 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 +01005174 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005175 setverdict(pass);
5176 } else {
5177 repeat;
5178 }
5179 }
5180 [] PCU.receive { repeat; }
5181 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005183 }
5184 }
5185}
5186
Philipp Maier94c08482021-02-01 17:36:05 +01005187/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5188testcase TC_pcu_ver_si1() runs on test_CT {
5189 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5190 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5191}
5192
5193/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5194testcase TC_pcu_ver_si3() runs on test_CT {
5195 const octetstring si3 := '49012223242526272929AABBCC'O;
5196 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5197}
5198
5199/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5200testcase TC_pcu_ver_si13() runs on test_CT {
5201 const octetstring si13 := '01010203040506070909'O;
5202 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5203}
5204
Harald Welte883340c2018-02-28 18:59:29 +01005205private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5206
5207/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005208friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005209 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5210runs on test_CT
5211{
5212 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5213 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5214}
5215
5216/* 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 +02005217friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5218 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005219runs on test_CT
5220{
5221 var PCUIF_send_data sd;
5222
5223 timer T := 3.0;
5224 T.start;
5225 alt {
5226 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5227 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5228 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5229 sd.data.u.rts_req.fn, sapi, data);
5230 }
5231 [] PCU.receive { repeat; }
5232 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005234 }
5235 }
5236}
5237
5238/* Send DATA.req on invalid BTS */
5239testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005240 var TfiUsfArr tua := f_TfiUsfArrInit();
5241 var octetstring data := '0000'O & f_rnd_octstring(21);
5242
5243 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005244
Harald Welte883340c2018-02-28 18:59:29 +01005245 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005246 f_TfiUsfArrSet(tua, 7, 0);
5247 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5248 f_sleep(1.0);
5249
5250 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005251}
5252
5253/* Send DATA.req on invalid TRX */
5254testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005255 var TfiUsfArr tua := f_TfiUsfArrInit();
5256 var octetstring data := '0000'O & f_rnd_octstring(21);
5257
5258 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005259
Harald Welte883340c2018-02-28 18:59:29 +01005260 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005261 f_TfiUsfArrSet(tua, 7, 0);
5262 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5263 f_sleep(1.0);
5264
5265 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005266}
5267
5268/* Send DATA.req on invalid timeslot */
5269testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005270 var TfiUsfArr tua := f_TfiUsfArrInit();
5271 var octetstring data := '0000'O & f_rnd_octstring(21);
5272
5273 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005274
Harald Welte883340c2018-02-28 18:59:29 +01005275 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005276 f_TfiUsfArrSet(tua, 7, 0);
5277 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5278 f_sleep(1.0);
5279
5280 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005281}
5282
5283/* Send DATA.req on timeslot that hasn't been activated */
5284testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005285 var TfiUsfArr tua := f_TfiUsfArrInit();
5286 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005287
Harald Welte7162a612019-05-26 12:56:09 +02005288 f_virtphy_common();
5289
5290 f_TfiUsfArrSet(tua, 7, 0);
5291 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5292 f_sleep(1.0);
5293
5294 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005295}
5296
Harald Weltead033dc2019-05-25 17:28:16 +02005297private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005298 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5299 boolean wait_rts := true)
5300runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005301 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005302 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005303
5304 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005305 if (wait_rts) {
5306 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5307 } else {
5308 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5309 }
Harald Weltead033dc2019-05-25 17:28:16 +02005310
5311 T.start;
5312 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005313 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005314 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5315 setverdict(pass);
5316 }
Harald Welte7162a612019-05-26 12:56:09 +02005317 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5318 setverdict(fail, "Received unexpected ", rx_dl);
5319 }
Harald Weltead033dc2019-05-25 17:28:16 +02005320 [] L1CTL.receive {
5321 repeat;
5322 }
Harald Welte7162a612019-05-26 12:56:09 +02005323 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005324 setverdict(fail, "Timeout waiting for ", data);
5325 }
Harald Welte7162a612019-05-26 12:56:09 +02005326 [not expect_data] T.timeout {
5327 setverdict(pass);
5328 }
Harald Weltead033dc2019-05-25 17:28:16 +02005329 }
5330}
5331
5332private function f_disable_dynamic_ts() runs on test_CT
5333{
5334 f_init_vty_bsc();
5335 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5336 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5337 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5338 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005339 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005340}
5341
5342private function f_virtphy_common() runs on test_CT {
5343 f_disable_dynamic_ts();
5344 f_init_l1ctl();
5345 f_l1_tune(L1CTL);
5346}
5347
5348testcase TC_pcu_data_req_pdtch() runs on test_CT {
5349 var TfiUsfArr tua := f_TfiUsfArrInit();
5350 var octetstring data := '0000'O & f_rnd_octstring(21);
5351
5352 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005353
Harald Welte883340c2018-02-28 18:59:29 +01005354 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005355 f_TfiUsfArrSet(tua, 7, 0);
5356 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5357 f_sleep(1.0);
5358
5359 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005360}
5361
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005362/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005363testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005364 var TfiUsfArr tua := f_TfiUsfArrInit();
5365 var octetstring data := '0000'O & f_rnd_octstring(21);
5366
5367 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005368
Harald Welte883340c2018-02-28 18:59:29 +01005369 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005370 f_TfiUsfArrSet(tua, 7, 0);
5371 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5372 f_sleep(1.0);
5373
5374 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005375}
5376
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005377private function f_TC_pcu_ptcch_ul(uint16_t ra)
5378runs on test_CT {
5379 var template PCUIF_Message pcu_rach_ind;
5380 var PCUIF_send_data sd;
5381 var GsmFrameNumber fn;
5382 timer T;
5383
5384 /* Send an Access Burst on PTCCH/U over the Um-interface */
5385 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5386 chan_nr := ts_RslChanNr_PDCH(7),
5387 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5388
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005389 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5390 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005391
5392 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5393 T.start(52.0 * 4.615 / 1000.0);
5394 alt {
5395 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5396 log("Rx an Access Burst on the PCU interface: ", sd.data);
5397 setverdict(pass);
5398 T.stop;
5399 }
5400 [] PCU.receive { repeat; }
5401 [] T.timeout {
5402 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5403 /* Keep going, that's not the end of the world */
5404 }
5405 }
5406}
5407
5408testcase TC_pcu_ptcch() runs on test_CT {
5409 var L1ctlDlMessage dl;
5410 var octetstring data;
5411 timer T;
5412
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005413 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005414 f_init_l1ctl();
5415 f_l1_tune(L1CTL);
5416
5417 /* Activate PDCH channel on TS7 */
5418 f_TC_pcu_act_req(0, 0, 7, true);
5419
5420 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005421 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005422 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005423 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005424 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005425
5426 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5427 for (var integer i := 0; i < 16; i := i + 1) {
5428 log("Sending an Access Burst towards the L1CTL interface");
5429 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5430 }
5431
5432 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5433 data := f_rnd_octstring(23);
5434
5435 /* Verify PTCCH/D: send a random data block, make sure it's received */
5436 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5437 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5438
5439 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5440 * let's give it more time in case if we miss the beginning. */
5441 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5442 alt {
5443 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5444 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5445 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5446 frame := data)) -> value dl {
5447 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5448 setverdict(pass);
5449 T.stop;
5450 }
5451 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5452 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5453 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5454 l2_data := data)) -> value dl {
5455 log("Rx PTCCH/D data block on L1CTL: ", dl);
5456 setverdict(pass);
5457 T.stop;
5458 }
5459 [] L1CTL.receive { repeat; }
5460 [] T.timeout {
5461 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5462 }
5463 }
5464}
5465
Harald Welte883340c2018-02-28 18:59:29 +01005466/* Send AGCH from PCU; check it appears on Um side */
5467testcase TC_pcu_data_req_agch() runs on test_CT {
5468 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005469 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005470 f_init_l1ctl();
5471 f_l1_tune(L1CTL);
5472
5473 f_TC_pcu_act_req(0, 0, 7, true);
5474 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5475
5476 T.start;
5477 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005478 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005479 setverdict(pass);
5480 }
5481 [] L1CTL.receive { repeat; }
5482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005484 }
5485 }
5486}
5487
Harald Welte928622b2019-05-26 13:22:59 +02005488/* Send AGCH from PCU; check it appears on Um side */
5489testcase TC_pcu_data_req_pch() runs on test_CT {
5490 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005491 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005492 f_init_l1ctl();
5493 f_l1_tune(L1CTL);
5494
5495 f_TC_pcu_act_req(0, 0, 7, true);
5496 /* three characters prefix: last 3 digits of IMSI as ASCII */
5497 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5498
5499 T.start;
5500 alt {
5501 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5502 setverdict(pass);
5503 }
5504 [] L1CTL.receive { repeat; }
5505 [] T.timeout {
5506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5507 }
5508 }
5509}
5510
Harald Welte883340c2018-02-28 18:59:29 +01005511/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5512testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5513 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005514 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005515 f_init_l1ctl();
5516 f_l1_tune(L1CTL);
5517
5518 /* append 3 last imsi digits so BTS can compute pagng group */
5519 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5520
5521 timer T := 0.5;
5522 T.start;
5523 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005524 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005525 /* TODO: verify paging group */
5526 setverdict(pass);
5527 }
5528 [] L1CTL.receive { repeat; }
5529 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005531 }
5532 }
5533}
5534
5535/* Send RACH from Um side, expect it to show up on PCU socket */
5536testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005537 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005538 f_init_l1ctl();
5539 f_l1_tune(L1CTL);
5540
5541 var GsmFrameNumber fn_last := 0;
5542 for (var integer i := 0; i < 1000; i := i+1) {
5543 var OCT1 ra := f_rnd_ra_ps();
5544 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5545 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005547 }
5548 fn_last := fn;
5549
5550 timer T := 2.0;
5551 T.start;
5552 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005553 [] 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 +01005554 T.stop;
5555 }
5556 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005558 }
5559 [] PCU.receive { repeat; }
5560 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005562 }
5563 }
5564 }
5565 setverdict(pass);
5566}
5567
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005568/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5569 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5570testcase TC_pcu_ext_rach_content() runs on test_CT {
5571 var template PCUIF_Message pcu_rach_ind;
5572 var GsmFrameNumber fn_last := 0;
5573 var L1ctlRachSynchSeq synch_seq;
5574 var PCUIF_BurstType pcu_bt;
5575 var GsmFrameNumber fn;
5576 var BIT11 ra11;
5577
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005578 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005579 f_init_l1ctl();
5580 f_l1_tune(L1CTL);
5581
5582 for (var integer i := 0; i < 1000; i := i+1) {
5583 /* We need to test both TS1 & TS2 */
5584 if (i rem 2 == 0) {
5585 synch_seq := RACH_SYNCH_SEQ_TS1;
5586 pcu_bt := BURST_TYPE_1;
5587 } else {
5588 synch_seq := RACH_SYNCH_SEQ_TS2;
5589 pcu_bt := BURST_TYPE_2;
5590 }
5591
5592 ra11 := f_rnd_ra11_ps();
5593 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5594 if (fn == fn_last) {
5595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5596 "Two RACH in same FN?!?");
5597 }
5598 fn_last := fn;
5599
5600 /* Compose the expected message */
5601 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005602 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005603 ra := bit2int(ra11),
5604 is_11bit := 1,
5605 burst_type := pcu_bt,
5606 fn := fn);
5607
5608 timer T := 2.0;
5609 T.start;
5610 alt {
5611 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5612 T.stop;
5613 }
5614 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5616 }
5617 [] PCU.receive { repeat; }
5618 [] T.timeout {
5619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5620 }
5621 }
5622 }
5623 setverdict(pass);
5624}
5625
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005626private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5627runs on test_CT {
5628 var template PCUIF_send_data sdt;
5629 var PCUIF_send_data sd;
5630 var int16_t lqual_cb;
5631 timer T := 1.0;
5632
5633 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5634 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5635
5636 /* Send a random PDTCH frame over Um */
5637 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5638 '0000'O & f_rnd_octstring(21)));
5639
5640 T.start;
5641 alt {
5642 /* If expected link quality is above the threshold */
5643 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5644 lqual_cb := sd.data.u.data_ind.lqual_cb;
5645 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5646
5647 /* Make sure the actual link quality matches the expected value */
5648 if (not match(lqual_cb, lqual_cb_exp)) {
5649 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5650 "expected value ", lqual_cb_exp));
5651 } else {
5652 setverdict(pass);
5653 }
5654 }
5655 /* If expected link quality is below the threshold */
5656 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5658 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5659 }
5660 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5661 [] PCU.receive { repeat; }
5662 [lqual_cb_exp < thresh] T.timeout {
5663 log("Rx nothing, as expected");
5664 setverdict(pass);
5665 }
5666 [lqual_cb_exp >= thresh] T.timeout {
5667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5668 "Timeout waiting for PCUIF_DATA.ind");
5669 }
5670 }
5671}
5672
5673/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5674testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005675 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005676 PCU.clear;
5677
5678 f_init_l1ctl();
5679 f_l1_tune(L1CTL);
5680
5681 /* Activate a PDCH channel on TS7 */
5682 f_TC_pcu_act_req(0, 0, 7, true);
5683
5684 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005685 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005686 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005687 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005688 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005689
5690 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5691 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5692 var TrxcMessage ret;
5693
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005694 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005695
5696 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5697 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5698 }
5699}
5700
Harald Welte883340c2018-02-28 18:59:29 +01005701/* Send PAGING via RSL, expect it to shw up on PCU socket */
5702testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005703 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005704
5705 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005706 var MobileIdentityLV mi_lv;
5707 var octetstring mi_lv_enc;
5708 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005709 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005710
Harald Welte883340c2018-02-28 18:59:29 +01005711 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005712 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005713 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005714 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005715 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005716
5717 /* Fancy encoding for PCUIF */
5718 mi_lv := valueof(ts_MI_LV(mi));
5719 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5720 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005721
5722 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005723 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005724 T.start;
5725 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005726 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005727 }
5728 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005730 }
5731 [] PCU.receive { repeat; }
5732 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005734 }
5735 }
5736 }
5737 setverdict(pass);
5738}
5739
Harald Welted66c9b82019-05-25 09:03:15 +02005740/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5741testcase TC_pcu_time_ind() runs on test_CT {
5742 var PCUIF_send_data pcu_sd;
5743 var integer num_time_ind := 0;
5744 var integer first_fn, last_fn;
5745 var float test_duration := 5.0;
5746 timer T;
5747
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005748 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005749 f_TC_pcu_act_req(0, 0, 7, true);
5750
5751 PCU.clear;
5752 T.start(test_duration);
5753 alt {
5754 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5755 num_time_ind := num_time_ind + 1;
5756 if (not isbound(first_fn)) {
5757 first_fn := pcu_sd.data.u.time_ind.fn;
5758 }
5759 last_fn := pcu_sd.data.u.time_ind.fn;
5760 repeat;
5761 }
5762 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5763 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5764 repeat;
5765 }
5766 [] PCU.receive {
5767 repeat;
5768 }
5769 [] T.timeout {}
5770 }
5771 var integer fn_expired := last_fn - first_fn;
5772 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5773
5774 /* verify the number of frames expired matches our expectation */
5775 const float c_GSM_FN_DURATION_MS := 4.61538;
5776 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005777 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005778 if (not match(fn_expired, t_fn_expected)) {
5779 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5780 }
5781
5782 /* There are three TIME.ind in every fn MOD 13 */
5783 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5784 /* Add some tolerance */
5785 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5786 if (not match(num_time_ind, t_time_ind_exp)) {
5787 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5788 }
5789
5790 setverdict(pass);
5791}
5792
Harald Welte4832c862019-05-25 14:57:18 +02005793/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5794testcase TC_pcu_rts_req() runs on test_CT {
5795 var PCUIF_send_data pcu_sd;
5796 var integer first_fn, last_fn;
5797 var integer num_rts_pdtch := 0;
5798 var integer num_rts_ptcch := 0;
5799 var float test_duration := 5.0;
5800 timer T;
5801
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005802 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005803 f_TC_pcu_act_req(0, 0, 7, true);
5804
5805 PCU.clear;
5806 T.start(test_duration);
5807 alt {
5808 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5809 -> value pcu_sd {
5810 num_rts_pdtch := num_rts_pdtch + 1;
5811 if (not isbound(first_fn)) {
5812 first_fn := pcu_sd.data.u.rts_req.fn;
5813 }
5814 last_fn := pcu_sd.data.u.rts_req.fn;
5815 repeat;
5816 }
5817 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5818 -> value pcu_sd {
5819 num_rts_ptcch := num_rts_ptcch + 1;
5820 if (not isbound(first_fn)) {
5821 first_fn := pcu_sd.data.u.rts_req.fn;
5822 }
5823 last_fn := pcu_sd.data.u.rts_req.fn;
5824 repeat;
5825 }
5826 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5827 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5828 repeat;
5829 }
5830 [] PCU.receive {
5831 repeat;
5832 }
5833 [] T.timeout {}
5834 }
5835 var integer fn_expired := last_fn - first_fn;
5836 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5837 ", num_rts_ptcch=", num_rts_ptcch);
5838
5839 /* verify the number of frames expired matches our expectation */
5840 const float c_GSM_FN_DURATION_MS := 4.61538;
5841 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005842 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005843 if (not match(fn_expired, t_fn_expected)) {
5844 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5845 }
5846
5847 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5848 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5849 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5850 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5851 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5852 t_ptcch_exp);
5853 }
5854
5855 /* We have 12 PDTCH blocks every 52-multiframe */
5856 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5857 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5858 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5859 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5860 t_pdtch_exp);
5861 }
5862
5863 setverdict(pass);
5864}
5865
Harald Welte07bd2d22019-05-25 11:03:30 +02005866/* test for generating Abis side OML ALERT from the PCU */
5867testcase TC_pcu_oml_alert() runs on test_CT {
5868 var PCUIF_send_data pcu_sd;
5869 var integer num_time_ind := 0;
5870 var integer first_fn, last_fn;
5871 var float test_duration := 5.0;
5872 timer T;
5873
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005874 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005875 f_TC_pcu_act_req(0, 0, 7, true);
5876
5877 /* re-connect CTRL port from BTS to BSC */
5878 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005879 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005880
5881 /* Send that OML Alert */
5882 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5883
5884 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5885 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5886 setverdict(pass);
5887}
5888
Harald Welteeaa9a862019-05-26 23:01:08 +02005889/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5890private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5891 var PCUIF_Message first_info;
5892 var integer pcu_conn_id := -1;
5893 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5894 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5895 var OCT4 tlli := '01020304'O;
5896 var OCT1 cause := '23'O;
5897 timer T := 5.0;
5898
5899 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5900
5901 f_l1_tune(L1CTL);
5902 RSL.clear;
5903
5904 f_est_dchan();
5905 L1CTL.clear;
5906
5907 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5908
5909 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5910 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5911 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5912
5913 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5914 T.start;
5915 alt {
5916 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5917 setverdict(pass);
5918 }
5919 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5920 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5921 }
5922 [] PCU.receive {
5923 repeat;
5924 }
5925 [] T.timeout {
5926 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5927 }
5928 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005929
5930 /* release the channel */
5931 f_rsl_chan_deact();
5932 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5933 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005934}
5935testcase TC_pcu_rr_suspend() runs on test_CT {
5936 var ConnHdlrPars pars;
5937 var ConnHdlr vc_conn;
5938
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005939 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005940
5941 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5942 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5943 vc_conn.done;
5944}
Harald Welte07bd2d22019-05-25 11:03:30 +02005945
Harald Weltea2e0e942019-05-27 18:12:53 +02005946/* Ensure that PCUIF socket can accept only a single connection */
5947testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005948 var boolean connected := false;
5949 var UD_connect_result cr;
5950 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005951 timer T := 5.0;
5952
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005953 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5954 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5955
Harald Weltea2e0e942019-05-27 18:12:53 +02005956 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005957 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005958
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005959 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005960 PCU.send(UD_connect:{mp_pcu_socket, -1});
5961 T.start;
5962 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005963 /* the IUT will first accept() the new connection, and close() it immediately */
5964 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5965 log("BTS has accept()ed connection");
5966 connected := true;
5967 cid := cr.id;
5968 repeat;
5969 }
5970 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5971 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005972 setverdict(pass);
5973 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005974 /* ignore other messages related to the first connection */
5975 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005976 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005977 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005978 }
5979 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005980
Harald Weltea2e0e942019-05-27 18:12:53 +02005981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5982}
5983
Harald Weltec8effb72019-05-27 18:23:04 +02005984/* Ensure that PCUIF socket can disconnect + reconnect */
5985testcase TC_pcu_socket_reconnect() runs on test_CT {
5986 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005987 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005988
5989 f_sleep(1.0);
5990
5991 f_pcuif_close(PCU, g_pcu_conn_id);
5992 g_pcu_conn_id := -1;
5993
5994 f_sleep(1.0);
5995
5996 /* re-connect */
5997 PCU.clear;
5998 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5999 setverdict(pass);
6000
6001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6002}
6003
Harald Weltebe030482019-05-27 22:29:35 +02006004/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006005private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6006runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006007 var L1ctlDlMessage l1_dl;
6008 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006009 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006010 timer T := 5.0;
6011 T.start;
6012 alt {
6013 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006014 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6015 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006016 repeat;
6017 }
6018 }
6019 [] pt.receive {
6020 repeat;
6021 }
6022 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6024 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006025 }
6026 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006027 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006028}
6029
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006030/* Check if GPRS Indicator is present in RR System Information of a given type */
6031private function f_si_has_gprs_indicator(RrMessageType si_type)
6032runs on test_CT return boolean {
6033 var SystemInformation si := f_get_si(L1CTL, si_type);
6034
6035 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006036 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006037 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006038 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006039 }
6040
6041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6042 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006043}
6044
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006045/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6046private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6047runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006048 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006049 f_init_l1ctl();
6050 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006051 f_sleep(2.0);
6052 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006053
6054 if (f_si_has_gprs_indicator(si_type)) {
6055 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006056 } else {
6057 setverdict(pass);
6058 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006059
Harald Weltebe030482019-05-27 22:29:35 +02006060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6061}
6062
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006063testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6064 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6065}
Harald Weltebe030482019-05-27 22:29:35 +02006066
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006067testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6068 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6069}
6070
6071/* Ensure that GPRS capability is advertised after PCU socket connect */
6072private function f_TC_pcu_socket_connect(RrMessageType si_type)
6073runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006074 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006075 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006076 f_init_l1ctl();
6077 f_l1_tune(L1CTL);
6078
6079 f_sleep(2.0);
6080 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006081
6082 if (not f_si_has_gprs_indicator(si_type)) {
6083 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006084 } else {
6085 setverdict(pass);
6086 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006087
Harald Weltebe030482019-05-27 22:29:35 +02006088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6089}
6090
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006091testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6092 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6093}
Harald Weltebe030482019-05-27 22:29:35 +02006094
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006095testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6096 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6097}
6098
6099/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6100private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6101runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006102 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006103 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006104 f_init_l1ctl();
6105 f_l1_tune(L1CTL);
6106
6107 f_pcuif_close(PCU, g_pcu_conn_id);
6108 g_pcu_conn_id := -1;
6109
6110 f_sleep(1.0);
6111
6112 /* re-connect */
6113 PCU.clear;
6114 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6115
6116 f_sleep(2.0);
6117 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006118
6119 if (f_si_has_gprs_indicator(si_type)) {
6120 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006121 } else {
6122 setverdict(pass);
6123 }
6124
6125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6126}
6127
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006128testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6129 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6130}
6131
6132testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6133 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6134}
6135
Oliver Smithf5239c72019-08-28 10:01:25 +02006136/* 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) */
6137testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6138 var SystemInformation si3 := valueof(ts_SI3_default);
6139
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006140 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006141
Harald Welte76220222020-10-11 20:32:44 +02006142 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6143 * information */
6144 timer T := 2.0;
6145 T.start;
6146 alt {
6147 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6148 [] T.timeout {}
6149 }
6150
Oliver Smithf5239c72019-08-28 10:01:25 +02006151 /* Verify cell_id */
6152 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6153 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6154 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006155 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6156 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6157 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006158 }
6159
6160 /* Verify LAC */
6161 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6162 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6163 if (lac_si3 != lac_pcu) {
6164 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6165 }
6166
6167 setverdict(pass);
6168}
Harald Welted66c9b82019-05-25 09:03:15 +02006169
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006170/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6171testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6172 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006173 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006174
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006175 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006176
6177 info_ind := g_pcu_last_info.u.info_ind;
6178
6179 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6180 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006181 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006182 /* Skip inactive timeslots */
6183 continue;
6184 }
6185
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006186 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006187 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006188 else
6189 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006190
6191 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006192 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006193 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006194 hsn := fhp.maio_hsn.hsn,
6195 maio := fhp.maio_hsn.maio,
6196 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006197 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006198 } else {
6199 tr_ts := tr_PCUIF_InfoTrxTsH0;
6200 }
6201
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006202 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006203 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6204 if (not match(ts, tr_ts)) {
6205 setverdict(fail, "Hopping parameters do not match: ",
6206 "received ", ts, " vs expected ", tr_ts);
6207 } else {
6208 setverdict(pass);
6209 }
6210 }
6211 }
6212}
6213
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006214/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006215testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6216 f_init_vty_bsc();
6217 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6218 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6219
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006220 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006221
6222 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006223 var template PCUIF_RemoteAddr tr_remote_addr := {
6224 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006225 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006226 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006227
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006228 if (not match(remote_addr, tr_remote_addr)) {
6229 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006230 }
6231
6232 setverdict(pass);
6233}
6234
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006235/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006236testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6237 f_init_vty_bsc();
6238 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6239
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006240 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006241
6242 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006243 var template PCUIF_RemoteAddr tr_remote_addr := {
6244 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6245 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6246 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006247
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006248 if (not match(remote_addr, tr_remote_addr)) {
6249 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006250 }
6251
6252 setverdict(pass);
6253}
6254
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006255/* Verify coding of two NSVCs in the INFO.ind message */
6256testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6257 f_init_vty_bsc();
6258
6259 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6260 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6261 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6262 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6263
6264 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6265 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6266 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6267 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6268
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006269 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006270
6271 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6272 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6273 var template PCUIF_RemoteAddr tr_remote_addr := {
6274 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006275 addr := {
6276 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6277 f_inet6_addr("fd00::ca:ff:ee")
6278 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006279 };
6280
6281 if (not match(info_ind.nsvci, { 1234, 5678 }))
6282 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6283 if (not match(remote_addr, tr_remote_addr))
6284 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6285 if (not match(info_ind.local_port, { 1234, 5678 }))
6286 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6287 if (not match(info_ind.remote_port, { 1234, 5678 }))
6288 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6289
6290 setverdict(pass);
6291}
6292
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006293/* Verify periodic interference reports on PDCH */
6294testcase TC_pcu_interf_ind() runs on test_CT {
6295 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006296 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006297 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006298 var PCUIF_send_data sd;
6299 timer T;
6300
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006301 /* Set the averaging/reporting period to 480ms */
6302 f_init_vty_bsc();
6303 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6304 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6305
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006306 f_init_with_pcuif();
6307 f_TC_pcu_act_req(0, 0, 7, true);
6308
6309 /* We need trxcon for NOPE indications */
6310 f_init_l1ctl();
6311 f_l1_tune(L1CTL);
6312
6313 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006314 tr_interf_ind := tr_PCUIF_INTERF_IND(
6315 bts_nr := 0,
6316 trx_nr := 0,
6317 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006318 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006319 );
6320
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006321 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006322 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006323 /* The first interference report may contain unreliable values, so we ignore it */
6324 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6325 /* 4 SACCH periods => 4 reports (plus some guard time) */
6326 T.start(0.480 * 4.0 + 0.480 / 2.0);
6327 first := false;
6328 repeat;
6329 }
6330 /* Subsequent interference reports shall match our expectations */
6331 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006332 /* Check TDMA frame number period */
6333 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6334 setverdict(fail, "Odd TDMA frame number := ",
6335 sd.data.u.interf_ind.fn);
6336 }
6337 interf_ind_num := interf_ind_num + 1;
6338 if (interf_ind_num < 4)
6339 { repeat; }
6340 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006341 [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 +02006342 setverdict(fail, "Received unexpected interference report: ", sd.data);
6343 }
6344 [] PCU.receive { repeat; }
6345 [] T.timeout {
6346 setverdict(fail, "Timeout waiting for interference reports");
6347 }
6348 }
6349
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006350 /* Reset the averaging/reporting period back to default */
6351 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6352
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6354}
6355
Harald Welte3d04ae62018-04-04 20:29:05 +02006356/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006357 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006358 ***********************************************************************/
6359
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006360private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6361 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006362runs on ConnHdlr {
6363 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006364
6365 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006366 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006367 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6368 repeat;
6369 }
6370 }
6371}
6372
6373private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6374runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006375 /* Expect BTS to immediately acknowledge activation as PDCH */
6376 PCU.clear;
6377 f_rsl_chan_act(g_pars.chan_mode);
6378 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006379 timer T_wait := 2.0;
6380 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006381 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006382 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006383 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006384 [] T_wait.timeout {
6385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6386 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6387 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006388 }
6389 /* try to activate this PDCH from the PCU point of view */
6390 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6391 /* FIXME: is there a response? */
6392}
6393
6394private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6395runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006396 /* Send RSL CHAN REL (deactivate) */
6397 PCU.clear;
6398 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6399 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006400 timer T_wait := 2.0;
6401 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006402 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006403 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006404 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006405 [] T_wait.timeout {
6406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6407 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6408 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006409 }
6410 /* Emulate PCU asking BTS to deactivate PDCH */
6411 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6412 alt {
6413 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6414 setverdict(pass);
6415 }
6416 [] RSL.receive { repeat; }
6417 }
6418}
6419
6420/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006421private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006422 var PCUIF_Message first_info;
6423 var integer ts_nr := g_chan_nr.tn;
6424 var integer trx_nr := 0;
6425 var integer bts_nr := 0;
6426 var integer pcu_conn_id := -1;
6427
6428 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6429
6430 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6431 f_sleep(3.0);
6432 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6433 setverdict(pass);
6434}
6435testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6436 var ConnHdlrPars pars;
6437 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006438 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006439
6440 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6441 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6442 vc_conn.done;
6443}
6444
6445/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006446private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006447 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006448 var integer pcu_conn_id := -1;
6449
6450 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6451
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006452 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6453 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6454 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006455 setverdict(pass);
6456}
6457testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6458 var ConnHdlrPars pars;
6459 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006460 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006461
6462 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6463 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6464 vc_conn.done;
6465}
6466
6467/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006468private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006469 var PCUIF_Message first_info;
6470 var integer ts_nr := g_chan_nr.tn;
6471 var integer trx_nr := 0;
6472 var integer bts_nr := 0;
6473 var integer pcu_conn_id := -1;
6474
6475 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6476
6477 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006478 /* Send a second Chan Activ and expect it to be NACKed */
6479 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6480 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006481 setverdict(pass);
6482}
6483testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6484 var ConnHdlrPars pars;
6485 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006486 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006487
6488 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6489 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6490 vc_conn.done;
6491}
6492
6493/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006494private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006495 var PCUIF_Message first_info;
6496 var integer ts_nr := g_chan_nr.tn;
6497 var integer trx_nr := 0;
6498 var integer bts_nr := 0;
6499 var integer pcu_conn_id := -1;
6500 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6501
6502 /* register for the TCH/F channel number */
6503 f_rslem_register(0, chan_nr);
6504
6505 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6506
6507 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6508 "RSL CHAN ACT");
6509 setverdict(pass);
6510}
6511testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6512 var ConnHdlrPars pars;
6513 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006514 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006515
6516 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6517 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6518 vc_conn.done;
6519}
6520
6521/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006522private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006523 var PCUIF_Message first_info;
6524 var integer ts_nr := g_chan_nr.tn;
6525 var integer trx_nr := 0;
6526 var integer bts_nr := 0;
6527 var integer pcu_conn_id := -1;
6528 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6529 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6530
6531 /* register for the TCH/H channel numbers */
6532 f_rslem_register(0, chan_nr[0]);
6533 f_rslem_register(0, chan_nr[1]);
6534
6535 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6536
6537 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6538 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6539 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6540 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6541 setverdict(pass);
6542}
6543testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6544 var ConnHdlrPars pars;
6545 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006546 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006547
6548 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6549 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6550 vc_conn.done;
6551}
6552
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006553/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6554private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6555 var PCUIF_Message first_info;
6556 var integer ts_nr := g_chan_nr.tn;
6557 var integer trx_nr := 0;
6558 var integer bts_nr := 0;
6559 var integer pcu_conn_id := -1;
6560 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6561 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6562 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6563 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6564 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6565 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6566 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6567 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6568
6569 /* register for the TCH/H channel numbers */
6570 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6571 f_rslem_register(0, chan_nr[i]);
6572 }
6573
6574 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6575
6576 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6577 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6578 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6579 }
6580 setverdict(pass);
6581}
6582testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6583 var ConnHdlrPars pars;
6584 var ConnHdlr vc_conn;
6585 f_init();
6586
6587 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6588 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6589 vc_conn.done;
6590}
6591
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006592/* Reproduce a race condition described in OS#5245 */
6593private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6594 f_rsl_chan_act(g_pars.chan_mode);
6595 f_sleep(1.0);
6596 f_rsl_chan_deact();
6597 setverdict(pass);
6598}
6599testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6600 var ConnHdlrPars pars[2];
6601 var ConnHdlr vc_conn[2];
6602 var TrxcMessage rsp;
6603
6604 f_init();
6605
6606 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6607 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6608 ts_TRXC_FAKE_TRXC_DELAY(200));
6609
6610 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6611 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6612 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6613 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6614 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6615 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6616 pars[i], l1ctl := false);
6617 }
6618
6619 /* Wait for all components to finish */
6620 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6621 vc_conn[i].done;
6622 }
6623
6624 /* Disable the artificial delay for TRXC RSP messages */
6625 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6626 ts_TRXC_FAKE_TRXC_DELAY(0));
6627}
6628testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6629 var ConnHdlrPars pars[8];
6630 var ConnHdlr vc_conn[8];
6631 var TrxcMessage rsp;
6632
6633 f_init();
6634
6635 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6636 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6637 ts_TRXC_FAKE_TRXC_DELAY(200));
6638
6639 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6640 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6641 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6642 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6643 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6644 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6645 pars[i], l1ctl := false);
6646 }
6647
6648 /* Wait for all components to finish */
6649 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6650 vc_conn[i].done;
6651 }
6652
6653 /* Disable the artificial delay for TRXC RSP messages */
6654 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6655 ts_TRXC_FAKE_TRXC_DELAY(0));
6656}
6657
Harald Welte9bbbfb52018-04-05 09:33:19 +02006658/***********************************************************************
6659 * IPA Style Dynamic Timeslot Support
6660 ***********************************************************************/
6661
6662private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6663runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006664 /* Expect BTS to immediately acknowledge activation as PDCH */
6665 PCU.clear;
6666 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6667 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006668 timer T_wait := 2.0;
6669 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006670 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006671 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006672 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006673 [] T_wait.timeout {
6674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6675 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6676 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006677 }
6678 /* try to activate this PDCH from the PCU point of view */
6679 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6680 /* FIXME: is there a response? */
6681
6682 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6683}
6684
6685private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6686runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006687 /* Send RSL CHAN REL (deactivate) */
6688 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6689 PCU.clear;
6690 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006691 timer T_wait := 2.0;
6692 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006693 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006694 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006695 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006696 [] T_wait.timeout {
6697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6698 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6699 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006700 }
6701 /* Emulate PCU asking BTS to deactivate PDCH */
6702 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6703 alt {
6704 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6705 setverdict(pass);
6706 }
6707 [] RSL.receive { repeat; }
6708 }
6709}
6710
6711/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006712private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006713 var PCUIF_Message first_info;
6714 var integer ts_nr := g_chan_nr.tn;
6715 var integer trx_nr := 0;
6716 var integer bts_nr := 0;
6717 var integer pcu_conn_id := -1;
6718
6719 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6720
6721 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6722 f_sleep(3.0);
6723 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6724
6725 setverdict(pass);
6726
6727}
6728testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6729 var ConnHdlrPars pars;
6730 var ConnHdlr vc_conn;
6731 f_init();
6732
6733 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6734 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6735 vc_conn.done;
6736}
6737
6738/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006739private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006740 var PCUIF_Message first_info;
6741 var integer ts_nr := g_chan_nr.tn;
6742 var integer trx_nr := 0;
6743 var integer bts_nr := 0;
6744 var integer pcu_conn_id := -1;
6745
6746 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6747
6748 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6749 "RSL CHAN ACT");
6750 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6751 "RF CHAN REL", true);
6752 setverdict(pass);
6753}
6754testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6755 var ConnHdlrPars pars;
6756 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006757 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006758
6759 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6760 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6761 vc_conn.done;
6762}
6763
6764/* 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 +07006765private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006766 var PCUIF_Message first_info;
6767 var integer ts_nr := g_chan_nr.tn;
6768 var integer trx_nr := 0;
6769 var integer bts_nr := 0;
6770 var integer pcu_conn_id := -1;
6771
6772 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6773
6774 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6775 "RSL CHAN ACT");
6776
6777 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6778 alt {
6779 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6780 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006782 }
6783 [] RSL.receive { repeat; }
6784 }
6785
6786 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6787 "RF CHAN REL", true);
6788 setverdict(pass);
6789}
6790testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6791 var ConnHdlrPars pars;
6792 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006793 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006794
6795 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6796 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6797 vc_conn.done;
6798}
6799
6800/* 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 +07006801private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006802 var PCUIF_Message first_info;
6803 var integer ts_nr := g_chan_nr.tn;
6804 var integer trx_nr := 0;
6805 var integer bts_nr := 0;
6806 var integer pcu_conn_id := -1;
6807
6808 /* register for the TCH/F channel number */
6809 f_rslem_register(0, g_chan_nr);
6810
6811 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6812
6813 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6814
6815 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6816 "RSL CHAN ACT");
6817
6818 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6819
6820 setverdict(pass);
6821}
6822testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6823 var ConnHdlrPars pars;
6824 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006825 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006826
6827 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6828 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6829 vc_conn.done;
6830}
6831
6832
Harald Welte0472ab42018-03-12 15:02:26 +01006833/***********************************************************************
6834 * LAPDm / RLL related
6835 ***********************************************************************/
6836
6837private function f_tx_lapdm(template (value) LapdmFrame l,
6838 template (value) RslLinkId link_id) runs on ConnHdlr {
6839 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006840 var template (value) SacchL1Header l1h;
6841
6842 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006843 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006844 /* Compose dummy L1 header */
6845 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6846 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 +02006847 } else {
6848 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006849 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 +01006850 }
Harald Welte0472ab42018-03-12 15:02:26 +01006851}
6852
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006853friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006854 uint3_t sapi,
6855 RslLinkId link_id,
6856 octetstring l3,
6857 boolean exp
6858}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006859friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006860friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6861 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006862 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006863 sapi := sapi,
6864 link_id := id,
6865 l3 := l3,
6866 exp := exp
6867}
6868
6869/* execute the same callback function with a set of different parameters (tcs) on a
6870 * variety of logical channels */
6871private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6872 var ConnHdlrPars pars;
6873 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006874 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006875
6876 /* test on each of the channels we have */
6877 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6878 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6879
6880 /* test each of the test cases on the current channel */
6881 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6882 pars.spec.rll := tcs[j];
6883 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6884 vc_conn := f_start_handler(fn, pars);
6885 vc_conn.done;
6886 }
6887 }
6888
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006890}
6891
6892/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6893private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6894 var RllTestCase tc := g_pars.spec.rll;
6895 timer T := 3.0;
6896
6897 f_l1_tune(L1CTL);
6898 RSL.clear;
6899
6900 /* activate the logical channel */
6901 f_est_dchan();
6902 L1CTL.clear;
6903
6904 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6905 T.start;
6906 alt {
6907 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6908 if (tc.exp) {
6909 setverdict(pass);
6910 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006912 }
6913 }
6914 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6915 if (tc.exp) {
6916 setverdict(pass);
6917 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006919 }
6920 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006921 /* We also expect to receive the measurements */
6922 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006923 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006925 }
6926 [not tc.exp] T.timeout {
6927 setverdict(pass);
6928 }
6929 }
6930
6931 f_rsl_chan_deact();
6932 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6933 f_rslem_unregister(0, g_chan_nr);
6934}
6935testcase TC_rll_est_ind() runs on test_CT {
6936 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006937 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006938 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006939 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006940 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006941 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006942 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6943 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006944 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006945 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006946 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006947 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006948 };
6949 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6950}
6951
6952/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6953private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6954 var RllTestCase tc := g_pars.spec.rll;
6955 var L1ctlDlMessage dl;
6956 timer T := 3.0;
6957
6958 f_l1_tune(L1CTL);
6959 RSL.clear;
6960
6961 /* activate the logical channel */
6962 f_est_dchan();
6963 L1CTL.clear;
6964
6965 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6966 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6967 T.start;
6968 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006969 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006970 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006972 }
6973 }
6974
6975 f_rsl_chan_deact();
6976 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6977 f_rslem_unregister(0, g_chan_nr);
6978}
6979testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6980 var RllTestCases tcs := {
6981 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006982 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006983 };
6984 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6985}
6986testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6987 var RllTestCases tcs := {
6988 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006989 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006990 }
6991 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6992}
6993
6994/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006995friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006996 var L1ctlDlMessage dl;
6997 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6998 var LapdmFrame lapdm;
6999 var octetstring l2 := dl.payload.data_ind.payload;
7000 if (dl.dl_info.link_id.c == SACCH) {
7001 /* remove L1 header */
7002 l2 := substr(l2, 2, lengthof(l2)-2);
7003 }
7004 if (ischosen(exp.ab)) {
7005 lapdm.ab := dec_LapdmFrameAB(l2);
7006 } else if (ischosen(exp.b4)) {
7007 lapdm.b4 := dec_LapdmFrameB4(l2);
7008 } else if (ischosen(exp.bbis)) {
7009 lapdm.bbis := dec_LapdmFrameBbis(l2);
7010 }
7011 log("Rx LAPDm ", lapdm);
7012 if (match(lapdm, exp)) {
7013 setverdict(pass);
7014 } else {
7015 repeat;
7016 }
7017 }
7018 [] L1CTL.receive { repeat; }
7019}
7020private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7021 timer T := t;
7022 T.start;
7023 alt {
7024 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007026 }
7027 [] as_l1_exp_lapdm(exp);
7028 }
7029}
7030
7031/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7032private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
7033 /* send SABM from MS -> BTS */
7034 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7035 /* expect RLL EST IND on Abis */
7036 alt {
7037 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7038 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7039 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007041 }
7042 [] RSL.receive { repeat; }
7043 }
7044 /* expect UA from BTS -> MS */
7045 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7046}
7047
7048/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7049private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7050 var RllTestCase tc := g_pars.spec.rll;
7051
7052 f_l1_tune(L1CTL);
7053 RSL.clear;
7054
7055 /* activate the logical channel */
7056 f_est_dchan();
7057 L1CTL.clear;
7058
7059 /* first establish the link-layer */
7060 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7061
7062 /* then send the DISC */
7063 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7064 /* ... and expect the REL IND on the RSL side */
7065 alt {
7066 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7067 setverdict(pass);
7068 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007069 /* We also expect to receive the measurements */
7070 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007071 }
7072
7073 /* release the channel */
7074 f_rsl_chan_deact();
7075 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7076 f_rslem_unregister(0, g_chan_nr);
7077}
7078testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7079 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007080 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007081 };
7082 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7083}
7084
7085testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7086 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007087 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007088 };
7089 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7090}
7091testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7092 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007093 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007094 };
7095 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7096}
7097testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7098 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007099 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007100 };
7101 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7102}
7103
7104/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7105private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7106 var RllTestCase tc := g_pars.spec.rll;
7107 f_l1_tune(L1CTL);
7108 RSL.clear;
7109
7110 /* activate the logical channel */
7111 f_est_dchan();
7112 L1CTL.clear;
7113
7114 /* first establish the link-layer */
7115 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7116
7117 /* then send the REL REQ via RSL */
7118 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7119 /* ... and expect the DISC on the Um side */
7120 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007121 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007122 /* FIXME: send a UA in resposne to the DISC */
7123 }
7124 }
7125
7126 /* release the channel */
7127 f_rsl_chan_deact();
7128 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7129 f_rslem_unregister(0, g_chan_nr);
7130}
7131testcase TC_rll_rel_req() runs on test_CT {
7132 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007133 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7134 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7135 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7136 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007137 };
7138 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7139}
7140
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007141/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007142testcase TC_rll_data_req() runs on test_CT {
7143}
7144
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007145/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007146testcase TC_rll_data_ind() runs on test_CT {
7147}
7148
7149/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7150private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7151 var RllTestCase tc := g_pars.spec.rll;
7152
7153 f_l1_tune(L1CTL);
7154 RSL.clear;
7155
7156 f_est_dchan();
7157 L1CTL.clear;
7158
7159 /* Send UNITDATA REQ on RSL side */
7160 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7161 /* Expect it to arrive on the other side */
7162 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007163 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007164 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007165 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007166 }
7167
7168 /* release the channel */
7169 f_rsl_chan_deact();
7170 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7171 f_rslem_unregister(0, g_chan_nr);
7172}
7173testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7174 var octetstring l3 := f_rnd_octstring(15);
7175 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007176 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7177 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007178 };
7179 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7180}
7181testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7182 var octetstring l3 := f_rnd_octstring(19);
7183 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007184 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7185 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007186 };
7187 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7188}
7189
7190/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7191private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7192 var RllTestCase tc := g_pars.spec.rll;
7193
7194 f_l1_tune(L1CTL);
7195 RSL.clear;
7196
7197 f_est_dchan();
7198 L1CTL.clear;
7199
7200 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007201 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007202 /* Expdct RLL UNITDATA IND on RSL side */
7203 alt {
7204 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7205 setverdict(pass);
7206 }
7207 [] RSL.receive { repeat; }
7208 }
7209
7210 /* release the channel */
7211 f_rsl_chan_deact();
7212 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7213 f_rslem_unregister(0, g_chan_nr);
7214}
7215testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007216 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007217 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007218 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7219 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007220 };
7221 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7222}
7223testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7224 var octetstring l3 := f_rnd_octstring(18);
7225 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007226 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7227 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007228 };
7229 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7230}
7231
Harald Weltee613f962018-04-18 22:38:16 +02007232/***********************************************************************
7233 * Encryption Related
7234 ***********************************************************************/
7235
7236/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007237private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007238 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7239 if (link_id.c == SACCH) {
7240 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7241 } else {
7242 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7243 }
7244}
7245
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007246/* Expect (or not expect) other kinds of messages */
7247private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7248 [exp_any] RSL.receive { repeat; }
7249 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007251 }
7252}
7253
Harald Weltee613f962018-04-18 22:38:16 +02007254/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007255private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007256 RslLinkId link_id,
7257 octetstring l3,
7258 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007259 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007260) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007261 timer T := 3.0;
7262 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7263 T.start;
7264 /* Expect RLL UNITDATA IND on RSL side */
7265 alt {
7266 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7267 setverdict(pass);
7268 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007269 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007270 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007271 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007273 }
Harald Weltee613f962018-04-18 22:38:16 +02007274 }
7275}
7276
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007277/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7278private function f_data_mo(
7279 RslLinkId link_id,
7280 boolean p, uint3_t nr, uint3_t ns,
7281 octetstring l3,
7282 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007283 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007284) runs on ConnHdlr {
7285 timer T := 3.0;
7286 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7287 T.start;
7288 /* Expect RLL DATA IND on RSL side */
7289 alt {
7290 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7291 setverdict(pass);
7292 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007293 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007294 [] as_rsl_any_ind(exp_any);
7295 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007297 }
7298 }
7299}
7300
Harald Weltee613f962018-04-18 22:38:16 +02007301/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007302private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007303 f_l1_tune(L1CTL);
7304 f_est_dchan(true);
7305
7306 /* now we actually need to transmit some data both ways to check if the encryption works */
7307 var L1ctlDlMessage dl;
7308
Stefan Sperling603d98e2018-07-25 16:47:28 +02007309 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007310 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7311
7312 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7313 f_unitdata_mt(link_id, l3);
7314
7315 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7316 f_unitdata_mo(link_id, l3);
7317
7318 /* release the channel */
7319 f_rsl_chan_deact();
7320 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7321 f_rslem_unregister(0, g_chan_nr);
7322}
7323testcase TC_chan_act_a51() runs on test_CT {
7324 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7325 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7326 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7327}
7328testcase TC_chan_act_a52() runs on test_CT {
7329 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7330 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7331 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7332}
7333testcase TC_chan_act_a53() runs on test_CT {
7334 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7335 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7336 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7337}
Eric Wildb9260392021-05-15 19:48:22 +02007338testcase TC_chan_act_a54() runs on test_CT {
7339 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7340 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7341 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7342}
Harald Weltee613f962018-04-18 22:38:16 +02007343
Eric Wildf1827a72019-05-28 17:37:35 +02007344/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7345 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 +07007346private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007347 f_l1_tune(L1CTL);
7348 f_est_dchan(true);
7349
7350 /* now we actually need to transmit some data both ways to check if the encryption works */
7351 var L1ctlDlMessage dl;
7352
7353 var octetstring l3 := f_rnd_octstring(20);
7354 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7355
7356 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7357 f_unitdata_mt(link_id, l3);
7358
7359 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7360 f_unitdata_mo(link_id, l3);
7361
7362 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007363 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007364
7365 /* modify key to break proper encryption */
7366 g_pars.encr.key := f_rnd_octstring(8);
7367 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7368 rsl.ies := rsl.ies & { ei };
7369 RSL.send(rsl);
7370
7371 timer T0 := 1.0;
7372 T0.start;
7373 /* Expect RSL MODIFY ACK */
7374 alt {
7375 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7376 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7378 }
7379 [] T0.timeout {
7380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7381 }
7382 }
7383
7384 var octetstring l3msg := f_rnd_octstring(15);
7385 timer T1 := 3.0;
7386 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7387 due to broken encryption */
7388 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7389 T1.start;
7390 alt {
7391 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7393 }
7394 [] T1.timeout {
7395 setverdict(pass);
7396 }
7397 }
7398
7399 /* release the channel */
7400 f_rsl_chan_deact();
7401 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7402 f_rslem_unregister(0, g_chan_nr);
7403}
7404testcase TC_rsl_modify_encr() runs on test_CT {
7405 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7406 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7407 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7408}
Harald Weltee613f962018-04-18 22:38:16 +02007409
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007410/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007411private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007412runs on test_CT {
7413 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7414 var ASP_RSL_Unitdata ud;
7415 timer T;
7416
7417 /* Intave is 6 SACCH periods by default */
7418 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7419
7420 T.start(Tval);
7421 alt {
7422 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7423 setverdict(pass);
7424 }
7425 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7426 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7427 }
7428 [] RSL_CCHAN.receive { repeat; }
7429 [] T.timeout {
7430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7431 "Timeout waiting for RF RESource INDication");
7432 }
7433 }
7434}
7435testcase TC_rsl_rf_resource_ind() runs on test_CT {
7436 var RSL_ResourceInfo info := { };
7437
7438 f_init(trx_nr := 0);
7439
7440 f_init_l1ctl();
7441 f_l1_tune(L1CTL);
7442
7443 /* g_AllChannels contains all logical channels */
7444 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7445 var RslChannelNr chan_nr := g_AllChannels[i];
7446
7447 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7448 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7449 { continue; }
7450
7451 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7452 }
7453
7454 /* Align to the first interference report */
7455 f_TC_rsl_rf_resource_ind(?);
7456
7457 /* Test 4 consecutive messages */
7458 for (var integer i := 0; i < 4; i := i + 1) {
7459 f_TC_rsl_rf_resource_ind(info);
7460 }
7461
7462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7463}
7464
Harald Weltee613f962018-04-18 22:38:16 +02007465/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007466private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007467 /* L3 payload doesn't matter, as it is passed transparently */
7468 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7469 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7470 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7471
7472 f_l1_tune(L1CTL);
7473
7474 /* first establish a dedicated channel in the clear */
7475 f_est_dchan(false);
7476
7477 /* Establish ABM */
7478 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7479
7480 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7481 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7482 /* expect the L3 to arrive still unencrypted on the MS side */
7483 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7484
7485 /* configure L1 to apply ciphering */
7486 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7487 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7488
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007489 /* send first ciphered I-frame in response and expect it on RSL */
7490 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007491
7492 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7493 * and hence enable encryption also on the downlink */
7494
7495 /* expect bi-directional communication work in encrypted mode */
7496 f_unitdata_mo(link_id, f_rnd_octstring(15));
7497 f_unitdata_mt(link_id, f_rnd_octstring(15));
7498
7499 /* release the channel */
7500 f_rsl_chan_deact();
7501 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7502 f_rslem_unregister(0, g_chan_nr);
7503}
7504testcase TC_encr_cmd_a51() runs on test_CT {
7505 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7506 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7507 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7508}
7509testcase TC_encr_cmd_a52() runs on test_CT {
7510 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7511 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7512 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7513}
7514testcase TC_encr_cmd_a53() runs on test_CT {
7515 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7516 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7517 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7518}
Eric Wildb9260392021-05-15 19:48:22 +02007519testcase TC_encr_cmd_a54() runs on test_CT {
7520 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7521 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7522 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7523}
Harald Weltee613f962018-04-18 22:38:16 +02007524
7525private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7526 var LapdmFrame lf;
7527 var octetstring reenc;
7528
7529 /* decode the LAPDm frame */
7530 if (ischosen(exp_match.ab)) {
7531 lf.ab := dec_LapdmFrameAB(enc);
7532 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007534 }
7535
7536 /* check if decoder result matches expectation */
7537 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007539 } else {
7540 log(name, ": matched");
7541 setverdict(pass);
7542 }
7543
7544 /* test if re-encoded frame equals original input */
7545 reenc := enc_LapdmFrame(lf);
7546 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007548 } else {
7549 setverdict(pass);
7550 }
7551}
7552
7553testcase TC_lapdm_selftest() runs on test_CT {
7554 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7555 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7556 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7557 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7558 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7559 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7560 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7561}
7562
Stefan Sperling4880be42018-08-07 18:12:59 +02007563/***********************************************************************
7564 * DTX Related (see GSM 05.08, section 8.3)
7565 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007566private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007567 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007568 var GsmFrameNumber first_fn;
7569 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007570 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007571 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007572 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7573 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007574 const integer frame_dtx_tchf_mod := 104;
7575 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7576 * which operates in terms of blocks rather than frames. */
7577 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7578 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007579 timer T := 5.0;
7580
7581 f_l1_tune(L1CTL);
7582 RSL.clear;
7583 L1CTL.clear;
7584
7585 /* activate TCHF signalling channel */
7586 f_est_dchan(false);
7587
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007588 /* A template for matching dummy LAPDm func=UA frames */
7589 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7590 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7591 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7592
Stefan Sperling4880be42018-08-07 18:12:59 +02007593 T.start;
7594 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007595 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007596 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007597
7598 if (is_first_frame) {
7599 is_first_frame := false;
7600 first_fn := dl.dl_info.frame_nr;
7601 }
7602
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007603 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007604 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007605 T.stop;
7606 f_rsl_chan_deact();
7607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007608
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007609 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7610 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007611
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007612 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007613 setverdict(fail, "Not enough fill frames received: ",
7614 nfill_frames, " out of ", expected_fill_frames);
7615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007616 } else {
7617 setverdict(pass);
7618 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007619 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007620 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7621 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7622 * we should only see the subset of frames numbers which correspond to a block boundary.
7623 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7624 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7625 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007626 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007627 repeat;
7628 }
7629 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007630 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7631 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7632 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007633 f_rsl_chan_deact();
7634 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007635 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007636 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007637 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007638 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007639 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007640
7641 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007642 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7643 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007644 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7645 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7646 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007647 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7648 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007649 case else {
7650 /* This shall not happen, just to be sure */
7651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7652 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007653 }
7654
7655 f_rsl_chan_deact();
7656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007657
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007658 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007659 setverdict(pass);
7660 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007661 setverdict(fail, "Not enough fill frames received: ",
7662 nfill_frames, " out of ", expected_fill_frames);
7663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007664 }
7665 } else {
7666 repeat;
7667 }
7668 }
7669 }
7670 [] L1CTL.receive { repeat; }
7671 [] T.timeout {
7672 f_rsl_chan_deact();
7673 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007675 }
7676 }
7677}
7678
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007679private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007680 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007681 var ConnHdlr vc_conn;
7682 var ConnHdlrPars pars;
7683 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007684 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007685 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007686 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007687 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007688 if (dtxd) {
7689 if (i >= 4) { /* DTX is only allowed on TCH/F */
7690 break;
7691 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007692 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007693 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007694 vc_conn.done;
7695 }
7696}
7697
7698/* Verify that L2 fill frames are sent on TCH in signaling mode if
7699 * there is nothing to transmit while DTX is disabled on downlink. */
7700testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7701 f_tch_sign_l2_fill_frame(false);
7702}
7703
7704/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7705 * there is nothing to transmit while DTX is enabled on downlink. */
7706testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7707 f_tch_sign_l2_fill_frame(true);
7708}
Harald Welte0472ab42018-03-12 15:02:26 +01007709
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007710testcase TC_chopped_ipa_ping() runs on test_CT {
7711 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7712}
7713
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007714testcase TC_chopped_ipa_payload() runs on test_CT {
7715 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7716}
7717
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007718
7719/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7720 * Return value: Measurement Report to be sent (encoded octetstring). */
7721type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7722 runs on ConnHdlr return octetstring;
7723
7724private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7725runs on ConnHdlr {
7726 var L1ctlDlMessage l1_dl;
7727 var SacchL1Header l1h;
7728 var octetstring l2;
7729
7730 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7731 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7732 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7733 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7734
7735 /* Pass it to the user specified call-back function */
7736 l2 := cb.apply(l1h, num_blocks);
7737 /* Send a Measurement Report generated by the call-back */
7738 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7739 l1_dl.dl_info.link_id,
7740 l1h, l2));
7741
7742 /* Shall we keep going? */
7743 num_blocks := num_blocks - 1;
7744 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7745 if (num_blocks > 0) { repeat; }
7746 }
7747 [] L1CTL.receive { repeat; }
7748}
7749
7750private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7751runs on ConnHdlr return octetstring {
7752 /* Command the L1 to apply received parameters */
7753 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7754
7755 /* Dummy measurement report (the results are invalid) */
7756 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7757}
7758
7759private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7760runs on ConnHdlr return octetstring {
7761 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7762 setverdict(fail, "Unexpected MS Power level change: ",
7763 g_pars.l1_pars.ms_power_level, " -> ",
7764 l1h.ms_power_lvl);
7765 }
7766
7767 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7768}
7769
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007770private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7771runs on ConnHdlr return octetstring {
7772 /* UL RSSI oscillation driven by SACCH block number */
7773 if (num_blocks rem 2 == 0) {
7774 f_trxc_fake_rssi(-100);
7775 } else {
7776 f_trxc_fake_rssi(-50);
7777 }
7778
7779 /* Make sure that MS power level remains constant */
7780 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7781}
7782
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007783/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7784private function f_TC_ms_pwr_ctrl_constant(charstring id)
7785runs on ConnHdlr {
7786 var integer num_blocks := 8;
7787 timer T := int2float(num_blocks);
7788
7789 f_l1_tune(L1CTL);
7790 RSL.clear;
7791
7792 /* These IEs are needed for autonomous MS power control */
7793 var template (value) RSL_IE_List ies := {
7794 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7795 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7796 }),
7797 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7798 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7799 })
7800 };
7801
7802 /* Ensure that 'rx-current' equals 'rx-target' */
7803 f_trxc_fake_rssi(mp_uplink_power_target);
7804
7805 /* Establish a dedicated channel */
7806 f_est_dchan(more_ies := valueof(ies));
7807
7808 L1CTL.clear;
7809 T.start;
7810 alt {
7811 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7812 [] T.timeout {
7813 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7814 num_blocks, " were not handled");
7815 }
7816 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007817
7818 /* Release the channel */
7819 f_rsl_chan_deact();
7820 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007821}
7822testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7823 var ConnHdlr vc_conn;
7824 var ConnHdlrPars pars;
7825
7826 f_init();
7827
7828 /* Explicitly configure the Uplink power target (in dBm) */
7829 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7830
7831 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7832 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7833 log(testcasename(), ": starting on ", pars.chan_nr);
7834
7835 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7836 pars, trxc_comp := true);
7837 vc_conn.done;
7838 }
7839
7840 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7842}
7843
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007844/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7845private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7846runs on ConnHdlr {
7847 var integer num_blocks := 16;
7848 timer T := int2float(num_blocks);
7849
7850 f_l1_tune(L1CTL);
7851 RSL.clear;
7852
7853 /* These IEs are needed for autonomous MS power control */
7854 var template (value) RSL_IE_List ies := {
7855 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7856 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7857 }),
7858 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7859 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7860 })
7861 };
7862
7863 /* Ensure that 'rx-current' equals 'rx-target' */
7864 f_trxc_fake_rssi(mp_uplink_power_target);
7865
7866 /* Establish a dedicated channel */
7867 f_est_dchan(more_ies := valueof(ies));
7868
7869 L1CTL.clear;
7870 T.start;
7871 alt {
7872 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7873 [] T.timeout {
7874 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7875 num_blocks, " were not handled");
7876 }
7877 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007878
7879 /* Release the channel */
7880 f_rsl_chan_deact();
7881 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007882}
7883testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7884 var ConnHdlr vc_conn;
7885 var ConnHdlrPars pars;
7886
7887 f_init();
7888
7889 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7890 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7891 /* Explicitly configure the Uplink power range (target and delte) */
7892 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7893 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7894
7895 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7896 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7897 log(testcasename(), ": starting on ", pars.chan_nr);
7898
7899 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7900 pars, trxc_comp := true);
7901 vc_conn.done;
7902 }
7903
7904 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7906}
7907
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007908private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7909 var template L1ctlDlMessage tr_bad_frame;
7910 var L1ctlDlMessage l1_dl;
7911 timer T := 8.0;
7912
7913 f_l1_tune(L1CTL);
7914 RSL.clear;
7915
7916 f_est_dchan();
7917
7918 /* There may be a few errors right after the channel activation */
7919 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7920 L1CTL.clear;
7921
7922 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7923 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7924 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7925 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7926 tr_bad_frame.payload := ?;
7927
7928 T.start;
7929 alt {
7930 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7931 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7932 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7933 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7934 }
7935 [] as_l1_sacch();
7936 [] L1CTL.receive { repeat; }
7937 [] T.timeout {
7938 /* We're done, break the loop */
7939 setverdict(pass);
7940 }
7941 }
7942
7943 f_rsl_chan_deact();
7944 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7945}
7946testcase TC_speech_no_rtp_tchf() runs on test_CT {
7947 var ConnHdlr vc_conn;
7948 var ConnHdlrPars pars;
7949
7950 f_init();
7951
7952 /* TS1, TCH/F, V1 (FR codec) */
7953 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7954 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7955 vc_conn.done;
7956}
7957testcase TC_speech_no_rtp_tchh() runs on test_CT {
7958 var ConnHdlr vc_conn;
7959 var ConnHdlrPars pars;
7960
7961 f_init();
7962
7963 /* TS5, TCH/H, V1 (HR codec) */
7964 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7965 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7966 vc_conn.done;
7967}
7968
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007969/* Verify handling of Downlink and Uplink speech frames */
7970private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7971 var L1ctlDlMessage l1_dl;
7972 var PDU_RTP rtp_pdu;
7973 var octetstring pl;
7974 timer Td, Tu;
7975
7976 f_l1_tune(L1CTL);
7977 f_est_dchan();
7978
7979 /* Activate the RTP emulation */
7980 pl := f_rnd_octstring(6);
7981 f_rtpem_activate(pl);
7982
7983 /* Give the scheduler some time to fill up the buffers */
7984 f_sleep(2.0);
7985 L1CTL.clear;
7986 RSL.clear;
7987
7988 /* Make sure that Downlink frames are received at the UE */
7989 Td.start(2.0);
7990 alt {
7991 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7992 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7993 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7994 l1_dl.payload.traffic_ind.data));
7995 setverdict(pass);
7996 }
7997 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7998 setverdict(fail, "Rx unexpected Downlink speech frame ",
7999 "(", l1_dl.payload.traffic_ind.data, ") ",
8000 "expected (", pl, ")");
8001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8002 }
8003 [] as_l1_sacch();
8004 [] L1CTL.receive { repeat; }
8005 [] Td.timeout {
8006 setverdict(fail, "Timeout waiting for Downlink speech frames");
8007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8008 }
8009 }
8010
8011 /* Make sure that Uplink frames are received at the BTS */
8012 RTPEM_DATA.clear;
8013 Tu.start(2.0);
8014 alt {
8015 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8016 if (rtp_pdu.data != pl)
8017 { repeat; }
8018 }
8019 [] RTPEM_DATA.receive { repeat; }
8020 [] Tu.timeout {
8021 setverdict(fail, "Timeout waiting for Uplink speech frames");
8022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8023 }
8024 }
8025
8026 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8028 f_rsl_chan_deact();
8029 f_rslem_unregister(0, g_chan_nr);
8030}
8031testcase TC_speech_rtp_tchf() runs on test_CT {
8032 var ConnHdlr vc_conn;
8033 var ConnHdlrPars pars;
8034
8035 f_init();
8036
8037 /* TS1, TCH/F, V1 (FR codec) */
8038 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8039 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8040 vc_conn.done;
8041
8042 /* TS1, TCH/F, V2 (EFR codec) */
8043 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8044 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8045 vc_conn.done;
8046
8047 /* TODO: also test V3 (AMR codec) */
8048
8049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8050}
8051testcase TC_speech_rtp_tchh() runs on test_CT {
8052 var ConnHdlr vc_conn;
8053 var ConnHdlrPars pars;
8054
8055 f_init();
8056
8057 /* TS5, TCH/H0, V1 (HR codec) */
8058 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8059 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8060 vc_conn.done;
8061
8062 /* TODO: also test V3 (AMR codec) */
8063
8064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8065}
8066
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008067private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8068 var GsmFrameNumber fn;
8069 var ChannelDescription ch_desc;
8070 var integer ra := 23;
8071
8072 f_l1_tune(L1CTL);
8073 RSL.clear;
8074
8075 /* Send RACH request and wait for ChanReq */
8076 fn := f_rach_req_wait_chan_rqd(ra);
8077
8078 /* The BSC already sends the Immediate Assignment, before the channel is active.
8079 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8080 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8081 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8082 if (g_pars.fhp.enabled) {
8083 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8084 } else {
8085 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8086 }
8087 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8088 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8089
8090 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8091 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8092 var L1ctlDlMessage dl;
8093 var GsmRrMessage rr;
8094
8095 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8096 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8097 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8098 rr_imm_ass.payload.imm_ass.chan_desc := *;
8099
8100 timer T := 1.0;
8101 T.start;
8102 alt {
8103 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8104 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8105 if (match(rr, rr_imm_ass)) {
8106 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8107 mtc.stop;
8108 } else {
8109 repeat;
8110 }
8111 }
8112 [] L1CTL.receive { repeat; }
8113 [] T.timeout;
8114 }
8115 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8116 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8117
8118 /* Now expect the IMM ASS on Um */
8119 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8120 setverdict(pass);
8121
8122 /* Release the channel */
8123 f_rsl_chan_deact();
8124 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8125}
8126
8127testcase TC_early_immediate_assignment() runs on test_CT {
8128 var ConnHdlr vc_conn;
8129 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8130 f_init();
8131 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8132 vc_conn.done;
8133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8134}
8135
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008136private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8137 var integer ra := oct2int(f_rnd_ra_cs());
8138 var ChannelDescription ch_desc;
8139
8140 /* Tune the MS to BCCH */
8141 f_l1_tune(L1CTL);
8142
8143 /* Send RACH request and wait for ChanReq */
8144 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8145
8146 /* Activate channel on the BTS side */
8147 f_rsl_chan_act(g_pars.chan_mode);
8148
8149 /* Craft channel description (with or without frequency hopping parameters) */
8150 if (g_pars.fhp.enabled) {
8151 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8152 } else {
8153 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8154 }
8155
8156 /* Send IMM.ASS via CCHAN */
8157 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8158 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8159
8160 /* Receive IMM.ASS on the MS side */
8161 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8162
8163 /* Match the Channel Description IE in received IMM.ASS */
8164 if (not match(imm_ass.chan_desc, ch_desc)) {
8165 setverdict(fail, "Channel Description IE does not match");
8166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8167 }
8168
8169 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8170 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8171
8172 /* Expect SACCH frames on Downlink */
8173 L1CTL.clear;
8174 f_exp_sacch(true);
8175
8176 /* We're done, deactivate and release */
8177 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8178 f_rsl_chan_deact();
8179}
8180testcase TC_est_dchan() runs on test_CT {
8181 var ConnHdlr vc_conn;
8182 var ConnHdlrPars pars;
8183
8184 f_init();
8185
8186 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8187 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8188 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8189 vc_conn.done;
8190 }
8191
8192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8193}
8194
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008195private type record TopTestCase {
8196 RSL_IE_BS_Power bs_power,
8197 RSL_IE_OSMO_TopAcchCap top_cap,
8198 record of TopTestStep steps
8199};
8200private type record TopTestStep {
8201 MeasurementResults meas_res optional,
8202 GsmRxLev overpower_sacch,
8203 GsmRxLev overpower_facch
8204};
8205
8206private function f_rxlev_match(template (present) RslLinkId link_id,
8207 template (present) GsmRxLev rxlev)
8208runs on ConnHdlr {
8209 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8210 if (not match(dl.dl_info.rx_level, rxlev)) {
8211 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8212 " does not match expected RxLev := ", rxlev);
8213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8214 }
8215}
8216
8217private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8218 var TopTestCase tc := g_pars.spec.top;
8219 var GsmRxLev rxlev_dcch;
8220 var L1ctlDlMessage dl;
8221
8222 /* Wait for Pau ramping to complete */
8223 f_sleep(6.0);
8224
8225 f_l1_tune(L1CTL);
8226 L1CTL.clear;
8227 RSL.clear;
8228
8229 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8230 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8231 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8232
8233 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8234 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8235
8236 /* Additional IEs for the CHANnel ACTIVation message */
8237 var template (value) RSL_IE_List ies := {
8238 /* Employ BS power control in static mode */
8239 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8240 bs_power := tc.bs_power
8241 }),
8242 /* Indicate the given Temporary Overpower capability */
8243 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8244 top_acch_cap := tc.top_cap
8245 })
8246 };
8247
8248 /* Establish a dedicated channel */
8249 f_est_dchan(more_ies := valueof(ies));
8250
8251 /* Give it some time to stabilize */
8252 f_sleep(0.480 * 2.0);
8253 L1CTL.clear;
8254 RSL.clear;
8255
8256 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8257 var TopTestStep step := tc.steps[i];
8258 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8259 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8260
8261 log("Executing step[", i, "] := ", step);
8262
8263 /* Send RR Measurement Report (if present) */
8264 if (ispresent(step.meas_res)) {
8265 f_transceive_meas_rep(step.meas_res);
8266 f_sleep(0.480 * 2.0);
8267 L1CTL.clear;
8268 }
8269
8270 /* Check RxLev on both FACCH and SACCH */
8271 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8272 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8273
8274 setverdict(pass);
8275 }
8276}
8277testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8278 var ConnHdlrPars pars;
8279 var ConnHdlr vc_conn;
8280
8281 f_init();
8282
8283 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008284 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008285 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8286 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8287 steps := {
8288 /* Channel established, no overpower */
8289 { meas_res := omit,
8290 overpower_sacch := 0, overpower_facch := 0 },
8291
8292 /* Worst possible RxQual value, overpower of 4dB */
8293 { meas_res := ts_MeasurementResults(rxq_f := 7),
8294 overpower_sacch := 4, overpower_facch := 4 },
8295 /* Worst possible RxQual value, disabling overpower */
8296 { meas_res := ts_MeasurementResults(rxq_f := 0),
8297 overpower_sacch := 0, overpower_facch := 0 },
8298
8299 /* Lower threshold not reached, no overpower */
8300 { meas_res := ts_MeasurementResults(rxq_f := 1),
8301 overpower_sacch := 0, overpower_facch := 0 },
8302 /* Lower threshold not reached, no overpower */
8303 { meas_res := ts_MeasurementResults(rxq_f := 2),
8304 overpower_sacch := 0, overpower_facch := 0 },
8305 /* Lower threshold reached, overpower of 4dB */
8306 { meas_res := ts_MeasurementResults(rxq_f := 4),
8307 overpower_sacch := 4, overpower_facch := 4 },
8308 /* Upper threshold not reached, keeping overpower */
8309 { meas_res := ts_MeasurementResults(rxq_f := 3),
8310 overpower_sacch := 4, overpower_facch := 4 },
8311 /* Upper threshold reached, disabling overpower */
8312 { meas_res := ts_MeasurementResults(rxq_f := 2),
8313 overpower_sacch := 0, overpower_facch := 0 }
8314 }
8315 };
8316
8317 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8318 spec := { top := top }, trx_nr := 1));
8319 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8320 vc_conn.done;
8321
8322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8323}
8324testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8325 var ConnHdlrPars pars;
8326 var ConnHdlr vc_conn;
8327
8328 f_init();
8329
8330 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008331 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008332 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8333 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8334 steps := {
8335 /* Channel established, no overpower */
8336 { meas_res := omit,
8337 overpower_sacch := 0, overpower_facch := 0 },
8338
8339 /* Invalid measurement results, no overpower */
8340 { meas_res := ts_MeasurementResults(rxq_f := 7,
8341 rxq_s := 7,
8342 valid := false),
8343 overpower_sacch := 0, overpower_facch := 0 },
8344
8345 /* DTXu was in use, no overpower */
8346 { meas_res := ts_MeasurementResults(rxq_f := 7,
8347 rxq_s := 0,
8348 dtx_used := true),
8349 overpower_sacch := 0, overpower_facch := 0 },
8350 /* DTXu was in use, overpower of 4 dB */
8351 { meas_res := ts_MeasurementResults(rxq_f := 0,
8352 rxq_s := 7,
8353 dtx_used := true),
8354 overpower_sacch := 4, overpower_facch := 4 }
8355 }
8356 };
8357
8358 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8359 spec := { top := top }, trx_nr := 1));
8360 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8361 vc_conn.done;
8362
8363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8364}
8365testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8366 var ConnHdlrPars pars;
8367 var ConnHdlr vc_conn;
8368
8369 f_init();
8370
8371 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008372 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008373 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8374 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8375 rxqual := 0, /* always on */
8376 sacch_enable := false),
8377 steps := {
8378 /* Channel established, FACCH overpower */
8379 { meas_res := omit,
8380 overpower_sacch := 0, overpower_facch := 4 },
8381 /* MS indicates good RxQual, no difference */
8382 { meas_res := ts_MeasurementResults(rxq_f := 0),
8383 overpower_sacch := 0, overpower_facch := 4 },
8384 /* MS indicates bad RxQual, no difference */
8385 { meas_res := ts_MeasurementResults(rxq_f := 7),
8386 overpower_sacch := 0, overpower_facch := 4 }
8387 }
8388 };
8389
8390 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8391 spec := { top := top }, trx_nr := 1));
8392 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8393 vc_conn.done;
8394
8395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8396}
8397testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8398 var ConnHdlrPars pars;
8399 var ConnHdlr vc_conn;
8400
8401 f_init();
8402
8403 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008404 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008405 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8406 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8407 rxqual := 0, /* always on */
8408 facch_enable := false),
8409 steps := {
8410 /* Channel established, SACCH overpower */
8411 { meas_res := omit,
8412 overpower_sacch := 4, overpower_facch := 0 },
8413 /* MS indicates good RxQual, no difference */
8414 { meas_res := ts_MeasurementResults(rxq_f := 0),
8415 overpower_sacch := 4, overpower_facch := 0 },
8416 /* MS indicates bad RxQual, no difference */
8417 { meas_res := ts_MeasurementResults(rxq_f := 7),
8418 overpower_sacch := 4, overpower_facch := 0 }
8419 }
8420 };
8421
8422 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8423 spec := { top := top }, trx_nr := 1));
8424 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8425 vc_conn.done;
8426
8427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8428}
8429testcase TC_acch_overpower_limit() runs on test_CT {
8430 var ConnHdlrPars pars;
8431 var ConnHdlr vc_conn;
8432
8433 f_init();
8434
8435 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008436 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008437 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8438 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8439 rxqual := 0 /* always on */),
8440 steps := {
8441 /* Channel established, ACCH overpower of 2dB */
8442 { meas_res := omit,
8443 overpower_sacch := 2, overpower_facch := 2 },
8444 /* MS indicates good RxQual, no difference */
8445 { meas_res := ts_MeasurementResults(rxq_f := 0),
8446 overpower_sacch := 2, overpower_facch := 2 },
8447 /* MS indicates bad RxQual, no difference */
8448 { meas_res := ts_MeasurementResults(rxq_f := 7),
8449 overpower_sacch := 2, overpower_facch := 2 }
8450 }
8451 };
8452
8453 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8454 spec := { top := top }, trx_nr := 1));
8455 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8456 vc_conn.done;
8457
8458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8459}
8460
Harald Welte0472ab42018-03-12 15:02:26 +01008461/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8462/* protocol error as per 44.006 */
8463/* link layer failure (repetition of I-frame N200 times without ACK */
8464/* repetition of SABM or DISC N200 times without ACK */
8465/* receptiom of SABM in multi-frame established state */
8466
8467
Harald Welte68e495b2018-02-25 00:05:57 +01008468/* TODO Areas:
8469
8470* channel activation
8471** with BS_Power / MS_Power, bypassing power control loop
8472** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008473** with timing advance from initial activation on
8474* mode modify
8475** encryption
8476** multirate
8477* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008478** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008479* BS Power Control
8480* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008481* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008482** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008483* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008484** DATA_IND from BTS->PCU
8485** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008486
8487*/
Harald Welte70767382018-02-21 12:16:40 +01008488
8489control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008490 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008491 execute( TC_chan_act_stress() );
8492 execute( TC_chan_act_react() );
8493 execute( TC_chan_deact_not_active() );
8494 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008495 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008496 execute( TC_sacch_filling() );
8497 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008498 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008499 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008500 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008501 execute( TC_sacch_chan_act_ho_async() );
8502 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008503 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008504 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008505 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008506 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008507 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008508 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008509 execute( TC_rach_load_idle_thresh0() );
8510 execute( TC_rach_load_idle_below_thresh() );
8511 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008512 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008513 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008514 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008515 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008516 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008517 execute( TC_meas_res_sign_tchf() );
8518 execute( TC_meas_res_sign_tchh() );
8519 execute( TC_meas_res_sign_sdcch4() );
8520 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008521 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008522 execute( TC_meas_res_speech_tchf_sapi3() );
8523 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008524 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008525 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008526 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008527 execute( TC_rsl_bs_pwr_static_ass() );
8528 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008529 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008530 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008531 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008532 execute( TC_rsl_ms_pwr_dyn_up() );
8533 execute( TC_rsl_ms_pwr_dyn_down() );
8534 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8535 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008536 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008537 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008538 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008539 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008540 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008541 execute( TC_paging_imsi_80percent() );
8542 execute( TC_paging_tmsi_80percent() );
8543 execute( TC_paging_imsi_200percent() );
8544 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008545 execute( TC_rsl_protocol_error() );
8546 execute( TC_rsl_mand_ie_error() );
8547 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008548 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008549 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008550 execute( TC_si_sched_2bis() );
8551 execute( TC_si_sched_2ter() );
8552 execute( TC_si_sched_2ter_2bis() );
8553 execute( TC_si_sched_2quater() );
8554 execute( TC_si_sched_13() );
8555 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008556 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008557 execute( TC_ipa_crcx_twice_not_active() );
8558 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008559 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008560 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008561
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008562 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008563 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008564 execute( TC_pcu_act_req() );
8565 execute( TC_pcu_act_req_wrong_ts() );
8566 execute( TC_pcu_act_req_wrong_bts() );
8567 execute( TC_pcu_act_req_wrong_trx() );
8568 execute( TC_pcu_deact_req() );
8569 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008570 execute( TC_pcu_ver_si1() );
8571 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008572 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008573 if (mp_l1_supports_gprs) {
8574 execute( TC_pcu_data_req_pdtch() );
8575 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008576 execute( TC_pcu_data_req_wrong_bts() );
8577 execute( TC_pcu_data_req_wrong_trx() );
8578 execute( TC_pcu_data_req_wrong_ts() );
8579 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008580 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008581 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008582 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008583 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008584 execute( TC_pcu_data_req_imm_ass_pch() );
8585 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008586 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008587 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008588 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008589 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008590 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008591 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008592 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008593 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008594 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008595 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008596 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008597 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008598 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008599 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008600 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008601 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008602 execute( TC_dyn_osmo_pdch_act_deact() );
8603 execute( TC_dyn_osmo_pdch_double_act() );
8604 execute( TC_dyn_ipa_pdch_act_deact() );
8605 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008606 execute( TC_pcu_info_ind_fh_params() );
8607 execute( TC_pcu_socket_nsvc_ipv4() );
8608 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008609 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008610 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008611 } else {
8612 log("PCU socket path not available, skipping PCU tests");
8613 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008614
Harald Welte3d04ae62018-04-04 20:29:05 +02008615 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008616 execute( TC_dyn_osmo_pdch_tchf_act() );
8617 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008618 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008619 execute( TC_dyn_ipa_pdch_tchf_act() );
8620 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008621
8622 execute( TC_rll_est_ind() );
8623 execute( TC_rll_est_req_DCCH_3() );
8624 execute( TC_rll_est_req_ACCH_3() );
8625 execute( TC_rll_rel_ind_DCCH_0() );
8626 execute( TC_rll_rel_ind_DCCH_3() );
8627 execute( TC_rll_rel_ind_ACCH_0() );
8628 execute( TC_rll_rel_ind_ACCH_3() );
8629 execute( TC_rll_rel_req() );
8630 execute( TC_rll_unit_data_req_DCCH() );
8631 execute( TC_rll_unit_data_req_ACCH() );
8632 execute( TC_rll_unit_data_ind_DCCH() );
8633 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008634
8635 execute( TC_chan_act_a51() );
8636 execute( TC_chan_act_a52() );
8637 execute( TC_chan_act_a53() );
8638 execute( TC_encr_cmd_a51() );
8639 execute( TC_encr_cmd_a52() );
8640 execute( TC_encr_cmd_a53() );
8641
Harald Welteee25aae2019-05-19 14:32:37 +02008642 execute( TC_err_rep_wrong_mdisc() );
8643 execute( TC_err_rep_wrong_msg_type() );
8644 execute( TC_err_rep_wrong_sequence() );
8645
Harald Weltee613f962018-04-18 22:38:16 +02008646 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008647
8648 execute( TC_tch_sign_l2_fill_frame() );
8649 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008650
8651 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008652 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008653
8654 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008655 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008656
8657 execute( TC_speech_no_rtp_tchf() );
8658 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008659 execute( TC_speech_rtp_tchf() );
8660 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008661
8662 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008663
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008664 execute( TC_acch_overpower_rxqual_thresh() );
8665 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8666 execute( TC_acch_overpower_always_on_facch() );
8667 execute( TC_acch_overpower_always_on_sacch() );
8668 execute( TC_acch_overpower_limit() );
8669
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008670 /* BEWARE: these test cases can potentially break the IUT or cause
8671 * weird/unexpected behavior. Ensure that they are executed last. */
8672 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8673 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008674}
8675
8676
8677}