blob: 1d3dfe7c81f5d0326f3479ffefd595880bd8aee8 [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
920/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
921 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
922 * payload is treated as PDU_ML3_NW_MS. */
923private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
924 template (present) PDU_ML3_NW_MS tr_pdu := ?,
925 template (present) GsmSapi sapi := 0)
926runs on ConnHdlr {
927 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
928 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
929 var LapdmFrameAB lapdm_frame;
930
931 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
932 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
933 }
934}
935
Harald Welte93640c62018-02-25 16:59:33 +0100936/***********************************************************************
937 * Channel Activation / Deactivation
938 ***********************************************************************/
939
Harald Welte70767382018-02-21 12:16:40 +0100940/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700941private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100942 for (var integer i := 0; i < 500; i := i+1) {
943 f_rsl_chan_act(g_pars.chan_mode);
944 f_rsl_chan_deact();
945 }
946 setverdict(pass);
947}
948testcase TC_chan_act_stress() runs on test_CT {
949 var ConnHdlr vc_conn;
950 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200951 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100952 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
953 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100955}
956
957/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700958private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100959 f_rsl_chan_act(g_pars.chan_mode);
960 /* attempt to activate the same lchan again -> expect reject */
961 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
962 alt {
963 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100965 }
966 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
967 setverdict(pass);
968 }
969 }
970 f_rsl_chan_deact();
971}
972testcase TC_chan_act_react() runs on test_CT {
973 var ConnHdlr vc_conn;
974 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100975 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100976 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
977 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100979}
980
981/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700982private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100983 timer T := 3.0;
984 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
985 T.start;
986 alt {
987 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
988 setverdict(pass);
989 }
990 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100992 }
993 }
994}
995testcase TC_chan_deact_not_active() runs on test_CT {
996 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100997 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100998 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
999 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001001}
1002
1003/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001004private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001005 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1006 alt {
1007 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001009 }
1010 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1011 setverdict(pass);
1012 }
1013 }
1014}
1015private type record WrongChanNrCase {
1016 RslChannelNr chan_nr,
1017 charstring description
1018}
1019private type record of WrongChanNrCase WrongChanNrCases;
1020private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1021 chan_nr := chan_nr,
1022 description := desc
1023}
1024
1025testcase TC_chan_act_wrong_nr() runs on test_CT {
1026 var ConnHdlr vc_conn;
1027 var ConnHdlrPars pars;
1028
Harald Welte294b0a22018-03-10 23:26:48 +01001029 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001030
1031 var WrongChanNrCases wrong := {
1032 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1033 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1034 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1035 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1036 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1037 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1038 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1039 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1040 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1041 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1042 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1043 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1044 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1045 };
1046
1047 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1048 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1049 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1050 vc_conn.done;
1051 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001053}
1054
Harald Weltee613f962018-04-18 22:38:16 +02001055/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001056friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001057 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001058 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001059
1060 /* test on each of the channels we have */
1061 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1062 pars.chan_nr := valueof(g_AllChanTypes[i]);
1063
1064 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1065 vc_conn := f_start_handler(fn, pars);
1066 vc_conn.done;
1067 }
1068
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001070}
1071
Harald Welte93640c62018-02-25 16:59:33 +01001072/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001073 * SACCH handling
1074 ***********************************************************************/
1075
1076private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1077 timer T_sacch := 3.0;
1078 T_sacch.start;
1079 alt {
1080 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001082 }
1083 [not exp] T_sacch.timeout {
1084 setverdict(pass);
1085 }
1086 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1087 setverdict(pass);
1088 }
1089 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001091 }
1092 [] L1CTL.receive { repeat; }
1093 [] RSL.receive { repeat; }
1094 }
1095}
1096
1097/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1098private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1099 f_l1_tune(L1CTL);
1100 RSL.clear;
1101
1102 /* activate the logical channel */
1103 f_est_dchan();
1104 L1CTL.clear;
1105
1106 /* check that SACCH actually are received as expected */
1107 f_exp_sacch(true);
1108
1109 /* deactivate SACCH on the logical channel */
1110 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1111 f_sleep(1.0);
1112 L1CTL.clear;
1113
1114 /* check that no SACCH are received anymore */
1115 f_exp_sacch(false);
1116
1117 /* release the channel */
1118 f_rsl_chan_deact();
1119 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1120}
1121testcase TC_deact_sacch() runs on test_CT {
1122 var ConnHdlr vc_conn;
1123 var ConnHdlrPars pars;
1124 f_init();
1125 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1126 //for (var integer i := 0; i < 1; i := i+1) {
1127 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1128 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1129 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1130 vc_conn.done;
1131 }
1132 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001134}
1135
Harald Welte55700662018-03-12 13:15:43 +01001136/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001137private function f_sacch_present(template octetstring l3_exp,
1138 boolean do_fail := true)
1139runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001140 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001141 timer T_sacch := 3.0;
1142 L1CTL.clear;
1143 T_sacch.start;
1144 alt {
1145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1146 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1147 if (match(l3, l3_exp)) {
1148 setverdict(pass);
1149 } else {
1150 repeat;
1151 }
1152 }
1153 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001154 [not do_fail] T_sacch.timeout {
1155 log("Timeout waiting for SACCH ", l3_exp);
1156 }
1157 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001158 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001160 }
1161 }
1162}
1163
Harald Welte55700662018-03-12 13:15:43 +01001164/* verify that given SACCH payload is not present */
1165private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1166 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001167 timer T_sacch := 3.0;
1168 L1CTL.clear;
1169 T_sacch.start;
1170 alt {
1171 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1172 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1173 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001174 setverdict(fail, "Received unexpected SACCH ", dl);
1175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001176 } else {
1177 repeat;
1178 }
1179 }
1180 [] L1CTL.receive { repeat; }
1181 [] T_sacch.timeout {
1182 setverdict(pass);
1183 }
1184 }
1185}
1186
Harald Welte629cc6b2018-03-11 17:19:05 +01001187/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001188private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1189 /* Set a known default SACCH filling for SI5 */
1190 var octetstring si5 := f_rnd_octstring(19);
1191 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1192
1193 f_l1_tune(L1CTL);
1194 RSL.clear;
1195
1196 /* activate the logical channel */
1197 f_est_dchan();
1198
1199 /* check that the specified SI5 value is actually sent */
1200 f_sacch_present(si5);
1201
1202 /* release the channel */
1203 RSL.clear;
1204 f_rsl_chan_deact();
1205 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1206}
1207testcase TC_sacch_filling() runs on test_CT {
1208 var ConnHdlr vc_conn;
1209 var ConnHdlrPars pars;
1210 f_init();
1211 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1212 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1213 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1214 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1215 vc_conn.done;
1216 }
1217 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001219}
1220
Harald Welte629cc6b2018-03-11 17:19:05 +01001221/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001222private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1223 /* Set a known default SACCH filling for SI5 */
1224 var octetstring si5 := f_rnd_octstring(19);
1225 var octetstring si5_diff := f_rnd_octstring(19);
1226 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1227
1228 f_l1_tune(L1CTL);
1229 RSL.clear;
1230
1231 log("Activating channel, expecting standard SI5");
1232 /* activate the logical channel */
1233 f_est_dchan();
1234 /* check that the specified SI5 value is actually sent */
1235 f_sacch_present(si5);
1236
1237 /* set channel-specific different SI5 */
1238 log("Setting channel specific SACCH INFO, expecting it");
1239 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1240 /* check that the specified lchan-specific value is now used */
1241 f_sacch_present(si5_diff);
1242
1243 /* deactivate the channel and re-activate it, this should result in default SI5 */
1244 log("De-activating and re-activating channel, expecting standard SI5");
1245 f_rsl_chan_deact();
1246 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1247 /* Verify that the TRX-wide default SACCH filling is present again */
1248 f_sacch_present(si5);
1249
1250 /* release the channel */
1251 RSL.clear;
1252 f_rsl_chan_deact();
1253 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1254}
1255testcase TC_sacch_info_mod() runs on test_CT {
1256 var ConnHdlr vc_conn;
1257 var ConnHdlrPars pars;
1258 f_init();
1259 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1260 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1261 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1262 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1263 vc_conn.done;
1264 }
1265 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001267}
1268
Harald Welte075d84c2018-03-12 13:07:24 +01001269/* Test SACCH scheduling of multiple different SI message types */
1270private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1271 var octetstring si5 := f_rnd_octstring(19);
1272 var octetstring si5bis := f_rnd_octstring(19);
1273 var octetstring si5ter := f_rnd_octstring(19);
1274 var octetstring si6 := f_rnd_octstring(19);
1275
1276 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1277 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1278 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1279 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1280
1281 f_l1_tune(L1CTL);
1282 RSL.clear;
1283
1284 /* activate the logical channel */
1285 f_est_dchan();
1286 L1CTL.clear;
1287
1288 /* check that SACCH actually are received as expected */
1289 f_sacch_present(si5);
1290 f_sacch_present(si5bis);
1291 f_sacch_present(si5ter);
1292 f_sacch_present(si6);
1293
1294 /* release the channel */
1295 f_rsl_chan_deact();
1296 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1297}
1298testcase TC_sacch_multi() runs on test_CT {
1299 var ConnHdlr vc_conn;
1300 var ConnHdlrPars pars;
1301 f_init();
1302 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1303 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1304 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1305 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1306 vc_conn.done;
1307 }
1308 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001310}
1311
Harald Welte55700662018-03-12 13:15:43 +01001312/* Test if SACH information is modified as expected */
1313private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1314 var octetstring si5 := f_rnd_octstring(19);
1315 var octetstring si6 := f_rnd_octstring(19);
1316
1317 /* First, configure both SI5 and SI6 to be transmitted */
1318 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1319 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1320
1321 f_l1_tune(L1CTL);
1322 RSL.clear;
1323
1324 /* activate the logical channel */
1325 f_est_dchan();
1326 L1CTL.clear;
1327
1328 /* check that SACCH actually are received as expected */
1329 f_sacch_present(si5);
1330 f_sacch_present(si6);
1331
1332 /* disable SI6 */
1333 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1334
1335 /* check that SI5 is still transmitted */
1336 f_sacch_present(si5);
1337 /* check if SI6 is now gone */
1338 f_sacch_missing(si6);
1339
1340 /* release the channel */
1341 f_rsl_chan_deact();
1342 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1343}
1344testcase TC_sacch_multi_chg() runs on test_CT {
1345 var ConnHdlr vc_conn;
1346 var ConnHdlrPars pars;
1347 f_init();
1348 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1349 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1350 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1351 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1352 vc_conn.done;
1353 }
1354 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001356}
1357
Harald Weltec8d363c2019-05-19 20:36:48 +02001358/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1359private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1360 var octetstring si5 := f_rnd_octstring(19);
1361 var octetstring si6 := f_rnd_octstring(19);
1362 var octetstring si5_specific := f_rnd_octstring(19);
1363 var octetstring si6_specific := f_rnd_octstring(19);
1364
1365 /* First, configure both SI5 and SI6 to be transmitted */
1366 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1367 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1368
1369 f_l1_tune(L1CTL);
1370 RSL.clear;
1371
1372 /* activate channel with different SACCH filling */
1373 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1374 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1375 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1376 }));
1377 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1378 RSL_IE_Body:{sacch_info := sacch_info})) };
1379 f_est_dchan(more_ies := addl_ies);
1380
1381 /* check that SACCH actually are received as expected */
1382 f_sacch_present(si5_specific);
1383 f_sacch_present(si6_specific);
1384
1385 /* release the channel */
1386 f_rsl_chan_deact();
1387 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1388}
1389testcase TC_sacch_chan_act() runs on test_CT {
1390 var ConnHdlr vc_conn;
1391 var ConnHdlrPars pars;
1392 f_init();
1393
1394 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1395 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1396 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1397 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1398 vc_conn.done;
1399 }
1400 /* TODO: do the above in parallel, rather than sequentially? */
1401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1402}
1403
Harald Welte8b01c792019-05-19 22:51:25 +02001404/* verify that SACCH DL transmission is started only if MS power IE present
1405 * see section 4.1.3 of 3GPP TS 48.058 */
1406private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1407 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001408 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001409
1410 f_l1_tune(L1CTL);
1411 RSL.clear;
1412
1413 /* Step 1: Activate ASYNC HO channel without MS power IE */
1414
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001415 var integer ho_ref := oct2int(f_rnd_octstring(1));
1416 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1417 RSL_IE_Body:{ handover_ref := ho_ref }));
1418 var RSL_IE_List addl_ies := {
1419 ho_ref_ie
1420 };
1421
Harald Welte8b01c792019-05-19 22:51:25 +02001422 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001423 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 +02001424 /* don't perform immediate assignment here, as we're testing non-IA case */
1425 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001426 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001427
1428 /* Verify that no DL SACCH is being received */
1429 f_sacch_missing(?);
1430
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001431 /* Send handover Access Burst and expect SACCH to start */
1432 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1433
1434 f_sacch_present(si5);
1435
Harald Welte8b01c792019-05-19 22:51:25 +02001436 f_rsl_chan_deact();
1437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1438
1439
1440 /* Step 2: Activate ASYNC HO channel with MS power IE */
1441
1442 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001443 addl_ies := {
1444 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001445 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1446 };
1447 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1448 /* don't perform immediate assignment here, as we're testing non-IA case */
1449 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001450 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001451
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001452 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1453 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1454 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001455
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001456 /* Send handover Access Burst and expect SACCH to remain present */
1457 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1458
1459 f_sacch_present(si5);
1460
Harald Welte8b01c792019-05-19 22:51:25 +02001461 f_rsl_chan_deact();
1462 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1463}
1464testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1465 var ConnHdlr vc_conn;
1466 var ConnHdlrPars pars;
1467 f_init();
1468
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001469 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1470 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1471 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001472 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1473 vc_conn.done;
1474 }
1475 /* TODO: do the above in parallel, rather than sequentially? */
1476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1477}
1478
1479/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1480 * see section 4.1.4 of 3GPP TS 48.058 */
1481private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1482 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001483 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1484
Harald Welte8b01c792019-05-19 22:51:25 +02001485 var RSL_IE_List addl_ies;
1486
1487 f_l1_tune(L1CTL);
1488 RSL.clear;
1489
1490 /* Step 1: Activate SYNC HO channel without MS power IE */
1491
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001492 var integer ho_ref := oct2int(f_rnd_octstring(1));
1493 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1494 RSL_IE_Body:{ handover_ref := ho_ref }));
1495 addl_ies := {
1496 ho_ref_ie
1497 };
1498
Harald Welte8b01c792019-05-19 22:51:25 +02001499 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001500 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 +02001501 /* don't perform immediate assignment here, as we're testing non-IA case */
1502 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001503 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001504
1505 /* Verify that no DL SACCH is being received */
1506 f_sacch_missing(?);
1507
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001508 /* Send handover Access Burst and expect SACCH to start */
1509 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1510
1511 f_sacch_present(si5);
1512
Harald Welte8b01c792019-05-19 22:51:25 +02001513 f_rsl_chan_deact();
1514 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1515
1516
1517 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1518
1519 /* Activate channel on BTS side */
1520 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001521 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001522 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1523 };
1524 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1525 /* don't perform immediate assignment here, as we're testing non-IA case */
1526 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001527 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001528
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001529 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1530 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1531 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001532
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001533 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001534 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1535
1536 f_sacch_present(si5);
1537
Harald Welte8b01c792019-05-19 22:51:25 +02001538 f_rsl_chan_deact();
1539 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1540
1541
1542 /* Step 2b: Activate SYNC HO channel with TA IE */
1543
1544 /* Activate channel on BTS side */
1545 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001546 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001547 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1548 };
1549 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1550 /* don't perform immediate assignment here, as we're testing non-IA case */
1551 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001552 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001553
1554 /* Verify that no DL SACCH is being received */
1555 f_sacch_missing(?);
1556
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001557 /* Send handover Access Burst and expect SACCH to start */
1558 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1559
1560 f_sacch_present(si5);
1561
Harald Welte8b01c792019-05-19 22:51:25 +02001562 f_rsl_chan_deact();
1563 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1564
1565
1566 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1567
1568 /* Activate channel on BTS side */
1569 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001570 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001571 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1572 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1573 };
1574 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1575 /* don't perform immediate assignment here, as we're testing non-IA case */
1576 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001577 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001578
1579 /* Verify that DL SACCH is being received */
1580 f_sacch_present(si5);
1581
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001582 /* Send handover Access Burst and expect SACCH to remain present */
1583 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1584
1585 f_sacch_present(si5);
1586
Harald Welte8b01c792019-05-19 22:51:25 +02001587 f_rsl_chan_deact();
1588 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1589}
1590testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1591 var ConnHdlr vc_conn;
1592 var ConnHdlrPars pars;
1593 f_init();
1594
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001595 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1596 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1597 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001598 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1599 vc_conn.done;
1600 }
1601 /* TODO: do the above in parallel, rather than sequentially? */
1602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1603}
Harald Welte629cc6b2018-03-11 17:19:05 +01001604
1605
1606/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001607 * RACH Handling
1608 ***********************************************************************/
1609
Harald Welte8c24c2b2018-02-26 08:31:31 +01001610/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001611private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001612 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001613 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001614 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001615
Harald Welte8c24c2b2018-02-26 08:31:31 +01001616 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001617 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001618 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001619 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001620 if (emerg == true) {
1621 ra := f_rnd_ra_emerg();
1622 } else {
1623 ra := f_rnd_ra_cs();
1624 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001625 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1626 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001628 }
1629 fn_last := fn;
1630
1631 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001632 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001633 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001634 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001635 T.stop;
1636 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001637 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001639 }
1640 [] RSL_CCHAN.receive { repeat; }
1641 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001642 test_failed := true;
1643 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001644 }
1645 }
1646 }
Maxba06feb2019-03-05 10:52:46 +01001647 if (test_failed) {
1648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001649 }
Maxba06feb2019-03-05 10:52:46 +01001650 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001652}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001653
Philipp Maier16ade782020-07-08 21:36:00 +02001654/* Normal variant */
1655testcase TC_rach_content() runs on test_CT {
1656 f_TC_rach_content(emerg := false);
1657}
1658
1659/* Emergency call variant */
1660testcase TC_rach_content_emerg() runs on test_CT {
1661 f_TC_rach_content(emerg := true);
1662}
1663
Harald Welte8c24c2b2018-02-26 08:31:31 +01001664/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1665testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001666 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001667 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001668 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001669 f_l1_tune(L1CTL);
1670
1671 var GsmFrameNumber fn_last := 0;
1672 for (var integer i := 0; i < 1000; i := i+1) {
1673 var OCT1 ra := f_rnd_ra_cs();
1674 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1675 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001677 }
1678 fn_last := fn;
1679 }
1680 var integer rsl_chrqd := 0;
1681 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001682 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001683 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001684 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001686 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001687 repeat;
1688 }
1689 [] RSL_CCHAN.receive { repeat; }
1690 [] T.timeout { }
1691 }
1692 if (rsl_chrqd == 1000) {
1693 setverdict(pass);
1694 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001695 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001696 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001698}
1699
Harald Welte3453ab42019-05-24 21:19:58 +02001700private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1701 var charstring bts_str := "bts " & int2str(bts_nr);
1702 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1703}
1704
1705/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1706private template integer tr_rach_slots_per_interval := (90 .. 130);
1707
1708/* Expect 0 RACH load on an idle BTS that has just started up */
1709testcase TC_rach_load_idle_thresh0() runs on test_CT {
1710 var ASP_RSL_Unitdata rx_ud;
1711
1712 f_init_vty_bsc();
1713 /* send load indications even at 0% load */
1714 f_vty_load_ind_thresh(0);
1715 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1716 f_sleep(2.0);
1717
1718 f_init();
1719
Harald Weltee37f9a52020-10-11 20:45:23 +02001720 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1721 alt {
1722 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1723 [] RSL_CCHAN.receive { repeat }
1724 }
1725
Harald Welte3453ab42019-05-24 21:19:58 +02001726 timer T := 5.0;
1727 T.start;
1728 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001729 [] 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 +02001730 setverdict(pass);
1731 repeat;
1732 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001733 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001734 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1735 repeat;
1736 }
1737 [] RSL_CCHAN.receive {
1738 repeat;
1739 }
1740 [] T.timeout { }
1741 }
1742
1743 f_vty_load_ind_thresh(10);
1744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1745}
1746
1747/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1748testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1749 var ASP_RSL_Unitdata rx_ud;
1750
1751 f_init_vty_bsc();
1752 f_init();
1753
1754 timer T := 5.0;
1755 T.start;
1756 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001757 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001758 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1759 repeat;
1760 }
1761 [] RSL_CCHAN.receive {
1762 repeat;
1763 }
1764 [] T.timeout {
1765 setverdict(pass);
1766 }
1767 }
1768
1769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1770}
1771
1772/* Expect 0 RACH load on an idle BTS that has just started up */
1773testcase TC_rach_load_count() runs on test_CT {
1774 var ASP_RSL_Unitdata rx_ud;
1775 var integer load_access_count := 0;
1776
1777 f_init_vty_bsc();
1778 /* send load indications even at 0% load */
1779 f_vty_load_ind_thresh(0);
1780 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1781 f_sleep(2.0);
1782 f_init();
1783
1784 f_init_l1ctl();
1785 f_sleep(1.0);
1786 f_l1_tune(L1CTL);
1787
Harald Welte52ae1682020-10-11 20:45:55 +02001788 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1789 alt {
1790 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1791 [] RSL_CCHAN.receive { repeat }
1792 }
1793
Harald Welte3453ab42019-05-24 21:19:58 +02001794 var GsmFrameNumber fn_last := 0;
1795 for (var integer i := 0; i < 1000; i := i+1) {
1796 var OCT1 ra := f_rnd_ra_cs();
1797 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1798 if (fn == fn_last) {
1799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1800 }
1801 fn_last := fn;
1802 }
1803
1804 timer T := 5.0;
1805 T.start;
1806 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001807 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001808 -> value rx_ud {
1809 var RSL_IE_Body ie;
1810 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1811 load_access_count := load_access_count + ie.rach_load.access_count;
1812 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1813 setverdict(fail, "Access count cannot be < Busy count");
1814 }
1815 repeat;
1816 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001817 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001818 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1819 repeat;
1820 }
1821 [] RSL_CCHAN.receive {
1822 repeat;
1823 }
1824 [] T.timeout { }
1825 }
1826 if (load_access_count == 1000) {
1827 setverdict(pass);
1828 } else {
1829 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1830 }
1831
1832 f_vty_load_ind_thresh(10);
1833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1834}
1835
Harald Welte54a2a2d2018-02-26 09:14:05 +01001836private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001837 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001838 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001839 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001840 f_sleep(0.5);
1841
1842 /* Transmit RACH request + wait for confirmation */
1843 var OCT1 ra := f_rnd_ra_cs();
1844 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1845
1846 /* Check for expected result */
1847 timer T := 1.5;
1848 T.start;
1849 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001850 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001851 setverdict(pass);
1852 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001853 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001855 }
1856 [] RSL_CCHAN.receive { repeat; }
1857 [not expect_pass] T.timeout {
1858 setverdict(pass);
1859 }
1860 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001862 }
1863 }
1864}
1865
1866/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1867testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001868 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001869 f_init_l1ctl();
1870 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001871 f_sleep(1.0);
1872
1873 /* default max-ta is 63 (full range of GSM timing advance */
1874
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001875 /* We allow early arrival up to 2 symbols */
1876 f_rach_toffs(-1*256, true);
1877 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001878 f_rach_toffs(-10*256, false);
1879
1880 /* 0 / 32 / 63 bits is legal / permitted */
1881 f_rach_toffs(0, true);
1882 f_rach_toffs(32*256, true);
1883 f_rach_toffs(63*256, true);
1884
1885 /* more than 63 bits is not legal / permitted */
1886 f_rach_toffs(64*256, false);
1887 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001889}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001890
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001891private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001892 var GsmFrameNumber fn;
1893 var RSL_Message rm;
1894
1895 f_l1_tune(L1CTL);
1896 RSL.clear;
1897
1898 /* Generate a random Handover Reference */
1899 var integer ho_ref := oct2int(f_rnd_octstring(1));
1900
1901 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1902 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1903 RSL_IE_Body:{ handover_ref := ho_ref }));
1904
1905 /* Activate a channel on the BTS side (no encryption) */
1906 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1907 act_type := t_RSL_IE_ActType_HO_SYNC);
1908
1909 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1910 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001911 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001912
1913 /* Send handover Access Burst */
1914 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1915
1916 /* TODO: test mismatching Handover Reference, and missing IE */
1917
1918 /* Wait for handover detection */
1919 timer T := 3.0;
1920 T.start;
1921 alt {
1922 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1923 log("Handover RACH has been detected: ", rm);
1924 setverdict(pass);
1925 }
1926 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1928 log2str("RSL_CHAN_RQD was not expected: ", rm));
1929 }
1930 [] RSL.receive { repeat; }
1931 [] T.timeout {
1932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1933 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1934 }
1935 }
1936
1937 /* Release the channel */
1938 f_rsl_chan_deact();
1939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1940}
1941
1942/* Test handover RACH detection */
1943testcase TC_ho_rach() runs on test_CT {
1944 var ConnHdlrPars pars;
1945 var ConnHdlr vc_conn;
1946
1947 f_init();
1948
1949 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1950 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1951 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1952 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1953 vc_conn.done;
1954 }
1955
1956 /* TODO: do the above in parallel, rather than sequentially? */
1957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1958}
1959
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001960/* Test sending of the RR Physical Information message on DCCH */
1961private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1962 var PDU_ML3_NW_MS dcch_pdu;
1963 var integer count := 0;
1964 var L1ctlDlMessage dl;
1965 timer T;
1966
1967 f_l1_tune(L1CTL);
1968 RSL.clear;
1969
1970 /* Generate a random Handover Reference */
1971 var integer ho_ref := oct2int(f_rnd_octstring(1));
1972
1973 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1974 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1975 RSL_IE_Body:{ handover_ref := ho_ref }));
1976
1977 /* Activate a channel on the BTS side (no encryption) */
1978 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1979 act_type := t_RSL_IE_ActType_HO_SYNC);
1980
1981 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1982 * waiting for Immediate Assignment and sending of an Access Burst. */
1983 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
1984
1985 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
1986 * context means any L2 frames, not only the RR Physical Information. */
1987 T.start(2.0);
1988 L1CTL.clear;
1989 alt {
1990 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
1991 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
1992 T.stop;
1993 }
1994 [] L1CTL.receive { repeat; }
1995 [] T.timeout { setverdict(pass); }
1996 }
1997
1998 /* Send handover Access Burst */
1999 log("Sending handover Access Burst");
2000 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2001
2002 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2003 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2004 L1CTL.clear;
2005 alt {
2006 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2007 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2008 log("Rx RR Physical Information: ", dcch_pdu);
2009 /* Wait until the count reaches Ny1 */
2010 count := count + 1;
2011 if (count < mp_ho_ny1)
2012 { repeat; }
2013 setverdict(pass);
2014 }
2015 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2016 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2018 }
2019 [] L1CTL.receive { repeat; }
2020 [] T.timeout {
2021 setverdict(fail, "Timeout waiting for RR Physical Information");
2022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2023 }
2024 }
2025
2026 /* Release the channel */
2027 f_rsl_chan_deact();
2028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2029}
2030testcase TC_ho_physical_info() runs on test_CT {
2031 var ConnHdlrPars pars;
2032 var ConnHdlr vc_conn;
2033
2034 f_init();
2035
2036 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2037 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2038 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2039 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2040 vc_conn.done;
2041 }
2042
2043 /* TODO: do the above in parallel, rather than sequentially? */
2044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2045}
2046
Harald Welte93640c62018-02-25 16:59:33 +01002047/***********************************************************************
2048 * Measurement Processing / Reporting
2049 ***********************************************************************/
2050
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002051private template (value) LapdmAddressField
2052ts_LapdmAddr(template (value) LapdmSapi sapi,
2053 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002054 spare := '0'B,
2055 lpd := 0,
2056 sapi := sapi,
2057 c_r := c_r,
2058 ea := true
2059}
2060
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002061private template (value) LapdmFrameAB
2062ts_LAPDm_AB(template (value) LapdmSapi sapi,
2063 template (value) GsmRrL3Message l3,
2064 template (value) boolean c_r := false,
2065 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002066 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002067 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002068 len := 0, /* overwritten */
2069 m := false,
2070 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002071 payload := enc_GsmRrL3Message(valueof(l3)),
2072 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002073}
2074
2075/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002076private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002077 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002078 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002079
Harald Weltef8df4cb2018-03-10 15:15:08 +01002080 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002081 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002082
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002083 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002084 g_pars.l1_pars.meas_ul.full.rxlev,
2085 g_pars.l1_pars.meas_ul.sub.rxlev,
2086 g_pars.l1_pars.meas_ul.full.rxqual,
2087 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002088 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002089
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002090 var template (value) SacchL1Header l1h := ts_SacchL1Header(
2091 g_pars.l1_pars.ms_power_level, false,
2092 g_pars.l1_pars.ms_actual_ta);
2093
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002094 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2095 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002096
2097 log("Sending Measurement Report: ", l1h, l2);
2098 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002099 repeat;
2100 }
2101}
2102
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002103/* handle incoming downlink SACCH, decode the L1 header into the given record */
2104private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2105 boolean do_apply := true)
2106runs on ConnHdlr
2107{
2108 var L1ctlDlMessage l1_dl;
2109
2110 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2111 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2112 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2113 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2114
2115 if (do_apply) {
2116 /* Update TA and MS power to follow what BTS requests */
2117 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2118 }
2119 }
2120}
2121
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002122private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002123 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002124 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002125 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2126 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002127 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2128 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002129 repeat;
2130 }
2131}
2132
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002133private altstep as_l1_tch_loop() runs on ConnHdlr {
2134 var L1ctlDlMessage l1_dl;
2135 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2136 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002137
2138 /* occasionaly inject FACCH frames into the uplink */
2139 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2140 var octetstring pl := '010301'O;
2141 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2142 f_pad_oct(pl, 23, '2B'O)));
2143 } else {
2144 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2145 l1_dl.payload.traffic_ind.data));
2146 }
2147
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002148 repeat;
2149 }
2150}
2151
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002152private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002153 uint6_t rxlev,
2154 uint3_t rxqual
2155}
2156
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002157private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002158 MeasElem full,
2159 MeasElem sub
2160}
2161
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002162private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002163 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002164 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002165 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002166 MeasElemFS meas_ul,
2167 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002168 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002169 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002170 uint8_t ms_actual_ta,
2171 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002172}
2173
2174/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2175private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2176 return 63 + (toffs256s/256);
2177}
2178
Harald Welted5684392018-03-10 18:22:04 +01002179private function f_max(integer a, integer b) return integer {
2180 if (a > b) {
2181 return a;
2182 } else {
2183 return b;
2184 }
2185}
2186
2187private function f_min(integer a, integer b) return integer {
2188 if (a < b) {
2189 return a;
2190 } else {
2191 return b;
2192 }
2193}
2194
2195/* compute negative tolerance val-tolerance, ensure >= min */
2196private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2197 val := val - tolerance;
2198 return f_max(val, min);
2199}
2200
2201/* compute positive tolerance val+tolerance, ensure <= max */
2202private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2203 val := val + tolerance;
2204 return f_min(val, max);
2205}
2206
2207/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2208private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2209return template integer {
2210 var template integer ret;
2211 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2212 return ret;
2213}
2214
2215
Harald Welte70767382018-02-21 12:16:40 +01002216/* build a template for matching measurement results against */
2217private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2218 var ConnL1Pars l1p := g_pars.l1_pars;
2219 var template RSL_IE_UplinkMeas ul_meas := {
2220 len := 3,
2221 rfu := '0'B,
2222 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002223 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002224 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002225 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002226 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002227 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2228 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002229 supp_meas_info := omit
2230 };
Harald Welte685d5982018-02-27 20:42:05 +01002231 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002232 ul_meas.len := (3+8);
2233 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002234 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002235 toa256_min := ?,
2236 toa256_max := ?,
2237 toa256_std_dev := ?
2238 }
Harald Welte685d5982018-02-27 20:42:05 +01002239 }
Harald Welte70767382018-02-21 12:16:40 +01002240 var template RSL_IE_BS_Power bs_power := {
2241 reserved := 0,
2242 epc := false,
2243 fpc := false,
2244 power_level := l1p.bs_power_level
2245 };
2246 var template RSL_IE_L1Info l1_info := {
2247 ms_power_lvl := l1p.ms_power_level,
2248 fpc := false,
2249 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002250 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002251 };
2252 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002253 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002254 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2255 ?, t_toffs);
2256}
2257
Philipp Maierdd841d32019-12-17 14:44:54 +01002258/* build a template for matching measurement results that do not contain any
2259 * MS related measurement (l1_info, l3_info and ms timing offset). */
2260private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2261 var ConnL1Pars l1p := g_pars.l1_pars;
2262 var template RSL_IE_UplinkMeas ul_meas := {
2263 len := 3,
2264 rfu := '0'B,
2265 dtx_d := l1p.dtx_enabled,
2266 rxlev_f_u := ?,
2267 reserved1 := '00'B,
2268 rxlev_s_u := ?,
2269 reserved2 := '00'B,
2270 rxq_f_u := ?,
2271 rxq_s_u := ?,
2272 supp_meas_info := omit
2273 };
2274 if (l1p.toa256_enabled) {
2275 ul_meas.len := (3+8);
2276 ul_meas.supp_meas_info := {
2277 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2278 toa256_min := ?,
2279 toa256_max := ?,
2280 toa256_std_dev := ?
2281 }
2282 }
2283 var template RSL_IE_BS_Power bs_power := {
2284 reserved := 0,
2285 epc := false,
2286 fpc := false,
2287 power_level := l1p.bs_power_level
2288 };
2289
2290 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2291}
2292
Harald Welte70767382018-02-21 12:16:40 +01002293/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002294private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002295 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002296 var boolean chan_est := false;
2297
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002298 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002299
2300 /* Receive osmocom specific measurement reports. This is the normal
2301 * case. Here we verify that the measurement reports we sent are
2302 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002303 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2304 /* increment counter of next to-be-expected meas rep */
2305 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2306 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002307 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002308
2309 /* The following two cases may only happen in the beginning
2310 * of the channel establishment phase. Once we have received
2311 * the "our" measurement report the first time, the channel
2312 * is established and empty or hardcoded TRXCON reports must
2313 * not occur anymore. */
2314 chan_est := true;
2315
2316 repeat;
2317 }
2318
2319 /* When the BTS has established the channel, the MS might need slightly
2320 * more time to establish the channel and actually start sending. The
2321 * result is then a measurement report that just lacks the measurement
2322 * information of the MS. This is normal and we tolerate this behavior. */
2323 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2324 /* increment counter of next to-be-expected meas rep */
2325 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2326 /* Re-start the timer expecting the next MEAS RES */
2327 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002328 repeat;
2329 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002330
2331 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2332 * measurements if the TTCN3 side does not supply measurement input in
2333 * time. In those cases TRXCON will either use a cached measurement
2334 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2335 * report the templates above will not match. We tolerate this
2336 * behavior, but only once. */
2337 [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 +01002338 /* increment counter of next to-be-expected meas rep */
2339 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2340 if (g_first_meas_res) {
2341 g_first_meas_res := false;
2342 repeat;
2343 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002345 }
Harald Welte70767382018-02-21 12:16:40 +01002346 }
2347 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002349 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002350 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002352 }
2353}
2354
Harald Weltee613f962018-04-18 22:38:16 +02002355private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2356 select (rsl_alg_id) {
2357 case (RSL_ALG_ID_A5_0) { return 0; }
2358 case (RSL_ALG_ID_A5_1) { return 1; }
2359 case (RSL_ALG_ID_A5_2) { return 2; }
2360 case (RSL_ALG_ID_A5_3) { return 3; }
2361 case (RSL_ALG_ID_A5_4) { return 4; }
2362 case (RSL_ALG_ID_A5_5) { return 5; }
2363 case (RSL_ALG_ID_A5_6) { return 6; }
2364 case (RSL_ALG_ID_A5_7) { return 7; }
2365 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2367 /* Make compiler happy by calling mtc.stop here. It is already
2368 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002369 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002370 }
2371 }
2372}
2373
2374private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2375 select (rsl_alg_id) {
2376 case (RSL_ALG_ID_A5_1) { return '000'B; }
2377 case (RSL_ALG_ID_A5_2) { return '001'B; }
2378 case (RSL_ALG_ID_A5_3) { return '010'B; }
2379 case (RSL_ALG_ID_A5_4) { return '011'B; }
2380 case (RSL_ALG_ID_A5_5) { return '100'B; }
2381 case (RSL_ALG_ID_A5_6) { return '101'B; }
2382 case (RSL_ALG_ID_A5_7) { return '110'B; }
2383 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2385 /* Make compiler happy by calling mtc.stop here. It is already
2386 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002387 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002388 }
2389 }
2390}
2391
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002392/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2393private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2394 var GsmFrameNumber fn;
2395 timer T := 8.0;
2396
2397 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2398 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2399
2400 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2401 /* Send the actual RACH */
2402 fn := f_L1CTL_RACH(L1CTL, ra);
2403
2404 T.start;
2405 alt {
2406 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2407 [] T.timeout {
2408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2409 }
2410 }
2411 T.stop
2412 return fn;
2413}
Harald Weltee613f962018-04-18 22:38:16 +02002414
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002415/* Tune to a dedicated channel: L1CTL only */
2416private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002417 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002418 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002419 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002420 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002421 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002422 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002423 pars.fhp.maio_hsn.hsn,
2424 pars.fhp.maio_hsn.maio,
2425 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002426 }
2427}
2428
Harald Welte70767382018-02-21 12:16:40 +01002429/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002430private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002431 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002432
2433 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002434 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002435
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002436 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002437 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002438 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002439 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002440 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2441 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002442 }
2443
Harald Welte70767382018-02-21 12:16:40 +01002444 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002445 f_l1ctl_est_dchan(L1CTL, g_pars);
2446
Harald Weltee613f962018-04-18 22:38:16 +02002447 /* enable encryption, if requested */
2448 if (encr_enable) {
2449 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2450 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2451 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002452
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002453 /* Send TCH Mode Request to the L1 if needed */
2454 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2455 var L1ctlTchMode tch_mode;
2456
2457 select (g_pars.chan_mode.coding_alg_rate) {
2458 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2459 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2460 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2461 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2462 case else {
2463 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2464 " is not supported by the L1, falling back to signalling");
2465 tch_mode := L1CTL_CHAN_MODE_SIGN;
2466 }
2467 }
2468
2469 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2470 }
2471
Harald Weltefa45e9e2018-03-10 18:59:03 +01002472 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002473}
2474
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002475/* Initialize and start the RTP emulation component for a ConnHdlr */
2476friend function f_rtpem_activate(inout octetstring payload,
2477 RtpemConfig cfg := c_RtpemDefaultCfg,
2478 RtpemMode mode := RTPEM_MODE_BIDIR)
2479runs on ConnHdlr {
2480 /* Step 0: initialize, connect and start the emulation component */
2481 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2482 map(vc_RTPEM:RTP, system:RTP);
2483 map(vc_RTPEM:RTCP, system:RTCP);
2484 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2485 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2486 vc_RTPEM.start(RTP_Emulation.f_main());
2487
2488 /* Step 1: configure the RTP parameters */
2489 var integer payload_len := 0;
2490 var octetstring hdr := ''O;
2491
2492 select (g_pars.chan_mode) {
2493 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2494 { payload_len := 33; hdr := 'D0'O; }
2495 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2496 { payload_len := 15; hdr := '00'O; }
2497 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2498 { payload_len := 31; hdr := 'C0'O; }
2499 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2500 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2502 }
2503 }
2504
2505 /* Pad the payload to conform the expected length */
2506 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2507 cfg.tx_fixed_payload := payload;
2508 f_rtpem_configure(RTPEM_CTRL, cfg);
2509
2510 /* Step 2: bind the RTP emulation to the configured address */
2511 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2512 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2513
2514 /* Step 3: send CRCX with the configured address/port to the IUT */
2515 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2516 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2517 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2518 "IPA CRCX ACK");
2519
2520 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2521 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2522 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2523 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2524
2525 /* Step 5: set the given RTP emulation mode */
2526 f_rtpem_mode(RTPEM_CTRL, mode);
2527}
2528
Harald Welte70767382018-02-21 12:16:40 +01002529/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002530private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002531 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002532 RSL.clear;
2533
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002534 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002535 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002536 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002537 }
Harald Welte70767382018-02-21 12:16:40 +01002538
2539 f_est_dchan();
2540
2541 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2542 * RSL measurement reports on Abis side */
2543 timer T := 8.0;
2544 T.start;
2545 alt {
2546 [] as_l1_sacch();
2547 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002548 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002549 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002550 [] L1CTL.receive { repeat; }
2551 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002552 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002553 * of any earlier errors, so if we reach this timeout, we're good */
2554 setverdict(pass);
2555 }
2556 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002558 }
2559 }
2560 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002561 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002562}
Harald Welte0472ab42018-03-12 15:02:26 +01002563
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002564/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2565private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002566 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002567 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2568 timer Tup := 10.0;
2569 Tup.start;
2570 alt {
2571 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2572 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2573 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002574
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002575 if (rx_lvl != max_rx_lvl) {
2576 repeat;
2577 }
2578 Tup.stop;
2579 }
2580 [] L1CTL.receive { repeat; }
2581 [] Tup.timeout {
2582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2583 log2str("Didn't reach full power ", max_rx_lvl));
2584 }
2585 }
2586 return max_rx_lvl;
2587}
2588
2589/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2590private function f_verify_ramp_up() runs on ConnHdlr {
2591 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002592 var integer initial_rx_lvl := -1;
2593 var integer last_rx_lvl := -1;
2594 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2595
2596 timer T := 2.0;
2597 alt {
2598 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2599 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2600 log("Received rx_level=", rx_lvl);
2601 if (initial_rx_lvl == -1) {
2602 initial_rx_lvl := rx_lvl;
2603 last_rx_lvl := rx_lvl;
2604
2605 /* Expect a somehow low value during first received messages */
2606 if (initial_rx_lvl >= max_rx_lvl / 2) {
2607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2608 log2str("Detected high initial tx power during ramp up: ",
2609 initial_rx_lvl , ", full power is", max_rx_lvl));
2610 }
2611 }
2612
2613 /* received Rx level bigger than maximum allowed power by CN */
2614 if (rx_lvl > max_rx_lvl) {
2615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2616 log2str("Detected Tx power higher than full power: ",
2617 rx_lvl , " > ", max_rx_lvl));
2618 }
2619
2620 /* Make sure it never decreases, since we are rumping up */
2621 if (last_rx_lvl > rx_lvl) {
2622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2623 log2str("Detected Tx power decrease during ramp up: ",
2624 last_rx_lvl , " -> ", rx_lvl));
2625 }
2626
2627 if (rx_lvl == max_rx_lvl and not T.running) {
2628 /* We reached the maximum power, start timer and receive
2629 /* a few more to make sure we don't surpass it */
2630 log("Reached full power, wating a bit more until success");
2631 T.start;
2632 }
2633
2634 last_rx_lvl := rx_lvl;
2635 repeat;
2636 }
2637 [] L1CTL.receive { repeat; }
2638 [] T.timeout { }
2639 }
2640
2641 /* We didn't increase tx power during ramp up */
2642 if (initial_rx_lvl < last_rx_lvl) {
2643 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2644 } else {
2645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2646 log2str("No Tx power increase during whole ramp up: ",
2647 initial_rx_lvl , " -> ", last_rx_lvl));
2648 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002649}
2650
2651/* verify BTS ramps power down to rx_level 0 */
2652private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2653 var L1ctlDlMessage l1_dl;
2654 var integer last_rx_lvl := max_rx_lvl;
2655
2656 timer Tdown := 5.0;
2657 Tdown.start;
2658 alt {
2659 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2660 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2661 log("Received rx_level=", rx_lvl);
2662
2663 /* received Rx level bigger than maximum allowed power by CN */
2664 if (rx_lvl > max_rx_lvl) {
2665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2666 log2str("Detected Tx power higher than full power: ",
2667 rx_lvl , " > ", max_rx_lvl));
2668 }
2669
2670 /* Make sure it never increases, since we are rumping down */
2671 if (last_rx_lvl < rx_lvl) {
2672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2673 log2str("Detected Tx power increase during ramp up: ",
2674 last_rx_lvl , " -> ", rx_lvl));
2675 }
2676
2677 last_rx_lvl := rx_lvl;
2678 if (last_rx_lvl != 0) {
2679 repeat;
2680 }
2681 /* we reached power level 0, we are done */
2682 Tdown.stop;
2683 }
2684 [] L1CTL.receive { repeat; }
2685 [] Tdown.timeout { }
2686 }
2687
2688 /* We didn't increase tx power during ramp down */
2689 if (max_rx_lvl > last_rx_lvl) {
2690 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2691 } else {
2692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2693 log2str("No Tx power decrease during whole ramp down: ",
2694 max_rx_lvl , " -> ", last_rx_lvl));
2695 }
2696}
2697
2698/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002699private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002700 f_l1_tune(L1CTL);
2701 RSL.clear;
2702
2703 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002704
2705 setverdict(pass);
2706}
2707testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2708 var ConnHdlr vc_conn;
2709 var ConnHdlrPars pars;
2710 f_init();
2711 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2712 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2713 pcu_comp := false, trxc_comp := true);
2714 vc_conn.done;
2715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2716}
2717
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002718/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002719private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002720 f_connhdlr_init_vty_bsc();
2721
2722 f_l1_tune(L1CTL);
2723 RSL.clear;
2724
2725 /* Wait until BTS is started and at full power */
2726 var integer max_rx_lvl := f_wait_ramp_up();
2727 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2728
2729 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2730 f_verify_ramp_down(max_rx_lvl);
2731
2732 setverdict(pass);
2733}
2734testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2735 var ConnHdlr vc_conn;
2736 var ConnHdlrPars pars;
2737 f_init();
2738 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2739 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2740 pcu_comp := false, trxc_comp := true);
2741 vc_conn.done;
2742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2743}
2744
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002745/* Verify Tx power:
2746 * + ramping down during ADM state UNLOCKED->LOCKED
2747 * + ramping up during ADM state LOCKED->UNLOCKED
2748 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002749private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002750 var L1ctlDlMessage l1_dl;
2751 var integer last_rx_lvl;
2752
2753 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, ", changing ADM state to LOCKED");
2761
2762 log("ADM STATE UNLOCKED->LOCKED");
2763 f_vty_enter_cfg_trx(BSCVTY);
2764 f_vty_transceive(BSCVTY, "rf_locked 1");
2765 last_rx_lvl := max_rx_lvl;
2766 f_verify_ramp_down(max_rx_lvl);
2767
2768 /* Let some time after we received 0dBm, then check we don't receive BCCH
2769 * anymore because scheduler has stopped after ramping down */
2770 f_sleep(2.0);
2771 L1CTL.clear;
2772 timer Tlocked := 2.0;
2773 Tlocked.start;
2774 alt {
2775 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2777 log2str("Received data_ind during rf_locked: ", l1_dl));
2778 }
2779 [] L1CTL.receive { repeat; }
2780 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2781 }
2782
2783 log("ADM STATE LOCKED->UNLOCKED");
2784 f_vty_transceive(BSCVTY, "rf_locked 0");
2785 f_verify_ramp_up();
2786 setverdict(pass);
2787}
2788testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2789 var ConnHdlr vc_conn;
2790 var ConnHdlrPars pars;
2791 f_init();
2792 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2793 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2794 pcu_comp := false, trxc_comp := true);
2795 vc_conn.done;
2796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2797}
2798
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002799private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002800 timer T := 8.0;
2801 T.start;
2802 var RSL_Message rsl;
2803 alt {
2804 [] as_l1_sacch();
2805 [] L1CTL.receive { repeat; }
2806 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2807 if (rsl.ies[3].body.bs_power.power_level == level) {
2808 setverdict(pass)
2809 } else {
2810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2811 }
2812 }
2813 [] T.timeout {
2814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2815 }
2816 }
2817}
2818
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002819/* See if the RSL MEASurement RESult contains expeced BS power level
2820 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002821private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002822 f_l1_tune(L1CTL);
2823 RSL.clear;
2824
2825 if (mp_bts_trxc_port != -1) {
2826 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2827 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2828 }
2829
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002830 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002831 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2832 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2833
2834 f_est_dchan(more_ies :={valueof(pwr)});
2835
2836 f_check_meas_bs_power_level(pwr_var);
2837
2838 f_rsl_chan_deact();
2839 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2840}
2841
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002842/* See if the RSL MEASurement RESult contains expeced BS power level
2843 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002844private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002845 f_l1_tune(L1CTL);
2846 RSL.clear;
2847
2848 if (mp_bts_trxc_port != -1) {
2849 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2850 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2851 }
2852
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002853 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002854 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2855
2856 f_est_dchan();
2857
2858 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2859
2860 f_check_meas_bs_power_level(pwr_var);
2861
2862 f_rsl_chan_deact();
2863 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2864}
2865
2866testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2867 var ConnHdlr vc_conn;
2868 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002869
Eric Wildae8f2622019-06-18 17:05:11 +02002870 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002871
2872 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2873 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2874 pcu_comp := false, trxc_comp := true);
2875 vc_conn.done;
2876
Eric Wildae8f2622019-06-18 17:05:11 +02002877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2878}
2879
2880testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2881 var ConnHdlr vc_conn;
2882 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002883
Eric Wildae8f2622019-06-18 17:05:11 +02002884 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002885
2886 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2887 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2888 pcu_comp := false, trxc_comp := true);
2889 vc_conn.done;
2890
Eric Wildae8f2622019-06-18 17:05:11 +02002891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2892}
2893
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002894/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2895 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2896 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002897private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002898 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002899 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002900
2901 f_trxc_fake_rssi(rxlev2dbm(10));
2902 f_l1_tune(L1CTL);
2903 RSL.clear;
2904
2905 var RSL_IE_List addl_ies;
2906 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2907
2908 addl_ies := {
2909 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2910 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2911 };
2912
2913 /* establish with power parameters */
2914 f_est_dchan(more_ies := addl_ies);
2915
2916 /* set a high value to ensure L1 power control level increases */
2917 f_trxc_fake_rssi(rxlev2dbm(20));
2918
2919 timer T2 := 6.0;
2920 T2.start;
2921 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002922 [] as_l1_sacch_l1h(l1h) {
2923 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002924 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002925 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002926 T2.stop;
2927 }
2928 [] L1CTL.receive { repeat; }
2929 [] T2.timeout {
2930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2931 "Power Level in L1 header has not increased sufficiently");
2932 }
2933 }
2934
2935 /* set a low value to ensure L1 power control level decreases */
2936 f_trxc_fake_rssi(rxlev2dbm(0));
2937
2938 timer T4 := 6.0;
2939 T4.start;
2940 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002941 [] as_l1_sacch_l1h(l1h) {
2942 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002943 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002944 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002945 T4.stop;
2946 setverdict(pass, "Power level in L1 decreased/increased as expected");
2947 }
2948 [] L1CTL.receive { repeat; }
2949 [] T4.timeout {
2950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2951 "Power Level in L1 header has not decreased sufficiently");
2952 }
2953 }
2954
2955 f_rsl_chan_deact();
2956 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2957
2958}
2959
2960/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002961private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002962 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002963 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002964
2965 /* set a low value to ensure power increases */
2966 f_trxc_fake_rssi(rxlev2dbm(10));
2967 f_l1_tune(L1CTL);
2968 RSL.clear;
2969
2970 var RSL_IE_List addl_ies;
2971 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2972
2973 addl_ies := {
2974 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2975 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2976 };
2977
2978 /* establish with power parameters */
2979 f_est_dchan(more_ies := addl_ies);
2980
2981 timer T1 := 10.0;
2982 T1.start;
2983 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002985 [] L1CTL.receive { repeat; }
2986 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002987 if (not isbound(l1h)) {
2988 setverdict(fail, "No SACCH blocks were received");
2989 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002990 setverdict(fail, "Power level in L1 header should not have changed");
2991 }
2992 }
2993 }
2994
2995 f_rsl_chan_deact();
2996 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2997
2998}
2999
3000/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003001private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003002 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003003 var uint5_t pwr_var := 15;
3004 var uint5_t pwr_max_var := f_get_max_power_from_band();
3005
3006 /* set a low value to ensure power increases */
3007 f_trxc_fake_rssi(rxlev2dbm(10));
3008 f_l1_tune(L1CTL);
3009 RSL.clear;
3010
3011 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3012 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3013
3014 /* establish with fixed power level */
3015 f_est_dchan(more_ies :={valueof(pwr)});
3016
3017 /* check our initial power level */
3018 f_wait_for_l1_power_level(pwr_var);
3019
3020 /* update power param to enable power loop
3021 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3022 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3023
3024 /* wait, then check that our power level was reduced */
3025 timer T1 := 10.0;
3026 T1.start;
3027 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003028 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003029 [] L1CTL.receive { repeat; }
3030 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003031 if (not isbound(l1h)) {
3032 setverdict(fail, "No SACCH blocks were received");
3033 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003034 setverdict(pass, "Power level in L1 header reduced as expected");
3035 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003036 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3037 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003038 }
3039 }
3040 }
3041
3042 f_rsl_chan_deact();
3043 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3044
3045}
3046
3047/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003048private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003049 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003050
3051 /* set a high value to ensure power decreases */
3052 f_trxc_fake_rssi(rxlev2dbm(50));
3053 f_l1_tune(L1CTL);
3054 RSL.clear;
3055
3056 var uint5_t pwr_var := 5;
3057 var uint5_t pwr_target_val := 15;
3058
3059 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3060 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3061
3062 /* establish with fixed power level */
3063 f_est_dchan(more_ies :={valueof(pwr)});
3064
3065 /* check our initial power level */
3066 f_wait_for_l1_power_level(pwr_var);
3067
3068 /* update power param to enable power loop
3069 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003070 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003071
3072 /* wait, then check that our power level was increased */
3073 timer T1 := 10.0;
3074 T1.start;
3075 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003076 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003077 [] L1CTL.receive { repeat; }
3078 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003079 if (not isbound(l1h)) {
3080 setverdict(fail, "No SACCH blocks were received");
3081 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3082 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003083 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003084 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003085 }
3086 }
3087 }
3088
3089 f_rsl_chan_deact();
3090 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3091
3092}
3093
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003094/* See if the power level remains constant when MS Power Parameters IE
3095 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003096private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003097 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003098
3099 /* set a high value to ensure power decreases */
3100 f_trxc_fake_rssi(rxlev2dbm(50));
3101 f_l1_tune(L1CTL);
3102 RSL.clear;
3103
3104 var uint5_t pwr_var := 5;
3105
3106 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3107 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3108
3109 /* establish with fixed power level */
3110 f_est_dchan(more_ies :={valueof(pwr)});
3111
3112 /* check our initial power level */
3113 f_wait_for_l1_power_level(pwr_var);
3114
3115 /* wait, then check that our power level did not change */
3116 timer T1 := 10.0;
3117 T1.start;
3118 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003119 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3120 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3122 "BS power control should not be active unless we receive a power parameters IE!");
3123 }
3124 repeat;
3125 }
3126 [] L1CTL.receive { repeat; }
3127 [] T1.timeout { setverdict(pass); }
3128 }
3129
3130 f_rsl_chan_deact();
3131 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3132
3133}
3134
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003135/* See if the power level remains constant when MS Power Parameters IE
3136 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003137private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003138 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003139
3140 /* set a high value to ensure power decreases */
3141 f_trxc_fake_rssi(rxlev2dbm(50));
3142 f_l1_tune(L1CTL);
3143 RSL.clear;
3144
3145 var uint5_t pwr_var := 5;
3146
3147 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3148 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3149
3150 /* establish with fixed power level */
3151 f_est_dchan(more_ies :={valueof(pwr)});
3152
3153 /* check our initial power level */
3154 f_wait_for_l1_power_level(pwr_var);
3155
3156 /* pwr control without power params IE, should NOT activate MS power control*/
3157 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3158
3159 /* wait, then check that our power level did not change */
3160 timer T1 := 10.0;
3161 T1.start;
3162 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003163 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3164 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3166 "BS power control should not be active unless we receive a power parameters IE!");
3167 }
3168 repeat;
3169 }
3170 [] L1CTL.receive { repeat; }
3171 [] T1.timeout { setverdict(pass); }
3172 }
3173
3174 f_rsl_chan_deact();
3175 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3176
3177}
3178
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003179private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003180 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003181 timer T0 := 10.0;
3182 T0.start;
3183 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003184 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3185 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3187 "Power level in L1 header != signaled (RSL) power level.");
3188 }
3189 }
3190 [] L1CTL.receive { repeat; }
3191 [] T0.timeout {
3192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3193 "Timeout waiting for initial power level");
3194 }
3195 }
3196 T0.stop;
3197}
3198
3199private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3200 var IntegerRecord min_dbm_level;
3201 var IntegerRecord max_dbm_level;
3202 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3203
3204 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3205 if (min_dbm_level[i] == level) {
3206 return true;
3207 }
3208 }
3209 return false;
3210}
3211
3212private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3213 var IntegerRecord min_dbm_level;
3214 var IntegerRecord max_dbm_level;
3215 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3216
3217 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3218 if (max_dbm_level[i] == level) {
3219 return true;
3220 }
3221 }
3222 return false;
3223}
3224
3225private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3226 var IntegerRecord min_dbm_level;
3227 var IntegerRecord max_dbm_level;
3228 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3229 return max_dbm_level[0];
3230}
3231
3232type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003233private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003234private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3235 // 45.005 4.1.1
3236 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3237 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3238 2, 1, 0};
3239 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3240 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3241 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3242 var IntegerRecord rv;
3243
3244 select(band){
3245 case (BtsBand_allGSM){
3246 rv := gsm_power;
3247 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3248 max_dbm_level := {2, 1, 0};
3249 }
3250 case("DCS1800"){
3251 rv := dcs_power;
3252 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3253 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3254 }
3255 case("PCS1900"){
3256 rv := pcs_power;
3257 min_dbm_level := {15};
3258 max_dbm_level := {30};
3259 }
Harald Welte194b6912020-10-11 21:01:55 +02003260 case else {
3261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3262 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003263 }
3264
3265 return rv;
3266}
3267
3268private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003269 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 +02003270}
3271
3272testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3273 var ConnHdlr vc_conn;
3274 var ConnHdlrPars pars;
3275 f_init();
3276 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3277 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3278 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3279 pars.bts0_band := f_vty_get_bts0_band();
3280 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3281 vc_conn.done;
3282 }
3283 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3285}
3286
3287testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3288 var ConnHdlr vc_conn;
3289 var ConnHdlrPars pars;
3290 f_init();
3291 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3292 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3293 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3294 pars.bts0_band := f_vty_get_bts0_band();
3295 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3296 vc_conn.done;
3297 }
3298 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3300}
3301
3302testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3303 var ConnHdlr vc_conn;
3304 var ConnHdlrPars pars;
3305 f_init();
3306 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3307 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3308 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3309 pars.bts0_band := f_vty_get_bts0_band();
3310 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3311 vc_conn.done;
3312 }
3313 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3315}
3316
3317testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3318 var ConnHdlr vc_conn;
3319 var ConnHdlrPars pars;
3320 f_init();
3321 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3322 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3323 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3324 pars.bts0_band := f_vty_get_bts0_band();
3325 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3326 vc_conn.done;
3327 }
3328 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3330}
3331
Eric Wild280ccb82019-06-17 11:11:52 +02003332testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3333 var ConnHdlr vc_conn;
3334 var ConnHdlrPars pars;
3335 f_init();
3336 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3337 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3338 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3339 pars.bts0_band := f_vty_get_bts0_band();
3340 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3341 vc_conn.done;
3342 }
3343 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3345}
3346
Eric Wild095024b2019-06-17 15:08:57 +02003347testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3348 var ConnHdlr vc_conn;
3349 var ConnHdlrPars pars;
3350 f_init();
3351 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3352 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3353 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3354 pars.bts0_band := f_vty_get_bts0_band();
3355 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3356 vc_conn.done;
3357 }
3358 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3360}
3361
Philipp Maier149c3922020-10-22 17:29:36 +02003362function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003363 var template RSL_IE_ChannelMode ch_mode;
3364 var ConnHdlr vc_conn;
3365 var ConnHdlrPars pars;
3366 f_init();
3367 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3368 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3369 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003370 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003371 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3372 pcu_comp := false, trxc_comp := true);
3373 vc_conn.done;
3374 }
3375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3376}
Philipp Maier149c3922020-10-22 17:29:36 +02003377
3378testcase TC_meas_res_speech_tchf() runs on test_CT {
3379 f_TC_meas_res_speech_tchf(false);
3380}
3381
3382testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3383 f_TC_meas_res_speech_tchf(true);
3384}
3385
3386function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003387 var template RSL_IE_ChannelMode ch_mode;
3388 var ConnHdlr vc_conn;
3389 var ConnHdlrPars pars;
3390 f_init();
3391 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3392 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3393 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003394 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003395 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3396 pcu_comp := false, trxc_comp := true);
3397 vc_conn.done;
3398 }
3399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3400}
Philipp Maier149c3922020-10-22 17:29:36 +02003401
3402testcase TC_meas_res_speech_tchh() runs on test_CT {
3403 f_TC_meas_res_speech_tchh(false)
3404}
3405
3406testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3407 f_TC_meas_res_speech_tchh(true)
3408}
3409
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003410testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3411 var template RSL_IE_ChannelMode ch_mode;
3412 var ConnHdlr vc_conn;
3413 var ConnHdlrPars pars;
3414 f_init();
3415 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3416 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3417 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3418 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3419 pars.l1_pars.toa256_enabled := true;
3420 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3421 pcu_comp := false, trxc_comp := true);
3422 vc_conn.done;
3423 }
3424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3425}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003426
Harald Welte70767382018-02-21 12:16:40 +01003427testcase TC_meas_res_sign_tchf() runs on test_CT {
3428 var ConnHdlr vc_conn;
3429 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003430 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003431 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003432 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003433 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003434 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3435 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003436 vc_conn.done;
3437 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003439}
3440testcase TC_meas_res_sign_tchh() runs on test_CT {
3441 var ConnHdlr vc_conn;
3442 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003443 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003444 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003445 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003446 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003447 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3448 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003449 vc_conn.done;
3450 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003452}
3453testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3454 var ConnHdlr vc_conn;
3455 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003456 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003457 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003458 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3459 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003460 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3461 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003462 vc_conn.done;
3463 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003465}
3466testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3467 var ConnHdlr vc_conn;
3468 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003469 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003470 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003471 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3472 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003473 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3474 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003475 vc_conn.done;
3476 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003478}
Harald Welte685d5982018-02-27 20:42:05 +01003479testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3480 var ConnHdlr vc_conn;
3481 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003482 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003483 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3484 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003485 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003486 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003487 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3488 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003489 vc_conn.done;
3490 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003492}
3493
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003494/* Make sure that we always get RSL MEASurement RESult messages regardless
3495 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3496private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3497 timer Texec := 8.0;
3498 timer Timpf := 2.0;
3499 timer Tmr;
3500
3501 f_l1_tune(L1CTL);
3502 RSL.clear;
3503
3504 f_est_dchan();
3505 L1CTL.clear;
3506
3507 /* Establish the main SAPI=0 link on DCCH first */
3508 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3509
3510 /* Give more time for the first RSL MEASurement RESult */
3511 Tmr.start(0.480 * 2.0);
3512 Texec.start; /* EXECution timer */
3513 Timpf.start; /* IMPFung timer */
3514
3515 alt {
3516 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3517 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3518 /* Reschedule the MEAS RES timer */
3519 Tmr.start(0.480 + 0.120);
3520 repeat;
3521 }
3522 [] RSL.receive { repeat; }
3523 [] Tmr.timeout {
3524 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3525 }
3526 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3527 [] Timpf.timeout {
3528 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3529 log("Injected SAPI=3 traffic on SACCH");
3530 Timpf.start;
3531 repeat;
3532 }
3533 /* We're good if survived so far */
3534 [] Texec.timeout {
3535 setverdict(pass);
3536 }
3537 }
3538
3539 f_rsl_chan_deact();
3540 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3541 f_rslem_unregister(0, g_chan_nr);
3542}
3543testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3544 var template RSL_IE_ChannelMode ch_mode;
3545 var template ConnHdlrPars pars;
3546 var ConnHdlr vc_conn;
3547
3548 f_init();
3549
3550 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3551 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3552
3553 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3554 vc_conn.done;
3555
3556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3557}
3558testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3559 var template RSL_IE_ChannelMode ch_mode;
3560 var template ConnHdlrPars pars;
3561 var ConnHdlr vc_conn;
3562
3563 f_init();
3564
3565 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3566 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3567
3568 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3569 vc_conn.done;
3570
3571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3572}
3573
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003574/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3575 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003576private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003577 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003578 var RSL_IE_MS_Power ms_power;
3579 var RSL_Message rsl;
3580 var uint5_t power_level := 0;
3581
3582 f_l1_tune(L1CTL);
3583 RSL.clear;
3584
3585 f_est_dchan();
3586
3587 ms_power.reserved := 0;
3588 ms_power.fpc_epc := false;
3589
3590 /* Send the first power control command. This will disable any BTS/TRX
3591 * internal power control and switch the MS (which is not in scope of
3592 * this test) to a constant power level. We start with a power level
3593 * of 0 */
3594 ms_power.power_level := power_level;
3595 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3596 RSL.send(rsl);
3597
3598 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003599 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3600 if (l1h.ms_power_lvl != power_level) {
3601 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3602 "match the signaled (RSL) power level := ", power_level);
3603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003604 }
3605
3606 /* Signal a new power level via RSL for the next turn. */
3607 if (power_level < 31) {
3608 power_level := power_level + 1;
3609 ms_power.power_level := power_level;
3610 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3611 RSL.send(rsl);
3612 repeat;
3613 }
3614
3615 }
3616
3617 /* Ignore all other blocks */
3618 [] L1CTL.receive { repeat; }
3619
3620 }
3621
3622 f_rsl_chan_deact();
3623 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3624
3625 setverdict(pass);
3626}
3627
3628testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3629 var ConnHdlr vc_conn;
3630 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003631 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003632
3633 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3634 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3635 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3636 vc_conn.done;
3637 }
3638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3639}
Harald Welte70767382018-02-21 12:16:40 +01003640
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003641/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003642TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003643private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003644 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003645 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003646
3647 f_l1_tune(L1CTL);
3648 RSL.clear;
3649
3650 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003651 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003652
3653 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3654
3655
3656 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003657 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3658 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003659 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3660 }
3661
3662 }
3663
3664 /* Ignore all other blocks */
3665 [] L1CTL.receive { repeat; }
3666
3667 }
3668
3669 f_rsl_chan_deact();
3670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3671
3672 setverdict(pass);
3673}
3674
3675testcase TC_rsl_chan_initial_ta() runs on test_CT {
3676 var ConnHdlr vc_conn;
3677 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003678 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003679 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003680 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3681 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003682 vc_conn.done;
3683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3684}
3685
Eric Wilde57e1a62019-05-28 13:30:55 +02003686/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003687private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003688 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003689 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003690
3691 var RSL_IE_MS_Power ms_power;
3692 ms_power.reserved := 0;
3693 ms_power.fpc_epc := false;
3694 ms_power.power_level := ms_power_level;
3695
3696 f_l1_tune(L1CTL);
3697 RSL.clear;
3698
3699 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3700
3701 timer T := 1.0;
3702 T.start;
3703 alt {
3704 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003705 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3706 if (l1h.ms_power_lvl != ms_power_level) {
3707 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3708 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003709 }
3710 }
3711 /* Ignore all other blocks */
3712 [] L1CTL.receive { repeat; }
3713 [] T.timeout {
3714 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3715 }
3716 }
3717
3718 f_rsl_chan_deact();
3719 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3720 setverdict(pass);
3721}
3722
3723testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3724 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3725 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3726}
3727
Harald Welte0472ab42018-03-12 15:02:26 +01003728/* 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 +01003729private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003730 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003731 RSL.clear;
3732
3733 f_est_dchan();
3734 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003735 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003736
3737 timer T := 40.0;
3738 T.start;
3739 alt {
3740 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3741 setverdict(pass)
3742 }
3743 [] RSL.receive { repeat };
3744 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003746 }
3747 }
3748 f_rsl_chan_deact();
3749}
3750testcase TC_conn_fail_crit() runs on test_CT {
3751 var ConnHdlr vc_conn;
3752 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003753 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003754 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3755 pars.t_guard := 60.0;
3756 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3757 vc_conn.done;
3758}
3759
Harald Welte93640c62018-02-25 16:59:33 +01003760/***********************************************************************
3761 * Paging
3762 ***********************************************************************/
3763
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003764private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003765 if (tmsi == 'FFFFFFFF'O) {
3766 return true;
3767 } else {
3768 return false;
3769 }
3770}
Harald Welte70767382018-02-21 12:16:40 +01003771
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003772private type record allowedFn { integer frame_nr }
3773private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3774private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3775private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3776private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3777private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3778private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3779private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3780private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3781private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003782{
3783 var integer frame_nr_51;
3784 frame_nr_51 := frame_nr mod 51
3785
3786 var allowedFn fn_check;
3787 fn_check.frame_nr := frame_nr_51;
3788
3789 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003791 return;
3792 }
3793
3794 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3795 return;
3796 }
3797 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3798 return;
3799 }
3800 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3801 return;
3802 }
3803 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3804 return;
3805 }
3806 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3807 return;
3808 }
3809 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3810 return;
3811 }
3812 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3813 return;
3814 }
3815 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3816 return;
3817 }
3818
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003820 return;
3821}
3822
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003823private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3824 inout integer num_paging_rcv_ids,
3825 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003826runs on test_CT {
3827 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003828 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003829 repeat;
3830 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003831 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003832 var octetstring without_plen :=
3833 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3834 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003835
3836 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3837
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003838 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3839 /* Ignore empty RR Paging Request (PCH filling) messages.
3840 * TODO: does it make sense to count them? */
3841 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003842 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3843 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003844 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003845 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3846 }
3847 } else if (match(rr, tr_PAGING_REQ2)) {
3848 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3849 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3850 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3851 }
3852 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3853 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3854 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003855 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003856 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3857 }
3858 } else if (match(rr, tr_PAGING_REQ3)) {
3859 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3860 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3861 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3862 }
3863 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3864 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3865 }
3866 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3867 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3868 }
3869 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3870 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3871 }
3872 }
3873 repeat;
3874 }
3875}
3876
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003877private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003878 boolean combined_ccch,
3879 integer bs_ag_blks_res,
3880 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003881 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3882 * paging command that is issued via RSL. */
3883 integer ps_load_modulus,
3884 /* Wait until the paging queue inside the BTS is congested before starting to add
3885 * pagings via the PCU socket (0 = disabled) */
3886 boolean ps_wait_cong,
3887 /* Maximum time to wait until the paging queue is drained at the end of the test.
3888 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3889 * to set this value to 18s, however the draining process may take significantly
3890 * longer when the queue contains paging requests for PS as those are implemented
3891 * as immediate assignments and require an entire MAC block alone. */
3892 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003893 boolean exp_load_ind,
3894 boolean exp_overload,
3895 boolean use_tmsi
3896}
3897
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003898private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003899 integer num_paging_sent,
3900 integer num_paging_rcv_msgs,
3901 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003902 integer num_overload,
3903 /* When free space inside the paging queue reaches more than 2 thirds
3904 * of its capacity cong_detected is set to true. */
3905 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003906}
3907
Harald Welte68e495b2018-02-25 00:05:57 +01003908/* Helper function for paging related testing */
3909private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003910 /* Using the PCU socket affects the timing of the paging processing. We only
3911 * activate the PCU socket if we do paging load tests that include additional
3912 * paging load that is introduced through the PCU socket. */
3913 if (cfg.ps_load_modulus > 0) {
3914 f_init_with_pcuif();
3915 } else {
3916 f_init();
3917 }
Harald Welte68e495b2018-02-25 00:05:57 +01003918 f_init_l1ctl();
3919 f_l1_tune(L1CTL);
3920
Philipp Maierca058272021-06-23 10:35:23 +02003921 var octetstring imm_ass := f_rnd_octstring(23);
3922 var ASP_RSL_Unitdata load_ind;
3923
Harald Welte68e495b2018-02-25 00:05:57 +01003924 var PagingTestState st := {
3925 num_paging_sent := 0,
3926 num_paging_rcv_msgs := 0,
3927 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003928 num_overload := 0,
3929 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003930 };
3931
3932 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3933 var float max_pch_imsi_per_sec;
3934 if (cfg.use_tmsi) {
3935 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3936 } else {
3937 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3938 }
3939 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3940 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003941 var float time_total := 20.0;
3942 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3943 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003944
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003945 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3946 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003947
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003948 timer T_itv := 0.0;
3949 T_itv.start;
3950 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003951 alt {
3952 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003953 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003954 st.num_overload := st.num_overload + 1;
3955 repeat;
3956 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003957 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003958 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003959 }
Philipp Maierca058272021-06-23 10:35:23 +02003960 [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 +01003961 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003962
3963 /* Detect paging congestion: The logic inside the BTS will diagnose the
3964 * paging queue as congested when the fill state is more than 66% (which
3965 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3966 * paging congestion is detected pagings that are issued through the PCU
3967 * socket (PS) are dropped in order to prefer the CS related pagings. */
3968 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3969 st.cong_detected := true;
3970 }
3971
Harald Welte68e495b2018-02-25 00:05:57 +01003972 /* FIXME: analyze/verify interval + contents */
3973 repeat;
3974 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003975 /* ignore other RSL messages like RF RESource INDication */
3976 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003977 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003978 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003979 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003980 /* Only relevant when testing including with PCU sock connected */
3981 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003982 [] T_itv.timeout {
3983 /* Send paging cmds based on elapsed time */
3984 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3985 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003986 var MobileIdentityV mi;
3987
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003988 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003989 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003990 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003991 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003992 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003993 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003994
3995 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003996 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 +02003997
Philipp Maierca058272021-06-23 10:35:23 +02003998 /* Add additional pagings through the PCU socket interface. */
3999 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4000 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4001 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4002 }
4003 }
4004
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004005 st.num_paging_sent := st.num_paging_sent + 1;
4006 }
4007 if (st.num_paging_sent < pkt_total) {
4008 /* Wait for interval to next PAGING COMMAND */
4009 var float time_now := T_total.read;
4010 var float next_sched := int2float(st.num_paging_sent)*interval;
4011 if (next_sched > time_now) {
4012 T_itv.start(next_sched - time_now);
4013 } else {
4014 T_itv.start(0.0);
4015 }
4016 } else {
4017 /* We are done, no need to keep counting */
4018 T_total.stop;
4019 }
4020 }
4021 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004022 }
4023 }
4024
Philipp Maierca058272021-06-23 10:35:23 +02004025 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004026 T_wait.start;
4027 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004028 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004029 [] L1CTL.receive { repeat; }
4030 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004031 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004032 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004033 /* ignore other RSL messages like RF RESource INDication */
4034 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004035 /* Only relevant when testing including with PCU sock connected */
4036 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004037 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004038 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 +01004039 }
Harald Welte68e495b2018-02-25 00:05:57 +01004040 }
4041
4042 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4043 " rcvd_ids=", st.num_paging_rcv_ids);
4044 return st;
4045}
4046
4047/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4048 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4049 * - that CCCH LOAD IND (PCH) are being generated
4050 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4051testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004052 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004053 var PagingTestCfg cfg := {
4054 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004055 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004056 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004057 ps_load_modulus := 0,
4058 ps_wait_cong := false,
4059 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004060 exp_load_ind := true,
4061 exp_overload := false,
4062 use_tmsi := false
4063 };
4064 var PagingTestState st := f_TC_paging(cfg);
4065 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4067 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004068 } else {
4069 setverdict(pass);
4070 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004071 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004072}
4073
4074/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4075 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4076 * - that CCCH LOAD IND (PCH) are being generated
4077 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4078testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004079 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004080 var PagingTestCfg cfg := {
4081 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004082 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004083 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004084 ps_load_modulus := 0,
4085 ps_wait_cong := false,
4086 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004087 exp_load_ind := true,
4088 exp_overload := false,
4089 use_tmsi := true
4090 };
4091 var PagingTestState st := f_TC_paging(cfg);
4092 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4094 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004095 } else {
4096 setverdict(pass);
4097 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004099}
4100
4101/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4102 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4103 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4104 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4105testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004106 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004107 var PagingTestCfg cfg := {
4108 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004109 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004110 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004111 ps_load_modulus := 0,
4112 ps_wait_cong := false,
4113 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004114 exp_load_ind := true,
4115 exp_overload := true,
4116 use_tmsi := false
4117 };
4118 var PagingTestState st := f_TC_paging(cfg);
4119 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4120 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004121 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004122 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004123 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 +01004124 } else {
4125 setverdict(pass);
4126 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004128}
4129
4130/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4131 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4132 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4133 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4134testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004135 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004136 var PagingTestCfg cfg := {
4137 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004138 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004139 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004140 ps_load_modulus := 0,
4141 ps_wait_cong := false,
4142 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004143 exp_load_ind := true,
4144 exp_overload := true,
4145 use_tmsi := true
4146 };
4147 var PagingTestState st := f_TC_paging(cfg);
4148 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4149 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004150 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004151 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004152 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 +01004153 } else {
4154 setverdict(pass);
4155 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004157}
4158
Philipp Maierca058272021-06-23 10:35:23 +02004159/* Same as above, but with additional paging load created by PS pagings that
4160 * are issued through the PCU socket. The additional load is introduced when
4161 * the paging queue is already two thirds full. Since the BTS implements a
4162 * prioritization logic that drops the pagings from the PCU under in those
4163 * congestive sitautions the behaviour on the PS side is expected to be
4164 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4165testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4166 var SystemInformation si3 := valueof(ts_SI3_default);
4167 var PagingTestCfg cfg := {
4168 combined_ccch := true,
4169 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4170 load_factor := 2.0,
4171 ps_load_modulus := 16,
4172 ps_wait_cong := true,
4173 queue_drain_timeout := 18.0,
4174 exp_load_ind := true,
4175 exp_overload := true,
4176 use_tmsi := false
4177 };
4178 var PagingTestState st := f_TC_paging(cfg);
4179 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4180 * slots and will fully drain that buffer before returning */
4181 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4182 if (not match(st.num_paging_rcv_ids, tpl)) {
4183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4184 } else {
4185 setverdict(pass);
4186 }
4187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4188}
4189
4190
Harald Welte68e495b2018-02-25 00:05:57 +01004191
Harald Welte93640c62018-02-25 16:59:33 +01004192/***********************************************************************
4193 * Immediate Assignment / AGCH
4194 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004195private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004196 len := 0,
4197 ma := ''B
4198}
Harald Welte93640c62018-02-25 16:59:33 +01004199
Harald Weltee8d750e2018-06-10 21:41:35 +02004200private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4201 return int2str(num_tx) & " sent, "
4202 & int2str(num_rx) & " received, "
4203 & int2str(num_del) & " deleted";
4204}
4205
4206private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4207 var L1ctlDlMessage l1_dl;
4208 timer T := 10.0;
4209 var integer num_tx := 0;
4210 var integer num_rx := 0;
4211 var integer num_del := 0;
4212 var charstring res_str;
4213 var float rx_ratio;
4214
Harald Welte10474062019-05-30 16:48:17 +02004215 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004216 f_init_l1ctl();
4217 f_l1_tune(L1CTL);
4218
4219 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004220 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004221 mp_trx_pars[0].arfcn,
4222 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004223 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4224 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004225 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004226 num_tx := num_tx+1;
4227 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004228 }
4229 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004230 T.start;
4231 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004232 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004233 num_del := num_del+1;
4234 repeat;
4235 }
4236 [] RSL_CCHAN.receive {
4237 repeat;
4238 }
4239 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004240 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4241 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4242 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004243 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004244 } else {
4245 num_rx := num_rx+1;
4246 }
4247 repeat;
4248 }
4249 [] L1CTL.receive { repeat; }
4250 [] T.timeout { }
4251 }
4252 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4253 log("AGCH test: " & res_str);
4254 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004256 }
4257 rx_ratio := int2float(num_rx) / int2float(num_tx);
4258 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004259 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 +02004260 } else {
4261 setverdict(pass);
4262 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004264}
4265
Harald Weltee8d750e2018-06-10 21:41:35 +02004266/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4267testcase TC_imm_ass_1000_20ms() runs on test_CT {
4268 f_TC_imm_ass(1000, 0.02, 0.25);
4269}
4270
4271/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4272testcase TC_imm_ass_200_0ms() runs on test_CT {
4273 f_TC_imm_ass(200, 0.0, 0.05);
4274}
4275
4276/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4277testcase TC_imm_ass_200_76ms() runs on test_CT {
4278 f_TC_imm_ass(150, 0.076, 1.00);
4279}
4280
4281
4282
Harald Welte48494ca2018-02-25 16:59:50 +01004283/***********************************************************************
4284 * BCCH
4285 ***********************************************************************/
4286
4287/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004288private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004289 GsmFrameNumber frame_number,
4290 SystemInformation si
4291}
4292
4293/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004294private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004295
4296/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004297private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004298
4299/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004300private function f_si_vecslot_contains(SystemInformationVector arr,
4301 RrMessageType key,
4302 boolean bcch_ext := false)
4303return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004304 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4305 var integer fn_mod51 := arr[i].frame_number mod 51;
4306 if (not bcch_ext and fn_mod51 == 2 or
4307 bcch_ext and fn_mod51 == 6) {
4308 if (arr[i].si.header.message_type == key) {
4309 return true;
4310 }
4311 }
4312 }
4313 return false;
4314}
4315
4316/* 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 +07004317private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4318 integer tc, RrMessageType key,
4319 boolean ext_bcch := false)
4320{
Harald Welte48494ca2018-02-25 16:59:50 +01004321 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004323 }
4324}
4325
4326/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004327private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4328 RrMessageType key)
4329return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004330 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4331 if (f_si_vecslot_contains(arr[tc], key) or
4332 f_si_vecslot_contains(arr[tc], key, true)) {
4333 return true;
4334 }
4335 }
4336 return false;
4337}
4338
4339/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004340private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4341 RrMessageType key,
4342 boolean bcch_ext := false,
4343 integer n := 1, integer m := 4)
4344return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004345 var integer count := 0;
4346 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4348 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004349 }
4350 for (var integer i:= 0; i < m; i := i + 1) {
4351 var integer fn_mod51 := arr[i].frame_number mod 51;
4352 if (not bcch_ext and fn_mod51 == 2 or
4353 bcch_ext and fn_mod51 == 6) {
4354 if (arr[i].si.header.message_type == key) {
4355 count := count + 1;
4356 }
4357 }
4358 }
4359 if (count >= n) {
4360 return true;
4361 } else {
4362 return false;
4363 }
4364}
4365
4366/* 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 +07004367private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4368 integer tc, RrMessageType key,
4369 boolean ext_bcch := false,
4370 integer n, integer m)
4371{
Harald Welte48494ca2018-02-25 16:59:50 +01004372 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004374 }
4375}
4376
4377/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004378private function f_si_vecslot_contains_only(SystemInformationVector arr,
4379 RrMessageType key,
4380 boolean bcch_ext := false)
4381return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004382 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4383 var integer fn_mod51 := arr[i].frame_number mod 51;
4384 if (not bcch_ext and fn_mod51 == 2 or
4385 bcch_ext and fn_mod51 == 6) {
4386 if (arr[i].si.header.message_type != key) {
4387 return false;
4388 }
4389 }
4390 }
4391 return true;
4392}
4393
4394/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004395private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4396 integer tc, RrMessageType key,
4397 boolean ext_bcch := false)
4398{
Harald Welte48494ca2018-02-25 16:59:50 +01004399 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004401 }
4402}
4403
4404/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004405private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004406 boolean bcch_extended,
4407 boolean si1_present,
4408 boolean si2bis_present,
4409 boolean si2ter_present,
4410 boolean si2quater_present,
4411 boolean si7_present,
4412 boolean si8_present,
4413 boolean si9_present,
4414 boolean si13_present,
4415 boolean si13alt_present,
4416 boolean si15_present,
4417 boolean si16_present,
4418 boolean si17_present,
4419 boolean si2n_present,
4420 boolean si21_present,
4421 boolean si22_present
4422}
4423
4424/* 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 +07004425private function f_validate_si_scheduling(SystemInformationConfig cfg,
4426 SystemInformationVectorPerTc si_per_tc)
4427{
Harald Welte48494ca2018-02-25 16:59:50 +01004428 var integer i;
4429 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4430 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004432 }
4433 }
4434 if (cfg.si1_present) {
4435 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4436 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4437 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4438 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4439 /* make sure *ALL* contain SI1 */
4440 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4441 }
4442 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4443 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4444 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4445 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4446 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4447 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4448
4449 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4450 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4451 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4452 * consecutive occurrences of TC = 4. */
4453 if (cfg.si2bis_present and not cfg.si2ter_present) {
4454 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4455 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4456 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4457 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4458 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4459 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4460 }
4461
4462 if (cfg.si7_present or cfg.si8_present) {
4463 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4464 * if System Information type 4 does not contain all information needed for cell
4465 * selection and reselection. */
4466 if (not cfg.bcch_extended) {
4467 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4468 }
4469 if (cfg.si7_present) {
4470 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4471 }
4472 if (cfg.si8_present) {
4473 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4474 }
4475 }
4476
4477 if (cfg.si2quater_present) {
4478 /* iii) System information type 2 quater is sent if needed, as determined by the system
4479 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4480 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4481 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4482 * within any of 4 consecutive occurrences of TC = 5. */
4483 if (not (cfg.bcch_extended)) {
4484 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4485 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4486 } else {
4487 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4488 }
4489 } else {
4490 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4491 }
4492 }
4493 if (cfg.si9_present) {
4494 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4495 * in system information type 3 as defined in 3GPP TS 44.018. */
4496 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4497 }
4498 if (cfg.si13_present) {
4499 /* vii) System Information type 13 is only related to the GPRS service. System Information
4500 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4501 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4502 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4503 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4504 * within any of 4 consecutive occurrences of TC=4. */
4505 if (not cfg.bcch_extended) {
4506 log("not-bccch-extended");
4507 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4508 } else {
4509 log("bccch-extended");
4510 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4511 }
4512 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004514 }
4515 }
4516 if (cfg.si16_present or cfg.si17_present) {
4517 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4518 * should not be sent in a cell where network sharing is used (see rule xv). */
4519 if (cfg.si22_present) {
4520 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4521 }
4522 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004524 }
4525 if (not cfg.bcch_extended) {
4526 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4527 }
4528 if (cfg.si16_present) {
4529 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4530 }
4531 if (cfg.si17_present) {
4532 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4533 }
4534 }
4535
4536 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4537 * broadcast information. The frequency with which they are sent is determined by the
4538 * system operator. System Information type 9 identifies the scheduling of System
4539 * Information type 18 and 20 messages. */
4540
4541 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4542 * Information Type 19 is present, then its scheduling shall be indicated in System
4543 * Information Type 9. */
4544
4545 if (cfg.si15_present) {
4546 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4547 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4548 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4549 * 4 consecutive occurrences of TC = 1. */
4550 if (not cfg.bcch_extended) {
4551 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4552 } else {
4553 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4554 }
4555 }
4556 if (cfg.si13alt_present) {
4557 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4558 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4559 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4560 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4561 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4562 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4563 * of TC = 4. */
4564 if (cfg.si13_present) {
4565 testcase.stop("Error: Cannot have SI13alt and SI13");
4566 }
4567 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004569 }
4570 if (not cfg.bcch_extended) {
4571 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4572 } else {
4573 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4574 }
4575 }
4576 if (cfg.si2n_present) {
4577 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4578 * as determined by the system operator. In the case that the message is sent on the
4579 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4580 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4581 * consecutive occurrences of TC = 4. */
4582 if (not cfg.bcch_extended) {
4583 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4584 } else {
4585 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4586 }
4587 }
4588 if (cfg.si21_present) {
4589 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4590 * determined by the system operator. If Extended Access Barring is in use in the cell
4591 * then this message is sent at least once within any of 4 consecutive occurrences of
4592 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4593 * cell then this message shall only be sent on BCCH Ext. */
4594 if (not cfg.bcch_extended) {
4595 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4596 } else {
4597 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4598 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004600 }
4601 }
4602 }
4603 if (cfg.si22_present) {
4604 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4605 * should not be sent in a cell where SoLSA is used (see rule viii). System
4606 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4607 * =2 and TC=6. */
4608 if (cfg.si16_present or cfg.si17_present) {
4609 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4610 }
4611 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4612 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004614 }
4615 if (not cfg.bcch_extended) {
4616 testcase.stop("Error: SI22 requires BCCH Extd!");
4617 } else {
4618 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4619 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4620 }
4621 }
4622}
4623
4624/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004625private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4626return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004627 timer T := duration;
4628 var SystemInformationVectorPerTc si_per_tc;
4629 var L1ctlDlMessage l1_dl;
4630
4631 /* initialize all per-TC vectors empty */
4632 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4633 si_per_tc[i] := {};
4634 }
4635
4636 /* flush all previous L1 queued msgs */
4637 pt.clear;
4638
4639 T.start;
4640 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004641 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004642 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4643 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4644 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004645 repeat;
4646 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004647
Harald Welte48494ca2018-02-25 16:59:50 +01004648 var integer tc := f_gsm_compute_tc(sig.frame_number);
4649 log("SI received at TC=", tc, ": ", sig.si);
4650 /* append to the per-TC bucket */
4651 si_per_tc[tc] := si_per_tc[tc] & { sig };
4652 repeat;
4653 }
4654 [] pt.receive { repeat; }
4655 [] T.timeout { }
4656 }
4657
4658 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4659 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4660 }
4661 log("si_per_tc=", si_per_tc);
4662 return si_per_tc;
4663}
4664
4665/* helper function: Set given SI via RSL + validate scheduling.
4666 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004667private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004668 var SystemInformationVectorPerTc si_per_tc;
4669 f_init_l1ctl();
4670 f_l1_tune(L1CTL);
4671
4672 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004673 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004674 f_validate_si_scheduling(si_cfg, si_per_tc);
4675
4676 setverdict(pass);
4677}
4678
4679testcase TC_si_sched_default() runs on test_CT {
4680 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004681 /* 2+3+4 are mandatory and set in f_init() */
4682 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004684}
4685
4686testcase TC_si_sched_1() runs on test_CT {
4687 f_init();
4688 si_cfg.si1_present := true;
4689 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004690 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004692}
4693
4694testcase TC_si_sched_2bis() runs on test_CT {
4695 f_init();
4696 si_cfg.si2bis_present := true;
4697 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4698 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004700}
4701
4702testcase TC_si_sched_2ter() runs on test_CT {
4703 f_init();
4704 si_cfg.si2ter_present := true;
4705 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4706 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004708}
4709
4710testcase TC_si_sched_2ter_2bis() runs on test_CT {
4711 f_init();
4712 si_cfg.si2bis_present := true;
4713 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4714 si_cfg.si2ter_present := true;
4715 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4716 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004718}
4719
4720testcase TC_si_sched_2quater() runs on test_CT {
4721 f_init();
4722 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004723 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004724 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004726}
4727
4728testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004729 /* NOTE: PCUIF connection is not used in this test case, but
4730 * without it the IUT would not broadcast SI13 (see OS#3075). */
4731 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004732 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004733 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004734 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004736}
4737
4738testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004739 /* NOTE: PCUIF connection is not used in this test case, but
4740 * without it the IUT would not broadcast SI13 (see OS#3075). */
4741 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004742 si_cfg.si2bis_present := true;
4743 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4744 si_cfg.si2ter_present := true;
4745 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4746 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004747 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004748 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004749 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004750 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004752}
4753
4754
Harald Welte68e495b2018-02-25 00:05:57 +01004755testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004756 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004757 /* FIXME: enable / disable individual BCCH info */
4758 //ts_RSL_BCCH_INFO(si_type, info);
4759 /* expect no ERROR REPORT after either of them *
4760 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004762}
4763
Harald Welte93640c62018-02-25 16:59:33 +01004764/***********************************************************************
4765 * Low-Level Protocol Errors / ERROR REPORT
4766 ***********************************************************************/
4767
Harald Welte01d982c2018-02-25 01:31:40 +01004768private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4769 timer T := 5.0;
4770 T.start;
4771 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004772 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004773 setverdict(pass);
4774 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004775 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004777 }
4778 [] RSL_CCHAN.receive {
4779 repeat;
4780 }
4781 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004783 }
4784 }
4785}
4786
4787/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4788testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004789 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004790 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4791 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004792 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004793
4794 f_exp_err_rep(RSL_ERR_PROTO);
4795}
4796
4797/* Provoke a mandatory IE error and match on ERROR REPORT */
4798testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004799 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004800
4801 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4802 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004803 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004804
4805 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4806}
4807
4808/* Provoke an IE content error and match on ERROR REPORT */
4809testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004810 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004811 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4812 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004813 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004814
4815 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4816}
4817
Harald Welteee25aae2019-05-19 14:32:37 +02004818/* attempt to activate channel with wrong RSL Message Discriminator IE */
4819function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4820 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4821 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4822 RSL.send(rsl);
4823 f_rslem_unregister(0, g_chan_nr);
4824}
4825testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4826 var ConnHdlr vc_conn;
4827 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4828
Harald Welte10474062019-05-30 16:48:17 +02004829 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004830
4831 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4832 vc_conn.done;
4833 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4834
4835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4836}
4837
4838/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004839private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004840 var template (value) RSL_Message rsl_tx;
4841 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4842 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4843 RSL.send(rsl_tx);
4844 f_rslem_unregister(0, g_chan_nr);
4845}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004846private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004847 var template (value) RSL_Message rsl_tx;
4848 /* we first have to activate the dedicated channel */
4849 f_rsl_chan_act(g_pars.chan_mode);
4850 /* ... to then send an invalid RLL message */
4851 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4852 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4853 RSL.send(rsl_tx);
4854 f_rslem_unregister(0, g_chan_nr);
4855}
4856testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4857 var ConnHdlr vc_conn;
4858 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4859 var template (value) RSL_Message rsl_tx;
4860
Harald Welte10474062019-05-30 16:48:17 +02004861 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004862
4863 /* Common Channel with wrong message type */
4864 RSL_CCHAN.clear;
4865 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4866 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004867 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004868 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4869
4870 /* TRX Management */
4871 RSL_CCHAN.clear;
4872 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4873 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004874 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004875 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4876
4877 /* Dedicated Channel */
4878 RSL_CCHAN.clear;
4879 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4880 vc_conn.done;
4881 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4882
4883 /* RLL */
4884 RSL_CCHAN.clear;
4885 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4886 vc_conn.done;
4887 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4888}
4889
4890/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004891private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004892 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4893 f_rslem_unregister(0, g_chan_nr);
4894}
4895testcase TC_err_rep_wrong_sequence() runs on test_CT {
4896 var ConnHdlr vc_conn;
4897 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4898
Harald Welte10474062019-05-30 16:48:17 +02004899 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004900
4901 RSL_CCHAN.clear;
4902 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4903 vc_conn.done;
4904 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4905}
4906
Harald Welte93640c62018-02-25 16:59:33 +01004907/***********************************************************************
4908 * IPA CRCX/MDCX/DLCS media stream handling
4909 ***********************************************************************/
4910
Harald Weltea871a382018-02-25 02:03:14 +01004911/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004912private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004913 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4914 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004915}
4916testcase TC_ipa_dlcx_not_active() runs on test_CT {
4917 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004918 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004919 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4920 vc_conn.done;
4921}
Harald Welte68e495b2018-02-25 00:05:57 +01004922
Harald Weltea3f1df92018-02-25 12:49:55 +01004923/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004924private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004925 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4926 "IPA CRCX ACK");
4927 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4928 "IPA CRCX NACK");
4929}
4930testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4931 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004932 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004933 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4934 vc_conn.done;
4935}
4936
4937/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004938private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004939 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4940 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004941 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004942 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4943 var uint7_t rtp_pt2 := f_rnd_int(127);
4944 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4945 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4946 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4947 "IPA MDCX ACK");
4948 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4949 "IPA DLCX ACK");
4950}
4951testcase TC_ipa_crcx_mdcx_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 Weltea3f1df92018-02-25 12:49:55 +01004954 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4955 vc_conn.done;
4956}
4957
Harald Welte3ae11da2018-02-25 13:36:06 +01004958/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004959private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004960 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4961 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004962 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004963 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4964 var uint7_t rtp_pt2 := f_rnd_int(127);
4965 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4966 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4967 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4968 "IPA MDCX ACK");
4969 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004970 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004971 remote_port := f_rnd_int(c_UINT16_MAX);
4972 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4973 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4974 "IPA MDCX ACK");
4975 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4976 "IPA DLCX ACK");
4977}
4978testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4979 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004980 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004981 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4982 vc_conn.done;
4983}
4984
Harald Welte9912eb52018-02-25 13:30:15 +01004985/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004986private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004987 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4988 "IPA CRCX NACK");
4989}
4990testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4991 var ConnHdlrPars pars;
4992 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004993 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004994
4995 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4996 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4997 vc_conn.done;
4998
4999 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5000 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5001 vc_conn.done;
5002}
5003
Harald Weltea3f1df92018-02-25 12:49:55 +01005004
Harald Welte883340c2018-02-28 18:59:29 +01005005/***********************************************************************
5006 * PCU Socket related tests
5007 ***********************************************************************/
5008
Harald Welte07bd2d22019-05-25 11:03:30 +02005009/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005010friend 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 +01005011runs on test_CT {
5012 timer T := 3.0;
5013
5014 /* we don't expect any RTS.req before PDCH are active */
5015 T.start;
5016 alt {
5017 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005019 }
5020 [] PCU.receive { repeat; }
5021 [] T.timeout { }
5022 }
5023
5024 /* Send PDCH activate request for known PDCH timeslot */
5025 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5026
5027 /* we now expect RTS.req for this timeslot (only) */
5028 T.start;
5029 alt {
5030 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5031 setverdict(pass);
5032 }
5033 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5034 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005036 }
5037 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005039 }
5040 [] PCU.receive { repeat; }
5041 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005043 }
5044 [not exp_success] T.timeout {
5045 setverdict(pass);
5046 }
5047 }
5048}
5049
Harald Welte07bd2d22019-05-25 11:03:30 +02005050/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005051friend 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 +01005052runs on test_CT {
5053 timer T := 3.0;
5054
5055 /* Send PDCH activate request for known PDCH timeslot */
5056 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 +02005057 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5058 * when it will actually have been executed in the BTS */
5059 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005060 PCU.clear;
5061 /* we now expect no RTS.req for this timeslot */
5062 T.start;
5063 alt {
5064 [] 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 +02005065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005066 }
5067 [] PCU.receive { repeat; }
5068 [] T.timeout {
5069 setverdict(pass);
5070 }
5071 }
5072}
5073
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005074friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005075 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005076 map(self:PCU, system:PCU);
5077 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005078 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5079}
5080
Harald Welte883340c2018-02-28 18:59:29 +01005081/* PDCH activation via PCU socket; check for presence of RTS.req */
5082testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005083 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005084
Harald Welte883340c2018-02-28 18:59:29 +01005085 f_TC_pcu_act_req(0, 0, 7, true);
5086}
5087
5088/* PDCH activation via PCU socket on non-PDCU timeslot */
5089testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005090 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005091
Harald Welte883340c2018-02-28 18:59:29 +01005092 f_TC_pcu_act_req(0, 0, 1, false);
5093}
5094
5095/* PDCH activation via PCU socket on wrong BTS */
5096testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005097 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005098
Harald Welte883340c2018-02-28 18:59:29 +01005099 f_TC_pcu_act_req(23, 0, 7, false);
5100}
5101
5102/* PDCH activation via PCU socket on wrong TRX */
5103testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005104 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005105
Harald Welte883340c2018-02-28 18:59:29 +01005106 f_TC_pcu_act_req(0, 23, 7, false);
5107}
5108
5109/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5110testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005111 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005112
Harald Welte883340c2018-02-28 18:59:29 +01005113 /* Activate PDCH */
5114 f_TC_pcu_act_req(0, 0, 7, true);
5115 f_sleep(1.0);
5116 /* and De-Activate again */
5117 f_TC_pcu_deact_req(0, 0, 7);
5118}
5119
5120/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5121testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005122 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005123
Harald Welte883340c2018-02-28 18:59:29 +01005124 f_TC_pcu_deact_req(0, 0, 1);
5125}
5126
5127/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005128function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005129 var PCUIF_send_data sd;
5130 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005131 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005132
5133 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005134 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005135
Harald Welte883340c2018-02-28 18:59:29 +01005136 T.start;
5137 alt {
5138 [] 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 +01005139 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005140 setverdict(pass);
5141 } else {
5142 repeat;
5143 }
5144 }
5145 [] PCU.receive { repeat; }
5146 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005148 }
5149 }
5150}
5151
Philipp Maier94c08482021-02-01 17:36:05 +01005152/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5153testcase TC_pcu_ver_si1() runs on test_CT {
5154 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5155 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5156}
5157
5158/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5159testcase TC_pcu_ver_si3() runs on test_CT {
5160 const octetstring si3 := '49012223242526272929AABBCC'O;
5161 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5162}
5163
5164/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5165testcase TC_pcu_ver_si13() runs on test_CT {
5166 const octetstring si13 := '01010203040506070909'O;
5167 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5168}
5169
Harald Welte883340c2018-02-28 18:59:29 +01005170private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5171
5172/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005173friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005174 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5175runs on test_CT
5176{
5177 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5178 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5179}
5180
5181/* 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 +02005182friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5183 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005184runs on test_CT
5185{
5186 var PCUIF_send_data sd;
5187
5188 timer T := 3.0;
5189 T.start;
5190 alt {
5191 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5192 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5193 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5194 sd.data.u.rts_req.fn, sapi, data);
5195 }
5196 [] PCU.receive { repeat; }
5197 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005199 }
5200 }
5201}
5202
5203/* Send DATA.req on invalid BTS */
5204testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005205 var TfiUsfArr tua := f_TfiUsfArrInit();
5206 var octetstring data := '0000'O & f_rnd_octstring(21);
5207
5208 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005209
Harald Welte883340c2018-02-28 18:59:29 +01005210 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005211 f_TfiUsfArrSet(tua, 7, 0);
5212 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5213 f_sleep(1.0);
5214
5215 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005216}
5217
5218/* Send DATA.req on invalid TRX */
5219testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005220 var TfiUsfArr tua := f_TfiUsfArrInit();
5221 var octetstring data := '0000'O & f_rnd_octstring(21);
5222
5223 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005224
Harald Welte883340c2018-02-28 18:59:29 +01005225 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005226 f_TfiUsfArrSet(tua, 7, 0);
5227 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5228 f_sleep(1.0);
5229
5230 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005231}
5232
5233/* Send DATA.req on invalid timeslot */
5234testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005235 var TfiUsfArr tua := f_TfiUsfArrInit();
5236 var octetstring data := '0000'O & f_rnd_octstring(21);
5237
5238 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005239
Harald Welte883340c2018-02-28 18:59:29 +01005240 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005241 f_TfiUsfArrSet(tua, 7, 0);
5242 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5243 f_sleep(1.0);
5244
5245 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005246}
5247
5248/* Send DATA.req on timeslot that hasn't been activated */
5249testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005250 var TfiUsfArr tua := f_TfiUsfArrInit();
5251 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005252
Harald Welte7162a612019-05-26 12:56:09 +02005253 f_virtphy_common();
5254
5255 f_TfiUsfArrSet(tua, 7, 0);
5256 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5257 f_sleep(1.0);
5258
5259 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005260}
5261
Harald Weltead033dc2019-05-25 17:28:16 +02005262private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005263 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5264 boolean wait_rts := true)
5265runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005266 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005267 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005268
5269 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005270 if (wait_rts) {
5271 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5272 } else {
5273 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5274 }
Harald Weltead033dc2019-05-25 17:28:16 +02005275
5276 T.start;
5277 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005278 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005279 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5280 setverdict(pass);
5281 }
Harald Welte7162a612019-05-26 12:56:09 +02005282 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5283 setverdict(fail, "Received unexpected ", rx_dl);
5284 }
Harald Weltead033dc2019-05-25 17:28:16 +02005285 [] L1CTL.receive {
5286 repeat;
5287 }
Harald Welte7162a612019-05-26 12:56:09 +02005288 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005289 setverdict(fail, "Timeout waiting for ", data);
5290 }
Harald Welte7162a612019-05-26 12:56:09 +02005291 [not expect_data] T.timeout {
5292 setverdict(pass);
5293 }
Harald Weltead033dc2019-05-25 17:28:16 +02005294 }
5295}
5296
5297private function f_disable_dynamic_ts() runs on test_CT
5298{
5299 f_init_vty_bsc();
5300 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5301 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5302 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5303 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005304 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005305}
5306
5307private function f_virtphy_common() runs on test_CT {
5308 f_disable_dynamic_ts();
5309 f_init_l1ctl();
5310 f_l1_tune(L1CTL);
5311}
5312
5313testcase TC_pcu_data_req_pdtch() runs on test_CT {
5314 var TfiUsfArr tua := f_TfiUsfArrInit();
5315 var octetstring data := '0000'O & f_rnd_octstring(21);
5316
5317 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005318
Harald Welte883340c2018-02-28 18:59:29 +01005319 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005320 f_TfiUsfArrSet(tua, 7, 0);
5321 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5322 f_sleep(1.0);
5323
5324 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005325}
5326
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005327/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005328testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005329 var TfiUsfArr tua := f_TfiUsfArrInit();
5330 var octetstring data := '0000'O & f_rnd_octstring(21);
5331
5332 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005333
Harald Welte883340c2018-02-28 18:59:29 +01005334 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005335 f_TfiUsfArrSet(tua, 7, 0);
5336 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5337 f_sleep(1.0);
5338
5339 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005340}
5341
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005342private function f_TC_pcu_ptcch_ul(uint16_t ra)
5343runs on test_CT {
5344 var template PCUIF_Message pcu_rach_ind;
5345 var PCUIF_send_data sd;
5346 var GsmFrameNumber fn;
5347 timer T;
5348
5349 /* Send an Access Burst on PTCCH/U over the Um-interface */
5350 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5351 chan_nr := ts_RslChanNr_PDCH(7),
5352 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5353
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005354 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5355 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005356
5357 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5358 T.start(52.0 * 4.615 / 1000.0);
5359 alt {
5360 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5361 log("Rx an Access Burst on the PCU interface: ", sd.data);
5362 setverdict(pass);
5363 T.stop;
5364 }
5365 [] PCU.receive { repeat; }
5366 [] T.timeout {
5367 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5368 /* Keep going, that's not the end of the world */
5369 }
5370 }
5371}
5372
5373testcase TC_pcu_ptcch() runs on test_CT {
5374 var L1ctlDlMessage dl;
5375 var octetstring data;
5376 timer T;
5377
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005378 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005379 f_init_l1ctl();
5380 f_l1_tune(L1CTL);
5381
5382 /* Activate PDCH channel on TS7 */
5383 f_TC_pcu_act_req(0, 0, 7, true);
5384
5385 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005386 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005387 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005388 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005389 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005390
5391 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5392 for (var integer i := 0; i < 16; i := i + 1) {
5393 log("Sending an Access Burst towards the L1CTL interface");
5394 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5395 }
5396
5397 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5398 data := f_rnd_octstring(23);
5399
5400 /* Verify PTCCH/D: send a random data block, make sure it's received */
5401 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5402 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5403
5404 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5405 * let's give it more time in case if we miss the beginning. */
5406 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5407 alt {
5408 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5409 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5410 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5411 frame := data)) -> value dl {
5412 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5413 setverdict(pass);
5414 T.stop;
5415 }
5416 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5417 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5418 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5419 l2_data := data)) -> value dl {
5420 log("Rx PTCCH/D data block on L1CTL: ", dl);
5421 setverdict(pass);
5422 T.stop;
5423 }
5424 [] L1CTL.receive { repeat; }
5425 [] T.timeout {
5426 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5427 }
5428 }
5429}
5430
Harald Welte883340c2018-02-28 18:59:29 +01005431/* Send AGCH from PCU; check it appears on Um side */
5432testcase TC_pcu_data_req_agch() runs on test_CT {
5433 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005434 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005435 f_init_l1ctl();
5436 f_l1_tune(L1CTL);
5437
5438 f_TC_pcu_act_req(0, 0, 7, true);
5439 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5440
5441 T.start;
5442 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005443 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005444 setverdict(pass);
5445 }
5446 [] L1CTL.receive { repeat; }
5447 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005449 }
5450 }
5451}
5452
Harald Welte928622b2019-05-26 13:22:59 +02005453/* Send AGCH from PCU; check it appears on Um side */
5454testcase TC_pcu_data_req_pch() runs on test_CT {
5455 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005456 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005457 f_init_l1ctl();
5458 f_l1_tune(L1CTL);
5459
5460 f_TC_pcu_act_req(0, 0, 7, true);
5461 /* three characters prefix: last 3 digits of IMSI as ASCII */
5462 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5463
5464 T.start;
5465 alt {
5466 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5467 setverdict(pass);
5468 }
5469 [] L1CTL.receive { repeat; }
5470 [] T.timeout {
5471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5472 }
5473 }
5474}
5475
Harald Welte883340c2018-02-28 18:59:29 +01005476/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5477testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5478 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005479 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005480 f_init_l1ctl();
5481 f_l1_tune(L1CTL);
5482
5483 /* append 3 last imsi digits so BTS can compute pagng group */
5484 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5485
5486 timer T := 0.5;
5487 T.start;
5488 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005489 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005490 /* TODO: verify paging group */
5491 setverdict(pass);
5492 }
5493 [] L1CTL.receive { repeat; }
5494 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005496 }
5497 }
5498}
5499
5500/* Send RACH from Um side, expect it to show up on PCU socket */
5501testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005502 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005503 f_init_l1ctl();
5504 f_l1_tune(L1CTL);
5505
5506 var GsmFrameNumber fn_last := 0;
5507 for (var integer i := 0; i < 1000; i := i+1) {
5508 var OCT1 ra := f_rnd_ra_ps();
5509 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5510 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005512 }
5513 fn_last := fn;
5514
5515 timer T := 2.0;
5516 T.start;
5517 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005518 [] 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 +01005519 T.stop;
5520 }
5521 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005523 }
5524 [] PCU.receive { repeat; }
5525 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005527 }
5528 }
5529 }
5530 setverdict(pass);
5531}
5532
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005533/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5534 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5535testcase TC_pcu_ext_rach_content() runs on test_CT {
5536 var template PCUIF_Message pcu_rach_ind;
5537 var GsmFrameNumber fn_last := 0;
5538 var L1ctlRachSynchSeq synch_seq;
5539 var PCUIF_BurstType pcu_bt;
5540 var GsmFrameNumber fn;
5541 var BIT11 ra11;
5542
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005543 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005544 f_init_l1ctl();
5545 f_l1_tune(L1CTL);
5546
5547 for (var integer i := 0; i < 1000; i := i+1) {
5548 /* We need to test both TS1 & TS2 */
5549 if (i rem 2 == 0) {
5550 synch_seq := RACH_SYNCH_SEQ_TS1;
5551 pcu_bt := BURST_TYPE_1;
5552 } else {
5553 synch_seq := RACH_SYNCH_SEQ_TS2;
5554 pcu_bt := BURST_TYPE_2;
5555 }
5556
5557 ra11 := f_rnd_ra11_ps();
5558 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5559 if (fn == fn_last) {
5560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5561 "Two RACH in same FN?!?");
5562 }
5563 fn_last := fn;
5564
5565 /* Compose the expected message */
5566 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005567 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005568 ra := bit2int(ra11),
5569 is_11bit := 1,
5570 burst_type := pcu_bt,
5571 fn := fn);
5572
5573 timer T := 2.0;
5574 T.start;
5575 alt {
5576 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5577 T.stop;
5578 }
5579 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5581 }
5582 [] PCU.receive { repeat; }
5583 [] T.timeout {
5584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5585 }
5586 }
5587 }
5588 setverdict(pass);
5589}
5590
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005591private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5592runs on test_CT {
5593 var template PCUIF_send_data sdt;
5594 var PCUIF_send_data sd;
5595 var int16_t lqual_cb;
5596 timer T := 1.0;
5597
5598 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5599 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5600
5601 /* Send a random PDTCH frame over Um */
5602 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5603 '0000'O & f_rnd_octstring(21)));
5604
5605 T.start;
5606 alt {
5607 /* If expected link quality is above the threshold */
5608 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5609 lqual_cb := sd.data.u.data_ind.lqual_cb;
5610 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5611
5612 /* Make sure the actual link quality matches the expected value */
5613 if (not match(lqual_cb, lqual_cb_exp)) {
5614 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5615 "expected value ", lqual_cb_exp));
5616 } else {
5617 setverdict(pass);
5618 }
5619 }
5620 /* If expected link quality is below the threshold */
5621 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5623 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5624 }
5625 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5626 [] PCU.receive { repeat; }
5627 [lqual_cb_exp < thresh] T.timeout {
5628 log("Rx nothing, as expected");
5629 setverdict(pass);
5630 }
5631 [lqual_cb_exp >= thresh] T.timeout {
5632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5633 "Timeout waiting for PCUIF_DATA.ind");
5634 }
5635 }
5636}
5637
5638/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5639testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005640 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005641 PCU.clear;
5642
5643 f_init_l1ctl();
5644 f_l1_tune(L1CTL);
5645
5646 /* Activate a PDCH channel on TS7 */
5647 f_TC_pcu_act_req(0, 0, 7, true);
5648
5649 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005650 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005651 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005652 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005653 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005654
5655 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5656 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5657 var TrxcMessage ret;
5658
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005659 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005660
5661 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5662 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5663 }
5664}
5665
Harald Welte883340c2018-02-28 18:59:29 +01005666/* Send PAGING via RSL, expect it to shw up on PCU socket */
5667testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005668 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005669
5670 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005671 var MobileIdentityLV mi_lv;
5672 var octetstring mi_lv_enc;
5673 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005674 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005675
Harald Welte883340c2018-02-28 18:59:29 +01005676 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005677 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005678 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005679 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005680 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005681
5682 /* Fancy encoding for PCUIF */
5683 mi_lv := valueof(ts_MI_LV(mi));
5684 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5685 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005686
5687 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005688 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005689 T.start;
5690 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005691 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005692 }
5693 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005695 }
5696 [] PCU.receive { repeat; }
5697 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005699 }
5700 }
5701 }
5702 setverdict(pass);
5703}
5704
Harald Welted66c9b82019-05-25 09:03:15 +02005705/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5706testcase TC_pcu_time_ind() runs on test_CT {
5707 var PCUIF_send_data pcu_sd;
5708 var integer num_time_ind := 0;
5709 var integer first_fn, last_fn;
5710 var float test_duration := 5.0;
5711 timer T;
5712
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005713 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005714 f_TC_pcu_act_req(0, 0, 7, true);
5715
5716 PCU.clear;
5717 T.start(test_duration);
5718 alt {
5719 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5720 num_time_ind := num_time_ind + 1;
5721 if (not isbound(first_fn)) {
5722 first_fn := pcu_sd.data.u.time_ind.fn;
5723 }
5724 last_fn := pcu_sd.data.u.time_ind.fn;
5725 repeat;
5726 }
5727 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5728 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5729 repeat;
5730 }
5731 [] PCU.receive {
5732 repeat;
5733 }
5734 [] T.timeout {}
5735 }
5736 var integer fn_expired := last_fn - first_fn;
5737 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5738
5739 /* verify the number of frames expired matches our expectation */
5740 const float c_GSM_FN_DURATION_MS := 4.61538;
5741 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005742 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005743 if (not match(fn_expired, t_fn_expected)) {
5744 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5745 }
5746
5747 /* There are three TIME.ind in every fn MOD 13 */
5748 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5749 /* Add some tolerance */
5750 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5751 if (not match(num_time_ind, t_time_ind_exp)) {
5752 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5753 }
5754
5755 setverdict(pass);
5756}
5757
Harald Welte4832c862019-05-25 14:57:18 +02005758/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5759testcase TC_pcu_rts_req() runs on test_CT {
5760 var PCUIF_send_data pcu_sd;
5761 var integer first_fn, last_fn;
5762 var integer num_rts_pdtch := 0;
5763 var integer num_rts_ptcch := 0;
5764 var float test_duration := 5.0;
5765 timer T;
5766
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005767 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005768 f_TC_pcu_act_req(0, 0, 7, true);
5769
5770 PCU.clear;
5771 T.start(test_duration);
5772 alt {
5773 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5774 -> value pcu_sd {
5775 num_rts_pdtch := num_rts_pdtch + 1;
5776 if (not isbound(first_fn)) {
5777 first_fn := pcu_sd.data.u.rts_req.fn;
5778 }
5779 last_fn := pcu_sd.data.u.rts_req.fn;
5780 repeat;
5781 }
5782 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5783 -> value pcu_sd {
5784 num_rts_ptcch := num_rts_ptcch + 1;
5785 if (not isbound(first_fn)) {
5786 first_fn := pcu_sd.data.u.rts_req.fn;
5787 }
5788 last_fn := pcu_sd.data.u.rts_req.fn;
5789 repeat;
5790 }
5791 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5792 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5793 repeat;
5794 }
5795 [] PCU.receive {
5796 repeat;
5797 }
5798 [] T.timeout {}
5799 }
5800 var integer fn_expired := last_fn - first_fn;
5801 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5802 ", num_rts_ptcch=", num_rts_ptcch);
5803
5804 /* verify the number of frames expired matches our expectation */
5805 const float c_GSM_FN_DURATION_MS := 4.61538;
5806 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005807 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005808 if (not match(fn_expired, t_fn_expected)) {
5809 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5810 }
5811
5812 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5813 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5814 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5815 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5816 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5817 t_ptcch_exp);
5818 }
5819
5820 /* We have 12 PDTCH blocks every 52-multiframe */
5821 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5822 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5823 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5824 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5825 t_pdtch_exp);
5826 }
5827
5828 setverdict(pass);
5829}
5830
Harald Welte07bd2d22019-05-25 11:03:30 +02005831/* test for generating Abis side OML ALERT from the PCU */
5832testcase TC_pcu_oml_alert() runs on test_CT {
5833 var PCUIF_send_data pcu_sd;
5834 var integer num_time_ind := 0;
5835 var integer first_fn, last_fn;
5836 var float test_duration := 5.0;
5837 timer T;
5838
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005839 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005840 f_TC_pcu_act_req(0, 0, 7, true);
5841
5842 /* re-connect CTRL port from BTS to BSC */
5843 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005844 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005845
5846 /* Send that OML Alert */
5847 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5848
5849 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5850 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5851 setverdict(pass);
5852}
5853
Harald Welteeaa9a862019-05-26 23:01:08 +02005854/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5855private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5856 var PCUIF_Message first_info;
5857 var integer pcu_conn_id := -1;
5858 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5859 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5860 var OCT4 tlli := '01020304'O;
5861 var OCT1 cause := '23'O;
5862 timer T := 5.0;
5863
5864 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5865
5866 f_l1_tune(L1CTL);
5867 RSL.clear;
5868
5869 f_est_dchan();
5870 L1CTL.clear;
5871
5872 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5873
5874 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5875 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5876 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5877
5878 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5879 T.start;
5880 alt {
5881 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5882 setverdict(pass);
5883 }
5884 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5885 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5886 }
5887 [] PCU.receive {
5888 repeat;
5889 }
5890 [] T.timeout {
5891 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5892 }
5893 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005894
5895 /* release the channel */
5896 f_rsl_chan_deact();
5897 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5898 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005899}
5900testcase TC_pcu_rr_suspend() runs on test_CT {
5901 var ConnHdlrPars pars;
5902 var ConnHdlr vc_conn;
5903
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005904 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005905
5906 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5907 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5908 vc_conn.done;
5909}
Harald Welte07bd2d22019-05-25 11:03:30 +02005910
Harald Weltea2e0e942019-05-27 18:12:53 +02005911/* Ensure that PCUIF socket can accept only a single connection */
5912testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005913 var boolean connected := false;
5914 var UD_connect_result cr;
5915 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005916 timer T := 5.0;
5917
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005918 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5919 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5920
Harald Weltea2e0e942019-05-27 18:12:53 +02005921 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005922 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005923
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005924 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005925 PCU.send(UD_connect:{mp_pcu_socket, -1});
5926 T.start;
5927 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005928 /* the IUT will first accept() the new connection, and close() it immediately */
5929 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5930 log("BTS has accept()ed connection");
5931 connected := true;
5932 cid := cr.id;
5933 repeat;
5934 }
5935 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5936 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005937 setverdict(pass);
5938 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005939 /* ignore other messages related to the first connection */
5940 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005941 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005942 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005943 }
5944 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005945
Harald Weltea2e0e942019-05-27 18:12:53 +02005946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5947}
5948
Harald Weltec8effb72019-05-27 18:23:04 +02005949/* Ensure that PCUIF socket can disconnect + reconnect */
5950testcase TC_pcu_socket_reconnect() runs on test_CT {
5951 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005952 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005953
5954 f_sleep(1.0);
5955
5956 f_pcuif_close(PCU, g_pcu_conn_id);
5957 g_pcu_conn_id := -1;
5958
5959 f_sleep(1.0);
5960
5961 /* re-connect */
5962 PCU.clear;
5963 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5964 setverdict(pass);
5965
5966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5967}
5968
Harald Weltebe030482019-05-27 22:29:35 +02005969/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005970private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5971runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005972 var L1ctlDlMessage l1_dl;
5973 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005974 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005975 timer T := 5.0;
5976 T.start;
5977 alt {
5978 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005979 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5980 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005981 repeat;
5982 }
5983 }
5984 [] pt.receive {
5985 repeat;
5986 }
5987 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5989 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005990 }
5991 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005992 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005993}
5994
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005995/* Check if GPRS Indicator is present in RR System Information of a given type */
5996private function f_si_has_gprs_indicator(RrMessageType si_type)
5997runs on test_CT return boolean {
5998 var SystemInformation si := f_get_si(L1CTL, si_type);
5999
6000 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006001 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006002 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006003 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006004 }
6005
6006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6007 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006008}
6009
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006010/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6011private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6012runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006013 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006014 f_init_l1ctl();
6015 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006016 f_sleep(2.0);
6017 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006018
6019 if (f_si_has_gprs_indicator(si_type)) {
6020 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006021 } else {
6022 setverdict(pass);
6023 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006024
Harald Weltebe030482019-05-27 22:29:35 +02006025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6026}
6027
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006028testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6029 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6030}
Harald Weltebe030482019-05-27 22:29:35 +02006031
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006032testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6033 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6034}
6035
6036/* Ensure that GPRS capability is advertised after PCU socket connect */
6037private function f_TC_pcu_socket_connect(RrMessageType si_type)
6038runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006039 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006040 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006041 f_init_l1ctl();
6042 f_l1_tune(L1CTL);
6043
6044 f_sleep(2.0);
6045 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006046
6047 if (not f_si_has_gprs_indicator(si_type)) {
6048 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006049 } else {
6050 setverdict(pass);
6051 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006052
Harald Weltebe030482019-05-27 22:29:35 +02006053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6054}
6055
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006056testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6057 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6058}
Harald Weltebe030482019-05-27 22:29:35 +02006059
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006060testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6061 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6062}
6063
6064/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6065private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6066runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006067 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006068 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006069 f_init_l1ctl();
6070 f_l1_tune(L1CTL);
6071
6072 f_pcuif_close(PCU, g_pcu_conn_id);
6073 g_pcu_conn_id := -1;
6074
6075 f_sleep(1.0);
6076
6077 /* re-connect */
6078 PCU.clear;
6079 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6080
6081 f_sleep(2.0);
6082 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006083
6084 if (f_si_has_gprs_indicator(si_type)) {
6085 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006086 } else {
6087 setverdict(pass);
6088 }
6089
6090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6091}
6092
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006093testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6094 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6095}
6096
6097testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6098 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6099}
6100
Oliver Smithf5239c72019-08-28 10:01:25 +02006101/* 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) */
6102testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6103 var SystemInformation si3 := valueof(ts_SI3_default);
6104
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006105 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006106
Harald Welte76220222020-10-11 20:32:44 +02006107 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6108 * information */
6109 timer T := 2.0;
6110 T.start;
6111 alt {
6112 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6113 [] T.timeout {}
6114 }
6115
Oliver Smithf5239c72019-08-28 10:01:25 +02006116 /* Verify cell_id */
6117 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6118 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6119 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006120 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6121 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6122 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006123 }
6124
6125 /* Verify LAC */
6126 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6127 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6128 if (lac_si3 != lac_pcu) {
6129 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6130 }
6131
6132 setverdict(pass);
6133}
Harald Welted66c9b82019-05-25 09:03:15 +02006134
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006135/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6136testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6137 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006138 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006139
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006140 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006141
6142 info_ind := g_pcu_last_info.u.info_ind;
6143
6144 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6145 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006146 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006147 /* Skip inactive timeslots */
6148 continue;
6149 }
6150
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006151 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006152 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006153 else
6154 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006155
6156 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006157 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006158 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006159 hsn := fhp.maio_hsn.hsn,
6160 maio := fhp.maio_hsn.maio,
6161 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006162 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006163 } else {
6164 tr_ts := tr_PCUIF_InfoTrxTsH0;
6165 }
6166
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006167 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006168 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6169 if (not match(ts, tr_ts)) {
6170 setverdict(fail, "Hopping parameters do not match: ",
6171 "received ", ts, " vs expected ", tr_ts);
6172 } else {
6173 setverdict(pass);
6174 }
6175 }
6176 }
6177}
6178
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006179/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006180testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6181 f_init_vty_bsc();
6182 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6183 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6184
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006185 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006186
6187 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006188 var template PCUIF_RemoteAddr tr_remote_addr := {
6189 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006190 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006191 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006192
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006193 if (not match(remote_addr, tr_remote_addr)) {
6194 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006195 }
6196
6197 setverdict(pass);
6198}
6199
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006200/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006201testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6202 f_init_vty_bsc();
6203 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6204
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006205 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006206
6207 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006208 var template PCUIF_RemoteAddr tr_remote_addr := {
6209 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6210 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6211 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006212
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006213 if (not match(remote_addr, tr_remote_addr)) {
6214 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006215 }
6216
6217 setverdict(pass);
6218}
6219
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006220/* Verify coding of two NSVCs in the INFO.ind message */
6221testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6222 f_init_vty_bsc();
6223
6224 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6225 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6226 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6227 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6228
6229 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6230 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6231 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6232 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6233
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006234 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006235
6236 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6237 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6238 var template PCUIF_RemoteAddr tr_remote_addr := {
6239 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006240 addr := {
6241 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6242 f_inet6_addr("fd00::ca:ff:ee")
6243 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006244 };
6245
6246 if (not match(info_ind.nsvci, { 1234, 5678 }))
6247 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6248 if (not match(remote_addr, tr_remote_addr))
6249 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6250 if (not match(info_ind.local_port, { 1234, 5678 }))
6251 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6252 if (not match(info_ind.remote_port, { 1234, 5678 }))
6253 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6254
6255 setverdict(pass);
6256}
6257
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006258/* Verify periodic interference reports on PDCH */
6259testcase TC_pcu_interf_ind() runs on test_CT {
6260 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006261 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006262 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006263 var PCUIF_send_data sd;
6264 timer T;
6265
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006266 /* Set the averaging/reporting period to 480ms */
6267 f_init_vty_bsc();
6268 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6269 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6270
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006271 f_init_with_pcuif();
6272 f_TC_pcu_act_req(0, 0, 7, true);
6273
6274 /* We need trxcon for NOPE indications */
6275 f_init_l1ctl();
6276 f_l1_tune(L1CTL);
6277
6278 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006279 tr_interf_ind := tr_PCUIF_INTERF_IND(
6280 bts_nr := 0,
6281 trx_nr := 0,
6282 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006283 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006284 );
6285
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006286 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006287 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006288 /* The first interference report may contain unreliable values, so we ignore it */
6289 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6290 /* 4 SACCH periods => 4 reports (plus some guard time) */
6291 T.start(0.480 * 4.0 + 0.480 / 2.0);
6292 first := false;
6293 repeat;
6294 }
6295 /* Subsequent interference reports shall match our expectations */
6296 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006297 /* Check TDMA frame number period */
6298 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6299 setverdict(fail, "Odd TDMA frame number := ",
6300 sd.data.u.interf_ind.fn);
6301 }
6302 interf_ind_num := interf_ind_num + 1;
6303 if (interf_ind_num < 4)
6304 { repeat; }
6305 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006306 [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 +02006307 setverdict(fail, "Received unexpected interference report: ", sd.data);
6308 }
6309 [] PCU.receive { repeat; }
6310 [] T.timeout {
6311 setverdict(fail, "Timeout waiting for interference reports");
6312 }
6313 }
6314
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006315 /* Reset the averaging/reporting period back to default */
6316 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6317
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6319}
6320
Harald Welte3d04ae62018-04-04 20:29:05 +02006321/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006322 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006323 ***********************************************************************/
6324
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006325private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6326 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006327runs on ConnHdlr {
6328 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006329
6330 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006331 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006332 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6333 repeat;
6334 }
6335 }
6336}
6337
6338private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6339runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006340 /* Expect BTS to immediately acknowledge activation as PDCH */
6341 PCU.clear;
6342 f_rsl_chan_act(g_pars.chan_mode);
6343 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006344 timer T_wait := 2.0;
6345 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006346 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006347 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006348 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006349 [] T_wait.timeout {
6350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6351 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6352 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006353 }
6354 /* try to activate this PDCH from the PCU point of view */
6355 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6356 /* FIXME: is there a response? */
6357}
6358
6359private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6360runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006361 /* Send RSL CHAN REL (deactivate) */
6362 PCU.clear;
6363 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6364 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006365 timer T_wait := 2.0;
6366 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006367 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006368 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006369 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006370 [] T_wait.timeout {
6371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6372 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6373 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006374 }
6375 /* Emulate PCU asking BTS to deactivate PDCH */
6376 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6377 alt {
6378 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6379 setverdict(pass);
6380 }
6381 [] RSL.receive { repeat; }
6382 }
6383}
6384
6385/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006386private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006387 var PCUIF_Message first_info;
6388 var integer ts_nr := g_chan_nr.tn;
6389 var integer trx_nr := 0;
6390 var integer bts_nr := 0;
6391 var integer pcu_conn_id := -1;
6392
6393 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6394
6395 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6396 f_sleep(3.0);
6397 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6398 setverdict(pass);
6399}
6400testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6401 var ConnHdlrPars pars;
6402 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006403 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006404
6405 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6406 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6407 vc_conn.done;
6408}
6409
6410/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006411private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006412 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006413 var integer pcu_conn_id := -1;
6414
6415 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6416
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006417 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6418 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6419 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006420 setverdict(pass);
6421}
6422testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6423 var ConnHdlrPars pars;
6424 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006425 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006426
6427 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6428 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6429 vc_conn.done;
6430}
6431
6432/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006433private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006434 var PCUIF_Message first_info;
6435 var integer ts_nr := g_chan_nr.tn;
6436 var integer trx_nr := 0;
6437 var integer bts_nr := 0;
6438 var integer pcu_conn_id := -1;
6439
6440 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6441
6442 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006443 /* Send a second Chan Activ and expect it to be NACKed */
6444 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6445 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006446 setverdict(pass);
6447}
6448testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6449 var ConnHdlrPars pars;
6450 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006451 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006452
6453 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6454 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6455 vc_conn.done;
6456}
6457
6458/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006459private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006460 var PCUIF_Message first_info;
6461 var integer ts_nr := g_chan_nr.tn;
6462 var integer trx_nr := 0;
6463 var integer bts_nr := 0;
6464 var integer pcu_conn_id := -1;
6465 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6466
6467 /* register for the TCH/F channel number */
6468 f_rslem_register(0, chan_nr);
6469
6470 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6471
6472 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6473 "RSL CHAN ACT");
6474 setverdict(pass);
6475}
6476testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6477 var ConnHdlrPars pars;
6478 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006479 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006480
6481 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6482 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6483 vc_conn.done;
6484}
6485
6486/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006487private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006488 var PCUIF_Message first_info;
6489 var integer ts_nr := g_chan_nr.tn;
6490 var integer trx_nr := 0;
6491 var integer bts_nr := 0;
6492 var integer pcu_conn_id := -1;
6493 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6494 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6495
6496 /* register for the TCH/H channel numbers */
6497 f_rslem_register(0, chan_nr[0]);
6498 f_rslem_register(0, chan_nr[1]);
6499
6500 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6501
6502 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6503 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6504 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6505 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6506 setverdict(pass);
6507}
6508testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6509 var ConnHdlrPars pars;
6510 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006511 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006512
6513 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6514 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6515 vc_conn.done;
6516}
6517
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006518/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6519private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6520 var PCUIF_Message first_info;
6521 var integer ts_nr := g_chan_nr.tn;
6522 var integer trx_nr := 0;
6523 var integer bts_nr := 0;
6524 var integer pcu_conn_id := -1;
6525 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6526 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6527 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6528 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6529 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6530 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6531 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6532 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6533
6534 /* register for the TCH/H channel numbers */
6535 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6536 f_rslem_register(0, chan_nr[i]);
6537 }
6538
6539 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6540
6541 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6542 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6543 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6544 }
6545 setverdict(pass);
6546}
6547testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6548 var ConnHdlrPars pars;
6549 var ConnHdlr vc_conn;
6550 f_init();
6551
6552 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6553 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6554 vc_conn.done;
6555}
6556
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006557/* Reproduce a race condition described in OS#5245 */
6558private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6559 f_rsl_chan_act(g_pars.chan_mode);
6560 f_sleep(1.0);
6561 f_rsl_chan_deact();
6562 setverdict(pass);
6563}
6564testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6565 var ConnHdlrPars pars[2];
6566 var ConnHdlr vc_conn[2];
6567 var TrxcMessage rsp;
6568
6569 f_init();
6570
6571 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6572 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6573 ts_TRXC_FAKE_TRXC_DELAY(200));
6574
6575 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6576 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6577 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6578 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6579 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6580 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6581 pars[i], l1ctl := false);
6582 }
6583
6584 /* Wait for all components to finish */
6585 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6586 vc_conn[i].done;
6587 }
6588
6589 /* Disable the artificial delay for TRXC RSP messages */
6590 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6591 ts_TRXC_FAKE_TRXC_DELAY(0));
6592}
6593testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6594 var ConnHdlrPars pars[8];
6595 var ConnHdlr vc_conn[8];
6596 var TrxcMessage rsp;
6597
6598 f_init();
6599
6600 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6601 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6602 ts_TRXC_FAKE_TRXC_DELAY(200));
6603
6604 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6605 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6606 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6607 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6608 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6609 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6610 pars[i], l1ctl := false);
6611 }
6612
6613 /* Wait for all components to finish */
6614 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6615 vc_conn[i].done;
6616 }
6617
6618 /* Disable the artificial delay for TRXC RSP messages */
6619 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6620 ts_TRXC_FAKE_TRXC_DELAY(0));
6621}
6622
Harald Welte9bbbfb52018-04-05 09:33:19 +02006623/***********************************************************************
6624 * IPA Style Dynamic Timeslot Support
6625 ***********************************************************************/
6626
6627private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6628runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006629 /* Expect BTS to immediately acknowledge activation as PDCH */
6630 PCU.clear;
6631 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6632 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006633 timer T_wait := 2.0;
6634 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006635 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006636 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006637 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006638 [] T_wait.timeout {
6639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6640 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6641 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006642 }
6643 /* try to activate this PDCH from the PCU point of view */
6644 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6645 /* FIXME: is there a response? */
6646
6647 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6648}
6649
6650private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6651runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006652 /* Send RSL CHAN REL (deactivate) */
6653 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6654 PCU.clear;
6655 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006656 timer T_wait := 2.0;
6657 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006658 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006659 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006660 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006661 [] T_wait.timeout {
6662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6663 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6664 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006665 }
6666 /* Emulate PCU asking BTS to deactivate PDCH */
6667 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6668 alt {
6669 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6670 setverdict(pass);
6671 }
6672 [] RSL.receive { repeat; }
6673 }
6674}
6675
6676/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006677private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006678 var PCUIF_Message first_info;
6679 var integer ts_nr := g_chan_nr.tn;
6680 var integer trx_nr := 0;
6681 var integer bts_nr := 0;
6682 var integer pcu_conn_id := -1;
6683
6684 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6685
6686 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6687 f_sleep(3.0);
6688 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6689
6690 setverdict(pass);
6691
6692}
6693testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6694 var ConnHdlrPars pars;
6695 var ConnHdlr vc_conn;
6696 f_init();
6697
6698 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6699 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6700 vc_conn.done;
6701}
6702
6703/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006704private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006705 var PCUIF_Message first_info;
6706 var integer ts_nr := g_chan_nr.tn;
6707 var integer trx_nr := 0;
6708 var integer bts_nr := 0;
6709 var integer pcu_conn_id := -1;
6710
6711 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6712
6713 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6714 "RSL CHAN ACT");
6715 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6716 "RF CHAN REL", true);
6717 setverdict(pass);
6718}
6719testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6720 var ConnHdlrPars pars;
6721 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006722 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006723
6724 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6725 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6726 vc_conn.done;
6727}
6728
6729/* 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 +07006730private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006731 var PCUIF_Message first_info;
6732 var integer ts_nr := g_chan_nr.tn;
6733 var integer trx_nr := 0;
6734 var integer bts_nr := 0;
6735 var integer pcu_conn_id := -1;
6736
6737 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6738
6739 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6740 "RSL CHAN ACT");
6741
6742 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6743 alt {
6744 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6745 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006747 }
6748 [] RSL.receive { repeat; }
6749 }
6750
6751 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6752 "RF CHAN REL", true);
6753 setverdict(pass);
6754}
6755testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6756 var ConnHdlrPars pars;
6757 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006758 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006759
6760 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6761 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6762 vc_conn.done;
6763}
6764
6765/* 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 +07006766private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006767 var PCUIF_Message first_info;
6768 var integer ts_nr := g_chan_nr.tn;
6769 var integer trx_nr := 0;
6770 var integer bts_nr := 0;
6771 var integer pcu_conn_id := -1;
6772
6773 /* register for the TCH/F channel number */
6774 f_rslem_register(0, g_chan_nr);
6775
6776 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6777
6778 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6779
6780 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6781 "RSL CHAN ACT");
6782
6783 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6784
6785 setverdict(pass);
6786}
6787testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6788 var ConnHdlrPars pars;
6789 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006790 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006791
6792 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6793 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6794 vc_conn.done;
6795}
6796
6797
Harald Welte0472ab42018-03-12 15:02:26 +01006798/***********************************************************************
6799 * LAPDm / RLL related
6800 ***********************************************************************/
6801
6802private function f_tx_lapdm(template (value) LapdmFrame l,
6803 template (value) RslLinkId link_id) runs on ConnHdlr {
6804 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006805 var template (value) SacchL1Header l1h;
6806
6807 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006808 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006809 /* Compose dummy L1 header */
6810 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6811 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 +02006812 } else {
6813 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006814 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 +01006815 }
Harald Welte0472ab42018-03-12 15:02:26 +01006816}
6817
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006818friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006819 uint3_t sapi,
6820 RslLinkId link_id,
6821 octetstring l3,
6822 boolean exp
6823}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006824friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006825friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6826 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006827 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006828 sapi := sapi,
6829 link_id := id,
6830 l3 := l3,
6831 exp := exp
6832}
6833
6834/* execute the same callback function with a set of different parameters (tcs) on a
6835 * variety of logical channels */
6836private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6837 var ConnHdlrPars pars;
6838 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006839 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006840
6841 /* test on each of the channels we have */
6842 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6843 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6844
6845 /* test each of the test cases on the current channel */
6846 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6847 pars.spec.rll := tcs[j];
6848 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6849 vc_conn := f_start_handler(fn, pars);
6850 vc_conn.done;
6851 }
6852 }
6853
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006855}
6856
6857/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6858private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6859 var RllTestCase tc := g_pars.spec.rll;
6860 timer T := 3.0;
6861
6862 f_l1_tune(L1CTL);
6863 RSL.clear;
6864
6865 /* activate the logical channel */
6866 f_est_dchan();
6867 L1CTL.clear;
6868
6869 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6870 T.start;
6871 alt {
6872 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6873 if (tc.exp) {
6874 setverdict(pass);
6875 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006877 }
6878 }
6879 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6880 if (tc.exp) {
6881 setverdict(pass);
6882 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006884 }
6885 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006886 /* We also expect to receive the measurements */
6887 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006888 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006890 }
6891 [not tc.exp] T.timeout {
6892 setverdict(pass);
6893 }
6894 }
6895
6896 f_rsl_chan_deact();
6897 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6898 f_rslem_unregister(0, g_chan_nr);
6899}
6900testcase TC_rll_est_ind() runs on test_CT {
6901 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006902 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006903 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006904 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006905 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006906 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006907 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6908 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006909 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006910 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006911 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006912 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006913 };
6914 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6915}
6916
6917/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6918private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6919 var RllTestCase tc := g_pars.spec.rll;
6920 var L1ctlDlMessage dl;
6921 timer T := 3.0;
6922
6923 f_l1_tune(L1CTL);
6924 RSL.clear;
6925
6926 /* activate the logical channel */
6927 f_est_dchan();
6928 L1CTL.clear;
6929
6930 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6931 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6932 T.start;
6933 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006934 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006935 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006937 }
6938 }
6939
6940 f_rsl_chan_deact();
6941 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6942 f_rslem_unregister(0, g_chan_nr);
6943}
6944testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6945 var RllTestCases tcs := {
6946 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006947 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006948 };
6949 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6950}
6951testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6952 var RllTestCases tcs := {
6953 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006954 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006955 }
6956 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6957}
6958
6959/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006960friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006961 var L1ctlDlMessage dl;
6962 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6963 var LapdmFrame lapdm;
6964 var octetstring l2 := dl.payload.data_ind.payload;
6965 if (dl.dl_info.link_id.c == SACCH) {
6966 /* remove L1 header */
6967 l2 := substr(l2, 2, lengthof(l2)-2);
6968 }
6969 if (ischosen(exp.ab)) {
6970 lapdm.ab := dec_LapdmFrameAB(l2);
6971 } else if (ischosen(exp.b4)) {
6972 lapdm.b4 := dec_LapdmFrameB4(l2);
6973 } else if (ischosen(exp.bbis)) {
6974 lapdm.bbis := dec_LapdmFrameBbis(l2);
6975 }
6976 log("Rx LAPDm ", lapdm);
6977 if (match(lapdm, exp)) {
6978 setverdict(pass);
6979 } else {
6980 repeat;
6981 }
6982 }
6983 [] L1CTL.receive { repeat; }
6984}
6985private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6986 timer T := t;
6987 T.start;
6988 alt {
6989 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006991 }
6992 [] as_l1_exp_lapdm(exp);
6993 }
6994}
6995
6996/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6997private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6998 /* send SABM from MS -> BTS */
6999 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7000 /* expect RLL EST IND on Abis */
7001 alt {
7002 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7003 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7004 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007006 }
7007 [] RSL.receive { repeat; }
7008 }
7009 /* expect UA from BTS -> MS */
7010 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7011}
7012
7013/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7014private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7015 var RllTestCase tc := g_pars.spec.rll;
7016
7017 f_l1_tune(L1CTL);
7018 RSL.clear;
7019
7020 /* activate the logical channel */
7021 f_est_dchan();
7022 L1CTL.clear;
7023
7024 /* first establish the link-layer */
7025 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7026
7027 /* then send the DISC */
7028 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7029 /* ... and expect the REL IND on the RSL side */
7030 alt {
7031 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7032 setverdict(pass);
7033 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007034 /* We also expect to receive the measurements */
7035 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007036 }
7037
7038 /* release the channel */
7039 f_rsl_chan_deact();
7040 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7041 f_rslem_unregister(0, g_chan_nr);
7042}
7043testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7044 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007045 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007046 };
7047 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7048}
7049
7050testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7051 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007052 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007053 };
7054 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7055}
7056testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7057 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007058 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007059 };
7060 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7061}
7062testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7063 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007064 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007065 };
7066 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7067}
7068
7069/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7070private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7071 var RllTestCase tc := g_pars.spec.rll;
7072 f_l1_tune(L1CTL);
7073 RSL.clear;
7074
7075 /* activate the logical channel */
7076 f_est_dchan();
7077 L1CTL.clear;
7078
7079 /* first establish the link-layer */
7080 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7081
7082 /* then send the REL REQ via RSL */
7083 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7084 /* ... and expect the DISC on the Um side */
7085 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007086 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007087 /* FIXME: send a UA in resposne to the DISC */
7088 }
7089 }
7090
7091 /* release the channel */
7092 f_rsl_chan_deact();
7093 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7094 f_rslem_unregister(0, g_chan_nr);
7095}
7096testcase TC_rll_rel_req() runs on test_CT {
7097 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007098 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7099 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7100 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7101 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007102 };
7103 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7104}
7105
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007106/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007107testcase TC_rll_data_req() runs on test_CT {
7108}
7109
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007110/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007111testcase TC_rll_data_ind() runs on test_CT {
7112}
7113
7114/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7115private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7116 var RllTestCase tc := g_pars.spec.rll;
7117
7118 f_l1_tune(L1CTL);
7119 RSL.clear;
7120
7121 f_est_dchan();
7122 L1CTL.clear;
7123
7124 /* Send UNITDATA REQ on RSL side */
7125 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7126 /* Expect it to arrive on the other side */
7127 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007128 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007129 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007130 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007131 }
7132
7133 /* release the channel */
7134 f_rsl_chan_deact();
7135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7136 f_rslem_unregister(0, g_chan_nr);
7137}
7138testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7139 var octetstring l3 := f_rnd_octstring(15);
7140 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007141 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7142 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007143 };
7144 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7145}
7146testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7147 var octetstring l3 := f_rnd_octstring(19);
7148 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007149 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7150 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007151 };
7152 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7153}
7154
7155/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7156private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7157 var RllTestCase tc := g_pars.spec.rll;
7158
7159 f_l1_tune(L1CTL);
7160 RSL.clear;
7161
7162 f_est_dchan();
7163 L1CTL.clear;
7164
7165 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007166 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007167 /* Expdct RLL UNITDATA IND on RSL side */
7168 alt {
7169 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7170 setverdict(pass);
7171 }
7172 [] RSL.receive { repeat; }
7173 }
7174
7175 /* release the channel */
7176 f_rsl_chan_deact();
7177 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7178 f_rslem_unregister(0, g_chan_nr);
7179}
7180testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007181 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007182 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007183 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7184 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007185 };
7186 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7187}
7188testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7189 var octetstring l3 := f_rnd_octstring(18);
7190 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007191 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7192 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007193 };
7194 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7195}
7196
Harald Weltee613f962018-04-18 22:38:16 +02007197/***********************************************************************
7198 * Encryption Related
7199 ***********************************************************************/
7200
7201/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007202private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007203 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7204 if (link_id.c == SACCH) {
7205 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7206 } else {
7207 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7208 }
7209}
7210
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007211/* Expect (or not expect) other kinds of messages */
7212private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7213 [exp_any] RSL.receive { repeat; }
7214 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007216 }
7217}
7218
Harald Weltee613f962018-04-18 22:38:16 +02007219/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007220private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007221 RslLinkId link_id,
7222 octetstring l3,
7223 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007224 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007225) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007226 timer T := 3.0;
7227 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7228 T.start;
7229 /* Expect RLL UNITDATA IND on RSL side */
7230 alt {
7231 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7232 setverdict(pass);
7233 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007234 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007235 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007236 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007238 }
Harald Weltee613f962018-04-18 22:38:16 +02007239 }
7240}
7241
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007242/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7243private function f_data_mo(
7244 RslLinkId link_id,
7245 boolean p, uint3_t nr, uint3_t ns,
7246 octetstring l3,
7247 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007248 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007249) runs on ConnHdlr {
7250 timer T := 3.0;
7251 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7252 T.start;
7253 /* Expect RLL DATA IND on RSL side */
7254 alt {
7255 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7256 setverdict(pass);
7257 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007258 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007259 [] as_rsl_any_ind(exp_any);
7260 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007262 }
7263 }
7264}
7265
Harald Weltee613f962018-04-18 22:38:16 +02007266/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007267private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007268 f_l1_tune(L1CTL);
7269 f_est_dchan(true);
7270
7271 /* now we actually need to transmit some data both ways to check if the encryption works */
7272 var L1ctlDlMessage dl;
7273
Stefan Sperling603d98e2018-07-25 16:47:28 +02007274 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007275 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7276
7277 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7278 f_unitdata_mt(link_id, l3);
7279
7280 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7281 f_unitdata_mo(link_id, l3);
7282
7283 /* release the channel */
7284 f_rsl_chan_deact();
7285 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7286 f_rslem_unregister(0, g_chan_nr);
7287}
7288testcase TC_chan_act_a51() runs on test_CT {
7289 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7290 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7291 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7292}
7293testcase TC_chan_act_a52() runs on test_CT {
7294 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7295 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7296 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7297}
7298testcase TC_chan_act_a53() runs on test_CT {
7299 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7300 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7301 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7302}
Eric Wildb9260392021-05-15 19:48:22 +02007303testcase TC_chan_act_a54() runs on test_CT {
7304 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7305 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7306 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7307}
Harald Weltee613f962018-04-18 22:38:16 +02007308
Eric Wildf1827a72019-05-28 17:37:35 +02007309/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7310 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 +07007311private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007312 f_l1_tune(L1CTL);
7313 f_est_dchan(true);
7314
7315 /* now we actually need to transmit some data both ways to check if the encryption works */
7316 var L1ctlDlMessage dl;
7317
7318 var octetstring l3 := f_rnd_octstring(20);
7319 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7320
7321 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7322 f_unitdata_mt(link_id, l3);
7323
7324 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7325 f_unitdata_mo(link_id, l3);
7326
7327 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007328 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007329
7330 /* modify key to break proper encryption */
7331 g_pars.encr.key := f_rnd_octstring(8);
7332 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7333 rsl.ies := rsl.ies & { ei };
7334 RSL.send(rsl);
7335
7336 timer T0 := 1.0;
7337 T0.start;
7338 /* Expect RSL MODIFY ACK */
7339 alt {
7340 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7341 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7343 }
7344 [] T0.timeout {
7345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7346 }
7347 }
7348
7349 var octetstring l3msg := f_rnd_octstring(15);
7350 timer T1 := 3.0;
7351 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7352 due to broken encryption */
7353 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7354 T1.start;
7355 alt {
7356 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7358 }
7359 [] T1.timeout {
7360 setverdict(pass);
7361 }
7362 }
7363
7364 /* release the channel */
7365 f_rsl_chan_deact();
7366 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7367 f_rslem_unregister(0, g_chan_nr);
7368}
7369testcase TC_rsl_modify_encr() runs on test_CT {
7370 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7371 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7372 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7373}
Harald Weltee613f962018-04-18 22:38:16 +02007374
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007375/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007376private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007377runs on test_CT {
7378 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7379 var ASP_RSL_Unitdata ud;
7380 timer T;
7381
7382 /* Intave is 6 SACCH periods by default */
7383 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7384
7385 T.start(Tval);
7386 alt {
7387 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7388 setverdict(pass);
7389 }
7390 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7391 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7392 }
7393 [] RSL_CCHAN.receive { repeat; }
7394 [] T.timeout {
7395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7396 "Timeout waiting for RF RESource INDication");
7397 }
7398 }
7399}
7400testcase TC_rsl_rf_resource_ind() runs on test_CT {
7401 var RSL_ResourceInfo info := { };
7402
7403 f_init(trx_nr := 0);
7404
7405 f_init_l1ctl();
7406 f_l1_tune(L1CTL);
7407
7408 /* g_AllChannels contains all logical channels */
7409 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7410 var RslChannelNr chan_nr := g_AllChannels[i];
7411
7412 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7413 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7414 { continue; }
7415
7416 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7417 }
7418
7419 /* Align to the first interference report */
7420 f_TC_rsl_rf_resource_ind(?);
7421
7422 /* Test 4 consecutive messages */
7423 for (var integer i := 0; i < 4; i := i + 1) {
7424 f_TC_rsl_rf_resource_ind(info);
7425 }
7426
7427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7428}
7429
Harald Weltee613f962018-04-18 22:38:16 +02007430/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007431private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007432 /* L3 payload doesn't matter, as it is passed transparently */
7433 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7434 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7435 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7436
7437 f_l1_tune(L1CTL);
7438
7439 /* first establish a dedicated channel in the clear */
7440 f_est_dchan(false);
7441
7442 /* Establish ABM */
7443 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7444
7445 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7446 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7447 /* expect the L3 to arrive still unencrypted on the MS side */
7448 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7449
7450 /* configure L1 to apply ciphering */
7451 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7452 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7453
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007454 /* send first ciphered I-frame in response and expect it on RSL */
7455 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007456
7457 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7458 * and hence enable encryption also on the downlink */
7459
7460 /* expect bi-directional communication work in encrypted mode */
7461 f_unitdata_mo(link_id, f_rnd_octstring(15));
7462 f_unitdata_mt(link_id, f_rnd_octstring(15));
7463
7464 /* release the channel */
7465 f_rsl_chan_deact();
7466 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7467 f_rslem_unregister(0, g_chan_nr);
7468}
7469testcase TC_encr_cmd_a51() runs on test_CT {
7470 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7471 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7472 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7473}
7474testcase TC_encr_cmd_a52() runs on test_CT {
7475 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7476 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7477 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7478}
7479testcase TC_encr_cmd_a53() runs on test_CT {
7480 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7481 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7482 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7483}
Eric Wildb9260392021-05-15 19:48:22 +02007484testcase TC_encr_cmd_a54() runs on test_CT {
7485 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7486 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7487 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7488}
Harald Weltee613f962018-04-18 22:38:16 +02007489
7490private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7491 var LapdmFrame lf;
7492 var octetstring reenc;
7493
7494 /* decode the LAPDm frame */
7495 if (ischosen(exp_match.ab)) {
7496 lf.ab := dec_LapdmFrameAB(enc);
7497 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007499 }
7500
7501 /* check if decoder result matches expectation */
7502 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007504 } else {
7505 log(name, ": matched");
7506 setverdict(pass);
7507 }
7508
7509 /* test if re-encoded frame equals original input */
7510 reenc := enc_LapdmFrame(lf);
7511 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007513 } else {
7514 setverdict(pass);
7515 }
7516}
7517
7518testcase TC_lapdm_selftest() runs on test_CT {
7519 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7520 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7521 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7522 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7523 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7524 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7525 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7526}
7527
Stefan Sperling4880be42018-08-07 18:12:59 +02007528/***********************************************************************
7529 * DTX Related (see GSM 05.08, section 8.3)
7530 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007531private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007532 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007533 var GsmFrameNumber first_fn;
7534 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007535 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007536 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007537 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7538 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007539 const integer frame_dtx_tchf_mod := 104;
7540 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7541 * which operates in terms of blocks rather than frames. */
7542 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7543 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007544 timer T := 5.0;
7545
7546 f_l1_tune(L1CTL);
7547 RSL.clear;
7548 L1CTL.clear;
7549
7550 /* activate TCHF signalling channel */
7551 f_est_dchan(false);
7552
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007553 /* A template for matching dummy LAPDm func=UA frames */
7554 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7555 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7556 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7557
Stefan Sperling4880be42018-08-07 18:12:59 +02007558 T.start;
7559 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007560 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007561 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007562
7563 if (is_first_frame) {
7564 is_first_frame := false;
7565 first_fn := dl.dl_info.frame_nr;
7566 }
7567
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007568 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007569 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007570 T.stop;
7571 f_rsl_chan_deact();
7572 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007573
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007574 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7575 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007576
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007577 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007578 setverdict(fail, "Not enough fill frames received: ",
7579 nfill_frames, " out of ", expected_fill_frames);
7580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007581 } else {
7582 setverdict(pass);
7583 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007584 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007585 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7586 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7587 * we should only see the subset of frames numbers which correspond to a block boundary.
7588 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7589 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7590 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007591 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007592 repeat;
7593 }
7594 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007595 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7596 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7597 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007598 f_rsl_chan_deact();
7599 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007600 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007601 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007602 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007603 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007604 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007605
7606 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007607 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7608 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007609 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7610 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7611 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007612 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7613 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007614 case else {
7615 /* This shall not happen, just to be sure */
7616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7617 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007618 }
7619
7620 f_rsl_chan_deact();
7621 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007622
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007623 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007624 setverdict(pass);
7625 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007626 setverdict(fail, "Not enough fill frames received: ",
7627 nfill_frames, " out of ", expected_fill_frames);
7628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007629 }
7630 } else {
7631 repeat;
7632 }
7633 }
7634 }
7635 [] L1CTL.receive { repeat; }
7636 [] T.timeout {
7637 f_rsl_chan_deact();
7638 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007640 }
7641 }
7642}
7643
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007644private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007645 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007646 var ConnHdlr vc_conn;
7647 var ConnHdlrPars pars;
7648 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007649 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007650 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007651 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007652 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007653 if (dtxd) {
7654 if (i >= 4) { /* DTX is only allowed on TCH/F */
7655 break;
7656 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007657 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007658 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007659 vc_conn.done;
7660 }
7661}
7662
7663/* Verify that L2 fill frames are sent on TCH in signaling mode if
7664 * there is nothing to transmit while DTX is disabled on downlink. */
7665testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7666 f_tch_sign_l2_fill_frame(false);
7667}
7668
7669/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7670 * there is nothing to transmit while DTX is enabled on downlink. */
7671testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7672 f_tch_sign_l2_fill_frame(true);
7673}
Harald Welte0472ab42018-03-12 15:02:26 +01007674
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007675testcase TC_chopped_ipa_ping() runs on test_CT {
7676 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7677}
7678
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007679testcase TC_chopped_ipa_payload() runs on test_CT {
7680 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7681}
7682
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007683
7684/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7685 * Return value: Measurement Report to be sent (encoded octetstring). */
7686type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7687 runs on ConnHdlr return octetstring;
7688
7689private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7690runs on ConnHdlr {
7691 var L1ctlDlMessage l1_dl;
7692 var SacchL1Header l1h;
7693 var octetstring l2;
7694
7695 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7696 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7697 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7698 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7699
7700 /* Pass it to the user specified call-back function */
7701 l2 := cb.apply(l1h, num_blocks);
7702 /* Send a Measurement Report generated by the call-back */
7703 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7704 l1_dl.dl_info.link_id,
7705 l1h, l2));
7706
7707 /* Shall we keep going? */
7708 num_blocks := num_blocks - 1;
7709 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7710 if (num_blocks > 0) { repeat; }
7711 }
7712 [] L1CTL.receive { repeat; }
7713}
7714
7715private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7716runs on ConnHdlr return octetstring {
7717 /* Command the L1 to apply received parameters */
7718 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7719
7720 /* Dummy measurement report (the results are invalid) */
7721 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7722}
7723
7724private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7725runs on ConnHdlr return octetstring {
7726 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7727 setverdict(fail, "Unexpected MS Power level change: ",
7728 g_pars.l1_pars.ms_power_level, " -> ",
7729 l1h.ms_power_lvl);
7730 }
7731
7732 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7733}
7734
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007735private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7736runs on ConnHdlr return octetstring {
7737 /* UL RSSI oscillation driven by SACCH block number */
7738 if (num_blocks rem 2 == 0) {
7739 f_trxc_fake_rssi(-100);
7740 } else {
7741 f_trxc_fake_rssi(-50);
7742 }
7743
7744 /* Make sure that MS power level remains constant */
7745 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7746}
7747
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007748/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7749private function f_TC_ms_pwr_ctrl_constant(charstring id)
7750runs on ConnHdlr {
7751 var integer num_blocks := 8;
7752 timer T := int2float(num_blocks);
7753
7754 f_l1_tune(L1CTL);
7755 RSL.clear;
7756
7757 /* These IEs are needed for autonomous MS power control */
7758 var template (value) RSL_IE_List ies := {
7759 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7760 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7761 }),
7762 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7763 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7764 })
7765 };
7766
7767 /* Ensure that 'rx-current' equals 'rx-target' */
7768 f_trxc_fake_rssi(mp_uplink_power_target);
7769
7770 /* Establish a dedicated channel */
7771 f_est_dchan(more_ies := valueof(ies));
7772
7773 L1CTL.clear;
7774 T.start;
7775 alt {
7776 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7777 [] T.timeout {
7778 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7779 num_blocks, " were not handled");
7780 }
7781 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007782
7783 /* Release the channel */
7784 f_rsl_chan_deact();
7785 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007786}
7787testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7788 var ConnHdlr vc_conn;
7789 var ConnHdlrPars pars;
7790
7791 f_init();
7792
7793 /* Explicitly configure the Uplink power target (in dBm) */
7794 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7795
7796 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7797 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7798 log(testcasename(), ": starting on ", pars.chan_nr);
7799
7800 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7801 pars, trxc_comp := true);
7802 vc_conn.done;
7803 }
7804
7805 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7807}
7808
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007809/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7810private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7811runs on ConnHdlr {
7812 var integer num_blocks := 16;
7813 timer T := int2float(num_blocks);
7814
7815 f_l1_tune(L1CTL);
7816 RSL.clear;
7817
7818 /* These IEs are needed for autonomous MS power control */
7819 var template (value) RSL_IE_List ies := {
7820 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7821 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7822 }),
7823 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7824 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7825 })
7826 };
7827
7828 /* Ensure that 'rx-current' equals 'rx-target' */
7829 f_trxc_fake_rssi(mp_uplink_power_target);
7830
7831 /* Establish a dedicated channel */
7832 f_est_dchan(more_ies := valueof(ies));
7833
7834 L1CTL.clear;
7835 T.start;
7836 alt {
7837 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7838 [] T.timeout {
7839 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7840 num_blocks, " were not handled");
7841 }
7842 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007843
7844 /* Release the channel */
7845 f_rsl_chan_deact();
7846 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007847}
7848testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7849 var ConnHdlr vc_conn;
7850 var ConnHdlrPars pars;
7851
7852 f_init();
7853
7854 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7855 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7856 /* Explicitly configure the Uplink power range (target and delte) */
7857 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7858 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7859
7860 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7861 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7862 log(testcasename(), ": starting on ", pars.chan_nr);
7863
7864 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7865 pars, trxc_comp := true);
7866 vc_conn.done;
7867 }
7868
7869 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7871}
7872
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007873private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7874 var template L1ctlDlMessage tr_bad_frame;
7875 var L1ctlDlMessage l1_dl;
7876 timer T := 8.0;
7877
7878 f_l1_tune(L1CTL);
7879 RSL.clear;
7880
7881 f_est_dchan();
7882
7883 /* There may be a few errors right after the channel activation */
7884 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7885 L1CTL.clear;
7886
7887 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7888 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7889 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7890 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7891 tr_bad_frame.payload := ?;
7892
7893 T.start;
7894 alt {
7895 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7896 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7897 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7898 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7899 }
7900 [] as_l1_sacch();
7901 [] L1CTL.receive { repeat; }
7902 [] T.timeout {
7903 /* We're done, break the loop */
7904 setverdict(pass);
7905 }
7906 }
7907
7908 f_rsl_chan_deact();
7909 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7910}
7911testcase TC_speech_no_rtp_tchf() runs on test_CT {
7912 var ConnHdlr vc_conn;
7913 var ConnHdlrPars pars;
7914
7915 f_init();
7916
7917 /* TS1, TCH/F, V1 (FR codec) */
7918 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7919 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7920 vc_conn.done;
7921}
7922testcase TC_speech_no_rtp_tchh() runs on test_CT {
7923 var ConnHdlr vc_conn;
7924 var ConnHdlrPars pars;
7925
7926 f_init();
7927
7928 /* TS5, TCH/H, V1 (HR codec) */
7929 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7930 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7931 vc_conn.done;
7932}
7933
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007934/* Verify handling of Downlink and Uplink speech frames */
7935private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7936 var L1ctlDlMessage l1_dl;
7937 var PDU_RTP rtp_pdu;
7938 var octetstring pl;
7939 timer Td, Tu;
7940
7941 f_l1_tune(L1CTL);
7942 f_est_dchan();
7943
7944 /* Activate the RTP emulation */
7945 pl := f_rnd_octstring(6);
7946 f_rtpem_activate(pl);
7947
7948 /* Give the scheduler some time to fill up the buffers */
7949 f_sleep(2.0);
7950 L1CTL.clear;
7951 RSL.clear;
7952
7953 /* Make sure that Downlink frames are received at the UE */
7954 Td.start(2.0);
7955 alt {
7956 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7957 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7958 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7959 l1_dl.payload.traffic_ind.data));
7960 setverdict(pass);
7961 }
7962 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7963 setverdict(fail, "Rx unexpected Downlink speech frame ",
7964 "(", l1_dl.payload.traffic_ind.data, ") ",
7965 "expected (", pl, ")");
7966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7967 }
7968 [] as_l1_sacch();
7969 [] L1CTL.receive { repeat; }
7970 [] Td.timeout {
7971 setverdict(fail, "Timeout waiting for Downlink speech frames");
7972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7973 }
7974 }
7975
7976 /* Make sure that Uplink frames are received at the BTS */
7977 RTPEM_DATA.clear;
7978 Tu.start(2.0);
7979 alt {
7980 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7981 if (rtp_pdu.data != pl)
7982 { repeat; }
7983 }
7984 [] RTPEM_DATA.receive { repeat; }
7985 [] Tu.timeout {
7986 setverdict(fail, "Timeout waiting for Uplink speech frames");
7987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7988 }
7989 }
7990
7991 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7992 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7993 f_rsl_chan_deact();
7994 f_rslem_unregister(0, g_chan_nr);
7995}
7996testcase TC_speech_rtp_tchf() runs on test_CT {
7997 var ConnHdlr vc_conn;
7998 var ConnHdlrPars pars;
7999
8000 f_init();
8001
8002 /* TS1, TCH/F, V1 (FR codec) */
8003 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8004 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8005 vc_conn.done;
8006
8007 /* TS1, TCH/F, V2 (EFR codec) */
8008 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8009 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8010 vc_conn.done;
8011
8012 /* TODO: also test V3 (AMR codec) */
8013
8014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8015}
8016testcase TC_speech_rtp_tchh() runs on test_CT {
8017 var ConnHdlr vc_conn;
8018 var ConnHdlrPars pars;
8019
8020 f_init();
8021
8022 /* TS5, TCH/H0, V1 (HR codec) */
8023 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8024 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8025 vc_conn.done;
8026
8027 /* TODO: also test V3 (AMR codec) */
8028
8029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8030}
8031
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008032private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8033 var GsmFrameNumber fn;
8034 var ChannelDescription ch_desc;
8035 var integer ra := 23;
8036
8037 f_l1_tune(L1CTL);
8038 RSL.clear;
8039
8040 /* Send RACH request and wait for ChanReq */
8041 fn := f_rach_req_wait_chan_rqd(ra);
8042
8043 /* The BSC already sends the Immediate Assignment, before the channel is active.
8044 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8045 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8046 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8047 if (g_pars.fhp.enabled) {
8048 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8049 } else {
8050 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8051 }
8052 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8053 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8054
8055 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8056 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8057 var L1ctlDlMessage dl;
8058 var GsmRrMessage rr;
8059
8060 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8061 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8062 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8063 rr_imm_ass.payload.imm_ass.chan_desc := *;
8064
8065 timer T := 1.0;
8066 T.start;
8067 alt {
8068 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8069 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8070 if (match(rr, rr_imm_ass)) {
8071 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8072 mtc.stop;
8073 } else {
8074 repeat;
8075 }
8076 }
8077 [] L1CTL.receive { repeat; }
8078 [] T.timeout;
8079 }
8080 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8081 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8082
8083 /* Now expect the IMM ASS on Um */
8084 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8085 setverdict(pass);
8086
8087 /* Release the channel */
8088 f_rsl_chan_deact();
8089 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8090}
8091
8092testcase TC_early_immediate_assignment() runs on test_CT {
8093 var ConnHdlr vc_conn;
8094 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8095 f_init();
8096 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8097 vc_conn.done;
8098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8099}
8100
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008101private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8102 var integer ra := oct2int(f_rnd_ra_cs());
8103 var ChannelDescription ch_desc;
8104
8105 /* Tune the MS to BCCH */
8106 f_l1_tune(L1CTL);
8107
8108 /* Send RACH request and wait for ChanReq */
8109 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8110
8111 /* Activate channel on the BTS side */
8112 f_rsl_chan_act(g_pars.chan_mode);
8113
8114 /* Craft channel description (with or without frequency hopping parameters) */
8115 if (g_pars.fhp.enabled) {
8116 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8117 } else {
8118 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8119 }
8120
8121 /* Send IMM.ASS via CCHAN */
8122 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8123 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8124
8125 /* Receive IMM.ASS on the MS side */
8126 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8127
8128 /* Match the Channel Description IE in received IMM.ASS */
8129 if (not match(imm_ass.chan_desc, ch_desc)) {
8130 setverdict(fail, "Channel Description IE does not match");
8131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8132 }
8133
8134 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8135 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8136
8137 /* Expect SACCH frames on Downlink */
8138 L1CTL.clear;
8139 f_exp_sacch(true);
8140
8141 /* We're done, deactivate and release */
8142 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8143 f_rsl_chan_deact();
8144}
8145testcase TC_est_dchan() runs on test_CT {
8146 var ConnHdlr vc_conn;
8147 var ConnHdlrPars pars;
8148
8149 f_init();
8150
8151 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8152 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8153 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8154 vc_conn.done;
8155 }
8156
8157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8158}
8159
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008160private type record TopTestCase {
8161 RSL_IE_BS_Power bs_power,
8162 RSL_IE_OSMO_TopAcchCap top_cap,
8163 record of TopTestStep steps
8164};
8165private type record TopTestStep {
8166 MeasurementResults meas_res optional,
8167 GsmRxLev overpower_sacch,
8168 GsmRxLev overpower_facch
8169};
8170
8171private function f_rxlev_match(template (present) RslLinkId link_id,
8172 template (present) GsmRxLev rxlev)
8173runs on ConnHdlr {
8174 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8175 if (not match(dl.dl_info.rx_level, rxlev)) {
8176 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8177 " does not match expected RxLev := ", rxlev);
8178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8179 }
8180}
8181
8182private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8183 var TopTestCase tc := g_pars.spec.top;
8184 var GsmRxLev rxlev_dcch;
8185 var L1ctlDlMessage dl;
8186
8187 /* Wait for Pau ramping to complete */
8188 f_sleep(6.0);
8189
8190 f_l1_tune(L1CTL);
8191 L1CTL.clear;
8192 RSL.clear;
8193
8194 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8195 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8196 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8197
8198 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8199 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8200
8201 /* Additional IEs for the CHANnel ACTIVation message */
8202 var template (value) RSL_IE_List ies := {
8203 /* Employ BS power control in static mode */
8204 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8205 bs_power := tc.bs_power
8206 }),
8207 /* Indicate the given Temporary Overpower capability */
8208 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8209 top_acch_cap := tc.top_cap
8210 })
8211 };
8212
8213 /* Establish a dedicated channel */
8214 f_est_dchan(more_ies := valueof(ies));
8215
8216 /* Give it some time to stabilize */
8217 f_sleep(0.480 * 2.0);
8218 L1CTL.clear;
8219 RSL.clear;
8220
8221 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8222 var TopTestStep step := tc.steps[i];
8223 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8224 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8225
8226 log("Executing step[", i, "] := ", step);
8227
8228 /* Send RR Measurement Report (if present) */
8229 if (ispresent(step.meas_res)) {
8230 f_transceive_meas_rep(step.meas_res);
8231 f_sleep(0.480 * 2.0);
8232 L1CTL.clear;
8233 }
8234
8235 /* Check RxLev on both FACCH and SACCH */
8236 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8237 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8238
8239 setverdict(pass);
8240 }
8241}
8242testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8243 var ConnHdlrPars pars;
8244 var ConnHdlr vc_conn;
8245
8246 f_init();
8247
8248 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008249 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008250 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8251 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8252 steps := {
8253 /* Channel established, no overpower */
8254 { meas_res := omit,
8255 overpower_sacch := 0, overpower_facch := 0 },
8256
8257 /* Worst possible RxQual value, overpower of 4dB */
8258 { meas_res := ts_MeasurementResults(rxq_f := 7),
8259 overpower_sacch := 4, overpower_facch := 4 },
8260 /* Worst possible RxQual value, disabling overpower */
8261 { meas_res := ts_MeasurementResults(rxq_f := 0),
8262 overpower_sacch := 0, overpower_facch := 0 },
8263
8264 /* Lower threshold not reached, no overpower */
8265 { meas_res := ts_MeasurementResults(rxq_f := 1),
8266 overpower_sacch := 0, overpower_facch := 0 },
8267 /* Lower threshold not reached, no overpower */
8268 { meas_res := ts_MeasurementResults(rxq_f := 2),
8269 overpower_sacch := 0, overpower_facch := 0 },
8270 /* Lower threshold reached, overpower of 4dB */
8271 { meas_res := ts_MeasurementResults(rxq_f := 4),
8272 overpower_sacch := 4, overpower_facch := 4 },
8273 /* Upper threshold not reached, keeping overpower */
8274 { meas_res := ts_MeasurementResults(rxq_f := 3),
8275 overpower_sacch := 4, overpower_facch := 4 },
8276 /* Upper threshold reached, disabling overpower */
8277 { meas_res := ts_MeasurementResults(rxq_f := 2),
8278 overpower_sacch := 0, overpower_facch := 0 }
8279 }
8280 };
8281
8282 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8283 spec := { top := top }, trx_nr := 1));
8284 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8285 vc_conn.done;
8286
8287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8288}
8289testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8290 var ConnHdlrPars pars;
8291 var ConnHdlr vc_conn;
8292
8293 f_init();
8294
8295 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008296 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008297 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8298 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8299 steps := {
8300 /* Channel established, no overpower */
8301 { meas_res := omit,
8302 overpower_sacch := 0, overpower_facch := 0 },
8303
8304 /* Invalid measurement results, no overpower */
8305 { meas_res := ts_MeasurementResults(rxq_f := 7,
8306 rxq_s := 7,
8307 valid := false),
8308 overpower_sacch := 0, overpower_facch := 0 },
8309
8310 /* DTXu was in use, no overpower */
8311 { meas_res := ts_MeasurementResults(rxq_f := 7,
8312 rxq_s := 0,
8313 dtx_used := true),
8314 overpower_sacch := 0, overpower_facch := 0 },
8315 /* DTXu was in use, overpower of 4 dB */
8316 { meas_res := ts_MeasurementResults(rxq_f := 0,
8317 rxq_s := 7,
8318 dtx_used := true),
8319 overpower_sacch := 4, overpower_facch := 4 }
8320 }
8321 };
8322
8323 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8324 spec := { top := top }, trx_nr := 1));
8325 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8326 vc_conn.done;
8327
8328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8329}
8330testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8331 var ConnHdlrPars pars;
8332 var ConnHdlr vc_conn;
8333
8334 f_init();
8335
8336 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008337 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008338 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8339 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8340 rxqual := 0, /* always on */
8341 sacch_enable := false),
8342 steps := {
8343 /* Channel established, FACCH overpower */
8344 { meas_res := omit,
8345 overpower_sacch := 0, overpower_facch := 4 },
8346 /* MS indicates good RxQual, no difference */
8347 { meas_res := ts_MeasurementResults(rxq_f := 0),
8348 overpower_sacch := 0, overpower_facch := 4 },
8349 /* MS indicates bad RxQual, no difference */
8350 { meas_res := ts_MeasurementResults(rxq_f := 7),
8351 overpower_sacch := 0, overpower_facch := 4 }
8352 }
8353 };
8354
8355 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8356 spec := { top := top }, trx_nr := 1));
8357 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8358 vc_conn.done;
8359
8360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8361}
8362testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8363 var ConnHdlrPars pars;
8364 var ConnHdlr vc_conn;
8365
8366 f_init();
8367
8368 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008369 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008370 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8371 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8372 rxqual := 0, /* always on */
8373 facch_enable := false),
8374 steps := {
8375 /* Channel established, SACCH overpower */
8376 { meas_res := omit,
8377 overpower_sacch := 4, overpower_facch := 0 },
8378 /* MS indicates good RxQual, no difference */
8379 { meas_res := ts_MeasurementResults(rxq_f := 0),
8380 overpower_sacch := 4, overpower_facch := 0 },
8381 /* MS indicates bad RxQual, no difference */
8382 { meas_res := ts_MeasurementResults(rxq_f := 7),
8383 overpower_sacch := 4, overpower_facch := 0 }
8384 }
8385 };
8386
8387 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8388 spec := { top := top }, trx_nr := 1));
8389 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8390 vc_conn.done;
8391
8392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8393}
8394testcase TC_acch_overpower_limit() runs on test_CT {
8395 var ConnHdlrPars pars;
8396 var ConnHdlr vc_conn;
8397
8398 f_init();
8399
8400 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008401 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008402 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8403 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8404 rxqual := 0 /* always on */),
8405 steps := {
8406 /* Channel established, ACCH overpower of 2dB */
8407 { meas_res := omit,
8408 overpower_sacch := 2, overpower_facch := 2 },
8409 /* MS indicates good RxQual, no difference */
8410 { meas_res := ts_MeasurementResults(rxq_f := 0),
8411 overpower_sacch := 2, overpower_facch := 2 },
8412 /* MS indicates bad RxQual, no difference */
8413 { meas_res := ts_MeasurementResults(rxq_f := 7),
8414 overpower_sacch := 2, overpower_facch := 2 }
8415 }
8416 };
8417
8418 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8419 spec := { top := top }, trx_nr := 1));
8420 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8421 vc_conn.done;
8422
8423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8424}
8425
Harald Welte0472ab42018-03-12 15:02:26 +01008426/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8427/* protocol error as per 44.006 */
8428/* link layer failure (repetition of I-frame N200 times without ACK */
8429/* repetition of SABM or DISC N200 times without ACK */
8430/* receptiom of SABM in multi-frame established state */
8431
8432
Harald Welte68e495b2018-02-25 00:05:57 +01008433/* TODO Areas:
8434
8435* channel activation
8436** with BS_Power / MS_Power, bypassing power control loop
8437** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008438** with timing advance from initial activation on
8439* mode modify
8440** encryption
8441** multirate
8442* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008443** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008444* BS Power Control
8445* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008446* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008447** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008448* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008449** DATA_IND from BTS->PCU
8450** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008451
8452*/
Harald Welte70767382018-02-21 12:16:40 +01008453
8454control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008455 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008456 execute( TC_chan_act_stress() );
8457 execute( TC_chan_act_react() );
8458 execute( TC_chan_deact_not_active() );
8459 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008460 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008461 execute( TC_sacch_filling() );
8462 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008463 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008464 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008465 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008466 execute( TC_sacch_chan_act_ho_async() );
8467 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008468 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008469 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008470 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008471 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008472 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008473 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008474 execute( TC_rach_load_idle_thresh0() );
8475 execute( TC_rach_load_idle_below_thresh() );
8476 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008477 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008478 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008479 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008480 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008481 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008482 execute( TC_meas_res_sign_tchf() );
8483 execute( TC_meas_res_sign_tchh() );
8484 execute( TC_meas_res_sign_sdcch4() );
8485 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008486 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008487 execute( TC_meas_res_speech_tchf_sapi3() );
8488 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008489 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008490 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008491 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008492 execute( TC_rsl_bs_pwr_static_ass() );
8493 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008494 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008495 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008496 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008497 execute( TC_rsl_ms_pwr_dyn_up() );
8498 execute( TC_rsl_ms_pwr_dyn_down() );
8499 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8500 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008501 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008502 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008503 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008504 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008505 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008506 execute( TC_paging_imsi_80percent() );
8507 execute( TC_paging_tmsi_80percent() );
8508 execute( TC_paging_imsi_200percent() );
8509 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008510 execute( TC_rsl_protocol_error() );
8511 execute( TC_rsl_mand_ie_error() );
8512 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008513 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008514 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008515 execute( TC_si_sched_2bis() );
8516 execute( TC_si_sched_2ter() );
8517 execute( TC_si_sched_2ter_2bis() );
8518 execute( TC_si_sched_2quater() );
8519 execute( TC_si_sched_13() );
8520 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008521 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008522 execute( TC_ipa_crcx_twice_not_active() );
8523 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008524 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008525 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008526
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008527 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008528 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008529 execute( TC_pcu_act_req() );
8530 execute( TC_pcu_act_req_wrong_ts() );
8531 execute( TC_pcu_act_req_wrong_bts() );
8532 execute( TC_pcu_act_req_wrong_trx() );
8533 execute( TC_pcu_deact_req() );
8534 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008535 execute( TC_pcu_ver_si1() );
8536 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008537 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008538 if (mp_l1_supports_gprs) {
8539 execute( TC_pcu_data_req_pdtch() );
8540 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008541 execute( TC_pcu_data_req_wrong_bts() );
8542 execute( TC_pcu_data_req_wrong_trx() );
8543 execute( TC_pcu_data_req_wrong_ts() );
8544 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008545 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008546 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008547 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008548 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008549 execute( TC_pcu_data_req_imm_ass_pch() );
8550 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008551 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008552 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008553 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008554 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008555 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008556 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008557 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008558 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008559 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008560 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008561 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008562 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008563 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008564 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008565 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008566 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008567 execute( TC_dyn_osmo_pdch_act_deact() );
8568 execute( TC_dyn_osmo_pdch_double_act() );
8569 execute( TC_dyn_ipa_pdch_act_deact() );
8570 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008571 execute( TC_pcu_info_ind_fh_params() );
8572 execute( TC_pcu_socket_nsvc_ipv4() );
8573 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008574 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008575 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008576 } else {
8577 log("PCU socket path not available, skipping PCU tests");
8578 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008579
Harald Welte3d04ae62018-04-04 20:29:05 +02008580 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008581 execute( TC_dyn_osmo_pdch_tchf_act() );
8582 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008583 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008584 execute( TC_dyn_ipa_pdch_tchf_act() );
8585 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008586
8587 execute( TC_rll_est_ind() );
8588 execute( TC_rll_est_req_DCCH_3() );
8589 execute( TC_rll_est_req_ACCH_3() );
8590 execute( TC_rll_rel_ind_DCCH_0() );
8591 execute( TC_rll_rel_ind_DCCH_3() );
8592 execute( TC_rll_rel_ind_ACCH_0() );
8593 execute( TC_rll_rel_ind_ACCH_3() );
8594 execute( TC_rll_rel_req() );
8595 execute( TC_rll_unit_data_req_DCCH() );
8596 execute( TC_rll_unit_data_req_ACCH() );
8597 execute( TC_rll_unit_data_ind_DCCH() );
8598 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008599
8600 execute( TC_chan_act_a51() );
8601 execute( TC_chan_act_a52() );
8602 execute( TC_chan_act_a53() );
8603 execute( TC_encr_cmd_a51() );
8604 execute( TC_encr_cmd_a52() );
8605 execute( TC_encr_cmd_a53() );
8606
Harald Welteee25aae2019-05-19 14:32:37 +02008607 execute( TC_err_rep_wrong_mdisc() );
8608 execute( TC_err_rep_wrong_msg_type() );
8609 execute( TC_err_rep_wrong_sequence() );
8610
Harald Weltee613f962018-04-18 22:38:16 +02008611 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008612
8613 execute( TC_tch_sign_l2_fill_frame() );
8614 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008615
8616 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008617 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008618
8619 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008620 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008621
8622 execute( TC_speech_no_rtp_tchf() );
8623 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008624 execute( TC_speech_rtp_tchf() );
8625 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008626
8627 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008628
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008629 execute( TC_acch_overpower_rxqual_thresh() );
8630 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8631 execute( TC_acch_overpower_always_on_facch() );
8632 execute( TC_acch_overpower_always_on_sacch() );
8633 execute( TC_acch_overpower_limit() );
8634
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008635 /* BEWARE: these test cases can potentially break the IUT or cause
8636 * weird/unexpected behavior. Ensure that they are executed last. */
8637 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8638 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008639}
8640
8641
8642}