blob: 3a3d7cc3ef859d98790169048b0ea9af44ff5796 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +0300138 /* T3105 timer (see 3GPP TS 44.018, section 11.1.2) */
139 integer mp_ho_t3105_ms := 100;
140 /* Ny1 counter (see 3GPP TS 44.018, section 11.1.3) */
141 integer mp_ho_ny1 := 10;
Harald Welte70767382018-02-21 12:16:40 +0100142}
143
Harald Welte629cc6b2018-03-11 17:19:05 +0100144type record of RslChannelNr ChannelNrs;
145
Harald Welte70767382018-02-21 12:16:40 +0100146type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100148 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100149 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100150 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100151 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100152 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100153
154 /* L1CTL port (for classic tests) */
155 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100156
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700157 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700158 port TRXC_CODEC_PT BTS_TRXC;
159 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100160
Harald Weltef50e3ae2018-09-10 10:27:56 +0200161 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100162 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200163 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100164
Harald Welte883340c2018-02-28 18:59:29 +0100165 /* PCU Interface of BTS */
166 port PCUIF_CODEC_PT PCU;
167 var integer g_pcu_conn_id;
168 /* Last PCU INFO IND we received */
169 var PCUIF_Message g_pcu_last_info;
170
Harald Welte48494ca2018-02-25 16:59:50 +0100171 /* SI configuration */
172 var SystemInformationConfig si_cfg := {
173 bcch_extended := false,
174 si1_present := false,
175 si2bis_present := false,
176 si2ter_present := false,
177 si2quater_present := false,
178 si7_present := false,
179 si8_present := false,
180 si9_present := false,
181 si13_present := false,
182 si13alt_present := false,
183 si15_present := false,
184 si16_present := false,
185 si17_present := false,
186 si2n_present := false,
187 si21_present := false,
188 si22_present := false
189 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100190
191 /* all logical channels available on the BTS */
192 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100193 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
196/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200197type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100198 port L1CTL_PT L1CTL;
199
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700200 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700201 port TRXC_CODEC_PT BTS_TRXC;
202 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100203
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200204 /* port to be initialized optionally to access BSC VTY */
205 port TELNETasp_PT BSCVTY;
206
Harald Welte70767382018-02-21 12:16:40 +0100207 timer g_Tguard;
208 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
209
210 var ConnHdlrPars g_pars;
211 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100212 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200213
214 /* PCU Interface of BTS */
215 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200216
217 var RTP_Emulation_CT vc_RTPEM;
218 port RTPEM_CTRL_PT RTPEM_CTRL;
219 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100220}
221
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700222private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200226 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200228 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700229 timer T;
230
Harald Welte70767382018-02-21 12:16:40 +0100231 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
232 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
233
234 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
235 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
236 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
237
238 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
239 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700240
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700241 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700242 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700243 T.start(mp_ipa_up_timeout);
244 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700245 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700246 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
247 /* Make sure that all transceivers use unique stream ID */
248 if (trx_mask[enum2int(ev.sid)] == '1'B) {
249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
250 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
251 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700252
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700253 trx_mask[enum2int(ev.sid)] := '1'B;
254 trx_count := trx_count + 1;
255
256 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200257 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700258 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200259 /* This message (RF RESource INDication) is sent by the IUT itself */
260 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
261 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
264 }
265 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
267 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
268 }
269
270 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
271 rfind_count := rfind_count + 1;
272 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
273 if (rfind_count < mp_transceiver_num) { repeat; }
274 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700275 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
276 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
277 [] T.timeout {
278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
279 "Timeout waiting for RSL bring up");
280 }
281 }
Harald Welte70767382018-02-21 12:16:40 +0100282}
283
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700284friend type record length(1 .. 256) of TrxParsItem TrxPars;
285friend type record TrxParsItem {
286 GsmArfcn arfcn,
287 TrxTsPars ts
288};
289
290friend type record length(8) of TrxTsParsItem TrxTsPars;
291friend type record TrxTsParsItem {
292 PchanConfig config
293};
294
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700295friend type record FreqHopPars {
296 /* Whether frequency hopping is in use */
297 boolean enabled,
298 /* Mobile Allocation Index Offset / Hopping Sequence Number */
299 MaioHsn maio_hsn,
300 /* MA bitmap to be indicated in RR Immediate Assignment */
301 MobileAllocationLV ma_map,
302 /* The actual Mobile Allocation (ARFCN list) to be used */
303 L1ctlMA ma
304};
305
Harald Welte70767382018-02-21 12:16:40 +0100306type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700307 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100308 RslChannelNr chan_nr,
309 RSL_IE_ChannelMode chan_mode,
310 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100311 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200312 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200313 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700314 BtsBand bts0_band optional,
315
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700316 /* Training Sequence Code */
317 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700318 /* Frequency hopping parameters */
319 FreqHopPars fhp
320};
Harald Welte0472ab42018-03-12 15:02:26 +0100321
322/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200323friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300324 RllTestCase rll,
325 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100326}
327
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700328private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100329 max_retrans := RACH_MAX_RETRANS_7,
330 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100331 cell_barr_access := false,
332 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100333 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100334};
335
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700336private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100337 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200338 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100339 acs := '0'B,
340 neci := true,
341 rxlev_access_min := 0
342}
343
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700344private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100345 mcc_mnc := '262F42'H,
346 lac := 42
347}
348
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700349private template (value) GPRSIndicator ts_GPRSIndicator_def := {
350 ra_colour := 0,
351 si13_pos := '0'B
352}
353
354private template (value) SI3RestOctets ts_SI3RestOctets_def
355modifies ts_SI3RestOctets := {
356 gprs_ind := {
357 presence := CSN1_H,
358 ind := ts_GPRSIndicator_def
359 }
360}
361
362private template (value) SI4RestOctets ts_SI4RestOctets_def
363modifies ts_SI4RestOctets := {
364 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700365 presence := CSN1_H,
366 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700367 }
368}
369
Harald Welte7484fc42018-02-24 14:09:45 +0100370/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100373 payload := {
374 si3 := {
375 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100376 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100377 ctrl_chan_desc := {
378 msc_r99 := true,
379 att := true,
380 bs_ag_blks_res := 1,
381 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100382 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100383 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
384 spare := '00'B,
385 bs_pa_mfrms := 0, /* 2 multiframes */
386 t3212 := 1 /* 6 minutes */
387 },
Harald Welte82ccef72018-02-25 16:17:33 +0100388 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100389 dn_ind := false,
390 pwrc := false,
391 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100392 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100393 },
Harald Weltef10153f2018-02-25 16:34:05 +0100394 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100395 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200396 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100397 }
398 }
399}
Harald Welte70767382018-02-21 12:16:40 +0100400
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700401private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100402 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100403 payload := {
404 si2 := {
405 bcch_freq_list := '00000000000000000000000000000000'O,
406 ncc_permitted := '11111111'B,
407 rach_control := ts_RachCtrl_default
408 }
409 }
410}
411
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700412private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100413 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100414 payload := {
415 si4 := {
416 lai := ts_LAI_default,
417 cell_sel_par := ts_CellSelPar_default,
418 rach_control := ts_RachCtrl_default,
419 cbch_chan_desc := omit,
420 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200421 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100422 }
423 }
424}
425
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700426private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100427runs on test_CT {
428 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700429 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100430}
431
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700432private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100433runs on test_CT {
434 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
435 log("Setting ", rsl_si_type, ": ", si_dec);
436 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
437}
438
Harald Welte505cf9b2018-09-15 17:47:23 +0300439friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100440 map(self:BTSVTY, system:BTSVTY);
441 f_vty_set_prompts(BTSVTY);
442 f_vty_transceive(BTSVTY, "enable");
443}
444
Harald Welte505cf9b2018-09-15 17:47:23 +0300445friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200446 map(self:BSCVTY, system:BSCVTY);
447 f_vty_set_prompts(BSCVTY, "OsmoBSC");
448 f_vty_transceive(BSCVTY, "enable");
449}
450
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200451friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
452 map(self:BSCVTY, system:BSCVTY);
453 f_vty_set_prompts(BSCVTY, "OsmoBSC");
454 f_vty_transceive(BSCVTY, "enable");
455}
456
Harald Welte883340c2018-02-28 18:59:29 +0100457/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200458friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100460 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200461 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
462 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100463 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200464 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100466 }
467}
468
Harald Weltef26de0b2018-04-04 20:28:05 +0200469private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
470 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100471 timer T := 2.0;
472 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100473 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200474 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100475 return;
476 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100478
479 T.start;
480 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200481 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100484 }
485 }
486}
487
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
489 out integer trxc_conn_id) {
490 var Result res;
491
492 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
493 "", -1, -1, { udp := {} }, {});
494 if (not ispresent(res.connId)) {
495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
496 "Could not connect to the control (TRXC) interface " &
497 "of FakeTRX, check your configuration");
498 }
499 trxc_conn_id := res.connId;
500}
501
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100502/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700503friend function f_init(uint8_t trx_nr := 0)
504runs on test_CT
505{
506 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200507 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100508
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700509 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
510 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700511 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200512 g_AllChanTypes := {
513 /* TS 1..4: TCH/F */
514 valueof(ts_RslChanNr_Bm(1)),
515 /* TS 5: TCH/H */
516 valueof(ts_RslChanNr_Lm(5,1)),
517 /* TS 0: SDCCH/4 */
518 valueof(ts_RslChanNr_SDCCH4(0,2)),
519 /* TS 6: SDCCH/8 */
520 valueof(ts_RslChanNr_SDCCH8(6,4))
521 };
522 } else {
523 g_AllChanTypes := {
524 /* TS 1..4: TCH/F */
525 valueof(ts_RslChanNr_Bm(1)),
526 /* TS 0: SDCCH/4 */
527 valueof(ts_RslChanNr_SDCCH4(0,2)),
528 /* TS 6: SDCCH/8 */
529 valueof(ts_RslChanNr_SDCCH8(6,4))
530 };
531 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700532
533 g_AllChannels := { };
534
535 /* Generate list of all logical channels from module parameters */
536 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
537 select (trx_pars.ts[tn].config) {
538 case (GSM_PCHAN_CCCH_SDCCH4) {
539 g_AllChannels := g_AllChannels &
540 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
541 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
542 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
543 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
544 }
545 case (GSM_PCHAN_SDCCH8) {
546 g_AllChannels := g_AllChannels &
547 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
551 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
552 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
553 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
554 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
555 }
556 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
557 g_AllChannels := g_AllChannels &
558 { valueof(ts_RslChanNr_Lm(tn, 0)),
559 valueof(ts_RslChanNr_Lm(tn, 1)),
560 valueof(ts_RslChanNr_Bm(tn)) };
561 }
562 case (GSM_PCHAN_TCHH) {
563 g_AllChannels := g_AllChannels &
564 { valueof(ts_RslChanNr_Lm(tn, 0)),
565 valueof(ts_RslChanNr_Lm(tn, 1)) };
566 }
567 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
568 g_AllChannels := g_AllChannels &
569 { valueof(ts_RslChanNr_Bm(tn)) };
570 }
571 }
572 }
573
Harald Welte70767382018-02-21 12:16:40 +0100574 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100575 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100576 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100577 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100578
579 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100580 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
581 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
582 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
583 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100584
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700585 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100586 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700587
588 /* Init TRXC interface to FakeTRX */
589 map(self:BTS_TRXC, system:BTS_TRXC);
590 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
591
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700592 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600593 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
594 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700595 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600596 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100597 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200598
599 /* Wait some extra time to make sure the BTS emits a stable carrier.
600 * (this is only relevant when running the tests with a physical BTS.) */
601 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Harald Welte68e495b2018-02-25 00:05:57 +0100604/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700605friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100606 map(self:L1CTL, system:L1CTL);
607 f_connect_reset(L1CTL);
608}
609
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200610friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100611
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700612private type record length(8) of FreqHopGroups FreqHopConfig;
613
614private type record of FreqHopGroup FreqHopGroups;
615private type record FreqHopGroup {
616 uint6_t hsn,
617 FreqHopGroupItems trx_maio
618};
619
620private type record of FreqHopGroupItem FreqHopGroupItems;
621private type record FreqHopGroupItem {
622 uint8_t trx_nr,
623 uint6_t maio
624};
625
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700626friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
627 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700628{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700629 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 var integer i, j;
631
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700632 fhp.enabled := false;
633
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700634 for (i := 0; i < lengthof(groups); i := i + 1) {
635 var FreqHopGroup g := groups[i];
636 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
637 var FreqHopGroupItem gi := g.trx_maio[j];
638 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700639 fhp.maio_hsn.maio := gi.maio;
640 fhp.maio_hsn.hsn := g.hsn;
641 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700642 break;
643 }
644 }
645
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700646 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700648 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
649 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
650 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700651
652 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700653 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
654 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700655 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700656 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700657 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700658 }
659
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700660 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700661 break; /* We're done */
662 }
663 }
664}
665
Harald Welte70767382018-02-21 12:16:40 +0100666/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700667friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
668 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200669 boolean trxc_comp := false,
670 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100671runs on test_CT return ConnHdlr {
672 var charstring id := testcasename();
673 var ConnHdlr vc_conn;
674
675 vc_conn := ConnHdlr.create(id);
676 /* connect to RSL Emulation main component */
677 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
678 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700679
680 /* The ConnHdlr component may want to talk to some ports directly,
681 * so we disconnect it from the test_CT and connect it to the component.
682 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200683 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200684 unmap(self:PCU, system:PCU);
685 map(vc_conn:PCU, system:PCU);
686 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700687 if (trxc_comp) {
688 unmap(self:BTS_TRXC, system:BTS_TRXC);
689 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
690 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200691 if (l1ctl) {
692 map(vc_conn:L1CTL, system:L1CTL);
693 }
Harald Welte70767382018-02-21 12:16:40 +0100694
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700695 /* Obtain frequency hopping parameters for a given timeslot */
696 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700697 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700698 }
699
Harald Welte70767382018-02-21 12:16:40 +0100700 vc_conn.start(f_handler_init(fn, id, pars));
701 return vc_conn;
702}
703
Harald Welte70767382018-02-21 12:16:40 +0100704private altstep as_Tguard() runs on ConnHdlr {
705 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100707 }
708}
709
Harald Welte990a3612019-05-27 14:02:13 +0200710friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700711 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700712 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100713}
714
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700715private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100716 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600717 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700720private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100721 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600722 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100723}
724
725/* first function started in ConnHdlr component */
726private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
727runs on ConnHdlr {
728 g_pars := pars;
729 g_chan_nr := pars.chan_nr;
730
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200731 if (L1CTL.checkstate("Mapped")) {
732 f_connect_reset(L1CTL);
733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
Harald Welted48c0c72019-06-05 10:01:15 +0200735 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700736 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100737 }
Harald Welte70767382018-02-21 12:16:40 +0100738
739 g_Tguard.start(pars.t_guard);
740 activate(as_Tguard());
741
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700742 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100743
744 /* call the user-supplied test case function */
745 fn.apply(id);
746}
747
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700748private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
749 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200750runs on ConnHdlr return RSL_Message {
751 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100752 timer T := 3.0;
753 RSL.send(tx);
754 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100755 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200756 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100757 T.stop;
758 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100759 }
Harald Welte1eba3742018-02-25 12:48:14 +0100760 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100762 }
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] as_l1_sacch();
764 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700765 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700766 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100767 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100769 }
Harald Welte21240e62018-03-11 21:43:35 +0100770 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100771 }
Harald Welteb1726c92018-03-30 11:56:38 +0200772 return rx;
773}
774
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700775friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
776 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200777runs on ConnHdlr {
778 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100779}
780
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300781/* Send the given measurement results to the IUT over the Um interface,
782 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
783friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
784runs on ConnHdlr {
785 var template (value) SacchL1Header l1h;
786 var octetstring l2, l3;
787 timer T;
788
789 /* RR Measurement Report to be sent */
790 var GsmRrL3Message meas_rep := {
791 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
792 payload := { meas_rep := { meas_res := valueof(meas_res) } }
793 };
794
795 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
796 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
797 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
798 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
799 g_pars.l1_pars.ms_actual_ta);
800
801 /* Send RR Measurement Report over the Um interface */
802 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
803
804 /* Expect MEASurement RESult on the A-bis/RSL interface */
805 T.start(2.0);
806 alt {
807 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
808 setverdict(pass);
809 }
810 [] RSL.receive { repeat; }
811 [] T.timeout {
812 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
814 }
815 }
816}
817
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700818friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
819 boolean encr_enable := false,
820 RSL_IE_List more_ies := {},
821 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
822runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200823 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200824 if (encr_enable) {
825 /* append encryption related IEs, if requested */
826 var RSL_IE_EncryptionInfo encr_info;
827 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
828 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
829encr_info})) };
830 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200831 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200832 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100833}
834
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700835friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100836 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100837 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100838}
839
Harald Welte2f2b2b72019-05-31 22:24:57 +0200840friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200841 template RSL_IE_ChannelMode chan_mode,
842 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700843 uint8_t trx_nr := 0, float t_guard := 20.0) := {
844 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100845 chan_nr := valueof(chan_nr),
846 chan_mode := valueof(chan_mode),
847 t_guard := t_guard,
848 l1_pars := {
849 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100850 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100851 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100852 meas_ul := {
853 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 },
857 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200858 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 rxqual := 0
860 }
861 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200862 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100863 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200864 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200865 ms_actual_ta := mp_ms_actual_ta_exp,
866 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100867 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200868 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200869 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700870 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700871 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700872 fhp := {
873 enabled := false,
874 maio_hsn := ts_HsnMaio(0, 0),
875 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700876 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700877 }
Harald Welte70767382018-02-21 12:16:40 +0100878}
879
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300880/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
881 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
882private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
883 template (present) octetstring tr_data := ?,
884 template (present) RslChannelNr chan_nr := ?,
885 template (present) RslLinkId link_id := ?)
886runs on ConnHdlr {
887 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
888}
889
890/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
891 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
892private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
893 template (present) RslLinkId link_id := ?,
894 template (present) LapdmSapi sapi := ?,
895 boolean do_repeat := true)
896runs on ConnHdlr {
897 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
898 var L1ctlDlMessage dl_msg;
899
900 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
901 if (do_repeat) {
902 repeat;
903 }
904 }
905}
906
907/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
908 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
909private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
910 template (present) LapdmFrameAB tr_frame := ?,
911 template (present) RslLinkId link_id := ?)
912runs on ConnHdlr {
913 var L1ctlDlMessage dl_msg;
914
915 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
916 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
917 }
918}
919
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300920/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
921 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
922private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
923 template (present) LapdmFrameAB tr_frame := ?,
924 template (present) SacchL1Header tr_l1h := ?,
925 template (present) GsmSapi sapi := ?)
926runs on ConnHdlr {
927 var L1ctlDlMessage dl_msg;
928 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
929 template (present) L1ctlDataReq tr_data := {
930 l1header := tr_l1h,
931 l2_payload := decmatch tr_frame
932 };
933
934 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
935 var octetstring data := dl_msg.payload.data_ind.payload;
936 l1h := dec_SacchL1Header(substr(data, 0, 2));
937 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
938 }
939}
940
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300941/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
942 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
943 * payload is treated as PDU_ML3_NW_MS. */
944private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
945 template (present) PDU_ML3_NW_MS tr_pdu := ?,
946 template (present) GsmSapi sapi := 0)
947runs on ConnHdlr {
948 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
949 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
950 var LapdmFrameAB lapdm_frame;
951
952 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
953 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
954 }
955}
956
Harald Welte93640c62018-02-25 16:59:33 +0100957/***********************************************************************
958 * Channel Activation / Deactivation
959 ***********************************************************************/
960
Harald Welte70767382018-02-21 12:16:40 +0100961/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700962private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100963 for (var integer i := 0; i < 500; i := i+1) {
964 f_rsl_chan_act(g_pars.chan_mode);
965 f_rsl_chan_deact();
966 }
967 setverdict(pass);
968}
969testcase TC_chan_act_stress() runs on test_CT {
970 var ConnHdlr vc_conn;
971 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200972 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100973 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
974 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100976}
977
978/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700979private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100980 f_rsl_chan_act(g_pars.chan_mode);
981 /* attempt to activate the same lchan again -> expect reject */
982 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
983 alt {
984 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100986 }
987 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
988 setverdict(pass);
989 }
990 }
991 f_rsl_chan_deact();
992}
993testcase TC_chan_act_react() runs on test_CT {
994 var ConnHdlr vc_conn;
995 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100996 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100997 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
998 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001000}
1001
1002/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001003private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001004 timer T := 3.0;
1005 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1006 T.start;
1007 alt {
1008 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1009 setverdict(pass);
1010 }
1011 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001013 }
1014 }
1015}
1016testcase TC_chan_deact_not_active() runs on test_CT {
1017 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001019 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1020 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001022}
1023
1024/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001025private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001026 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1027 alt {
1028 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001030 }
1031 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1032 setverdict(pass);
1033 }
1034 }
1035}
1036private type record WrongChanNrCase {
1037 RslChannelNr chan_nr,
1038 charstring description
1039}
1040private type record of WrongChanNrCase WrongChanNrCases;
1041private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1042 chan_nr := chan_nr,
1043 description := desc
1044}
1045
1046testcase TC_chan_act_wrong_nr() runs on test_CT {
1047 var ConnHdlr vc_conn;
1048 var ConnHdlrPars pars;
1049
Harald Welte294b0a22018-03-10 23:26:48 +01001050 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001051
1052 var WrongChanNrCases wrong := {
1053 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1054 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1055 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1056 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1057 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1058 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1059 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1060 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1061 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1062 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1063 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1064 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1065 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1066 };
1067
1068 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1069 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1070 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1071 vc_conn.done;
1072 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001074}
1075
Harald Weltee613f962018-04-18 22:38:16 +02001076/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001077friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001078 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001079 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001080
1081 /* test on each of the channels we have */
1082 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1083 pars.chan_nr := valueof(g_AllChanTypes[i]);
1084
1085 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1086 vc_conn := f_start_handler(fn, pars);
1087 vc_conn.done;
1088 }
1089
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001091}
1092
Harald Welte93640c62018-02-25 16:59:33 +01001093/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001094 * SACCH handling
1095 ***********************************************************************/
1096
1097private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1098 timer T_sacch := 3.0;
1099 T_sacch.start;
1100 alt {
1101 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001103 }
1104 [not exp] T_sacch.timeout {
1105 setverdict(pass);
1106 }
1107 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1108 setverdict(pass);
1109 }
1110 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001112 }
1113 [] L1CTL.receive { repeat; }
1114 [] RSL.receive { repeat; }
1115 }
1116}
1117
1118/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1119private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1120 f_l1_tune(L1CTL);
1121 RSL.clear;
1122
1123 /* activate the logical channel */
1124 f_est_dchan();
1125 L1CTL.clear;
1126
1127 /* check that SACCH actually are received as expected */
1128 f_exp_sacch(true);
1129
1130 /* deactivate SACCH on the logical channel */
1131 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1132 f_sleep(1.0);
1133 L1CTL.clear;
1134
1135 /* check that no SACCH are received anymore */
1136 f_exp_sacch(false);
1137
1138 /* release the channel */
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_deact_sacch() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 //for (var integer i := 0; i < 1; i := i+1) {
1148 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1149 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1150 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1151 vc_conn.done;
1152 }
1153 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001155}
1156
Harald Welte55700662018-03-12 13:15:43 +01001157/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001158private function f_sacch_present(template octetstring l3_exp,
1159 boolean do_fail := true)
1160runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001161 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001162 timer T_sacch := 3.0;
1163 L1CTL.clear;
1164 T_sacch.start;
1165 alt {
1166 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1167 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1168 if (match(l3, l3_exp)) {
1169 setverdict(pass);
1170 } else {
1171 repeat;
1172 }
1173 }
1174 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001175 [not do_fail] T_sacch.timeout {
1176 log("Timeout waiting for SACCH ", l3_exp);
1177 }
1178 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001179 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001181 }
1182 }
1183}
1184
Harald Welte55700662018-03-12 13:15:43 +01001185/* verify that given SACCH payload is not present */
1186private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1187 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001188 timer T_sacch := 3.0;
1189 L1CTL.clear;
1190 T_sacch.start;
1191 alt {
1192 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1193 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1194 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001195 setverdict(fail, "Received unexpected SACCH ", dl);
1196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001197 } else {
1198 repeat;
1199 }
1200 }
1201 [] L1CTL.receive { repeat; }
1202 [] T_sacch.timeout {
1203 setverdict(pass);
1204 }
1205 }
1206}
1207
Harald Welte629cc6b2018-03-11 17:19:05 +01001208/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001209private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1210 /* Set a known default SACCH filling for SI5 */
1211 var octetstring si5 := f_rnd_octstring(19);
1212 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1213
1214 f_l1_tune(L1CTL);
1215 RSL.clear;
1216
1217 /* activate the logical channel */
1218 f_est_dchan();
1219
1220 /* check that the specified SI5 value is actually sent */
1221 f_sacch_present(si5);
1222
1223 /* release the channel */
1224 RSL.clear;
1225 f_rsl_chan_deact();
1226 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1227}
1228testcase TC_sacch_filling() runs on test_CT {
1229 var ConnHdlr vc_conn;
1230 var ConnHdlrPars pars;
1231 f_init();
1232 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1233 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1234 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1235 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1236 vc_conn.done;
1237 }
1238 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001240}
1241
Harald Welte629cc6b2018-03-11 17:19:05 +01001242/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001243private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1244 /* Set a known default SACCH filling for SI5 */
1245 var octetstring si5 := f_rnd_octstring(19);
1246 var octetstring si5_diff := f_rnd_octstring(19);
1247 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1248
1249 f_l1_tune(L1CTL);
1250 RSL.clear;
1251
1252 log("Activating channel, expecting standard SI5");
1253 /* activate the logical channel */
1254 f_est_dchan();
1255 /* check that the specified SI5 value is actually sent */
1256 f_sacch_present(si5);
1257
1258 /* set channel-specific different SI5 */
1259 log("Setting channel specific SACCH INFO, expecting it");
1260 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1261 /* check that the specified lchan-specific value is now used */
1262 f_sacch_present(si5_diff);
1263
1264 /* deactivate the channel and re-activate it, this should result in default SI5 */
1265 log("De-activating and re-activating channel, expecting standard SI5");
1266 f_rsl_chan_deact();
1267 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1268 /* Verify that the TRX-wide default SACCH filling is present again */
1269 f_sacch_present(si5);
1270
1271 /* release the channel */
1272 RSL.clear;
1273 f_rsl_chan_deact();
1274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1275}
1276testcase TC_sacch_info_mod() runs on test_CT {
1277 var ConnHdlr vc_conn;
1278 var ConnHdlrPars pars;
1279 f_init();
1280 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1281 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1282 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1283 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1284 vc_conn.done;
1285 }
1286 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001288}
1289
Harald Welte075d84c2018-03-12 13:07:24 +01001290/* Test SACCH scheduling of multiple different SI message types */
1291private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1292 var octetstring si5 := f_rnd_octstring(19);
1293 var octetstring si5bis := f_rnd_octstring(19);
1294 var octetstring si5ter := f_rnd_octstring(19);
1295 var octetstring si6 := f_rnd_octstring(19);
1296
1297 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1298 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1300 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1301
1302 f_l1_tune(L1CTL);
1303 RSL.clear;
1304
1305 /* activate the logical channel */
1306 f_est_dchan();
1307 L1CTL.clear;
1308
1309 /* check that SACCH actually are received as expected */
1310 f_sacch_present(si5);
1311 f_sacch_present(si5bis);
1312 f_sacch_present(si5ter);
1313 f_sacch_present(si6);
1314
1315 /* release the channel */
1316 f_rsl_chan_deact();
1317 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1318}
1319testcase TC_sacch_multi() runs on test_CT {
1320 var ConnHdlr vc_conn;
1321 var ConnHdlrPars pars;
1322 f_init();
1323 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1324 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1325 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1326 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1327 vc_conn.done;
1328 }
1329 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001331}
1332
Harald Welte55700662018-03-12 13:15:43 +01001333/* Test if SACH information is modified as expected */
1334private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1335 var octetstring si5 := f_rnd_octstring(19);
1336 var octetstring si6 := f_rnd_octstring(19);
1337
1338 /* First, configure both SI5 and SI6 to be transmitted */
1339 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1340 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1341
1342 f_l1_tune(L1CTL);
1343 RSL.clear;
1344
1345 /* activate the logical channel */
1346 f_est_dchan();
1347 L1CTL.clear;
1348
1349 /* check that SACCH actually are received as expected */
1350 f_sacch_present(si5);
1351 f_sacch_present(si6);
1352
1353 /* disable SI6 */
1354 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1355
1356 /* check that SI5 is still transmitted */
1357 f_sacch_present(si5);
1358 /* check if SI6 is now gone */
1359 f_sacch_missing(si6);
1360
1361 /* release the channel */
1362 f_rsl_chan_deact();
1363 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1364}
1365testcase TC_sacch_multi_chg() runs on test_CT {
1366 var ConnHdlr vc_conn;
1367 var ConnHdlrPars pars;
1368 f_init();
1369 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1370 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1371 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1372 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1373 vc_conn.done;
1374 }
1375 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001377}
1378
Harald Weltec8d363c2019-05-19 20:36:48 +02001379/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1380private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1381 var octetstring si5 := f_rnd_octstring(19);
1382 var octetstring si6 := f_rnd_octstring(19);
1383 var octetstring si5_specific := f_rnd_octstring(19);
1384 var octetstring si6_specific := f_rnd_octstring(19);
1385
1386 /* First, configure both SI5 and SI6 to be transmitted */
1387 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1388 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1389
1390 f_l1_tune(L1CTL);
1391 RSL.clear;
1392
1393 /* activate channel with different SACCH filling */
1394 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1395 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1396 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1397 }));
1398 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1399 RSL_IE_Body:{sacch_info := sacch_info})) };
1400 f_est_dchan(more_ies := addl_ies);
1401
1402 /* check that SACCH actually are received as expected */
1403 f_sacch_present(si5_specific);
1404 f_sacch_present(si6_specific);
1405
1406 /* release the channel */
1407 f_rsl_chan_deact();
1408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1409}
1410testcase TC_sacch_chan_act() runs on test_CT {
1411 var ConnHdlr vc_conn;
1412 var ConnHdlrPars pars;
1413 f_init();
1414
1415 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1416 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1417 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1418 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1419 vc_conn.done;
1420 }
1421 /* TODO: do the above in parallel, rather than sequentially? */
1422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1423}
1424
Harald Welte8b01c792019-05-19 22:51:25 +02001425/* verify that SACCH DL transmission is started only if MS power IE present
1426 * see section 4.1.3 of 3GPP TS 48.058 */
1427private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1428 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001429 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001430
1431 f_l1_tune(L1CTL);
1432 RSL.clear;
1433
1434 /* Step 1: Activate ASYNC HO channel without MS power IE */
1435
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001436 var integer ho_ref := oct2int(f_rnd_octstring(1));
1437 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1438 RSL_IE_Body:{ handover_ref := ho_ref }));
1439 var RSL_IE_List addl_ies := {
1440 ho_ref_ie
1441 };
1442
Harald Welte8b01c792019-05-19 22:51:25 +02001443 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001444 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001445 /* don't perform immediate assignment here, as we're testing non-IA case */
1446 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001447 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001448
1449 /* Verify that no DL SACCH is being received */
1450 f_sacch_missing(?);
1451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to start */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459
1460
1461 /* Step 2: Activate ASYNC HO channel with MS power IE */
1462
1463 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001464 addl_ies := {
1465 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001466 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1467 };
1468 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1469 /* don't perform immediate assignment here, as we're testing non-IA case */
1470 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001471 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001472
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001473 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1474 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1475 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001476
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001477 /* Send handover Access Burst and expect SACCH to remain present */
1478 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1479
1480 f_sacch_present(si5);
1481
Harald Welte8b01c792019-05-19 22:51:25 +02001482 f_rsl_chan_deact();
1483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1484}
1485testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init();
1489
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001490 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1491 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1492 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001493 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1494 vc_conn.done;
1495 }
1496 /* TODO: do the above in parallel, rather than sequentially? */
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
1499
1500/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1501 * see section 4.1.4 of 3GPP TS 48.058 */
1502private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1503 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001504 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1505
Harald Welte8b01c792019-05-19 22:51:25 +02001506 var RSL_IE_List addl_ies;
1507
1508 f_l1_tune(L1CTL);
1509 RSL.clear;
1510
1511 /* Step 1: Activate SYNC HO channel without MS power IE */
1512
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001513 var integer ho_ref := oct2int(f_rnd_octstring(1));
1514 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1515 RSL_IE_Body:{ handover_ref := ho_ref }));
1516 addl_ies := {
1517 ho_ref_ie
1518 };
1519
Harald Welte8b01c792019-05-19 22:51:25 +02001520 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001521 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001522 /* don't perform immediate assignment here, as we're testing non-IA case */
1523 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001524 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001525
1526 /* Verify that no DL SACCH is being received */
1527 f_sacch_missing(?);
1528
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001529 /* Send handover Access Burst and expect SACCH to start */
1530 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1531
1532 f_sacch_present(si5);
1533
Harald Welte8b01c792019-05-19 22:51:25 +02001534 f_rsl_chan_deact();
1535 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1536
1537
1538 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1539
1540 /* Activate channel on BTS side */
1541 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001542 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001543 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1544 };
1545 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1546 /* don't perform immediate assignment here, as we're testing non-IA case */
1547 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001548 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001549
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001550 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1551 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1552 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001553
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001554 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001555 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1556
1557 f_sacch_present(si5);
1558
Harald Welte8b01c792019-05-19 22:51:25 +02001559 f_rsl_chan_deact();
1560 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1561
1562
1563 /* Step 2b: Activate SYNC HO channel with TA IE */
1564
1565 /* Activate channel on BTS side */
1566 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001567 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001568 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1569 };
1570 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1571 /* don't perform immediate assignment here, as we're testing non-IA case */
1572 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001573 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001574
1575 /* Verify that no DL SACCH is being received */
1576 f_sacch_missing(?);
1577
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001578 /* Send handover Access Burst and expect SACCH to start */
1579 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1580
1581 f_sacch_present(si5);
1582
Harald Welte8b01c792019-05-19 22:51:25 +02001583 f_rsl_chan_deact();
1584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1585
1586
1587 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1588
1589 /* Activate channel on BTS side */
1590 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001591 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001592 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1593 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1594 };
1595 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1596 /* don't perform immediate assignment here, as we're testing non-IA case */
1597 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001598 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001599
1600 /* Verify that DL SACCH is being received */
1601 f_sacch_present(si5);
1602
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001603 /* Send handover Access Burst and expect SACCH to remain present */
1604 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1605
1606 f_sacch_present(si5);
1607
Harald Welte8b01c792019-05-19 22:51:25 +02001608 f_rsl_chan_deact();
1609 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1610}
1611testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1612 var ConnHdlr vc_conn;
1613 var ConnHdlrPars pars;
1614 f_init();
1615
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001616 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1617 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1618 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001619 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1620 vc_conn.done;
1621 }
1622 /* TODO: do the above in parallel, rather than sequentially? */
1623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1624}
Harald Welte629cc6b2018-03-11 17:19:05 +01001625
1626
1627/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001628 * RACH Handling
1629 ***********************************************************************/
1630
Harald Welte8c24c2b2018-02-26 08:31:31 +01001631/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001632private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001633 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001634 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001635 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001636
Harald Welte8c24c2b2018-02-26 08:31:31 +01001637 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001638 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001639 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001640 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001641 if (emerg == true) {
1642 ra := f_rnd_ra_emerg();
1643 } else {
1644 ra := f_rnd_ra_cs();
1645 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001646 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1647 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001649 }
1650 fn_last := fn;
1651
1652 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001653 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001654 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001655 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001656 T.stop;
1657 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001658 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660 }
1661 [] RSL_CCHAN.receive { repeat; }
1662 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001663 test_failed := true;
1664 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001665 }
1666 }
1667 }
Maxba06feb2019-03-05 10:52:46 +01001668 if (test_failed) {
1669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001670 }
Maxba06feb2019-03-05 10:52:46 +01001671 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001673}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001674
Philipp Maier16ade782020-07-08 21:36:00 +02001675/* Normal variant */
1676testcase TC_rach_content() runs on test_CT {
1677 f_TC_rach_content(emerg := false);
1678}
1679
1680/* Emergency call variant */
1681testcase TC_rach_content_emerg() runs on test_CT {
1682 f_TC_rach_content(emerg := true);
1683}
1684
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1686testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001687 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001688 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001689 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001690 f_l1_tune(L1CTL);
1691
1692 var GsmFrameNumber fn_last := 0;
1693 for (var integer i := 0; i < 1000; i := i+1) {
1694 var OCT1 ra := f_rnd_ra_cs();
1695 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1696 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001698 }
1699 fn_last := fn;
1700 }
1701 var integer rsl_chrqd := 0;
1702 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001703 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001704 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001705 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001706 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001707 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001708 repeat;
1709 }
1710 [] RSL_CCHAN.receive { repeat; }
1711 [] T.timeout { }
1712 }
1713 if (rsl_chrqd == 1000) {
1714 setverdict(pass);
1715 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001719}
1720
Harald Welte3453ab42019-05-24 21:19:58 +02001721private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1722 var charstring bts_str := "bts " & int2str(bts_nr);
1723 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1724}
1725
1726/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1727private template integer tr_rach_slots_per_interval := (90 .. 130);
1728
1729/* Expect 0 RACH load on an idle BTS that has just started up */
1730testcase TC_rach_load_idle_thresh0() runs on test_CT {
1731 var ASP_RSL_Unitdata rx_ud;
1732
1733 f_init_vty_bsc();
1734 /* send load indications even at 0% load */
1735 f_vty_load_ind_thresh(0);
1736 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1737 f_sleep(2.0);
1738
1739 f_init();
1740
Harald Weltee37f9a52020-10-11 20:45:23 +02001741 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1742 alt {
1743 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1744 [] RSL_CCHAN.receive { repeat }
1745 }
1746
Harald Welte3453ab42019-05-24 21:19:58 +02001747 timer T := 5.0;
1748 T.start;
1749 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001750 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001751 setverdict(pass);
1752 repeat;
1753 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001754 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001755 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1756 repeat;
1757 }
1758 [] RSL_CCHAN.receive {
1759 repeat;
1760 }
1761 [] T.timeout { }
1762 }
1763
1764 f_vty_load_ind_thresh(10);
1765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1766}
1767
1768/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1769testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1770 var ASP_RSL_Unitdata rx_ud;
1771
1772 f_init_vty_bsc();
1773 f_init();
1774
1775 timer T := 5.0;
1776 T.start;
1777 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001778 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001779 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1780 repeat;
1781 }
1782 [] RSL_CCHAN.receive {
1783 repeat;
1784 }
1785 [] T.timeout {
1786 setverdict(pass);
1787 }
1788 }
1789
1790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1791}
1792
1793/* Expect 0 RACH load on an idle BTS that has just started up */
1794testcase TC_rach_load_count() runs on test_CT {
1795 var ASP_RSL_Unitdata rx_ud;
1796 var integer load_access_count := 0;
1797
1798 f_init_vty_bsc();
1799 /* send load indications even at 0% load */
1800 f_vty_load_ind_thresh(0);
1801 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1802 f_sleep(2.0);
1803 f_init();
1804
1805 f_init_l1ctl();
1806 f_sleep(1.0);
1807 f_l1_tune(L1CTL);
1808
Harald Welte52ae1682020-10-11 20:45:55 +02001809 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1810 alt {
1811 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1812 [] RSL_CCHAN.receive { repeat }
1813 }
1814
Harald Welte3453ab42019-05-24 21:19:58 +02001815 var GsmFrameNumber fn_last := 0;
1816 for (var integer i := 0; i < 1000; i := i+1) {
1817 var OCT1 ra := f_rnd_ra_cs();
1818 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1819 if (fn == fn_last) {
1820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1821 }
1822 fn_last := fn;
1823 }
1824
1825 timer T := 5.0;
1826 T.start;
1827 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001828 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001829 -> value rx_ud {
1830 var RSL_IE_Body ie;
1831 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1832 load_access_count := load_access_count + ie.rach_load.access_count;
1833 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1834 setverdict(fail, "Access count cannot be < Busy count");
1835 }
1836 repeat;
1837 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001838 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001839 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1840 repeat;
1841 }
1842 [] RSL_CCHAN.receive {
1843 repeat;
1844 }
1845 [] T.timeout { }
1846 }
1847 if (load_access_count == 1000) {
1848 setverdict(pass);
1849 } else {
1850 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1851 }
1852
1853 f_vty_load_ind_thresh(10);
1854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1855}
1856
Harald Welte54a2a2d2018-02-26 09:14:05 +01001857private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001858 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001859 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001860 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001861 f_sleep(0.5);
1862
1863 /* Transmit RACH request + wait for confirmation */
1864 var OCT1 ra := f_rnd_ra_cs();
1865 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1866
1867 /* Check for expected result */
1868 timer T := 1.5;
1869 T.start;
1870 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001871 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001872 setverdict(pass);
1873 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001874 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001876 }
1877 [] RSL_CCHAN.receive { repeat; }
1878 [not expect_pass] T.timeout {
1879 setverdict(pass);
1880 }
1881 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001883 }
1884 }
1885}
1886
1887/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1888testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001889 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001890 f_init_l1ctl();
1891 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001892 f_sleep(1.0);
1893
1894 /* default max-ta is 63 (full range of GSM timing advance */
1895
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001896 /* We allow early arrival up to 2 symbols */
1897 f_rach_toffs(-1*256, true);
1898 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001899 f_rach_toffs(-10*256, false);
1900
1901 /* 0 / 32 / 63 bits is legal / permitted */
1902 f_rach_toffs(0, true);
1903 f_rach_toffs(32*256, true);
1904 f_rach_toffs(63*256, true);
1905
1906 /* more than 63 bits is not legal / permitted */
1907 f_rach_toffs(64*256, false);
1908 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001910}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001911
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001912private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001913 var GsmFrameNumber fn;
1914 var RSL_Message rm;
1915
1916 f_l1_tune(L1CTL);
1917 RSL.clear;
1918
1919 /* Generate a random Handover Reference */
1920 var integer ho_ref := oct2int(f_rnd_octstring(1));
1921
1922 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1923 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1924 RSL_IE_Body:{ handover_ref := ho_ref }));
1925
1926 /* Activate a channel on the BTS side (no encryption) */
1927 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1928 act_type := t_RSL_IE_ActType_HO_SYNC);
1929
1930 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1931 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001932 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001933
1934 /* Send handover Access Burst */
1935 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1936
1937 /* TODO: test mismatching Handover Reference, and missing IE */
1938
1939 /* Wait for handover detection */
1940 timer T := 3.0;
1941 T.start;
1942 alt {
1943 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1944 log("Handover RACH has been detected: ", rm);
1945 setverdict(pass);
1946 }
1947 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1949 log2str("RSL_CHAN_RQD was not expected: ", rm));
1950 }
1951 [] RSL.receive { repeat; }
1952 [] T.timeout {
1953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1954 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1955 }
1956 }
1957
1958 /* Release the channel */
1959 f_rsl_chan_deact();
1960 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1961}
1962
1963/* Test handover RACH detection */
1964testcase TC_ho_rach() runs on test_CT {
1965 var ConnHdlrPars pars;
1966 var ConnHdlr vc_conn;
1967
1968 f_init();
1969
1970 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1971 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1972 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1973 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1974 vc_conn.done;
1975 }
1976
1977 /* TODO: do the above in parallel, rather than sequentially? */
1978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1979}
1980
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001981/* Test sending of the RR Physical Information message on DCCH */
1982private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1983 var PDU_ML3_NW_MS dcch_pdu;
1984 var integer count := 0;
1985 var L1ctlDlMessage dl;
1986 timer T;
1987
1988 f_l1_tune(L1CTL);
1989 RSL.clear;
1990
1991 /* Generate a random Handover Reference */
1992 var integer ho_ref := oct2int(f_rnd_octstring(1));
1993
1994 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1995 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1996 RSL_IE_Body:{ handover_ref := ho_ref }));
1997
1998 /* Activate a channel on the BTS side (no encryption) */
1999 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2000 act_type := t_RSL_IE_ActType_HO_SYNC);
2001
2002 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2003 * waiting for Immediate Assignment and sending of an Access Burst. */
2004 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2005
2006 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2007 * context means any L2 frames, not only the RR Physical Information. */
2008 T.start(2.0);
2009 L1CTL.clear;
2010 alt {
2011 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2012 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2013 T.stop;
2014 }
2015 [] L1CTL.receive { repeat; }
2016 [] T.timeout { setverdict(pass); }
2017 }
2018
2019 /* Send handover Access Burst */
2020 log("Sending handover Access Burst");
2021 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2022
2023 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2024 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2025 L1CTL.clear;
2026 alt {
2027 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2028 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2029 log("Rx RR Physical Information: ", dcch_pdu);
2030 /* Wait until the count reaches Ny1 */
2031 count := count + 1;
2032 if (count < mp_ho_ny1)
2033 { repeat; }
2034 setverdict(pass);
2035 }
2036 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2037 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2039 }
2040 [] L1CTL.receive { repeat; }
2041 [] T.timeout {
2042 setverdict(fail, "Timeout waiting for RR Physical Information");
2043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2044 }
2045 }
2046
2047 /* Release the channel */
2048 f_rsl_chan_deact();
2049 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2050}
2051testcase TC_ho_physical_info() runs on test_CT {
2052 var ConnHdlrPars pars;
2053 var ConnHdlr vc_conn;
2054
2055 f_init();
2056
2057 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2058 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2059 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2060 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2061 vc_conn.done;
2062 }
2063
2064 /* TODO: do the above in parallel, rather than sequentially? */
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066}
2067
Harald Welte93640c62018-02-25 16:59:33 +01002068/***********************************************************************
2069 * Measurement Processing / Reporting
2070 ***********************************************************************/
2071
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002072private template (value) LapdmAddressField
2073ts_LapdmAddr(template (value) LapdmSapi sapi,
2074 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002075 spare := '0'B,
2076 lpd := 0,
2077 sapi := sapi,
2078 c_r := c_r,
2079 ea := true
2080}
2081
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002082private template (value) LapdmFrameAB
2083ts_LAPDm_AB(template (value) LapdmSapi sapi,
2084 template (value) GsmRrL3Message l3,
2085 template (value) boolean c_r := false,
2086 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002087 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002088 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002089 len := 0, /* overwritten */
2090 m := false,
2091 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002092 payload := enc_GsmRrL3Message(valueof(l3)),
2093 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002094}
2095
2096/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002097private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002098 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002099 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002100
Harald Weltef8df4cb2018-03-10 15:15:08 +01002101 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002102 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002103
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002104 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002105 g_pars.l1_pars.meas_ul.full.rxlev,
2106 g_pars.l1_pars.meas_ul.sub.rxlev,
2107 g_pars.l1_pars.meas_ul.full.rxqual,
2108 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002109 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002110
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002111 var template (value) SacchL1Header l1h := ts_SacchL1Header(
2112 g_pars.l1_pars.ms_power_level, false,
2113 g_pars.l1_pars.ms_actual_ta);
2114
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002115 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2116 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002117
2118 log("Sending Measurement Report: ", l1h, l2);
2119 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002120 repeat;
2121 }
2122}
2123
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002124/* handle incoming downlink SACCH, decode the L1 header into the given record */
2125private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2126 boolean do_apply := true)
2127runs on ConnHdlr
2128{
2129 var L1ctlDlMessage l1_dl;
2130
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2132 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2133 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2134 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2135
2136 if (do_apply) {
2137 /* Update TA and MS power to follow what BTS requests */
2138 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2139 }
2140 }
2141}
2142
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002143private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002144 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002146 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2147 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002148 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2149 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002150 repeat;
2151 }
2152}
2153
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002154private altstep as_l1_tch_loop() runs on ConnHdlr {
2155 var L1ctlDlMessage l1_dl;
2156 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2157 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002158
2159 /* occasionaly inject FACCH frames into the uplink */
2160 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2161 var octetstring pl := '010301'O;
2162 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2163 f_pad_oct(pl, 23, '2B'O)));
2164 } else {
2165 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2166 l1_dl.payload.traffic_ind.data));
2167 }
2168
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002169 repeat;
2170 }
2171}
2172
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002173private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002174 uint6_t rxlev,
2175 uint3_t rxqual
2176}
2177
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002178private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002179 MeasElem full,
2180 MeasElem sub
2181}
2182
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002183private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002184 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002185 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002186 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002187 MeasElemFS meas_ul,
2188 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002189 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002190 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002191 uint8_t ms_actual_ta,
2192 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002193}
2194
2195/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2196private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2197 return 63 + (toffs256s/256);
2198}
2199
Harald Welted5684392018-03-10 18:22:04 +01002200private function f_max(integer a, integer b) return integer {
2201 if (a > b) {
2202 return a;
2203 } else {
2204 return b;
2205 }
2206}
2207
2208private function f_min(integer a, integer b) return integer {
2209 if (a < b) {
2210 return a;
2211 } else {
2212 return b;
2213 }
2214}
2215
2216/* compute negative tolerance val-tolerance, ensure >= min */
2217private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2218 val := val - tolerance;
2219 return f_max(val, min);
2220}
2221
2222/* compute positive tolerance val+tolerance, ensure <= max */
2223private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2224 val := val + tolerance;
2225 return f_min(val, max);
2226}
2227
2228/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2229private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2230return template integer {
2231 var template integer ret;
2232 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2233 return ret;
2234}
2235
2236
Harald Welte70767382018-02-21 12:16:40 +01002237/* build a template for matching measurement results against */
2238private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2239 var ConnL1Pars l1p := g_pars.l1_pars;
2240 var template RSL_IE_UplinkMeas ul_meas := {
2241 len := 3,
2242 rfu := '0'B,
2243 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002244 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002245 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002246 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002247 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002248 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2249 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002250 supp_meas_info := omit
2251 };
Harald Welte685d5982018-02-27 20:42:05 +01002252 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002253 ul_meas.len := (3+8);
2254 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002255 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002256 toa256_min := ?,
2257 toa256_max := ?,
2258 toa256_std_dev := ?
2259 }
Harald Welte685d5982018-02-27 20:42:05 +01002260 }
Harald Welte70767382018-02-21 12:16:40 +01002261 var template RSL_IE_BS_Power bs_power := {
2262 reserved := 0,
2263 epc := false,
2264 fpc := false,
2265 power_level := l1p.bs_power_level
2266 };
2267 var template RSL_IE_L1Info l1_info := {
2268 ms_power_lvl := l1p.ms_power_level,
2269 fpc := false,
2270 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002271 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002272 };
2273 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002274 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002275 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2276 ?, t_toffs);
2277}
2278
Philipp Maierdd841d32019-12-17 14:44:54 +01002279/* build a template for matching measurement results that do not contain any
2280 * MS related measurement (l1_info, l3_info and ms timing offset). */
2281private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2282 var ConnL1Pars l1p := g_pars.l1_pars;
2283 var template RSL_IE_UplinkMeas ul_meas := {
2284 len := 3,
2285 rfu := '0'B,
2286 dtx_d := l1p.dtx_enabled,
2287 rxlev_f_u := ?,
2288 reserved1 := '00'B,
2289 rxlev_s_u := ?,
2290 reserved2 := '00'B,
2291 rxq_f_u := ?,
2292 rxq_s_u := ?,
2293 supp_meas_info := omit
2294 };
2295 if (l1p.toa256_enabled) {
2296 ul_meas.len := (3+8);
2297 ul_meas.supp_meas_info := {
2298 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2299 toa256_min := ?,
2300 toa256_max := ?,
2301 toa256_std_dev := ?
2302 }
2303 }
2304 var template RSL_IE_BS_Power bs_power := {
2305 reserved := 0,
2306 epc := false,
2307 fpc := false,
2308 power_level := l1p.bs_power_level
2309 };
2310
2311 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2312}
2313
Harald Welte70767382018-02-21 12:16:40 +01002314/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002315private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002316 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002317 var boolean chan_est := false;
2318
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002319 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002320
2321 /* Receive osmocom specific measurement reports. This is the normal
2322 * case. Here we verify that the measurement reports we sent are
2323 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002324 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2325 /* increment counter of next to-be-expected meas rep */
2326 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2327 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002328 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002329
2330 /* The following two cases may only happen in the beginning
2331 * of the channel establishment phase. Once we have received
2332 * the "our" measurement report the first time, the channel
2333 * is established and empty or hardcoded TRXCON reports must
2334 * not occur anymore. */
2335 chan_est := true;
2336
2337 repeat;
2338 }
2339
2340 /* When the BTS has established the channel, the MS might need slightly
2341 * more time to establish the channel and actually start sending. The
2342 * result is then a measurement report that just lacks the measurement
2343 * information of the MS. This is normal and we tolerate this behavior. */
2344 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2345 /* increment counter of next to-be-expected meas rep */
2346 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2347 /* Re-start the timer expecting the next MEAS RES */
2348 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002349 repeat;
2350 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002351
2352 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2353 * measurements if the TTCN3 side does not supply measurement input in
2354 * time. In those cases TRXCON will either use a cached measurement
2355 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2356 * report the templates above will not match. We tolerate this
2357 * behavior, but only once. */
2358 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01002359 /* increment counter of next to-be-expected meas rep */
2360 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2361 if (g_first_meas_res) {
2362 g_first_meas_res := false;
2363 repeat;
2364 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002366 }
Harald Welte70767382018-02-21 12:16:40 +01002367 }
2368 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002370 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002371 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002373 }
2374}
2375
Harald Weltee613f962018-04-18 22:38:16 +02002376private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2377 select (rsl_alg_id) {
2378 case (RSL_ALG_ID_A5_0) { return 0; }
2379 case (RSL_ALG_ID_A5_1) { return 1; }
2380 case (RSL_ALG_ID_A5_2) { return 2; }
2381 case (RSL_ALG_ID_A5_3) { return 3; }
2382 case (RSL_ALG_ID_A5_4) { return 4; }
2383 case (RSL_ALG_ID_A5_5) { return 5; }
2384 case (RSL_ALG_ID_A5_6) { return 6; }
2385 case (RSL_ALG_ID_A5_7) { return 7; }
2386 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2388 /* Make compiler happy by calling mtc.stop here. It is already
2389 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002390 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002391 }
2392 }
2393}
2394
2395private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2396 select (rsl_alg_id) {
2397 case (RSL_ALG_ID_A5_1) { return '000'B; }
2398 case (RSL_ALG_ID_A5_2) { return '001'B; }
2399 case (RSL_ALG_ID_A5_3) { return '010'B; }
2400 case (RSL_ALG_ID_A5_4) { return '011'B; }
2401 case (RSL_ALG_ID_A5_5) { return '100'B; }
2402 case (RSL_ALG_ID_A5_6) { return '101'B; }
2403 case (RSL_ALG_ID_A5_7) { return '110'B; }
2404 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2406 /* Make compiler happy by calling mtc.stop here. It is already
2407 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002408 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002409 }
2410 }
2411}
2412
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002413/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2414private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2415 var GsmFrameNumber fn;
2416 timer T := 8.0;
2417
2418 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2419 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2420
2421 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2422 /* Send the actual RACH */
2423 fn := f_L1CTL_RACH(L1CTL, ra);
2424
2425 T.start;
2426 alt {
2427 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2428 [] T.timeout {
2429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2430 }
2431 }
2432 T.stop
2433 return fn;
2434}
Harald Weltee613f962018-04-18 22:38:16 +02002435
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002436/* Tune to a dedicated channel: L1CTL only */
2437private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002438 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002439 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002440 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002441 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002442 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002443 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002444 pars.fhp.maio_hsn.hsn,
2445 pars.fhp.maio_hsn.maio,
2446 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002447 }
2448}
2449
Harald Welte70767382018-02-21 12:16:40 +01002450/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002451private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002452 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002453
2454 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002455 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002456
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002457 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002458 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002459 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002460 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002461 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2462 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002463 }
2464
Harald Welte70767382018-02-21 12:16:40 +01002465 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002466 f_l1ctl_est_dchan(L1CTL, g_pars);
2467
Harald Weltee613f962018-04-18 22:38:16 +02002468 /* enable encryption, if requested */
2469 if (encr_enable) {
2470 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2471 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2472 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002473
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002474 /* Send TCH Mode Request to the L1 if needed */
2475 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2476 var L1ctlTchMode tch_mode;
2477
2478 select (g_pars.chan_mode.coding_alg_rate) {
2479 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2480 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2481 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2482 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2483 case else {
2484 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2485 " is not supported by the L1, falling back to signalling");
2486 tch_mode := L1CTL_CHAN_MODE_SIGN;
2487 }
2488 }
2489
2490 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2491 }
2492
Harald Weltefa45e9e2018-03-10 18:59:03 +01002493 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002494}
2495
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002496/* Initialize and start the RTP emulation component for a ConnHdlr */
2497friend function f_rtpem_activate(inout octetstring payload,
2498 RtpemConfig cfg := c_RtpemDefaultCfg,
2499 RtpemMode mode := RTPEM_MODE_BIDIR)
2500runs on ConnHdlr {
2501 /* Step 0: initialize, connect and start the emulation component */
2502 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2503 map(vc_RTPEM:RTP, system:RTP);
2504 map(vc_RTPEM:RTCP, system:RTCP);
2505 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2506 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2507 vc_RTPEM.start(RTP_Emulation.f_main());
2508
2509 /* Step 1: configure the RTP parameters */
2510 var integer payload_len := 0;
2511 var octetstring hdr := ''O;
2512
2513 select (g_pars.chan_mode) {
2514 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2515 { payload_len := 33; hdr := 'D0'O; }
2516 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2517 { payload_len := 15; hdr := '00'O; }
2518 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2519 { payload_len := 31; hdr := 'C0'O; }
2520 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2521 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2523 }
2524 }
2525
2526 /* Pad the payload to conform the expected length */
2527 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2528 cfg.tx_fixed_payload := payload;
2529 f_rtpem_configure(RTPEM_CTRL, cfg);
2530
2531 /* Step 2: bind the RTP emulation to the configured address */
2532 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2533 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2534
2535 /* Step 3: send CRCX with the configured address/port to the IUT */
2536 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2537 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2538 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2539 "IPA CRCX ACK");
2540
2541 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2542 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2543 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2544 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2545
2546 /* Step 5: set the given RTP emulation mode */
2547 f_rtpem_mode(RTPEM_CTRL, mode);
2548}
2549
Harald Welte70767382018-02-21 12:16:40 +01002550/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002551private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002552 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002553 RSL.clear;
2554
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002555 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002556 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002557 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002558 }
Harald Welte70767382018-02-21 12:16:40 +01002559
2560 f_est_dchan();
2561
2562 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2563 * RSL measurement reports on Abis side */
2564 timer T := 8.0;
2565 T.start;
2566 alt {
2567 [] as_l1_sacch();
2568 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002569 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002570 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002571 [] L1CTL.receive { repeat; }
2572 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002573 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002574 * of any earlier errors, so if we reach this timeout, we're good */
2575 setverdict(pass);
2576 }
2577 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002579 }
2580 }
2581 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002582 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002583}
Harald Welte0472ab42018-03-12 15:02:26 +01002584
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002585/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2586private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002587 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002588 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2589 timer Tup := 10.0;
2590 Tup.start;
2591 alt {
2592 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2593 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2594 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002595
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002596 if (rx_lvl != max_rx_lvl) {
2597 repeat;
2598 }
2599 Tup.stop;
2600 }
2601 [] L1CTL.receive { repeat; }
2602 [] Tup.timeout {
2603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2604 log2str("Didn't reach full power ", max_rx_lvl));
2605 }
2606 }
2607 return max_rx_lvl;
2608}
2609
2610/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2611private function f_verify_ramp_up() runs on ConnHdlr {
2612 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002613 var integer initial_rx_lvl := -1;
2614 var integer last_rx_lvl := -1;
2615 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2616
2617 timer T := 2.0;
2618 alt {
2619 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2620 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2621 log("Received rx_level=", rx_lvl);
2622 if (initial_rx_lvl == -1) {
2623 initial_rx_lvl := rx_lvl;
2624 last_rx_lvl := rx_lvl;
2625
2626 /* Expect a somehow low value during first received messages */
2627 if (initial_rx_lvl >= max_rx_lvl / 2) {
2628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2629 log2str("Detected high initial tx power during ramp up: ",
2630 initial_rx_lvl , ", full power is", max_rx_lvl));
2631 }
2632 }
2633
2634 /* received Rx level bigger than maximum allowed power by CN */
2635 if (rx_lvl > max_rx_lvl) {
2636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2637 log2str("Detected Tx power higher than full power: ",
2638 rx_lvl , " > ", max_rx_lvl));
2639 }
2640
2641 /* Make sure it never decreases, since we are rumping up */
2642 if (last_rx_lvl > rx_lvl) {
2643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2644 log2str("Detected Tx power decrease during ramp up: ",
2645 last_rx_lvl , " -> ", rx_lvl));
2646 }
2647
2648 if (rx_lvl == max_rx_lvl and not T.running) {
2649 /* We reached the maximum power, start timer and receive
2650 /* a few more to make sure we don't surpass it */
2651 log("Reached full power, wating a bit more until success");
2652 T.start;
2653 }
2654
2655 last_rx_lvl := rx_lvl;
2656 repeat;
2657 }
2658 [] L1CTL.receive { repeat; }
2659 [] T.timeout { }
2660 }
2661
2662 /* We didn't increase tx power during ramp up */
2663 if (initial_rx_lvl < last_rx_lvl) {
2664 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2665 } else {
2666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2667 log2str("No Tx power increase during whole ramp up: ",
2668 initial_rx_lvl , " -> ", last_rx_lvl));
2669 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002670}
2671
2672/* verify BTS ramps power down to rx_level 0 */
2673private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2674 var L1ctlDlMessage l1_dl;
2675 var integer last_rx_lvl := max_rx_lvl;
2676
2677 timer Tdown := 5.0;
2678 Tdown.start;
2679 alt {
2680 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2681 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2682 log("Received rx_level=", rx_lvl);
2683
2684 /* received Rx level bigger than maximum allowed power by CN */
2685 if (rx_lvl > max_rx_lvl) {
2686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2687 log2str("Detected Tx power higher than full power: ",
2688 rx_lvl , " > ", max_rx_lvl));
2689 }
2690
2691 /* Make sure it never increases, since we are rumping down */
2692 if (last_rx_lvl < rx_lvl) {
2693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2694 log2str("Detected Tx power increase during ramp up: ",
2695 last_rx_lvl , " -> ", rx_lvl));
2696 }
2697
2698 last_rx_lvl := rx_lvl;
2699 if (last_rx_lvl != 0) {
2700 repeat;
2701 }
2702 /* we reached power level 0, we are done */
2703 Tdown.stop;
2704 }
2705 [] L1CTL.receive { repeat; }
2706 [] Tdown.timeout { }
2707 }
2708
2709 /* We didn't increase tx power during ramp down */
2710 if (max_rx_lvl > last_rx_lvl) {
2711 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2712 } else {
2713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2714 log2str("No Tx power decrease during whole ramp down: ",
2715 max_rx_lvl , " -> ", last_rx_lvl));
2716 }
2717}
2718
2719/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002720private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002721 f_l1_tune(L1CTL);
2722 RSL.clear;
2723
2724 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002725
2726 setverdict(pass);
2727}
2728testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2729 var ConnHdlr vc_conn;
2730 var ConnHdlrPars pars;
2731 f_init();
2732 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2733 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2734 pcu_comp := false, trxc_comp := true);
2735 vc_conn.done;
2736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2737}
2738
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002739/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002740private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002741 f_connhdlr_init_vty_bsc();
2742
2743 f_l1_tune(L1CTL);
2744 RSL.clear;
2745
2746 /* Wait until BTS is started and at full power */
2747 var integer max_rx_lvl := f_wait_ramp_up();
2748 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2749
2750 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2751 f_verify_ramp_down(max_rx_lvl);
2752
2753 setverdict(pass);
2754}
2755testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2756 var ConnHdlr vc_conn;
2757 var ConnHdlrPars pars;
2758 f_init();
2759 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2760 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2761 pcu_comp := false, trxc_comp := true);
2762 vc_conn.done;
2763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2764}
2765
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002766/* Verify Tx power:
2767 * + ramping down during ADM state UNLOCKED->LOCKED
2768 * + ramping up during ADM state LOCKED->UNLOCKED
2769 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002770private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002771 var L1ctlDlMessage l1_dl;
2772 var integer last_rx_lvl;
2773
2774 f_connhdlr_init_vty_bsc();
2775
2776 f_l1_tune(L1CTL);
2777 RSL.clear;
2778
2779 /* Wait until BTS is started and at full power */
2780 var integer max_rx_lvl := f_wait_ramp_up();
2781 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2782
2783 log("ADM STATE UNLOCKED->LOCKED");
2784 f_vty_enter_cfg_trx(BSCVTY);
2785 f_vty_transceive(BSCVTY, "rf_locked 1");
2786 last_rx_lvl := max_rx_lvl;
2787 f_verify_ramp_down(max_rx_lvl);
2788
2789 /* Let some time after we received 0dBm, then check we don't receive BCCH
2790 * anymore because scheduler has stopped after ramping down */
2791 f_sleep(2.0);
2792 L1CTL.clear;
2793 timer Tlocked := 2.0;
2794 Tlocked.start;
2795 alt {
2796 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2798 log2str("Received data_ind during rf_locked: ", l1_dl));
2799 }
2800 [] L1CTL.receive { repeat; }
2801 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2802 }
2803
2804 log("ADM STATE LOCKED->UNLOCKED");
2805 f_vty_transceive(BSCVTY, "rf_locked 0");
2806 f_verify_ramp_up();
2807 setverdict(pass);
2808}
2809testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2810 var ConnHdlr vc_conn;
2811 var ConnHdlrPars pars;
2812 f_init();
2813 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2814 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2815 pcu_comp := false, trxc_comp := true);
2816 vc_conn.done;
2817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2818}
2819
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002820private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002821 timer T := 8.0;
2822 T.start;
2823 var RSL_Message rsl;
2824 alt {
2825 [] as_l1_sacch();
2826 [] L1CTL.receive { repeat; }
2827 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2828 if (rsl.ies[3].body.bs_power.power_level == level) {
2829 setverdict(pass)
2830 } else {
2831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2832 }
2833 }
2834 [] T.timeout {
2835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2836 }
2837 }
2838}
2839
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002840/* See if the RSL MEASurement RESult contains expeced BS power level
2841 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002842private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002843 f_l1_tune(L1CTL);
2844 RSL.clear;
2845
2846 if (mp_bts_trxc_port != -1) {
2847 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2848 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2849 }
2850
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002851 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002852 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2853 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2854
2855 f_est_dchan(more_ies :={valueof(pwr)});
2856
2857 f_check_meas_bs_power_level(pwr_var);
2858
2859 f_rsl_chan_deact();
2860 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2861}
2862
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002863/* See if the RSL MEASurement RESult contains expeced BS power level
2864 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002865private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002866 f_l1_tune(L1CTL);
2867 RSL.clear;
2868
2869 if (mp_bts_trxc_port != -1) {
2870 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2871 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2872 }
2873
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002874 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002875 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2876
2877 f_est_dchan();
2878
2879 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2880
2881 f_check_meas_bs_power_level(pwr_var);
2882
2883 f_rsl_chan_deact();
2884 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2885}
2886
2887testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2888 var ConnHdlr vc_conn;
2889 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002890
Eric Wildae8f2622019-06-18 17:05:11 +02002891 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002892
2893 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2894 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2895 pcu_comp := false, trxc_comp := true);
2896 vc_conn.done;
2897
Eric Wildae8f2622019-06-18 17:05:11 +02002898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2899}
2900
2901testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2902 var ConnHdlr vc_conn;
2903 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002904
Eric Wildae8f2622019-06-18 17:05:11 +02002905 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002906
2907 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2908 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2909 pcu_comp := false, trxc_comp := true);
2910 vc_conn.done;
2911
Eric Wildae8f2622019-06-18 17:05:11 +02002912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2913}
2914
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002915/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2916 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2917 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002918private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002919 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002920 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002921
2922 f_trxc_fake_rssi(rxlev2dbm(10));
2923 f_l1_tune(L1CTL);
2924 RSL.clear;
2925
2926 var RSL_IE_List addl_ies;
2927 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2928
2929 addl_ies := {
2930 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2931 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2932 };
2933
2934 /* establish with power parameters */
2935 f_est_dchan(more_ies := addl_ies);
2936
2937 /* set a high value to ensure L1 power control level increases */
2938 f_trxc_fake_rssi(rxlev2dbm(20));
2939
2940 timer T2 := 6.0;
2941 T2.start;
2942 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002943 [] as_l1_sacch_l1h(l1h) {
2944 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002945 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002946 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002947 T2.stop;
2948 }
2949 [] L1CTL.receive { repeat; }
2950 [] T2.timeout {
2951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2952 "Power Level in L1 header has not increased sufficiently");
2953 }
2954 }
2955
2956 /* set a low value to ensure L1 power control level decreases */
2957 f_trxc_fake_rssi(rxlev2dbm(0));
2958
2959 timer T4 := 6.0;
2960 T4.start;
2961 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002962 [] as_l1_sacch_l1h(l1h) {
2963 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002964 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002965 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002966 T4.stop;
2967 setverdict(pass, "Power level in L1 decreased/increased as expected");
2968 }
2969 [] L1CTL.receive { repeat; }
2970 [] T4.timeout {
2971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2972 "Power Level in L1 header has not decreased sufficiently");
2973 }
2974 }
2975
2976 f_rsl_chan_deact();
2977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2978
2979}
2980
2981/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002982private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002983 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002985
2986 /* set a low value to ensure power increases */
2987 f_trxc_fake_rssi(rxlev2dbm(10));
2988 f_l1_tune(L1CTL);
2989 RSL.clear;
2990
2991 var RSL_IE_List addl_ies;
2992 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2993
2994 addl_ies := {
2995 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2996 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2997 };
2998
2999 /* establish with power parameters */
3000 f_est_dchan(more_ies := addl_ies);
3001
3002 timer T1 := 10.0;
3003 T1.start;
3004 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003005 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003006 [] L1CTL.receive { repeat; }
3007 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003008 if (not isbound(l1h)) {
3009 setverdict(fail, "No SACCH blocks were received");
3010 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003011 setverdict(fail, "Power level in L1 header should not have changed");
3012 }
3013 }
3014 }
3015
3016 f_rsl_chan_deact();
3017 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3018
3019}
3020
3021/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003022private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003023 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003024 var uint5_t pwr_var := 15;
3025 var uint5_t pwr_max_var := f_get_max_power_from_band();
3026
3027 /* set a low value to ensure power increases */
3028 f_trxc_fake_rssi(rxlev2dbm(10));
3029 f_l1_tune(L1CTL);
3030 RSL.clear;
3031
3032 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3033 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3034
3035 /* establish with fixed power level */
3036 f_est_dchan(more_ies :={valueof(pwr)});
3037
3038 /* check our initial power level */
3039 f_wait_for_l1_power_level(pwr_var);
3040
3041 /* update power param to enable power loop
3042 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3043 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3044
3045 /* wait, then check that our power level was reduced */
3046 timer T1 := 10.0;
3047 T1.start;
3048 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003049 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003050 [] L1CTL.receive { repeat; }
3051 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003052 if (not isbound(l1h)) {
3053 setverdict(fail, "No SACCH blocks were received");
3054 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003055 setverdict(pass, "Power level in L1 header reduced as expected");
3056 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003057 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3058 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003059 }
3060 }
3061 }
3062
3063 f_rsl_chan_deact();
3064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3065
3066}
3067
3068/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003069private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003070 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003071
3072 /* set a high value to ensure power decreases */
3073 f_trxc_fake_rssi(rxlev2dbm(50));
3074 f_l1_tune(L1CTL);
3075 RSL.clear;
3076
3077 var uint5_t pwr_var := 5;
3078 var uint5_t pwr_target_val := 15;
3079
3080 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3081 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3082
3083 /* establish with fixed power level */
3084 f_est_dchan(more_ies :={valueof(pwr)});
3085
3086 /* check our initial power level */
3087 f_wait_for_l1_power_level(pwr_var);
3088
3089 /* update power param to enable power loop
3090 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003091 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003092
3093 /* wait, then check that our power level was increased */
3094 timer T1 := 10.0;
3095 T1.start;
3096 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003097 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003098 [] L1CTL.receive { repeat; }
3099 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003100 if (not isbound(l1h)) {
3101 setverdict(fail, "No SACCH blocks were received");
3102 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3103 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003104 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003105 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003106 }
3107 }
3108 }
3109
3110 f_rsl_chan_deact();
3111 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3112
3113}
3114
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003115/* See if the power level remains constant when MS Power Parameters IE
3116 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003117private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003118 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003119
3120 /* set a high value to ensure power decreases */
3121 f_trxc_fake_rssi(rxlev2dbm(50));
3122 f_l1_tune(L1CTL);
3123 RSL.clear;
3124
3125 var uint5_t pwr_var := 5;
3126
3127 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3128 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3129
3130 /* establish with fixed power level */
3131 f_est_dchan(more_ies :={valueof(pwr)});
3132
3133 /* check our initial power level */
3134 f_wait_for_l1_power_level(pwr_var);
3135
3136 /* wait, then check that our power level did not change */
3137 timer T1 := 10.0;
3138 T1.start;
3139 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003140 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3141 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3143 "BS power control should not be active unless we receive a power parameters IE!");
3144 }
3145 repeat;
3146 }
3147 [] L1CTL.receive { repeat; }
3148 [] T1.timeout { setverdict(pass); }
3149 }
3150
3151 f_rsl_chan_deact();
3152 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3153
3154}
3155
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003156/* See if the power level remains constant when MS Power Parameters IE
3157 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003158private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003159 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003160
3161 /* set a high value to ensure power decreases */
3162 f_trxc_fake_rssi(rxlev2dbm(50));
3163 f_l1_tune(L1CTL);
3164 RSL.clear;
3165
3166 var uint5_t pwr_var := 5;
3167
3168 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3169 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3170
3171 /* establish with fixed power level */
3172 f_est_dchan(more_ies :={valueof(pwr)});
3173
3174 /* check our initial power level */
3175 f_wait_for_l1_power_level(pwr_var);
3176
3177 /* pwr control without power params IE, should NOT activate MS power control*/
3178 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3179
3180 /* wait, then check that our power level did not change */
3181 timer T1 := 10.0;
3182 T1.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 != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3187 "BS power control should not be active unless we receive a power parameters IE!");
3188 }
3189 repeat;
3190 }
3191 [] L1CTL.receive { repeat; }
3192 [] T1.timeout { setverdict(pass); }
3193 }
3194
3195 f_rsl_chan_deact();
3196 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3197
3198}
3199
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003200private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003201 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003202 timer T0 := 10.0;
3203 T0.start;
3204 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003205 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3206 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3208 "Power level in L1 header != signaled (RSL) power level.");
3209 }
3210 }
3211 [] L1CTL.receive { repeat; }
3212 [] T0.timeout {
3213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3214 "Timeout waiting for initial power level");
3215 }
3216 }
3217 T0.stop;
3218}
3219
3220private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3221 var IntegerRecord min_dbm_level;
3222 var IntegerRecord max_dbm_level;
3223 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3224
3225 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3226 if (min_dbm_level[i] == level) {
3227 return true;
3228 }
3229 }
3230 return false;
3231}
3232
3233private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3234 var IntegerRecord min_dbm_level;
3235 var IntegerRecord max_dbm_level;
3236 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3237
3238 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3239 if (max_dbm_level[i] == level) {
3240 return true;
3241 }
3242 }
3243 return false;
3244}
3245
3246private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3247 var IntegerRecord min_dbm_level;
3248 var IntegerRecord max_dbm_level;
3249 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3250 return max_dbm_level[0];
3251}
3252
3253type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003254private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003255private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3256 // 45.005 4.1.1
3257 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3258 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3259 2, 1, 0};
3260 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3261 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3262 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3263 var IntegerRecord rv;
3264
3265 select(band){
3266 case (BtsBand_allGSM){
3267 rv := gsm_power;
3268 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3269 max_dbm_level := {2, 1, 0};
3270 }
3271 case("DCS1800"){
3272 rv := dcs_power;
3273 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3274 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3275 }
3276 case("PCS1900"){
3277 rv := pcs_power;
3278 min_dbm_level := {15};
3279 max_dbm_level := {30};
3280 }
Harald Welte194b6912020-10-11 21:01:55 +02003281 case else {
3282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3283 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003284 }
3285
3286 return rv;
3287}
3288
3289private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003290 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 +02003291}
3292
3293testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3294 var ConnHdlr vc_conn;
3295 var ConnHdlrPars pars;
3296 f_init();
3297 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3298 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3299 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3300 pars.bts0_band := f_vty_get_bts0_band();
3301 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3302 vc_conn.done;
3303 }
3304 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3306}
3307
3308testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3309 var ConnHdlr vc_conn;
3310 var ConnHdlrPars pars;
3311 f_init();
3312 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3313 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3314 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3315 pars.bts0_band := f_vty_get_bts0_band();
3316 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3317 vc_conn.done;
3318 }
3319 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3321}
3322
3323testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3324 var ConnHdlr vc_conn;
3325 var ConnHdlrPars pars;
3326 f_init();
3327 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3328 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3329 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3330 pars.bts0_band := f_vty_get_bts0_band();
3331 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3332 vc_conn.done;
3333 }
3334 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3336}
3337
3338testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3339 var ConnHdlr vc_conn;
3340 var ConnHdlrPars pars;
3341 f_init();
3342 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3343 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3344 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3345 pars.bts0_band := f_vty_get_bts0_band();
3346 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3347 vc_conn.done;
3348 }
3349 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3351}
3352
Eric Wild280ccb82019-06-17 11:11:52 +02003353testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3354 var ConnHdlr vc_conn;
3355 var ConnHdlrPars pars;
3356 f_init();
3357 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3358 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3359 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3360 pars.bts0_band := f_vty_get_bts0_band();
3361 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3362 vc_conn.done;
3363 }
3364 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3366}
3367
Eric Wild095024b2019-06-17 15:08:57 +02003368testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3369 var ConnHdlr vc_conn;
3370 var ConnHdlrPars pars;
3371 f_init();
3372 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3373 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3374 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3375 pars.bts0_band := f_vty_get_bts0_band();
3376 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3377 vc_conn.done;
3378 }
3379 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3381}
3382
Philipp Maier149c3922020-10-22 17:29:36 +02003383function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003384 var template RSL_IE_ChannelMode ch_mode;
3385 var ConnHdlr vc_conn;
3386 var ConnHdlrPars pars;
3387 f_init();
3388 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3389 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3390 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003391 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003392 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3393 pcu_comp := false, trxc_comp := true);
3394 vc_conn.done;
3395 }
3396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3397}
Philipp Maier149c3922020-10-22 17:29:36 +02003398
3399testcase TC_meas_res_speech_tchf() runs on test_CT {
3400 f_TC_meas_res_speech_tchf(false);
3401}
3402
3403testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3404 f_TC_meas_res_speech_tchf(true);
3405}
3406
3407function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003408 var template RSL_IE_ChannelMode ch_mode;
3409 var ConnHdlr vc_conn;
3410 var ConnHdlrPars pars;
3411 f_init();
3412 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3413 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3414 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003415 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003416 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3417 pcu_comp := false, trxc_comp := true);
3418 vc_conn.done;
3419 }
3420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3421}
Philipp Maier149c3922020-10-22 17:29:36 +02003422
3423testcase TC_meas_res_speech_tchh() runs on test_CT {
3424 f_TC_meas_res_speech_tchh(false)
3425}
3426
3427testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3428 f_TC_meas_res_speech_tchh(true)
3429}
3430
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003431testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3432 var template RSL_IE_ChannelMode ch_mode;
3433 var ConnHdlr vc_conn;
3434 var ConnHdlrPars pars;
3435 f_init();
3436 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3437 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3438 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3439 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3440 pars.l1_pars.toa256_enabled := true;
3441 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3442 pcu_comp := false, trxc_comp := true);
3443 vc_conn.done;
3444 }
3445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3446}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003447
Harald Welte70767382018-02-21 12:16:40 +01003448testcase TC_meas_res_sign_tchf() runs on test_CT {
3449 var ConnHdlr vc_conn;
3450 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003451 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003452 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003453 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003454 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003455 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3456 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003457 vc_conn.done;
3458 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003460}
3461testcase TC_meas_res_sign_tchh() runs on test_CT {
3462 var ConnHdlr vc_conn;
3463 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003464 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003465 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003466 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003467 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003468 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3469 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003470 vc_conn.done;
3471 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003473}
3474testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3475 var ConnHdlr vc_conn;
3476 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003477 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003478 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003479 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3480 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003481 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3482 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003483 vc_conn.done;
3484 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003486}
3487testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3488 var ConnHdlr vc_conn;
3489 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003490 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003491 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003492 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3493 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003494 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3495 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003496 vc_conn.done;
3497 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003499}
Harald Welte685d5982018-02-27 20:42:05 +01003500testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3501 var ConnHdlr vc_conn;
3502 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003503 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003504 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3505 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003506 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003507 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003508 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3509 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003510 vc_conn.done;
3511 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003513}
3514
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003515/* Make sure that we always get RSL MEASurement RESult messages regardless
3516 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3517private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3518 timer Texec := 8.0;
3519 timer Timpf := 2.0;
3520 timer Tmr;
3521
3522 f_l1_tune(L1CTL);
3523 RSL.clear;
3524
3525 f_est_dchan();
3526 L1CTL.clear;
3527
3528 /* Establish the main SAPI=0 link on DCCH first */
3529 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3530
3531 /* Give more time for the first RSL MEASurement RESult */
3532 Tmr.start(0.480 * 2.0);
3533 Texec.start; /* EXECution timer */
3534 Timpf.start; /* IMPFung timer */
3535
3536 alt {
3537 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3538 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3539 /* Reschedule the MEAS RES timer */
3540 Tmr.start(0.480 + 0.120);
3541 repeat;
3542 }
3543 [] RSL.receive { repeat; }
3544 [] Tmr.timeout {
3545 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3546 }
3547 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3548 [] Timpf.timeout {
3549 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3550 log("Injected SAPI=3 traffic on SACCH");
3551 Timpf.start;
3552 repeat;
3553 }
3554 /* We're good if survived so far */
3555 [] Texec.timeout {
3556 setverdict(pass);
3557 }
3558 }
3559
3560 f_rsl_chan_deact();
3561 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3562 f_rslem_unregister(0, g_chan_nr);
3563}
3564testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3565 var template RSL_IE_ChannelMode ch_mode;
3566 var template ConnHdlrPars pars;
3567 var ConnHdlr vc_conn;
3568
3569 f_init();
3570
3571 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3572 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3573
3574 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3575 vc_conn.done;
3576
3577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3578}
3579testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3580 var template RSL_IE_ChannelMode ch_mode;
3581 var template ConnHdlrPars pars;
3582 var ConnHdlr vc_conn;
3583
3584 f_init();
3585
3586 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3587 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3588
3589 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3590 vc_conn.done;
3591
3592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3593}
3594
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003595/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3596 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003597private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003598 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003599 var RSL_IE_MS_Power ms_power;
3600 var RSL_Message rsl;
3601 var uint5_t power_level := 0;
3602
3603 f_l1_tune(L1CTL);
3604 RSL.clear;
3605
3606 f_est_dchan();
3607
3608 ms_power.reserved := 0;
3609 ms_power.fpc_epc := false;
3610
3611 /* Send the first power control command. This will disable any BTS/TRX
3612 * internal power control and switch the MS (which is not in scope of
3613 * this test) to a constant power level. We start with a power level
3614 * of 0 */
3615 ms_power.power_level := power_level;
3616 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3617 RSL.send(rsl);
3618
3619 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003620 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3621 if (l1h.ms_power_lvl != power_level) {
3622 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3623 "match the signaled (RSL) power level := ", power_level);
3624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003625 }
3626
3627 /* Signal a new power level via RSL for the next turn. */
3628 if (power_level < 31) {
3629 power_level := power_level + 1;
3630 ms_power.power_level := power_level;
3631 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3632 RSL.send(rsl);
3633 repeat;
3634 }
3635
3636 }
3637
3638 /* Ignore all other blocks */
3639 [] L1CTL.receive { repeat; }
3640
3641 }
3642
3643 f_rsl_chan_deact();
3644 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3645
3646 setverdict(pass);
3647}
3648
3649testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3650 var ConnHdlr vc_conn;
3651 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003652 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003653
3654 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3655 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3656 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3657 vc_conn.done;
3658 }
3659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3660}
Harald Welte70767382018-02-21 12:16:40 +01003661
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003662/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003663TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003664private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003665 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003666 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003667
3668 f_l1_tune(L1CTL);
3669 RSL.clear;
3670
3671 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003672 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003673
3674 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3675
3676
3677 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003678 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3679 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003680 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3681 }
3682
3683 }
3684
3685 /* Ignore all other blocks */
3686 [] L1CTL.receive { repeat; }
3687
3688 }
3689
3690 f_rsl_chan_deact();
3691 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3692
3693 setverdict(pass);
3694}
3695
3696testcase TC_rsl_chan_initial_ta() runs on test_CT {
3697 var ConnHdlr vc_conn;
3698 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003699 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003700 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003701 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3702 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003703 vc_conn.done;
3704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3705}
3706
Eric Wilde57e1a62019-05-28 13:30:55 +02003707/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003708private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003709 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003710 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003711
3712 var RSL_IE_MS_Power ms_power;
3713 ms_power.reserved := 0;
3714 ms_power.fpc_epc := false;
3715 ms_power.power_level := ms_power_level;
3716
3717 f_l1_tune(L1CTL);
3718 RSL.clear;
3719
3720 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3721
3722 timer T := 1.0;
3723 T.start;
3724 alt {
3725 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003726 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3727 if (l1h.ms_power_lvl != ms_power_level) {
3728 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3729 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003730 }
3731 }
3732 /* Ignore all other blocks */
3733 [] L1CTL.receive { repeat; }
3734 [] T.timeout {
3735 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3736 }
3737 }
3738
3739 f_rsl_chan_deact();
3740 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3741 setverdict(pass);
3742}
3743
3744testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3745 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3746 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3747}
3748
Harald Welte0472ab42018-03-12 15:02:26 +01003749/* 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 +01003750private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003751 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003752 RSL.clear;
3753
3754 f_est_dchan();
3755 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003756 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003757
3758 timer T := 40.0;
3759 T.start;
3760 alt {
3761 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3762 setverdict(pass)
3763 }
3764 [] RSL.receive { repeat };
3765 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003767 }
3768 }
3769 f_rsl_chan_deact();
3770}
3771testcase TC_conn_fail_crit() runs on test_CT {
3772 var ConnHdlr vc_conn;
3773 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003774 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003775 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3776 pars.t_guard := 60.0;
3777 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3778 vc_conn.done;
3779}
3780
Harald Welte93640c62018-02-25 16:59:33 +01003781/***********************************************************************
3782 * Paging
3783 ***********************************************************************/
3784
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003785private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003786 if (tmsi == 'FFFFFFFF'O) {
3787 return true;
3788 } else {
3789 return false;
3790 }
3791}
Harald Welte70767382018-02-21 12:16:40 +01003792
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003793private type record allowedFn { integer frame_nr }
3794private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3795private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3796private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3797private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3798private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3799private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3800private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3801private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3802private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003803{
3804 var integer frame_nr_51;
3805 frame_nr_51 := frame_nr mod 51
3806
3807 var allowedFn fn_check;
3808 fn_check.frame_nr := frame_nr_51;
3809
3810 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003812 return;
3813 }
3814
3815 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3816 return;
3817 }
3818 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3819 return;
3820 }
3821 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3822 return;
3823 }
3824 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3825 return;
3826 }
3827 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3828 return;
3829 }
3830 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3831 return;
3832 }
3833 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3834 return;
3835 }
3836 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3837 return;
3838 }
3839
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003841 return;
3842}
3843
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003844private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3845 inout integer num_paging_rcv_ids,
3846 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003847runs on test_CT {
3848 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003849 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003850 repeat;
3851 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003852 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003853 var octetstring without_plen :=
3854 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3855 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003856
3857 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3858
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003859 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3860 /* Ignore empty RR Paging Request (PCH filling) messages.
3861 * TODO: does it make sense to count them? */
3862 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003863 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3864 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003865 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003866 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3867 }
3868 } else if (match(rr, tr_PAGING_REQ2)) {
3869 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3870 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3871 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3872 }
3873 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3874 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3875 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003876 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003877 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3878 }
3879 } else if (match(rr, tr_PAGING_REQ3)) {
3880 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3881 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3882 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3883 }
3884 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3885 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3886 }
3887 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3889 }
3890 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3891 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3892 }
3893 }
3894 repeat;
3895 }
3896}
3897
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003898private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003899 boolean combined_ccch,
3900 integer bs_ag_blks_res,
3901 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003902 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3903 * paging command that is issued via RSL. */
3904 integer ps_load_modulus,
3905 /* Wait until the paging queue inside the BTS is congested before starting to add
3906 * pagings via the PCU socket (0 = disabled) */
3907 boolean ps_wait_cong,
3908 /* Maximum time to wait until the paging queue is drained at the end of the test.
3909 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3910 * to set this value to 18s, however the draining process may take significantly
3911 * longer when the queue contains paging requests for PS as those are implemented
3912 * as immediate assignments and require an entire MAC block alone. */
3913 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003914 boolean exp_load_ind,
3915 boolean exp_overload,
3916 boolean use_tmsi
3917}
3918
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003919private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003920 integer num_paging_sent,
3921 integer num_paging_rcv_msgs,
3922 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003923 integer num_overload,
3924 /* When free space inside the paging queue reaches more than 2 thirds
3925 * of its capacity cong_detected is set to true. */
3926 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003927}
3928
Harald Welte68e495b2018-02-25 00:05:57 +01003929/* Helper function for paging related testing */
3930private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003931 /* Using the PCU socket affects the timing of the paging processing. We only
3932 * activate the PCU socket if we do paging load tests that include additional
3933 * paging load that is introduced through the PCU socket. */
3934 if (cfg.ps_load_modulus > 0) {
3935 f_init_with_pcuif();
3936 } else {
3937 f_init();
3938 }
Harald Welte68e495b2018-02-25 00:05:57 +01003939 f_init_l1ctl();
3940 f_l1_tune(L1CTL);
3941
Philipp Maierca058272021-06-23 10:35:23 +02003942 var octetstring imm_ass := f_rnd_octstring(23);
3943 var ASP_RSL_Unitdata load_ind;
3944
Harald Welte68e495b2018-02-25 00:05:57 +01003945 var PagingTestState st := {
3946 num_paging_sent := 0,
3947 num_paging_rcv_msgs := 0,
3948 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003949 num_overload := 0,
3950 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003951 };
3952
3953 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3954 var float max_pch_imsi_per_sec;
3955 if (cfg.use_tmsi) {
3956 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3957 } else {
3958 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3959 }
3960 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3961 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003962 var float time_total := 20.0;
3963 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3964 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003965
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003966 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3967 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003968
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003969 timer T_itv := 0.0;
3970 T_itv.start;
3971 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003972 alt {
3973 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003974 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003975 st.num_overload := st.num_overload + 1;
3976 repeat;
3977 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003978 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003980 }
Philipp Maierca058272021-06-23 10:35:23 +02003981 [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 +01003982 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003983
3984 /* Detect paging congestion: The logic inside the BTS will diagnose the
3985 * paging queue as congested when the fill state is more than 66% (which
3986 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3987 * paging congestion is detected pagings that are issued through the PCU
3988 * socket (PS) are dropped in order to prefer the CS related pagings. */
3989 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3990 st.cong_detected := true;
3991 }
3992
Harald Welte68e495b2018-02-25 00:05:57 +01003993 /* FIXME: analyze/verify interval + contents */
3994 repeat;
3995 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003996 /* ignore other RSL messages like RF RESource INDication */
3997 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003998 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003999 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004000 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004001 /* Only relevant when testing including with PCU sock connected */
4002 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004003 [] T_itv.timeout {
4004 /* Send paging cmds based on elapsed time */
4005 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4006 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004007 var MobileIdentityV mi;
4008
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004009 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004010 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004011 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004012 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004013 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004014 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004015
4016 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004017 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 +02004018
Philipp Maierca058272021-06-23 10:35:23 +02004019 /* Add additional pagings through the PCU socket interface. */
4020 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4021 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4022 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4023 }
4024 }
4025
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004026 st.num_paging_sent := st.num_paging_sent + 1;
4027 }
4028 if (st.num_paging_sent < pkt_total) {
4029 /* Wait for interval to next PAGING COMMAND */
4030 var float time_now := T_total.read;
4031 var float next_sched := int2float(st.num_paging_sent)*interval;
4032 if (next_sched > time_now) {
4033 T_itv.start(next_sched - time_now);
4034 } else {
4035 T_itv.start(0.0);
4036 }
4037 } else {
4038 /* We are done, no need to keep counting */
4039 T_total.stop;
4040 }
4041 }
4042 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004043 }
4044 }
4045
Philipp Maierca058272021-06-23 10:35:23 +02004046 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004047 T_wait.start;
4048 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004049 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004050 [] L1CTL.receive { repeat; }
4051 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004052 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004053 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004054 /* ignore other RSL messages like RF RESource INDication */
4055 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004056 /* Only relevant when testing including with PCU sock connected */
4057 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004058 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004059 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 +01004060 }
Harald Welte68e495b2018-02-25 00:05:57 +01004061 }
4062
4063 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4064 " rcvd_ids=", st.num_paging_rcv_ids);
4065 return st;
4066}
4067
4068/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4069 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4070 * - that CCCH LOAD IND (PCH) are being generated
4071 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4072testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004073 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004074 var PagingTestCfg cfg := {
4075 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004076 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004077 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004078 ps_load_modulus := 0,
4079 ps_wait_cong := false,
4080 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004081 exp_load_ind := true,
4082 exp_overload := false,
4083 use_tmsi := false
4084 };
4085 var PagingTestState st := f_TC_paging(cfg);
4086 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4088 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004089 } else {
4090 setverdict(pass);
4091 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004093}
4094
4095/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4096 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4097 * - that CCCH LOAD IND (PCH) are being generated
4098 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4099testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004100 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004101 var PagingTestCfg cfg := {
4102 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004103 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004104 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004105 ps_load_modulus := 0,
4106 ps_wait_cong := false,
4107 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004108 exp_load_ind := true,
4109 exp_overload := false,
4110 use_tmsi := true
4111 };
4112 var PagingTestState st := f_TC_paging(cfg);
4113 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4115 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004116 } else {
4117 setverdict(pass);
4118 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004120}
4121
4122/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4123 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4124 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4125 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4126testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004127 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004128 var PagingTestCfg cfg := {
4129 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004130 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004131 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004132 ps_load_modulus := 0,
4133 ps_wait_cong := false,
4134 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004135 exp_load_ind := true,
4136 exp_overload := true,
4137 use_tmsi := false
4138 };
4139 var PagingTestState st := f_TC_paging(cfg);
4140 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4141 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004142 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004143 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004144 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 +01004145 } else {
4146 setverdict(pass);
4147 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004149}
4150
4151/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4152 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4153 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4154 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4155testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004156 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004157 var PagingTestCfg cfg := {
4158 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004159 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004160 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004161 ps_load_modulus := 0,
4162 ps_wait_cong := false,
4163 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004164 exp_load_ind := true,
4165 exp_overload := true,
4166 use_tmsi := true
4167 };
4168 var PagingTestState st := f_TC_paging(cfg);
4169 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4170 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004171 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004172 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004173 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 +01004174 } else {
4175 setverdict(pass);
4176 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004178}
4179
Philipp Maierca058272021-06-23 10:35:23 +02004180/* Same as above, but with additional paging load created by PS pagings that
4181 * are issued through the PCU socket. The additional load is introduced when
4182 * the paging queue is already two thirds full. Since the BTS implements a
4183 * prioritization logic that drops the pagings from the PCU under in those
4184 * congestive sitautions the behaviour on the PS side is expected to be
4185 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4186testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4187 var SystemInformation si3 := valueof(ts_SI3_default);
4188 var PagingTestCfg cfg := {
4189 combined_ccch := true,
4190 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4191 load_factor := 2.0,
4192 ps_load_modulus := 16,
4193 ps_wait_cong := true,
4194 queue_drain_timeout := 18.0,
4195 exp_load_ind := true,
4196 exp_overload := true,
4197 use_tmsi := false
4198 };
4199 var PagingTestState st := f_TC_paging(cfg);
4200 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4201 * slots and will fully drain that buffer before returning */
4202 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4203 if (not match(st.num_paging_rcv_ids, tpl)) {
4204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4205 } else {
4206 setverdict(pass);
4207 }
4208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4209}
4210
4211
Harald Welte68e495b2018-02-25 00:05:57 +01004212
Harald Welte93640c62018-02-25 16:59:33 +01004213/***********************************************************************
4214 * Immediate Assignment / AGCH
4215 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004216private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004217 len := 0,
4218 ma := ''B
4219}
Harald Welte93640c62018-02-25 16:59:33 +01004220
Harald Weltee8d750e2018-06-10 21:41:35 +02004221private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4222 return int2str(num_tx) & " sent, "
4223 & int2str(num_rx) & " received, "
4224 & int2str(num_del) & " deleted";
4225}
4226
4227private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4228 var L1ctlDlMessage l1_dl;
4229 timer T := 10.0;
4230 var integer num_tx := 0;
4231 var integer num_rx := 0;
4232 var integer num_del := 0;
4233 var charstring res_str;
4234 var float rx_ratio;
4235
Harald Welte10474062019-05-30 16:48:17 +02004236 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004237 f_init_l1ctl();
4238 f_l1_tune(L1CTL);
4239
4240 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004241 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004242 mp_trx_pars[0].arfcn,
4243 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004244 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4245 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004246 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004247 num_tx := num_tx+1;
4248 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004249 }
4250 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004251 T.start;
4252 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004253 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004254 num_del := num_del+1;
4255 repeat;
4256 }
4257 [] RSL_CCHAN.receive {
4258 repeat;
4259 }
4260 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004261 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4262 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4263 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004264 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004265 } else {
4266 num_rx := num_rx+1;
4267 }
4268 repeat;
4269 }
4270 [] L1CTL.receive { repeat; }
4271 [] T.timeout { }
4272 }
4273 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4274 log("AGCH test: " & res_str);
4275 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004277 }
4278 rx_ratio := int2float(num_rx) / int2float(num_tx);
4279 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004280 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 +02004281 } else {
4282 setverdict(pass);
4283 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004285}
4286
Harald Weltee8d750e2018-06-10 21:41:35 +02004287/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4288testcase TC_imm_ass_1000_20ms() runs on test_CT {
4289 f_TC_imm_ass(1000, 0.02, 0.25);
4290}
4291
4292/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4293testcase TC_imm_ass_200_0ms() runs on test_CT {
4294 f_TC_imm_ass(200, 0.0, 0.05);
4295}
4296
4297/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4298testcase TC_imm_ass_200_76ms() runs on test_CT {
4299 f_TC_imm_ass(150, 0.076, 1.00);
4300}
4301
4302
4303
Harald Welte48494ca2018-02-25 16:59:50 +01004304/***********************************************************************
4305 * BCCH
4306 ***********************************************************************/
4307
4308/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004309private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004310 GsmFrameNumber frame_number,
4311 SystemInformation si
4312}
4313
4314/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004315private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004316
4317/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004318private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004319
4320/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004321private function f_si_vecslot_contains(SystemInformationVector arr,
4322 RrMessageType key,
4323 boolean bcch_ext := false)
4324return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004325 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4326 var integer fn_mod51 := arr[i].frame_number mod 51;
4327 if (not bcch_ext and fn_mod51 == 2 or
4328 bcch_ext and fn_mod51 == 6) {
4329 if (arr[i].si.header.message_type == key) {
4330 return true;
4331 }
4332 }
4333 }
4334 return false;
4335}
4336
4337/* 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 +07004338private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4339 integer tc, RrMessageType key,
4340 boolean ext_bcch := false)
4341{
Harald Welte48494ca2018-02-25 16:59:50 +01004342 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004344 }
4345}
4346
4347/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004348private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4349 RrMessageType key)
4350return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004351 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4352 if (f_si_vecslot_contains(arr[tc], key) or
4353 f_si_vecslot_contains(arr[tc], key, true)) {
4354 return true;
4355 }
4356 }
4357 return false;
4358}
4359
4360/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004361private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4362 RrMessageType key,
4363 boolean bcch_ext := false,
4364 integer n := 1, integer m := 4)
4365return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004366 var integer count := 0;
4367 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4369 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004370 }
4371 for (var integer i:= 0; i < m; i := i + 1) {
4372 var integer fn_mod51 := arr[i].frame_number mod 51;
4373 if (not bcch_ext and fn_mod51 == 2 or
4374 bcch_ext and fn_mod51 == 6) {
4375 if (arr[i].si.header.message_type == key) {
4376 count := count + 1;
4377 }
4378 }
4379 }
4380 if (count >= n) {
4381 return true;
4382 } else {
4383 return false;
4384 }
4385}
4386
4387/* 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 +07004388private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4389 integer tc, RrMessageType key,
4390 boolean ext_bcch := false,
4391 integer n, integer m)
4392{
Harald Welte48494ca2018-02-25 16:59:50 +01004393 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004395 }
4396}
4397
4398/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004399private function f_si_vecslot_contains_only(SystemInformationVector arr,
4400 RrMessageType key,
4401 boolean bcch_ext := false)
4402return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004403 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4404 var integer fn_mod51 := arr[i].frame_number mod 51;
4405 if (not bcch_ext and fn_mod51 == 2 or
4406 bcch_ext and fn_mod51 == 6) {
4407 if (arr[i].si.header.message_type != key) {
4408 return false;
4409 }
4410 }
4411 }
4412 return true;
4413}
4414
4415/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004416private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4417 integer tc, RrMessageType key,
4418 boolean ext_bcch := false)
4419{
Harald Welte48494ca2018-02-25 16:59:50 +01004420 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004422 }
4423}
4424
4425/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004426private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004427 boolean bcch_extended,
4428 boolean si1_present,
4429 boolean si2bis_present,
4430 boolean si2ter_present,
4431 boolean si2quater_present,
4432 boolean si7_present,
4433 boolean si8_present,
4434 boolean si9_present,
4435 boolean si13_present,
4436 boolean si13alt_present,
4437 boolean si15_present,
4438 boolean si16_present,
4439 boolean si17_present,
4440 boolean si2n_present,
4441 boolean si21_present,
4442 boolean si22_present
4443}
4444
4445/* 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 +07004446private function f_validate_si_scheduling(SystemInformationConfig cfg,
4447 SystemInformationVectorPerTc si_per_tc)
4448{
Harald Welte48494ca2018-02-25 16:59:50 +01004449 var integer i;
4450 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4451 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004453 }
4454 }
4455 if (cfg.si1_present) {
4456 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4457 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4458 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4459 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4460 /* make sure *ALL* contain SI1 */
4461 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4462 }
4463 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4464 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4465 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4466 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4467 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4468 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4469
4470 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4471 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4472 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4473 * consecutive occurrences of TC = 4. */
4474 if (cfg.si2bis_present and not cfg.si2ter_present) {
4475 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4476 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4477 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4478 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4479 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4480 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4481 }
4482
4483 if (cfg.si7_present or cfg.si8_present) {
4484 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4485 * if System Information type 4 does not contain all information needed for cell
4486 * selection and reselection. */
4487 if (not cfg.bcch_extended) {
4488 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4489 }
4490 if (cfg.si7_present) {
4491 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4492 }
4493 if (cfg.si8_present) {
4494 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4495 }
4496 }
4497
4498 if (cfg.si2quater_present) {
4499 /* iii) System information type 2 quater is sent if needed, as determined by the system
4500 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4501 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4502 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4503 * within any of 4 consecutive occurrences of TC = 5. */
4504 if (not (cfg.bcch_extended)) {
4505 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4506 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4507 } else {
4508 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4509 }
4510 } else {
4511 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4512 }
4513 }
4514 if (cfg.si9_present) {
4515 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4516 * in system information type 3 as defined in 3GPP TS 44.018. */
4517 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4518 }
4519 if (cfg.si13_present) {
4520 /* vii) System Information type 13 is only related to the GPRS service. System Information
4521 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4522 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4523 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4524 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4525 * within any of 4 consecutive occurrences of TC=4. */
4526 if (not cfg.bcch_extended) {
4527 log("not-bccch-extended");
4528 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4529 } else {
4530 log("bccch-extended");
4531 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4532 }
4533 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004535 }
4536 }
4537 if (cfg.si16_present or cfg.si17_present) {
4538 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4539 * should not be sent in a cell where network sharing is used (see rule xv). */
4540 if (cfg.si22_present) {
4541 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4542 }
4543 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004545 }
4546 if (not cfg.bcch_extended) {
4547 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4548 }
4549 if (cfg.si16_present) {
4550 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4551 }
4552 if (cfg.si17_present) {
4553 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4554 }
4555 }
4556
4557 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4558 * broadcast information. The frequency with which they are sent is determined by the
4559 * system operator. System Information type 9 identifies the scheduling of System
4560 * Information type 18 and 20 messages. */
4561
4562 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4563 * Information Type 19 is present, then its scheduling shall be indicated in System
4564 * Information Type 9. */
4565
4566 if (cfg.si15_present) {
4567 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4568 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4569 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4570 * 4 consecutive occurrences of TC = 1. */
4571 if (not cfg.bcch_extended) {
4572 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4573 } else {
4574 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4575 }
4576 }
4577 if (cfg.si13alt_present) {
4578 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4579 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4580 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4581 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4582 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4583 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4584 * of TC = 4. */
4585 if (cfg.si13_present) {
4586 testcase.stop("Error: Cannot have SI13alt and SI13");
4587 }
4588 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004590 }
4591 if (not cfg.bcch_extended) {
4592 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4593 } else {
4594 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4595 }
4596 }
4597 if (cfg.si2n_present) {
4598 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4599 * as determined by the system operator. In the case that the message is sent on the
4600 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4601 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4602 * consecutive occurrences of TC = 4. */
4603 if (not cfg.bcch_extended) {
4604 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4605 } else {
4606 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4607 }
4608 }
4609 if (cfg.si21_present) {
4610 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4611 * determined by the system operator. If Extended Access Barring is in use in the cell
4612 * then this message is sent at least once within any of 4 consecutive occurrences of
4613 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4614 * cell then this message shall only be sent on BCCH Ext. */
4615 if (not cfg.bcch_extended) {
4616 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4617 } else {
4618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4619 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004621 }
4622 }
4623 }
4624 if (cfg.si22_present) {
4625 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4626 * should not be sent in a cell where SoLSA is used (see rule viii). System
4627 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4628 * =2 and TC=6. */
4629 if (cfg.si16_present or cfg.si17_present) {
4630 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4631 }
4632 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4633 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004635 }
4636 if (not cfg.bcch_extended) {
4637 testcase.stop("Error: SI22 requires BCCH Extd!");
4638 } else {
4639 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4640 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4641 }
4642 }
4643}
4644
4645/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004646private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4647return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004648 timer T := duration;
4649 var SystemInformationVectorPerTc si_per_tc;
4650 var L1ctlDlMessage l1_dl;
4651
4652 /* initialize all per-TC vectors empty */
4653 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4654 si_per_tc[i] := {};
4655 }
4656
4657 /* flush all previous L1 queued msgs */
4658 pt.clear;
4659
4660 T.start;
4661 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004662 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004663 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4664 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4665 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004666 repeat;
4667 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004668
Harald Welte48494ca2018-02-25 16:59:50 +01004669 var integer tc := f_gsm_compute_tc(sig.frame_number);
4670 log("SI received at TC=", tc, ": ", sig.si);
4671 /* append to the per-TC bucket */
4672 si_per_tc[tc] := si_per_tc[tc] & { sig };
4673 repeat;
4674 }
4675 [] pt.receive { repeat; }
4676 [] T.timeout { }
4677 }
4678
4679 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4680 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4681 }
4682 log("si_per_tc=", si_per_tc);
4683 return si_per_tc;
4684}
4685
4686/* helper function: Set given SI via RSL + validate scheduling.
4687 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004688private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004689 var SystemInformationVectorPerTc si_per_tc;
4690 f_init_l1ctl();
4691 f_l1_tune(L1CTL);
4692
4693 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004694 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004695 f_validate_si_scheduling(si_cfg, si_per_tc);
4696
4697 setverdict(pass);
4698}
4699
4700testcase TC_si_sched_default() runs on test_CT {
4701 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004702 /* 2+3+4 are mandatory and set in f_init() */
4703 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004705}
4706
4707testcase TC_si_sched_1() runs on test_CT {
4708 f_init();
4709 si_cfg.si1_present := true;
4710 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004711 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004713}
4714
4715testcase TC_si_sched_2bis() runs on test_CT {
4716 f_init();
4717 si_cfg.si2bis_present := true;
4718 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4719 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004721}
4722
4723testcase TC_si_sched_2ter() runs on test_CT {
4724 f_init();
4725 si_cfg.si2ter_present := true;
4726 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4727 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004729}
4730
4731testcase TC_si_sched_2ter_2bis() runs on test_CT {
4732 f_init();
4733 si_cfg.si2bis_present := true;
4734 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4735 si_cfg.si2ter_present := true;
4736 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4737 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004739}
4740
4741testcase TC_si_sched_2quater() runs on test_CT {
4742 f_init();
4743 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004744 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004745 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004747}
4748
4749testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004750 /* NOTE: PCUIF connection is not used in this test case, but
4751 * without it the IUT would not broadcast SI13 (see OS#3075). */
4752 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004753 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004754 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004755 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004757}
4758
4759testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004760 /* NOTE: PCUIF connection is not used in this test case, but
4761 * without it the IUT would not broadcast SI13 (see OS#3075). */
4762 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004763 si_cfg.si2bis_present := true;
4764 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4765 si_cfg.si2ter_present := true;
4766 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4767 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004769 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004770 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004771 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004773}
4774
4775
Harald Welte68e495b2018-02-25 00:05:57 +01004776testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004777 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004778 /* FIXME: enable / disable individual BCCH info */
4779 //ts_RSL_BCCH_INFO(si_type, info);
4780 /* expect no ERROR REPORT after either of them *
4781 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004783}
4784
Harald Welte93640c62018-02-25 16:59:33 +01004785/***********************************************************************
4786 * Low-Level Protocol Errors / ERROR REPORT
4787 ***********************************************************************/
4788
Harald Welte01d982c2018-02-25 01:31:40 +01004789private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4790 timer T := 5.0;
4791 T.start;
4792 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004793 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004794 setverdict(pass);
4795 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004796 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004798 }
4799 [] RSL_CCHAN.receive {
4800 repeat;
4801 }
4802 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004804 }
4805 }
4806}
4807
4808/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4809testcase TC_rsl_protocol_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 := omit;
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_PROTO);
4816}
4817
4818/* Provoke a mandatory IE error and match on ERROR REPORT */
4819testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004820 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004821
4822 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4823 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004824 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004825
4826 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4827}
4828
4829/* Provoke an IE content error and match on ERROR REPORT */
4830testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004831 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004832 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4833 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004834 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004835
4836 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4837}
4838
Harald Welteee25aae2019-05-19 14:32:37 +02004839/* attempt to activate channel with wrong RSL Message Discriminator IE */
4840function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4841 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4842 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4843 RSL.send(rsl);
4844 f_rslem_unregister(0, g_chan_nr);
4845}
4846testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4847 var ConnHdlr vc_conn;
4848 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4849
Harald Welte10474062019-05-30 16:48:17 +02004850 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004851
4852 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4853 vc_conn.done;
4854 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4855
4856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4857}
4858
4859/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004860private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004861 var template (value) RSL_Message rsl_tx;
4862 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4863 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4864 RSL.send(rsl_tx);
4865 f_rslem_unregister(0, g_chan_nr);
4866}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004867private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004868 var template (value) RSL_Message rsl_tx;
4869 /* we first have to activate the dedicated channel */
4870 f_rsl_chan_act(g_pars.chan_mode);
4871 /* ... to then send an invalid RLL message */
4872 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4873 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4874 RSL.send(rsl_tx);
4875 f_rslem_unregister(0, g_chan_nr);
4876}
4877testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4878 var ConnHdlr vc_conn;
4879 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4880 var template (value) RSL_Message rsl_tx;
4881
Harald Welte10474062019-05-30 16:48:17 +02004882 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004883
4884 /* Common Channel with wrong message type */
4885 RSL_CCHAN.clear;
4886 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4887 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004888 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004889 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4890
4891 /* TRX Management */
4892 RSL_CCHAN.clear;
4893 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4894 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004895 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004896 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4897
4898 /* Dedicated Channel */
4899 RSL_CCHAN.clear;
4900 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4901 vc_conn.done;
4902 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4903
4904 /* RLL */
4905 RSL_CCHAN.clear;
4906 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4907 vc_conn.done;
4908 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4909}
4910
4911/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004912private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004913 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4914 f_rslem_unregister(0, g_chan_nr);
4915}
4916testcase TC_err_rep_wrong_sequence() runs on test_CT {
4917 var ConnHdlr vc_conn;
4918 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4919
Harald Welte10474062019-05-30 16:48:17 +02004920 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004921
4922 RSL_CCHAN.clear;
4923 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4924 vc_conn.done;
4925 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4926}
4927
Harald Welte93640c62018-02-25 16:59:33 +01004928/***********************************************************************
4929 * IPA CRCX/MDCX/DLCS media stream handling
4930 ***********************************************************************/
4931
Harald Weltea871a382018-02-25 02:03:14 +01004932/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004933private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004934 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4935 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004936}
4937testcase TC_ipa_dlcx_not_active() runs on test_CT {
4938 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004939 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004940 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4941 vc_conn.done;
4942}
Harald Welte68e495b2018-02-25 00:05:57 +01004943
Harald Weltea3f1df92018-02-25 12:49:55 +01004944/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004945private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004946 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4947 "IPA CRCX ACK");
4948 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4949 "IPA CRCX NACK");
4950}
4951testcase TC_ipa_crcx_twice_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_twice_not_active), pars);
4955 vc_conn.done;
4956}
4957
4958/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004959private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004960 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4961 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004962 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +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 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4970 "IPA DLCX ACK");
4971}
4972testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4973 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004974 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004975 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4976 vc_conn.done;
4977}
4978
Harald Welte3ae11da2018-02-25 13:36:06 +01004979/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004980private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004981 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4982 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004983 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004984 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4985 var uint7_t rtp_pt2 := f_rnd_int(127);
4986 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4987 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4988 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4989 "IPA MDCX ACK");
4990 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004991 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004992 remote_port := f_rnd_int(c_UINT16_MAX);
4993 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4994 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4995 "IPA MDCX ACK");
4996 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4997 "IPA DLCX ACK");
4998}
4999testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5000 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005001 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005002 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5003 vc_conn.done;
5004}
5005
Harald Welte9912eb52018-02-25 13:30:15 +01005006/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005007private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005008 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5009 "IPA CRCX NACK");
5010}
5011testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5012 var ConnHdlrPars pars;
5013 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005014 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005015
5016 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5017 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5018 vc_conn.done;
5019
5020 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5021 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5022 vc_conn.done;
5023}
5024
Harald Weltea3f1df92018-02-25 12:49:55 +01005025
Harald Welte883340c2018-02-28 18:59:29 +01005026/***********************************************************************
5027 * PCU Socket related tests
5028 ***********************************************************************/
5029
Harald Welte07bd2d22019-05-25 11:03:30 +02005030/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005031friend 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 +01005032runs on test_CT {
5033 timer T := 3.0;
5034
5035 /* we don't expect any RTS.req before PDCH are active */
5036 T.start;
5037 alt {
5038 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005040 }
5041 [] PCU.receive { repeat; }
5042 [] T.timeout { }
5043 }
5044
5045 /* Send PDCH activate request for known PDCH timeslot */
5046 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5047
5048 /* we now expect RTS.req for this timeslot (only) */
5049 T.start;
5050 alt {
5051 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5052 setverdict(pass);
5053 }
5054 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5055 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005057 }
5058 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005060 }
5061 [] PCU.receive { repeat; }
5062 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005064 }
5065 [not exp_success] T.timeout {
5066 setverdict(pass);
5067 }
5068 }
5069}
5070
Harald Welte07bd2d22019-05-25 11:03:30 +02005071/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005072friend 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 +01005073runs on test_CT {
5074 timer T := 3.0;
5075
5076 /* Send PDCH activate request for known PDCH timeslot */
5077 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 +02005078 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5079 * when it will actually have been executed in the BTS */
5080 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005081 PCU.clear;
5082 /* we now expect no RTS.req for this timeslot */
5083 T.start;
5084 alt {
5085 [] 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 +02005086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005087 }
5088 [] PCU.receive { repeat; }
5089 [] T.timeout {
5090 setverdict(pass);
5091 }
5092 }
5093}
5094
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005095friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005096 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005097 map(self:PCU, system:PCU);
5098 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005099 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5100}
5101
Harald Welte883340c2018-02-28 18:59:29 +01005102/* PDCH activation via PCU socket; check for presence of RTS.req */
5103testcase TC_pcu_act_req() 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, 0, 7, true);
5107}
5108
5109/* PDCH activation via PCU socket on non-PDCU timeslot */
5110testcase TC_pcu_act_req_wrong_ts() 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 f_TC_pcu_act_req(0, 0, 1, false);
5114}
5115
5116/* PDCH activation via PCU socket on wrong BTS */
5117testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005118 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005119
Harald Welte883340c2018-02-28 18:59:29 +01005120 f_TC_pcu_act_req(23, 0, 7, false);
5121}
5122
5123/* PDCH activation via PCU socket on wrong TRX */
5124testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005125 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005126
Harald Welte883340c2018-02-28 18:59:29 +01005127 f_TC_pcu_act_req(0, 23, 7, false);
5128}
5129
5130/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5131testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005132 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005133
Harald Welte883340c2018-02-28 18:59:29 +01005134 /* Activate PDCH */
5135 f_TC_pcu_act_req(0, 0, 7, true);
5136 f_sleep(1.0);
5137 /* and De-Activate again */
5138 f_TC_pcu_deact_req(0, 0, 7);
5139}
5140
5141/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5142testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005143 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005144
Harald Welte883340c2018-02-28 18:59:29 +01005145 f_TC_pcu_deact_req(0, 0, 1);
5146}
5147
5148/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005149function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005150 var PCUIF_send_data sd;
5151 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005152 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005153
5154 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005155 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005156
Harald Welte883340c2018-02-28 18:59:29 +01005157 T.start;
5158 alt {
5159 [] 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 +01005160 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005161 setverdict(pass);
5162 } else {
5163 repeat;
5164 }
5165 }
5166 [] PCU.receive { repeat; }
5167 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005169 }
5170 }
5171}
5172
Philipp Maier94c08482021-02-01 17:36:05 +01005173/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5174testcase TC_pcu_ver_si1() runs on test_CT {
5175 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5176 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5177}
5178
5179/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5180testcase TC_pcu_ver_si3() runs on test_CT {
5181 const octetstring si3 := '49012223242526272929AABBCC'O;
5182 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5183}
5184
5185/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5186testcase TC_pcu_ver_si13() runs on test_CT {
5187 const octetstring si13 := '01010203040506070909'O;
5188 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5189}
5190
Harald Welte883340c2018-02-28 18:59:29 +01005191private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5192
5193/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005194friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005195 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5196runs on test_CT
5197{
5198 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5199 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5200}
5201
5202/* 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 +02005203friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5204 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005205runs on test_CT
5206{
5207 var PCUIF_send_data sd;
5208
5209 timer T := 3.0;
5210 T.start;
5211 alt {
5212 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5213 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5214 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5215 sd.data.u.rts_req.fn, sapi, data);
5216 }
5217 [] PCU.receive { repeat; }
5218 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005220 }
5221 }
5222}
5223
5224/* Send DATA.req on invalid BTS */
5225testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005226 var TfiUsfArr tua := f_TfiUsfArrInit();
5227 var octetstring data := '0000'O & f_rnd_octstring(21);
5228
5229 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005230
Harald Welte883340c2018-02-28 18:59:29 +01005231 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005232 f_TfiUsfArrSet(tua, 7, 0);
5233 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5234 f_sleep(1.0);
5235
5236 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005237}
5238
5239/* Send DATA.req on invalid TRX */
5240testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005241 var TfiUsfArr tua := f_TfiUsfArrInit();
5242 var octetstring data := '0000'O & f_rnd_octstring(21);
5243
5244 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005245
Harald Welte883340c2018-02-28 18:59:29 +01005246 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005247 f_TfiUsfArrSet(tua, 7, 0);
5248 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5249 f_sleep(1.0);
5250
5251 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005252}
5253
5254/* Send DATA.req on invalid timeslot */
5255testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005256 var TfiUsfArr tua := f_TfiUsfArrInit();
5257 var octetstring data := '0000'O & f_rnd_octstring(21);
5258
5259 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005260
Harald Welte883340c2018-02-28 18:59:29 +01005261 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005262 f_TfiUsfArrSet(tua, 7, 0);
5263 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5264 f_sleep(1.0);
5265
5266 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005267}
5268
5269/* Send DATA.req on timeslot that hasn't been activated */
5270testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005271 var TfiUsfArr tua := f_TfiUsfArrInit();
5272 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005273
Harald Welte7162a612019-05-26 12:56:09 +02005274 f_virtphy_common();
5275
5276 f_TfiUsfArrSet(tua, 7, 0);
5277 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5278 f_sleep(1.0);
5279
5280 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005281}
5282
Harald Weltead033dc2019-05-25 17:28:16 +02005283private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005284 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5285 boolean wait_rts := true)
5286runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005287 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005288 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005289
5290 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005291 if (wait_rts) {
5292 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5293 } else {
5294 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5295 }
Harald Weltead033dc2019-05-25 17:28:16 +02005296
5297 T.start;
5298 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005299 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005300 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5301 setverdict(pass);
5302 }
Harald Welte7162a612019-05-26 12:56:09 +02005303 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5304 setverdict(fail, "Received unexpected ", rx_dl);
5305 }
Harald Weltead033dc2019-05-25 17:28:16 +02005306 [] L1CTL.receive {
5307 repeat;
5308 }
Harald Welte7162a612019-05-26 12:56:09 +02005309 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005310 setverdict(fail, "Timeout waiting for ", data);
5311 }
Harald Welte7162a612019-05-26 12:56:09 +02005312 [not expect_data] T.timeout {
5313 setverdict(pass);
5314 }
Harald Weltead033dc2019-05-25 17:28:16 +02005315 }
5316}
5317
5318private function f_disable_dynamic_ts() runs on test_CT
5319{
5320 f_init_vty_bsc();
5321 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5322 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5323 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5324 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005325 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005326}
5327
5328private function f_virtphy_common() runs on test_CT {
5329 f_disable_dynamic_ts();
5330 f_init_l1ctl();
5331 f_l1_tune(L1CTL);
5332}
5333
5334testcase TC_pcu_data_req_pdtch() runs on test_CT {
5335 var TfiUsfArr tua := f_TfiUsfArrInit();
5336 var octetstring data := '0000'O & f_rnd_octstring(21);
5337
5338 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005339
Harald Welte883340c2018-02-28 18:59:29 +01005340 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005341 f_TfiUsfArrSet(tua, 7, 0);
5342 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5343 f_sleep(1.0);
5344
5345 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005346}
5347
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005348/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005349testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005350 var TfiUsfArr tua := f_TfiUsfArrInit();
5351 var octetstring data := '0000'O & f_rnd_octstring(21);
5352
5353 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005354
Harald Welte883340c2018-02-28 18:59:29 +01005355 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005356 f_TfiUsfArrSet(tua, 7, 0);
5357 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5358 f_sleep(1.0);
5359
5360 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005361}
5362
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005363private function f_TC_pcu_ptcch_ul(uint16_t ra)
5364runs on test_CT {
5365 var template PCUIF_Message pcu_rach_ind;
5366 var PCUIF_send_data sd;
5367 var GsmFrameNumber fn;
5368 timer T;
5369
5370 /* Send an Access Burst on PTCCH/U over the Um-interface */
5371 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5372 chan_nr := ts_RslChanNr_PDCH(7),
5373 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5374
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005375 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5376 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005377
5378 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5379 T.start(52.0 * 4.615 / 1000.0);
5380 alt {
5381 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5382 log("Rx an Access Burst on the PCU interface: ", sd.data);
5383 setverdict(pass);
5384 T.stop;
5385 }
5386 [] PCU.receive { repeat; }
5387 [] T.timeout {
5388 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5389 /* Keep going, that's not the end of the world */
5390 }
5391 }
5392}
5393
5394testcase TC_pcu_ptcch() runs on test_CT {
5395 var L1ctlDlMessage dl;
5396 var octetstring data;
5397 timer T;
5398
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005399 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005400 f_init_l1ctl();
5401 f_l1_tune(L1CTL);
5402
5403 /* Activate PDCH channel on TS7 */
5404 f_TC_pcu_act_req(0, 0, 7, true);
5405
5406 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005407 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005408 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005409 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005410 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005411
5412 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5413 for (var integer i := 0; i < 16; i := i + 1) {
5414 log("Sending an Access Burst towards the L1CTL interface");
5415 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5416 }
5417
5418 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5419 data := f_rnd_octstring(23);
5420
5421 /* Verify PTCCH/D: send a random data block, make sure it's received */
5422 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5423 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5424
5425 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5426 * let's give it more time in case if we miss the beginning. */
5427 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5428 alt {
5429 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5430 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5431 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5432 frame := data)) -> value dl {
5433 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5434 setverdict(pass);
5435 T.stop;
5436 }
5437 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5438 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5439 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5440 l2_data := data)) -> value dl {
5441 log("Rx PTCCH/D data block on L1CTL: ", dl);
5442 setverdict(pass);
5443 T.stop;
5444 }
5445 [] L1CTL.receive { repeat; }
5446 [] T.timeout {
5447 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5448 }
5449 }
5450}
5451
Harald Welte883340c2018-02-28 18:59:29 +01005452/* Send AGCH from PCU; check it appears on Um side */
5453testcase TC_pcu_data_req_agch() runs on test_CT {
5454 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005455 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005456 f_init_l1ctl();
5457 f_l1_tune(L1CTL);
5458
5459 f_TC_pcu_act_req(0, 0, 7, true);
5460 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5461
5462 T.start;
5463 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005464 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005465 setverdict(pass);
5466 }
5467 [] L1CTL.receive { repeat; }
5468 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005470 }
5471 }
5472}
5473
Harald Welte928622b2019-05-26 13:22:59 +02005474/* Send AGCH from PCU; check it appears on Um side */
5475testcase TC_pcu_data_req_pch() runs on test_CT {
5476 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005477 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005478 f_init_l1ctl();
5479 f_l1_tune(L1CTL);
5480
5481 f_TC_pcu_act_req(0, 0, 7, true);
5482 /* three characters prefix: last 3 digits of IMSI as ASCII */
5483 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5484
5485 T.start;
5486 alt {
5487 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5488 setverdict(pass);
5489 }
5490 [] L1CTL.receive { repeat; }
5491 [] T.timeout {
5492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5493 }
5494 }
5495}
5496
Harald Welte883340c2018-02-28 18:59:29 +01005497/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5498testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5499 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005500 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005501 f_init_l1ctl();
5502 f_l1_tune(L1CTL);
5503
5504 /* append 3 last imsi digits so BTS can compute pagng group */
5505 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5506
5507 timer T := 0.5;
5508 T.start;
5509 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005510 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005511 /* TODO: verify paging group */
5512 setverdict(pass);
5513 }
5514 [] L1CTL.receive { repeat; }
5515 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005517 }
5518 }
5519}
5520
5521/* Send RACH from Um side, expect it to show up on PCU socket */
5522testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005523 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005524 f_init_l1ctl();
5525 f_l1_tune(L1CTL);
5526
5527 var GsmFrameNumber fn_last := 0;
5528 for (var integer i := 0; i < 1000; i := i+1) {
5529 var OCT1 ra := f_rnd_ra_ps();
5530 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5531 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005533 }
5534 fn_last := fn;
5535
5536 timer T := 2.0;
5537 T.start;
5538 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005539 [] 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 +01005540 T.stop;
5541 }
5542 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005544 }
5545 [] PCU.receive { repeat; }
5546 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005548 }
5549 }
5550 }
5551 setverdict(pass);
5552}
5553
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005554/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5555 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5556testcase TC_pcu_ext_rach_content() runs on test_CT {
5557 var template PCUIF_Message pcu_rach_ind;
5558 var GsmFrameNumber fn_last := 0;
5559 var L1ctlRachSynchSeq synch_seq;
5560 var PCUIF_BurstType pcu_bt;
5561 var GsmFrameNumber fn;
5562 var BIT11 ra11;
5563
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005564 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005565 f_init_l1ctl();
5566 f_l1_tune(L1CTL);
5567
5568 for (var integer i := 0; i < 1000; i := i+1) {
5569 /* We need to test both TS1 & TS2 */
5570 if (i rem 2 == 0) {
5571 synch_seq := RACH_SYNCH_SEQ_TS1;
5572 pcu_bt := BURST_TYPE_1;
5573 } else {
5574 synch_seq := RACH_SYNCH_SEQ_TS2;
5575 pcu_bt := BURST_TYPE_2;
5576 }
5577
5578 ra11 := f_rnd_ra11_ps();
5579 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5580 if (fn == fn_last) {
5581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5582 "Two RACH in same FN?!?");
5583 }
5584 fn_last := fn;
5585
5586 /* Compose the expected message */
5587 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005588 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005589 ra := bit2int(ra11),
5590 is_11bit := 1,
5591 burst_type := pcu_bt,
5592 fn := fn);
5593
5594 timer T := 2.0;
5595 T.start;
5596 alt {
5597 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5598 T.stop;
5599 }
5600 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5602 }
5603 [] PCU.receive { repeat; }
5604 [] T.timeout {
5605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5606 }
5607 }
5608 }
5609 setverdict(pass);
5610}
5611
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005612private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5613runs on test_CT {
5614 var template PCUIF_send_data sdt;
5615 var PCUIF_send_data sd;
5616 var int16_t lqual_cb;
5617 timer T := 1.0;
5618
5619 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5620 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5621
5622 /* Send a random PDTCH frame over Um */
5623 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5624 '0000'O & f_rnd_octstring(21)));
5625
5626 T.start;
5627 alt {
5628 /* If expected link quality is above the threshold */
5629 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5630 lqual_cb := sd.data.u.data_ind.lqual_cb;
5631 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5632
5633 /* Make sure the actual link quality matches the expected value */
5634 if (not match(lqual_cb, lqual_cb_exp)) {
5635 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5636 "expected value ", lqual_cb_exp));
5637 } else {
5638 setverdict(pass);
5639 }
5640 }
5641 /* If expected link quality is below the threshold */
5642 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5644 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5645 }
5646 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5647 [] PCU.receive { repeat; }
5648 [lqual_cb_exp < thresh] T.timeout {
5649 log("Rx nothing, as expected");
5650 setverdict(pass);
5651 }
5652 [lqual_cb_exp >= thresh] T.timeout {
5653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5654 "Timeout waiting for PCUIF_DATA.ind");
5655 }
5656 }
5657}
5658
5659/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5660testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005661 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005662 PCU.clear;
5663
5664 f_init_l1ctl();
5665 f_l1_tune(L1CTL);
5666
5667 /* Activate a PDCH channel on TS7 */
5668 f_TC_pcu_act_req(0, 0, 7, true);
5669
5670 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005671 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005672 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005673 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005674 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005675
5676 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5677 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5678 var TrxcMessage ret;
5679
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005680 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005681
5682 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5683 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5684 }
5685}
5686
Harald Welte883340c2018-02-28 18:59:29 +01005687/* Send PAGING via RSL, expect it to shw up on PCU socket */
5688testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005689 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005690
5691 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005692 var MobileIdentityLV mi_lv;
5693 var octetstring mi_lv_enc;
5694 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005695 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005696
Harald Welte883340c2018-02-28 18:59:29 +01005697 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005698 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005699 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005700 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005701 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005702
5703 /* Fancy encoding for PCUIF */
5704 mi_lv := valueof(ts_MI_LV(mi));
5705 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5706 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005707
5708 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005709 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005710 T.start;
5711 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005712 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005713 }
5714 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005716 }
5717 [] PCU.receive { repeat; }
5718 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005720 }
5721 }
5722 }
5723 setverdict(pass);
5724}
5725
Harald Welted66c9b82019-05-25 09:03:15 +02005726/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5727testcase TC_pcu_time_ind() runs on test_CT {
5728 var PCUIF_send_data pcu_sd;
5729 var integer num_time_ind := 0;
5730 var integer first_fn, last_fn;
5731 var float test_duration := 5.0;
5732 timer T;
5733
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005734 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005735 f_TC_pcu_act_req(0, 0, 7, true);
5736
5737 PCU.clear;
5738 T.start(test_duration);
5739 alt {
5740 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5741 num_time_ind := num_time_ind + 1;
5742 if (not isbound(first_fn)) {
5743 first_fn := pcu_sd.data.u.time_ind.fn;
5744 }
5745 last_fn := pcu_sd.data.u.time_ind.fn;
5746 repeat;
5747 }
5748 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5749 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5750 repeat;
5751 }
5752 [] PCU.receive {
5753 repeat;
5754 }
5755 [] T.timeout {}
5756 }
5757 var integer fn_expired := last_fn - first_fn;
5758 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5759
5760 /* verify the number of frames expired matches our expectation */
5761 const float c_GSM_FN_DURATION_MS := 4.61538;
5762 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005763 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005764 if (not match(fn_expired, t_fn_expected)) {
5765 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5766 }
5767
5768 /* There are three TIME.ind in every fn MOD 13 */
5769 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5770 /* Add some tolerance */
5771 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5772 if (not match(num_time_ind, t_time_ind_exp)) {
5773 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5774 }
5775
5776 setverdict(pass);
5777}
5778
Harald Welte4832c862019-05-25 14:57:18 +02005779/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5780testcase TC_pcu_rts_req() runs on test_CT {
5781 var PCUIF_send_data pcu_sd;
5782 var integer first_fn, last_fn;
5783 var integer num_rts_pdtch := 0;
5784 var integer num_rts_ptcch := 0;
5785 var float test_duration := 5.0;
5786 timer T;
5787
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005788 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005789 f_TC_pcu_act_req(0, 0, 7, true);
5790
5791 PCU.clear;
5792 T.start(test_duration);
5793 alt {
5794 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5795 -> value pcu_sd {
5796 num_rts_pdtch := num_rts_pdtch + 1;
5797 if (not isbound(first_fn)) {
5798 first_fn := pcu_sd.data.u.rts_req.fn;
5799 }
5800 last_fn := pcu_sd.data.u.rts_req.fn;
5801 repeat;
5802 }
5803 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5804 -> value pcu_sd {
5805 num_rts_ptcch := num_rts_ptcch + 1;
5806 if (not isbound(first_fn)) {
5807 first_fn := pcu_sd.data.u.rts_req.fn;
5808 }
5809 last_fn := pcu_sd.data.u.rts_req.fn;
5810 repeat;
5811 }
5812 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5813 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5814 repeat;
5815 }
5816 [] PCU.receive {
5817 repeat;
5818 }
5819 [] T.timeout {}
5820 }
5821 var integer fn_expired := last_fn - first_fn;
5822 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5823 ", num_rts_ptcch=", num_rts_ptcch);
5824
5825 /* verify the number of frames expired matches our expectation */
5826 const float c_GSM_FN_DURATION_MS := 4.61538;
5827 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005828 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005829 if (not match(fn_expired, t_fn_expected)) {
5830 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5831 }
5832
5833 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5834 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5835 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5836 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5837 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5838 t_ptcch_exp);
5839 }
5840
5841 /* We have 12 PDTCH blocks every 52-multiframe */
5842 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5843 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5844 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5845 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5846 t_pdtch_exp);
5847 }
5848
5849 setverdict(pass);
5850}
5851
Harald Welte07bd2d22019-05-25 11:03:30 +02005852/* test for generating Abis side OML ALERT from the PCU */
5853testcase TC_pcu_oml_alert() runs on test_CT {
5854 var PCUIF_send_data pcu_sd;
5855 var integer num_time_ind := 0;
5856 var integer first_fn, last_fn;
5857 var float test_duration := 5.0;
5858 timer T;
5859
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005860 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005861 f_TC_pcu_act_req(0, 0, 7, true);
5862
5863 /* re-connect CTRL port from BTS to BSC */
5864 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005865 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005866
5867 /* Send that OML Alert */
5868 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5869
5870 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5871 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5872 setverdict(pass);
5873}
5874
Harald Welteeaa9a862019-05-26 23:01:08 +02005875/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5876private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5877 var PCUIF_Message first_info;
5878 var integer pcu_conn_id := -1;
5879 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5880 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5881 var OCT4 tlli := '01020304'O;
5882 var OCT1 cause := '23'O;
5883 timer T := 5.0;
5884
5885 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5886
5887 f_l1_tune(L1CTL);
5888 RSL.clear;
5889
5890 f_est_dchan();
5891 L1CTL.clear;
5892
5893 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5894
5895 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5896 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5897 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5898
5899 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5900 T.start;
5901 alt {
5902 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5903 setverdict(pass);
5904 }
5905 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5906 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5907 }
5908 [] PCU.receive {
5909 repeat;
5910 }
5911 [] T.timeout {
5912 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5913 }
5914 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005915
5916 /* release the channel */
5917 f_rsl_chan_deact();
5918 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5919 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005920}
5921testcase TC_pcu_rr_suspend() runs on test_CT {
5922 var ConnHdlrPars pars;
5923 var ConnHdlr vc_conn;
5924
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005925 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005926
5927 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5928 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5929 vc_conn.done;
5930}
Harald Welte07bd2d22019-05-25 11:03:30 +02005931
Harald Weltea2e0e942019-05-27 18:12:53 +02005932/* Ensure that PCUIF socket can accept only a single connection */
5933testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005934 var boolean connected := false;
5935 var UD_connect_result cr;
5936 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005937 timer T := 5.0;
5938
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005939 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5940 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5941
Harald Weltea2e0e942019-05-27 18:12:53 +02005942 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005943 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005944
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005945 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005946 PCU.send(UD_connect:{mp_pcu_socket, -1});
5947 T.start;
5948 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005949 /* the IUT will first accept() the new connection, and close() it immediately */
5950 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5951 log("BTS has accept()ed connection");
5952 connected := true;
5953 cid := cr.id;
5954 repeat;
5955 }
5956 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5957 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005958 setverdict(pass);
5959 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005960 /* ignore other messages related to the first connection */
5961 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005962 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005963 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005964 }
5965 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005966
Harald Weltea2e0e942019-05-27 18:12:53 +02005967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5968}
5969
Harald Weltec8effb72019-05-27 18:23:04 +02005970/* Ensure that PCUIF socket can disconnect + reconnect */
5971testcase TC_pcu_socket_reconnect() runs on test_CT {
5972 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005973 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005974
5975 f_sleep(1.0);
5976
5977 f_pcuif_close(PCU, g_pcu_conn_id);
5978 g_pcu_conn_id := -1;
5979
5980 f_sleep(1.0);
5981
5982 /* re-connect */
5983 PCU.clear;
5984 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5985 setverdict(pass);
5986
5987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5988}
5989
Harald Weltebe030482019-05-27 22:29:35 +02005990/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005991private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5992runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005993 var L1ctlDlMessage l1_dl;
5994 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005995 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005996 timer T := 5.0;
5997 T.start;
5998 alt {
5999 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006000 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6001 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006002 repeat;
6003 }
6004 }
6005 [] pt.receive {
6006 repeat;
6007 }
6008 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6010 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006011 }
6012 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006013 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006014}
6015
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006016/* Check if GPRS Indicator is present in RR System Information of a given type */
6017private function f_si_has_gprs_indicator(RrMessageType si_type)
6018runs on test_CT return boolean {
6019 var SystemInformation si := f_get_si(L1CTL, si_type);
6020
6021 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006022 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006023 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006024 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006025 }
6026
6027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6028 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006029}
6030
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006031/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6032private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6033runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006034 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006035 f_init_l1ctl();
6036 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006037 f_sleep(2.0);
6038 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006039
6040 if (f_si_has_gprs_indicator(si_type)) {
6041 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006042 } else {
6043 setverdict(pass);
6044 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006045
Harald Weltebe030482019-05-27 22:29:35 +02006046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6047}
6048
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006049testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6050 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6051}
Harald Weltebe030482019-05-27 22:29:35 +02006052
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006053testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6054 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6055}
6056
6057/* Ensure that GPRS capability is advertised after PCU socket connect */
6058private function f_TC_pcu_socket_connect(RrMessageType si_type)
6059runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006060 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006061 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006062 f_init_l1ctl();
6063 f_l1_tune(L1CTL);
6064
6065 f_sleep(2.0);
6066 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006067
6068 if (not f_si_has_gprs_indicator(si_type)) {
6069 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006070 } else {
6071 setverdict(pass);
6072 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006073
Harald Weltebe030482019-05-27 22:29:35 +02006074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6075}
6076
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006077testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6078 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6079}
Harald Weltebe030482019-05-27 22:29:35 +02006080
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006081testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6082 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6083}
6084
6085/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6086private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6087runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006088 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006089 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006090 f_init_l1ctl();
6091 f_l1_tune(L1CTL);
6092
6093 f_pcuif_close(PCU, g_pcu_conn_id);
6094 g_pcu_conn_id := -1;
6095
6096 f_sleep(1.0);
6097
6098 /* re-connect */
6099 PCU.clear;
6100 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6101
6102 f_sleep(2.0);
6103 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006104
6105 if (f_si_has_gprs_indicator(si_type)) {
6106 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006107 } else {
6108 setverdict(pass);
6109 }
6110
6111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6112}
6113
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006114testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6115 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6116}
6117
6118testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6119 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6120}
6121
Oliver Smithf5239c72019-08-28 10:01:25 +02006122/* 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) */
6123testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6124 var SystemInformation si3 := valueof(ts_SI3_default);
6125
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006126 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006127
Harald Welte76220222020-10-11 20:32:44 +02006128 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6129 * information */
6130 timer T := 2.0;
6131 T.start;
6132 alt {
6133 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6134 [] T.timeout {}
6135 }
6136
Oliver Smithf5239c72019-08-28 10:01:25 +02006137 /* Verify cell_id */
6138 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6139 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6140 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006141 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6142 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6143 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006144 }
6145
6146 /* Verify LAC */
6147 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6148 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6149 if (lac_si3 != lac_pcu) {
6150 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6151 }
6152
6153 setverdict(pass);
6154}
Harald Welted66c9b82019-05-25 09:03:15 +02006155
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006156/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6157testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6158 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006159 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006160
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006161 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006162
6163 info_ind := g_pcu_last_info.u.info_ind;
6164
6165 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6166 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006167 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006168 /* Skip inactive timeslots */
6169 continue;
6170 }
6171
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006172 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006173 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006174 else
6175 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006176
6177 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006178 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006179 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006180 hsn := fhp.maio_hsn.hsn,
6181 maio := fhp.maio_hsn.maio,
6182 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006183 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006184 } else {
6185 tr_ts := tr_PCUIF_InfoTrxTsH0;
6186 }
6187
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006188 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006189 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6190 if (not match(ts, tr_ts)) {
6191 setverdict(fail, "Hopping parameters do not match: ",
6192 "received ", ts, " vs expected ", tr_ts);
6193 } else {
6194 setverdict(pass);
6195 }
6196 }
6197 }
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_ipv4() runs on test_CT {
6202 f_init_vty_bsc();
6203 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6204 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6205
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006206 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006207
6208 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006209 var template PCUIF_RemoteAddr tr_remote_addr := {
6210 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006211 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006212 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006213
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006214 if (not match(remote_addr, tr_remote_addr)) {
6215 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006216 }
6217
6218 setverdict(pass);
6219}
6220
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006221/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006222testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6223 f_init_vty_bsc();
6224 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6225
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006226 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006227
6228 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006229 var template PCUIF_RemoteAddr tr_remote_addr := {
6230 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6231 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6232 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006233
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006234 if (not match(remote_addr, tr_remote_addr)) {
6235 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006236 }
6237
6238 setverdict(pass);
6239}
6240
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006241/* Verify coding of two NSVCs in the INFO.ind message */
6242testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6243 f_init_vty_bsc();
6244
6245 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6246 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6247 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6248 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6249
6250 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6251 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6252 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6253 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6254
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006255 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006256
6257 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6258 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6259 var template PCUIF_RemoteAddr tr_remote_addr := {
6260 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006261 addr := {
6262 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6263 f_inet6_addr("fd00::ca:ff:ee")
6264 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006265 };
6266
6267 if (not match(info_ind.nsvci, { 1234, 5678 }))
6268 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6269 if (not match(remote_addr, tr_remote_addr))
6270 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6271 if (not match(info_ind.local_port, { 1234, 5678 }))
6272 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6273 if (not match(info_ind.remote_port, { 1234, 5678 }))
6274 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6275
6276 setverdict(pass);
6277}
6278
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006279/* Verify periodic interference reports on PDCH */
6280testcase TC_pcu_interf_ind() runs on test_CT {
6281 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006282 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006283 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006284 var PCUIF_send_data sd;
6285 timer T;
6286
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006287 /* Set the averaging/reporting period to 480ms */
6288 f_init_vty_bsc();
6289 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6290 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6291
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006292 f_init_with_pcuif();
6293 f_TC_pcu_act_req(0, 0, 7, true);
6294
6295 /* We need trxcon for NOPE indications */
6296 f_init_l1ctl();
6297 f_l1_tune(L1CTL);
6298
6299 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006300 tr_interf_ind := tr_PCUIF_INTERF_IND(
6301 bts_nr := 0,
6302 trx_nr := 0,
6303 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006304 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006305 );
6306
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006307 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006308 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006309 /* The first interference report may contain unreliable values, so we ignore it */
6310 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6311 /* 4 SACCH periods => 4 reports (plus some guard time) */
6312 T.start(0.480 * 4.0 + 0.480 / 2.0);
6313 first := false;
6314 repeat;
6315 }
6316 /* Subsequent interference reports shall match our expectations */
6317 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006318 /* Check TDMA frame number period */
6319 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6320 setverdict(fail, "Odd TDMA frame number := ",
6321 sd.data.u.interf_ind.fn);
6322 }
6323 interf_ind_num := interf_ind_num + 1;
6324 if (interf_ind_num < 4)
6325 { repeat; }
6326 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006327 [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 +02006328 setverdict(fail, "Received unexpected interference report: ", sd.data);
6329 }
6330 [] PCU.receive { repeat; }
6331 [] T.timeout {
6332 setverdict(fail, "Timeout waiting for interference reports");
6333 }
6334 }
6335
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006336 /* Reset the averaging/reporting period back to default */
6337 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6338
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6340}
6341
Harald Welte3d04ae62018-04-04 20:29:05 +02006342/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006343 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006344 ***********************************************************************/
6345
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006346private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6347 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006348runs on ConnHdlr {
6349 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006350
6351 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006352 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006353 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6354 repeat;
6355 }
6356 }
6357}
6358
6359private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6360runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006361 /* Expect BTS to immediately acknowledge activation as PDCH */
6362 PCU.clear;
6363 f_rsl_chan_act(g_pars.chan_mode);
6364 /* expect INFO_IND on PCU interface listing TS as PDCH */
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, '1'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 '1' on TS", g_chan_nr.tn));
6373 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006374 }
6375 /* try to activate this PDCH from the PCU point of view */
6376 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6377 /* FIXME: is there a response? */
6378}
6379
6380private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6381runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006382 /* Send RSL CHAN REL (deactivate) */
6383 PCU.clear;
6384 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6385 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006386 timer T_wait := 2.0;
6387 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006388 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006389 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006390 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006391 [] T_wait.timeout {
6392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6393 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6394 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006395 }
6396 /* Emulate PCU asking BTS to deactivate PDCH */
6397 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6398 alt {
6399 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6400 setverdict(pass);
6401 }
6402 [] RSL.receive { repeat; }
6403 }
6404}
6405
6406/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006407private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006408 var PCUIF_Message first_info;
6409 var integer ts_nr := g_chan_nr.tn;
6410 var integer trx_nr := 0;
6411 var integer bts_nr := 0;
6412 var integer pcu_conn_id := -1;
6413
6414 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6415
6416 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6417 f_sleep(3.0);
6418 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6419 setverdict(pass);
6420}
6421testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6422 var ConnHdlrPars pars;
6423 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006424 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006425
6426 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6427 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6428 vc_conn.done;
6429}
6430
6431/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006432private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006433 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006434 var integer pcu_conn_id := -1;
6435
6436 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6437
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006438 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6439 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6440 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006441 setverdict(pass);
6442}
6443testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6444 var ConnHdlrPars pars;
6445 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006446 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006447
6448 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6449 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6450 vc_conn.done;
6451}
6452
6453/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006454private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006455 var PCUIF_Message first_info;
6456 var integer ts_nr := g_chan_nr.tn;
6457 var integer trx_nr := 0;
6458 var integer bts_nr := 0;
6459 var integer pcu_conn_id := -1;
6460
6461 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6462
6463 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006464 /* Send a second Chan Activ and expect it to be NACKed */
6465 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6466 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006467 setverdict(pass);
6468}
6469testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6470 var ConnHdlrPars pars;
6471 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006472 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006473
6474 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6475 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6476 vc_conn.done;
6477}
6478
6479/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006480private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006481 var PCUIF_Message first_info;
6482 var integer ts_nr := g_chan_nr.tn;
6483 var integer trx_nr := 0;
6484 var integer bts_nr := 0;
6485 var integer pcu_conn_id := -1;
6486 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6487
6488 /* register for the TCH/F channel number */
6489 f_rslem_register(0, chan_nr);
6490
6491 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6492
6493 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6494 "RSL CHAN ACT");
6495 setverdict(pass);
6496}
6497testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6498 var ConnHdlrPars pars;
6499 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006500 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006501
6502 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6503 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6504 vc_conn.done;
6505}
6506
6507/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006508private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006509 var PCUIF_Message first_info;
6510 var integer ts_nr := g_chan_nr.tn;
6511 var integer trx_nr := 0;
6512 var integer bts_nr := 0;
6513 var integer pcu_conn_id := -1;
6514 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6515 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6516
6517 /* register for the TCH/H channel numbers */
6518 f_rslem_register(0, chan_nr[0]);
6519 f_rslem_register(0, chan_nr[1]);
6520
6521 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6522
6523 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6524 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6525 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6526 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6527 setverdict(pass);
6528}
6529testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6530 var ConnHdlrPars pars;
6531 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006532 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006533
6534 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6535 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6536 vc_conn.done;
6537}
6538
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006539/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6540private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6541 var PCUIF_Message first_info;
6542 var integer ts_nr := g_chan_nr.tn;
6543 var integer trx_nr := 0;
6544 var integer bts_nr := 0;
6545 var integer pcu_conn_id := -1;
6546 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6547 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6548 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6549 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6550 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6551 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6552 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6553 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6554
6555 /* register for the TCH/H channel numbers */
6556 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6557 f_rslem_register(0, chan_nr[i]);
6558 }
6559
6560 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6561
6562 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6563 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6564 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6565 }
6566 setverdict(pass);
6567}
6568testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6569 var ConnHdlrPars pars;
6570 var ConnHdlr vc_conn;
6571 f_init();
6572
6573 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6574 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6575 vc_conn.done;
6576}
6577
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006578/* Reproduce a race condition described in OS#5245 */
6579private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6580 f_rsl_chan_act(g_pars.chan_mode);
6581 f_sleep(1.0);
6582 f_rsl_chan_deact();
6583 setverdict(pass);
6584}
6585testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6586 var ConnHdlrPars pars[2];
6587 var ConnHdlr vc_conn[2];
6588 var TrxcMessage rsp;
6589
6590 f_init();
6591
6592 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6593 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6594 ts_TRXC_FAKE_TRXC_DELAY(200));
6595
6596 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6597 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6598 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6599 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6600 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6601 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6602 pars[i], l1ctl := false);
6603 }
6604
6605 /* Wait for all components to finish */
6606 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6607 vc_conn[i].done;
6608 }
6609
6610 /* Disable the artificial delay for TRXC RSP messages */
6611 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6612 ts_TRXC_FAKE_TRXC_DELAY(0));
6613}
6614testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6615 var ConnHdlrPars pars[8];
6616 var ConnHdlr vc_conn[8];
6617 var TrxcMessage rsp;
6618
6619 f_init();
6620
6621 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6622 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6623 ts_TRXC_FAKE_TRXC_DELAY(200));
6624
6625 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6626 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6627 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6628 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6629 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6630 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6631 pars[i], l1ctl := false);
6632 }
6633
6634 /* Wait for all components to finish */
6635 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6636 vc_conn[i].done;
6637 }
6638
6639 /* Disable the artificial delay for TRXC RSP messages */
6640 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6641 ts_TRXC_FAKE_TRXC_DELAY(0));
6642}
6643
Harald Welte9bbbfb52018-04-05 09:33:19 +02006644/***********************************************************************
6645 * IPA Style Dynamic Timeslot Support
6646 ***********************************************************************/
6647
6648private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6649runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006650 /* Expect BTS to immediately acknowledge activation as PDCH */
6651 PCU.clear;
6652 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6653 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006654 timer T_wait := 2.0;
6655 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006656 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006657 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006658 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006659 [] T_wait.timeout {
6660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6661 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6662 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006663 }
6664 /* try to activate this PDCH from the PCU point of view */
6665 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6666 /* FIXME: is there a response? */
6667
6668 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6669}
6670
6671private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6672runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006673 /* Send RSL CHAN REL (deactivate) */
6674 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6675 PCU.clear;
6676 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006677 timer T_wait := 2.0;
6678 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006679 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006680 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006681 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006682 [] T_wait.timeout {
6683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6684 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6685 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006686 }
6687 /* Emulate PCU asking BTS to deactivate PDCH */
6688 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6689 alt {
6690 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6691 setverdict(pass);
6692 }
6693 [] RSL.receive { repeat; }
6694 }
6695}
6696
6697/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006698private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006699 var PCUIF_Message first_info;
6700 var integer ts_nr := g_chan_nr.tn;
6701 var integer trx_nr := 0;
6702 var integer bts_nr := 0;
6703 var integer pcu_conn_id := -1;
6704
6705 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6706
6707 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6708 f_sleep(3.0);
6709 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6710
6711 setverdict(pass);
6712
6713}
6714testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6715 var ConnHdlrPars pars;
6716 var ConnHdlr vc_conn;
6717 f_init();
6718
6719 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6720 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6721 vc_conn.done;
6722}
6723
6724/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006725private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006726 var PCUIF_Message first_info;
6727 var integer ts_nr := g_chan_nr.tn;
6728 var integer trx_nr := 0;
6729 var integer bts_nr := 0;
6730 var integer pcu_conn_id := -1;
6731
6732 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6733
6734 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6735 "RSL CHAN ACT");
6736 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6737 "RF CHAN REL", true);
6738 setverdict(pass);
6739}
6740testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6741 var ConnHdlrPars pars;
6742 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006743 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006744
6745 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6746 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6747 vc_conn.done;
6748}
6749
6750/* 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 +07006751private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006752 var PCUIF_Message first_info;
6753 var integer ts_nr := g_chan_nr.tn;
6754 var integer trx_nr := 0;
6755 var integer bts_nr := 0;
6756 var integer pcu_conn_id := -1;
6757
6758 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6759
6760 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6761 "RSL CHAN ACT");
6762
6763 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6764 alt {
6765 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6766 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006767 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006768 }
6769 [] RSL.receive { repeat; }
6770 }
6771
6772 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6773 "RF CHAN REL", true);
6774 setverdict(pass);
6775}
6776testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6777 var ConnHdlrPars pars;
6778 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006779 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006780
6781 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6782 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6783 vc_conn.done;
6784}
6785
6786/* 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 +07006787private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006788 var PCUIF_Message first_info;
6789 var integer ts_nr := g_chan_nr.tn;
6790 var integer trx_nr := 0;
6791 var integer bts_nr := 0;
6792 var integer pcu_conn_id := -1;
6793
6794 /* register for the TCH/F channel number */
6795 f_rslem_register(0, g_chan_nr);
6796
6797 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6798
6799 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6800
6801 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6802 "RSL CHAN ACT");
6803
6804 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6805
6806 setverdict(pass);
6807}
6808testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6809 var ConnHdlrPars pars;
6810 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006811 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006812
6813 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6814 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6815 vc_conn.done;
6816}
6817
6818
Harald Welte0472ab42018-03-12 15:02:26 +01006819/***********************************************************************
6820 * LAPDm / RLL related
6821 ***********************************************************************/
6822
6823private function f_tx_lapdm(template (value) LapdmFrame l,
6824 template (value) RslLinkId link_id) runs on ConnHdlr {
6825 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006826 var template (value) SacchL1Header l1h;
6827
6828 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006829 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006830 /* Compose dummy L1 header */
6831 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6832 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 +02006833 } else {
6834 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006835 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 +01006836 }
Harald Welte0472ab42018-03-12 15:02:26 +01006837}
6838
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006839friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006840 uint3_t sapi,
6841 RslLinkId link_id,
6842 octetstring l3,
6843 boolean exp
6844}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006845friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006846friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6847 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006848 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006849 sapi := sapi,
6850 link_id := id,
6851 l3 := l3,
6852 exp := exp
6853}
6854
6855/* execute the same callback function with a set of different parameters (tcs) on a
6856 * variety of logical channels */
6857private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6858 var ConnHdlrPars pars;
6859 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006860 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006861
6862 /* test on each of the channels we have */
6863 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6864 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6865
6866 /* test each of the test cases on the current channel */
6867 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6868 pars.spec.rll := tcs[j];
6869 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6870 vc_conn := f_start_handler(fn, pars);
6871 vc_conn.done;
6872 }
6873 }
6874
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006876}
6877
6878/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6879private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6880 var RllTestCase tc := g_pars.spec.rll;
6881 timer T := 3.0;
6882
6883 f_l1_tune(L1CTL);
6884 RSL.clear;
6885
6886 /* activate the logical channel */
6887 f_est_dchan();
6888 L1CTL.clear;
6889
6890 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6891 T.start;
6892 alt {
6893 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6894 if (tc.exp) {
6895 setverdict(pass);
6896 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006898 }
6899 }
6900 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6901 if (tc.exp) {
6902 setverdict(pass);
6903 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006905 }
6906 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006907 /* We also expect to receive the measurements */
6908 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006909 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006911 }
6912 [not tc.exp] T.timeout {
6913 setverdict(pass);
6914 }
6915 }
6916
6917 f_rsl_chan_deact();
6918 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6919 f_rslem_unregister(0, g_chan_nr);
6920}
6921testcase TC_rll_est_ind() runs on test_CT {
6922 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006923 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006924 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006925 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006926 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006927 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006928 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6929 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006930 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006931 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006932 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006933 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006934 };
6935 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6936}
6937
6938/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6939private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6940 var RllTestCase tc := g_pars.spec.rll;
6941 var L1ctlDlMessage dl;
6942 timer T := 3.0;
6943
6944 f_l1_tune(L1CTL);
6945 RSL.clear;
6946
6947 /* activate the logical channel */
6948 f_est_dchan();
6949 L1CTL.clear;
6950
6951 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6952 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6953 T.start;
6954 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006955 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006956 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006958 }
6959 }
6960
6961 f_rsl_chan_deact();
6962 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6963 f_rslem_unregister(0, g_chan_nr);
6964}
6965testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6966 var RllTestCases tcs := {
6967 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006968 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006969 };
6970 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6971}
6972testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6973 var RllTestCases tcs := {
6974 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006975 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006976 }
6977 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6978}
6979
6980/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006981friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006982 var L1ctlDlMessage dl;
6983 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6984 var LapdmFrame lapdm;
6985 var octetstring l2 := dl.payload.data_ind.payload;
6986 if (dl.dl_info.link_id.c == SACCH) {
6987 /* remove L1 header */
6988 l2 := substr(l2, 2, lengthof(l2)-2);
6989 }
6990 if (ischosen(exp.ab)) {
6991 lapdm.ab := dec_LapdmFrameAB(l2);
6992 } else if (ischosen(exp.b4)) {
6993 lapdm.b4 := dec_LapdmFrameB4(l2);
6994 } else if (ischosen(exp.bbis)) {
6995 lapdm.bbis := dec_LapdmFrameBbis(l2);
6996 }
6997 log("Rx LAPDm ", lapdm);
6998 if (match(lapdm, exp)) {
6999 setverdict(pass);
7000 } else {
7001 repeat;
7002 }
7003 }
7004 [] L1CTL.receive { repeat; }
7005}
7006private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7007 timer T := t;
7008 T.start;
7009 alt {
7010 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007012 }
7013 [] as_l1_exp_lapdm(exp);
7014 }
7015}
7016
7017/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7018private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
7019 /* send SABM from MS -> BTS */
7020 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7021 /* expect RLL EST IND on Abis */
7022 alt {
7023 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7024 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7025 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007027 }
7028 [] RSL.receive { repeat; }
7029 }
7030 /* expect UA from BTS -> MS */
7031 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7032}
7033
7034/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7035private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7036 var RllTestCase tc := g_pars.spec.rll;
7037
7038 f_l1_tune(L1CTL);
7039 RSL.clear;
7040
7041 /* activate the logical channel */
7042 f_est_dchan();
7043 L1CTL.clear;
7044
7045 /* first establish the link-layer */
7046 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7047
7048 /* then send the DISC */
7049 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7050 /* ... and expect the REL IND on the RSL side */
7051 alt {
7052 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7053 setverdict(pass);
7054 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007055 /* We also expect to receive the measurements */
7056 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007057 }
7058
7059 /* release the channel */
7060 f_rsl_chan_deact();
7061 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7062 f_rslem_unregister(0, g_chan_nr);
7063}
7064testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7065 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007066 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007067 };
7068 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7069}
7070
7071testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7072 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007073 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007074 };
7075 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7076}
7077testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7078 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007079 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007080 };
7081 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7082}
7083testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7084 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007085 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007086 };
7087 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7088}
7089
7090/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7091private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7092 var RllTestCase tc := g_pars.spec.rll;
7093 f_l1_tune(L1CTL);
7094 RSL.clear;
7095
7096 /* activate the logical channel */
7097 f_est_dchan();
7098 L1CTL.clear;
7099
7100 /* first establish the link-layer */
7101 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7102
7103 /* then send the REL REQ via RSL */
7104 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7105 /* ... and expect the DISC on the Um side */
7106 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007107 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007108 /* FIXME: send a UA in resposne to the DISC */
7109 }
7110 }
7111
7112 /* release the channel */
7113 f_rsl_chan_deact();
7114 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7115 f_rslem_unregister(0, g_chan_nr);
7116}
7117testcase TC_rll_rel_req() runs on test_CT {
7118 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007119 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7120 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7121 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7122 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007123 };
7124 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7125}
7126
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007127/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007128testcase TC_rll_data_req() runs on test_CT {
7129}
7130
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007131/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007132testcase TC_rll_data_ind() runs on test_CT {
7133}
7134
7135/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7136private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7137 var RllTestCase tc := g_pars.spec.rll;
7138
7139 f_l1_tune(L1CTL);
7140 RSL.clear;
7141
7142 f_est_dchan();
7143 L1CTL.clear;
7144
7145 /* Send UNITDATA REQ on RSL side */
7146 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7147 /* Expect it to arrive on the other side */
7148 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007149 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007150 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007151 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007152 }
7153
7154 /* release the channel */
7155 f_rsl_chan_deact();
7156 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7157 f_rslem_unregister(0, g_chan_nr);
7158}
7159testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7160 var octetstring l3 := f_rnd_octstring(15);
7161 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007162 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7163 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007164 };
7165 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7166}
7167testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7168 var octetstring l3 := f_rnd_octstring(19);
7169 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007170 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7171 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007172 };
7173 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7174}
7175
7176/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7177private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7178 var RllTestCase tc := g_pars.spec.rll;
7179
7180 f_l1_tune(L1CTL);
7181 RSL.clear;
7182
7183 f_est_dchan();
7184 L1CTL.clear;
7185
7186 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007187 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007188 /* Expdct RLL UNITDATA IND on RSL side */
7189 alt {
7190 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7191 setverdict(pass);
7192 }
7193 [] RSL.receive { repeat; }
7194 }
7195
7196 /* release the channel */
7197 f_rsl_chan_deact();
7198 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7199 f_rslem_unregister(0, g_chan_nr);
7200}
7201testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007202 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007203 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007204 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7205 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007206 };
7207 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7208}
7209testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7210 var octetstring l3 := f_rnd_octstring(18);
7211 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007212 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7213 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007214 };
7215 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7216}
7217
Harald Weltee613f962018-04-18 22:38:16 +02007218/***********************************************************************
7219 * Encryption Related
7220 ***********************************************************************/
7221
7222/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007223private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007224 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7225 if (link_id.c == SACCH) {
7226 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7227 } else {
7228 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7229 }
7230}
7231
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007232/* Expect (or not expect) other kinds of messages */
7233private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7234 [exp_any] RSL.receive { repeat; }
7235 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007237 }
7238}
7239
Harald Weltee613f962018-04-18 22:38:16 +02007240/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007241private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007242 RslLinkId link_id,
7243 octetstring l3,
7244 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007245 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007246) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007247 timer T := 3.0;
7248 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7249 T.start;
7250 /* Expect RLL UNITDATA IND on RSL side */
7251 alt {
7252 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7253 setverdict(pass);
7254 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007255 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007256 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007257 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007259 }
Harald Weltee613f962018-04-18 22:38:16 +02007260 }
7261}
7262
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007263/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7264private function f_data_mo(
7265 RslLinkId link_id,
7266 boolean p, uint3_t nr, uint3_t ns,
7267 octetstring l3,
7268 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007269 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007270) runs on ConnHdlr {
7271 timer T := 3.0;
7272 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7273 T.start;
7274 /* Expect RLL DATA IND on RSL side */
7275 alt {
7276 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7277 setverdict(pass);
7278 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007279 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007280 [] as_rsl_any_ind(exp_any);
7281 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007283 }
7284 }
7285}
7286
Harald Weltee613f962018-04-18 22:38:16 +02007287/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007288private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007289 f_l1_tune(L1CTL);
7290 f_est_dchan(true);
7291
7292 /* now we actually need to transmit some data both ways to check if the encryption works */
7293 var L1ctlDlMessage dl;
7294
Stefan Sperling603d98e2018-07-25 16:47:28 +02007295 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007296 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7297
7298 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7299 f_unitdata_mt(link_id, l3);
7300
7301 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7302 f_unitdata_mo(link_id, l3);
7303
7304 /* release the channel */
7305 f_rsl_chan_deact();
7306 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7307 f_rslem_unregister(0, g_chan_nr);
7308}
7309testcase TC_chan_act_a51() runs on test_CT {
7310 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7311 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7312 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7313}
7314testcase TC_chan_act_a52() runs on test_CT {
7315 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7316 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7317 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7318}
7319testcase TC_chan_act_a53() runs on test_CT {
7320 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7321 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7322 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7323}
Eric Wildb9260392021-05-15 19:48:22 +02007324testcase TC_chan_act_a54() runs on test_CT {
7325 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7326 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7327 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7328}
Harald Weltee613f962018-04-18 22:38:16 +02007329
Eric Wildf1827a72019-05-28 17:37:35 +02007330/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7331 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 +07007332private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007333 f_l1_tune(L1CTL);
7334 f_est_dchan(true);
7335
7336 /* now we actually need to transmit some data both ways to check if the encryption works */
7337 var L1ctlDlMessage dl;
7338
7339 var octetstring l3 := f_rnd_octstring(20);
7340 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7341
7342 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7343 f_unitdata_mt(link_id, l3);
7344
7345 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7346 f_unitdata_mo(link_id, l3);
7347
7348 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007349 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007350
7351 /* modify key to break proper encryption */
7352 g_pars.encr.key := f_rnd_octstring(8);
7353 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7354 rsl.ies := rsl.ies & { ei };
7355 RSL.send(rsl);
7356
7357 timer T0 := 1.0;
7358 T0.start;
7359 /* Expect RSL MODIFY ACK */
7360 alt {
7361 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7362 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7364 }
7365 [] T0.timeout {
7366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7367 }
7368 }
7369
7370 var octetstring l3msg := f_rnd_octstring(15);
7371 timer T1 := 3.0;
7372 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7373 due to broken encryption */
7374 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7375 T1.start;
7376 alt {
7377 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7379 }
7380 [] T1.timeout {
7381 setverdict(pass);
7382 }
7383 }
7384
7385 /* release the channel */
7386 f_rsl_chan_deact();
7387 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7388 f_rslem_unregister(0, g_chan_nr);
7389}
7390testcase TC_rsl_modify_encr() runs on test_CT {
7391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7392 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7393 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7394}
Harald Weltee613f962018-04-18 22:38:16 +02007395
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007396/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007397private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007398runs on test_CT {
7399 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7400 var ASP_RSL_Unitdata ud;
7401 timer T;
7402
7403 /* Intave is 6 SACCH periods by default */
7404 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7405
7406 T.start(Tval);
7407 alt {
7408 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7409 setverdict(pass);
7410 }
7411 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7412 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7413 }
7414 [] RSL_CCHAN.receive { repeat; }
7415 [] T.timeout {
7416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7417 "Timeout waiting for RF RESource INDication");
7418 }
7419 }
7420}
7421testcase TC_rsl_rf_resource_ind() runs on test_CT {
7422 var RSL_ResourceInfo info := { };
7423
7424 f_init(trx_nr := 0);
7425
7426 f_init_l1ctl();
7427 f_l1_tune(L1CTL);
7428
7429 /* g_AllChannels contains all logical channels */
7430 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7431 var RslChannelNr chan_nr := g_AllChannels[i];
7432
7433 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7434 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7435 { continue; }
7436
7437 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7438 }
7439
7440 /* Align to the first interference report */
7441 f_TC_rsl_rf_resource_ind(?);
7442
7443 /* Test 4 consecutive messages */
7444 for (var integer i := 0; i < 4; i := i + 1) {
7445 f_TC_rsl_rf_resource_ind(info);
7446 }
7447
7448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7449}
7450
Harald Weltee613f962018-04-18 22:38:16 +02007451/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007452private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007453 /* L3 payload doesn't matter, as it is passed transparently */
7454 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7455 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7456 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7457
7458 f_l1_tune(L1CTL);
7459
7460 /* first establish a dedicated channel in the clear */
7461 f_est_dchan(false);
7462
7463 /* Establish ABM */
7464 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7465
7466 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7467 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7468 /* expect the L3 to arrive still unencrypted on the MS side */
7469 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7470
7471 /* configure L1 to apply ciphering */
7472 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7473 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7474
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007475 /* send first ciphered I-frame in response and expect it on RSL */
7476 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007477
7478 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7479 * and hence enable encryption also on the downlink */
7480
7481 /* expect bi-directional communication work in encrypted mode */
7482 f_unitdata_mo(link_id, f_rnd_octstring(15));
7483 f_unitdata_mt(link_id, f_rnd_octstring(15));
7484
7485 /* release the channel */
7486 f_rsl_chan_deact();
7487 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7488 f_rslem_unregister(0, g_chan_nr);
7489}
7490testcase TC_encr_cmd_a51() runs on test_CT {
7491 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7492 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7493 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7494}
7495testcase TC_encr_cmd_a52() runs on test_CT {
7496 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7497 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7498 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7499}
7500testcase TC_encr_cmd_a53() runs on test_CT {
7501 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7502 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7503 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7504}
Eric Wildb9260392021-05-15 19:48:22 +02007505testcase TC_encr_cmd_a54() runs on test_CT {
7506 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7507 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7508 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7509}
Harald Weltee613f962018-04-18 22:38:16 +02007510
7511private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7512 var LapdmFrame lf;
7513 var octetstring reenc;
7514
7515 /* decode the LAPDm frame */
7516 if (ischosen(exp_match.ab)) {
7517 lf.ab := dec_LapdmFrameAB(enc);
7518 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007520 }
7521
7522 /* check if decoder result matches expectation */
7523 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007525 } else {
7526 log(name, ": matched");
7527 setverdict(pass);
7528 }
7529
7530 /* test if re-encoded frame equals original input */
7531 reenc := enc_LapdmFrame(lf);
7532 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007534 } else {
7535 setverdict(pass);
7536 }
7537}
7538
7539testcase TC_lapdm_selftest() runs on test_CT {
7540 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7541 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7542 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7543 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7544 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7545 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7546 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7547}
7548
Stefan Sperling4880be42018-08-07 18:12:59 +02007549/***********************************************************************
7550 * DTX Related (see GSM 05.08, section 8.3)
7551 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007552private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007553 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007554 var GsmFrameNumber first_fn;
7555 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007556 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007557 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007558 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7559 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007560 const integer frame_dtx_tchf_mod := 104;
7561 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7562 * which operates in terms of blocks rather than frames. */
7563 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7564 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007565 timer T := 5.0;
7566
7567 f_l1_tune(L1CTL);
7568 RSL.clear;
7569 L1CTL.clear;
7570
7571 /* activate TCHF signalling channel */
7572 f_est_dchan(false);
7573
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007574 /* A template for matching dummy LAPDm func=UA frames */
7575 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7576 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7577 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7578
Stefan Sperling4880be42018-08-07 18:12:59 +02007579 T.start;
7580 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007581 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007582 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007583
7584 if (is_first_frame) {
7585 is_first_frame := false;
7586 first_fn := dl.dl_info.frame_nr;
7587 }
7588
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007589 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007590 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007591 T.stop;
7592 f_rsl_chan_deact();
7593 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007594
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007595 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7596 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007597
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007598 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007599 setverdict(fail, "Not enough fill frames received: ",
7600 nfill_frames, " out of ", expected_fill_frames);
7601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007602 } else {
7603 setverdict(pass);
7604 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007605 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007606 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7607 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7608 * we should only see the subset of frames numbers which correspond to a block boundary.
7609 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7610 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7611 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007612 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007613 repeat;
7614 }
7615 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007616 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7617 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7618 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007619 f_rsl_chan_deact();
7620 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007621 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007622 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007623 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007624 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007625 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007626
7627 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007628 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7629 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007630 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7631 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7632 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007633 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7634 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007635 case else {
7636 /* This shall not happen, just to be sure */
7637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7638 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007639 }
7640
7641 f_rsl_chan_deact();
7642 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007643
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007644 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007645 setverdict(pass);
7646 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007647 setverdict(fail, "Not enough fill frames received: ",
7648 nfill_frames, " out of ", expected_fill_frames);
7649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007650 }
7651 } else {
7652 repeat;
7653 }
7654 }
7655 }
7656 [] L1CTL.receive { repeat; }
7657 [] T.timeout {
7658 f_rsl_chan_deact();
7659 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007661 }
7662 }
7663}
7664
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007665private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007666 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007667 var ConnHdlr vc_conn;
7668 var ConnHdlrPars pars;
7669 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007670 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007671 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007672 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007673 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007674 if (dtxd) {
7675 if (i >= 4) { /* DTX is only allowed on TCH/F */
7676 break;
7677 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007678 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007679 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007680 vc_conn.done;
7681 }
7682}
7683
7684/* Verify that L2 fill frames are sent on TCH in signaling mode if
7685 * there is nothing to transmit while DTX is disabled on downlink. */
7686testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7687 f_tch_sign_l2_fill_frame(false);
7688}
7689
7690/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7691 * there is nothing to transmit while DTX is enabled on downlink. */
7692testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7693 f_tch_sign_l2_fill_frame(true);
7694}
Harald Welte0472ab42018-03-12 15:02:26 +01007695
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007696testcase TC_chopped_ipa_ping() runs on test_CT {
7697 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7698}
7699
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007700testcase TC_chopped_ipa_payload() runs on test_CT {
7701 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7702}
7703
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007704
7705/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7706 * Return value: Measurement Report to be sent (encoded octetstring). */
7707type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7708 runs on ConnHdlr return octetstring;
7709
7710private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7711runs on ConnHdlr {
7712 var L1ctlDlMessage l1_dl;
7713 var SacchL1Header l1h;
7714 var octetstring l2;
7715
7716 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7717 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7718 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7719 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7720
7721 /* Pass it to the user specified call-back function */
7722 l2 := cb.apply(l1h, num_blocks);
7723 /* Send a Measurement Report generated by the call-back */
7724 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7725 l1_dl.dl_info.link_id,
7726 l1h, l2));
7727
7728 /* Shall we keep going? */
7729 num_blocks := num_blocks - 1;
7730 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7731 if (num_blocks > 0) { repeat; }
7732 }
7733 [] L1CTL.receive { repeat; }
7734}
7735
7736private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7737runs on ConnHdlr return octetstring {
7738 /* Command the L1 to apply received parameters */
7739 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7740
7741 /* Dummy measurement report (the results are invalid) */
7742 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7743}
7744
7745private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7746runs on ConnHdlr return octetstring {
7747 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7748 setverdict(fail, "Unexpected MS Power level change: ",
7749 g_pars.l1_pars.ms_power_level, " -> ",
7750 l1h.ms_power_lvl);
7751 }
7752
7753 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7754}
7755
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007756private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7757runs on ConnHdlr return octetstring {
7758 /* UL RSSI oscillation driven by SACCH block number */
7759 if (num_blocks rem 2 == 0) {
7760 f_trxc_fake_rssi(-100);
7761 } else {
7762 f_trxc_fake_rssi(-50);
7763 }
7764
7765 /* Make sure that MS power level remains constant */
7766 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7767}
7768
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007769/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7770private function f_TC_ms_pwr_ctrl_constant(charstring id)
7771runs on ConnHdlr {
7772 var integer num_blocks := 8;
7773 timer T := int2float(num_blocks);
7774
7775 f_l1_tune(L1CTL);
7776 RSL.clear;
7777
7778 /* These IEs are needed for autonomous MS power control */
7779 var template (value) RSL_IE_List ies := {
7780 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7781 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7782 }),
7783 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7784 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7785 })
7786 };
7787
7788 /* Ensure that 'rx-current' equals 'rx-target' */
7789 f_trxc_fake_rssi(mp_uplink_power_target);
7790
7791 /* Establish a dedicated channel */
7792 f_est_dchan(more_ies := valueof(ies));
7793
7794 L1CTL.clear;
7795 T.start;
7796 alt {
7797 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7798 [] T.timeout {
7799 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7800 num_blocks, " were not handled");
7801 }
7802 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007803
7804 /* Release the channel */
7805 f_rsl_chan_deact();
7806 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007807}
7808testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7809 var ConnHdlr vc_conn;
7810 var ConnHdlrPars pars;
7811
7812 f_init();
7813
7814 /* Explicitly configure the Uplink power target (in dBm) */
7815 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7816
7817 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7818 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7819 log(testcasename(), ": starting on ", pars.chan_nr);
7820
7821 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7822 pars, trxc_comp := true);
7823 vc_conn.done;
7824 }
7825
7826 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7828}
7829
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007830/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7831private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7832runs on ConnHdlr {
7833 var integer num_blocks := 16;
7834 timer T := int2float(num_blocks);
7835
7836 f_l1_tune(L1CTL);
7837 RSL.clear;
7838
7839 /* These IEs are needed for autonomous MS power control */
7840 var template (value) RSL_IE_List ies := {
7841 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7842 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7843 }),
7844 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7845 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7846 })
7847 };
7848
7849 /* Ensure that 'rx-current' equals 'rx-target' */
7850 f_trxc_fake_rssi(mp_uplink_power_target);
7851
7852 /* Establish a dedicated channel */
7853 f_est_dchan(more_ies := valueof(ies));
7854
7855 L1CTL.clear;
7856 T.start;
7857 alt {
7858 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7859 [] T.timeout {
7860 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7861 num_blocks, " were not handled");
7862 }
7863 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007864
7865 /* Release the channel */
7866 f_rsl_chan_deact();
7867 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007868}
7869testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7870 var ConnHdlr vc_conn;
7871 var ConnHdlrPars pars;
7872
7873 f_init();
7874
7875 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7876 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7877 /* Explicitly configure the Uplink power range (target and delte) */
7878 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7879 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7880
7881 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7882 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7883 log(testcasename(), ": starting on ", pars.chan_nr);
7884
7885 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7886 pars, trxc_comp := true);
7887 vc_conn.done;
7888 }
7889
7890 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7892}
7893
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007894private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7895 var template L1ctlDlMessage tr_bad_frame;
7896 var L1ctlDlMessage l1_dl;
7897 timer T := 8.0;
7898
7899 f_l1_tune(L1CTL);
7900 RSL.clear;
7901
7902 f_est_dchan();
7903
7904 /* There may be a few errors right after the channel activation */
7905 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7906 L1CTL.clear;
7907
7908 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7909 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7910 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7911 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7912 tr_bad_frame.payload := ?;
7913
7914 T.start;
7915 alt {
7916 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7917 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7918 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7919 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7920 }
7921 [] as_l1_sacch();
7922 [] L1CTL.receive { repeat; }
7923 [] T.timeout {
7924 /* We're done, break the loop */
7925 setverdict(pass);
7926 }
7927 }
7928
7929 f_rsl_chan_deact();
7930 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7931}
7932testcase TC_speech_no_rtp_tchf() runs on test_CT {
7933 var ConnHdlr vc_conn;
7934 var ConnHdlrPars pars;
7935
7936 f_init();
7937
7938 /* TS1, TCH/F, V1 (FR codec) */
7939 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7940 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7941 vc_conn.done;
7942}
7943testcase TC_speech_no_rtp_tchh() runs on test_CT {
7944 var ConnHdlr vc_conn;
7945 var ConnHdlrPars pars;
7946
7947 f_init();
7948
7949 /* TS5, TCH/H, V1 (HR codec) */
7950 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7951 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7952 vc_conn.done;
7953}
7954
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007955/* Verify handling of Downlink and Uplink speech frames */
7956private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7957 var L1ctlDlMessage l1_dl;
7958 var PDU_RTP rtp_pdu;
7959 var octetstring pl;
7960 timer Td, Tu;
7961
7962 f_l1_tune(L1CTL);
7963 f_est_dchan();
7964
7965 /* Activate the RTP emulation */
7966 pl := f_rnd_octstring(6);
7967 f_rtpem_activate(pl);
7968
7969 /* Give the scheduler some time to fill up the buffers */
7970 f_sleep(2.0);
7971 L1CTL.clear;
7972 RSL.clear;
7973
7974 /* Make sure that Downlink frames are received at the UE */
7975 Td.start(2.0);
7976 alt {
7977 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7978 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7979 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7980 l1_dl.payload.traffic_ind.data));
7981 setverdict(pass);
7982 }
7983 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7984 setverdict(fail, "Rx unexpected Downlink speech frame ",
7985 "(", l1_dl.payload.traffic_ind.data, ") ",
7986 "expected (", pl, ")");
7987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7988 }
7989 [] as_l1_sacch();
7990 [] L1CTL.receive { repeat; }
7991 [] Td.timeout {
7992 setverdict(fail, "Timeout waiting for Downlink speech frames");
7993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7994 }
7995 }
7996
7997 /* Make sure that Uplink frames are received at the BTS */
7998 RTPEM_DATA.clear;
7999 Tu.start(2.0);
8000 alt {
8001 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8002 if (rtp_pdu.data != pl)
8003 { repeat; }
8004 }
8005 [] RTPEM_DATA.receive { repeat; }
8006 [] Tu.timeout {
8007 setverdict(fail, "Timeout waiting for Uplink speech frames");
8008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8009 }
8010 }
8011
8012 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8013 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8014 f_rsl_chan_deact();
8015 f_rslem_unregister(0, g_chan_nr);
8016}
8017testcase TC_speech_rtp_tchf() runs on test_CT {
8018 var ConnHdlr vc_conn;
8019 var ConnHdlrPars pars;
8020
8021 f_init();
8022
8023 /* TS1, TCH/F, V1 (FR codec) */
8024 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8025 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8026 vc_conn.done;
8027
8028 /* TS1, TCH/F, V2 (EFR codec) */
8029 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8030 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8031 vc_conn.done;
8032
8033 /* TODO: also test V3 (AMR codec) */
8034
8035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8036}
8037testcase TC_speech_rtp_tchh() runs on test_CT {
8038 var ConnHdlr vc_conn;
8039 var ConnHdlrPars pars;
8040
8041 f_init();
8042
8043 /* TS5, TCH/H0, V1 (HR codec) */
8044 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8045 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8046 vc_conn.done;
8047
8048 /* TODO: also test V3 (AMR codec) */
8049
8050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8051}
8052
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008053private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8054 var GsmFrameNumber fn;
8055 var ChannelDescription ch_desc;
8056 var integer ra := 23;
8057
8058 f_l1_tune(L1CTL);
8059 RSL.clear;
8060
8061 /* Send RACH request and wait for ChanReq */
8062 fn := f_rach_req_wait_chan_rqd(ra);
8063
8064 /* The BSC already sends the Immediate Assignment, before the channel is active.
8065 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8066 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8067 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8068 if (g_pars.fhp.enabled) {
8069 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8070 } else {
8071 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8072 }
8073 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8074 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8075
8076 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8077 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8078 var L1ctlDlMessage dl;
8079 var GsmRrMessage rr;
8080
8081 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8082 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8083 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8084 rr_imm_ass.payload.imm_ass.chan_desc := *;
8085
8086 timer T := 1.0;
8087 T.start;
8088 alt {
8089 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8090 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8091 if (match(rr, rr_imm_ass)) {
8092 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8093 mtc.stop;
8094 } else {
8095 repeat;
8096 }
8097 }
8098 [] L1CTL.receive { repeat; }
8099 [] T.timeout;
8100 }
8101 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8102 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8103
8104 /* Now expect the IMM ASS on Um */
8105 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8106 setverdict(pass);
8107
8108 /* Release the channel */
8109 f_rsl_chan_deact();
8110 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8111}
8112
8113testcase TC_early_immediate_assignment() runs on test_CT {
8114 var ConnHdlr vc_conn;
8115 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8116 f_init();
8117 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8118 vc_conn.done;
8119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8120}
8121
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008122private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8123 var integer ra := oct2int(f_rnd_ra_cs());
8124 var ChannelDescription ch_desc;
8125
8126 /* Tune the MS to BCCH */
8127 f_l1_tune(L1CTL);
8128
8129 /* Send RACH request and wait for ChanReq */
8130 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8131
8132 /* Activate channel on the BTS side */
8133 f_rsl_chan_act(g_pars.chan_mode);
8134
8135 /* Craft channel description (with or without frequency hopping parameters) */
8136 if (g_pars.fhp.enabled) {
8137 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8138 } else {
8139 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8140 }
8141
8142 /* Send IMM.ASS via CCHAN */
8143 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8144 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8145
8146 /* Receive IMM.ASS on the MS side */
8147 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8148
8149 /* Match the Channel Description IE in received IMM.ASS */
8150 if (not match(imm_ass.chan_desc, ch_desc)) {
8151 setverdict(fail, "Channel Description IE does not match");
8152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8153 }
8154
8155 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8156 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8157
8158 /* Expect SACCH frames on Downlink */
8159 L1CTL.clear;
8160 f_exp_sacch(true);
8161
8162 /* We're done, deactivate and release */
8163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8164 f_rsl_chan_deact();
8165}
8166testcase TC_est_dchan() runs on test_CT {
8167 var ConnHdlr vc_conn;
8168 var ConnHdlrPars pars;
8169
8170 f_init();
8171
8172 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8173 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8174 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8175 vc_conn.done;
8176 }
8177
8178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8179}
8180
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008181private type record TopTestCase {
8182 RSL_IE_BS_Power bs_power,
8183 RSL_IE_OSMO_TopAcchCap top_cap,
8184 record of TopTestStep steps
8185};
8186private type record TopTestStep {
8187 MeasurementResults meas_res optional,
8188 GsmRxLev overpower_sacch,
8189 GsmRxLev overpower_facch
8190};
8191
8192private function f_rxlev_match(template (present) RslLinkId link_id,
8193 template (present) GsmRxLev rxlev)
8194runs on ConnHdlr {
8195 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8196 if (not match(dl.dl_info.rx_level, rxlev)) {
8197 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8198 " does not match expected RxLev := ", rxlev);
8199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8200 }
8201}
8202
8203private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8204 var TopTestCase tc := g_pars.spec.top;
8205 var GsmRxLev rxlev_dcch;
8206 var L1ctlDlMessage dl;
8207
8208 /* Wait for Pau ramping to complete */
8209 f_sleep(6.0);
8210
8211 f_l1_tune(L1CTL);
8212 L1CTL.clear;
8213 RSL.clear;
8214
8215 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8216 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8217 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8218
8219 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8220 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8221
8222 /* Additional IEs for the CHANnel ACTIVation message */
8223 var template (value) RSL_IE_List ies := {
8224 /* Employ BS power control in static mode */
8225 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8226 bs_power := tc.bs_power
8227 }),
8228 /* Indicate the given Temporary Overpower capability */
8229 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8230 top_acch_cap := tc.top_cap
8231 })
8232 };
8233
8234 /* Establish a dedicated channel */
8235 f_est_dchan(more_ies := valueof(ies));
8236
8237 /* Give it some time to stabilize */
8238 f_sleep(0.480 * 2.0);
8239 L1CTL.clear;
8240 RSL.clear;
8241
8242 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8243 var TopTestStep step := tc.steps[i];
8244 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8245 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8246
8247 log("Executing step[", i, "] := ", step);
8248
8249 /* Send RR Measurement Report (if present) */
8250 if (ispresent(step.meas_res)) {
8251 f_transceive_meas_rep(step.meas_res);
8252 f_sleep(0.480 * 2.0);
8253 L1CTL.clear;
8254 }
8255
8256 /* Check RxLev on both FACCH and SACCH */
8257 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8258 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8259
8260 setverdict(pass);
8261 }
8262}
8263testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8264 var ConnHdlrPars pars;
8265 var ConnHdlr vc_conn;
8266
8267 f_init();
8268
8269 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008270 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008271 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8272 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8273 steps := {
8274 /* Channel established, no overpower */
8275 { meas_res := omit,
8276 overpower_sacch := 0, overpower_facch := 0 },
8277
8278 /* Worst possible RxQual value, overpower of 4dB */
8279 { meas_res := ts_MeasurementResults(rxq_f := 7),
8280 overpower_sacch := 4, overpower_facch := 4 },
8281 /* Worst possible RxQual value, disabling overpower */
8282 { meas_res := ts_MeasurementResults(rxq_f := 0),
8283 overpower_sacch := 0, overpower_facch := 0 },
8284
8285 /* Lower threshold not reached, no overpower */
8286 { meas_res := ts_MeasurementResults(rxq_f := 1),
8287 overpower_sacch := 0, overpower_facch := 0 },
8288 /* Lower threshold not reached, no overpower */
8289 { meas_res := ts_MeasurementResults(rxq_f := 2),
8290 overpower_sacch := 0, overpower_facch := 0 },
8291 /* Lower threshold reached, overpower of 4dB */
8292 { meas_res := ts_MeasurementResults(rxq_f := 4),
8293 overpower_sacch := 4, overpower_facch := 4 },
8294 /* Upper threshold not reached, keeping overpower */
8295 { meas_res := ts_MeasurementResults(rxq_f := 3),
8296 overpower_sacch := 4, overpower_facch := 4 },
8297 /* Upper threshold reached, disabling overpower */
8298 { meas_res := ts_MeasurementResults(rxq_f := 2),
8299 overpower_sacch := 0, overpower_facch := 0 }
8300 }
8301 };
8302
8303 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8304 spec := { top := top }, trx_nr := 1));
8305 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8306 vc_conn.done;
8307
8308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8309}
8310testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8311 var ConnHdlrPars pars;
8312 var ConnHdlr vc_conn;
8313
8314 f_init();
8315
8316 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008317 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008318 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8319 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8320 steps := {
8321 /* Channel established, no overpower */
8322 { meas_res := omit,
8323 overpower_sacch := 0, overpower_facch := 0 },
8324
8325 /* Invalid measurement results, no overpower */
8326 { meas_res := ts_MeasurementResults(rxq_f := 7,
8327 rxq_s := 7,
8328 valid := false),
8329 overpower_sacch := 0, overpower_facch := 0 },
8330
8331 /* DTXu was in use, no overpower */
8332 { meas_res := ts_MeasurementResults(rxq_f := 7,
8333 rxq_s := 0,
8334 dtx_used := true),
8335 overpower_sacch := 0, overpower_facch := 0 },
8336 /* DTXu was in use, overpower of 4 dB */
8337 { meas_res := ts_MeasurementResults(rxq_f := 0,
8338 rxq_s := 7,
8339 dtx_used := true),
8340 overpower_sacch := 4, overpower_facch := 4 }
8341 }
8342 };
8343
8344 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8345 spec := { top := top }, trx_nr := 1));
8346 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8347 vc_conn.done;
8348
8349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8350}
8351testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8352 var ConnHdlrPars pars;
8353 var ConnHdlr vc_conn;
8354
8355 f_init();
8356
8357 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008358 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008359 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8360 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8361 rxqual := 0, /* always on */
8362 sacch_enable := false),
8363 steps := {
8364 /* Channel established, FACCH overpower */
8365 { meas_res := omit,
8366 overpower_sacch := 0, overpower_facch := 4 },
8367 /* MS indicates good RxQual, no difference */
8368 { meas_res := ts_MeasurementResults(rxq_f := 0),
8369 overpower_sacch := 0, overpower_facch := 4 },
8370 /* MS indicates bad RxQual, no difference */
8371 { meas_res := ts_MeasurementResults(rxq_f := 7),
8372 overpower_sacch := 0, overpower_facch := 4 }
8373 }
8374 };
8375
8376 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8377 spec := { top := top }, trx_nr := 1));
8378 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8379 vc_conn.done;
8380
8381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8382}
8383testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8384 var ConnHdlrPars pars;
8385 var ConnHdlr vc_conn;
8386
8387 f_init();
8388
8389 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008390 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008391 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8392 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8393 rxqual := 0, /* always on */
8394 facch_enable := false),
8395 steps := {
8396 /* Channel established, SACCH overpower */
8397 { meas_res := omit,
8398 overpower_sacch := 4, overpower_facch := 0 },
8399 /* MS indicates good RxQual, no difference */
8400 { meas_res := ts_MeasurementResults(rxq_f := 0),
8401 overpower_sacch := 4, overpower_facch := 0 },
8402 /* MS indicates bad RxQual, no difference */
8403 { meas_res := ts_MeasurementResults(rxq_f := 7),
8404 overpower_sacch := 4, overpower_facch := 0 }
8405 }
8406 };
8407
8408 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8409 spec := { top := top }, trx_nr := 1));
8410 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8411 vc_conn.done;
8412
8413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8414}
8415testcase TC_acch_overpower_limit() runs on test_CT {
8416 var ConnHdlrPars pars;
8417 var ConnHdlr vc_conn;
8418
8419 f_init();
8420
8421 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008422 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008423 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8424 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8425 rxqual := 0 /* always on */),
8426 steps := {
8427 /* Channel established, ACCH overpower of 2dB */
8428 { meas_res := omit,
8429 overpower_sacch := 2, overpower_facch := 2 },
8430 /* MS indicates good RxQual, no difference */
8431 { meas_res := ts_MeasurementResults(rxq_f := 0),
8432 overpower_sacch := 2, overpower_facch := 2 },
8433 /* MS indicates bad RxQual, no difference */
8434 { meas_res := ts_MeasurementResults(rxq_f := 7),
8435 overpower_sacch := 2, overpower_facch := 2 }
8436 }
8437 };
8438
8439 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8440 spec := { top := top }, trx_nr := 1));
8441 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8442 vc_conn.done;
8443
8444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8445}
8446
Harald Welte0472ab42018-03-12 15:02:26 +01008447/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8448/* protocol error as per 44.006 */
8449/* link layer failure (repetition of I-frame N200 times without ACK */
8450/* repetition of SABM or DISC N200 times without ACK */
8451/* receptiom of SABM in multi-frame established state */
8452
8453
Harald Welte68e495b2018-02-25 00:05:57 +01008454/* TODO Areas:
8455
8456* channel activation
8457** with BS_Power / MS_Power, bypassing power control loop
8458** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008459** with timing advance from initial activation on
8460* mode modify
8461** encryption
8462** multirate
8463* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008464** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008465* BS Power Control
8466* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008467* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008468** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008469* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008470** DATA_IND from BTS->PCU
8471** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008472
8473*/
Harald Welte70767382018-02-21 12:16:40 +01008474
8475control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008476 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008477 execute( TC_chan_act_stress() );
8478 execute( TC_chan_act_react() );
8479 execute( TC_chan_deact_not_active() );
8480 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008481 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008482 execute( TC_sacch_filling() );
8483 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008484 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008485 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008486 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008487 execute( TC_sacch_chan_act_ho_async() );
8488 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008489 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008490 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008491 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008492 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008493 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008494 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008495 execute( TC_rach_load_idle_thresh0() );
8496 execute( TC_rach_load_idle_below_thresh() );
8497 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008498 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008499 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008500 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008501 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008502 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008503 execute( TC_meas_res_sign_tchf() );
8504 execute( TC_meas_res_sign_tchh() );
8505 execute( TC_meas_res_sign_sdcch4() );
8506 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008507 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008508 execute( TC_meas_res_speech_tchf_sapi3() );
8509 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008510 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008511 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008512 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008513 execute( TC_rsl_bs_pwr_static_ass() );
8514 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008515 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008516 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008517 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008518 execute( TC_rsl_ms_pwr_dyn_up() );
8519 execute( TC_rsl_ms_pwr_dyn_down() );
8520 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8521 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008522 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008523 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008524 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008525 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008526 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008527 execute( TC_paging_imsi_80percent() );
8528 execute( TC_paging_tmsi_80percent() );
8529 execute( TC_paging_imsi_200percent() );
8530 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008531 execute( TC_rsl_protocol_error() );
8532 execute( TC_rsl_mand_ie_error() );
8533 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008534 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008535 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008536 execute( TC_si_sched_2bis() );
8537 execute( TC_si_sched_2ter() );
8538 execute( TC_si_sched_2ter_2bis() );
8539 execute( TC_si_sched_2quater() );
8540 execute( TC_si_sched_13() );
8541 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008542 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008543 execute( TC_ipa_crcx_twice_not_active() );
8544 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008545 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008546 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008547
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008548 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008549 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008550 execute( TC_pcu_act_req() );
8551 execute( TC_pcu_act_req_wrong_ts() );
8552 execute( TC_pcu_act_req_wrong_bts() );
8553 execute( TC_pcu_act_req_wrong_trx() );
8554 execute( TC_pcu_deact_req() );
8555 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008556 execute( TC_pcu_ver_si1() );
8557 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008558 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008559 if (mp_l1_supports_gprs) {
8560 execute( TC_pcu_data_req_pdtch() );
8561 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008562 execute( TC_pcu_data_req_wrong_bts() );
8563 execute( TC_pcu_data_req_wrong_trx() );
8564 execute( TC_pcu_data_req_wrong_ts() );
8565 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008566 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008567 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008568 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008569 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008570 execute( TC_pcu_data_req_imm_ass_pch() );
8571 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008572 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008573 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008574 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008575 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008576 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008577 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008578 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008579 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008580 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008581 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008582 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008583 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008584 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008585 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008586 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008587 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008588 execute( TC_dyn_osmo_pdch_act_deact() );
8589 execute( TC_dyn_osmo_pdch_double_act() );
8590 execute( TC_dyn_ipa_pdch_act_deact() );
8591 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008592 execute( TC_pcu_info_ind_fh_params() );
8593 execute( TC_pcu_socket_nsvc_ipv4() );
8594 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008595 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008596 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008597 } else {
8598 log("PCU socket path not available, skipping PCU tests");
8599 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008600
Harald Welte3d04ae62018-04-04 20:29:05 +02008601 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008602 execute( TC_dyn_osmo_pdch_tchf_act() );
8603 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008604 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008605 execute( TC_dyn_ipa_pdch_tchf_act() );
8606 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008607
8608 execute( TC_rll_est_ind() );
8609 execute( TC_rll_est_req_DCCH_3() );
8610 execute( TC_rll_est_req_ACCH_3() );
8611 execute( TC_rll_rel_ind_DCCH_0() );
8612 execute( TC_rll_rel_ind_DCCH_3() );
8613 execute( TC_rll_rel_ind_ACCH_0() );
8614 execute( TC_rll_rel_ind_ACCH_3() );
8615 execute( TC_rll_rel_req() );
8616 execute( TC_rll_unit_data_req_DCCH() );
8617 execute( TC_rll_unit_data_req_ACCH() );
8618 execute( TC_rll_unit_data_ind_DCCH() );
8619 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008620
8621 execute( TC_chan_act_a51() );
8622 execute( TC_chan_act_a52() );
8623 execute( TC_chan_act_a53() );
8624 execute( TC_encr_cmd_a51() );
8625 execute( TC_encr_cmd_a52() );
8626 execute( TC_encr_cmd_a53() );
8627
Harald Welteee25aae2019-05-19 14:32:37 +02008628 execute( TC_err_rep_wrong_mdisc() );
8629 execute( TC_err_rep_wrong_msg_type() );
8630 execute( TC_err_rep_wrong_sequence() );
8631
Harald Weltee613f962018-04-18 22:38:16 +02008632 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008633
8634 execute( TC_tch_sign_l2_fill_frame() );
8635 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008636
8637 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008638 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008639
8640 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008641 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008642
8643 execute( TC_speech_no_rtp_tchf() );
8644 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008645 execute( TC_speech_rtp_tchf() );
8646 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008647
8648 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008649
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008650 execute( TC_acch_overpower_rxqual_thresh() );
8651 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8652 execute( TC_acch_overpower_always_on_facch() );
8653 execute( TC_acch_overpower_always_on_sacch() );
8654 execute( TC_acch_overpower_limit() );
8655
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008656 /* BEWARE: these test cases can potentially break the IUT or cause
8657 * weird/unexpected behavior. Ensure that they are executed last. */
8658 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8659 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008660}
8661
8662
8663}