blob: 5837a03952f69a28155244a128442423a25852b8 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +0300138 /* T3105 timer (see 3GPP TS 44.018, section 11.1.2) */
139 integer mp_ho_t3105_ms := 100;
140 /* Ny1 counter (see 3GPP TS 44.018, section 11.1.3) */
141 integer mp_ho_ny1 := 10;
Harald Welte70767382018-02-21 12:16:40 +0100142}
143
Harald Welte629cc6b2018-03-11 17:19:05 +0100144type record of RslChannelNr ChannelNrs;
145
Harald Welte70767382018-02-21 12:16:40 +0100146type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100148 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100149 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100150 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100151 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100152 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100153
154 /* L1CTL port (for classic tests) */
155 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100156
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700157 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700158 port TRXC_CODEC_PT BTS_TRXC;
159 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100160
Harald Weltef50e3ae2018-09-10 10:27:56 +0200161 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100162 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200163 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100164
Harald Welte883340c2018-02-28 18:59:29 +0100165 /* PCU Interface of BTS */
166 port PCUIF_CODEC_PT PCU;
167 var integer g_pcu_conn_id;
168 /* Last PCU INFO IND we received */
169 var PCUIF_Message g_pcu_last_info;
170
Harald Welte48494ca2018-02-25 16:59:50 +0100171 /* SI configuration */
172 var SystemInformationConfig si_cfg := {
173 bcch_extended := false,
174 si1_present := false,
175 si2bis_present := false,
176 si2ter_present := false,
177 si2quater_present := false,
178 si7_present := false,
179 si8_present := false,
180 si9_present := false,
181 si13_present := false,
182 si13alt_present := false,
183 si15_present := false,
184 si16_present := false,
185 si17_present := false,
186 si2n_present := false,
187 si21_present := false,
188 si22_present := false
189 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100190
191 /* all logical channels available on the BTS */
192 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100193 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
196/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200197type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100198 port L1CTL_PT L1CTL;
199
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700200 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700201 port TRXC_CODEC_PT BTS_TRXC;
202 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100203
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200204 /* port to be initialized optionally to access BSC VTY */
205 port TELNETasp_PT BSCVTY;
206
Harald Welte70767382018-02-21 12:16:40 +0100207 timer g_Tguard;
208 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
209
210 var ConnHdlrPars g_pars;
211 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100212 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200213
214 /* PCU Interface of BTS */
215 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200216
217 var RTP_Emulation_CT vc_RTPEM;
218 port RTPEM_CTRL_PT RTPEM_CTRL;
219 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100220}
221
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700222private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200226 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200228 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700229 timer T;
230
Harald Welte70767382018-02-21 12:16:40 +0100231 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
232 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
233
234 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
235 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
236 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
237
238 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
239 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700240
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700241 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700242 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700243 T.start(mp_ipa_up_timeout);
244 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700245 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700246 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
247 /* Make sure that all transceivers use unique stream ID */
248 if (trx_mask[enum2int(ev.sid)] == '1'B) {
249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
250 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
251 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700252
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700253 trx_mask[enum2int(ev.sid)] := '1'B;
254 trx_count := trx_count + 1;
255
256 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200257 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700258 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200259 /* This message (RF RESource INDication) is sent by the IUT itself */
260 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
261 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
264 }
265 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
267 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
268 }
269
270 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
271 rfind_count := rfind_count + 1;
272 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
273 if (rfind_count < mp_transceiver_num) { repeat; }
274 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700275 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
276 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
277 [] T.timeout {
278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
279 "Timeout waiting for RSL bring up");
280 }
281 }
Harald Welte70767382018-02-21 12:16:40 +0100282}
283
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700284friend type record length(1 .. 256) of TrxParsItem TrxPars;
285friend type record TrxParsItem {
286 GsmArfcn arfcn,
287 TrxTsPars ts
288};
289
290friend type record length(8) of TrxTsParsItem TrxTsPars;
291friend type record TrxTsParsItem {
292 PchanConfig config
293};
294
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700295friend type record FreqHopPars {
296 /* Whether frequency hopping is in use */
297 boolean enabled,
298 /* Mobile Allocation Index Offset / Hopping Sequence Number */
299 MaioHsn maio_hsn,
300 /* MA bitmap to be indicated in RR Immediate Assignment */
301 MobileAllocationLV ma_map,
302 /* The actual Mobile Allocation (ARFCN list) to be used */
303 L1ctlMA ma
304};
305
Harald Welte70767382018-02-21 12:16:40 +0100306type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700307 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100308 RslChannelNr chan_nr,
309 RSL_IE_ChannelMode chan_mode,
310 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100311 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200312 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200313 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700314 BtsBand bts0_band optional,
315
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700316 /* Training Sequence Code */
317 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700318 /* Frequency hopping parameters */
319 FreqHopPars fhp
320};
Harald Welte0472ab42018-03-12 15:02:26 +0100321
322/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200323friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300324 RllTestCase rll,
325 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100326}
327
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700328private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100329 max_retrans := RACH_MAX_RETRANS_7,
330 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100331 cell_barr_access := false,
332 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100333 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100334};
335
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700336private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100337 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200338 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100339 acs := '0'B,
340 neci := true,
341 rxlev_access_min := 0
342}
343
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700344private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100345 mcc_mnc := '262F42'H,
346 lac := 42
347}
348
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700349private template (value) GPRSIndicator ts_GPRSIndicator_def := {
350 ra_colour := 0,
351 si13_pos := '0'B
352}
353
354private template (value) SI3RestOctets ts_SI3RestOctets_def
355modifies ts_SI3RestOctets := {
356 gprs_ind := {
357 presence := CSN1_H,
358 ind := ts_GPRSIndicator_def
359 }
360}
361
362private template (value) SI4RestOctets ts_SI4RestOctets_def
363modifies ts_SI4RestOctets := {
364 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700365 presence := CSN1_H,
366 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700367 }
368}
369
Harald Welte7484fc42018-02-24 14:09:45 +0100370/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100373 payload := {
374 si3 := {
375 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100376 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100377 ctrl_chan_desc := {
378 msc_r99 := true,
379 att := true,
380 bs_ag_blks_res := 1,
381 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100382 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100383 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
384 spare := '00'B,
385 bs_pa_mfrms := 0, /* 2 multiframes */
386 t3212 := 1 /* 6 minutes */
387 },
Harald Welte82ccef72018-02-25 16:17:33 +0100388 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100389 dn_ind := false,
390 pwrc := false,
391 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100392 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100393 },
Harald Weltef10153f2018-02-25 16:34:05 +0100394 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100395 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200396 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100397 }
398 }
399}
Harald Welte70767382018-02-21 12:16:40 +0100400
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700401private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100402 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100403 payload := {
404 si2 := {
405 bcch_freq_list := '00000000000000000000000000000000'O,
406 ncc_permitted := '11111111'B,
407 rach_control := ts_RachCtrl_default
408 }
409 }
410}
411
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700412private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100413 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100414 payload := {
415 si4 := {
416 lai := ts_LAI_default,
417 cell_sel_par := ts_CellSelPar_default,
418 rach_control := ts_RachCtrl_default,
419 cbch_chan_desc := omit,
420 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200421 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100422 }
423 }
424}
425
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700426private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100427runs on test_CT {
428 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700429 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100430}
431
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700432private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100433runs on test_CT {
434 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
435 log("Setting ", rsl_si_type, ": ", si_dec);
436 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
437}
438
Harald Welte505cf9b2018-09-15 17:47:23 +0300439friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100440 map(self:BTSVTY, system:BTSVTY);
441 f_vty_set_prompts(BTSVTY);
442 f_vty_transceive(BTSVTY, "enable");
443}
444
Harald Welte505cf9b2018-09-15 17:47:23 +0300445friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200446 map(self:BSCVTY, system:BSCVTY);
447 f_vty_set_prompts(BSCVTY, "OsmoBSC");
448 f_vty_transceive(BSCVTY, "enable");
449}
450
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200451friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
452 map(self:BSCVTY, system:BSCVTY);
453 f_vty_set_prompts(BSCVTY, "OsmoBSC");
454 f_vty_transceive(BSCVTY, "enable");
455}
456
Harald Welte883340c2018-02-28 18:59:29 +0100457/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200458friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100460 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200461 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
462 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100463 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200464 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100466 }
467}
468
Harald Weltef26de0b2018-04-04 20:28:05 +0200469private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
470 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100471 timer T := 2.0;
472 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100473 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200474 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100475 return;
476 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100478
479 T.start;
480 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200481 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100484 }
485 }
486}
487
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700488private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
489 out integer trxc_conn_id) {
490 var Result res;
491
492 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
493 "", -1, -1, { udp := {} }, {});
494 if (not ispresent(res.connId)) {
495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
496 "Could not connect to the control (TRXC) interface " &
497 "of FakeTRX, check your configuration");
498 }
499 trxc_conn_id := res.connId;
500}
501
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100502/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700503friend function f_init(uint8_t trx_nr := 0)
504runs on test_CT
505{
506 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200507 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100508
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700509 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
510 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700511 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200512 g_AllChanTypes := {
513 /* TS 1..4: TCH/F */
514 valueof(ts_RslChanNr_Bm(1)),
515 /* TS 5: TCH/H */
516 valueof(ts_RslChanNr_Lm(5,1)),
517 /* TS 0: SDCCH/4 */
518 valueof(ts_RslChanNr_SDCCH4(0,2)),
519 /* TS 6: SDCCH/8 */
520 valueof(ts_RslChanNr_SDCCH8(6,4))
521 };
522 } else {
523 g_AllChanTypes := {
524 /* TS 1..4: TCH/F */
525 valueof(ts_RslChanNr_Bm(1)),
526 /* TS 0: SDCCH/4 */
527 valueof(ts_RslChanNr_SDCCH4(0,2)),
528 /* TS 6: SDCCH/8 */
529 valueof(ts_RslChanNr_SDCCH8(6,4))
530 };
531 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700532
533 g_AllChannels := { };
534
535 /* Generate list of all logical channels from module parameters */
536 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
537 select (trx_pars.ts[tn].config) {
538 case (GSM_PCHAN_CCCH_SDCCH4) {
539 g_AllChannels := g_AllChannels &
540 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
541 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
542 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
543 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
544 }
545 case (GSM_PCHAN_SDCCH8) {
546 g_AllChannels := g_AllChannels &
547 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
551 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
552 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
553 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
554 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
555 }
556 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
557 g_AllChannels := g_AllChannels &
558 { valueof(ts_RslChanNr_Lm(tn, 0)),
559 valueof(ts_RslChanNr_Lm(tn, 1)),
560 valueof(ts_RslChanNr_Bm(tn)) };
561 }
562 case (GSM_PCHAN_TCHH) {
563 g_AllChannels := g_AllChannels &
564 { valueof(ts_RslChanNr_Lm(tn, 0)),
565 valueof(ts_RslChanNr_Lm(tn, 1)) };
566 }
567 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
568 g_AllChannels := g_AllChannels &
569 { valueof(ts_RslChanNr_Bm(tn)) };
570 }
571 }
572 }
573
Harald Welte70767382018-02-21 12:16:40 +0100574 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100575 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100576 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100577 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100578
579 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100580 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
581 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
582 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
583 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100584
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700585 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100586 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700587
588 /* Init TRXC interface to FakeTRX */
589 map(self:BTS_TRXC, system:BTS_TRXC);
590 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
591
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700592 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600593 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
594 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700595 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600596 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100597 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200598
599 /* Wait some extra time to make sure the BTS emits a stable carrier.
600 * (this is only relevant when running the tests with a physical BTS.) */
601 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Harald Welte68e495b2018-02-25 00:05:57 +0100604/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700605friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100606 map(self:L1CTL, system:L1CTL);
607 f_connect_reset(L1CTL);
608}
609
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200610friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100611
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700612private type record length(8) of FreqHopGroups FreqHopConfig;
613
614private type record of FreqHopGroup FreqHopGroups;
615private type record FreqHopGroup {
616 uint6_t hsn,
617 FreqHopGroupItems trx_maio
618};
619
620private type record of FreqHopGroupItem FreqHopGroupItems;
621private type record FreqHopGroupItem {
622 uint8_t trx_nr,
623 uint6_t maio
624};
625
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700626friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
627 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700628{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700629 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 var integer i, j;
631
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700632 fhp.enabled := false;
633
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700634 for (i := 0; i < lengthof(groups); i := i + 1) {
635 var FreqHopGroup g := groups[i];
636 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
637 var FreqHopGroupItem gi := g.trx_maio[j];
638 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700639 fhp.maio_hsn.maio := gi.maio;
640 fhp.maio_hsn.hsn := g.hsn;
641 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700642 break;
643 }
644 }
645
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700646 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700648 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
649 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
650 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700651
652 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700653 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
654 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700655 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700656 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700657 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700658 }
659
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700660 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700661 break; /* We're done */
662 }
663 }
664}
665
Harald Welte70767382018-02-21 12:16:40 +0100666/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700667friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
668 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200669 boolean trxc_comp := false,
670 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100671runs on test_CT return ConnHdlr {
672 var charstring id := testcasename();
673 var ConnHdlr vc_conn;
674
675 vc_conn := ConnHdlr.create(id);
676 /* connect to RSL Emulation main component */
677 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
678 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700679
680 /* The ConnHdlr component may want to talk to some ports directly,
681 * so we disconnect it from the test_CT and connect it to the component.
682 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200683 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200684 unmap(self:PCU, system:PCU);
685 map(vc_conn:PCU, system:PCU);
686 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700687 if (trxc_comp) {
688 unmap(self:BTS_TRXC, system:BTS_TRXC);
689 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
690 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200691 if (l1ctl) {
692 map(vc_conn:L1CTL, system:L1CTL);
693 }
Harald Welte70767382018-02-21 12:16:40 +0100694
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700695 /* Obtain frequency hopping parameters for a given timeslot */
696 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700697 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700698 }
699
Harald Welte70767382018-02-21 12:16:40 +0100700 vc_conn.start(f_handler_init(fn, id, pars));
701 return vc_conn;
702}
703
Harald Welte70767382018-02-21 12:16:40 +0100704private altstep as_Tguard() runs on ConnHdlr {
705 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100707 }
708}
709
Harald Welte990a3612019-05-27 14:02:13 +0200710friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700711 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700712 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100713}
714
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700715private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100716 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600717 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700720private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100721 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600722 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100723}
724
725/* first function started in ConnHdlr component */
726private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
727runs on ConnHdlr {
728 g_pars := pars;
729 g_chan_nr := pars.chan_nr;
730
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200731 if (L1CTL.checkstate("Mapped")) {
732 f_connect_reset(L1CTL);
733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
Harald Welted48c0c72019-06-05 10:01:15 +0200735 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700736 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100737 }
Harald Welte70767382018-02-21 12:16:40 +0100738
739 g_Tguard.start(pars.t_guard);
740 activate(as_Tguard());
741
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700742 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100743
744 /* call the user-supplied test case function */
745 fn.apply(id);
746}
747
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700748private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
749 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200750runs on ConnHdlr return RSL_Message {
751 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100752 timer T := 3.0;
753 RSL.send(tx);
754 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100755 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200756 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100757 T.stop;
758 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100759 }
Harald Welte1eba3742018-02-25 12:48:14 +0100760 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100762 }
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] as_l1_sacch();
764 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700765 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700766 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100767 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100769 }
Harald Welte21240e62018-03-11 21:43:35 +0100770 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100771 }
Harald Welteb1726c92018-03-30 11:56:38 +0200772 return rx;
773}
774
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700775friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
776 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200777runs on ConnHdlr {
778 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100779}
780
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300781/* Send the given measurement results to the IUT over the Um interface,
782 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
783friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
784runs on ConnHdlr {
785 var template (value) SacchL1Header l1h;
786 var octetstring l2, l3;
787 timer T;
788
789 /* RR Measurement Report to be sent */
790 var GsmRrL3Message meas_rep := {
791 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
792 payload := { meas_rep := { meas_res := valueof(meas_res) } }
793 };
794
795 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
796 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
797 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
798 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
799 g_pars.l1_pars.ms_actual_ta);
800
801 /* Send RR Measurement Report over the Um interface */
802 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
803
804 /* Expect MEASurement RESult on the A-bis/RSL interface */
805 T.start(2.0);
806 alt {
807 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
808 setverdict(pass);
809 }
810 [] RSL.receive { repeat; }
811 [] T.timeout {
812 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
814 }
815 }
816}
817
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700818friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
819 boolean encr_enable := false,
820 RSL_IE_List more_ies := {},
821 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
822runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200823 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200824 if (encr_enable) {
825 /* append encryption related IEs, if requested */
826 var RSL_IE_EncryptionInfo encr_info;
827 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
828 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
829encr_info})) };
830 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200831 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200832 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100833}
834
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700835friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100836 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100837 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100838}
839
Harald Welte2f2b2b72019-05-31 22:24:57 +0200840friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200841 template RSL_IE_ChannelMode chan_mode,
842 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700843 uint8_t trx_nr := 0, float t_guard := 20.0) := {
844 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100845 chan_nr := valueof(chan_nr),
846 chan_mode := valueof(chan_mode),
847 t_guard := t_guard,
848 l1_pars := {
849 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100850 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100851 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100852 meas_ul := {
853 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 },
857 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200858 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 rxqual := 0
860 }
861 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200862 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100863 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200864 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200865 ms_actual_ta := mp_ms_actual_ta_exp,
866 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100867 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200868 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200869 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700870 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700871 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700872 fhp := {
873 enabled := false,
874 maio_hsn := ts_HsnMaio(0, 0),
875 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700876 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700877 }
Harald Welte70767382018-02-21 12:16:40 +0100878}
879
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300880/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
881 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
882private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
883 template (present) octetstring tr_data := ?,
884 template (present) RslChannelNr chan_nr := ?,
885 template (present) RslLinkId link_id := ?)
886runs on ConnHdlr {
887 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
888}
889
890/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
891 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
892private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
893 template (present) RslLinkId link_id := ?,
894 template (present) LapdmSapi sapi := ?,
895 boolean do_repeat := true)
896runs on ConnHdlr {
897 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
898 var L1ctlDlMessage dl_msg;
899
900 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
901 if (do_repeat) {
902 repeat;
903 }
904 }
905}
906
907/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
908 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
909private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
910 template (present) LapdmFrameAB tr_frame := ?,
911 template (present) RslLinkId link_id := ?)
912runs on ConnHdlr {
913 var L1ctlDlMessage dl_msg;
914
915 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
916 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
917 }
918}
919
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300920/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
921 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
922private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
923 template (present) LapdmFrameAB tr_frame := ?,
924 template (present) SacchL1Header tr_l1h := ?,
925 template (present) GsmSapi sapi := ?)
926runs on ConnHdlr {
927 var L1ctlDlMessage dl_msg;
928 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
929 template (present) L1ctlDataReq tr_data := {
930 l1header := tr_l1h,
931 l2_payload := decmatch tr_frame
932 };
933
934 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
935 var octetstring data := dl_msg.payload.data_ind.payload;
936 l1h := dec_SacchL1Header(substr(data, 0, 2));
937 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
938 }
939}
940
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300941/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
942 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
943 * payload is treated as PDU_ML3_NW_MS. */
944private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
945 template (present) PDU_ML3_NW_MS tr_pdu := ?,
946 template (present) GsmSapi sapi := 0)
947runs on ConnHdlr {
948 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
949 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
950 var LapdmFrameAB lapdm_frame;
951
952 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
953 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
954 }
955}
956
Harald Welte93640c62018-02-25 16:59:33 +0100957/***********************************************************************
958 * Channel Activation / Deactivation
959 ***********************************************************************/
960
Harald Welte70767382018-02-21 12:16:40 +0100961/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700962private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100963 for (var integer i := 0; i < 500; i := i+1) {
964 f_rsl_chan_act(g_pars.chan_mode);
965 f_rsl_chan_deact();
966 }
967 setverdict(pass);
968}
969testcase TC_chan_act_stress() runs on test_CT {
970 var ConnHdlr vc_conn;
971 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200972 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100973 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
974 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100976}
977
978/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700979private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100980 f_rsl_chan_act(g_pars.chan_mode);
981 /* attempt to activate the same lchan again -> expect reject */
982 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
983 alt {
984 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100986 }
987 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
988 setverdict(pass);
989 }
990 }
991 f_rsl_chan_deact();
992}
993testcase TC_chan_act_react() runs on test_CT {
994 var ConnHdlr vc_conn;
995 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100996 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100997 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
998 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001000}
1001
1002/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001003private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001004 timer T := 3.0;
1005 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1006 T.start;
1007 alt {
1008 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1009 setverdict(pass);
1010 }
1011 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001013 }
1014 }
1015}
1016testcase TC_chan_deact_not_active() runs on test_CT {
1017 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001018 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001019 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1020 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001022}
1023
1024/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001025private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001026 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1027 alt {
1028 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001030 }
1031 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1032 setverdict(pass);
1033 }
1034 }
1035}
1036private type record WrongChanNrCase {
1037 RslChannelNr chan_nr,
1038 charstring description
1039}
1040private type record of WrongChanNrCase WrongChanNrCases;
1041private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1042 chan_nr := chan_nr,
1043 description := desc
1044}
1045
1046testcase TC_chan_act_wrong_nr() runs on test_CT {
1047 var ConnHdlr vc_conn;
1048 var ConnHdlrPars pars;
1049
Harald Welte294b0a22018-03-10 23:26:48 +01001050 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001051
1052 var WrongChanNrCases wrong := {
1053 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1054 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1055 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1056 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1057 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1058 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1059 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1060 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1061 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1062 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1063 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1064 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1065 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1066 };
1067
1068 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1069 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1070 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1071 vc_conn.done;
1072 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001074}
1075
Harald Weltee613f962018-04-18 22:38:16 +02001076/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001077friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001078 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001079 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001080
1081 /* test on each of the channels we have */
1082 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1083 pars.chan_nr := valueof(g_AllChanTypes[i]);
1084
1085 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1086 vc_conn := f_start_handler(fn, pars);
1087 vc_conn.done;
1088 }
1089
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001091}
1092
Harald Welte93640c62018-02-25 16:59:33 +01001093/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001094 * SACCH handling
1095 ***********************************************************************/
1096
1097private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1098 timer T_sacch := 3.0;
1099 T_sacch.start;
1100 alt {
1101 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001103 }
1104 [not exp] T_sacch.timeout {
1105 setverdict(pass);
1106 }
1107 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1108 setverdict(pass);
1109 }
1110 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001111 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001112 }
1113 [] L1CTL.receive { repeat; }
1114 [] RSL.receive { repeat; }
1115 }
1116}
1117
1118/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1119private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1120 f_l1_tune(L1CTL);
1121 RSL.clear;
1122
1123 /* activate the logical channel */
1124 f_est_dchan();
1125 L1CTL.clear;
1126
1127 /* check that SACCH actually are received as expected */
1128 f_exp_sacch(true);
1129
1130 /* deactivate SACCH on the logical channel */
1131 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1132 f_sleep(1.0);
1133 L1CTL.clear;
1134
1135 /* check that no SACCH are received anymore */
1136 f_exp_sacch(false);
1137
1138 /* release the channel */
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_deact_sacch() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 //for (var integer i := 0; i < 1; i := i+1) {
1148 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1149 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1150 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1151 vc_conn.done;
1152 }
1153 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001155}
1156
Harald Welte55700662018-03-12 13:15:43 +01001157/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001158private function f_sacch_present(template octetstring l3_exp,
1159 boolean do_fail := true)
1160runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001161 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001162 timer T_sacch := 3.0;
1163 L1CTL.clear;
1164 T_sacch.start;
1165 alt {
1166 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1167 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1168 if (match(l3, l3_exp)) {
1169 setverdict(pass);
1170 } else {
1171 repeat;
1172 }
1173 }
1174 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001175 [not do_fail] T_sacch.timeout {
1176 log("Timeout waiting for SACCH ", l3_exp);
1177 }
1178 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001179 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001181 }
1182 }
1183}
1184
Harald Welte55700662018-03-12 13:15:43 +01001185/* verify that given SACCH payload is not present */
1186private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1187 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001188 timer T_sacch := 3.0;
1189 L1CTL.clear;
1190 T_sacch.start;
1191 alt {
1192 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1193 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1194 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001195 setverdict(fail, "Received unexpected SACCH ", dl);
1196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001197 } else {
1198 repeat;
1199 }
1200 }
1201 [] L1CTL.receive { repeat; }
1202 [] T_sacch.timeout {
1203 setverdict(pass);
1204 }
1205 }
1206}
1207
Harald Welte629cc6b2018-03-11 17:19:05 +01001208/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001209private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1210 /* Set a known default SACCH filling for SI5 */
1211 var octetstring si5 := f_rnd_octstring(19);
1212 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1213
1214 f_l1_tune(L1CTL);
1215 RSL.clear;
1216
1217 /* activate the logical channel */
1218 f_est_dchan();
1219
1220 /* check that the specified SI5 value is actually sent */
1221 f_sacch_present(si5);
1222
1223 /* release the channel */
1224 RSL.clear;
1225 f_rsl_chan_deact();
1226 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1227}
1228testcase TC_sacch_filling() runs on test_CT {
1229 var ConnHdlr vc_conn;
1230 var ConnHdlrPars pars;
1231 f_init();
1232 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1233 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1234 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1235 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1236 vc_conn.done;
1237 }
1238 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001240}
1241
Harald Welte629cc6b2018-03-11 17:19:05 +01001242/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001243private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1244 /* Set a known default SACCH filling for SI5 */
1245 var octetstring si5 := f_rnd_octstring(19);
1246 var octetstring si5_diff := f_rnd_octstring(19);
1247 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1248
1249 f_l1_tune(L1CTL);
1250 RSL.clear;
1251
1252 log("Activating channel, expecting standard SI5");
1253 /* activate the logical channel */
1254 f_est_dchan();
1255 /* check that the specified SI5 value is actually sent */
1256 f_sacch_present(si5);
1257
1258 /* set channel-specific different SI5 */
1259 log("Setting channel specific SACCH INFO, expecting it");
1260 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1261 /* check that the specified lchan-specific value is now used */
1262 f_sacch_present(si5_diff);
1263
1264 /* deactivate the channel and re-activate it, this should result in default SI5 */
1265 log("De-activating and re-activating channel, expecting standard SI5");
1266 f_rsl_chan_deact();
1267 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1268 /* Verify that the TRX-wide default SACCH filling is present again */
1269 f_sacch_present(si5);
1270
1271 /* release the channel */
1272 RSL.clear;
1273 f_rsl_chan_deact();
1274 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1275}
1276testcase TC_sacch_info_mod() runs on test_CT {
1277 var ConnHdlr vc_conn;
1278 var ConnHdlrPars pars;
1279 f_init();
1280 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1281 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1282 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1283 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1284 vc_conn.done;
1285 }
1286 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001288}
1289
Harald Welte075d84c2018-03-12 13:07:24 +01001290/* Test SACCH scheduling of multiple different SI message types */
1291private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1292 var octetstring si5 := f_rnd_octstring(19);
1293 var octetstring si5bis := f_rnd_octstring(19);
1294 var octetstring si5ter := f_rnd_octstring(19);
1295 var octetstring si6 := f_rnd_octstring(19);
1296
1297 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1298 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1300 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1301
1302 f_l1_tune(L1CTL);
1303 RSL.clear;
1304
1305 /* activate the logical channel */
1306 f_est_dchan();
1307 L1CTL.clear;
1308
1309 /* check that SACCH actually are received as expected */
1310 f_sacch_present(si5);
1311 f_sacch_present(si5bis);
1312 f_sacch_present(si5ter);
1313 f_sacch_present(si6);
1314
1315 /* release the channel */
1316 f_rsl_chan_deact();
1317 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1318}
1319testcase TC_sacch_multi() runs on test_CT {
1320 var ConnHdlr vc_conn;
1321 var ConnHdlrPars pars;
1322 f_init();
1323 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1324 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1325 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1326 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1327 vc_conn.done;
1328 }
1329 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001331}
1332
Harald Welte55700662018-03-12 13:15:43 +01001333/* Test if SACH information is modified as expected */
1334private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1335 var octetstring si5 := f_rnd_octstring(19);
1336 var octetstring si6 := f_rnd_octstring(19);
1337
1338 /* First, configure both SI5 and SI6 to be transmitted */
1339 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1340 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1341
1342 f_l1_tune(L1CTL);
1343 RSL.clear;
1344
1345 /* activate the logical channel */
1346 f_est_dchan();
1347 L1CTL.clear;
1348
1349 /* check that SACCH actually are received as expected */
1350 f_sacch_present(si5);
1351 f_sacch_present(si6);
1352
1353 /* disable SI6 */
1354 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1355
1356 /* check that SI5 is still transmitted */
1357 f_sacch_present(si5);
1358 /* check if SI6 is now gone */
1359 f_sacch_missing(si6);
1360
1361 /* release the channel */
1362 f_rsl_chan_deact();
1363 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1364}
1365testcase TC_sacch_multi_chg() runs on test_CT {
1366 var ConnHdlr vc_conn;
1367 var ConnHdlrPars pars;
1368 f_init();
1369 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1370 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1371 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1372 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1373 vc_conn.done;
1374 }
1375 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001377}
1378
Harald Weltec8d363c2019-05-19 20:36:48 +02001379/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1380private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1381 var octetstring si5 := f_rnd_octstring(19);
1382 var octetstring si6 := f_rnd_octstring(19);
1383 var octetstring si5_specific := f_rnd_octstring(19);
1384 var octetstring si6_specific := f_rnd_octstring(19);
1385
1386 /* First, configure both SI5 and SI6 to be transmitted */
1387 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1388 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1389
1390 f_l1_tune(L1CTL);
1391 RSL.clear;
1392
1393 /* activate channel with different SACCH filling */
1394 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1395 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1396 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1397 }));
1398 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1399 RSL_IE_Body:{sacch_info := sacch_info})) };
1400 f_est_dchan(more_ies := addl_ies);
1401
1402 /* check that SACCH actually are received as expected */
1403 f_sacch_present(si5_specific);
1404 f_sacch_present(si6_specific);
1405
1406 /* release the channel */
1407 f_rsl_chan_deact();
1408 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1409}
1410testcase TC_sacch_chan_act() runs on test_CT {
1411 var ConnHdlr vc_conn;
1412 var ConnHdlrPars pars;
1413 f_init();
1414
1415 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1416 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1417 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1418 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1419 vc_conn.done;
1420 }
1421 /* TODO: do the above in parallel, rather than sequentially? */
1422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1423}
1424
Harald Welte8b01c792019-05-19 22:51:25 +02001425/* verify that SACCH DL transmission is started only if MS power IE present
1426 * see section 4.1.3 of 3GPP TS 48.058 */
1427private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1428 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001429 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001430
1431 f_l1_tune(L1CTL);
1432 RSL.clear;
1433
1434 /* Step 1: Activate ASYNC HO channel without MS power IE */
1435
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001436 var integer ho_ref := oct2int(f_rnd_octstring(1));
1437 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1438 RSL_IE_Body:{ handover_ref := ho_ref }));
1439 var RSL_IE_List addl_ies := {
1440 ho_ref_ie
1441 };
1442
Harald Welte8b01c792019-05-19 22:51:25 +02001443 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001444 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001445 /* don't perform immediate assignment here, as we're testing non-IA case */
1446 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001447 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001448
1449 /* Verify that no DL SACCH is being received */
1450 f_sacch_missing(?);
1451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to start */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459
1460
1461 /* Step 2: Activate ASYNC HO channel with MS power IE */
1462
1463 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001464 addl_ies := {
1465 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001466 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1467 };
1468 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1469 /* don't perform immediate assignment here, as we're testing non-IA case */
1470 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001471 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001472
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001473 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1474 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1475 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001476
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001477 /* Send handover Access Burst and expect SACCH to remain present */
1478 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1479
1480 f_sacch_present(si5);
1481
Harald Welte8b01c792019-05-19 22:51:25 +02001482 f_rsl_chan_deact();
1483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1484}
1485testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init();
1489
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001490 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1491 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1492 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001493 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1494 vc_conn.done;
1495 }
1496 /* TODO: do the above in parallel, rather than sequentially? */
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
1499
1500/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1501 * see section 4.1.4 of 3GPP TS 48.058 */
1502private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1503 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001504 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1505
Harald Welte8b01c792019-05-19 22:51:25 +02001506 var RSL_IE_List addl_ies;
1507
1508 f_l1_tune(L1CTL);
1509 RSL.clear;
1510
1511 /* Step 1: Activate SYNC HO channel without MS power IE */
1512
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001513 var integer ho_ref := oct2int(f_rnd_octstring(1));
1514 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1515 RSL_IE_Body:{ handover_ref := ho_ref }));
1516 addl_ies := {
1517 ho_ref_ie
1518 };
1519
Harald Welte8b01c792019-05-19 22:51:25 +02001520 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001521 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001522 /* don't perform immediate assignment here, as we're testing non-IA case */
1523 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001524 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001525
1526 /* Verify that no DL SACCH is being received */
1527 f_sacch_missing(?);
1528
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001529 /* Send handover Access Burst and expect SACCH to start */
1530 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1531
1532 f_sacch_present(si5);
1533
Harald Welte8b01c792019-05-19 22:51:25 +02001534 f_rsl_chan_deact();
1535 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1536
1537
1538 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1539
1540 /* Activate channel on BTS side */
1541 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001542 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001543 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1544 };
1545 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1546 /* don't perform immediate assignment here, as we're testing non-IA case */
1547 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001548 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001549
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001550 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1551 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1552 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001553
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001554 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001555 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1556
1557 f_sacch_present(si5);
1558
Harald Welte8b01c792019-05-19 22:51:25 +02001559 f_rsl_chan_deact();
1560 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1561
1562
1563 /* Step 2b: Activate SYNC HO channel with TA IE */
1564
1565 /* Activate channel on BTS side */
1566 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001567 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001568 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1569 };
1570 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1571 /* don't perform immediate assignment here, as we're testing non-IA case */
1572 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001573 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001574
1575 /* Verify that no DL SACCH is being received */
1576 f_sacch_missing(?);
1577
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001578 /* Send handover Access Burst and expect SACCH to start */
1579 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1580
1581 f_sacch_present(si5);
1582
Harald Welte8b01c792019-05-19 22:51:25 +02001583 f_rsl_chan_deact();
1584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1585
1586
1587 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1588
1589 /* Activate channel on BTS side */
1590 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001591 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001592 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1593 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1594 };
1595 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1596 /* don't perform immediate assignment here, as we're testing non-IA case */
1597 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001598 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001599
1600 /* Verify that DL SACCH is being received */
1601 f_sacch_present(si5);
1602
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001603 /* Send handover Access Burst and expect SACCH to remain present */
1604 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1605
1606 f_sacch_present(si5);
1607
Harald Welte8b01c792019-05-19 22:51:25 +02001608 f_rsl_chan_deact();
1609 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1610}
1611testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1612 var ConnHdlr vc_conn;
1613 var ConnHdlrPars pars;
1614 f_init();
1615
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001616 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1617 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1618 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001619 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1620 vc_conn.done;
1621 }
1622 /* TODO: do the above in parallel, rather than sequentially? */
1623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1624}
Harald Welte629cc6b2018-03-11 17:19:05 +01001625
1626
1627/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001628 * RACH Handling
1629 ***********************************************************************/
1630
Harald Welte8c24c2b2018-02-26 08:31:31 +01001631/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001632private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001633 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001634 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001635 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001636
Harald Welte8c24c2b2018-02-26 08:31:31 +01001637 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001638 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001639 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001640 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001641 if (emerg == true) {
1642 ra := f_rnd_ra_emerg();
1643 } else {
1644 ra := f_rnd_ra_cs();
1645 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001646 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1647 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001649 }
1650 fn_last := fn;
1651
1652 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001653 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001654 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001655 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001656 T.stop;
1657 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001658 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660 }
1661 [] RSL_CCHAN.receive { repeat; }
1662 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001663 test_failed := true;
1664 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001665 }
1666 }
1667 }
Maxba06feb2019-03-05 10:52:46 +01001668 if (test_failed) {
1669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001670 }
Maxba06feb2019-03-05 10:52:46 +01001671 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001673}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001674
Philipp Maier16ade782020-07-08 21:36:00 +02001675/* Normal variant */
1676testcase TC_rach_content() runs on test_CT {
1677 f_TC_rach_content(emerg := false);
1678}
1679
1680/* Emergency call variant */
1681testcase TC_rach_content_emerg() runs on test_CT {
1682 f_TC_rach_content(emerg := true);
1683}
1684
Harald Welte8c24c2b2018-02-26 08:31:31 +01001685/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1686testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001687 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001688 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001689 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001690 f_l1_tune(L1CTL);
1691
1692 var GsmFrameNumber fn_last := 0;
1693 for (var integer i := 0; i < 1000; i := i+1) {
1694 var OCT1 ra := f_rnd_ra_cs();
1695 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1696 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001698 }
1699 fn_last := fn;
1700 }
1701 var integer rsl_chrqd := 0;
1702 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001703 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001704 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001705 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001706 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001707 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001708 repeat;
1709 }
1710 [] RSL_CCHAN.receive { repeat; }
1711 [] T.timeout { }
1712 }
1713 if (rsl_chrqd == 1000) {
1714 setverdict(pass);
1715 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001719}
1720
Harald Welte3453ab42019-05-24 21:19:58 +02001721private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1722 var charstring bts_str := "bts " & int2str(bts_nr);
1723 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1724}
1725
1726/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1727private template integer tr_rach_slots_per_interval := (90 .. 130);
1728
1729/* Expect 0 RACH load on an idle BTS that has just started up */
1730testcase TC_rach_load_idle_thresh0() runs on test_CT {
1731 var ASP_RSL_Unitdata rx_ud;
1732
1733 f_init_vty_bsc();
1734 /* send load indications even at 0% load */
1735 f_vty_load_ind_thresh(0);
1736 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1737 f_sleep(2.0);
1738
1739 f_init();
1740
Harald Weltee37f9a52020-10-11 20:45:23 +02001741 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1742 alt {
1743 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1744 [] RSL_CCHAN.receive { repeat }
1745 }
1746
Harald Welte3453ab42019-05-24 21:19:58 +02001747 timer T := 5.0;
1748 T.start;
1749 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001750 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001751 setverdict(pass);
1752 repeat;
1753 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001754 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001755 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1756 repeat;
1757 }
1758 [] RSL_CCHAN.receive {
1759 repeat;
1760 }
1761 [] T.timeout { }
1762 }
1763
1764 f_vty_load_ind_thresh(10);
1765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1766}
1767
1768/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1769testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1770 var ASP_RSL_Unitdata rx_ud;
1771
1772 f_init_vty_bsc();
1773 f_init();
1774
1775 timer T := 5.0;
1776 T.start;
1777 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001778 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001779 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1780 repeat;
1781 }
1782 [] RSL_CCHAN.receive {
1783 repeat;
1784 }
1785 [] T.timeout {
1786 setverdict(pass);
1787 }
1788 }
1789
1790 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1791}
1792
1793/* Expect 0 RACH load on an idle BTS that has just started up */
1794testcase TC_rach_load_count() runs on test_CT {
1795 var ASP_RSL_Unitdata rx_ud;
1796 var integer load_access_count := 0;
1797
1798 f_init_vty_bsc();
1799 /* send load indications even at 0% load */
1800 f_vty_load_ind_thresh(0);
1801 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1802 f_sleep(2.0);
1803 f_init();
1804
1805 f_init_l1ctl();
1806 f_sleep(1.0);
1807 f_l1_tune(L1CTL);
1808
Harald Welte52ae1682020-10-11 20:45:55 +02001809 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1810 alt {
1811 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1812 [] RSL_CCHAN.receive { repeat }
1813 }
1814
Harald Welte3453ab42019-05-24 21:19:58 +02001815 var GsmFrameNumber fn_last := 0;
1816 for (var integer i := 0; i < 1000; i := i+1) {
1817 var OCT1 ra := f_rnd_ra_cs();
1818 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1819 if (fn == fn_last) {
1820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1821 }
1822 fn_last := fn;
1823 }
1824
1825 timer T := 5.0;
1826 T.start;
1827 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001828 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001829 -> value rx_ud {
1830 var RSL_IE_Body ie;
1831 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1832 load_access_count := load_access_count + ie.rach_load.access_count;
1833 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1834 setverdict(fail, "Access count cannot be < Busy count");
1835 }
1836 repeat;
1837 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001838 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001839 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1840 repeat;
1841 }
1842 [] RSL_CCHAN.receive {
1843 repeat;
1844 }
1845 [] T.timeout { }
1846 }
1847 if (load_access_count == 1000) {
1848 setverdict(pass);
1849 } else {
1850 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1851 }
1852
1853 f_vty_load_ind_thresh(10);
1854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1855}
1856
Harald Welte54a2a2d2018-02-26 09:14:05 +01001857private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001858 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001859 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001860 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001861 f_sleep(0.5);
1862
1863 /* Transmit RACH request + wait for confirmation */
1864 var OCT1 ra := f_rnd_ra_cs();
1865 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1866
1867 /* Check for expected result */
1868 timer T := 1.5;
1869 T.start;
1870 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001871 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001872 setverdict(pass);
1873 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001874 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001876 }
1877 [] RSL_CCHAN.receive { repeat; }
1878 [not expect_pass] T.timeout {
1879 setverdict(pass);
1880 }
1881 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001883 }
1884 }
1885}
1886
1887/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1888testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001889 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001890 f_init_l1ctl();
1891 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001892 f_sleep(1.0);
1893
1894 /* default max-ta is 63 (full range of GSM timing advance */
1895
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001896 /* We allow early arrival up to 2 symbols */
1897 f_rach_toffs(-1*256, true);
1898 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001899 f_rach_toffs(-10*256, false);
1900
1901 /* 0 / 32 / 63 bits is legal / permitted */
1902 f_rach_toffs(0, true);
1903 f_rach_toffs(32*256, true);
1904 f_rach_toffs(63*256, true);
1905
1906 /* more than 63 bits is not legal / permitted */
1907 f_rach_toffs(64*256, false);
1908 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001910}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001911
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001912private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001913 var GsmFrameNumber fn;
1914 var RSL_Message rm;
1915
1916 f_l1_tune(L1CTL);
1917 RSL.clear;
1918
1919 /* Generate a random Handover Reference */
1920 var integer ho_ref := oct2int(f_rnd_octstring(1));
1921
1922 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1923 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1924 RSL_IE_Body:{ handover_ref := ho_ref }));
1925
1926 /* Activate a channel on the BTS side (no encryption) */
1927 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1928 act_type := t_RSL_IE_ActType_HO_SYNC);
1929
1930 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1931 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001932 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001933
1934 /* Send handover Access Burst */
1935 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1936
1937 /* TODO: test mismatching Handover Reference, and missing IE */
1938
1939 /* Wait for handover detection */
1940 timer T := 3.0;
1941 T.start;
1942 alt {
1943 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1944 log("Handover RACH has been detected: ", rm);
1945 setverdict(pass);
1946 }
1947 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1949 log2str("RSL_CHAN_RQD was not expected: ", rm));
1950 }
1951 [] RSL.receive { repeat; }
1952 [] T.timeout {
1953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1954 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1955 }
1956 }
1957
1958 /* Release the channel */
1959 f_rsl_chan_deact();
1960 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1961}
1962
1963/* Test handover RACH detection */
1964testcase TC_ho_rach() runs on test_CT {
1965 var ConnHdlrPars pars;
1966 var ConnHdlr vc_conn;
1967
1968 f_init();
1969
1970 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1971 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1972 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1973 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1974 vc_conn.done;
1975 }
1976
1977 /* TODO: do the above in parallel, rather than sequentially? */
1978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1979}
1980
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001981/* Test sending of the RR Physical Information message on DCCH */
1982private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1983 var PDU_ML3_NW_MS dcch_pdu;
1984 var integer count := 0;
1985 var L1ctlDlMessage dl;
1986 timer T;
1987
1988 f_l1_tune(L1CTL);
1989 RSL.clear;
1990
1991 /* Generate a random Handover Reference */
1992 var integer ho_ref := oct2int(f_rnd_octstring(1));
1993
1994 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1995 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1996 RSL_IE_Body:{ handover_ref := ho_ref }));
1997
1998 /* Activate a channel on the BTS side (no encryption) */
1999 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2000 act_type := t_RSL_IE_ActType_HO_SYNC);
2001
2002 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2003 * waiting for Immediate Assignment and sending of an Access Burst. */
2004 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2005
2006 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2007 * context means any L2 frames, not only the RR Physical Information. */
2008 T.start(2.0);
2009 L1CTL.clear;
2010 alt {
2011 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2012 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2013 T.stop;
2014 }
2015 [] L1CTL.receive { repeat; }
2016 [] T.timeout { setverdict(pass); }
2017 }
2018
2019 /* Send handover Access Burst */
2020 log("Sending handover Access Burst");
2021 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2022
2023 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2024 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2025 L1CTL.clear;
2026 alt {
2027 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2028 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2029 log("Rx RR Physical Information: ", dcch_pdu);
2030 /* Wait until the count reaches Ny1 */
2031 count := count + 1;
2032 if (count < mp_ho_ny1)
2033 { repeat; }
2034 setverdict(pass);
2035 }
2036 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2037 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2039 }
2040 [] L1CTL.receive { repeat; }
2041 [] T.timeout {
2042 setverdict(fail, "Timeout waiting for RR Physical Information");
2043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2044 }
2045 }
2046
2047 /* Release the channel */
2048 f_rsl_chan_deact();
2049 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2050}
2051testcase TC_ho_physical_info() runs on test_CT {
2052 var ConnHdlrPars pars;
2053 var ConnHdlr vc_conn;
2054
2055 f_init();
2056
2057 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2058 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2059 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2060 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2061 vc_conn.done;
2062 }
2063
2064 /* TODO: do the above in parallel, rather than sequentially? */
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066}
2067
Harald Welte93640c62018-02-25 16:59:33 +01002068/***********************************************************************
2069 * Measurement Processing / Reporting
2070 ***********************************************************************/
2071
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002072private template (value) LapdmAddressField
2073ts_LapdmAddr(template (value) LapdmSapi sapi,
2074 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002075 spare := '0'B,
2076 lpd := 0,
2077 sapi := sapi,
2078 c_r := c_r,
2079 ea := true
2080}
2081
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002082private template (value) LapdmFrameAB
2083ts_LAPDm_AB(template (value) LapdmSapi sapi,
2084 template (value) GsmRrL3Message l3,
2085 template (value) boolean c_r := false,
2086 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002087 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002088 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002089 len := 0, /* overwritten */
2090 m := false,
2091 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002092 payload := enc_GsmRrL3Message(valueof(l3)),
2093 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002094}
2095
2096/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002097private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002098 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002099 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002100
Harald Weltef8df4cb2018-03-10 15:15:08 +01002101 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002102 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002103
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002104 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002105 g_pars.l1_pars.meas_ul.full.rxlev,
2106 g_pars.l1_pars.meas_ul.sub.rxlev,
2107 g_pars.l1_pars.meas_ul.full.rxqual,
2108 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002109 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002110
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002111 var template (value) SacchL1Header l1h := ts_SacchL1Header(
2112 g_pars.l1_pars.ms_power_level, false,
2113 g_pars.l1_pars.ms_actual_ta);
2114
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002115 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2116 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002117
2118 log("Sending Measurement Report: ", l1h, l2);
2119 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002120 repeat;
2121 }
2122}
2123
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002124/* handle incoming downlink SACCH, decode the L1 header into the given record */
2125private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2126 boolean do_apply := true)
2127runs on ConnHdlr
2128{
2129 var L1ctlDlMessage l1_dl;
2130
2131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2132 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2133 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2134 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2135
2136 if (do_apply) {
2137 /* Update TA and MS power to follow what BTS requests */
2138 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2139 }
2140 }
2141}
2142
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002143private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002144 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002146 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2147 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002148 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2149 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002150 repeat;
2151 }
2152}
2153
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002154private altstep as_l1_tch_loop() runs on ConnHdlr {
2155 var L1ctlDlMessage l1_dl;
2156 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2157 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002158
2159 /* occasionaly inject FACCH frames into the uplink */
2160 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2161 var octetstring pl := '010301'O;
2162 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2163 f_pad_oct(pl, 23, '2B'O)));
2164 } else {
2165 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2166 l1_dl.payload.traffic_ind.data));
2167 }
2168
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002169 repeat;
2170 }
2171}
2172
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002173private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002174 uint6_t rxlev,
2175 uint3_t rxqual
2176}
2177
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002178private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002179 MeasElem full,
2180 MeasElem sub
2181}
2182
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002183private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002184 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002185 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002186 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002187 MeasElemFS meas_ul,
2188 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002189 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002190 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002191 uint8_t ms_actual_ta,
2192 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002193}
2194
2195/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2196private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2197 return 63 + (toffs256s/256);
2198}
2199
Harald Welted5684392018-03-10 18:22:04 +01002200private function f_max(integer a, integer b) return integer {
2201 if (a > b) {
2202 return a;
2203 } else {
2204 return b;
2205 }
2206}
2207
2208private function f_min(integer a, integer b) return integer {
2209 if (a < b) {
2210 return a;
2211 } else {
2212 return b;
2213 }
2214}
2215
2216/* compute negative tolerance val-tolerance, ensure >= min */
2217private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2218 val := val - tolerance;
2219 return f_max(val, min);
2220}
2221
2222/* compute positive tolerance val+tolerance, ensure <= max */
2223private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2224 val := val + tolerance;
2225 return f_min(val, max);
2226}
2227
2228/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2229private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2230return template integer {
2231 var template integer ret;
2232 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2233 return ret;
2234}
2235
2236
Harald Welte70767382018-02-21 12:16:40 +01002237/* build a template for matching measurement results against */
2238private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2239 var ConnL1Pars l1p := g_pars.l1_pars;
2240 var template RSL_IE_UplinkMeas ul_meas := {
2241 len := 3,
2242 rfu := '0'B,
2243 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002244 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002245 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002246 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002247 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002248 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2249 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002250 supp_meas_info := omit
2251 };
Harald Welte685d5982018-02-27 20:42:05 +01002252 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002253 ul_meas.len := (3+8);
2254 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002255 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002256 toa256_min := ?,
2257 toa256_max := ?,
2258 toa256_std_dev := ?
2259 }
Harald Welte685d5982018-02-27 20:42:05 +01002260 }
Harald Welte70767382018-02-21 12:16:40 +01002261 var template RSL_IE_BS_Power bs_power := {
2262 reserved := 0,
2263 epc := false,
2264 fpc := false,
2265 power_level := l1p.bs_power_level
2266 };
2267 var template RSL_IE_L1Info l1_info := {
2268 ms_power_lvl := l1p.ms_power_level,
2269 fpc := false,
2270 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002271 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002272 };
2273 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002274 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002275 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2276 ?, t_toffs);
2277}
2278
Philipp Maierdd841d32019-12-17 14:44:54 +01002279/* build a template for matching measurement results that do not contain any
2280 * MS related measurement (l1_info, l3_info and ms timing offset). */
2281private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2282 var ConnL1Pars l1p := g_pars.l1_pars;
2283 var template RSL_IE_UplinkMeas ul_meas := {
2284 len := 3,
2285 rfu := '0'B,
2286 dtx_d := l1p.dtx_enabled,
2287 rxlev_f_u := ?,
2288 reserved1 := '00'B,
2289 rxlev_s_u := ?,
2290 reserved2 := '00'B,
2291 rxq_f_u := ?,
2292 rxq_s_u := ?,
2293 supp_meas_info := omit
2294 };
2295 if (l1p.toa256_enabled) {
2296 ul_meas.len := (3+8);
2297 ul_meas.supp_meas_info := {
2298 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2299 toa256_min := ?,
2300 toa256_max := ?,
2301 toa256_std_dev := ?
2302 }
2303 }
2304 var template RSL_IE_BS_Power bs_power := {
2305 reserved := 0,
2306 epc := false,
2307 fpc := false,
2308 power_level := l1p.bs_power_level
2309 };
2310
2311 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2312}
2313
Harald Welte70767382018-02-21 12:16:40 +01002314/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002315private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002316 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002317 var boolean chan_est := false;
2318
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002319 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002320
2321 /* Receive osmocom specific measurement reports. This is the normal
2322 * case. Here we verify that the measurement reports we sent are
2323 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002324 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2325 /* increment counter of next to-be-expected meas rep */
2326 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2327 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002328 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002329
2330 /* The following two cases may only happen in the beginning
2331 * of the channel establishment phase. Once we have received
2332 * the "our" measurement report the first time, the channel
2333 * is established and empty or hardcoded TRXCON reports must
2334 * not occur anymore. */
2335 chan_est := true;
2336
2337 repeat;
2338 }
2339
2340 /* When the BTS has established the channel, the MS might need slightly
2341 * more time to establish the channel and actually start sending. The
2342 * result is then a measurement report that just lacks the measurement
2343 * information of the MS. This is normal and we tolerate this behavior. */
2344 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2345 /* increment counter of next to-be-expected meas rep */
2346 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2347 /* Re-start the timer expecting the next MEAS RES */
2348 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002349 repeat;
2350 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002351
2352 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2353 * measurements if the TTCN3 side does not supply measurement input in
2354 * time. In those cases TRXCON will either use a cached measurement
2355 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2356 * report the templates above will not match. We tolerate this
2357 * behavior, but only once. */
2358 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01002359 /* increment counter of next to-be-expected meas rep */
2360 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2361 if (g_first_meas_res) {
2362 g_first_meas_res := false;
2363 repeat;
2364 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002366 }
Harald Welte70767382018-02-21 12:16:40 +01002367 }
2368 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002370 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002371 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002373 }
2374}
2375
Harald Weltee613f962018-04-18 22:38:16 +02002376private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2377 select (rsl_alg_id) {
2378 case (RSL_ALG_ID_A5_0) { return 0; }
2379 case (RSL_ALG_ID_A5_1) { return 1; }
2380 case (RSL_ALG_ID_A5_2) { return 2; }
2381 case (RSL_ALG_ID_A5_3) { return 3; }
2382 case (RSL_ALG_ID_A5_4) { return 4; }
2383 case (RSL_ALG_ID_A5_5) { return 5; }
2384 case (RSL_ALG_ID_A5_6) { return 6; }
2385 case (RSL_ALG_ID_A5_7) { return 7; }
2386 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2388 /* Make compiler happy by calling mtc.stop here. It is already
2389 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002390 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002391 }
2392 }
2393}
2394
2395private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2396 select (rsl_alg_id) {
2397 case (RSL_ALG_ID_A5_1) { return '000'B; }
2398 case (RSL_ALG_ID_A5_2) { return '001'B; }
2399 case (RSL_ALG_ID_A5_3) { return '010'B; }
2400 case (RSL_ALG_ID_A5_4) { return '011'B; }
2401 case (RSL_ALG_ID_A5_5) { return '100'B; }
2402 case (RSL_ALG_ID_A5_6) { return '101'B; }
2403 case (RSL_ALG_ID_A5_7) { return '110'B; }
2404 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2406 /* Make compiler happy by calling mtc.stop here. It is already
2407 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002408 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002409 }
2410 }
2411}
2412
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002413/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2414private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2415 var GsmFrameNumber fn;
2416 timer T := 8.0;
2417
2418 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2419 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2420
2421 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2422 /* Send the actual RACH */
2423 fn := f_L1CTL_RACH(L1CTL, ra);
2424
2425 T.start;
2426 alt {
2427 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2428 [] T.timeout {
2429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2430 }
2431 }
2432 T.stop
2433 return fn;
2434}
Harald Weltee613f962018-04-18 22:38:16 +02002435
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002436/* Tune to a dedicated channel: L1CTL only */
2437private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002438 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002439 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002440 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002441 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002442 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002443 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002444 pars.fhp.maio_hsn.hsn,
2445 pars.fhp.maio_hsn.maio,
2446 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002447 }
2448}
2449
Harald Welte70767382018-02-21 12:16:40 +01002450/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002451private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002452 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002453
2454 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002455 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002456
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002457 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002458 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002459 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002460 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002461 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2462 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002463 }
2464
Harald Welte70767382018-02-21 12:16:40 +01002465 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002466 f_l1ctl_est_dchan(L1CTL, g_pars);
2467
Harald Weltee613f962018-04-18 22:38:16 +02002468 /* enable encryption, if requested */
2469 if (encr_enable) {
2470 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2471 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2472 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002473
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002474 /* Send TCH Mode Request to the L1 if needed */
2475 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2476 var L1ctlTchMode tch_mode;
2477
2478 select (g_pars.chan_mode.coding_alg_rate) {
2479 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2480 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2481 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2482 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2483 case else {
2484 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2485 " is not supported by the L1, falling back to signalling");
2486 tch_mode := L1CTL_CHAN_MODE_SIGN;
2487 }
2488 }
2489
2490 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2491 }
2492
Harald Weltefa45e9e2018-03-10 18:59:03 +01002493 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002494}
2495
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002496/* Initialize and start the RTP emulation component for a ConnHdlr */
2497friend function f_rtpem_activate(inout octetstring payload,
2498 RtpemConfig cfg := c_RtpemDefaultCfg,
2499 RtpemMode mode := RTPEM_MODE_BIDIR)
2500runs on ConnHdlr {
2501 /* Step 0: initialize, connect and start the emulation component */
2502 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2503 map(vc_RTPEM:RTP, system:RTP);
2504 map(vc_RTPEM:RTCP, system:RTCP);
2505 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2506 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2507 vc_RTPEM.start(RTP_Emulation.f_main());
2508
2509 /* Step 1: configure the RTP parameters */
2510 var integer payload_len := 0;
2511 var octetstring hdr := ''O;
2512
2513 select (g_pars.chan_mode) {
2514 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2515 { payload_len := 33; hdr := 'D0'O; }
2516 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2517 { payload_len := 15; hdr := '00'O; }
2518 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2519 { payload_len := 31; hdr := 'C0'O; }
2520 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2521 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2523 }
2524 }
2525
2526 /* Pad the payload to conform the expected length */
2527 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2528 cfg.tx_fixed_payload := payload;
2529 f_rtpem_configure(RTPEM_CTRL, cfg);
2530
2531 /* Step 2: bind the RTP emulation to the configured address */
2532 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2533 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2534
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002535 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2536 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2537 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2538 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2539 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002540 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2541 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002542 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002543
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002544 /* Step 3b: send MDCX with the configured address/port to the IUT */
2545 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2546 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2547 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2548 remote_port := rtpem_bind_port,
2549 rtp_pt2 := 0),
2550 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2551 "IPA MDCX ACK");
2552
2553 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2554 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2555 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2556 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002557
2558 /* Step 5: set the given RTP emulation mode */
2559 f_rtpem_mode(RTPEM_CTRL, mode);
2560}
2561
Harald Welte70767382018-02-21 12:16:40 +01002562/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002563private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002564 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002565 RSL.clear;
2566
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002567 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002568 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002569 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002570 }
Harald Welte70767382018-02-21 12:16:40 +01002571
2572 f_est_dchan();
2573
2574 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2575 * RSL measurement reports on Abis side */
2576 timer T := 8.0;
2577 T.start;
2578 alt {
2579 [] as_l1_sacch();
2580 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002581 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002582 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002583 [] L1CTL.receive { repeat; }
2584 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002585 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002586 * of any earlier errors, so if we reach this timeout, we're good */
2587 setverdict(pass);
2588 }
2589 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002591 }
2592 }
2593 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002594 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002595}
Harald Welte0472ab42018-03-12 15:02:26 +01002596
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002597/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2598private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002599 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002600 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2601 timer Tup := 10.0;
2602 Tup.start;
2603 alt {
2604 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2605 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2606 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002607
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002608 if (rx_lvl != max_rx_lvl) {
2609 repeat;
2610 }
2611 Tup.stop;
2612 }
2613 [] L1CTL.receive { repeat; }
2614 [] Tup.timeout {
2615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2616 log2str("Didn't reach full power ", max_rx_lvl));
2617 }
2618 }
2619 return max_rx_lvl;
2620}
2621
2622/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2623private function f_verify_ramp_up() runs on ConnHdlr {
2624 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002625 var integer initial_rx_lvl := -1;
2626 var integer last_rx_lvl := -1;
2627 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2628
2629 timer T := 2.0;
2630 alt {
2631 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2632 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2633 log("Received rx_level=", rx_lvl);
2634 if (initial_rx_lvl == -1) {
2635 initial_rx_lvl := rx_lvl;
2636 last_rx_lvl := rx_lvl;
2637
2638 /* Expect a somehow low value during first received messages */
2639 if (initial_rx_lvl >= max_rx_lvl / 2) {
2640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2641 log2str("Detected high initial tx power during ramp up: ",
2642 initial_rx_lvl , ", full power is", max_rx_lvl));
2643 }
2644 }
2645
2646 /* received Rx level bigger than maximum allowed power by CN */
2647 if (rx_lvl > max_rx_lvl) {
2648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2649 log2str("Detected Tx power higher than full power: ",
2650 rx_lvl , " > ", max_rx_lvl));
2651 }
2652
2653 /* Make sure it never decreases, since we are rumping up */
2654 if (last_rx_lvl > rx_lvl) {
2655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2656 log2str("Detected Tx power decrease during ramp up: ",
2657 last_rx_lvl , " -> ", rx_lvl));
2658 }
2659
2660 if (rx_lvl == max_rx_lvl and not T.running) {
2661 /* We reached the maximum power, start timer and receive
2662 /* a few more to make sure we don't surpass it */
2663 log("Reached full power, wating a bit more until success");
2664 T.start;
2665 }
2666
2667 last_rx_lvl := rx_lvl;
2668 repeat;
2669 }
2670 [] L1CTL.receive { repeat; }
2671 [] T.timeout { }
2672 }
2673
2674 /* We didn't increase tx power during ramp up */
2675 if (initial_rx_lvl < last_rx_lvl) {
2676 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2677 } else {
2678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2679 log2str("No Tx power increase during whole ramp up: ",
2680 initial_rx_lvl , " -> ", last_rx_lvl));
2681 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002682}
2683
2684/* verify BTS ramps power down to rx_level 0 */
2685private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2686 var L1ctlDlMessage l1_dl;
2687 var integer last_rx_lvl := max_rx_lvl;
2688
2689 timer Tdown := 5.0;
2690 Tdown.start;
2691 alt {
2692 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2693 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2694 log("Received rx_level=", rx_lvl);
2695
2696 /* received Rx level bigger than maximum allowed power by CN */
2697 if (rx_lvl > max_rx_lvl) {
2698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2699 log2str("Detected Tx power higher than full power: ",
2700 rx_lvl , " > ", max_rx_lvl));
2701 }
2702
2703 /* Make sure it never increases, since we are rumping down */
2704 if (last_rx_lvl < rx_lvl) {
2705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2706 log2str("Detected Tx power increase during ramp up: ",
2707 last_rx_lvl , " -> ", rx_lvl));
2708 }
2709
2710 last_rx_lvl := rx_lvl;
2711 if (last_rx_lvl != 0) {
2712 repeat;
2713 }
2714 /* we reached power level 0, we are done */
2715 Tdown.stop;
2716 }
2717 [] L1CTL.receive { repeat; }
2718 [] Tdown.timeout { }
2719 }
2720
2721 /* We didn't increase tx power during ramp down */
2722 if (max_rx_lvl > last_rx_lvl) {
2723 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2724 } else {
2725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2726 log2str("No Tx power decrease during whole ramp down: ",
2727 max_rx_lvl , " -> ", last_rx_lvl));
2728 }
2729}
2730
2731/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002732private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002733 f_l1_tune(L1CTL);
2734 RSL.clear;
2735
2736 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002737
2738 setverdict(pass);
2739}
2740testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2741 var ConnHdlr vc_conn;
2742 var ConnHdlrPars pars;
2743 f_init();
2744 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2745 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2746 pcu_comp := false, trxc_comp := true);
2747 vc_conn.done;
2748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2749}
2750
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002751/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002752private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002753 f_connhdlr_init_vty_bsc();
2754
2755 f_l1_tune(L1CTL);
2756 RSL.clear;
2757
2758 /* Wait until BTS is started and at full power */
2759 var integer max_rx_lvl := f_wait_ramp_up();
2760 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2761
2762 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2763 f_verify_ramp_down(max_rx_lvl);
2764
2765 setverdict(pass);
2766}
2767testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2768 var ConnHdlr vc_conn;
2769 var ConnHdlrPars pars;
2770 f_init();
2771 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2772 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2773 pcu_comp := false, trxc_comp := true);
2774 vc_conn.done;
2775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2776}
2777
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002778/* Verify Tx power:
2779 * + ramping down during ADM state UNLOCKED->LOCKED
2780 * + ramping up during ADM state LOCKED->UNLOCKED
2781 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002782private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002783 var L1ctlDlMessage l1_dl;
2784 var integer last_rx_lvl;
2785
2786 f_connhdlr_init_vty_bsc();
2787
2788 f_l1_tune(L1CTL);
2789 RSL.clear;
2790
2791 /* Wait until BTS is started and at full power */
2792 var integer max_rx_lvl := f_wait_ramp_up();
2793 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2794
2795 log("ADM STATE UNLOCKED->LOCKED");
2796 f_vty_enter_cfg_trx(BSCVTY);
2797 f_vty_transceive(BSCVTY, "rf_locked 1");
2798 last_rx_lvl := max_rx_lvl;
2799 f_verify_ramp_down(max_rx_lvl);
2800
2801 /* Let some time after we received 0dBm, then check we don't receive BCCH
2802 * anymore because scheduler has stopped after ramping down */
2803 f_sleep(2.0);
2804 L1CTL.clear;
2805 timer Tlocked := 2.0;
2806 Tlocked.start;
2807 alt {
2808 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2810 log2str("Received data_ind during rf_locked: ", l1_dl));
2811 }
2812 [] L1CTL.receive { repeat; }
2813 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2814 }
2815
2816 log("ADM STATE LOCKED->UNLOCKED");
2817 f_vty_transceive(BSCVTY, "rf_locked 0");
2818 f_verify_ramp_up();
2819 setverdict(pass);
2820}
2821testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2822 var ConnHdlr vc_conn;
2823 var ConnHdlrPars pars;
2824 f_init();
2825 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2826 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2827 pcu_comp := false, trxc_comp := true);
2828 vc_conn.done;
2829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2830}
2831
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002832private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002833 timer T := 8.0;
2834 T.start;
2835 var RSL_Message rsl;
2836 alt {
2837 [] as_l1_sacch();
2838 [] L1CTL.receive { repeat; }
2839 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2840 if (rsl.ies[3].body.bs_power.power_level == level) {
2841 setverdict(pass)
2842 } else {
2843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2844 }
2845 }
2846 [] T.timeout {
2847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2848 }
2849 }
2850}
2851
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002852/* See if the RSL MEASurement RESult contains expeced BS power level
2853 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002854private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002855 f_l1_tune(L1CTL);
2856 RSL.clear;
2857
2858 if (mp_bts_trxc_port != -1) {
2859 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2860 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2861 }
2862
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002863 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002864 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2865 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2866
2867 f_est_dchan(more_ies :={valueof(pwr)});
2868
2869 f_check_meas_bs_power_level(pwr_var);
2870
2871 f_rsl_chan_deact();
2872 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2873}
2874
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002875/* See if the RSL MEASurement RESult contains expeced BS power level
2876 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002877private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002878 f_l1_tune(L1CTL);
2879 RSL.clear;
2880
2881 if (mp_bts_trxc_port != -1) {
2882 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2883 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2884 }
2885
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002886 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002887 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2888
2889 f_est_dchan();
2890
2891 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2892
2893 f_check_meas_bs_power_level(pwr_var);
2894
2895 f_rsl_chan_deact();
2896 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2897}
2898
2899testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2900 var ConnHdlr vc_conn;
2901 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002902
Eric Wildae8f2622019-06-18 17:05:11 +02002903 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002904
2905 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2906 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2907 pcu_comp := false, trxc_comp := true);
2908 vc_conn.done;
2909
Eric Wildae8f2622019-06-18 17:05:11 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2911}
2912
2913testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2914 var ConnHdlr vc_conn;
2915 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002916
Eric Wildae8f2622019-06-18 17:05:11 +02002917 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002918
2919 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2920 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2921 pcu_comp := false, trxc_comp := true);
2922 vc_conn.done;
2923
Eric Wildae8f2622019-06-18 17:05:11 +02002924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2925}
2926
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002927/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2928 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2929 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002930private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002931 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002932 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002933
2934 f_trxc_fake_rssi(rxlev2dbm(10));
2935 f_l1_tune(L1CTL);
2936 RSL.clear;
2937
2938 var RSL_IE_List addl_ies;
2939 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2940
2941 addl_ies := {
2942 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2943 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2944 };
2945
2946 /* establish with power parameters */
2947 f_est_dchan(more_ies := addl_ies);
2948
2949 /* set a high value to ensure L1 power control level increases */
2950 f_trxc_fake_rssi(rxlev2dbm(20));
2951
2952 timer T2 := 6.0;
2953 T2.start;
2954 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002955 [] as_l1_sacch_l1h(l1h) {
2956 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002957 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002958 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002959 T2.stop;
2960 }
2961 [] L1CTL.receive { repeat; }
2962 [] T2.timeout {
2963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2964 "Power Level in L1 header has not increased sufficiently");
2965 }
2966 }
2967
2968 /* set a low value to ensure L1 power control level decreases */
2969 f_trxc_fake_rssi(rxlev2dbm(0));
2970
2971 timer T4 := 6.0;
2972 T4.start;
2973 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002974 [] as_l1_sacch_l1h(l1h) {
2975 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002976 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002977 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002978 T4.stop;
2979 setverdict(pass, "Power level in L1 decreased/increased as expected");
2980 }
2981 [] L1CTL.receive { repeat; }
2982 [] T4.timeout {
2983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2984 "Power Level in L1 header has not decreased sufficiently");
2985 }
2986 }
2987
2988 f_rsl_chan_deact();
2989 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2990
2991}
2992
2993/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002994private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002995 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002996 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002997
2998 /* set a low value to ensure power increases */
2999 f_trxc_fake_rssi(rxlev2dbm(10));
3000 f_l1_tune(L1CTL);
3001 RSL.clear;
3002
3003 var RSL_IE_List addl_ies;
3004 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3005
3006 addl_ies := {
3007 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3008 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3009 };
3010
3011 /* establish with power parameters */
3012 f_est_dchan(more_ies := addl_ies);
3013
3014 timer T1 := 10.0;
3015 T1.start;
3016 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003017 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003018 [] L1CTL.receive { repeat; }
3019 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003020 if (not isbound(l1h)) {
3021 setverdict(fail, "No SACCH blocks were received");
3022 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003023 setverdict(fail, "Power level in L1 header should not have changed");
3024 }
3025 }
3026 }
3027
3028 f_rsl_chan_deact();
3029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3030
3031}
3032
3033/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003034private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003035 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003036 var uint5_t pwr_var := 15;
3037 var uint5_t pwr_max_var := f_get_max_power_from_band();
3038
3039 /* set a low value to ensure power increases */
3040 f_trxc_fake_rssi(rxlev2dbm(10));
3041 f_l1_tune(L1CTL);
3042 RSL.clear;
3043
3044 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3045 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3046
3047 /* establish with fixed power level */
3048 f_est_dchan(more_ies :={valueof(pwr)});
3049
3050 /* check our initial power level */
3051 f_wait_for_l1_power_level(pwr_var);
3052
3053 /* update power param to enable power loop
3054 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3055 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3056
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003057 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3058 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3059 * Add an extra offset to avoid race conditions: +1.92s. */
3060 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003061 T1.start;
3062 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003063 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003064 [] L1CTL.receive { repeat; }
3065 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003066 if (not isbound(l1h)) {
3067 setverdict(fail, "No SACCH blocks were received");
3068 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003069 setverdict(pass, "Power level in L1 header reduced as expected");
3070 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003071 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3072 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003073 }
3074 }
3075 }
3076
3077 f_rsl_chan_deact();
3078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3079
3080}
3081
3082/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003083private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003084 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003085
3086 /* set a high value to ensure power decreases */
3087 f_trxc_fake_rssi(rxlev2dbm(50));
3088 f_l1_tune(L1CTL);
3089 RSL.clear;
3090
3091 var uint5_t pwr_var := 5;
3092 var uint5_t pwr_target_val := 15;
3093
3094 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3095 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3096
3097 /* establish with fixed power level */
3098 f_est_dchan(more_ies :={valueof(pwr)});
3099
3100 /* check our initial power level */
3101 f_wait_for_l1_power_level(pwr_var);
3102
3103 /* update power param to enable power loop
3104 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003105 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003106
3107 /* wait, then check that our power level was increased */
3108 timer T1 := 10.0;
3109 T1.start;
3110 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003111 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003112 [] L1CTL.receive { repeat; }
3113 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003114 if (not isbound(l1h)) {
3115 setverdict(fail, "No SACCH blocks were received");
3116 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3117 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003118 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003119 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003120 }
3121 }
3122 }
3123
3124 f_rsl_chan_deact();
3125 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3126
3127}
3128
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003129/* See if the power level remains constant when MS Power Parameters IE
3130 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003131private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003132 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003133
3134 /* set a high value to ensure power decreases */
3135 f_trxc_fake_rssi(rxlev2dbm(50));
3136 f_l1_tune(L1CTL);
3137 RSL.clear;
3138
3139 var uint5_t pwr_var := 5;
3140
3141 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3142 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3143
3144 /* establish with fixed power level */
3145 f_est_dchan(more_ies :={valueof(pwr)});
3146
3147 /* check our initial power level */
3148 f_wait_for_l1_power_level(pwr_var);
3149
3150 /* wait, then check that our power level did not change */
3151 timer T1 := 10.0;
3152 T1.start;
3153 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003154 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3155 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3157 "BS power control should not be active unless we receive a power parameters IE!");
3158 }
3159 repeat;
3160 }
3161 [] L1CTL.receive { repeat; }
3162 [] T1.timeout { setverdict(pass); }
3163 }
3164
3165 f_rsl_chan_deact();
3166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3167
3168}
3169
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003170/* See if the power level remains constant when MS Power Parameters IE
3171 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003172private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003173 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003174
3175 /* set a high value to ensure power decreases */
3176 f_trxc_fake_rssi(rxlev2dbm(50));
3177 f_l1_tune(L1CTL);
3178 RSL.clear;
3179
3180 var uint5_t pwr_var := 5;
3181
3182 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3183 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3184
3185 /* establish with fixed power level */
3186 f_est_dchan(more_ies :={valueof(pwr)});
3187
3188 /* check our initial power level */
3189 f_wait_for_l1_power_level(pwr_var);
3190
3191 /* pwr control without power params IE, should NOT activate MS power control*/
3192 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3193
3194 /* wait, then check that our power level did not change */
3195 timer T1 := 10.0;
3196 T1.start;
3197 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003198 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3199 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3201 "BS power control should not be active unless we receive a power parameters IE!");
3202 }
3203 repeat;
3204 }
3205 [] L1CTL.receive { repeat; }
3206 [] T1.timeout { setverdict(pass); }
3207 }
3208
3209 f_rsl_chan_deact();
3210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3211
3212}
3213
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003214private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003215 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003216 timer T0 := 10.0;
3217 T0.start;
3218 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003219 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3220 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3222 "Power level in L1 header != signaled (RSL) power level.");
3223 }
3224 }
3225 [] L1CTL.receive { repeat; }
3226 [] T0.timeout {
3227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3228 "Timeout waiting for initial power level");
3229 }
3230 }
3231 T0.stop;
3232}
3233
3234private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3235 var IntegerRecord min_dbm_level;
3236 var IntegerRecord max_dbm_level;
3237 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3238
3239 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3240 if (min_dbm_level[i] == level) {
3241 return true;
3242 }
3243 }
3244 return false;
3245}
3246
3247private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3248 var IntegerRecord min_dbm_level;
3249 var IntegerRecord max_dbm_level;
3250 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3251
3252 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3253 if (max_dbm_level[i] == level) {
3254 return true;
3255 }
3256 }
3257 return false;
3258}
3259
3260private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3261 var IntegerRecord min_dbm_level;
3262 var IntegerRecord max_dbm_level;
3263 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3264 return max_dbm_level[0];
3265}
3266
3267type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003268private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003269private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3270 // 45.005 4.1.1
3271 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3272 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3273 2, 1, 0};
3274 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3275 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3276 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3277 var IntegerRecord rv;
3278
3279 select(band){
3280 case (BtsBand_allGSM){
3281 rv := gsm_power;
3282 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3283 max_dbm_level := {2, 1, 0};
3284 }
3285 case("DCS1800"){
3286 rv := dcs_power;
3287 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3288 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3289 }
3290 case("PCS1900"){
3291 rv := pcs_power;
3292 min_dbm_level := {15};
3293 max_dbm_level := {30};
3294 }
Harald Welte194b6912020-10-11 21:01:55 +02003295 case else {
3296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3297 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003298 }
3299
3300 return rv;
3301}
3302
3303private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003304 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of*type* in band (\w+),*", 0);
Eric Wild61edb7e2019-06-03 12:38:31 +02003305}
3306
3307testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3308 var ConnHdlr vc_conn;
3309 var ConnHdlrPars pars;
3310 f_init();
3311 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3312 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3313 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3314 pars.bts0_band := f_vty_get_bts0_band();
3315 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3316 vc_conn.done;
3317 }
3318 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3320}
3321
3322testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3323 var ConnHdlr vc_conn;
3324 var ConnHdlrPars pars;
3325 f_init();
3326 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3327 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3328 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3329 pars.bts0_band := f_vty_get_bts0_band();
3330 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3331 vc_conn.done;
3332 }
3333 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3335}
3336
3337testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3338 var ConnHdlr vc_conn;
3339 var ConnHdlrPars pars;
3340 f_init();
3341 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3342 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3343 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3344 pars.bts0_band := f_vty_get_bts0_band();
3345 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3346 vc_conn.done;
3347 }
3348 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3350}
3351
3352testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3353 var ConnHdlr vc_conn;
3354 var ConnHdlrPars pars;
3355 f_init();
3356 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3357 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3358 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3359 pars.bts0_band := f_vty_get_bts0_band();
3360 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3361 vc_conn.done;
3362 }
3363 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3365}
3366
Eric Wild280ccb82019-06-17 11:11:52 +02003367testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3368 var ConnHdlr vc_conn;
3369 var ConnHdlrPars pars;
3370 f_init();
3371 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3372 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3373 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3374 pars.bts0_band := f_vty_get_bts0_band();
3375 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3376 vc_conn.done;
3377 }
3378 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3380}
3381
Eric Wild095024b2019-06-17 15:08:57 +02003382testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3383 var ConnHdlr vc_conn;
3384 var ConnHdlrPars pars;
3385 f_init();
3386 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3387 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3388 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3389 pars.bts0_band := f_vty_get_bts0_band();
3390 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3391 vc_conn.done;
3392 }
3393 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3395}
3396
Philipp Maier149c3922020-10-22 17:29:36 +02003397function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003398 var template RSL_IE_ChannelMode ch_mode;
3399 var ConnHdlr vc_conn;
3400 var ConnHdlrPars pars;
3401 f_init();
3402 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3403 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3404 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003405 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003406 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3407 pcu_comp := false, trxc_comp := true);
3408 vc_conn.done;
3409 }
3410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3411}
Philipp Maier149c3922020-10-22 17:29:36 +02003412
3413testcase TC_meas_res_speech_tchf() runs on test_CT {
3414 f_TC_meas_res_speech_tchf(false);
3415}
3416
3417testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3418 f_TC_meas_res_speech_tchf(true);
3419}
3420
3421function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003422 var template RSL_IE_ChannelMode ch_mode;
3423 var ConnHdlr vc_conn;
3424 var ConnHdlrPars pars;
3425 f_init();
3426 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3427 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3428 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003429 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003430 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3431 pcu_comp := false, trxc_comp := true);
3432 vc_conn.done;
3433 }
3434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3435}
Philipp Maier149c3922020-10-22 17:29:36 +02003436
3437testcase TC_meas_res_speech_tchh() runs on test_CT {
3438 f_TC_meas_res_speech_tchh(false)
3439}
3440
3441testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3442 f_TC_meas_res_speech_tchh(true)
3443}
3444
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003445testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3446 var template RSL_IE_ChannelMode ch_mode;
3447 var ConnHdlr vc_conn;
3448 var ConnHdlrPars pars;
3449 f_init();
3450 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3451 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3452 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3453 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3454 pars.l1_pars.toa256_enabled := true;
3455 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3456 pcu_comp := false, trxc_comp := true);
3457 vc_conn.done;
3458 }
3459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3460}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003461
Harald Welte70767382018-02-21 12:16:40 +01003462testcase TC_meas_res_sign_tchf() runs on test_CT {
3463 var ConnHdlr vc_conn;
3464 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003465 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003466 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003467 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003468 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003469 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3470 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003471 vc_conn.done;
3472 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003474}
3475testcase TC_meas_res_sign_tchh() runs on test_CT {
3476 var ConnHdlr vc_conn;
3477 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003478 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003479 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003480 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003481 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003482 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3483 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003484 vc_conn.done;
3485 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003487}
3488testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3489 var ConnHdlr vc_conn;
3490 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003491 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003492 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003493 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3494 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003495 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3496 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003497 vc_conn.done;
3498 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003500}
3501testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3502 var ConnHdlr vc_conn;
3503 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003504 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003505 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003506 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3507 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003508 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3509 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003510 vc_conn.done;
3511 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003513}
Harald Welte685d5982018-02-27 20:42:05 +01003514testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3515 var ConnHdlr vc_conn;
3516 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003517 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003518 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3519 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003520 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003521 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003522 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3523 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003524 vc_conn.done;
3525 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003527}
3528
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003529/* Make sure that we always get RSL MEASurement RESult messages regardless
3530 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3531private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3532 timer Texec := 8.0;
3533 timer Timpf := 2.0;
3534 timer Tmr;
3535
3536 f_l1_tune(L1CTL);
3537 RSL.clear;
3538
3539 f_est_dchan();
3540 L1CTL.clear;
3541
3542 /* Establish the main SAPI=0 link on DCCH first */
3543 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3544
3545 /* Give more time for the first RSL MEASurement RESult */
3546 Tmr.start(0.480 * 2.0);
3547 Texec.start; /* EXECution timer */
3548 Timpf.start; /* IMPFung timer */
3549
3550 alt {
3551 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3552 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3553 /* Reschedule the MEAS RES timer */
3554 Tmr.start(0.480 + 0.120);
3555 repeat;
3556 }
3557 [] RSL.receive { repeat; }
3558 [] Tmr.timeout {
3559 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3560 }
3561 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3562 [] Timpf.timeout {
3563 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3564 log("Injected SAPI=3 traffic on SACCH");
3565 Timpf.start;
3566 repeat;
3567 }
3568 /* We're good if survived so far */
3569 [] Texec.timeout {
3570 setverdict(pass);
3571 }
3572 }
3573
3574 f_rsl_chan_deact();
3575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3576 f_rslem_unregister(0, g_chan_nr);
3577}
3578testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3579 var template RSL_IE_ChannelMode ch_mode;
3580 var template ConnHdlrPars pars;
3581 var ConnHdlr vc_conn;
3582
3583 f_init();
3584
3585 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3586 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3587
3588 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3589 vc_conn.done;
3590
3591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3592}
3593testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3594 var template RSL_IE_ChannelMode ch_mode;
3595 var template ConnHdlrPars pars;
3596 var ConnHdlr vc_conn;
3597
3598 f_init();
3599
3600 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3601 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3602
3603 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3604 vc_conn.done;
3605
3606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3607}
3608
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003609/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3610 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003611private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003612 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003613 var RSL_IE_MS_Power ms_power;
3614 var RSL_Message rsl;
3615 var uint5_t power_level := 0;
3616
3617 f_l1_tune(L1CTL);
3618 RSL.clear;
3619
3620 f_est_dchan();
3621
3622 ms_power.reserved := 0;
3623 ms_power.fpc_epc := false;
3624
3625 /* Send the first power control command. This will disable any BTS/TRX
3626 * internal power control and switch the MS (which is not in scope of
3627 * this test) to a constant power level. We start with a power level
3628 * of 0 */
3629 ms_power.power_level := power_level;
3630 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3631 RSL.send(rsl);
3632
3633 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003634 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3635 if (l1h.ms_power_lvl != power_level) {
3636 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3637 "match the signaled (RSL) power level := ", power_level);
3638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003639 }
3640
3641 /* Signal a new power level via RSL for the next turn. */
3642 if (power_level < 31) {
3643 power_level := power_level + 1;
3644 ms_power.power_level := power_level;
3645 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3646 RSL.send(rsl);
3647 repeat;
3648 }
3649
3650 }
3651
3652 /* Ignore all other blocks */
3653 [] L1CTL.receive { repeat; }
3654
3655 }
3656
3657 f_rsl_chan_deact();
3658 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3659
3660 setverdict(pass);
3661}
3662
3663testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3664 var ConnHdlr vc_conn;
3665 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003666 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003667
3668 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3669 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3670 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3671 vc_conn.done;
3672 }
3673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3674}
Harald Welte70767382018-02-21 12:16:40 +01003675
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003676/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003677TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003678private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003679 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003680 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003681
3682 f_l1_tune(L1CTL);
3683 RSL.clear;
3684
3685 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003686 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003687
3688 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3689
3690
3691 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003692 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3693 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003694 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3695 }
3696
3697 }
3698
3699 /* Ignore all other blocks */
3700 [] L1CTL.receive { repeat; }
3701
3702 }
3703
3704 f_rsl_chan_deact();
3705 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3706
3707 setverdict(pass);
3708}
3709
3710testcase TC_rsl_chan_initial_ta() runs on test_CT {
3711 var ConnHdlr vc_conn;
3712 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003713 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003714 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003715 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3716 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003717 vc_conn.done;
3718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3719}
3720
Eric Wilde57e1a62019-05-28 13:30:55 +02003721/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003722private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003723 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003724 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003725
3726 var RSL_IE_MS_Power ms_power;
3727 ms_power.reserved := 0;
3728 ms_power.fpc_epc := false;
3729 ms_power.power_level := ms_power_level;
3730
3731 f_l1_tune(L1CTL);
3732 RSL.clear;
3733
3734 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3735
3736 timer T := 1.0;
3737 T.start;
3738 alt {
3739 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003740 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3741 if (l1h.ms_power_lvl != ms_power_level) {
3742 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3743 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003744 }
3745 }
3746 /* Ignore all other blocks */
3747 [] L1CTL.receive { repeat; }
3748 [] T.timeout {
3749 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3750 }
3751 }
3752
3753 f_rsl_chan_deact();
3754 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3755 setverdict(pass);
3756}
3757
3758testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3759 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3760 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3761}
3762
Harald Welte0472ab42018-03-12 15:02:26 +01003763/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND (TS 48.058 4.10) */
Harald Welte70767382018-02-21 12:16:40 +01003764private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003765 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003766 RSL.clear;
3767
3768 f_est_dchan();
3769 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003770 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003771
3772 timer T := 40.0;
3773 T.start;
3774 alt {
3775 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3776 setverdict(pass)
3777 }
3778 [] RSL.receive { repeat };
3779 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003781 }
3782 }
3783 f_rsl_chan_deact();
3784}
3785testcase TC_conn_fail_crit() runs on test_CT {
3786 var ConnHdlr vc_conn;
3787 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003788 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003789 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3790 pars.t_guard := 60.0;
3791 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3792 vc_conn.done;
3793}
3794
Harald Welte93640c62018-02-25 16:59:33 +01003795/***********************************************************************
3796 * Paging
3797 ***********************************************************************/
3798
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003799private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003800 if (tmsi == 'FFFFFFFF'O) {
3801 return true;
3802 } else {
3803 return false;
3804 }
3805}
Harald Welte70767382018-02-21 12:16:40 +01003806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003807private type record allowedFn { integer frame_nr }
3808private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3809private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3810private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3811private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3812private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3813private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3814private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3815private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3816private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003817{
3818 var integer frame_nr_51;
3819 frame_nr_51 := frame_nr mod 51
3820
3821 var allowedFn fn_check;
3822 fn_check.frame_nr := frame_nr_51;
3823
3824 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003826 return;
3827 }
3828
3829 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3830 return;
3831 }
3832 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3833 return;
3834 }
3835 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3836 return;
3837 }
3838 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3839 return;
3840 }
3841 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3842 return;
3843 }
3844 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3845 return;
3846 }
3847 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3848 return;
3849 }
3850 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3851 return;
3852 }
3853
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003855 return;
3856}
3857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003858private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3859 inout integer num_paging_rcv_ids,
3860 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003861runs on test_CT {
3862 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003863 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003864 repeat;
3865 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003866 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003867 var octetstring without_plen :=
3868 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3869 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003870
3871 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3872
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003873 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3874 /* Ignore empty RR Paging Request (PCH filling) messages.
3875 * TODO: does it make sense to count them? */
3876 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003877 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3878 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003879 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003880 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3881 }
3882 } else if (match(rr, tr_PAGING_REQ2)) {
3883 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3884 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3885 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3886 }
3887 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3888 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3889 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003890 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003891 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3892 }
3893 } else if (match(rr, tr_PAGING_REQ3)) {
3894 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3895 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3896 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3897 }
3898 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3899 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3900 }
3901 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3902 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3903 }
3904 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3905 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3906 }
3907 }
3908 repeat;
3909 }
3910}
3911
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003912private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003913 boolean combined_ccch,
3914 integer bs_ag_blks_res,
3915 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003916 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3917 * paging command that is issued via RSL. */
3918 integer ps_load_modulus,
3919 /* Wait until the paging queue inside the BTS is congested before starting to add
3920 * pagings via the PCU socket (0 = disabled) */
3921 boolean ps_wait_cong,
3922 /* Maximum time to wait until the paging queue is drained at the end of the test.
3923 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3924 * to set this value to 18s, however the draining process may take significantly
3925 * longer when the queue contains paging requests for PS as those are implemented
3926 * as immediate assignments and require an entire MAC block alone. */
3927 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003928 boolean exp_load_ind,
3929 boolean exp_overload,
3930 boolean use_tmsi
3931}
3932
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003933private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003934 integer num_paging_sent,
3935 integer num_paging_rcv_msgs,
3936 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003937 integer num_overload,
3938 /* When free space inside the paging queue reaches more than 2 thirds
3939 * of its capacity cong_detected is set to true. */
3940 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003941}
3942
Harald Welte68e495b2018-02-25 00:05:57 +01003943/* Helper function for paging related testing */
3944private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003945 /* Using the PCU socket affects the timing of the paging processing. We only
3946 * activate the PCU socket if we do paging load tests that include additional
3947 * paging load that is introduced through the PCU socket. */
3948 if (cfg.ps_load_modulus > 0) {
3949 f_init_with_pcuif();
3950 } else {
3951 f_init();
3952 }
Harald Welte68e495b2018-02-25 00:05:57 +01003953 f_init_l1ctl();
3954 f_l1_tune(L1CTL);
3955
Philipp Maierca058272021-06-23 10:35:23 +02003956 var octetstring imm_ass := f_rnd_octstring(23);
3957 var ASP_RSL_Unitdata load_ind;
3958
Harald Welte68e495b2018-02-25 00:05:57 +01003959 var PagingTestState st := {
3960 num_paging_sent := 0,
3961 num_paging_rcv_msgs := 0,
3962 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003963 num_overload := 0,
3964 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003965 };
3966
3967 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3968 var float max_pch_imsi_per_sec;
3969 if (cfg.use_tmsi) {
3970 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3971 } else {
3972 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3973 }
3974 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3975 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003976 var float time_total := 20.0;
3977 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3978 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003979
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003980 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3981 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003982
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003983 timer T_itv := 0.0;
3984 T_itv.start;
3985 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003986 alt {
3987 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003988 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003989 st.num_overload := st.num_overload + 1;
3990 repeat;
3991 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003992 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003994 }
Philipp Maierca058272021-06-23 10:35:23 +02003995 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind {
Harald Welte68e495b2018-02-25 00:05:57 +01003996 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003997
3998 /* Detect paging congestion: The logic inside the BTS will diagnose the
3999 * paging queue as congested when the fill state is more than 66% (which
4000 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4001 * paging congestion is detected pagings that are issued through the PCU
4002 * socket (PS) are dropped in order to prefer the CS related pagings. */
4003 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4004 st.cong_detected := true;
4005 }
4006
Harald Welte68e495b2018-02-25 00:05:57 +01004007 /* FIXME: analyze/verify interval + contents */
4008 repeat;
4009 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004010 /* ignore other RSL messages like RF RESource INDication */
4011 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004012 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004013 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004014 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004015 /* Only relevant when testing including with PCU sock connected */
4016 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004017 [] T_itv.timeout {
4018 /* Send paging cmds based on elapsed time */
4019 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4020 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004021 var MobileIdentityV mi;
4022
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004023 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004024 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004025 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004026 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004027 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004028 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004029
4030 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004031 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, st.num_paging_sent mod 4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004032
Philipp Maierca058272021-06-23 10:35:23 +02004033 /* Add additional pagings through the PCU socket interface. */
4034 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4035 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4036 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4037 }
4038 }
4039
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004040 st.num_paging_sent := st.num_paging_sent + 1;
4041 }
4042 if (st.num_paging_sent < pkt_total) {
4043 /* Wait for interval to next PAGING COMMAND */
4044 var float time_now := T_total.read;
4045 var float next_sched := int2float(st.num_paging_sent)*interval;
4046 if (next_sched > time_now) {
4047 T_itv.start(next_sched - time_now);
4048 } else {
4049 T_itv.start(0.0);
4050 }
4051 } else {
4052 /* We are done, no need to keep counting */
4053 T_total.stop;
4054 }
4055 }
4056 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004057 }
4058 }
4059
Philipp Maierca058272021-06-23 10:35:23 +02004060 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004061 T_wait.start;
4062 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004063 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004064 [] L1CTL.receive { repeat; }
4065 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004066 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004067 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004068 /* ignore other RSL messages like RF RESource INDication */
4069 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004070 /* Only relevant when testing including with PCU sock connected */
4071 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004072 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Waiting for paging queue, last detected fill state: ", load_ind.rsl.ies[1].body.paging_load));
Harald Welte68e495b2018-02-25 00:05:57 +01004074 }
Harald Welte68e495b2018-02-25 00:05:57 +01004075 }
4076
4077 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4078 " rcvd_ids=", st.num_paging_rcv_ids);
4079 return st;
4080}
4081
4082/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4083 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4084 * - that CCCH LOAD IND (PCH) are being generated
4085 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4086testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004087 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004088 var PagingTestCfg cfg := {
4089 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004090 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004091 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004092 ps_load_modulus := 0,
4093 ps_wait_cong := false,
4094 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004095 exp_load_ind := true,
4096 exp_overload := false,
4097 use_tmsi := false
4098 };
4099 var PagingTestState st := f_TC_paging(cfg);
4100 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4102 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004103 } else {
4104 setverdict(pass);
4105 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004107}
4108
4109/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4110 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4111 * - that CCCH LOAD IND (PCH) are being generated
4112 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4113testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004114 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004115 var PagingTestCfg cfg := {
4116 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004117 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004118 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004119 ps_load_modulus := 0,
4120 ps_wait_cong := false,
4121 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004122 exp_load_ind := true,
4123 exp_overload := false,
4124 use_tmsi := true
4125 };
4126 var PagingTestState st := f_TC_paging(cfg);
4127 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4129 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004130 } else {
4131 setverdict(pass);
4132 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004134}
4135
4136/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4137 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4138 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4139 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4140testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004141 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004142 var PagingTestCfg cfg := {
4143 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004144 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004145 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004146 ps_load_modulus := 0,
4147 ps_wait_cong := false,
4148 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004149 exp_load_ind := true,
4150 exp_overload := true,
4151 use_tmsi := false
4152 };
4153 var PagingTestState st := f_TC_paging(cfg);
4154 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4155 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004156 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004157 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004159 } else {
4160 setverdict(pass);
4161 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004163}
4164
4165/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4166 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4167 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4168 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4169testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004170 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004171 var PagingTestCfg cfg := {
4172 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004173 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004174 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004175 ps_load_modulus := 0,
4176 ps_wait_cong := false,
4177 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004178 exp_load_ind := true,
4179 exp_overload := true,
4180 use_tmsi := true
4181 };
4182 var PagingTestState st := f_TC_paging(cfg);
4183 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4184 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004185 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004186 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004188 } else {
4189 setverdict(pass);
4190 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004192}
4193
Philipp Maierca058272021-06-23 10:35:23 +02004194/* Same as above, but with additional paging load created by PS pagings that
4195 * are issued through the PCU socket. The additional load is introduced when
4196 * the paging queue is already two thirds full. Since the BTS implements a
4197 * prioritization logic that drops the pagings from the PCU under in those
4198 * congestive sitautions the behaviour on the PS side is expected to be
4199 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4200testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4201 var SystemInformation si3 := valueof(ts_SI3_default);
4202 var PagingTestCfg cfg := {
4203 combined_ccch := true,
4204 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4205 load_factor := 2.0,
4206 ps_load_modulus := 16,
4207 ps_wait_cong := true,
4208 queue_drain_timeout := 18.0,
4209 exp_load_ind := true,
4210 exp_overload := true,
4211 use_tmsi := false
4212 };
4213 var PagingTestState st := f_TC_paging(cfg);
4214 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4215 * slots and will fully drain that buffer before returning */
4216 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4217 if (not match(st.num_paging_rcv_ids, tpl)) {
4218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4219 } else {
4220 setverdict(pass);
4221 }
4222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4223}
4224
4225
Harald Welte68e495b2018-02-25 00:05:57 +01004226
Harald Welte93640c62018-02-25 16:59:33 +01004227/***********************************************************************
4228 * Immediate Assignment / AGCH
4229 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004230private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004231 len := 0,
4232 ma := ''B
4233}
Harald Welte93640c62018-02-25 16:59:33 +01004234
Harald Weltee8d750e2018-06-10 21:41:35 +02004235private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4236 return int2str(num_tx) & " sent, "
4237 & int2str(num_rx) & " received, "
4238 & int2str(num_del) & " deleted";
4239}
4240
4241private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4242 var L1ctlDlMessage l1_dl;
4243 timer T := 10.0;
4244 var integer num_tx := 0;
4245 var integer num_rx := 0;
4246 var integer num_del := 0;
4247 var charstring res_str;
4248 var float rx_ratio;
4249
Harald Welte10474062019-05-30 16:48:17 +02004250 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004251 f_init_l1ctl();
4252 f_l1_tune(L1CTL);
4253
4254 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004255 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004256 mp_trx_pars[0].arfcn,
4257 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004258 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4259 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004260 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004261 num_tx := num_tx+1;
4262 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004263 }
4264 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004265 T.start;
4266 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004267 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004268 num_del := num_del+1;
4269 repeat;
4270 }
4271 [] RSL_CCHAN.receive {
4272 repeat;
4273 }
4274 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004275 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4276 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4277 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004278 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004279 } else {
4280 num_rx := num_rx+1;
4281 }
4282 repeat;
4283 }
4284 [] L1CTL.receive { repeat; }
4285 [] T.timeout { }
4286 }
4287 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4288 log("AGCH test: " & res_str);
4289 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004291 }
4292 rx_ratio := int2float(num_rx) / int2float(num_tx);
4293 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004295 } else {
4296 setverdict(pass);
4297 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004299}
4300
Harald Weltee8d750e2018-06-10 21:41:35 +02004301/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4302testcase TC_imm_ass_1000_20ms() runs on test_CT {
4303 f_TC_imm_ass(1000, 0.02, 0.25);
4304}
4305
4306/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4307testcase TC_imm_ass_200_0ms() runs on test_CT {
4308 f_TC_imm_ass(200, 0.0, 0.05);
4309}
4310
4311/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4312testcase TC_imm_ass_200_76ms() runs on test_CT {
4313 f_TC_imm_ass(150, 0.076, 1.00);
4314}
4315
4316
4317
Harald Welte48494ca2018-02-25 16:59:50 +01004318/***********************************************************************
4319 * BCCH
4320 ***********************************************************************/
4321
4322/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004323private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004324 GsmFrameNumber frame_number,
4325 SystemInformation si
4326}
4327
4328/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004329private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004330
4331/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004332private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004333
4334/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004335private function f_si_vecslot_contains(SystemInformationVector arr,
4336 RrMessageType key,
4337 boolean bcch_ext := false)
4338return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004339 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4340 var integer fn_mod51 := arr[i].frame_number mod 51;
4341 if (not bcch_ext and fn_mod51 == 2 or
4342 bcch_ext and fn_mod51 == 6) {
4343 if (arr[i].si.header.message_type == key) {
4344 return true;
4345 }
4346 }
4347 }
4348 return false;
4349}
4350
4351/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004352private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4353 integer tc, RrMessageType key,
4354 boolean ext_bcch := false)
4355{
Harald Welte48494ca2018-02-25 16:59:50 +01004356 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004358 }
4359}
4360
4361/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004362private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4363 RrMessageType key)
4364return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004365 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4366 if (f_si_vecslot_contains(arr[tc], key) or
4367 f_si_vecslot_contains(arr[tc], key, true)) {
4368 return true;
4369 }
4370 }
4371 return false;
4372}
4373
4374/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004375private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4376 RrMessageType key,
4377 boolean bcch_ext := false,
4378 integer n := 1, integer m := 4)
4379return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004380 var integer count := 0;
4381 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4383 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004384 }
4385 for (var integer i:= 0; i < m; i := i + 1) {
4386 var integer fn_mod51 := arr[i].frame_number mod 51;
4387 if (not bcch_ext and fn_mod51 == 2 or
4388 bcch_ext and fn_mod51 == 6) {
4389 if (arr[i].si.header.message_type == key) {
4390 count := count + 1;
4391 }
4392 }
4393 }
4394 if (count >= n) {
4395 return true;
4396 } else {
4397 return false;
4398 }
4399}
4400
4401/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004402private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4403 integer tc, RrMessageType key,
4404 boolean ext_bcch := false,
4405 integer n, integer m)
4406{
Harald Welte48494ca2018-02-25 16:59:50 +01004407 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004409 }
4410}
4411
4412/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004413private function f_si_vecslot_contains_only(SystemInformationVector arr,
4414 RrMessageType key,
4415 boolean bcch_ext := false)
4416return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004417 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4418 var integer fn_mod51 := arr[i].frame_number mod 51;
4419 if (not bcch_ext and fn_mod51 == 2 or
4420 bcch_ext and fn_mod51 == 6) {
4421 if (arr[i].si.header.message_type != key) {
4422 return false;
4423 }
4424 }
4425 }
4426 return true;
4427}
4428
4429/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004430private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4431 integer tc, RrMessageType key,
4432 boolean ext_bcch := false)
4433{
Harald Welte48494ca2018-02-25 16:59:50 +01004434 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004436 }
4437}
4438
4439/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004440private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004441 boolean bcch_extended,
4442 boolean si1_present,
4443 boolean si2bis_present,
4444 boolean si2ter_present,
4445 boolean si2quater_present,
4446 boolean si7_present,
4447 boolean si8_present,
4448 boolean si9_present,
4449 boolean si13_present,
4450 boolean si13alt_present,
4451 boolean si15_present,
4452 boolean si16_present,
4453 boolean si17_present,
4454 boolean si2n_present,
4455 boolean si21_present,
4456 boolean si22_present
4457}
4458
4459/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004460private function f_validate_si_scheduling(SystemInformationConfig cfg,
4461 SystemInformationVectorPerTc si_per_tc)
4462{
Harald Welte48494ca2018-02-25 16:59:50 +01004463 var integer i;
4464 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4465 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004467 }
4468 }
4469 if (cfg.si1_present) {
4470 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4471 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4472 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4473 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4474 /* make sure *ALL* contain SI1 */
4475 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4476 }
4477 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4478 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4479 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4480 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4481 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4482 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4483
4484 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4485 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4486 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4487 * consecutive occurrences of TC = 4. */
4488 if (cfg.si2bis_present and not cfg.si2ter_present) {
4489 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4490 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4491 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4492 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4493 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4494 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4495 }
4496
4497 if (cfg.si7_present or cfg.si8_present) {
4498 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4499 * if System Information type 4 does not contain all information needed for cell
4500 * selection and reselection. */
4501 if (not cfg.bcch_extended) {
4502 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4503 }
4504 if (cfg.si7_present) {
4505 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4506 }
4507 if (cfg.si8_present) {
4508 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4509 }
4510 }
4511
4512 if (cfg.si2quater_present) {
4513 /* iii) System information type 2 quater is sent if needed, as determined by the system
4514 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4515 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4516 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4517 * within any of 4 consecutive occurrences of TC = 5. */
4518 if (not (cfg.bcch_extended)) {
4519 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4520 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4521 } else {
4522 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4523 }
4524 } else {
4525 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4526 }
4527 }
4528 if (cfg.si9_present) {
4529 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4530 * in system information type 3 as defined in 3GPP TS 44.018. */
4531 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4532 }
4533 if (cfg.si13_present) {
4534 /* vii) System Information type 13 is only related to the GPRS service. System Information
4535 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4536 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4537 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4538 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4539 * within any of 4 consecutive occurrences of TC=4. */
4540 if (not cfg.bcch_extended) {
4541 log("not-bccch-extended");
4542 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4543 } else {
4544 log("bccch-extended");
4545 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4546 }
4547 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004549 }
4550 }
4551 if (cfg.si16_present or cfg.si17_present) {
4552 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4553 * should not be sent in a cell where network sharing is used (see rule xv). */
4554 if (cfg.si22_present) {
4555 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4556 }
4557 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004559 }
4560 if (not cfg.bcch_extended) {
4561 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4562 }
4563 if (cfg.si16_present) {
4564 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4565 }
4566 if (cfg.si17_present) {
4567 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4568 }
4569 }
4570
4571 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4572 * broadcast information. The frequency with which they are sent is determined by the
4573 * system operator. System Information type 9 identifies the scheduling of System
4574 * Information type 18 and 20 messages. */
4575
4576 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4577 * Information Type 19 is present, then its scheduling shall be indicated in System
4578 * Information Type 9. */
4579
4580 if (cfg.si15_present) {
4581 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4582 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4583 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4584 * 4 consecutive occurrences of TC = 1. */
4585 if (not cfg.bcch_extended) {
4586 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4587 } else {
4588 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4589 }
4590 }
4591 if (cfg.si13alt_present) {
4592 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4593 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4594 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4595 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4596 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4597 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4598 * of TC = 4. */
4599 if (cfg.si13_present) {
4600 testcase.stop("Error: Cannot have SI13alt and SI13");
4601 }
4602 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004604 }
4605 if (not cfg.bcch_extended) {
4606 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4607 } else {
4608 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4609 }
4610 }
4611 if (cfg.si2n_present) {
4612 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4613 * as determined by the system operator. In the case that the message is sent on the
4614 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4615 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4616 * consecutive occurrences of TC = 4. */
4617 if (not cfg.bcch_extended) {
4618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4619 } else {
4620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4621 }
4622 }
4623 if (cfg.si21_present) {
4624 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4625 * determined by the system operator. If Extended Access Barring is in use in the cell
4626 * then this message is sent at least once within any of 4 consecutive occurrences of
4627 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4628 * cell then this message shall only be sent on BCCH Ext. */
4629 if (not cfg.bcch_extended) {
4630 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4631 } else {
4632 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4633 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004635 }
4636 }
4637 }
4638 if (cfg.si22_present) {
4639 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4640 * should not be sent in a cell where SoLSA is used (see rule viii). System
4641 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4642 * =2 and TC=6. */
4643 if (cfg.si16_present or cfg.si17_present) {
4644 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4645 }
4646 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4647 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004649 }
4650 if (not cfg.bcch_extended) {
4651 testcase.stop("Error: SI22 requires BCCH Extd!");
4652 } else {
4653 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4654 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4655 }
4656 }
4657}
4658
4659/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004660private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4661return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004662 timer T := duration;
4663 var SystemInformationVectorPerTc si_per_tc;
4664 var L1ctlDlMessage l1_dl;
4665
4666 /* initialize all per-TC vectors empty */
4667 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4668 si_per_tc[i] := {};
4669 }
4670
4671 /* flush all previous L1 queued msgs */
4672 pt.clear;
4673
4674 T.start;
4675 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004676 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004677 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4678 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4679 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004680 repeat;
4681 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004682
Harald Welte48494ca2018-02-25 16:59:50 +01004683 var integer tc := f_gsm_compute_tc(sig.frame_number);
4684 log("SI received at TC=", tc, ": ", sig.si);
4685 /* append to the per-TC bucket */
4686 si_per_tc[tc] := si_per_tc[tc] & { sig };
4687 repeat;
4688 }
4689 [] pt.receive { repeat; }
4690 [] T.timeout { }
4691 }
4692
4693 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4694 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4695 }
4696 log("si_per_tc=", si_per_tc);
4697 return si_per_tc;
4698}
4699
4700/* helper function: Set given SI via RSL + validate scheduling.
4701 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004702private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004703 var SystemInformationVectorPerTc si_per_tc;
4704 f_init_l1ctl();
4705 f_l1_tune(L1CTL);
4706
4707 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004708 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004709 f_validate_si_scheduling(si_cfg, si_per_tc);
4710
4711 setverdict(pass);
4712}
4713
4714testcase TC_si_sched_default() runs on test_CT {
4715 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004716 /* 2+3+4 are mandatory and set in f_init() */
4717 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004719}
4720
4721testcase TC_si_sched_1() runs on test_CT {
4722 f_init();
4723 si_cfg.si1_present := true;
4724 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004725 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004727}
4728
4729testcase TC_si_sched_2bis() runs on test_CT {
4730 f_init();
4731 si_cfg.si2bis_present := true;
4732 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4733 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004735}
4736
4737testcase TC_si_sched_2ter() runs on test_CT {
4738 f_init();
4739 si_cfg.si2ter_present := true;
4740 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4741 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004743}
4744
4745testcase TC_si_sched_2ter_2bis() runs on test_CT {
4746 f_init();
4747 si_cfg.si2bis_present := true;
4748 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4749 si_cfg.si2ter_present := true;
4750 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4751 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004753}
4754
4755testcase TC_si_sched_2quater() runs on test_CT {
4756 f_init();
4757 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004758 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004759 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004761}
4762
4763testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004764 /* NOTE: PCUIF connection is not used in this test case, but
4765 * without it the IUT would not broadcast SI13 (see OS#3075). */
4766 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004767 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004768 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004769 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004771}
4772
4773testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004774 /* NOTE: PCUIF connection is not used in this test case, but
4775 * without it the IUT would not broadcast SI13 (see OS#3075). */
4776 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004777 si_cfg.si2bis_present := true;
4778 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4779 si_cfg.si2ter_present := true;
4780 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4781 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004782 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004783 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004784 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004785 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004787}
4788
4789
Harald Welte68e495b2018-02-25 00:05:57 +01004790testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004791 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004792 /* FIXME: enable / disable individual BCCH info */
4793 //ts_RSL_BCCH_INFO(si_type, info);
4794 /* expect no ERROR REPORT after either of them *
4795 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004797}
4798
Harald Welte93640c62018-02-25 16:59:33 +01004799/***********************************************************************
4800 * Low-Level Protocol Errors / ERROR REPORT
4801 ***********************************************************************/
4802
Harald Welte01d982c2018-02-25 01:31:40 +01004803private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4804 timer T := 5.0;
4805 T.start;
4806 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004807 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004808 setverdict(pass);
4809 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004810 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004812 }
4813 [] RSL_CCHAN.receive {
4814 repeat;
4815 }
4816 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004818 }
4819 }
4820}
4821
4822/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4823testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004824 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004825 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4826 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004827 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004828
4829 f_exp_err_rep(RSL_ERR_PROTO);
4830}
4831
4832/* Provoke a mandatory IE error and match on ERROR REPORT */
4833testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004834 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004835
4836 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4837 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004838 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004839
4840 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4841}
4842
4843/* Provoke an IE content error and match on ERROR REPORT */
4844testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004845 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004846 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4847 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004848 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004849
4850 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4851}
4852
Harald Welteee25aae2019-05-19 14:32:37 +02004853/* attempt to activate channel with wrong RSL Message Discriminator IE */
4854function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4855 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4856 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4857 RSL.send(rsl);
4858 f_rslem_unregister(0, g_chan_nr);
4859}
4860testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4861 var ConnHdlr vc_conn;
4862 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4863
Harald Welte10474062019-05-30 16:48:17 +02004864 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004865
4866 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4867 vc_conn.done;
4868 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4869
4870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4871}
4872
4873/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004874private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004875 var template (value) RSL_Message rsl_tx;
4876 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4877 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4878 RSL.send(rsl_tx);
4879 f_rslem_unregister(0, g_chan_nr);
4880}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004881private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004882 var template (value) RSL_Message rsl_tx;
4883 /* we first have to activate the dedicated channel */
4884 f_rsl_chan_act(g_pars.chan_mode);
4885 /* ... to then send an invalid RLL message */
4886 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4887 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4888 RSL.send(rsl_tx);
4889 f_rslem_unregister(0, g_chan_nr);
4890}
4891testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4892 var ConnHdlr vc_conn;
4893 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4894 var template (value) RSL_Message rsl_tx;
4895
Harald Welte10474062019-05-30 16:48:17 +02004896 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004897
4898 /* Common Channel with wrong message type */
4899 RSL_CCHAN.clear;
4900 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4901 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004902 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004903 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4904
4905 /* TRX Management */
4906 RSL_CCHAN.clear;
4907 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4908 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004909 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004910 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4911
4912 /* Dedicated Channel */
4913 RSL_CCHAN.clear;
4914 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4915 vc_conn.done;
4916 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4917
4918 /* RLL */
4919 RSL_CCHAN.clear;
4920 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4921 vc_conn.done;
4922 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4923}
4924
4925/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004926private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004927 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4928 f_rslem_unregister(0, g_chan_nr);
4929}
4930testcase TC_err_rep_wrong_sequence() runs on test_CT {
4931 var ConnHdlr vc_conn;
4932 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4933
Harald Welte10474062019-05-30 16:48:17 +02004934 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004935
4936 RSL_CCHAN.clear;
4937 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4938 vc_conn.done;
4939 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4940}
4941
Harald Welte93640c62018-02-25 16:59:33 +01004942/***********************************************************************
4943 * IPA CRCX/MDCX/DLCS media stream handling
4944 ***********************************************************************/
4945
Harald Weltea871a382018-02-25 02:03:14 +01004946/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004947private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004948 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4949 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004950}
4951testcase TC_ipa_dlcx_not_active() runs on test_CT {
4952 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004953 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004954 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4955 vc_conn.done;
4956}
Harald Welte68e495b2018-02-25 00:05:57 +01004957
Harald Weltea3f1df92018-02-25 12:49:55 +01004958/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004959private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004960 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4961 "IPA CRCX ACK");
4962 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4963 "IPA CRCX NACK");
4964}
4965testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4966 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004967 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004968 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4969 vc_conn.done;
4970}
4971
4972/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004973private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004974 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4975 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004976 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004977 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4978 var uint7_t rtp_pt2 := f_rnd_int(127);
4979 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4980 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4981 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4982 "IPA MDCX ACK");
4983 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4984 "IPA DLCX ACK");
4985}
4986testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4987 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004988 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004989 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4990 vc_conn.done;
4991}
4992
Harald Welte3ae11da2018-02-25 13:36:06 +01004993/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004994private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004995 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4996 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004997 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004998 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4999 var uint7_t rtp_pt2 := f_rnd_int(127);
5000 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5001 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5002 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5003 "IPA MDCX ACK");
5004 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005005 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005006 remote_port := f_rnd_int(c_UINT16_MAX);
5007 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5008 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5009 "IPA MDCX ACK");
5010 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5011 "IPA DLCX ACK");
5012}
5013testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5014 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005015 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005016 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5017 vc_conn.done;
5018}
5019
Harald Welte9912eb52018-02-25 13:30:15 +01005020/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005021private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005022 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5023 "IPA CRCX NACK");
5024}
5025testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5026 var ConnHdlrPars pars;
5027 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005028 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005029
5030 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5031 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5032 vc_conn.done;
5033
5034 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5035 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5036 vc_conn.done;
5037}
5038
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005039/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5040private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5041 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5042 var PortNumber bind_port := 16811;
5043 var RSL_Message crcx_ack;
5044
5045 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5046 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5047 "IPA CRCX ACK");
5048 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5049 if (match(bts_bind_ip, "0.0.0.0")) {
5050 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5051 }
5052
5053 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5054 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5055 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5056 "IPA DLCX ACK");
5057}
5058testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5059 var ConnHdlrPars pars;
5060 var ConnHdlr vc_conn;
5061 f_init();
5062
5063 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5064 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5065 vc_conn.done;
5066
5067 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5068 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5069 vc_conn.done;
5070}
5071
Harald Weltea3f1df92018-02-25 12:49:55 +01005072
Harald Welte883340c2018-02-28 18:59:29 +01005073/***********************************************************************
5074 * PCU Socket related tests
5075 ***********************************************************************/
5076
Harald Welte07bd2d22019-05-25 11:03:30 +02005077/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005078friend 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 +01005079runs on test_CT {
5080 timer T := 3.0;
5081
5082 /* we don't expect any RTS.req before PDCH are active */
5083 T.start;
5084 alt {
5085 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005087 }
5088 [] PCU.receive { repeat; }
5089 [] T.timeout { }
5090 }
5091
5092 /* Send PDCH activate request for known PDCH timeslot */
5093 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5094
5095 /* we now expect RTS.req for this timeslot (only) */
5096 T.start;
5097 alt {
5098 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5099 setverdict(pass);
5100 }
5101 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5102 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005104 }
5105 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005107 }
5108 [] PCU.receive { repeat; }
5109 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005111 }
5112 [not exp_success] T.timeout {
5113 setverdict(pass);
5114 }
5115 }
5116}
5117
Harald Welte07bd2d22019-05-25 11:03:30 +02005118/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005119friend 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 +01005120runs on test_CT {
5121 timer T := 3.0;
5122
5123 /* Send PDCH activate request for known PDCH timeslot */
5124 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 +02005125 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5126 * when it will actually have been executed in the BTS */
5127 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005128 PCU.clear;
5129 /* we now expect no RTS.req for this timeslot */
5130 T.start;
5131 alt {
5132 [] 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 +02005133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005134 }
5135 [] PCU.receive { repeat; }
5136 [] T.timeout {
5137 setverdict(pass);
5138 }
5139 }
5140}
5141
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005142friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005143 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005144 map(self:PCU, system:PCU);
5145 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005146 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5147}
5148
Harald Welte883340c2018-02-28 18:59:29 +01005149/* PDCH activation via PCU socket; check for presence of RTS.req */
5150testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005151 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005152
Harald Welte883340c2018-02-28 18:59:29 +01005153 f_TC_pcu_act_req(0, 0, 7, true);
5154}
5155
5156/* PDCH activation via PCU socket on non-PDCU timeslot */
5157testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005158 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005159
Harald Welte883340c2018-02-28 18:59:29 +01005160 f_TC_pcu_act_req(0, 0, 1, false);
5161}
5162
5163/* PDCH activation via PCU socket on wrong BTS */
5164testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005165 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005166
Harald Welte883340c2018-02-28 18:59:29 +01005167 f_TC_pcu_act_req(23, 0, 7, false);
5168}
5169
5170/* PDCH activation via PCU socket on wrong TRX */
5171testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005172 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005173
Harald Welte883340c2018-02-28 18:59:29 +01005174 f_TC_pcu_act_req(0, 23, 7, false);
5175}
5176
5177/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5178testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005179 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005180
Harald Welte883340c2018-02-28 18:59:29 +01005181 /* Activate PDCH */
5182 f_TC_pcu_act_req(0, 0, 7, true);
5183 f_sleep(1.0);
5184 /* and De-Activate again */
5185 f_TC_pcu_deact_req(0, 0, 7);
5186}
5187
5188/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5189testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005190 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005191
Harald Welte883340c2018-02-28 18:59:29 +01005192 f_TC_pcu_deact_req(0, 0, 1);
5193}
5194
5195/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005196function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005197 var PCUIF_send_data sd;
5198 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005199 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005200
5201 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005202 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005203
Harald Welte883340c2018-02-28 18:59:29 +01005204 T.start;
5205 alt {
5206 [] 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 +01005207 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005208 setverdict(pass);
5209 } else {
5210 repeat;
5211 }
5212 }
5213 [] PCU.receive { repeat; }
5214 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005216 }
5217 }
5218}
5219
Philipp Maier94c08482021-02-01 17:36:05 +01005220/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5221testcase TC_pcu_ver_si1() runs on test_CT {
5222 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5223 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5224}
5225
5226/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5227testcase TC_pcu_ver_si3() runs on test_CT {
5228 const octetstring si3 := '49012223242526272929AABBCC'O;
5229 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5230}
5231
5232/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5233testcase TC_pcu_ver_si13() runs on test_CT {
5234 const octetstring si13 := '01010203040506070909'O;
5235 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5236}
5237
Harald Welte883340c2018-02-28 18:59:29 +01005238private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5239
5240/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005241friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005242 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5243runs on test_CT
5244{
5245 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5246 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5247}
5248
5249/* 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 +02005250friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5251 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005252runs on test_CT
5253{
5254 var PCUIF_send_data sd;
5255
5256 timer T := 3.0;
5257 T.start;
5258 alt {
5259 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5260 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5261 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5262 sd.data.u.rts_req.fn, sapi, data);
5263 }
5264 [] PCU.receive { repeat; }
5265 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005267 }
5268 }
5269}
5270
5271/* Send DATA.req on invalid BTS */
5272testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005273 var TfiUsfArr tua := f_TfiUsfArrInit();
5274 var octetstring data := '0000'O & f_rnd_octstring(21);
5275
5276 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005277
Harald Welte883340c2018-02-28 18:59:29 +01005278 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005279 f_TfiUsfArrSet(tua, 7, 0);
5280 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5281 f_sleep(1.0);
5282
5283 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005284}
5285
5286/* Send DATA.req on invalid TRX */
5287testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005288 var TfiUsfArr tua := f_TfiUsfArrInit();
5289 var octetstring data := '0000'O & f_rnd_octstring(21);
5290
5291 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005292
Harald Welte883340c2018-02-28 18:59:29 +01005293 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005294 f_TfiUsfArrSet(tua, 7, 0);
5295 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5296 f_sleep(1.0);
5297
5298 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005299}
5300
5301/* Send DATA.req on invalid timeslot */
5302testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005303 var TfiUsfArr tua := f_TfiUsfArrInit();
5304 var octetstring data := '0000'O & f_rnd_octstring(21);
5305
5306 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005307
Harald Welte883340c2018-02-28 18:59:29 +01005308 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005309 f_TfiUsfArrSet(tua, 7, 0);
5310 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5311 f_sleep(1.0);
5312
5313 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005314}
5315
5316/* Send DATA.req on timeslot that hasn't been activated */
5317testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005318 var TfiUsfArr tua := f_TfiUsfArrInit();
5319 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005320
Harald Welte7162a612019-05-26 12:56:09 +02005321 f_virtphy_common();
5322
5323 f_TfiUsfArrSet(tua, 7, 0);
5324 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5325 f_sleep(1.0);
5326
5327 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005328}
5329
Harald Weltead033dc2019-05-25 17:28:16 +02005330private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005331 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5332 boolean wait_rts := true)
5333runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005334 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005335 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005336
5337 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005338 if (wait_rts) {
5339 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5340 } else {
5341 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5342 }
Harald Weltead033dc2019-05-25 17:28:16 +02005343
5344 T.start;
5345 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005346 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005347 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5348 setverdict(pass);
5349 }
Harald Welte7162a612019-05-26 12:56:09 +02005350 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5351 setverdict(fail, "Received unexpected ", rx_dl);
5352 }
Harald Weltead033dc2019-05-25 17:28:16 +02005353 [] L1CTL.receive {
5354 repeat;
5355 }
Harald Welte7162a612019-05-26 12:56:09 +02005356 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005357 setverdict(fail, "Timeout waiting for ", data);
5358 }
Harald Welte7162a612019-05-26 12:56:09 +02005359 [not expect_data] T.timeout {
5360 setverdict(pass);
5361 }
Harald Weltead033dc2019-05-25 17:28:16 +02005362 }
5363}
5364
5365private function f_disable_dynamic_ts() runs on test_CT
5366{
5367 f_init_vty_bsc();
5368 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5369 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5370 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5371 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005372 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005373}
5374
5375private function f_virtphy_common() runs on test_CT {
5376 f_disable_dynamic_ts();
5377 f_init_l1ctl();
5378 f_l1_tune(L1CTL);
5379}
5380
5381testcase TC_pcu_data_req_pdtch() runs on test_CT {
5382 var TfiUsfArr tua := f_TfiUsfArrInit();
5383 var octetstring data := '0000'O & f_rnd_octstring(21);
5384
5385 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005386
Harald Welte883340c2018-02-28 18:59:29 +01005387 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005388 f_TfiUsfArrSet(tua, 7, 0);
5389 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5390 f_sleep(1.0);
5391
5392 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005393}
5394
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005395/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005396testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005397 var TfiUsfArr tua := f_TfiUsfArrInit();
5398 var octetstring data := '0000'O & f_rnd_octstring(21);
5399
5400 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005401
Harald Welte883340c2018-02-28 18:59:29 +01005402 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005403 f_TfiUsfArrSet(tua, 7, 0);
5404 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5405 f_sleep(1.0);
5406
5407 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005408}
5409
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005410private function f_TC_pcu_ptcch_ul(uint16_t ra)
5411runs on test_CT {
5412 var template PCUIF_Message pcu_rach_ind;
5413 var PCUIF_send_data sd;
5414 var GsmFrameNumber fn;
5415 timer T;
5416
5417 /* Send an Access Burst on PTCCH/U over the Um-interface */
5418 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5419 chan_nr := ts_RslChanNr_PDCH(7),
5420 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5421
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005422 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5423 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005424
5425 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5426 T.start(52.0 * 4.615 / 1000.0);
5427 alt {
5428 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5429 log("Rx an Access Burst on the PCU interface: ", sd.data);
5430 setverdict(pass);
5431 T.stop;
5432 }
5433 [] PCU.receive { repeat; }
5434 [] T.timeout {
5435 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5436 /* Keep going, that's not the end of the world */
5437 }
5438 }
5439}
5440
5441testcase TC_pcu_ptcch() runs on test_CT {
5442 var L1ctlDlMessage dl;
5443 var octetstring data;
5444 timer T;
5445
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005446 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005447 f_init_l1ctl();
5448 f_l1_tune(L1CTL);
5449
5450 /* Activate PDCH channel on TS7 */
5451 f_TC_pcu_act_req(0, 0, 7, true);
5452
5453 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005454 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005455 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005456 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005457 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005458
5459 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5460 for (var integer i := 0; i < 16; i := i + 1) {
5461 log("Sending an Access Burst towards the L1CTL interface");
5462 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5463 }
5464
5465 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5466 data := f_rnd_octstring(23);
5467
5468 /* Verify PTCCH/D: send a random data block, make sure it's received */
5469 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5470 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5471
5472 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5473 * let's give it more time in case if we miss the beginning. */
5474 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5475 alt {
5476 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5477 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5478 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5479 frame := data)) -> value dl {
5480 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5481 setverdict(pass);
5482 T.stop;
5483 }
5484 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5485 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5486 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5487 l2_data := data)) -> value dl {
5488 log("Rx PTCCH/D data block on L1CTL: ", dl);
5489 setverdict(pass);
5490 T.stop;
5491 }
5492 [] L1CTL.receive { repeat; }
5493 [] T.timeout {
5494 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5495 }
5496 }
5497}
5498
Harald Welte883340c2018-02-28 18:59:29 +01005499/* Send AGCH from PCU; check it appears on Um side */
5500testcase TC_pcu_data_req_agch() runs on test_CT {
5501 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005502 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005503 f_init_l1ctl();
5504 f_l1_tune(L1CTL);
5505
5506 f_TC_pcu_act_req(0, 0, 7, true);
5507 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5508
5509 T.start;
5510 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005511 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005512 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
Harald Welte928622b2019-05-26 13:22:59 +02005521/* Send AGCH from PCU; check it appears on Um side */
5522testcase TC_pcu_data_req_pch() runs on test_CT {
5523 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005524 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005525 f_init_l1ctl();
5526 f_l1_tune(L1CTL);
5527
5528 f_TC_pcu_act_req(0, 0, 7, true);
5529 /* three characters prefix: last 3 digits of IMSI as ASCII */
5530 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5531
5532 T.start;
5533 alt {
5534 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5535 setverdict(pass);
5536 }
5537 [] L1CTL.receive { repeat; }
5538 [] T.timeout {
5539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5540 }
5541 }
5542}
5543
Harald Welte883340c2018-02-28 18:59:29 +01005544/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5545testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5546 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005547 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005548 f_init_l1ctl();
5549 f_l1_tune(L1CTL);
5550
5551 /* append 3 last imsi digits so BTS can compute pagng group */
5552 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5553
5554 timer T := 0.5;
5555 T.start;
5556 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005557 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005558 /* TODO: verify paging group */
5559 setverdict(pass);
5560 }
5561 [] L1CTL.receive { repeat; }
5562 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005564 }
5565 }
5566}
5567
5568/* Send RACH from Um side, expect it to show up on PCU socket */
5569testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005570 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005571 f_init_l1ctl();
5572 f_l1_tune(L1CTL);
5573
5574 var GsmFrameNumber fn_last := 0;
5575 for (var integer i := 0; i < 1000; i := i+1) {
5576 var OCT1 ra := f_rnd_ra_ps();
5577 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5578 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005580 }
5581 fn_last := fn;
5582
5583 timer T := 2.0;
5584 T.start;
5585 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005586 [] 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 +01005587 T.stop;
5588 }
5589 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005591 }
5592 [] PCU.receive { repeat; }
5593 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005595 }
5596 }
5597 }
5598 setverdict(pass);
5599}
5600
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005601/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5602 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5603testcase TC_pcu_ext_rach_content() runs on test_CT {
5604 var template PCUIF_Message pcu_rach_ind;
5605 var GsmFrameNumber fn_last := 0;
5606 var L1ctlRachSynchSeq synch_seq;
5607 var PCUIF_BurstType pcu_bt;
5608 var GsmFrameNumber fn;
5609 var BIT11 ra11;
5610
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005611 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005612 f_init_l1ctl();
5613 f_l1_tune(L1CTL);
5614
5615 for (var integer i := 0; i < 1000; i := i+1) {
5616 /* We need to test both TS1 & TS2 */
5617 if (i rem 2 == 0) {
5618 synch_seq := RACH_SYNCH_SEQ_TS1;
5619 pcu_bt := BURST_TYPE_1;
5620 } else {
5621 synch_seq := RACH_SYNCH_SEQ_TS2;
5622 pcu_bt := BURST_TYPE_2;
5623 }
5624
5625 ra11 := f_rnd_ra11_ps();
5626 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5627 if (fn == fn_last) {
5628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5629 "Two RACH in same FN?!?");
5630 }
5631 fn_last := fn;
5632
5633 /* Compose the expected message */
5634 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005635 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005636 ra := bit2int(ra11),
5637 is_11bit := 1,
5638 burst_type := pcu_bt,
5639 fn := fn);
5640
5641 timer T := 2.0;
5642 T.start;
5643 alt {
5644 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5645 T.stop;
5646 }
5647 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5649 }
5650 [] PCU.receive { repeat; }
5651 [] T.timeout {
5652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5653 }
5654 }
5655 }
5656 setverdict(pass);
5657}
5658
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005659private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5660runs on test_CT {
5661 var template PCUIF_send_data sdt;
5662 var PCUIF_send_data sd;
5663 var int16_t lqual_cb;
5664 timer T := 1.0;
5665
5666 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5667 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5668
5669 /* Send a random PDTCH frame over Um */
5670 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5671 '0000'O & f_rnd_octstring(21)));
5672
5673 T.start;
5674 alt {
5675 /* If expected link quality is above the threshold */
5676 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5677 lqual_cb := sd.data.u.data_ind.lqual_cb;
5678 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5679
5680 /* Make sure the actual link quality matches the expected value */
5681 if (not match(lqual_cb, lqual_cb_exp)) {
5682 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5683 "expected value ", lqual_cb_exp));
5684 } else {
5685 setverdict(pass);
5686 }
5687 }
5688 /* If expected link quality is below the threshold */
5689 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5691 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5692 }
5693 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5694 [] PCU.receive { repeat; }
5695 [lqual_cb_exp < thresh] T.timeout {
5696 log("Rx nothing, as expected");
5697 setverdict(pass);
5698 }
5699 [lqual_cb_exp >= thresh] T.timeout {
5700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5701 "Timeout waiting for PCUIF_DATA.ind");
5702 }
5703 }
5704}
5705
5706/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5707testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005708 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005709 PCU.clear;
5710
5711 f_init_l1ctl();
5712 f_l1_tune(L1CTL);
5713
5714 /* Activate a PDCH channel on TS7 */
5715 f_TC_pcu_act_req(0, 0, 7, true);
5716
5717 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005718 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005719 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005720 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005721 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005722
5723 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5724 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5725 var TrxcMessage ret;
5726
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005727 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005728
5729 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5730 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5731 }
5732}
5733
Harald Welte883340c2018-02-28 18:59:29 +01005734/* Send PAGING via RSL, expect it to shw up on PCU socket */
5735testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005736 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005737
5738 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005739 var MobileIdentityLV mi_lv;
5740 var octetstring mi_lv_enc;
5741 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005742 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005743
Harald Welte883340c2018-02-28 18:59:29 +01005744 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005745 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005746 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005747 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005748 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005749
5750 /* Fancy encoding for PCUIF */
5751 mi_lv := valueof(ts_MI_LV(mi));
5752 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5753 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005754
5755 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005756 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005757 T.start;
5758 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005759 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005760 }
5761 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005763 }
5764 [] PCU.receive { repeat; }
5765 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005767 }
5768 }
5769 }
5770 setverdict(pass);
5771}
5772
Harald Welted66c9b82019-05-25 09:03:15 +02005773/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5774testcase TC_pcu_time_ind() runs on test_CT {
5775 var PCUIF_send_data pcu_sd;
5776 var integer num_time_ind := 0;
5777 var integer first_fn, last_fn;
5778 var float test_duration := 5.0;
5779 timer T;
5780
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005781 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005782 f_TC_pcu_act_req(0, 0, 7, true);
5783
5784 PCU.clear;
5785 T.start(test_duration);
5786 alt {
5787 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5788 num_time_ind := num_time_ind + 1;
5789 if (not isbound(first_fn)) {
5790 first_fn := pcu_sd.data.u.time_ind.fn;
5791 }
5792 last_fn := pcu_sd.data.u.time_ind.fn;
5793 repeat;
5794 }
5795 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5796 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5797 repeat;
5798 }
5799 [] PCU.receive {
5800 repeat;
5801 }
5802 [] T.timeout {}
5803 }
5804 var integer fn_expired := last_fn - first_fn;
5805 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5806
5807 /* verify the number of frames expired matches our expectation */
5808 const float c_GSM_FN_DURATION_MS := 4.61538;
5809 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005810 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005811 if (not match(fn_expired, t_fn_expected)) {
5812 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5813 }
5814
5815 /* There are three TIME.ind in every fn MOD 13 */
5816 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5817 /* Add some tolerance */
5818 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5819 if (not match(num_time_ind, t_time_ind_exp)) {
5820 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5821 }
5822
5823 setverdict(pass);
5824}
5825
Harald Welte4832c862019-05-25 14:57:18 +02005826/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5827testcase TC_pcu_rts_req() runs on test_CT {
5828 var PCUIF_send_data pcu_sd;
5829 var integer first_fn, last_fn;
5830 var integer num_rts_pdtch := 0;
5831 var integer num_rts_ptcch := 0;
5832 var float test_duration := 5.0;
5833 timer T;
5834
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005835 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005836 f_TC_pcu_act_req(0, 0, 7, true);
5837
5838 PCU.clear;
5839 T.start(test_duration);
5840 alt {
5841 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5842 -> value pcu_sd {
5843 num_rts_pdtch := num_rts_pdtch + 1;
5844 if (not isbound(first_fn)) {
5845 first_fn := pcu_sd.data.u.rts_req.fn;
5846 }
5847 last_fn := pcu_sd.data.u.rts_req.fn;
5848 repeat;
5849 }
5850 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5851 -> value pcu_sd {
5852 num_rts_ptcch := num_rts_ptcch + 1;
5853 if (not isbound(first_fn)) {
5854 first_fn := pcu_sd.data.u.rts_req.fn;
5855 }
5856 last_fn := pcu_sd.data.u.rts_req.fn;
5857 repeat;
5858 }
5859 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5860 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5861 repeat;
5862 }
5863 [] PCU.receive {
5864 repeat;
5865 }
5866 [] T.timeout {}
5867 }
5868 var integer fn_expired := last_fn - first_fn;
5869 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5870 ", num_rts_ptcch=", num_rts_ptcch);
5871
5872 /* verify the number of frames expired matches our expectation */
5873 const float c_GSM_FN_DURATION_MS := 4.61538;
5874 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005875 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005876 if (not match(fn_expired, t_fn_expected)) {
5877 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5878 }
5879
5880 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5881 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5882 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5883 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5884 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5885 t_ptcch_exp);
5886 }
5887
5888 /* We have 12 PDTCH blocks every 52-multiframe */
5889 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5890 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5891 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5892 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5893 t_pdtch_exp);
5894 }
5895
5896 setverdict(pass);
5897}
5898
Harald Welte07bd2d22019-05-25 11:03:30 +02005899/* test for generating Abis side OML ALERT from the PCU */
5900testcase TC_pcu_oml_alert() runs on test_CT {
5901 var PCUIF_send_data pcu_sd;
5902 var integer num_time_ind := 0;
5903 var integer first_fn, last_fn;
5904 var float test_duration := 5.0;
5905 timer T;
5906
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005907 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005908 f_TC_pcu_act_req(0, 0, 7, true);
5909
5910 /* re-connect CTRL port from BTS to BSC */
5911 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005912 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005913
5914 /* Send that OML Alert */
5915 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5916
5917 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5918 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5919 setverdict(pass);
5920}
5921
Harald Welteeaa9a862019-05-26 23:01:08 +02005922/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5923private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5924 var PCUIF_Message first_info;
5925 var integer pcu_conn_id := -1;
5926 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5927 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5928 var OCT4 tlli := '01020304'O;
5929 var OCT1 cause := '23'O;
5930 timer T := 5.0;
5931
5932 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5933
5934 f_l1_tune(L1CTL);
5935 RSL.clear;
5936
5937 f_est_dchan();
5938 L1CTL.clear;
5939
5940 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5941
5942 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5943 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5944 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5945
5946 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5947 T.start;
5948 alt {
5949 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5950 setverdict(pass);
5951 }
5952 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5953 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5954 }
5955 [] PCU.receive {
5956 repeat;
5957 }
5958 [] T.timeout {
5959 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5960 }
5961 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005962
5963 /* release the channel */
5964 f_rsl_chan_deact();
5965 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5966 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005967}
5968testcase TC_pcu_rr_suspend() runs on test_CT {
5969 var ConnHdlrPars pars;
5970 var ConnHdlr vc_conn;
5971
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005972 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005973
5974 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5975 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5976 vc_conn.done;
5977}
Harald Welte07bd2d22019-05-25 11:03:30 +02005978
Harald Weltea2e0e942019-05-27 18:12:53 +02005979/* Ensure that PCUIF socket can accept only a single connection */
5980testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005981 var boolean connected := false;
5982 var UD_connect_result cr;
5983 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005984 timer T := 5.0;
5985
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005986 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5987 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5988
Harald Weltea2e0e942019-05-27 18:12:53 +02005989 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005990 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005991
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005992 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005993 PCU.send(UD_connect:{mp_pcu_socket, -1});
5994 T.start;
5995 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005996 /* the IUT will first accept() the new connection, and close() it immediately */
5997 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5998 log("BTS has accept()ed connection");
5999 connected := true;
6000 cid := cr.id;
6001 repeat;
6002 }
6003 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6004 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006005 setverdict(pass);
6006 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006007 /* ignore other messages related to the first connection */
6008 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006009 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006010 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006011 }
6012 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006013
Harald Weltea2e0e942019-05-27 18:12:53 +02006014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6015}
6016
Harald Weltec8effb72019-05-27 18:23:04 +02006017/* Ensure that PCUIF socket can disconnect + reconnect */
6018testcase TC_pcu_socket_reconnect() runs on test_CT {
6019 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006020 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006021
6022 f_sleep(1.0);
6023
6024 f_pcuif_close(PCU, g_pcu_conn_id);
6025 g_pcu_conn_id := -1;
6026
6027 f_sleep(1.0);
6028
6029 /* re-connect */
6030 PCU.clear;
6031 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6032 setverdict(pass);
6033
6034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6035}
6036
Harald Weltebe030482019-05-27 22:29:35 +02006037/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006038private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6039runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006040 var L1ctlDlMessage l1_dl;
6041 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006042 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006043 timer T := 5.0;
6044 T.start;
6045 alt {
6046 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006047 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6048 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006049 repeat;
6050 }
6051 }
6052 [] pt.receive {
6053 repeat;
6054 }
6055 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6057 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006058 }
6059 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006060 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006061}
6062
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006063/* Check if GPRS Indicator is present in RR System Information of a given type */
6064private function f_si_has_gprs_indicator(RrMessageType si_type)
6065runs on test_CT return boolean {
6066 var SystemInformation si := f_get_si(L1CTL, si_type);
6067
6068 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006069 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006070 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006071 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006072 }
6073
6074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6075 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006076}
6077
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006078/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6079private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6080runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006081 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006082 f_init_l1ctl();
6083 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006084 f_sleep(2.0);
6085 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006086
6087 if (f_si_has_gprs_indicator(si_type)) {
6088 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006089 } else {
6090 setverdict(pass);
6091 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006092
Harald Weltebe030482019-05-27 22:29:35 +02006093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6094}
6095
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006096testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6097 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6098}
Harald Weltebe030482019-05-27 22:29:35 +02006099
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006100testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6101 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6102}
6103
6104/* Ensure that GPRS capability is advertised after PCU socket connect */
6105private function f_TC_pcu_socket_connect(RrMessageType si_type)
6106runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006107 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006108 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006109 f_init_l1ctl();
6110 f_l1_tune(L1CTL);
6111
6112 f_sleep(2.0);
6113 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006114
6115 if (not f_si_has_gprs_indicator(si_type)) {
6116 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006117 } else {
6118 setverdict(pass);
6119 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006120
Harald Weltebe030482019-05-27 22:29:35 +02006121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6122}
6123
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006124testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6125 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6126}
Harald Weltebe030482019-05-27 22:29:35 +02006127
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006128testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6129 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6130}
6131
6132/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6133private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6134runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006135 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006136 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006137 f_init_l1ctl();
6138 f_l1_tune(L1CTL);
6139
6140 f_pcuif_close(PCU, g_pcu_conn_id);
6141 g_pcu_conn_id := -1;
6142
6143 f_sleep(1.0);
6144
6145 /* re-connect */
6146 PCU.clear;
6147 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6148
6149 f_sleep(2.0);
6150 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006151
6152 if (f_si_has_gprs_indicator(si_type)) {
6153 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006154 } else {
6155 setverdict(pass);
6156 }
6157
6158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6159}
6160
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006161testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6162 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6163}
6164
6165testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6166 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6167}
6168
Oliver Smithf5239c72019-08-28 10:01:25 +02006169/* 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) */
6170testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6171 var SystemInformation si3 := valueof(ts_SI3_default);
6172
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006173 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006174
Harald Welte76220222020-10-11 20:32:44 +02006175 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6176 * information */
6177 timer T := 2.0;
6178 T.start;
6179 alt {
6180 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6181 [] T.timeout {}
6182 }
6183
Oliver Smithf5239c72019-08-28 10:01:25 +02006184 /* Verify cell_id */
6185 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6186 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6187 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006188 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6189 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6190 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006191 }
6192
6193 /* Verify LAC */
6194 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6195 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6196 if (lac_si3 != lac_pcu) {
6197 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6198 }
6199
6200 setverdict(pass);
6201}
Harald Welted66c9b82019-05-25 09:03:15 +02006202
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006203/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6204testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6205 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006206 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006207
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006208 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006209
6210 info_ind := g_pcu_last_info.u.info_ind;
6211
6212 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6213 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006214 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006215 /* Skip inactive timeslots */
6216 continue;
6217 }
6218
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006219 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006220 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006221 else
6222 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006223
6224 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006225 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006226 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006227 hsn := fhp.maio_hsn.hsn,
6228 maio := fhp.maio_hsn.maio,
6229 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006230 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006231 } else {
6232 tr_ts := tr_PCUIF_InfoTrxTsH0;
6233 }
6234
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006235 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006236 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6237 if (not match(ts, tr_ts)) {
6238 setverdict(fail, "Hopping parameters do not match: ",
6239 "received ", ts, " vs expected ", tr_ts);
6240 } else {
6241 setverdict(pass);
6242 }
6243 }
6244 }
6245}
6246
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006247/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006248testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6249 f_init_vty_bsc();
6250 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6251 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6252
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006253 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006254
6255 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006256 var template PCUIF_RemoteAddr tr_remote_addr := {
6257 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006258 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006259 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006260
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006261 if (not match(remote_addr, tr_remote_addr)) {
6262 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006263 }
6264
6265 setverdict(pass);
6266}
6267
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006268/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006269testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6270 f_init_vty_bsc();
6271 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6272
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006273 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006274
6275 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006276 var template PCUIF_RemoteAddr tr_remote_addr := {
6277 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6278 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6279 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006280
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006281 if (not match(remote_addr, tr_remote_addr)) {
6282 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006283 }
6284
6285 setverdict(pass);
6286}
6287
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006288/* Verify coding of two NSVCs in the INFO.ind message */
6289testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6290 f_init_vty_bsc();
6291
6292 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6293 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6294 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6295 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6296
6297 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6298 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6299 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6300 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6301
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006302 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006303
6304 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6305 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6306 var template PCUIF_RemoteAddr tr_remote_addr := {
6307 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006308 addr := {
6309 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6310 f_inet6_addr("fd00::ca:ff:ee")
6311 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006312 };
6313
6314 if (not match(info_ind.nsvci, { 1234, 5678 }))
6315 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6316 if (not match(remote_addr, tr_remote_addr))
6317 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6318 if (not match(info_ind.local_port, { 1234, 5678 }))
6319 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6320 if (not match(info_ind.remote_port, { 1234, 5678 }))
6321 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6322
6323 setverdict(pass);
6324}
6325
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006326/* Verify periodic interference reports on PDCH */
6327testcase TC_pcu_interf_ind() runs on test_CT {
6328 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006329 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006330 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006331 var PCUIF_send_data sd;
6332 timer T;
6333
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006334 /* Set the averaging/reporting period to 480ms */
6335 f_init_vty_bsc();
6336 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6337 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6338
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006339 f_init_with_pcuif();
6340 f_TC_pcu_act_req(0, 0, 7, true);
6341
6342 /* We need trxcon for NOPE indications */
6343 f_init_l1ctl();
6344 f_l1_tune(L1CTL);
6345
6346 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006347 tr_interf_ind := tr_PCUIF_INTERF_IND(
6348 bts_nr := 0,
6349 trx_nr := 0,
6350 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006351 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006352 );
6353
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006354 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006355 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006356 /* The first interference report may contain unreliable values, so we ignore it */
6357 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6358 /* 4 SACCH periods => 4 reports (plus some guard time) */
6359 T.start(0.480 * 4.0 + 0.480 / 2.0);
6360 first := false;
6361 repeat;
6362 }
6363 /* Subsequent interference reports shall match our expectations */
6364 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006365 /* Check TDMA frame number period */
6366 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6367 setverdict(fail, "Odd TDMA frame number := ",
6368 sd.data.u.interf_ind.fn);
6369 }
6370 interf_ind_num := interf_ind_num + 1;
6371 if (interf_ind_num < 4)
6372 { repeat; }
6373 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006374 [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 +02006375 setverdict(fail, "Received unexpected interference report: ", sd.data);
6376 }
6377 [] PCU.receive { repeat; }
6378 [] T.timeout {
6379 setverdict(fail, "Timeout waiting for interference reports");
6380 }
6381 }
6382
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006383 /* Reset the averaging/reporting period back to default */
6384 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6385
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6387}
6388
Harald Welte3d04ae62018-04-04 20:29:05 +02006389/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006390 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006391 ***********************************************************************/
6392
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006393private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6394 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006395runs on ConnHdlr {
6396 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006397
6398 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006399 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006400 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6401 repeat;
6402 }
6403 }
6404}
6405
6406private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6407runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006408 /* Expect BTS to immediately acknowledge activation as PDCH */
6409 PCU.clear;
6410 f_rsl_chan_act(g_pars.chan_mode);
6411 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006412 timer T_wait := 2.0;
6413 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006414 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006415 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006416 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006417 [] T_wait.timeout {
6418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6419 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6420 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006421 }
6422 /* try to activate this PDCH from the PCU point of view */
6423 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6424 /* FIXME: is there a response? */
6425}
6426
6427private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6428runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006429 /* Send RSL CHAN REL (deactivate) */
6430 PCU.clear;
6431 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6432 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006433 timer T_wait := 2.0;
6434 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006435 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006436 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006437 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006438 [] T_wait.timeout {
6439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6440 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6441 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006442 }
6443 /* Emulate PCU asking BTS to deactivate PDCH */
6444 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6445 alt {
6446 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6447 setverdict(pass);
6448 }
6449 [] RSL.receive { repeat; }
6450 }
6451}
6452
6453/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006454private function f_TC_dyn_osmo_pdch_act_deact(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);
6464 f_sleep(3.0);
6465 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6466 setverdict(pass);
6467}
6468testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6469 var ConnHdlrPars pars;
6470 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006471 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006472
6473 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6474 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6475 vc_conn.done;
6476}
6477
6478/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006479private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006480 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006481 var integer pcu_conn_id := -1;
6482
6483 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6484
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006485 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6486 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6487 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006488 setverdict(pass);
6489}
6490testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6491 var ConnHdlrPars pars;
6492 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006493 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006494
6495 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6496 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6497 vc_conn.done;
6498}
6499
6500/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006501private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006502 var PCUIF_Message first_info;
6503 var integer ts_nr := g_chan_nr.tn;
6504 var integer trx_nr := 0;
6505 var integer bts_nr := 0;
6506 var integer pcu_conn_id := -1;
6507
6508 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6509
6510 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006511 /* Send a second Chan Activ and expect it to be NACKed */
6512 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6513 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006514 setverdict(pass);
6515}
6516testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6517 var ConnHdlrPars pars;
6518 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006519 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006520
6521 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6522 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6523 vc_conn.done;
6524}
6525
6526/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006527private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006528 var PCUIF_Message first_info;
6529 var integer ts_nr := g_chan_nr.tn;
6530 var integer trx_nr := 0;
6531 var integer bts_nr := 0;
6532 var integer pcu_conn_id := -1;
6533 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6534
6535 /* register for the TCH/F channel number */
6536 f_rslem_register(0, chan_nr);
6537
6538 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6539
6540 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6541 "RSL CHAN ACT");
6542 setverdict(pass);
6543}
6544testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6545 var ConnHdlrPars pars;
6546 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006547 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006548
6549 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6550 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6551 vc_conn.done;
6552}
6553
6554/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006555private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006556 var PCUIF_Message first_info;
6557 var integer ts_nr := g_chan_nr.tn;
6558 var integer trx_nr := 0;
6559 var integer bts_nr := 0;
6560 var integer pcu_conn_id := -1;
6561 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6562 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6563
6564 /* register for the TCH/H channel numbers */
6565 f_rslem_register(0, chan_nr[0]);
6566 f_rslem_register(0, chan_nr[1]);
6567
6568 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6569
6570 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6571 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6572 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6573 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6574 setverdict(pass);
6575}
6576testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6577 var ConnHdlrPars pars;
6578 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006579 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006580
6581 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6582 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6583 vc_conn.done;
6584}
6585
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006586/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6587private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6588 var PCUIF_Message first_info;
6589 var integer ts_nr := g_chan_nr.tn;
6590 var integer trx_nr := 0;
6591 var integer bts_nr := 0;
6592 var integer pcu_conn_id := -1;
6593 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6594 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6595 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6596 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6597 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6598 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6599 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6600 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6601
6602 /* register for the TCH/H channel numbers */
6603 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6604 f_rslem_register(0, chan_nr[i]);
6605 }
6606
6607 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6608
6609 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6610 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6611 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6612 }
6613 setverdict(pass);
6614}
6615testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6616 var ConnHdlrPars pars;
6617 var ConnHdlr vc_conn;
6618 f_init();
6619
6620 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6621 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6622 vc_conn.done;
6623}
6624
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006625/* Reproduce a race condition described in OS#5245 */
6626private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6627 f_rsl_chan_act(g_pars.chan_mode);
6628 f_sleep(1.0);
6629 f_rsl_chan_deact();
6630 setverdict(pass);
6631}
6632testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6633 var ConnHdlrPars pars[2];
6634 var ConnHdlr vc_conn[2];
6635 var TrxcMessage rsp;
6636
6637 f_init();
6638
6639 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6640 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6641 ts_TRXC_FAKE_TRXC_DELAY(200));
6642
6643 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6644 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6645 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6646 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6647 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6648 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6649 pars[i], l1ctl := false);
6650 }
6651
6652 /* Wait for all components to finish */
6653 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6654 vc_conn[i].done;
6655 }
6656
6657 /* Disable the artificial delay for TRXC RSP messages */
6658 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6659 ts_TRXC_FAKE_TRXC_DELAY(0));
6660}
6661testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6662 var ConnHdlrPars pars[8];
6663 var ConnHdlr vc_conn[8];
6664 var TrxcMessage rsp;
6665
6666 f_init();
6667
6668 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6669 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6670 ts_TRXC_FAKE_TRXC_DELAY(200));
6671
6672 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6673 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6674 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6675 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6676 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6677 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6678 pars[i], l1ctl := false);
6679 }
6680
6681 /* Wait for all components to finish */
6682 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6683 vc_conn[i].done;
6684 }
6685
6686 /* Disable the artificial delay for TRXC RSP messages */
6687 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6688 ts_TRXC_FAKE_TRXC_DELAY(0));
6689}
6690
Harald Welte9bbbfb52018-04-05 09:33:19 +02006691/***********************************************************************
6692 * IPA Style Dynamic Timeslot Support
6693 ***********************************************************************/
6694
6695private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6696runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006697 /* Expect BTS to immediately acknowledge activation as PDCH */
6698 PCU.clear;
6699 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6700 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006701 timer T_wait := 2.0;
6702 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006703 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006704 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006705 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006706 [] T_wait.timeout {
6707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6708 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6709 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006710 }
6711 /* try to activate this PDCH from the PCU point of view */
6712 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6713 /* FIXME: is there a response? */
6714
6715 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6716}
6717
6718private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6719runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006720 /* Send RSL CHAN REL (deactivate) */
6721 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6722 PCU.clear;
6723 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006724 timer T_wait := 2.0;
6725 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006726 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006727 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006728 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006729 [] T_wait.timeout {
6730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6731 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6732 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006733 }
6734 /* Emulate PCU asking BTS to deactivate PDCH */
6735 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6736 alt {
6737 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6738 setverdict(pass);
6739 }
6740 [] RSL.receive { repeat; }
6741 }
6742}
6743
6744/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006745private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006746 var PCUIF_Message first_info;
6747 var integer ts_nr := g_chan_nr.tn;
6748 var integer trx_nr := 0;
6749 var integer bts_nr := 0;
6750 var integer pcu_conn_id := -1;
6751
6752 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6753
6754 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6755 f_sleep(3.0);
6756 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6757
6758 setverdict(pass);
6759
6760}
6761testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6762 var ConnHdlrPars pars;
6763 var ConnHdlr vc_conn;
6764 f_init();
6765
6766 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6767 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6768 vc_conn.done;
6769}
6770
6771/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006772private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006773 var PCUIF_Message first_info;
6774 var integer ts_nr := g_chan_nr.tn;
6775 var integer trx_nr := 0;
6776 var integer bts_nr := 0;
6777 var integer pcu_conn_id := -1;
6778
6779 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6780
6781 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6782 "RSL CHAN ACT");
6783 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6784 "RF CHAN REL", true);
6785 setverdict(pass);
6786}
6787testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6788 var ConnHdlrPars pars;
6789 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006790 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006791
6792 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6793 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6794 vc_conn.done;
6795}
6796
6797/* 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 +07006798private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006799 var PCUIF_Message first_info;
6800 var integer ts_nr := g_chan_nr.tn;
6801 var integer trx_nr := 0;
6802 var integer bts_nr := 0;
6803 var integer pcu_conn_id := -1;
6804
6805 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6806
6807 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6808 "RSL CHAN ACT");
6809
6810 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6811 alt {
6812 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6813 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006815 }
6816 [] RSL.receive { repeat; }
6817 }
6818
6819 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6820 "RF CHAN REL", true);
6821 setverdict(pass);
6822}
6823testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6824 var ConnHdlrPars pars;
6825 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006826 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006827
6828 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6829 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6830 vc_conn.done;
6831}
6832
6833/* 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 +07006834private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006835 var PCUIF_Message first_info;
6836 var integer ts_nr := g_chan_nr.tn;
6837 var integer trx_nr := 0;
6838 var integer bts_nr := 0;
6839 var integer pcu_conn_id := -1;
6840
6841 /* register for the TCH/F channel number */
6842 f_rslem_register(0, g_chan_nr);
6843
6844 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6845
6846 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6847
6848 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6849 "RSL CHAN ACT");
6850
6851 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6852
6853 setverdict(pass);
6854}
6855testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6856 var ConnHdlrPars pars;
6857 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006858 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006859
6860 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6861 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6862 vc_conn.done;
6863}
6864
6865
Harald Welte0472ab42018-03-12 15:02:26 +01006866/***********************************************************************
6867 * LAPDm / RLL related
6868 ***********************************************************************/
6869
6870private function f_tx_lapdm(template (value) LapdmFrame l,
6871 template (value) RslLinkId link_id) runs on ConnHdlr {
6872 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006873 var template (value) SacchL1Header l1h;
6874
6875 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006876 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006877 /* Compose dummy L1 header */
6878 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6879 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 +02006880 } else {
6881 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006882 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 +01006883 }
Harald Welte0472ab42018-03-12 15:02:26 +01006884}
6885
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006886friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006887 uint3_t sapi,
6888 RslLinkId link_id,
6889 octetstring l3,
6890 boolean exp
6891}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006892friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006893friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6894 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006895 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006896 sapi := sapi,
6897 link_id := id,
6898 l3 := l3,
6899 exp := exp
6900}
6901
6902/* execute the same callback function with a set of different parameters (tcs) on a
6903 * variety of logical channels */
6904private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6905 var ConnHdlrPars pars;
6906 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006907 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006908
6909 /* test on each of the channels we have */
6910 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6911 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6912
6913 /* test each of the test cases on the current channel */
6914 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6915 pars.spec.rll := tcs[j];
6916 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6917 vc_conn := f_start_handler(fn, pars);
6918 vc_conn.done;
6919 }
6920 }
6921
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006923}
6924
6925/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6926private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6927 var RllTestCase tc := g_pars.spec.rll;
6928 timer T := 3.0;
6929
6930 f_l1_tune(L1CTL);
6931 RSL.clear;
6932
6933 /* activate the logical channel */
6934 f_est_dchan();
6935 L1CTL.clear;
6936
6937 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6938 T.start;
6939 alt {
6940 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6941 if (tc.exp) {
6942 setverdict(pass);
6943 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006945 }
6946 }
6947 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6948 if (tc.exp) {
6949 setverdict(pass);
6950 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006952 }
6953 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006954 /* We also expect to receive the measurements */
6955 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006956 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006958 }
6959 [not tc.exp] T.timeout {
6960 setverdict(pass);
6961 }
6962 }
6963
6964 f_rsl_chan_deact();
6965 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6966 f_rslem_unregister(0, g_chan_nr);
6967}
6968testcase TC_rll_est_ind() runs on test_CT {
6969 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006970 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006971 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006972 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006973 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006974 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006975 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6976 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006977 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006978 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006979 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006980 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006981 };
6982 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6983}
6984
6985/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6986private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6987 var RllTestCase tc := g_pars.spec.rll;
6988 var L1ctlDlMessage dl;
6989 timer T := 3.0;
6990
6991 f_l1_tune(L1CTL);
6992 RSL.clear;
6993
6994 /* activate the logical channel */
6995 f_est_dchan();
6996 L1CTL.clear;
6997
6998 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6999 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
7000 T.start;
7001 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007002 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007003 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007005 }
7006 }
7007
7008 f_rsl_chan_deact();
7009 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7010 f_rslem_unregister(0, g_chan_nr);
7011}
7012testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7013 var RllTestCases tcs := {
7014 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007015 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007016 };
7017 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7018}
7019testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7020 var RllTestCases tcs := {
7021 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007022 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007023 }
7024 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7025}
7026
7027/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007028friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007029 var L1ctlDlMessage dl;
7030 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7031 var LapdmFrame lapdm;
7032 var octetstring l2 := dl.payload.data_ind.payload;
7033 if (dl.dl_info.link_id.c == SACCH) {
7034 /* remove L1 header */
7035 l2 := substr(l2, 2, lengthof(l2)-2);
7036 }
7037 if (ischosen(exp.ab)) {
7038 lapdm.ab := dec_LapdmFrameAB(l2);
7039 } else if (ischosen(exp.b4)) {
7040 lapdm.b4 := dec_LapdmFrameB4(l2);
7041 } else if (ischosen(exp.bbis)) {
7042 lapdm.bbis := dec_LapdmFrameBbis(l2);
7043 }
7044 log("Rx LAPDm ", lapdm);
7045 if (match(lapdm, exp)) {
7046 setverdict(pass);
7047 } else {
7048 repeat;
7049 }
7050 }
7051 [] L1CTL.receive { repeat; }
7052}
7053private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7054 timer T := t;
7055 T.start;
7056 alt {
7057 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007059 }
7060 [] as_l1_exp_lapdm(exp);
7061 }
7062}
7063
7064/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7065private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
7066 /* send SABM from MS -> BTS */
7067 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7068 /* expect RLL EST IND on Abis */
7069 alt {
7070 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7071 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7072 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007074 }
7075 [] RSL.receive { repeat; }
7076 }
7077 /* expect UA from BTS -> MS */
7078 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7079}
7080
7081/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7082private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7083 var RllTestCase tc := g_pars.spec.rll;
7084
7085 f_l1_tune(L1CTL);
7086 RSL.clear;
7087
7088 /* activate the logical channel */
7089 f_est_dchan();
7090 L1CTL.clear;
7091
7092 /* first establish the link-layer */
7093 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7094
7095 /* then send the DISC */
7096 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7097 /* ... and expect the REL IND on the RSL side */
7098 alt {
7099 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7100 setverdict(pass);
7101 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007102 /* We also expect to receive the measurements */
7103 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007104 }
7105
7106 /* release the channel */
7107 f_rsl_chan_deact();
7108 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7109 f_rslem_unregister(0, g_chan_nr);
7110}
7111testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7112 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007113 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007114 };
7115 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7116}
7117
7118testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7119 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007120 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007121 };
7122 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7123}
7124testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7125 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007126 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007127 };
7128 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7129}
7130testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7131 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007132 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007133 };
7134 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7135}
7136
7137/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7138private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7139 var RllTestCase tc := g_pars.spec.rll;
7140 f_l1_tune(L1CTL);
7141 RSL.clear;
7142
7143 /* activate the logical channel */
7144 f_est_dchan();
7145 L1CTL.clear;
7146
7147 /* first establish the link-layer */
7148 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7149
7150 /* then send the REL REQ via RSL */
7151 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7152 /* ... and expect the DISC on the Um side */
7153 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007154 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007155 /* FIXME: send a UA in resposne to the DISC */
7156 }
7157 }
7158
7159 /* release the channel */
7160 f_rsl_chan_deact();
7161 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7162 f_rslem_unregister(0, g_chan_nr);
7163}
7164testcase TC_rll_rel_req() runs on test_CT {
7165 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007166 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7167 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7168 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7169 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007170 };
7171 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7172}
7173
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007174/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007175testcase TC_rll_data_req() runs on test_CT {
7176}
7177
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007178/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007179testcase TC_rll_data_ind() runs on test_CT {
7180}
7181
7182/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7183private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7184 var RllTestCase tc := g_pars.spec.rll;
7185
7186 f_l1_tune(L1CTL);
7187 RSL.clear;
7188
7189 f_est_dchan();
7190 L1CTL.clear;
7191
7192 /* Send UNITDATA REQ on RSL side */
7193 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7194 /* Expect it to arrive on the other side */
7195 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007196 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007197 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007198 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007199 }
7200
7201 /* release the channel */
7202 f_rsl_chan_deact();
7203 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7204 f_rslem_unregister(0, g_chan_nr);
7205}
7206testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7207 var octetstring l3 := f_rnd_octstring(15);
7208 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007209 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7210 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007211 };
7212 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7213}
7214testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7215 var octetstring l3 := f_rnd_octstring(19);
7216 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007217 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7218 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007219 };
7220 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7221}
7222
7223/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7224private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7225 var RllTestCase tc := g_pars.spec.rll;
7226
7227 f_l1_tune(L1CTL);
7228 RSL.clear;
7229
7230 f_est_dchan();
7231 L1CTL.clear;
7232
7233 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007234 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007235 /* Expdct RLL UNITDATA IND on RSL side */
7236 alt {
7237 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7238 setverdict(pass);
7239 }
7240 [] RSL.receive { repeat; }
7241 }
7242
7243 /* release the channel */
7244 f_rsl_chan_deact();
7245 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7246 f_rslem_unregister(0, g_chan_nr);
7247}
7248testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007249 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007250 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007251 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7252 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007253 };
7254 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7255}
7256testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7257 var octetstring l3 := f_rnd_octstring(18);
7258 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007259 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7260 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007261 };
7262 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7263}
7264
Harald Weltee613f962018-04-18 22:38:16 +02007265/***********************************************************************
7266 * Encryption Related
7267 ***********************************************************************/
7268
7269/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007270private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007271 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7272 if (link_id.c == SACCH) {
7273 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7274 } else {
7275 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7276 }
7277}
7278
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007279/* Expect (or not expect) other kinds of messages */
7280private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7281 [exp_any] RSL.receive { repeat; }
7282 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007284 }
7285}
7286
Harald Weltee613f962018-04-18 22:38:16 +02007287/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007288private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007289 RslLinkId link_id,
7290 octetstring l3,
7291 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007292 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007293) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007294 timer T := 3.0;
7295 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7296 T.start;
7297 /* Expect RLL UNITDATA IND on RSL side */
7298 alt {
7299 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7300 setverdict(pass);
7301 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007302 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007303 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007304 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007306 }
Harald Weltee613f962018-04-18 22:38:16 +02007307 }
7308}
7309
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007310/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7311private function f_data_mo(
7312 RslLinkId link_id,
7313 boolean p, uint3_t nr, uint3_t ns,
7314 octetstring l3,
7315 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007316 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007317) runs on ConnHdlr {
7318 timer T := 3.0;
7319 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7320 T.start;
7321 /* Expect RLL DATA IND on RSL side */
7322 alt {
7323 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7324 setverdict(pass);
7325 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007326 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007327 [] as_rsl_any_ind(exp_any);
7328 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007330 }
7331 }
7332}
7333
Harald Weltee613f962018-04-18 22:38:16 +02007334/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007335private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007336 f_l1_tune(L1CTL);
7337 f_est_dchan(true);
7338
7339 /* now we actually need to transmit some data both ways to check if the encryption works */
7340 var L1ctlDlMessage dl;
7341
Stefan Sperling603d98e2018-07-25 16:47:28 +02007342 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007343 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7344
7345 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7346 f_unitdata_mt(link_id, l3);
7347
7348 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7349 f_unitdata_mo(link_id, l3);
7350
7351 /* release the channel */
7352 f_rsl_chan_deact();
7353 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7354 f_rslem_unregister(0, g_chan_nr);
7355}
7356testcase TC_chan_act_a51() runs on test_CT {
7357 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7358 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7359 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7360}
7361testcase TC_chan_act_a52() runs on test_CT {
7362 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7363 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7364 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7365}
7366testcase TC_chan_act_a53() runs on test_CT {
7367 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7368 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7369 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7370}
Eric Wildb9260392021-05-15 19:48:22 +02007371testcase TC_chan_act_a54() runs on test_CT {
7372 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7373 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7374 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7375}
Harald Weltee613f962018-04-18 22:38:16 +02007376
Eric Wildf1827a72019-05-28 17:37:35 +02007377/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7378 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 +07007379private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007380 f_l1_tune(L1CTL);
7381 f_est_dchan(true);
7382
7383 /* now we actually need to transmit some data both ways to check if the encryption works */
7384 var L1ctlDlMessage dl;
7385
7386 var octetstring l3 := f_rnd_octstring(20);
7387 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7388
7389 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7390 f_unitdata_mt(link_id, l3);
7391
7392 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7393 f_unitdata_mo(link_id, l3);
7394
7395 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007396 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007397
7398 /* modify key to break proper encryption */
7399 g_pars.encr.key := f_rnd_octstring(8);
7400 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7401 rsl.ies := rsl.ies & { ei };
7402 RSL.send(rsl);
7403
7404 timer T0 := 1.0;
7405 T0.start;
7406 /* Expect RSL MODIFY ACK */
7407 alt {
7408 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7409 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7411 }
7412 [] T0.timeout {
7413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7414 }
7415 }
7416
7417 var octetstring l3msg := f_rnd_octstring(15);
7418 timer T1 := 3.0;
7419 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7420 due to broken encryption */
7421 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7422 T1.start;
7423 alt {
7424 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7426 }
7427 [] T1.timeout {
7428 setverdict(pass);
7429 }
7430 }
7431
7432 /* release the channel */
7433 f_rsl_chan_deact();
7434 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7435 f_rslem_unregister(0, g_chan_nr);
7436}
7437testcase TC_rsl_modify_encr() runs on test_CT {
7438 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7439 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7440 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7441}
Harald Weltee613f962018-04-18 22:38:16 +02007442
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007443/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007444private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007445runs on test_CT {
7446 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7447 var ASP_RSL_Unitdata ud;
7448 timer T;
7449
7450 /* Intave is 6 SACCH periods by default */
7451 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7452
7453 T.start(Tval);
7454 alt {
7455 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7456 setverdict(pass);
7457 }
7458 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7459 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7460 }
7461 [] RSL_CCHAN.receive { repeat; }
7462 [] T.timeout {
7463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7464 "Timeout waiting for RF RESource INDication");
7465 }
7466 }
7467}
7468testcase TC_rsl_rf_resource_ind() runs on test_CT {
7469 var RSL_ResourceInfo info := { };
7470
7471 f_init(trx_nr := 0);
7472
7473 f_init_l1ctl();
7474 f_l1_tune(L1CTL);
7475
7476 /* g_AllChannels contains all logical channels */
7477 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7478 var RslChannelNr chan_nr := g_AllChannels[i];
7479
7480 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7481 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7482 { continue; }
7483
7484 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7485 }
7486
7487 /* Align to the first interference report */
7488 f_TC_rsl_rf_resource_ind(?);
7489
7490 /* Test 4 consecutive messages */
7491 for (var integer i := 0; i < 4; i := i + 1) {
7492 f_TC_rsl_rf_resource_ind(info);
7493 }
7494
7495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7496}
7497
Harald Weltee613f962018-04-18 22:38:16 +02007498/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007499private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007500 /* L3 payload doesn't matter, as it is passed transparently */
7501 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7502 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7503 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7504
7505 f_l1_tune(L1CTL);
7506
7507 /* first establish a dedicated channel in the clear */
7508 f_est_dchan(false);
7509
7510 /* Establish ABM */
7511 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7512
7513 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7514 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7515 /* expect the L3 to arrive still unencrypted on the MS side */
7516 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7517
7518 /* configure L1 to apply ciphering */
7519 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7520 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7521
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007522 /* send first ciphered I-frame in response and expect it on RSL */
7523 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007524
7525 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7526 * and hence enable encryption also on the downlink */
7527
7528 /* expect bi-directional communication work in encrypted mode */
7529 f_unitdata_mo(link_id, f_rnd_octstring(15));
7530 f_unitdata_mt(link_id, f_rnd_octstring(15));
7531
7532 /* release the channel */
7533 f_rsl_chan_deact();
7534 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7535 f_rslem_unregister(0, g_chan_nr);
7536}
7537testcase TC_encr_cmd_a51() runs on test_CT {
7538 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7539 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7540 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7541}
7542testcase TC_encr_cmd_a52() runs on test_CT {
7543 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7544 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7545 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7546}
7547testcase TC_encr_cmd_a53() runs on test_CT {
7548 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7549 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7550 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7551}
Eric Wildb9260392021-05-15 19:48:22 +02007552testcase TC_encr_cmd_a54() runs on test_CT {
7553 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7554 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7555 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7556}
Harald Weltee613f962018-04-18 22:38:16 +02007557
7558private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7559 var LapdmFrame lf;
7560 var octetstring reenc;
7561
7562 /* decode the LAPDm frame */
7563 if (ischosen(exp_match.ab)) {
7564 lf.ab := dec_LapdmFrameAB(enc);
7565 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007567 }
7568
7569 /* check if decoder result matches expectation */
7570 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007572 } else {
7573 log(name, ": matched");
7574 setverdict(pass);
7575 }
7576
7577 /* test if re-encoded frame equals original input */
7578 reenc := enc_LapdmFrame(lf);
7579 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007581 } else {
7582 setverdict(pass);
7583 }
7584}
7585
7586testcase TC_lapdm_selftest() runs on test_CT {
7587 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7588 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7589 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7590 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7591 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7592 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7593 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7594}
7595
Stefan Sperling4880be42018-08-07 18:12:59 +02007596/***********************************************************************
7597 * DTX Related (see GSM 05.08, section 8.3)
7598 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007599private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007600 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007601 var GsmFrameNumber first_fn;
7602 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007603 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007604 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007605 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7606 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007607 const integer frame_dtx_tchf_mod := 104;
7608 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7609 * which operates in terms of blocks rather than frames. */
7610 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7611 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007612 timer T := 5.0;
7613
7614 f_l1_tune(L1CTL);
7615 RSL.clear;
7616 L1CTL.clear;
7617
7618 /* activate TCHF signalling channel */
7619 f_est_dchan(false);
7620
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007621 /* A template for matching dummy LAPDm func=UA frames */
7622 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7623 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7624 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7625
Stefan Sperling4880be42018-08-07 18:12:59 +02007626 T.start;
7627 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007628 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007629 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007630
7631 if (is_first_frame) {
7632 is_first_frame := false;
7633 first_fn := dl.dl_info.frame_nr;
7634 }
7635
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007636 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007637 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007638 T.stop;
7639 f_rsl_chan_deact();
7640 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007641
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007642 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7643 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007644
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007645 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007646 setverdict(fail, "Not enough fill frames received: ",
7647 nfill_frames, " out of ", expected_fill_frames);
7648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007649 } else {
7650 setverdict(pass);
7651 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007652 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007653 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7654 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7655 * we should only see the subset of frames numbers which correspond to a block boundary.
7656 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7657 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7658 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007659 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007660 repeat;
7661 }
7662 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007663 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7664 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7665 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007666 f_rsl_chan_deact();
7667 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007668 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007669 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007670 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007671 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007672 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007673
7674 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007675 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7676 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007677 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7678 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7679 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007680 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7681 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007682 case else {
7683 /* This shall not happen, just to be sure */
7684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7685 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007686 }
7687
7688 f_rsl_chan_deact();
7689 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007690
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007691 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007692 setverdict(pass);
7693 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007694 setverdict(fail, "Not enough fill frames received: ",
7695 nfill_frames, " out of ", expected_fill_frames);
7696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007697 }
7698 } else {
7699 repeat;
7700 }
7701 }
7702 }
7703 [] L1CTL.receive { repeat; }
7704 [] T.timeout {
7705 f_rsl_chan_deact();
7706 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007708 }
7709 }
7710}
7711
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007712private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007713 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007714 var ConnHdlr vc_conn;
7715 var ConnHdlrPars pars;
7716 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007717 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007718 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007719 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007720 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007721 if (dtxd) {
7722 if (i >= 4) { /* DTX is only allowed on TCH/F */
7723 break;
7724 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007725 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007726 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007727 vc_conn.done;
7728 }
7729}
7730
7731/* Verify that L2 fill frames are sent on TCH in signaling mode if
7732 * there is nothing to transmit while DTX is disabled on downlink. */
7733testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7734 f_tch_sign_l2_fill_frame(false);
7735}
7736
7737/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7738 * there is nothing to transmit while DTX is enabled on downlink. */
7739testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7740 f_tch_sign_l2_fill_frame(true);
7741}
Harald Welte0472ab42018-03-12 15:02:26 +01007742
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007743testcase TC_chopped_ipa_ping() runs on test_CT {
7744 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7745}
7746
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007747testcase TC_chopped_ipa_payload() runs on test_CT {
7748 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7749}
7750
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007751
7752/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7753 * Return value: Measurement Report to be sent (encoded octetstring). */
7754type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7755 runs on ConnHdlr return octetstring;
7756
7757private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7758runs on ConnHdlr {
7759 var L1ctlDlMessage l1_dl;
7760 var SacchL1Header l1h;
7761 var octetstring l2;
7762
7763 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7764 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7765 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7766 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7767
7768 /* Pass it to the user specified call-back function */
7769 l2 := cb.apply(l1h, num_blocks);
7770 /* Send a Measurement Report generated by the call-back */
7771 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7772 l1_dl.dl_info.link_id,
7773 l1h, l2));
7774
7775 /* Shall we keep going? */
7776 num_blocks := num_blocks - 1;
7777 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7778 if (num_blocks > 0) { repeat; }
7779 }
7780 [] L1CTL.receive { repeat; }
7781}
7782
7783private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7784runs on ConnHdlr return octetstring {
7785 /* Command the L1 to apply received parameters */
7786 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7787
7788 /* Dummy measurement report (the results are invalid) */
7789 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7790}
7791
7792private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7793runs on ConnHdlr return octetstring {
7794 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7795 setverdict(fail, "Unexpected MS Power level change: ",
7796 g_pars.l1_pars.ms_power_level, " -> ",
7797 l1h.ms_power_lvl);
7798 }
7799
7800 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7801}
7802
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007803private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7804runs on ConnHdlr return octetstring {
7805 /* UL RSSI oscillation driven by SACCH block number */
7806 if (num_blocks rem 2 == 0) {
7807 f_trxc_fake_rssi(-100);
7808 } else {
7809 f_trxc_fake_rssi(-50);
7810 }
7811
7812 /* Make sure that MS power level remains constant */
7813 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7814}
7815
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007816/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7817private function f_TC_ms_pwr_ctrl_constant(charstring id)
7818runs on ConnHdlr {
7819 var integer num_blocks := 8;
7820 timer T := int2float(num_blocks);
7821
7822 f_l1_tune(L1CTL);
7823 RSL.clear;
7824
7825 /* These IEs are needed for autonomous MS power control */
7826 var template (value) RSL_IE_List ies := {
7827 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7828 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7829 }),
7830 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7831 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7832 })
7833 };
7834
7835 /* Ensure that 'rx-current' equals 'rx-target' */
7836 f_trxc_fake_rssi(mp_uplink_power_target);
7837
7838 /* Establish a dedicated channel */
7839 f_est_dchan(more_ies := valueof(ies));
7840
7841 L1CTL.clear;
7842 T.start;
7843 alt {
7844 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7845 [] T.timeout {
7846 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7847 num_blocks, " were not handled");
7848 }
7849 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007850
7851 /* Release the channel */
7852 f_rsl_chan_deact();
7853 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007854}
7855testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7856 var ConnHdlr vc_conn;
7857 var ConnHdlrPars pars;
7858
7859 f_init();
7860
7861 /* Explicitly configure the Uplink power target (in dBm) */
7862 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7863
7864 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7865 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7866 log(testcasename(), ": starting on ", pars.chan_nr);
7867
7868 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7869 pars, trxc_comp := true);
7870 vc_conn.done;
7871 }
7872
7873 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7875}
7876
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007877/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7878private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7879runs on ConnHdlr {
7880 var integer num_blocks := 16;
7881 timer T := int2float(num_blocks);
7882
7883 f_l1_tune(L1CTL);
7884 RSL.clear;
7885
7886 /* These IEs are needed for autonomous MS power control */
7887 var template (value) RSL_IE_List ies := {
7888 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7889 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7890 }),
7891 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7892 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7893 })
7894 };
7895
7896 /* Ensure that 'rx-current' equals 'rx-target' */
7897 f_trxc_fake_rssi(mp_uplink_power_target);
7898
7899 /* Establish a dedicated channel */
7900 f_est_dchan(more_ies := valueof(ies));
7901
7902 L1CTL.clear;
7903 T.start;
7904 alt {
7905 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7906 [] T.timeout {
7907 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7908 num_blocks, " were not handled");
7909 }
7910 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007911
7912 /* Release the channel */
7913 f_rsl_chan_deact();
7914 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007915}
7916testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7917 var ConnHdlr vc_conn;
7918 var ConnHdlrPars pars;
7919
7920 f_init();
7921
7922 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7923 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7924 /* Explicitly configure the Uplink power range (target and delte) */
7925 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7926 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7927
7928 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7929 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7930 log(testcasename(), ": starting on ", pars.chan_nr);
7931
7932 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7933 pars, trxc_comp := true);
7934 vc_conn.done;
7935 }
7936
7937 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7939}
7940
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007941private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7942 var template L1ctlDlMessage tr_bad_frame;
7943 var L1ctlDlMessage l1_dl;
7944 timer T := 8.0;
7945
7946 f_l1_tune(L1CTL);
7947 RSL.clear;
7948
7949 f_est_dchan();
7950
7951 /* There may be a few errors right after the channel activation */
7952 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7953 L1CTL.clear;
7954
7955 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7956 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7957 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7958 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7959 tr_bad_frame.payload := ?;
7960
7961 T.start;
7962 alt {
7963 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7964 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7965 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7966 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7967 }
7968 [] as_l1_sacch();
7969 [] L1CTL.receive { repeat; }
7970 [] T.timeout {
7971 /* We're done, break the loop */
7972 setverdict(pass);
7973 }
7974 }
7975
7976 f_rsl_chan_deact();
7977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7978}
7979testcase TC_speech_no_rtp_tchf() runs on test_CT {
7980 var ConnHdlr vc_conn;
7981 var ConnHdlrPars pars;
7982
7983 f_init();
7984
7985 /* TS1, TCH/F, V1 (FR codec) */
7986 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7987 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7988 vc_conn.done;
7989}
7990testcase TC_speech_no_rtp_tchh() runs on test_CT {
7991 var ConnHdlr vc_conn;
7992 var ConnHdlrPars pars;
7993
7994 f_init();
7995
7996 /* TS5, TCH/H, V1 (HR codec) */
7997 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7998 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7999 vc_conn.done;
8000}
8001
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008002/* Verify handling of Downlink and Uplink speech frames */
8003private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8004 var L1ctlDlMessage l1_dl;
8005 var PDU_RTP rtp_pdu;
8006 var octetstring pl;
8007 timer Td, Tu;
8008
8009 f_l1_tune(L1CTL);
8010 f_est_dchan();
8011
8012 /* Activate the RTP emulation */
8013 pl := f_rnd_octstring(6);
8014 f_rtpem_activate(pl);
8015
8016 /* Give the scheduler some time to fill up the buffers */
8017 f_sleep(2.0);
8018 L1CTL.clear;
8019 RSL.clear;
8020
8021 /* Make sure that Downlink frames are received at the UE */
8022 Td.start(2.0);
8023 alt {
8024 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8025 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8026 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8027 l1_dl.payload.traffic_ind.data));
8028 setverdict(pass);
8029 }
8030 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8031 setverdict(fail, "Rx unexpected Downlink speech frame ",
8032 "(", l1_dl.payload.traffic_ind.data, ") ",
8033 "expected (", pl, ")");
8034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8035 }
8036 [] as_l1_sacch();
8037 [] L1CTL.receive { repeat; }
8038 [] Td.timeout {
8039 setverdict(fail, "Timeout waiting for Downlink speech frames");
8040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8041 }
8042 }
8043
8044 /* Make sure that Uplink frames are received at the BTS */
8045 RTPEM_DATA.clear;
8046 Tu.start(2.0);
8047 alt {
8048 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8049 if (rtp_pdu.data != pl)
8050 { repeat; }
8051 }
8052 [] RTPEM_DATA.receive { repeat; }
8053 [] Tu.timeout {
8054 setverdict(fail, "Timeout waiting for Uplink speech frames");
8055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8056 }
8057 }
8058
8059 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8060 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8061 f_rsl_chan_deact();
8062 f_rslem_unregister(0, g_chan_nr);
8063}
8064testcase TC_speech_rtp_tchf() runs on test_CT {
8065 var ConnHdlr vc_conn;
8066 var ConnHdlrPars pars;
8067
8068 f_init();
8069
8070 /* TS1, TCH/F, V1 (FR codec) */
8071 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8072 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8073 vc_conn.done;
8074
8075 /* TS1, TCH/F, V2 (EFR codec) */
8076 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8077 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8078 vc_conn.done;
8079
8080 /* TODO: also test V3 (AMR codec) */
8081
8082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8083}
8084testcase TC_speech_rtp_tchh() runs on test_CT {
8085 var ConnHdlr vc_conn;
8086 var ConnHdlrPars pars;
8087
8088 f_init();
8089
8090 /* TS5, TCH/H0, V1 (HR codec) */
8091 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8092 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8093 vc_conn.done;
8094
8095 /* TODO: also test V3 (AMR codec) */
8096
8097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8098}
8099
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008100private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8101 var GsmFrameNumber fn;
8102 var ChannelDescription ch_desc;
8103 var integer ra := 23;
8104
8105 f_l1_tune(L1CTL);
8106 RSL.clear;
8107
8108 /* Send RACH request and wait for ChanReq */
8109 fn := f_rach_req_wait_chan_rqd(ra);
8110
8111 /* The BSC already sends the Immediate Assignment, before the channel is active.
8112 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8113 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8114 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8115 if (g_pars.fhp.enabled) {
8116 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8117 } else {
8118 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8119 }
8120 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8121 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8122
8123 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8124 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8125 var L1ctlDlMessage dl;
8126 var GsmRrMessage rr;
8127
8128 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8129 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8130 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8131 rr_imm_ass.payload.imm_ass.chan_desc := *;
8132
8133 timer T := 1.0;
8134 T.start;
8135 alt {
8136 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8137 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8138 if (match(rr, rr_imm_ass)) {
8139 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8140 mtc.stop;
8141 } else {
8142 repeat;
8143 }
8144 }
8145 [] L1CTL.receive { repeat; }
8146 [] T.timeout;
8147 }
8148 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8149 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8150
8151 /* Now expect the IMM ASS on Um */
8152 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8153 setverdict(pass);
8154
8155 /* Release the channel */
8156 f_rsl_chan_deact();
8157 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8158}
8159
8160testcase TC_early_immediate_assignment() runs on test_CT {
8161 var ConnHdlr vc_conn;
8162 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8163 f_init();
8164 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8165 vc_conn.done;
8166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8167}
8168
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008169private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8170 var integer ra := oct2int(f_rnd_ra_cs());
8171 var ChannelDescription ch_desc;
8172
8173 /* Tune the MS to BCCH */
8174 f_l1_tune(L1CTL);
8175
8176 /* Send RACH request and wait for ChanReq */
8177 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8178
8179 /* Activate channel on the BTS side */
8180 f_rsl_chan_act(g_pars.chan_mode);
8181
8182 /* Craft channel description (with or without frequency hopping parameters) */
8183 if (g_pars.fhp.enabled) {
8184 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8185 } else {
8186 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8187 }
8188
8189 /* Send IMM.ASS via CCHAN */
8190 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8191 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8192
8193 /* Receive IMM.ASS on the MS side */
8194 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8195
8196 /* Match the Channel Description IE in received IMM.ASS */
8197 if (not match(imm_ass.chan_desc, ch_desc)) {
8198 setverdict(fail, "Channel Description IE does not match");
8199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8200 }
8201
8202 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8203 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8204
8205 /* Expect SACCH frames on Downlink */
8206 L1CTL.clear;
8207 f_exp_sacch(true);
8208
8209 /* We're done, deactivate and release */
8210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8211 f_rsl_chan_deact();
8212}
8213testcase TC_est_dchan() runs on test_CT {
8214 var ConnHdlr vc_conn;
8215 var ConnHdlrPars pars;
8216
8217 f_init();
8218
8219 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8220 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8221 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8222 vc_conn.done;
8223 }
8224
8225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8226}
8227
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008228private type record TopTestCase {
8229 RSL_IE_BS_Power bs_power,
8230 RSL_IE_OSMO_TopAcchCap top_cap,
8231 record of TopTestStep steps
8232};
8233private type record TopTestStep {
8234 MeasurementResults meas_res optional,
8235 GsmRxLev overpower_sacch,
8236 GsmRxLev overpower_facch
8237};
8238
8239private function f_rxlev_match(template (present) RslLinkId link_id,
8240 template (present) GsmRxLev rxlev)
8241runs on ConnHdlr {
8242 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8243 if (not match(dl.dl_info.rx_level, rxlev)) {
8244 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8245 " does not match expected RxLev := ", rxlev);
8246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8247 }
8248}
8249
8250private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8251 var TopTestCase tc := g_pars.spec.top;
8252 var GsmRxLev rxlev_dcch;
8253 var L1ctlDlMessage dl;
8254
8255 /* Wait for Pau ramping to complete */
8256 f_sleep(6.0);
8257
8258 f_l1_tune(L1CTL);
8259 L1CTL.clear;
8260 RSL.clear;
8261
8262 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8263 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8264 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8265
8266 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8267 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8268
8269 /* Additional IEs for the CHANnel ACTIVation message */
8270 var template (value) RSL_IE_List ies := {
8271 /* Employ BS power control in static mode */
8272 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8273 bs_power := tc.bs_power
8274 }),
8275 /* Indicate the given Temporary Overpower capability */
8276 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8277 top_acch_cap := tc.top_cap
8278 })
8279 };
8280
8281 /* Establish a dedicated channel */
8282 f_est_dchan(more_ies := valueof(ies));
8283
8284 /* Give it some time to stabilize */
8285 f_sleep(0.480 * 2.0);
8286 L1CTL.clear;
8287 RSL.clear;
8288
8289 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8290 var TopTestStep step := tc.steps[i];
8291 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8292 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8293
8294 log("Executing step[", i, "] := ", step);
8295
8296 /* Send RR Measurement Report (if present) */
8297 if (ispresent(step.meas_res)) {
8298 f_transceive_meas_rep(step.meas_res);
8299 f_sleep(0.480 * 2.0);
8300 L1CTL.clear;
8301 }
8302
8303 /* Check RxLev on both FACCH and SACCH */
8304 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8305 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8306
8307 setverdict(pass);
8308 }
8309}
8310testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8311 var ConnHdlrPars pars;
8312 var ConnHdlr vc_conn;
8313
8314 f_init();
8315
8316 /* Verify lower and upper RxQual thresholds */
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 /* Worst possible RxQual value, overpower of 4dB */
8326 { meas_res := ts_MeasurementResults(rxq_f := 7),
8327 overpower_sacch := 4, overpower_facch := 4 },
8328 /* Worst possible RxQual value, disabling overpower */
8329 { meas_res := ts_MeasurementResults(rxq_f := 0),
8330 overpower_sacch := 0, overpower_facch := 0 },
8331
8332 /* Lower threshold not reached, no overpower */
8333 { meas_res := ts_MeasurementResults(rxq_f := 1),
8334 overpower_sacch := 0, overpower_facch := 0 },
8335 /* Lower threshold not reached, no overpower */
8336 { meas_res := ts_MeasurementResults(rxq_f := 2),
8337 overpower_sacch := 0, overpower_facch := 0 },
8338 /* Lower threshold reached, overpower of 4dB */
8339 { meas_res := ts_MeasurementResults(rxq_f := 4),
8340 overpower_sacch := 4, overpower_facch := 4 },
8341 /* Upper threshold not reached, keeping overpower */
8342 { meas_res := ts_MeasurementResults(rxq_f := 3),
8343 overpower_sacch := 4, overpower_facch := 4 },
8344 /* Upper threshold reached, disabling overpower */
8345 { meas_res := ts_MeasurementResults(rxq_f := 2),
8346 overpower_sacch := 0, overpower_facch := 0 }
8347 }
8348 };
8349
8350 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8351 spec := { top := top }, trx_nr := 1));
8352 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8353 vc_conn.done;
8354
8355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8356}
8357testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8358 var ConnHdlrPars pars;
8359 var ConnHdlr vc_conn;
8360
8361 f_init();
8362
8363 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008364 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008365 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8366 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8367 steps := {
8368 /* Channel established, no overpower */
8369 { meas_res := omit,
8370 overpower_sacch := 0, overpower_facch := 0 },
8371
8372 /* Invalid measurement results, no overpower */
8373 { meas_res := ts_MeasurementResults(rxq_f := 7,
8374 rxq_s := 7,
8375 valid := false),
8376 overpower_sacch := 0, overpower_facch := 0 },
8377
8378 /* DTXu was in use, no overpower */
8379 { meas_res := ts_MeasurementResults(rxq_f := 7,
8380 rxq_s := 0,
8381 dtx_used := true),
8382 overpower_sacch := 0, overpower_facch := 0 },
8383 /* DTXu was in use, overpower of 4 dB */
8384 { meas_res := ts_MeasurementResults(rxq_f := 0,
8385 rxq_s := 7,
8386 dtx_used := true),
8387 overpower_sacch := 4, overpower_facch := 4 }
8388 }
8389 };
8390
8391 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8392 spec := { top := top }, trx_nr := 1));
8393 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8394 vc_conn.done;
8395
8396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8397}
8398testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8399 var ConnHdlrPars pars;
8400 var ConnHdlr vc_conn;
8401
8402 f_init();
8403
8404 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008405 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008406 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8407 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8408 rxqual := 0, /* always on */
8409 sacch_enable := false),
8410 steps := {
8411 /* Channel established, FACCH overpower */
8412 { meas_res := omit,
8413 overpower_sacch := 0, overpower_facch := 4 },
8414 /* MS indicates good RxQual, no difference */
8415 { meas_res := ts_MeasurementResults(rxq_f := 0),
8416 overpower_sacch := 0, overpower_facch := 4 },
8417 /* MS indicates bad RxQual, no difference */
8418 { meas_res := ts_MeasurementResults(rxq_f := 7),
8419 overpower_sacch := 0, overpower_facch := 4 }
8420 }
8421 };
8422
8423 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8424 spec := { top := top }, trx_nr := 1));
8425 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8426 vc_conn.done;
8427
8428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8429}
8430testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8431 var ConnHdlrPars pars;
8432 var ConnHdlr vc_conn;
8433
8434 f_init();
8435
8436 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008437 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008438 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8439 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8440 rxqual := 0, /* always on */
8441 facch_enable := false),
8442 steps := {
8443 /* Channel established, SACCH overpower */
8444 { meas_res := omit,
8445 overpower_sacch := 4, overpower_facch := 0 },
8446 /* MS indicates good RxQual, no difference */
8447 { meas_res := ts_MeasurementResults(rxq_f := 0),
8448 overpower_sacch := 4, overpower_facch := 0 },
8449 /* MS indicates bad RxQual, no difference */
8450 { meas_res := ts_MeasurementResults(rxq_f := 7),
8451 overpower_sacch := 4, overpower_facch := 0 }
8452 }
8453 };
8454
8455 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8456 spec := { top := top }, trx_nr := 1));
8457 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8458 vc_conn.done;
8459
8460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8461}
8462testcase TC_acch_overpower_limit() runs on test_CT {
8463 var ConnHdlrPars pars;
8464 var ConnHdlr vc_conn;
8465
8466 f_init();
8467
8468 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008469 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008470 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8471 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8472 rxqual := 0 /* always on */),
8473 steps := {
8474 /* Channel established, ACCH overpower of 2dB */
8475 { meas_res := omit,
8476 overpower_sacch := 2, overpower_facch := 2 },
8477 /* MS indicates good RxQual, no difference */
8478 { meas_res := ts_MeasurementResults(rxq_f := 0),
8479 overpower_sacch := 2, overpower_facch := 2 },
8480 /* MS indicates bad RxQual, no difference */
8481 { meas_res := ts_MeasurementResults(rxq_f := 7),
8482 overpower_sacch := 2, overpower_facch := 2 }
8483 }
8484 };
8485
8486 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8487 spec := { top := top }, trx_nr := 1));
8488 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8489 vc_conn.done;
8490
8491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8492}
8493
Harald Welte0472ab42018-03-12 15:02:26 +01008494/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8495/* protocol error as per 44.006 */
8496/* link layer failure (repetition of I-frame N200 times without ACK */
8497/* repetition of SABM or DISC N200 times without ACK */
8498/* receptiom of SABM in multi-frame established state */
8499
8500
Harald Welte68e495b2018-02-25 00:05:57 +01008501/* TODO Areas:
8502
8503* channel activation
8504** with BS_Power / MS_Power, bypassing power control loop
8505** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008506** with timing advance from initial activation on
8507* mode modify
8508** encryption
8509** multirate
8510* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008511** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008512* BS Power Control
8513* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008514* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008515** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008516* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008517** DATA_IND from BTS->PCU
8518** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008519
8520*/
Harald Welte70767382018-02-21 12:16:40 +01008521
8522control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008523 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008524 execute( TC_chan_act_stress() );
8525 execute( TC_chan_act_react() );
8526 execute( TC_chan_deact_not_active() );
8527 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008528 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008529 execute( TC_sacch_filling() );
8530 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008531 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008532 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008533 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008534 execute( TC_sacch_chan_act_ho_async() );
8535 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008536 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008537 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008538 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008539 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008540 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008541 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008542 execute( TC_rach_load_idle_thresh0() );
8543 execute( TC_rach_load_idle_below_thresh() );
8544 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008545 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008546 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008547 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008548 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008549 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008550 execute( TC_meas_res_sign_tchf() );
8551 execute( TC_meas_res_sign_tchh() );
8552 execute( TC_meas_res_sign_sdcch4() );
8553 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008554 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008555 execute( TC_meas_res_speech_tchf_sapi3() );
8556 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008557 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008558 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008559 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008560 execute( TC_rsl_bs_pwr_static_ass() );
8561 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008562 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008563 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008564 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008565 execute( TC_rsl_ms_pwr_dyn_up() );
8566 execute( TC_rsl_ms_pwr_dyn_down() );
8567 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8568 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008569 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008570 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008571 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008572 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008573 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008574 execute( TC_paging_imsi_80percent() );
8575 execute( TC_paging_tmsi_80percent() );
8576 execute( TC_paging_imsi_200percent() );
8577 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008578 execute( TC_rsl_protocol_error() );
8579 execute( TC_rsl_mand_ie_error() );
8580 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008581 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008582 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008583 execute( TC_si_sched_2bis() );
8584 execute( TC_si_sched_2ter() );
8585 execute( TC_si_sched_2ter_2bis() );
8586 execute( TC_si_sched_2quater() );
8587 execute( TC_si_sched_13() );
8588 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008589 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008590 execute( TC_ipa_crcx_twice_not_active() );
8591 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008592 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008593 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008594 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008595
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008596 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008597 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008598 execute( TC_pcu_act_req() );
8599 execute( TC_pcu_act_req_wrong_ts() );
8600 execute( TC_pcu_act_req_wrong_bts() );
8601 execute( TC_pcu_act_req_wrong_trx() );
8602 execute( TC_pcu_deact_req() );
8603 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008604 execute( TC_pcu_ver_si1() );
8605 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008606 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008607 if (mp_l1_supports_gprs) {
8608 execute( TC_pcu_data_req_pdtch() );
8609 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008610 execute( TC_pcu_data_req_wrong_bts() );
8611 execute( TC_pcu_data_req_wrong_trx() );
8612 execute( TC_pcu_data_req_wrong_ts() );
8613 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008614 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008615 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008616 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008617 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008618 execute( TC_pcu_data_req_imm_ass_pch() );
8619 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008620 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008621 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008622 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008623 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008624 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008625 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008626 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008627 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008628 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008629 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008630 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008631 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008632 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008633 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008634 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008635 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008636 execute( TC_dyn_osmo_pdch_act_deact() );
8637 execute( TC_dyn_osmo_pdch_double_act() );
8638 execute( TC_dyn_ipa_pdch_act_deact() );
8639 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008640 execute( TC_pcu_info_ind_fh_params() );
8641 execute( TC_pcu_socket_nsvc_ipv4() );
8642 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008643 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008644 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008645 } else {
8646 log("PCU socket path not available, skipping PCU tests");
8647 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008648
Harald Welte3d04ae62018-04-04 20:29:05 +02008649 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008650 execute( TC_dyn_osmo_pdch_tchf_act() );
8651 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008652 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008653 execute( TC_dyn_ipa_pdch_tchf_act() );
8654 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008655
8656 execute( TC_rll_est_ind() );
8657 execute( TC_rll_est_req_DCCH_3() );
8658 execute( TC_rll_est_req_ACCH_3() );
8659 execute( TC_rll_rel_ind_DCCH_0() );
8660 execute( TC_rll_rel_ind_DCCH_3() );
8661 execute( TC_rll_rel_ind_ACCH_0() );
8662 execute( TC_rll_rel_ind_ACCH_3() );
8663 execute( TC_rll_rel_req() );
8664 execute( TC_rll_unit_data_req_DCCH() );
8665 execute( TC_rll_unit_data_req_ACCH() );
8666 execute( TC_rll_unit_data_ind_DCCH() );
8667 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008668
8669 execute( TC_chan_act_a51() );
8670 execute( TC_chan_act_a52() );
8671 execute( TC_chan_act_a53() );
8672 execute( TC_encr_cmd_a51() );
8673 execute( TC_encr_cmd_a52() );
8674 execute( TC_encr_cmd_a53() );
8675
Harald Welteee25aae2019-05-19 14:32:37 +02008676 execute( TC_err_rep_wrong_mdisc() );
8677 execute( TC_err_rep_wrong_msg_type() );
8678 execute( TC_err_rep_wrong_sequence() );
8679
Harald Weltee613f962018-04-18 22:38:16 +02008680 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008681
8682 execute( TC_tch_sign_l2_fill_frame() );
8683 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008684
8685 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008686 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008687
8688 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008689 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008690
8691 execute( TC_speech_no_rtp_tchf() );
8692 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008693 execute( TC_speech_rtp_tchf() );
8694 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008695
8696 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008697
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008698 execute( TC_acch_overpower_rxqual_thresh() );
8699 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8700 execute( TC_acch_overpower_always_on_facch() );
8701 execute( TC_acch_overpower_always_on_sacch() );
8702 execute( TC_acch_overpower_limit() );
8703
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008704 /* BEWARE: these test cases can potentially break the IUT or cause
8705 * weird/unexpected behavior. Ensure that they are executed last. */
8706 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8707 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008708}
8709
8710
8711}