blob: 6772cc5ccdbdd22896c4eb3dca42fe2e675c1c25 [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);
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +0700798 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300799
800 /* Send RR Measurement Report over the Um interface */
801 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
802
803 /* Expect MEASurement RESult on the A-bis/RSL interface */
804 T.start(2.0);
805 alt {
806 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
807 setverdict(pass);
808 }
809 [] RSL.receive { repeat; }
810 [] T.timeout {
811 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
813 }
814 }
815}
816
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700817friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
818 boolean encr_enable := false,
819 RSL_IE_List more_ies := {},
820 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
821runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200822 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200823 if (encr_enable) {
824 /* append encryption related IEs, if requested */
825 var RSL_IE_EncryptionInfo encr_info;
826 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
827 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
828encr_info})) };
829 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200830 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200831 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100832}
833
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700834friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100835 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 +0100836 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100837}
838
Harald Welte2f2b2b72019-05-31 22:24:57 +0200839friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200840 template RSL_IE_ChannelMode chan_mode,
841 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700842 uint8_t trx_nr := 0, float t_guard := 20.0) := {
843 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100844 chan_nr := valueof(chan_nr),
845 chan_mode := valueof(chan_mode),
846 t_guard := t_guard,
847 l1_pars := {
848 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100849 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100850 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100851 meas_ul := {
852 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200853 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100854 rxqual := 0
855 },
856 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200857 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100858 rxqual := 0
859 }
860 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200861 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100862 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200863 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200864 ms_actual_ta := mp_ms_actual_ta_exp,
865 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100866 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200867 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200868 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700869 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700870 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700871 fhp := {
872 enabled := false,
873 maio_hsn := ts_HsnMaio(0, 0),
874 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700875 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700876 }
Harald Welte70767382018-02-21 12:16:40 +0100877}
878
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300879/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
880 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
881private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
882 template (present) octetstring tr_data := ?,
883 template (present) RslChannelNr chan_nr := ?,
884 template (present) RslLinkId link_id := ?)
885runs on ConnHdlr {
886 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
887}
888
889/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
890 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
891private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
892 template (present) RslLinkId link_id := ?,
893 template (present) LapdmSapi sapi := ?,
894 boolean do_repeat := true)
895runs on ConnHdlr {
896 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
897 var L1ctlDlMessage dl_msg;
898
899 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
900 if (do_repeat) {
901 repeat;
902 }
903 }
904}
905
906/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
907 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
908private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
909 template (present) LapdmFrameAB tr_frame := ?,
910 template (present) RslLinkId link_id := ?)
911runs on ConnHdlr {
912 var L1ctlDlMessage dl_msg;
913
914 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
915 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
916 }
917}
918
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300919/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
920 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
921private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
922 template (present) LapdmFrameAB tr_frame := ?,
923 template (present) SacchL1Header tr_l1h := ?,
924 template (present) GsmSapi sapi := ?)
925runs on ConnHdlr {
926 var L1ctlDlMessage dl_msg;
927 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
928 template (present) L1ctlDataReq tr_data := {
929 l1header := tr_l1h,
930 l2_payload := decmatch tr_frame
931 };
932
933 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
934 var octetstring data := dl_msg.payload.data_ind.payload;
935 l1h := dec_SacchL1Header(substr(data, 0, 2));
936 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
937 }
938}
939
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300940/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
941 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
942 * payload is treated as PDU_ML3_NW_MS. */
943private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
944 template (present) PDU_ML3_NW_MS tr_pdu := ?,
945 template (present) GsmSapi sapi := 0)
946runs on ConnHdlr {
947 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
948 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
949 var LapdmFrameAB lapdm_frame;
950
951 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
952 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
953 }
954}
955
Harald Welte93640c62018-02-25 16:59:33 +0100956/***********************************************************************
957 * Channel Activation / Deactivation
958 ***********************************************************************/
959
Harald Welte70767382018-02-21 12:16:40 +0100960/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700961private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100962 for (var integer i := 0; i < 500; i := i+1) {
963 f_rsl_chan_act(g_pars.chan_mode);
964 f_rsl_chan_deact();
965 }
966 setverdict(pass);
967}
968testcase TC_chan_act_stress() runs on test_CT {
969 var ConnHdlr vc_conn;
970 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200971 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100972 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
973 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100975}
976
977/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700978private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100979 f_rsl_chan_act(g_pars.chan_mode);
980 /* attempt to activate the same lchan again -> expect reject */
981 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
982 alt {
983 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100985 }
986 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
987 setverdict(pass);
988 }
989 }
990 f_rsl_chan_deact();
991}
992testcase TC_chan_act_react() runs on test_CT {
993 var ConnHdlr vc_conn;
994 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100995 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100996 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
997 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100999}
1000
1001/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001002private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001003 timer T := 3.0;
1004 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1005 T.start;
1006 alt {
1007 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1008 setverdict(pass);
1009 }
1010 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001012 }
1013 }
1014}
1015testcase TC_chan_deact_not_active() runs on test_CT {
1016 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001017 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001018 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1019 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001021}
1022
1023/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001024private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001025 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1026 alt {
1027 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001029 }
1030 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1031 setverdict(pass);
1032 }
1033 }
1034}
1035private type record WrongChanNrCase {
1036 RslChannelNr chan_nr,
1037 charstring description
1038}
1039private type record of WrongChanNrCase WrongChanNrCases;
1040private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1041 chan_nr := chan_nr,
1042 description := desc
1043}
1044
1045testcase TC_chan_act_wrong_nr() runs on test_CT {
1046 var ConnHdlr vc_conn;
1047 var ConnHdlrPars pars;
1048
Harald Welte294b0a22018-03-10 23:26:48 +01001049 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001050
1051 var WrongChanNrCases wrong := {
1052 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1053 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1054 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1055 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1056 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1057 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1058 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1059 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1060 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1061 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1062 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1063 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1064 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1065 };
1066
1067 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1068 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1069 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1070 vc_conn.done;
1071 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001073}
1074
Harald Weltee613f962018-04-18 22:38:16 +02001075/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001076friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001077 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001078 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001079
1080 /* test on each of the channels we have */
1081 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1082 pars.chan_nr := valueof(g_AllChanTypes[i]);
1083
1084 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1085 vc_conn := f_start_handler(fn, pars);
1086 vc_conn.done;
1087 }
1088
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001090}
1091
Harald Welte93640c62018-02-25 16:59:33 +01001092/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001093 * SACCH handling
1094 ***********************************************************************/
1095
1096private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1097 timer T_sacch := 3.0;
1098 T_sacch.start;
1099 alt {
1100 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001102 }
1103 [not exp] T_sacch.timeout {
1104 setverdict(pass);
1105 }
1106 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1107 setverdict(pass);
1108 }
1109 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001111 }
1112 [] L1CTL.receive { repeat; }
1113 [] RSL.receive { repeat; }
1114 }
1115}
1116
1117/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1118private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1119 f_l1_tune(L1CTL);
1120 RSL.clear;
1121
1122 /* activate the logical channel */
1123 f_est_dchan();
1124 L1CTL.clear;
1125
1126 /* check that SACCH actually are received as expected */
1127 f_exp_sacch(true);
1128
1129 /* deactivate SACCH on the logical channel */
1130 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1131 f_sleep(1.0);
1132 L1CTL.clear;
1133
1134 /* check that no SACCH are received anymore */
1135 f_exp_sacch(false);
1136
1137 /* release the channel */
1138 f_rsl_chan_deact();
1139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1140}
1141testcase TC_deact_sacch() runs on test_CT {
1142 var ConnHdlr vc_conn;
1143 var ConnHdlrPars pars;
1144 f_init();
1145 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1146 //for (var integer i := 0; i < 1; i := i+1) {
1147 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1148 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1149 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1150 vc_conn.done;
1151 }
1152 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001154}
1155
Harald Welte55700662018-03-12 13:15:43 +01001156/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001157private function f_sacch_present(template octetstring l3_exp,
1158 boolean do_fail := true)
1159runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001160 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001161 timer T_sacch := 3.0;
1162 L1CTL.clear;
1163 T_sacch.start;
1164 alt {
1165 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1166 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1167 if (match(l3, l3_exp)) {
1168 setverdict(pass);
1169 } else {
1170 repeat;
1171 }
1172 }
1173 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001174 [not do_fail] T_sacch.timeout {
1175 log("Timeout waiting for SACCH ", l3_exp);
1176 }
1177 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001178 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001180 }
1181 }
1182}
1183
Harald Welte55700662018-03-12 13:15:43 +01001184/* verify that given SACCH payload is not present */
1185private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1186 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001187 timer T_sacch := 3.0;
1188 L1CTL.clear;
1189 T_sacch.start;
1190 alt {
1191 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1192 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1193 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001194 setverdict(fail, "Received unexpected SACCH ", dl);
1195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001196 } else {
1197 repeat;
1198 }
1199 }
1200 [] L1CTL.receive { repeat; }
1201 [] T_sacch.timeout {
1202 setverdict(pass);
1203 }
1204 }
1205}
1206
Harald Welte629cc6b2018-03-11 17:19:05 +01001207/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001208private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1209 /* Set a known default SACCH filling for SI5 */
1210 var octetstring si5 := f_rnd_octstring(19);
1211 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1212
1213 f_l1_tune(L1CTL);
1214 RSL.clear;
1215
1216 /* activate the logical channel */
1217 f_est_dchan();
1218
1219 /* check that the specified SI5 value is actually sent */
1220 f_sacch_present(si5);
1221
1222 /* release the channel */
1223 RSL.clear;
1224 f_rsl_chan_deact();
1225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1226}
1227testcase TC_sacch_filling() runs on test_CT {
1228 var ConnHdlr vc_conn;
1229 var ConnHdlrPars pars;
1230 f_init();
1231 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1232 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1233 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1234 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1235 vc_conn.done;
1236 }
1237 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001239}
1240
Harald Welte629cc6b2018-03-11 17:19:05 +01001241/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001242private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1243 /* Set a known default SACCH filling for SI5 */
1244 var octetstring si5 := f_rnd_octstring(19);
1245 var octetstring si5_diff := f_rnd_octstring(19);
1246 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1247
1248 f_l1_tune(L1CTL);
1249 RSL.clear;
1250
1251 log("Activating channel, expecting standard SI5");
1252 /* activate the logical channel */
1253 f_est_dchan();
1254 /* check that the specified SI5 value is actually sent */
1255 f_sacch_present(si5);
1256
1257 /* set channel-specific different SI5 */
1258 log("Setting channel specific SACCH INFO, expecting it");
1259 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1260 /* check that the specified lchan-specific value is now used */
1261 f_sacch_present(si5_diff);
1262
1263 /* deactivate the channel and re-activate it, this should result in default SI5 */
1264 log("De-activating and re-activating channel, expecting standard SI5");
1265 f_rsl_chan_deact();
1266 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1267 /* Verify that the TRX-wide default SACCH filling is present again */
1268 f_sacch_present(si5);
1269
1270 /* release the channel */
1271 RSL.clear;
1272 f_rsl_chan_deact();
1273 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1274}
1275testcase TC_sacch_info_mod() runs on test_CT {
1276 var ConnHdlr vc_conn;
1277 var ConnHdlrPars pars;
1278 f_init();
1279 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1280 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1281 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1282 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1283 vc_conn.done;
1284 }
1285 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001287}
1288
Harald Welte075d84c2018-03-12 13:07:24 +01001289/* Test SACCH scheduling of multiple different SI message types */
1290private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1291 var octetstring si5 := f_rnd_octstring(19);
1292 var octetstring si5bis := f_rnd_octstring(19);
1293 var octetstring si5ter := f_rnd_octstring(19);
1294 var octetstring si6 := f_rnd_octstring(19);
1295
1296 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1297 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1298 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1299 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1300
1301 f_l1_tune(L1CTL);
1302 RSL.clear;
1303
1304 /* activate the logical channel */
1305 f_est_dchan();
1306 L1CTL.clear;
1307
1308 /* check that SACCH actually are received as expected */
1309 f_sacch_present(si5);
1310 f_sacch_present(si5bis);
1311 f_sacch_present(si5ter);
1312 f_sacch_present(si6);
1313
1314 /* release the channel */
1315 f_rsl_chan_deact();
1316 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1317}
1318testcase TC_sacch_multi() runs on test_CT {
1319 var ConnHdlr vc_conn;
1320 var ConnHdlrPars pars;
1321 f_init();
1322 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1323 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1324 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1325 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1326 vc_conn.done;
1327 }
1328 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001330}
1331
Harald Welte55700662018-03-12 13:15:43 +01001332/* Test if SACH information is modified as expected */
1333private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1334 var octetstring si5 := f_rnd_octstring(19);
1335 var octetstring si6 := f_rnd_octstring(19);
1336
1337 /* First, configure both SI5 and SI6 to be transmitted */
1338 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1339 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1340
1341 f_l1_tune(L1CTL);
1342 RSL.clear;
1343
1344 /* activate the logical channel */
1345 f_est_dchan();
1346 L1CTL.clear;
1347
1348 /* check that SACCH actually are received as expected */
1349 f_sacch_present(si5);
1350 f_sacch_present(si6);
1351
1352 /* disable SI6 */
1353 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1354
1355 /* check that SI5 is still transmitted */
1356 f_sacch_present(si5);
1357 /* check if SI6 is now gone */
1358 f_sacch_missing(si6);
1359
1360 /* release the channel */
1361 f_rsl_chan_deact();
1362 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1363}
1364testcase TC_sacch_multi_chg() runs on test_CT {
1365 var ConnHdlr vc_conn;
1366 var ConnHdlrPars pars;
1367 f_init();
1368 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1369 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1370 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1371 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1372 vc_conn.done;
1373 }
1374 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001376}
1377
Harald Weltec8d363c2019-05-19 20:36:48 +02001378/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1379private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1380 var octetstring si5 := f_rnd_octstring(19);
1381 var octetstring si6 := f_rnd_octstring(19);
1382 var octetstring si5_specific := f_rnd_octstring(19);
1383 var octetstring si6_specific := f_rnd_octstring(19);
1384
1385 /* First, configure both SI5 and SI6 to be transmitted */
1386 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1387 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1388
1389 f_l1_tune(L1CTL);
1390 RSL.clear;
1391
1392 /* activate channel with different SACCH filling */
1393 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1394 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1395 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1396 }));
1397 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1398 RSL_IE_Body:{sacch_info := sacch_info})) };
1399 f_est_dchan(more_ies := addl_ies);
1400
1401 /* check that SACCH actually are received as expected */
1402 f_sacch_present(si5_specific);
1403 f_sacch_present(si6_specific);
1404
1405 /* release the channel */
1406 f_rsl_chan_deact();
1407 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1408}
1409testcase TC_sacch_chan_act() runs on test_CT {
1410 var ConnHdlr vc_conn;
1411 var ConnHdlrPars pars;
1412 f_init();
1413
1414 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1415 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1416 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1417 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1418 vc_conn.done;
1419 }
1420 /* TODO: do the above in parallel, rather than sequentially? */
1421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1422}
1423
Harald Welte8b01c792019-05-19 22:51:25 +02001424/* verify that SACCH DL transmission is started only if MS power IE present
1425 * see section 4.1.3 of 3GPP TS 48.058 */
1426private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1427 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001428 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001429
1430 f_l1_tune(L1CTL);
1431 RSL.clear;
1432
1433 /* Step 1: Activate ASYNC HO channel without MS power IE */
1434
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001435 var integer ho_ref := oct2int(f_rnd_octstring(1));
1436 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1437 RSL_IE_Body:{ handover_ref := ho_ref }));
1438 var RSL_IE_List addl_ies := {
1439 ho_ref_ie
1440 };
1441
Harald Welte8b01c792019-05-19 22:51:25 +02001442 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001443 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 +02001444 /* don't perform immediate assignment here, as we're testing non-IA case */
1445 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001446 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001447
1448 /* Verify that no DL SACCH is being received */
1449 f_sacch_missing(?);
1450
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001451 /* Send handover Access Burst and expect SACCH to start */
1452 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1453
1454 f_sacch_present(si5);
1455
Harald Welte8b01c792019-05-19 22:51:25 +02001456 f_rsl_chan_deact();
1457 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1458
1459
1460 /* Step 2: Activate ASYNC HO channel with MS power IE */
1461
1462 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001463 addl_ies := {
1464 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001465 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1466 };
1467 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1468 /* don't perform immediate assignment here, as we're testing non-IA case */
1469 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001470 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001471
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001472 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1473 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1474 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001475
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001476 /* Send handover Access Burst and expect SACCH to remain present */
1477 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1478
1479 f_sacch_present(si5);
1480
Harald Welte8b01c792019-05-19 22:51:25 +02001481 f_rsl_chan_deact();
1482 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1483}
1484testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1485 var ConnHdlr vc_conn;
1486 var ConnHdlrPars pars;
1487 f_init();
1488
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001489 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1490 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1491 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001492 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1493 vc_conn.done;
1494 }
1495 /* TODO: do the above in parallel, rather than sequentially? */
1496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1497}
1498
1499/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1500 * see section 4.1.4 of 3GPP TS 48.058 */
1501private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1502 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001503 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1504
Harald Welte8b01c792019-05-19 22:51:25 +02001505 var RSL_IE_List addl_ies;
1506
1507 f_l1_tune(L1CTL);
1508 RSL.clear;
1509
1510 /* Step 1: Activate SYNC HO channel without MS power IE */
1511
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001512 var integer ho_ref := oct2int(f_rnd_octstring(1));
1513 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1514 RSL_IE_Body:{ handover_ref := ho_ref }));
1515 addl_ies := {
1516 ho_ref_ie
1517 };
1518
Harald Welte8b01c792019-05-19 22:51:25 +02001519 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001520 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 +02001521 /* don't perform immediate assignment here, as we're testing non-IA case */
1522 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001523 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001524
1525 /* Verify that no DL SACCH is being received */
1526 f_sacch_missing(?);
1527
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001528 /* Send handover Access Burst and expect SACCH to start */
1529 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1530
1531 f_sacch_present(si5);
1532
Harald Welte8b01c792019-05-19 22:51:25 +02001533 f_rsl_chan_deact();
1534 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1535
1536
1537 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1538
1539 /* Activate channel on BTS side */
1540 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001541 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001542 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1543 };
1544 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1545 /* don't perform immediate assignment here, as we're testing non-IA case */
1546 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001547 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001548
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001549 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1550 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1551 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001552
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001553 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001554 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1555
1556 f_sacch_present(si5);
1557
Harald Welte8b01c792019-05-19 22:51:25 +02001558 f_rsl_chan_deact();
1559 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1560
1561
1562 /* Step 2b: Activate SYNC HO channel with TA IE */
1563
1564 /* Activate channel on BTS side */
1565 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001566 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001567 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1568 };
1569 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1570 /* don't perform immediate assignment here, as we're testing non-IA case */
1571 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001572 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001573
1574 /* Verify that no DL SACCH is being received */
1575 f_sacch_missing(?);
1576
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001577 /* Send handover Access Burst and expect SACCH to start */
1578 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1579
1580 f_sacch_present(si5);
1581
Harald Welte8b01c792019-05-19 22:51:25 +02001582 f_rsl_chan_deact();
1583 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1584
1585
1586 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1587
1588 /* Activate channel on BTS side */
1589 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001590 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001591 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1592 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1593 };
1594 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1595 /* don't perform immediate assignment here, as we're testing non-IA case */
1596 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001597 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001598
1599 /* Verify that DL SACCH is being received */
1600 f_sacch_present(si5);
1601
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001602 /* Send handover Access Burst and expect SACCH to remain present */
1603 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1604
1605 f_sacch_present(si5);
1606
Harald Welte8b01c792019-05-19 22:51:25 +02001607 f_rsl_chan_deact();
1608 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1609}
1610testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1611 var ConnHdlr vc_conn;
1612 var ConnHdlrPars pars;
1613 f_init();
1614
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001615 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1616 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1617 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001618 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1619 vc_conn.done;
1620 }
1621 /* TODO: do the above in parallel, rather than sequentially? */
1622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1623}
Harald Welte629cc6b2018-03-11 17:19:05 +01001624
1625
1626/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001627 * RACH Handling
1628 ***********************************************************************/
1629
Harald Welte8c24c2b2018-02-26 08:31:31 +01001630/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001631private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001632 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001633 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001634 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001635
Harald Welte8c24c2b2018-02-26 08:31:31 +01001636 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001637 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001638 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001639 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001640 if (emerg == true) {
1641 ra := f_rnd_ra_emerg();
1642 } else {
1643 ra := f_rnd_ra_cs();
1644 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001645 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1646 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001648 }
1649 fn_last := fn;
1650
1651 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001652 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001653 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001654 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001655 T.stop;
1656 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001657 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001659 }
1660 [] RSL_CCHAN.receive { repeat; }
1661 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001662 test_failed := true;
1663 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001664 }
1665 }
1666 }
Maxba06feb2019-03-05 10:52:46 +01001667 if (test_failed) {
1668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001669 }
Maxba06feb2019-03-05 10:52:46 +01001670 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001672}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001673
Philipp Maier16ade782020-07-08 21:36:00 +02001674/* Normal variant */
1675testcase TC_rach_content() runs on test_CT {
1676 f_TC_rach_content(emerg := false);
1677}
1678
1679/* Emergency call variant */
1680testcase TC_rach_content_emerg() runs on test_CT {
1681 f_TC_rach_content(emerg := true);
1682}
1683
Harald Welte8c24c2b2018-02-26 08:31:31 +01001684/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1685testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001686 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001687 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001688 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001689 f_l1_tune(L1CTL);
1690
1691 var GsmFrameNumber fn_last := 0;
1692 for (var integer i := 0; i < 1000; i := i+1) {
1693 var OCT1 ra := f_rnd_ra_cs();
1694 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1695 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001697 }
1698 fn_last := fn;
1699 }
1700 var integer rsl_chrqd := 0;
1701 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001702 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001703 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001704 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001705 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001706 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001707 repeat;
1708 }
1709 [] RSL_CCHAN.receive { repeat; }
1710 [] T.timeout { }
1711 }
1712 if (rsl_chrqd == 1000) {
1713 setverdict(pass);
1714 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001716 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001718}
1719
Harald Welte3453ab42019-05-24 21:19:58 +02001720private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1721 var charstring bts_str := "bts " & int2str(bts_nr);
1722 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1723}
1724
1725/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1726private template integer tr_rach_slots_per_interval := (90 .. 130);
1727
1728/* Expect 0 RACH load on an idle BTS that has just started up */
1729testcase TC_rach_load_idle_thresh0() runs on test_CT {
1730 var ASP_RSL_Unitdata rx_ud;
1731
1732 f_init_vty_bsc();
1733 /* send load indications even at 0% load */
1734 f_vty_load_ind_thresh(0);
1735 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1736 f_sleep(2.0);
1737
1738 f_init();
1739
Harald Weltee37f9a52020-10-11 20:45:23 +02001740 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1741 alt {
1742 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1743 [] RSL_CCHAN.receive { repeat }
1744 }
1745
Harald Welte3453ab42019-05-24 21:19:58 +02001746 timer T := 5.0;
1747 T.start;
1748 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001749 [] 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 +02001750 setverdict(pass);
1751 repeat;
1752 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001753 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001754 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1755 repeat;
1756 }
1757 [] RSL_CCHAN.receive {
1758 repeat;
1759 }
1760 [] T.timeout { }
1761 }
1762
1763 f_vty_load_ind_thresh(10);
1764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1765}
1766
1767/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1768testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1769 var ASP_RSL_Unitdata rx_ud;
1770
1771 f_init_vty_bsc();
1772 f_init();
1773
1774 timer T := 5.0;
1775 T.start;
1776 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001777 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001778 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1779 repeat;
1780 }
1781 [] RSL_CCHAN.receive {
1782 repeat;
1783 }
1784 [] T.timeout {
1785 setverdict(pass);
1786 }
1787 }
1788
1789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1790}
1791
1792/* Expect 0 RACH load on an idle BTS that has just started up */
1793testcase TC_rach_load_count() runs on test_CT {
1794 var ASP_RSL_Unitdata rx_ud;
1795 var integer load_access_count := 0;
1796
1797 f_init_vty_bsc();
1798 /* send load indications even at 0% load */
1799 f_vty_load_ind_thresh(0);
1800 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1801 f_sleep(2.0);
1802 f_init();
1803
1804 f_init_l1ctl();
1805 f_sleep(1.0);
1806 f_l1_tune(L1CTL);
1807
Harald Welte52ae1682020-10-11 20:45:55 +02001808 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1809 alt {
1810 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1811 [] RSL_CCHAN.receive { repeat }
1812 }
1813
Harald Welte3453ab42019-05-24 21:19:58 +02001814 var GsmFrameNumber fn_last := 0;
1815 for (var integer i := 0; i < 1000; i := i+1) {
1816 var OCT1 ra := f_rnd_ra_cs();
1817 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1818 if (fn == fn_last) {
1819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1820 }
1821 fn_last := fn;
1822 }
1823
1824 timer T := 5.0;
1825 T.start;
1826 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001827 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001828 -> value rx_ud {
1829 var RSL_IE_Body ie;
1830 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1831 load_access_count := load_access_count + ie.rach_load.access_count;
1832 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1833 setverdict(fail, "Access count cannot be < Busy count");
1834 }
1835 repeat;
1836 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001837 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001838 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1839 repeat;
1840 }
1841 [] RSL_CCHAN.receive {
1842 repeat;
1843 }
1844 [] T.timeout { }
1845 }
1846 if (load_access_count == 1000) {
1847 setverdict(pass);
1848 } else {
1849 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1850 }
1851
1852 f_vty_load_ind_thresh(10);
1853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1854}
1855
Harald Welte54a2a2d2018-02-26 09:14:05 +01001856private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001857 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001858 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001859 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001860 f_sleep(0.5);
1861
1862 /* Transmit RACH request + wait for confirmation */
1863 var OCT1 ra := f_rnd_ra_cs();
1864 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1865
1866 /* Check for expected result */
1867 timer T := 1.5;
1868 T.start;
1869 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001870 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001871 setverdict(pass);
1872 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001873 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001875 }
1876 [] RSL_CCHAN.receive { repeat; }
1877 [not expect_pass] T.timeout {
1878 setverdict(pass);
1879 }
1880 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001882 }
1883 }
1884}
1885
1886/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1887testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001888 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001889 f_init_l1ctl();
1890 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001891 f_sleep(1.0);
1892
1893 /* default max-ta is 63 (full range of GSM timing advance */
1894
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001895 /* We allow early arrival up to 2 symbols */
1896 f_rach_toffs(-1*256, true);
1897 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001898 f_rach_toffs(-10*256, false);
1899
1900 /* 0 / 32 / 63 bits is legal / permitted */
1901 f_rach_toffs(0, true);
1902 f_rach_toffs(32*256, true);
1903 f_rach_toffs(63*256, true);
1904
1905 /* more than 63 bits is not legal / permitted */
1906 f_rach_toffs(64*256, false);
1907 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001909}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001910
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001911private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001912 var GsmFrameNumber fn;
1913 var RSL_Message rm;
1914
1915 f_l1_tune(L1CTL);
1916 RSL.clear;
1917
1918 /* Generate a random Handover Reference */
1919 var integer ho_ref := oct2int(f_rnd_octstring(1));
1920
1921 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1922 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1923 RSL_IE_Body:{ handover_ref := ho_ref }));
1924
1925 /* Activate a channel on the BTS side (no encryption) */
1926 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1927 act_type := t_RSL_IE_ActType_HO_SYNC);
1928
1929 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1930 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001931 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001932
1933 /* Send handover Access Burst */
1934 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1935
1936 /* TODO: test mismatching Handover Reference, and missing IE */
1937
1938 /* Wait for handover detection */
1939 timer T := 3.0;
1940 T.start;
1941 alt {
1942 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1943 log("Handover RACH has been detected: ", rm);
1944 setverdict(pass);
1945 }
1946 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1948 log2str("RSL_CHAN_RQD was not expected: ", rm));
1949 }
1950 [] RSL.receive { repeat; }
1951 [] T.timeout {
1952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1953 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1954 }
1955 }
1956
1957 /* Release the channel */
1958 f_rsl_chan_deact();
1959 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1960}
1961
1962/* Test handover RACH detection */
1963testcase TC_ho_rach() runs on test_CT {
1964 var ConnHdlrPars pars;
1965 var ConnHdlr vc_conn;
1966
1967 f_init();
1968
1969 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1970 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1971 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1972 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1973 vc_conn.done;
1974 }
1975
1976 /* TODO: do the above in parallel, rather than sequentially? */
1977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1978}
1979
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03001980/* Test sending of the RR Physical Information message on DCCH */
1981private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
1982 var PDU_ML3_NW_MS dcch_pdu;
1983 var integer count := 0;
1984 var L1ctlDlMessage dl;
1985 timer T;
1986
1987 f_l1_tune(L1CTL);
1988 RSL.clear;
1989
1990 /* Generate a random Handover Reference */
1991 var integer ho_ref := oct2int(f_rnd_octstring(1));
1992
1993 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1994 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1995 RSL_IE_Body:{ handover_ref := ho_ref }));
1996
1997 /* Activate a channel on the BTS side (no encryption) */
1998 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1999 act_type := t_RSL_IE_ActType_HO_SYNC);
2000
2001 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2002 * waiting for Immediate Assignment and sending of an Access Burst. */
2003 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2004
2005 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2006 * context means any L2 frames, not only the RR Physical Information. */
2007 T.start(2.0);
2008 L1CTL.clear;
2009 alt {
2010 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2011 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2012 T.stop;
2013 }
2014 [] L1CTL.receive { repeat; }
2015 [] T.timeout { setverdict(pass); }
2016 }
2017
2018 /* Send handover Access Burst */
2019 log("Sending handover Access Burst");
2020 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2021
2022 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2023 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2024 L1CTL.clear;
2025 alt {
2026 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2027 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2028 log("Rx RR Physical Information: ", dcch_pdu);
2029 /* Wait until the count reaches Ny1 */
2030 count := count + 1;
2031 if (count < mp_ho_ny1)
2032 { repeat; }
2033 setverdict(pass);
2034 }
2035 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2036 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2038 }
2039 [] L1CTL.receive { repeat; }
2040 [] T.timeout {
2041 setverdict(fail, "Timeout waiting for RR Physical Information");
2042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2043 }
2044 }
2045
2046 /* Release the channel */
2047 f_rsl_chan_deact();
2048 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2049}
2050testcase TC_ho_physical_info() runs on test_CT {
2051 var ConnHdlrPars pars;
2052 var ConnHdlr vc_conn;
2053
2054 f_init();
2055
2056 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2057 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2058 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2059 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2060 vc_conn.done;
2061 }
2062
2063 /* TODO: do the above in parallel, rather than sequentially? */
2064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2065}
2066
Harald Welte93640c62018-02-25 16:59:33 +01002067/***********************************************************************
2068 * Measurement Processing / Reporting
2069 ***********************************************************************/
2070
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002071private template (value) LapdmAddressField
2072ts_LapdmAddr(template (value) LapdmSapi sapi,
2073 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002074 spare := '0'B,
2075 lpd := 0,
2076 sapi := sapi,
2077 c_r := c_r,
2078 ea := true
2079}
2080
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002081private template (value) LapdmFrameAB
2082ts_LAPDm_AB(template (value) LapdmSapi sapi,
2083 template (value) GsmRrL3Message l3,
2084 template (value) boolean c_r := false,
2085 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002086 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002087 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002088 len := 0, /* overwritten */
2089 m := false,
2090 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002091 payload := enc_GsmRrL3Message(valueof(l3)),
2092 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002093}
2094
2095/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002096private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002097 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002098 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002099
Harald Weltef8df4cb2018-03-10 15:15:08 +01002100 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002101 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002102
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002103 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002104 g_pars.l1_pars.meas_ul.full.rxlev,
2105 g_pars.l1_pars.meas_ul.sub.rxlev,
2106 g_pars.l1_pars.meas_ul.full.rxqual,
2107 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002108 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002109
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002110 var template (value) SacchL1Header l1h := ts_SacchL1Header(
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07002111 g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002112
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002113 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2114 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002115
2116 log("Sending Measurement Report: ", l1h, l2);
2117 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002118 repeat;
2119 }
2120}
2121
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002122/* handle incoming downlink SACCH, decode the L1 header into the given record */
2123private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2124 boolean do_apply := true)
2125runs on ConnHdlr
2126{
2127 var L1ctlDlMessage l1_dl;
2128
2129 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2130 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2131 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2132 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2133
2134 if (do_apply) {
2135 /* Update TA and MS power to follow what BTS requests */
2136 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2137 }
2138 }
2139}
2140
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002141private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002142 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002143 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002144 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2145 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002146 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2147 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002148 repeat;
2149 }
2150}
2151
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002152private altstep as_l1_tch_loop() runs on ConnHdlr {
2153 var L1ctlDlMessage l1_dl;
2154 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2155 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002156
2157 /* occasionaly inject FACCH frames into the uplink */
2158 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2159 var octetstring pl := '010301'O;
2160 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2161 f_pad_oct(pl, 23, '2B'O)));
2162 } else {
2163 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2164 l1_dl.payload.traffic_ind.data));
2165 }
2166
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002167 repeat;
2168 }
2169}
2170
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002171private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002172 uint6_t rxlev,
2173 uint3_t rxqual
2174}
2175
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002176private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002177 MeasElem full,
2178 MeasElem sub
2179}
2180
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002181private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002182 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002183 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002184 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002185 MeasElemFS meas_ul,
2186 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002187 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002188 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002189 uint8_t ms_actual_ta,
2190 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002191}
2192
2193/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2194private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2195 return 63 + (toffs256s/256);
2196}
2197
Harald Welted5684392018-03-10 18:22:04 +01002198private function f_max(integer a, integer b) return integer {
2199 if (a > b) {
2200 return a;
2201 } else {
2202 return b;
2203 }
2204}
2205
2206private function f_min(integer a, integer b) return integer {
2207 if (a < b) {
2208 return a;
2209 } else {
2210 return b;
2211 }
2212}
2213
2214/* compute negative tolerance val-tolerance, ensure >= min */
2215private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2216 val := val - tolerance;
2217 return f_max(val, min);
2218}
2219
2220/* compute positive tolerance val+tolerance, ensure <= max */
2221private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2222 val := val + tolerance;
2223 return f_min(val, max);
2224}
2225
2226/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2227private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2228return template integer {
2229 var template integer ret;
2230 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2231 return ret;
2232}
2233
2234
Harald Welte70767382018-02-21 12:16:40 +01002235/* build a template for matching measurement results against */
2236private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2237 var ConnL1Pars l1p := g_pars.l1_pars;
2238 var template RSL_IE_UplinkMeas ul_meas := {
2239 len := 3,
2240 rfu := '0'B,
2241 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002242 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002243 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002244 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002245 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002246 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2247 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002248 supp_meas_info := omit
2249 };
Harald Welte685d5982018-02-27 20:42:05 +01002250 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002251 ul_meas.len := (3+8);
2252 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002253 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002254 toa256_min := ?,
2255 toa256_max := ?,
2256 toa256_std_dev := ?
2257 }
Harald Welte685d5982018-02-27 20:42:05 +01002258 }
Harald Welte70767382018-02-21 12:16:40 +01002259 var template RSL_IE_BS_Power bs_power := {
2260 reserved := 0,
2261 epc := false,
2262 fpc := false,
2263 power_level := l1p.bs_power_level
2264 };
2265 var template RSL_IE_L1Info l1_info := {
2266 ms_power_lvl := l1p.ms_power_level,
2267 fpc := false,
2268 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002269 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002270 };
2271 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002272 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002273 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2274 ?, t_toffs);
2275}
2276
Philipp Maierdd841d32019-12-17 14:44:54 +01002277/* build a template for matching measurement results that do not contain any
2278 * MS related measurement (l1_info, l3_info and ms timing offset). */
2279private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2280 var ConnL1Pars l1p := g_pars.l1_pars;
2281 var template RSL_IE_UplinkMeas ul_meas := {
2282 len := 3,
2283 rfu := '0'B,
2284 dtx_d := l1p.dtx_enabled,
2285 rxlev_f_u := ?,
2286 reserved1 := '00'B,
2287 rxlev_s_u := ?,
2288 reserved2 := '00'B,
2289 rxq_f_u := ?,
2290 rxq_s_u := ?,
2291 supp_meas_info := omit
2292 };
2293 if (l1p.toa256_enabled) {
2294 ul_meas.len := (3+8);
2295 ul_meas.supp_meas_info := {
2296 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2297 toa256_min := ?,
2298 toa256_max := ?,
2299 toa256_std_dev := ?
2300 }
2301 }
2302 var template RSL_IE_BS_Power bs_power := {
2303 reserved := 0,
2304 epc := false,
2305 fpc := false,
2306 power_level := l1p.bs_power_level
2307 };
2308
2309 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2310}
2311
Harald Welte70767382018-02-21 12:16:40 +01002312/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002313private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002314 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002315 var boolean chan_est := false;
2316
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002317 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002318
2319 /* Receive osmocom specific measurement reports. This is the normal
2320 * case. Here we verify that the measurement reports we sent are
2321 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002322 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2323 /* increment counter of next to-be-expected meas rep */
2324 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2325 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002326 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002327
2328 /* The following two cases may only happen in the beginning
2329 * of the channel establishment phase. Once we have received
2330 * the "our" measurement report the first time, the channel
2331 * is established and empty or hardcoded TRXCON reports must
2332 * not occur anymore. */
2333 chan_est := true;
2334
2335 repeat;
2336 }
2337
2338 /* When the BTS has established the channel, the MS might need slightly
2339 * more time to establish the channel and actually start sending. The
2340 * result is then a measurement report that just lacks the measurement
2341 * information of the MS. This is normal and we tolerate this behavior. */
2342 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2343 /* increment counter of next to-be-expected meas rep */
2344 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2345 /* Re-start the timer expecting the next MEAS RES */
2346 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002347 repeat;
2348 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002349
2350 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2351 * measurements if the TTCN3 side does not supply measurement input in
2352 * time. In those cases TRXCON will either use a cached measurement
2353 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2354 * report the templates above will not match. We tolerate this
2355 * behavior, but only once. */
2356 [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 +01002357 /* increment counter of next to-be-expected meas rep */
2358 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2359 if (g_first_meas_res) {
2360 g_first_meas_res := false;
2361 repeat;
2362 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002364 }
Harald Welte70767382018-02-21 12:16:40 +01002365 }
2366 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002368 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002369 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002371 }
2372}
2373
Harald Weltee613f962018-04-18 22:38:16 +02002374private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2375 select (rsl_alg_id) {
2376 case (RSL_ALG_ID_A5_0) { return 0; }
2377 case (RSL_ALG_ID_A5_1) { return 1; }
2378 case (RSL_ALG_ID_A5_2) { return 2; }
2379 case (RSL_ALG_ID_A5_3) { return 3; }
2380 case (RSL_ALG_ID_A5_4) { return 4; }
2381 case (RSL_ALG_ID_A5_5) { return 5; }
2382 case (RSL_ALG_ID_A5_6) { return 6; }
2383 case (RSL_ALG_ID_A5_7) { return 7; }
2384 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2386 /* Make compiler happy by calling mtc.stop here. It is already
2387 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002388 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002389 }
2390 }
2391}
2392
2393private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2394 select (rsl_alg_id) {
2395 case (RSL_ALG_ID_A5_1) { return '000'B; }
2396 case (RSL_ALG_ID_A5_2) { return '001'B; }
2397 case (RSL_ALG_ID_A5_3) { return '010'B; }
2398 case (RSL_ALG_ID_A5_4) { return '011'B; }
2399 case (RSL_ALG_ID_A5_5) { return '100'B; }
2400 case (RSL_ALG_ID_A5_6) { return '101'B; }
2401 case (RSL_ALG_ID_A5_7) { return '110'B; }
2402 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2404 /* Make compiler happy by calling mtc.stop here. It is already
2405 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002406 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002407 }
2408 }
2409}
2410
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002411/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2412private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2413 var GsmFrameNumber fn;
2414 timer T := 8.0;
2415
2416 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2417 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2418
2419 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2420 /* Send the actual RACH */
2421 fn := f_L1CTL_RACH(L1CTL, ra);
2422
2423 T.start;
2424 alt {
2425 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2426 [] T.timeout {
2427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2428 }
2429 }
2430 T.stop
2431 return fn;
2432}
Harald Weltee613f962018-04-18 22:38:16 +02002433
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002434/* Tune to a dedicated channel: L1CTL only */
2435private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002436 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002437 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002438 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002439 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002440 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002441 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002442 pars.fhp.maio_hsn.hsn,
2443 pars.fhp.maio_hsn.maio,
2444 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002445 }
2446}
2447
Harald Welte70767382018-02-21 12:16:40 +01002448/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002449private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002450 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002451
2452 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002453 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002454
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002455 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002456 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002457 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002458 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002459 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2460 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002461 }
2462
Harald Welte70767382018-02-21 12:16:40 +01002463 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002464 f_l1ctl_est_dchan(L1CTL, g_pars);
2465
Harald Weltee613f962018-04-18 22:38:16 +02002466 /* enable encryption, if requested */
2467 if (encr_enable) {
2468 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2469 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2470 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002471
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002472 /* Send TCH Mode Request to the L1 if needed */
2473 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2474 var L1ctlTchMode tch_mode;
2475
2476 select (g_pars.chan_mode.coding_alg_rate) {
2477 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2478 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2479 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2480 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2481 case else {
2482 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2483 " is not supported by the L1, falling back to signalling");
2484 tch_mode := L1CTL_CHAN_MODE_SIGN;
2485 }
2486 }
2487
2488 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2489 }
2490
Harald Weltefa45e9e2018-03-10 18:59:03 +01002491 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002492}
2493
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002494/* Initialize and start the RTP emulation component for a ConnHdlr */
2495friend function f_rtpem_activate(inout octetstring payload,
2496 RtpemConfig cfg := c_RtpemDefaultCfg,
2497 RtpemMode mode := RTPEM_MODE_BIDIR)
2498runs on ConnHdlr {
2499 /* Step 0: initialize, connect and start the emulation component */
2500 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2501 map(vc_RTPEM:RTP, system:RTP);
2502 map(vc_RTPEM:RTCP, system:RTCP);
2503 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2504 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2505 vc_RTPEM.start(RTP_Emulation.f_main());
2506
2507 /* Step 1: configure the RTP parameters */
2508 var integer payload_len := 0;
2509 var octetstring hdr := ''O;
2510
2511 select (g_pars.chan_mode) {
2512 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2513 { payload_len := 33; hdr := 'D0'O; }
2514 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2515 { payload_len := 15; hdr := '00'O; }
2516 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2517 { payload_len := 31; hdr := 'C0'O; }
2518 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2519 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2521 }
2522 }
2523
2524 /* Pad the payload to conform the expected length */
2525 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2526 cfg.tx_fixed_payload := payload;
2527 f_rtpem_configure(RTPEM_CTRL, cfg);
2528
2529 /* Step 2: bind the RTP emulation to the configured address */
2530 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2531 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2532
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002533 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2534 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2535 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2536 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2537 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002538 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2539 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002540 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002541
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002542 /* Step 3b: send MDCX with the configured address/port to the IUT */
2543 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2544 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2545 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2546 remote_port := rtpem_bind_port,
2547 rtp_pt2 := 0),
2548 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2549 "IPA MDCX ACK");
2550
2551 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2552 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2553 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2554 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002555
2556 /* Step 5: set the given RTP emulation mode */
2557 f_rtpem_mode(RTPEM_CTRL, mode);
2558}
2559
Harald Welte70767382018-02-21 12:16:40 +01002560/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002561private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002562 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002563 RSL.clear;
2564
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002565 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002566 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002567 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002568 }
Harald Welte70767382018-02-21 12:16:40 +01002569
2570 f_est_dchan();
2571
2572 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2573 * RSL measurement reports on Abis side */
2574 timer T := 8.0;
2575 T.start;
2576 alt {
2577 [] as_l1_sacch();
2578 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002579 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002580 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002581 [] L1CTL.receive { repeat; }
2582 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002583 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002584 * of any earlier errors, so if we reach this timeout, we're good */
2585 setverdict(pass);
2586 }
2587 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002589 }
2590 }
2591 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002592 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002593}
Harald Welte0472ab42018-03-12 15:02:26 +01002594
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002595/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2596private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002597 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002598 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2599 timer Tup := 10.0;
2600 Tup.start;
2601 alt {
2602 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2603 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2604 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002605
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002606 if (rx_lvl != max_rx_lvl) {
2607 repeat;
2608 }
2609 Tup.stop;
2610 }
2611 [] L1CTL.receive { repeat; }
2612 [] Tup.timeout {
2613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2614 log2str("Didn't reach full power ", max_rx_lvl));
2615 }
2616 }
2617 return max_rx_lvl;
2618}
2619
2620/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2621private function f_verify_ramp_up() runs on ConnHdlr {
2622 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002623 var integer initial_rx_lvl := -1;
2624 var integer last_rx_lvl := -1;
2625 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2626
2627 timer T := 2.0;
2628 alt {
2629 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2630 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2631 log("Received rx_level=", rx_lvl);
2632 if (initial_rx_lvl == -1) {
2633 initial_rx_lvl := rx_lvl;
2634 last_rx_lvl := rx_lvl;
2635
2636 /* Expect a somehow low value during first received messages */
2637 if (initial_rx_lvl >= max_rx_lvl / 2) {
2638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2639 log2str("Detected high initial tx power during ramp up: ",
2640 initial_rx_lvl , ", full power is", max_rx_lvl));
2641 }
2642 }
2643
2644 /* received Rx level bigger than maximum allowed power by CN */
2645 if (rx_lvl > max_rx_lvl) {
2646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2647 log2str("Detected Tx power higher than full power: ",
2648 rx_lvl , " > ", max_rx_lvl));
2649 }
2650
2651 /* Make sure it never decreases, since we are rumping up */
2652 if (last_rx_lvl > rx_lvl) {
2653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2654 log2str("Detected Tx power decrease during ramp up: ",
2655 last_rx_lvl , " -> ", rx_lvl));
2656 }
2657
2658 if (rx_lvl == max_rx_lvl and not T.running) {
2659 /* We reached the maximum power, start timer and receive
2660 /* a few more to make sure we don't surpass it */
2661 log("Reached full power, wating a bit more until success");
2662 T.start;
2663 }
2664
2665 last_rx_lvl := rx_lvl;
2666 repeat;
2667 }
2668 [] L1CTL.receive { repeat; }
2669 [] T.timeout { }
2670 }
2671
2672 /* We didn't increase tx power during ramp up */
2673 if (initial_rx_lvl < last_rx_lvl) {
2674 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2675 } else {
2676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2677 log2str("No Tx power increase during whole ramp up: ",
2678 initial_rx_lvl , " -> ", last_rx_lvl));
2679 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002680}
2681
2682/* verify BTS ramps power down to rx_level 0 */
2683private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2684 var L1ctlDlMessage l1_dl;
2685 var integer last_rx_lvl := max_rx_lvl;
2686
2687 timer Tdown := 5.0;
2688 Tdown.start;
2689 alt {
2690 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2691 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2692 log("Received rx_level=", rx_lvl);
2693
2694 /* received Rx level bigger than maximum allowed power by CN */
2695 if (rx_lvl > max_rx_lvl) {
2696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2697 log2str("Detected Tx power higher than full power: ",
2698 rx_lvl , " > ", max_rx_lvl));
2699 }
2700
2701 /* Make sure it never increases, since we are rumping down */
2702 if (last_rx_lvl < rx_lvl) {
2703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2704 log2str("Detected Tx power increase during ramp up: ",
2705 last_rx_lvl , " -> ", rx_lvl));
2706 }
2707
2708 last_rx_lvl := rx_lvl;
2709 if (last_rx_lvl != 0) {
2710 repeat;
2711 }
2712 /* we reached power level 0, we are done */
2713 Tdown.stop;
2714 }
2715 [] L1CTL.receive { repeat; }
2716 [] Tdown.timeout { }
2717 }
2718
2719 /* We didn't increase tx power during ramp down */
2720 if (max_rx_lvl > last_rx_lvl) {
2721 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2722 } else {
2723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2724 log2str("No Tx power decrease during whole ramp down: ",
2725 max_rx_lvl , " -> ", last_rx_lvl));
2726 }
2727}
2728
2729/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002730private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002731 f_l1_tune(L1CTL);
2732 RSL.clear;
2733
2734 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002735
2736 setverdict(pass);
2737}
2738testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2739 var ConnHdlr vc_conn;
2740 var ConnHdlrPars pars;
2741 f_init();
2742 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2743 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2744 pcu_comp := false, trxc_comp := true);
2745 vc_conn.done;
2746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2747}
2748
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002749/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002750private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002751 f_connhdlr_init_vty_bsc();
2752
2753 f_l1_tune(L1CTL);
2754 RSL.clear;
2755
2756 /* Wait until BTS is started and at full power */
2757 var integer max_rx_lvl := f_wait_ramp_up();
2758 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2759
2760 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2761 f_verify_ramp_down(max_rx_lvl);
2762
2763 setverdict(pass);
2764}
2765testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2766 var ConnHdlr vc_conn;
2767 var ConnHdlrPars pars;
2768 f_init();
2769 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2770 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2771 pcu_comp := false, trxc_comp := true);
2772 vc_conn.done;
2773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2774}
2775
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002776/* Verify Tx power:
2777 * + ramping down during ADM state UNLOCKED->LOCKED
2778 * + ramping up during ADM state LOCKED->UNLOCKED
2779 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002780private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002781 var L1ctlDlMessage l1_dl;
2782 var integer last_rx_lvl;
2783
2784 f_connhdlr_init_vty_bsc();
2785
2786 f_l1_tune(L1CTL);
2787 RSL.clear;
2788
2789 /* Wait until BTS is started and at full power */
2790 var integer max_rx_lvl := f_wait_ramp_up();
2791 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2792
2793 log("ADM STATE UNLOCKED->LOCKED");
2794 f_vty_enter_cfg_trx(BSCVTY);
2795 f_vty_transceive(BSCVTY, "rf_locked 1");
2796 last_rx_lvl := max_rx_lvl;
2797 f_verify_ramp_down(max_rx_lvl);
2798
2799 /* Let some time after we received 0dBm, then check we don't receive BCCH
2800 * anymore because scheduler has stopped after ramping down */
2801 f_sleep(2.0);
2802 L1CTL.clear;
2803 timer Tlocked := 2.0;
2804 Tlocked.start;
2805 alt {
2806 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2808 log2str("Received data_ind during rf_locked: ", l1_dl));
2809 }
2810 [] L1CTL.receive { repeat; }
2811 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2812 }
2813
2814 log("ADM STATE LOCKED->UNLOCKED");
2815 f_vty_transceive(BSCVTY, "rf_locked 0");
2816 f_verify_ramp_up();
2817 setverdict(pass);
2818}
2819testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2820 var ConnHdlr vc_conn;
2821 var ConnHdlrPars pars;
2822 f_init();
2823 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2824 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2825 pcu_comp := false, trxc_comp := true);
2826 vc_conn.done;
2827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2828}
2829
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002830private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002831 timer T := 8.0;
2832 T.start;
2833 var RSL_Message rsl;
2834 alt {
2835 [] as_l1_sacch();
2836 [] L1CTL.receive { repeat; }
2837 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2838 if (rsl.ies[3].body.bs_power.power_level == level) {
2839 setverdict(pass)
2840 } else {
2841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2842 }
2843 }
2844 [] T.timeout {
2845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2846 }
2847 }
2848}
2849
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002850/* See if the RSL MEASurement RESult contains expeced BS power level
2851 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002852private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002853 f_l1_tune(L1CTL);
2854 RSL.clear;
2855
2856 if (mp_bts_trxc_port != -1) {
2857 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2858 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2859 }
2860
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002861 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002862 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2863 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2864
2865 f_est_dchan(more_ies :={valueof(pwr)});
2866
2867 f_check_meas_bs_power_level(pwr_var);
2868
2869 f_rsl_chan_deact();
2870 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2871}
2872
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002873/* See if the RSL MEASurement RESult contains expeced BS power level
2874 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002875private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002876 f_l1_tune(L1CTL);
2877 RSL.clear;
2878
2879 if (mp_bts_trxc_port != -1) {
2880 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2881 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2882 }
2883
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002884 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002885 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2886
2887 f_est_dchan();
2888
2889 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2890
2891 f_check_meas_bs_power_level(pwr_var);
2892
2893 f_rsl_chan_deact();
2894 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2895}
2896
2897testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2898 var ConnHdlr vc_conn;
2899 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002900
Eric Wildae8f2622019-06-18 17:05:11 +02002901 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002902
2903 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2904 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2905 pcu_comp := false, trxc_comp := true);
2906 vc_conn.done;
2907
Eric Wildae8f2622019-06-18 17:05:11 +02002908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2909}
2910
2911testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2912 var ConnHdlr vc_conn;
2913 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002914
Eric Wildae8f2622019-06-18 17:05:11 +02002915 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002916
2917 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2918 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2919 pcu_comp := false, trxc_comp := true);
2920 vc_conn.done;
2921
Eric Wildae8f2622019-06-18 17:05:11 +02002922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2923}
2924
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002925/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2926 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2927 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002928private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002929 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002930 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002931
2932 f_trxc_fake_rssi(rxlev2dbm(10));
2933 f_l1_tune(L1CTL);
2934 RSL.clear;
2935
2936 var RSL_IE_List addl_ies;
2937 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2938
2939 addl_ies := {
2940 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2941 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2942 };
2943
2944 /* establish with power parameters */
2945 f_est_dchan(more_ies := addl_ies);
2946
2947 /* set a high value to ensure L1 power control level increases */
2948 f_trxc_fake_rssi(rxlev2dbm(20));
2949
2950 timer T2 := 6.0;
2951 T2.start;
2952 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002953 [] as_l1_sacch_l1h(l1h) {
2954 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002955 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002956 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002957 T2.stop;
2958 }
2959 [] L1CTL.receive { repeat; }
2960 [] T2.timeout {
2961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2962 "Power Level in L1 header has not increased sufficiently");
2963 }
2964 }
2965
2966 /* set a low value to ensure L1 power control level decreases */
2967 f_trxc_fake_rssi(rxlev2dbm(0));
2968
2969 timer T4 := 6.0;
2970 T4.start;
2971 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002972 [] as_l1_sacch_l1h(l1h) {
2973 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002974 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002975 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002976 T4.stop;
2977 setverdict(pass, "Power level in L1 decreased/increased as expected");
2978 }
2979 [] L1CTL.receive { repeat; }
2980 [] T4.timeout {
2981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2982 "Power Level in L1 header has not decreased sufficiently");
2983 }
2984 }
2985
2986 f_rsl_chan_deact();
2987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2988
2989}
2990
2991/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002992private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002993 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002994 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002995
2996 /* set a low value to ensure power increases */
2997 f_trxc_fake_rssi(rxlev2dbm(10));
2998 f_l1_tune(L1CTL);
2999 RSL.clear;
3000
3001 var RSL_IE_List addl_ies;
3002 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3003
3004 addl_ies := {
3005 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3006 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3007 };
3008
3009 /* establish with power parameters */
3010 f_est_dchan(more_ies := addl_ies);
3011
3012 timer T1 := 10.0;
3013 T1.start;
3014 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003015 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003016 [] L1CTL.receive { repeat; }
3017 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003018 if (not isbound(l1h)) {
3019 setverdict(fail, "No SACCH blocks were received");
3020 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003021 setverdict(fail, "Power level in L1 header should not have changed");
3022 }
3023 }
3024 }
3025
3026 f_rsl_chan_deact();
3027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3028
3029}
3030
3031/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003032private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003033 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003034 var uint5_t pwr_var := 15;
3035 var uint5_t pwr_max_var := f_get_max_power_from_band();
3036
3037 /* set a low value to ensure power increases */
3038 f_trxc_fake_rssi(rxlev2dbm(10));
3039 f_l1_tune(L1CTL);
3040 RSL.clear;
3041
3042 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3043 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3044
3045 /* establish with fixed power level */
3046 f_est_dchan(more_ies :={valueof(pwr)});
3047
3048 /* check our initial power level */
3049 f_wait_for_l1_power_level(pwr_var);
3050
3051 /* update power param to enable power loop
3052 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3053 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3054
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003055 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3056 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3057 * Add an extra offset to avoid race conditions: +1.92s. */
3058 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003059 T1.start;
3060 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003061 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003062 [] L1CTL.receive { repeat; }
3063 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003064 if (not isbound(l1h)) {
3065 setverdict(fail, "No SACCH blocks were received");
3066 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003067 setverdict(pass, "Power level in L1 header reduced as expected");
3068 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003069 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3070 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003071 }
3072 }
3073 }
3074
3075 f_rsl_chan_deact();
3076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3077
3078}
3079
3080/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003081private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003082 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003083
3084 /* set a high value to ensure power decreases */
3085 f_trxc_fake_rssi(rxlev2dbm(50));
3086 f_l1_tune(L1CTL);
3087 RSL.clear;
3088
3089 var uint5_t pwr_var := 5;
3090 var uint5_t pwr_target_val := 15;
3091
3092 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3093 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3094
3095 /* establish with fixed power level */
3096 f_est_dchan(more_ies :={valueof(pwr)});
3097
3098 /* check our initial power level */
3099 f_wait_for_l1_power_level(pwr_var);
3100
3101 /* update power param to enable power loop
3102 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003103 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003104
3105 /* wait, then check that our power level was increased */
3106 timer T1 := 10.0;
3107 T1.start;
3108 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003109 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003110 [] L1CTL.receive { repeat; }
3111 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003112 if (not isbound(l1h)) {
3113 setverdict(fail, "No SACCH blocks were received");
3114 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3115 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003116 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003117 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003118 }
3119 }
3120 }
3121
3122 f_rsl_chan_deact();
3123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3124
3125}
3126
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003127/* See if the power level remains constant when MS Power Parameters IE
3128 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003129private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003130 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003131
3132 /* set a high value to ensure power decreases */
3133 f_trxc_fake_rssi(rxlev2dbm(50));
3134 f_l1_tune(L1CTL);
3135 RSL.clear;
3136
3137 var uint5_t pwr_var := 5;
3138
3139 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3140 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3141
3142 /* establish with fixed power level */
3143 f_est_dchan(more_ies :={valueof(pwr)});
3144
3145 /* check our initial power level */
3146 f_wait_for_l1_power_level(pwr_var);
3147
3148 /* wait, then check that our power level did not change */
3149 timer T1 := 10.0;
3150 T1.start;
3151 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003152 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3153 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3155 "BS power control should not be active unless we receive a power parameters IE!");
3156 }
3157 repeat;
3158 }
3159 [] L1CTL.receive { repeat; }
3160 [] T1.timeout { setverdict(pass); }
3161 }
3162
3163 f_rsl_chan_deact();
3164 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3165
3166}
3167
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003168/* See if the power level remains constant when MS Power Parameters IE
3169 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003170private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003171 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003172
3173 /* set a high value to ensure power decreases */
3174 f_trxc_fake_rssi(rxlev2dbm(50));
3175 f_l1_tune(L1CTL);
3176 RSL.clear;
3177
3178 var uint5_t pwr_var := 5;
3179
3180 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3181 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3182
3183 /* establish with fixed power level */
3184 f_est_dchan(more_ies :={valueof(pwr)});
3185
3186 /* check our initial power level */
3187 f_wait_for_l1_power_level(pwr_var);
3188
3189 /* pwr control without power params IE, should NOT activate MS power control*/
3190 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3191
3192 /* wait, then check that our power level did not change */
3193 timer T1 := 10.0;
3194 T1.start;
3195 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003196 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3197 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3199 "BS power control should not be active unless we receive a power parameters IE!");
3200 }
3201 repeat;
3202 }
3203 [] L1CTL.receive { repeat; }
3204 [] T1.timeout { setverdict(pass); }
3205 }
3206
3207 f_rsl_chan_deact();
3208 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3209
3210}
3211
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003212private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003213 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003214 timer T0 := 10.0;
3215 T0.start;
3216 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003217 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3218 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3220 "Power level in L1 header != signaled (RSL) power level.");
3221 }
3222 }
3223 [] L1CTL.receive { repeat; }
3224 [] T0.timeout {
3225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3226 "Timeout waiting for initial power level");
3227 }
3228 }
3229 T0.stop;
3230}
3231
3232private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3233 var IntegerRecord min_dbm_level;
3234 var IntegerRecord max_dbm_level;
3235 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3236
3237 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3238 if (min_dbm_level[i] == level) {
3239 return true;
3240 }
3241 }
3242 return false;
3243}
3244
3245private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3246 var IntegerRecord min_dbm_level;
3247 var IntegerRecord max_dbm_level;
3248 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3249
3250 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3251 if (max_dbm_level[i] == level) {
3252 return true;
3253 }
3254 }
3255 return false;
3256}
3257
3258private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3259 var IntegerRecord min_dbm_level;
3260 var IntegerRecord max_dbm_level;
3261 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3262 return max_dbm_level[0];
3263}
3264
3265type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003266private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003267private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3268 // 45.005 4.1.1
3269 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3270 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3271 2, 1, 0};
3272 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3273 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3274 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3275 var IntegerRecord rv;
3276
3277 select(band){
3278 case (BtsBand_allGSM){
3279 rv := gsm_power;
3280 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3281 max_dbm_level := {2, 1, 0};
3282 }
3283 case("DCS1800"){
3284 rv := dcs_power;
3285 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3286 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3287 }
3288 case("PCS1900"){
3289 rv := pcs_power;
3290 min_dbm_level := {15};
3291 max_dbm_level := {30};
3292 }
Harald Welte194b6912020-10-11 21:01:55 +02003293 case else {
3294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3295 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003296 }
3297
3298 return rv;
3299}
3300
3301private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003302 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 +02003303}
3304
3305testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3306 var ConnHdlr vc_conn;
3307 var ConnHdlrPars pars;
3308 f_init();
3309 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3310 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3311 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3312 pars.bts0_band := f_vty_get_bts0_band();
3313 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3314 vc_conn.done;
3315 }
3316 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3318}
3319
3320testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3321 var ConnHdlr vc_conn;
3322 var ConnHdlrPars pars;
3323 f_init();
3324 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3325 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3326 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3327 pars.bts0_band := f_vty_get_bts0_band();
3328 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3329 vc_conn.done;
3330 }
3331 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3333}
3334
3335testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3336 var ConnHdlr vc_conn;
3337 var ConnHdlrPars pars;
3338 f_init();
3339 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3340 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3341 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3342 pars.bts0_band := f_vty_get_bts0_band();
3343 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3344 vc_conn.done;
3345 }
3346 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3348}
3349
3350testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3351 var ConnHdlr vc_conn;
3352 var ConnHdlrPars pars;
3353 f_init();
3354 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3355 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3356 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3357 pars.bts0_band := f_vty_get_bts0_band();
3358 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3359 vc_conn.done;
3360 }
3361 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3363}
3364
Eric Wild280ccb82019-06-17 11:11:52 +02003365testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3366 var ConnHdlr vc_conn;
3367 var ConnHdlrPars pars;
3368 f_init();
3369 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3370 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3371 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3372 pars.bts0_band := f_vty_get_bts0_band();
3373 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3374 vc_conn.done;
3375 }
3376 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3378}
3379
Eric Wild095024b2019-06-17 15:08:57 +02003380testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3381 var ConnHdlr vc_conn;
3382 var ConnHdlrPars pars;
3383 f_init();
3384 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3385 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3386 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3387 pars.bts0_band := f_vty_get_bts0_band();
3388 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3389 vc_conn.done;
3390 }
3391 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3393}
3394
Philipp Maier149c3922020-10-22 17:29:36 +02003395function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003396 var template RSL_IE_ChannelMode ch_mode;
3397 var ConnHdlr vc_conn;
3398 var ConnHdlrPars pars;
3399 f_init();
3400 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3401 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3402 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003403 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003404 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3405 pcu_comp := false, trxc_comp := true);
3406 vc_conn.done;
3407 }
3408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3409}
Philipp Maier149c3922020-10-22 17:29:36 +02003410
3411testcase TC_meas_res_speech_tchf() runs on test_CT {
3412 f_TC_meas_res_speech_tchf(false);
3413}
3414
3415testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3416 f_TC_meas_res_speech_tchf(true);
3417}
3418
3419function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003420 var template RSL_IE_ChannelMode ch_mode;
3421 var ConnHdlr vc_conn;
3422 var ConnHdlrPars pars;
3423 f_init();
3424 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3425 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3426 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003427 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003428 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3429 pcu_comp := false, trxc_comp := true);
3430 vc_conn.done;
3431 }
3432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3433}
Philipp Maier149c3922020-10-22 17:29:36 +02003434
3435testcase TC_meas_res_speech_tchh() runs on test_CT {
3436 f_TC_meas_res_speech_tchh(false)
3437}
3438
3439testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3440 f_TC_meas_res_speech_tchh(true)
3441}
3442
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003443testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3444 var template RSL_IE_ChannelMode ch_mode;
3445 var ConnHdlr vc_conn;
3446 var ConnHdlrPars pars;
3447 f_init();
3448 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3449 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3450 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3451 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3452 pars.l1_pars.toa256_enabled := true;
3453 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3454 pcu_comp := false, trxc_comp := true);
3455 vc_conn.done;
3456 }
3457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3458}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003459
Harald Welte70767382018-02-21 12:16:40 +01003460testcase TC_meas_res_sign_tchf() runs on test_CT {
3461 var ConnHdlr vc_conn;
3462 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003463 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003464 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003465 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003466 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003467 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3468 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003469 vc_conn.done;
3470 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003472}
3473testcase TC_meas_res_sign_tchh() runs on test_CT {
3474 var ConnHdlr vc_conn;
3475 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003476 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003477 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003478 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003479 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003480 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3481 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003482 vc_conn.done;
3483 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003485}
3486testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3487 var ConnHdlr vc_conn;
3488 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003489 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003490 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003491 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3492 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003493 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3494 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003495 vc_conn.done;
3496 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003498}
3499testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3500 var ConnHdlr vc_conn;
3501 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003502 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003503 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003504 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3505 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003506 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3507 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003508 vc_conn.done;
3509 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003511}
Harald Welte685d5982018-02-27 20:42:05 +01003512testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3513 var ConnHdlr vc_conn;
3514 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003515 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003516 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3517 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003518 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003519 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003520 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3521 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003522 vc_conn.done;
3523 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003525}
3526
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003527/* Make sure that we always get RSL MEASurement RESult messages regardless
3528 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3529private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3530 timer Texec := 8.0;
3531 timer Timpf := 2.0;
3532 timer Tmr;
3533
3534 f_l1_tune(L1CTL);
3535 RSL.clear;
3536
3537 f_est_dchan();
3538 L1CTL.clear;
3539
3540 /* Establish the main SAPI=0 link on DCCH first */
3541 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3542
3543 /* Give more time for the first RSL MEASurement RESult */
3544 Tmr.start(0.480 * 2.0);
3545 Texec.start; /* EXECution timer */
3546 Timpf.start; /* IMPFung timer */
3547
3548 alt {
3549 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3550 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3551 /* Reschedule the MEAS RES timer */
3552 Tmr.start(0.480 + 0.120);
3553 repeat;
3554 }
3555 [] RSL.receive { repeat; }
3556 [] Tmr.timeout {
3557 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3558 }
3559 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3560 [] Timpf.timeout {
3561 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3562 log("Injected SAPI=3 traffic on SACCH");
3563 Timpf.start;
3564 repeat;
3565 }
3566 /* We're good if survived so far */
3567 [] Texec.timeout {
3568 setverdict(pass);
3569 }
3570 }
3571
3572 f_rsl_chan_deact();
3573 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3574 f_rslem_unregister(0, g_chan_nr);
3575}
3576testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3577 var template RSL_IE_ChannelMode ch_mode;
3578 var template ConnHdlrPars pars;
3579 var ConnHdlr vc_conn;
3580
3581 f_init();
3582
3583 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3584 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3585
3586 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3587 vc_conn.done;
3588
3589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3590}
3591testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3592 var template RSL_IE_ChannelMode ch_mode;
3593 var template ConnHdlrPars pars;
3594 var ConnHdlr vc_conn;
3595
3596 f_init();
3597
3598 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3599 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3600
3601 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3602 vc_conn.done;
3603
3604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3605}
3606
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003607/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3608 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003609private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003610 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003611 var RSL_IE_MS_Power ms_power;
3612 var RSL_Message rsl;
3613 var uint5_t power_level := 0;
3614
3615 f_l1_tune(L1CTL);
3616 RSL.clear;
3617
3618 f_est_dchan();
3619
3620 ms_power.reserved := 0;
3621 ms_power.fpc_epc := false;
3622
3623 /* Send the first power control command. This will disable any BTS/TRX
3624 * internal power control and switch the MS (which is not in scope of
3625 * this test) to a constant power level. We start with a power level
3626 * of 0 */
3627 ms_power.power_level := power_level;
3628 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3629 RSL.send(rsl);
3630
3631 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003632 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3633 if (l1h.ms_power_lvl != power_level) {
3634 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3635 "match the signaled (RSL) power level := ", power_level);
3636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003637 }
3638
3639 /* Signal a new power level via RSL for the next turn. */
3640 if (power_level < 31) {
3641 power_level := power_level + 1;
3642 ms_power.power_level := power_level;
3643 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3644 RSL.send(rsl);
3645 repeat;
3646 }
3647
3648 }
3649
3650 /* Ignore all other blocks */
3651 [] L1CTL.receive { repeat; }
3652
3653 }
3654
3655 f_rsl_chan_deact();
3656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3657
3658 setverdict(pass);
3659}
3660
3661testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3662 var ConnHdlr vc_conn;
3663 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003664 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003665
3666 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3667 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3668 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3669 vc_conn.done;
3670 }
3671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3672}
Harald Welte70767382018-02-21 12:16:40 +01003673
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003674/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003675TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003676private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003677 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003678 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003679
3680 f_l1_tune(L1CTL);
3681 RSL.clear;
3682
3683 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003684 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003685
3686 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3687
3688
3689 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003690 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3691 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003692 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3693 }
3694
3695 }
3696
3697 /* Ignore all other blocks */
3698 [] L1CTL.receive { repeat; }
3699
3700 }
3701
3702 f_rsl_chan_deact();
3703 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3704
3705 setverdict(pass);
3706}
3707
3708testcase TC_rsl_chan_initial_ta() runs on test_CT {
3709 var ConnHdlr vc_conn;
3710 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003711 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003712 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003713 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3714 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003715 vc_conn.done;
3716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3717}
3718
Eric Wilde57e1a62019-05-28 13:30:55 +02003719/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003720private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003721 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003722 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003723
3724 var RSL_IE_MS_Power ms_power;
3725 ms_power.reserved := 0;
3726 ms_power.fpc_epc := false;
3727 ms_power.power_level := ms_power_level;
3728
3729 f_l1_tune(L1CTL);
3730 RSL.clear;
3731
3732 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3733
3734 timer T := 1.0;
3735 T.start;
3736 alt {
3737 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003738 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3739 if (l1h.ms_power_lvl != ms_power_level) {
3740 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3741 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003742 }
3743 }
3744 /* Ignore all other blocks */
3745 [] L1CTL.receive { repeat; }
3746 [] T.timeout {
3747 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3748 }
3749 }
3750
3751 f_rsl_chan_deact();
3752 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3753 setverdict(pass);
3754}
3755
3756testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3757 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3758 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3759}
3760
Harald Welte0472ab42018-03-12 15:02:26 +01003761/* 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 +01003762private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003763 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003764 RSL.clear;
3765
3766 f_est_dchan();
3767 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003768 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003769
3770 timer T := 40.0;
3771 T.start;
3772 alt {
3773 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3774 setverdict(pass)
3775 }
3776 [] RSL.receive { repeat };
3777 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003779 }
3780 }
3781 f_rsl_chan_deact();
3782}
3783testcase TC_conn_fail_crit() runs on test_CT {
3784 var ConnHdlr vc_conn;
3785 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003786 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003787 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3788 pars.t_guard := 60.0;
3789 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3790 vc_conn.done;
3791}
3792
Harald Welte93640c62018-02-25 16:59:33 +01003793/***********************************************************************
3794 * Paging
3795 ***********************************************************************/
3796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003797private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003798 if (tmsi == 'FFFFFFFF'O) {
3799 return true;
3800 } else {
3801 return false;
3802 }
3803}
Harald Welte70767382018-02-21 12:16:40 +01003804
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003805private type record allowedFn { integer frame_nr }
3806private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3807private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3808private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3809private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3810private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3811private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3812private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3813private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3814private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003815{
3816 var integer frame_nr_51;
3817 frame_nr_51 := frame_nr mod 51
3818
3819 var allowedFn fn_check;
3820 fn_check.frame_nr := frame_nr_51;
3821
3822 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003824 return;
3825 }
3826
3827 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3828 return;
3829 }
3830 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3831 return;
3832 }
3833 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3834 return;
3835 }
3836 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3837 return;
3838 }
3839 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3840 return;
3841 }
3842 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3843 return;
3844 }
3845 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3846 return;
3847 }
3848 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3849 return;
3850 }
3851
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003853 return;
3854}
3855
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003856private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3857 inout integer num_paging_rcv_ids,
3858 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003859runs on test_CT {
3860 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003861 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003862 repeat;
3863 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003864 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003865 var octetstring without_plen :=
3866 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3867 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003868
3869 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3870
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003871 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3872 /* Ignore empty RR Paging Request (PCH filling) messages.
3873 * TODO: does it make sense to count them? */
3874 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003875 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3876 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003877 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003878 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3879 }
3880 } else if (match(rr, tr_PAGING_REQ2)) {
3881 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3882 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3883 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3884 }
3885 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3886 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3887 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003888 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003889 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3890 }
3891 } else if (match(rr, tr_PAGING_REQ3)) {
3892 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3893 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3894 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3895 }
3896 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3897 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3898 }
3899 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3900 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3901 }
3902 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3903 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3904 }
3905 }
3906 repeat;
3907 }
3908}
3909
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003910private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003911 boolean combined_ccch,
3912 integer bs_ag_blks_res,
3913 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003914 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3915 * paging command that is issued via RSL. */
3916 integer ps_load_modulus,
3917 /* Wait until the paging queue inside the BTS is congested before starting to add
3918 * pagings via the PCU socket (0 = disabled) */
3919 boolean ps_wait_cong,
3920 /* Maximum time to wait until the paging queue is drained at the end of the test.
3921 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3922 * to set this value to 18s, however the draining process may take significantly
3923 * longer when the queue contains paging requests for PS as those are implemented
3924 * as immediate assignments and require an entire MAC block alone. */
3925 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003926 boolean exp_load_ind,
3927 boolean exp_overload,
3928 boolean use_tmsi
3929}
3930
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003931private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003932 integer num_paging_sent,
3933 integer num_paging_rcv_msgs,
3934 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003935 integer num_overload,
3936 /* When free space inside the paging queue reaches more than 2 thirds
3937 * of its capacity cong_detected is set to true. */
3938 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003939}
3940
Harald Welte68e495b2018-02-25 00:05:57 +01003941/* Helper function for paging related testing */
3942private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003943 /* Using the PCU socket affects the timing of the paging processing. We only
3944 * activate the PCU socket if we do paging load tests that include additional
3945 * paging load that is introduced through the PCU socket. */
3946 if (cfg.ps_load_modulus > 0) {
3947 f_init_with_pcuif();
3948 } else {
3949 f_init();
3950 }
Harald Welte68e495b2018-02-25 00:05:57 +01003951 f_init_l1ctl();
3952 f_l1_tune(L1CTL);
3953
Philipp Maierca058272021-06-23 10:35:23 +02003954 var octetstring imm_ass := f_rnd_octstring(23);
3955 var ASP_RSL_Unitdata load_ind;
3956
Harald Welte68e495b2018-02-25 00:05:57 +01003957 var PagingTestState st := {
3958 num_paging_sent := 0,
3959 num_paging_rcv_msgs := 0,
3960 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003961 num_overload := 0,
3962 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003963 };
3964
3965 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3966 var float max_pch_imsi_per_sec;
3967 if (cfg.use_tmsi) {
3968 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3969 } else {
3970 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3971 }
3972 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3973 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003974 var float time_total := 20.0;
3975 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3976 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003977
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003978 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3979 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003980
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003981 timer T_itv := 0.0;
3982 T_itv.start;
3983 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003984 alt {
3985 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003986 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003987 st.num_overload := st.num_overload + 1;
3988 repeat;
3989 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003990 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003992 }
Philipp Maierca058272021-06-23 10:35:23 +02003993 [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 +01003994 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003995
3996 /* Detect paging congestion: The logic inside the BTS will diagnose the
3997 * paging queue as congested when the fill state is more than 66% (which
3998 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3999 * paging congestion is detected pagings that are issued through the PCU
4000 * socket (PS) are dropped in order to prefer the CS related pagings. */
4001 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4002 st.cong_detected := true;
4003 }
4004
Harald Welte68e495b2018-02-25 00:05:57 +01004005 /* FIXME: analyze/verify interval + contents */
4006 repeat;
4007 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004008 /* ignore other RSL messages like RF RESource INDication */
4009 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004010 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004011 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004012 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004013 /* Only relevant when testing including with PCU sock connected */
4014 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004015 [] T_itv.timeout {
4016 /* Send paging cmds based on elapsed time */
4017 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4018 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004019 var MobileIdentityV mi;
4020
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004021 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004022 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004023 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004024 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004025 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004026 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004027
4028 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004029 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 +02004030
Philipp Maierca058272021-06-23 10:35:23 +02004031 /* Add additional pagings through the PCU socket interface. */
4032 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4033 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4034 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4035 }
4036 }
4037
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004038 st.num_paging_sent := st.num_paging_sent + 1;
4039 }
4040 if (st.num_paging_sent < pkt_total) {
4041 /* Wait for interval to next PAGING COMMAND */
4042 var float time_now := T_total.read;
4043 var float next_sched := int2float(st.num_paging_sent)*interval;
4044 if (next_sched > time_now) {
4045 T_itv.start(next_sched - time_now);
4046 } else {
4047 T_itv.start(0.0);
4048 }
4049 } else {
4050 /* We are done, no need to keep counting */
4051 T_total.stop;
4052 }
4053 }
4054 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004055 }
4056 }
4057
Philipp Maierca058272021-06-23 10:35:23 +02004058 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004059 T_wait.start;
4060 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004061 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004062 [] L1CTL.receive { repeat; }
4063 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004064 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004065 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004066 /* ignore other RSL messages like RF RESource INDication */
4067 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004068 /* Only relevant when testing including with PCU sock connected */
4069 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004070 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004071 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 +01004072 }
Harald Welte68e495b2018-02-25 00:05:57 +01004073 }
4074
4075 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4076 " rcvd_ids=", st.num_paging_rcv_ids);
4077 return st;
4078}
4079
4080/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4081 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4082 * - that CCCH LOAD IND (PCH) are being generated
4083 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4084testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004085 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004086 var PagingTestCfg cfg := {
4087 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004088 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004089 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004090 ps_load_modulus := 0,
4091 ps_wait_cong := false,
4092 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004093 exp_load_ind := true,
4094 exp_overload := false,
4095 use_tmsi := false
4096 };
4097 var PagingTestState st := f_TC_paging(cfg);
4098 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4100 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004101 } else {
4102 setverdict(pass);
4103 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004105}
4106
4107/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4108 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4109 * - that CCCH LOAD IND (PCH) are being generated
4110 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4111testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004112 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004113 var PagingTestCfg cfg := {
4114 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004115 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004116 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004117 ps_load_modulus := 0,
4118 ps_wait_cong := false,
4119 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004120 exp_load_ind := true,
4121 exp_overload := false,
4122 use_tmsi := true
4123 };
4124 var PagingTestState st := f_TC_paging(cfg);
4125 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4127 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004128 } else {
4129 setverdict(pass);
4130 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004132}
4133
4134/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4135 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4136 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4137 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4138testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004139 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004140 var PagingTestCfg cfg := {
4141 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004142 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004143 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004144 ps_load_modulus := 0,
4145 ps_wait_cong := false,
4146 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004147 exp_load_ind := true,
4148 exp_overload := true,
4149 use_tmsi := false
4150 };
4151 var PagingTestState st := f_TC_paging(cfg);
4152 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4153 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004154 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004155 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004156 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 +01004157 } else {
4158 setverdict(pass);
4159 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004161}
4162
4163/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4164 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4165 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4166 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4167testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004168 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004169 var PagingTestCfg cfg := {
4170 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004171 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004172 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004173 ps_load_modulus := 0,
4174 ps_wait_cong := false,
4175 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004176 exp_load_ind := true,
4177 exp_overload := true,
4178 use_tmsi := true
4179 };
4180 var PagingTestState st := f_TC_paging(cfg);
4181 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4182 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004183 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004184 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004185 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 +01004186 } else {
4187 setverdict(pass);
4188 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004190}
4191
Philipp Maierca058272021-06-23 10:35:23 +02004192/* Same as above, but with additional paging load created by PS pagings that
4193 * are issued through the PCU socket. The additional load is introduced when
4194 * the paging queue is already two thirds full. Since the BTS implements a
4195 * prioritization logic that drops the pagings from the PCU under in those
4196 * congestive sitautions the behaviour on the PS side is expected to be
4197 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4198testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4199 var SystemInformation si3 := valueof(ts_SI3_default);
4200 var PagingTestCfg cfg := {
4201 combined_ccch := true,
4202 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4203 load_factor := 2.0,
4204 ps_load_modulus := 16,
4205 ps_wait_cong := true,
4206 queue_drain_timeout := 18.0,
4207 exp_load_ind := true,
4208 exp_overload := true,
4209 use_tmsi := false
4210 };
4211 var PagingTestState st := f_TC_paging(cfg);
4212 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4213 * slots and will fully drain that buffer before returning */
4214 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4215 if (not match(st.num_paging_rcv_ids, tpl)) {
4216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4217 } else {
4218 setverdict(pass);
4219 }
4220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4221}
4222
4223
Harald Welte68e495b2018-02-25 00:05:57 +01004224
Harald Welte93640c62018-02-25 16:59:33 +01004225/***********************************************************************
4226 * Immediate Assignment / AGCH
4227 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004228private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004229 len := 0,
4230 ma := ''B
4231}
Harald Welte93640c62018-02-25 16:59:33 +01004232
Harald Weltee8d750e2018-06-10 21:41:35 +02004233private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4234 return int2str(num_tx) & " sent, "
4235 & int2str(num_rx) & " received, "
4236 & int2str(num_del) & " deleted";
4237}
4238
4239private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4240 var L1ctlDlMessage l1_dl;
4241 timer T := 10.0;
4242 var integer num_tx := 0;
4243 var integer num_rx := 0;
4244 var integer num_del := 0;
4245 var charstring res_str;
4246 var float rx_ratio;
4247
Harald Welte10474062019-05-30 16:48:17 +02004248 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004249 f_init_l1ctl();
4250 f_l1_tune(L1CTL);
4251
4252 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004253 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004254 mp_trx_pars[0].arfcn,
4255 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004256 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4257 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004258 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004259 num_tx := num_tx+1;
4260 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004261 }
4262 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004263 T.start;
4264 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004265 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004266 num_del := num_del+1;
4267 repeat;
4268 }
4269 [] RSL_CCHAN.receive {
4270 repeat;
4271 }
4272 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004273 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4274 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4275 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004276 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004277 } else {
4278 num_rx := num_rx+1;
4279 }
4280 repeat;
4281 }
4282 [] L1CTL.receive { repeat; }
4283 [] T.timeout { }
4284 }
4285 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4286 log("AGCH test: " & res_str);
4287 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004289 }
4290 rx_ratio := int2float(num_rx) / int2float(num_tx);
4291 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004292 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 +02004293 } else {
4294 setverdict(pass);
4295 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004297}
4298
Harald Weltee8d750e2018-06-10 21:41:35 +02004299/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4300testcase TC_imm_ass_1000_20ms() runs on test_CT {
4301 f_TC_imm_ass(1000, 0.02, 0.25);
4302}
4303
4304/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4305testcase TC_imm_ass_200_0ms() runs on test_CT {
4306 f_TC_imm_ass(200, 0.0, 0.05);
4307}
4308
4309/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4310testcase TC_imm_ass_200_76ms() runs on test_CT {
4311 f_TC_imm_ass(150, 0.076, 1.00);
4312}
4313
4314
4315
Harald Welte48494ca2018-02-25 16:59:50 +01004316/***********************************************************************
4317 * BCCH
4318 ***********************************************************************/
4319
4320/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004321private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004322 GsmFrameNumber frame_number,
4323 SystemInformation si
4324}
4325
4326/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004327private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004328
4329/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004330private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004331
4332/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004333private function f_si_vecslot_contains(SystemInformationVector arr,
4334 RrMessageType key,
4335 boolean bcch_ext := false)
4336return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004337 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4338 var integer fn_mod51 := arr[i].frame_number mod 51;
4339 if (not bcch_ext and fn_mod51 == 2 or
4340 bcch_ext and fn_mod51 == 6) {
4341 if (arr[i].si.header.message_type == key) {
4342 return true;
4343 }
4344 }
4345 }
4346 return false;
4347}
4348
4349/* 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 +07004350private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4351 integer tc, RrMessageType key,
4352 boolean ext_bcch := false)
4353{
Harald Welte48494ca2018-02-25 16:59:50 +01004354 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004356 }
4357}
4358
4359/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004360private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4361 RrMessageType key)
4362return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004363 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4364 if (f_si_vecslot_contains(arr[tc], key) or
4365 f_si_vecslot_contains(arr[tc], key, true)) {
4366 return true;
4367 }
4368 }
4369 return false;
4370}
4371
4372/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004373private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4374 RrMessageType key,
4375 boolean bcch_ext := false,
4376 integer n := 1, integer m := 4)
4377return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004378 var integer count := 0;
4379 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4381 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004382 }
4383 for (var integer i:= 0; i < m; i := i + 1) {
4384 var integer fn_mod51 := arr[i].frame_number mod 51;
4385 if (not bcch_ext and fn_mod51 == 2 or
4386 bcch_ext and fn_mod51 == 6) {
4387 if (arr[i].si.header.message_type == key) {
4388 count := count + 1;
4389 }
4390 }
4391 }
4392 if (count >= n) {
4393 return true;
4394 } else {
4395 return false;
4396 }
4397}
4398
4399/* 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 +07004400private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4401 integer tc, RrMessageType key,
4402 boolean ext_bcch := false,
4403 integer n, integer m)
4404{
Harald Welte48494ca2018-02-25 16:59:50 +01004405 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004407 }
4408}
4409
4410/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004411private function f_si_vecslot_contains_only(SystemInformationVector arr,
4412 RrMessageType key,
4413 boolean bcch_ext := false)
4414return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004415 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4416 var integer fn_mod51 := arr[i].frame_number mod 51;
4417 if (not bcch_ext and fn_mod51 == 2 or
4418 bcch_ext and fn_mod51 == 6) {
4419 if (arr[i].si.header.message_type != key) {
4420 return false;
4421 }
4422 }
4423 }
4424 return true;
4425}
4426
4427/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004428private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4429 integer tc, RrMessageType key,
4430 boolean ext_bcch := false)
4431{
Harald Welte48494ca2018-02-25 16:59:50 +01004432 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004434 }
4435}
4436
4437/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004438private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004439 boolean bcch_extended,
4440 boolean si1_present,
4441 boolean si2bis_present,
4442 boolean si2ter_present,
4443 boolean si2quater_present,
4444 boolean si7_present,
4445 boolean si8_present,
4446 boolean si9_present,
4447 boolean si13_present,
4448 boolean si13alt_present,
4449 boolean si15_present,
4450 boolean si16_present,
4451 boolean si17_present,
4452 boolean si2n_present,
4453 boolean si21_present,
4454 boolean si22_present
4455}
4456
4457/* 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 +07004458private function f_validate_si_scheduling(SystemInformationConfig cfg,
4459 SystemInformationVectorPerTc si_per_tc)
4460{
Harald Welte48494ca2018-02-25 16:59:50 +01004461 var integer i;
4462 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4463 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004465 }
4466 }
4467 if (cfg.si1_present) {
4468 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4469 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4470 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4471 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4472 /* make sure *ALL* contain SI1 */
4473 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4474 }
4475 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4476 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4477 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4478 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4479 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4480 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4481
4482 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4483 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4484 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4485 * consecutive occurrences of TC = 4. */
4486 if (cfg.si2bis_present and not cfg.si2ter_present) {
4487 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4488 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4489 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4490 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4491 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4492 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4493 }
4494
4495 if (cfg.si7_present or cfg.si8_present) {
4496 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4497 * if System Information type 4 does not contain all information needed for cell
4498 * selection and reselection. */
4499 if (not cfg.bcch_extended) {
4500 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4501 }
4502 if (cfg.si7_present) {
4503 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4504 }
4505 if (cfg.si8_present) {
4506 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4507 }
4508 }
4509
4510 if (cfg.si2quater_present) {
4511 /* iii) System information type 2 quater is sent if needed, as determined by the system
4512 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4513 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4514 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4515 * within any of 4 consecutive occurrences of TC = 5. */
4516 if (not (cfg.bcch_extended)) {
4517 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4518 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4519 } else {
4520 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4521 }
4522 } else {
4523 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4524 }
4525 }
4526 if (cfg.si9_present) {
4527 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4528 * in system information type 3 as defined in 3GPP TS 44.018. */
4529 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4530 }
4531 if (cfg.si13_present) {
4532 /* vii) System Information type 13 is only related to the GPRS service. System Information
4533 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4534 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4535 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4536 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4537 * within any of 4 consecutive occurrences of TC=4. */
4538 if (not cfg.bcch_extended) {
4539 log("not-bccch-extended");
4540 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4541 } else {
4542 log("bccch-extended");
4543 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4544 }
4545 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004547 }
4548 }
4549 if (cfg.si16_present or cfg.si17_present) {
4550 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4551 * should not be sent in a cell where network sharing is used (see rule xv). */
4552 if (cfg.si22_present) {
4553 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4554 }
4555 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004557 }
4558 if (not cfg.bcch_extended) {
4559 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4560 }
4561 if (cfg.si16_present) {
4562 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4563 }
4564 if (cfg.si17_present) {
4565 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4566 }
4567 }
4568
4569 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4570 * broadcast information. The frequency with which they are sent is determined by the
4571 * system operator. System Information type 9 identifies the scheduling of System
4572 * Information type 18 and 20 messages. */
4573
4574 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4575 * Information Type 19 is present, then its scheduling shall be indicated in System
4576 * Information Type 9. */
4577
4578 if (cfg.si15_present) {
4579 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4580 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4581 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4582 * 4 consecutive occurrences of TC = 1. */
4583 if (not cfg.bcch_extended) {
4584 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4585 } else {
4586 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4587 }
4588 }
4589 if (cfg.si13alt_present) {
4590 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4591 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4592 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4593 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4594 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4595 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4596 * of TC = 4. */
4597 if (cfg.si13_present) {
4598 testcase.stop("Error: Cannot have SI13alt and SI13");
4599 }
4600 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004602 }
4603 if (not cfg.bcch_extended) {
4604 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4605 } else {
4606 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4607 }
4608 }
4609 if (cfg.si2n_present) {
4610 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4611 * as determined by the system operator. In the case that the message is sent on the
4612 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4613 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4614 * consecutive occurrences of TC = 4. */
4615 if (not cfg.bcch_extended) {
4616 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4617 } else {
4618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4619 }
4620 }
4621 if (cfg.si21_present) {
4622 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4623 * determined by the system operator. If Extended Access Barring is in use in the cell
4624 * then this message is sent at least once within any of 4 consecutive occurrences of
4625 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4626 * cell then this message shall only be sent on BCCH Ext. */
4627 if (not cfg.bcch_extended) {
4628 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4629 } else {
4630 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4631 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004633 }
4634 }
4635 }
4636 if (cfg.si22_present) {
4637 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4638 * should not be sent in a cell where SoLSA is used (see rule viii). System
4639 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4640 * =2 and TC=6. */
4641 if (cfg.si16_present or cfg.si17_present) {
4642 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4643 }
4644 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4645 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004647 }
4648 if (not cfg.bcch_extended) {
4649 testcase.stop("Error: SI22 requires BCCH Extd!");
4650 } else {
4651 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4652 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4653 }
4654 }
4655}
4656
4657/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004658private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4659return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004660 timer T := duration;
4661 var SystemInformationVectorPerTc si_per_tc;
4662 var L1ctlDlMessage l1_dl;
4663
4664 /* initialize all per-TC vectors empty */
4665 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4666 si_per_tc[i] := {};
4667 }
4668
4669 /* flush all previous L1 queued msgs */
4670 pt.clear;
4671
4672 T.start;
4673 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004674 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004675 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4676 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4677 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004678 repeat;
4679 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004680
Harald Welte48494ca2018-02-25 16:59:50 +01004681 var integer tc := f_gsm_compute_tc(sig.frame_number);
4682 log("SI received at TC=", tc, ": ", sig.si);
4683 /* append to the per-TC bucket */
4684 si_per_tc[tc] := si_per_tc[tc] & { sig };
4685 repeat;
4686 }
4687 [] pt.receive { repeat; }
4688 [] T.timeout { }
4689 }
4690
4691 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4692 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4693 }
4694 log("si_per_tc=", si_per_tc);
4695 return si_per_tc;
4696}
4697
4698/* helper function: Set given SI via RSL + validate scheduling.
4699 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004700private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004701 var SystemInformationVectorPerTc si_per_tc;
4702 f_init_l1ctl();
4703 f_l1_tune(L1CTL);
4704
4705 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004706 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004707 f_validate_si_scheduling(si_cfg, si_per_tc);
4708
4709 setverdict(pass);
4710}
4711
4712testcase TC_si_sched_default() runs on test_CT {
4713 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004714 /* 2+3+4 are mandatory and set in f_init() */
4715 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004717}
4718
4719testcase TC_si_sched_1() runs on test_CT {
4720 f_init();
4721 si_cfg.si1_present := true;
4722 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004723 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004725}
4726
4727testcase TC_si_sched_2bis() runs on test_CT {
4728 f_init();
4729 si_cfg.si2bis_present := true;
4730 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4731 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004733}
4734
4735testcase TC_si_sched_2ter() runs on test_CT {
4736 f_init();
4737 si_cfg.si2ter_present := true;
4738 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4739 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004741}
4742
4743testcase TC_si_sched_2ter_2bis() runs on test_CT {
4744 f_init();
4745 si_cfg.si2bis_present := true;
4746 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4747 si_cfg.si2ter_present := true;
4748 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4749 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004750 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004751}
4752
4753testcase TC_si_sched_2quater() runs on test_CT {
4754 f_init();
4755 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004756 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004757 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004759}
4760
4761testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004762 /* NOTE: PCUIF connection is not used in this test case, but
4763 * without it the IUT would not broadcast SI13 (see OS#3075). */
4764 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004765 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004766 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004767 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004769}
4770
4771testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004772 /* NOTE: PCUIF connection is not used in this test case, but
4773 * without it the IUT would not broadcast SI13 (see OS#3075). */
4774 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004775 si_cfg.si2bis_present := true;
4776 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4777 si_cfg.si2ter_present := true;
4778 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4779 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004780 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004781 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004782 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004783 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004785}
4786
4787
Harald Welte68e495b2018-02-25 00:05:57 +01004788testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004789 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004790 /* FIXME: enable / disable individual BCCH info */
4791 //ts_RSL_BCCH_INFO(si_type, info);
4792 /* expect no ERROR REPORT after either of them *
4793 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004795}
4796
Harald Welte93640c62018-02-25 16:59:33 +01004797/***********************************************************************
4798 * Low-Level Protocol Errors / ERROR REPORT
4799 ***********************************************************************/
4800
Harald Welte01d982c2018-02-25 01:31:40 +01004801private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4802 timer T := 5.0;
4803 T.start;
4804 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004805 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004806 setverdict(pass);
4807 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004808 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004810 }
4811 [] RSL_CCHAN.receive {
4812 repeat;
4813 }
4814 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004816 }
4817 }
4818}
4819
4820/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4821testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004822 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004823 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4824 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004825 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004826
4827 f_exp_err_rep(RSL_ERR_PROTO);
4828}
4829
4830/* Provoke a mandatory IE error and match on ERROR REPORT */
4831testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004832 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004833
4834 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4835 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004836 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004837
4838 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4839}
4840
4841/* Provoke an IE content error and match on ERROR REPORT */
4842testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004843 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004844 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4845 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004846 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004847
4848 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4849}
4850
Harald Welteee25aae2019-05-19 14:32:37 +02004851/* attempt to activate channel with wrong RSL Message Discriminator IE */
4852function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4853 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4854 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4855 RSL.send(rsl);
4856 f_rslem_unregister(0, g_chan_nr);
4857}
4858testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4859 var ConnHdlr vc_conn;
4860 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4861
Harald Welte10474062019-05-30 16:48:17 +02004862 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004863
4864 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4865 vc_conn.done;
4866 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4867
4868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4869}
4870
4871/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004872private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004873 var template (value) RSL_Message rsl_tx;
4874 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4875 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4876 RSL.send(rsl_tx);
4877 f_rslem_unregister(0, g_chan_nr);
4878}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004879private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004880 var template (value) RSL_Message rsl_tx;
4881 /* we first have to activate the dedicated channel */
4882 f_rsl_chan_act(g_pars.chan_mode);
4883 /* ... to then send an invalid RLL message */
4884 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4885 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4886 RSL.send(rsl_tx);
4887 f_rslem_unregister(0, g_chan_nr);
4888}
4889testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4890 var ConnHdlr vc_conn;
4891 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4892 var template (value) RSL_Message rsl_tx;
4893
Harald Welte10474062019-05-30 16:48:17 +02004894 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004895
4896 /* Common Channel with wrong message type */
4897 RSL_CCHAN.clear;
4898 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4899 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004900 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004901 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4902
4903 /* TRX Management */
4904 RSL_CCHAN.clear;
4905 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4906 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004907 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004908 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4909
4910 /* Dedicated Channel */
4911 RSL_CCHAN.clear;
4912 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4913 vc_conn.done;
4914 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4915
4916 /* RLL */
4917 RSL_CCHAN.clear;
4918 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4919 vc_conn.done;
4920 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4921}
4922
4923/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004924private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004925 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4926 f_rslem_unregister(0, g_chan_nr);
4927}
4928testcase TC_err_rep_wrong_sequence() runs on test_CT {
4929 var ConnHdlr vc_conn;
4930 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4931
Harald Welte10474062019-05-30 16:48:17 +02004932 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004933
4934 RSL_CCHAN.clear;
4935 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4936 vc_conn.done;
4937 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4938}
4939
Harald Welte93640c62018-02-25 16:59:33 +01004940/***********************************************************************
4941 * IPA CRCX/MDCX/DLCS media stream handling
4942 ***********************************************************************/
4943
Harald Weltea871a382018-02-25 02:03:14 +01004944/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004945private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004946 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4947 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004948}
4949testcase TC_ipa_dlcx_not_active() runs on test_CT {
4950 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004951 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004952 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4953 vc_conn.done;
4954}
Harald Welte68e495b2018-02-25 00:05:57 +01004955
Harald Weltea3f1df92018-02-25 12:49:55 +01004956/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004957private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004958 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4959 "IPA CRCX ACK");
4960 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4961 "IPA CRCX NACK");
4962}
4963testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4964 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004965 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004966 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4967 vc_conn.done;
4968}
4969
4970/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004971private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004972 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4973 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004974 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004975 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4976 var uint7_t rtp_pt2 := f_rnd_int(127);
4977 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4978 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4979 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4980 "IPA MDCX ACK");
4981 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4982 "IPA DLCX ACK");
4983}
4984testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4985 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004986 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004987 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4988 vc_conn.done;
4989}
4990
Harald Welte3ae11da2018-02-25 13:36:06 +01004991/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004992private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004993 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4994 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004995 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004996 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4997 var uint7_t rtp_pt2 := f_rnd_int(127);
4998 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4999 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5000 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5001 "IPA MDCX ACK");
5002 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005003 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005004 remote_port := f_rnd_int(c_UINT16_MAX);
5005 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5006 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5007 "IPA MDCX ACK");
5008 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5009 "IPA DLCX ACK");
5010}
5011testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5012 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005013 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005014 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5015 vc_conn.done;
5016}
5017
Harald Welte9912eb52018-02-25 13:30:15 +01005018/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005019private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005020 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5021 "IPA CRCX NACK");
5022}
5023testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5024 var ConnHdlrPars pars;
5025 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005026 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005027
5028 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5029 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5030 vc_conn.done;
5031
5032 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5033 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5034 vc_conn.done;
5035}
5036
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005037/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5038private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5039 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5040 var PortNumber bind_port := 16811;
5041 var RSL_Message crcx_ack;
5042
5043 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5044 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5045 "IPA CRCX ACK");
5046 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5047 if (match(bts_bind_ip, "0.0.0.0")) {
5048 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5049 }
5050
5051 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5052 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5053 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5054 "IPA DLCX ACK");
5055}
5056testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5057 var ConnHdlrPars pars;
5058 var ConnHdlr vc_conn;
5059 f_init();
5060
5061 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5062 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5063 vc_conn.done;
5064
5065 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5066 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5067 vc_conn.done;
5068}
5069
Harald Weltea3f1df92018-02-25 12:49:55 +01005070
Harald Welte883340c2018-02-28 18:59:29 +01005071/***********************************************************************
5072 * PCU Socket related tests
5073 ***********************************************************************/
5074
Harald Welte07bd2d22019-05-25 11:03:30 +02005075/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005076friend 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 +01005077runs on test_CT {
5078 timer T := 3.0;
5079
5080 /* we don't expect any RTS.req before PDCH are active */
5081 T.start;
5082 alt {
5083 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005085 }
5086 [] PCU.receive { repeat; }
5087 [] T.timeout { }
5088 }
5089
5090 /* Send PDCH activate request for known PDCH timeslot */
5091 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5092
5093 /* we now expect RTS.req for this timeslot (only) */
5094 T.start;
5095 alt {
5096 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5097 setverdict(pass);
5098 }
5099 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5100 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005102 }
5103 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005105 }
5106 [] PCU.receive { repeat; }
5107 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005109 }
5110 [not exp_success] T.timeout {
5111 setverdict(pass);
5112 }
5113 }
5114}
5115
Harald Welte07bd2d22019-05-25 11:03:30 +02005116/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005117friend 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 +01005118runs on test_CT {
5119 timer T := 3.0;
5120
5121 /* Send PDCH activate request for known PDCH timeslot */
5122 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 +02005123 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5124 * when it will actually have been executed in the BTS */
5125 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005126 PCU.clear;
5127 /* we now expect no RTS.req for this timeslot */
5128 T.start;
5129 alt {
5130 [] 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 +02005131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005132 }
5133 [] PCU.receive { repeat; }
5134 [] T.timeout {
5135 setverdict(pass);
5136 }
5137 }
5138}
5139
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005140friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005141 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005142 map(self:PCU, system:PCU);
5143 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005144 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5145}
5146
Harald Welte883340c2018-02-28 18:59:29 +01005147/* PDCH activation via PCU socket; check for presence of RTS.req */
5148testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005149 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005150
Harald Welte883340c2018-02-28 18:59:29 +01005151 f_TC_pcu_act_req(0, 0, 7, true);
5152}
5153
5154/* PDCH activation via PCU socket on non-PDCU timeslot */
5155testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005156 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005157
Harald Welte883340c2018-02-28 18:59:29 +01005158 f_TC_pcu_act_req(0, 0, 1, false);
5159}
5160
5161/* PDCH activation via PCU socket on wrong BTS */
5162testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005163 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005164
Harald Welte883340c2018-02-28 18:59:29 +01005165 f_TC_pcu_act_req(23, 0, 7, false);
5166}
5167
5168/* PDCH activation via PCU socket on wrong TRX */
5169testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005170 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005171
Harald Welte883340c2018-02-28 18:59:29 +01005172 f_TC_pcu_act_req(0, 23, 7, false);
5173}
5174
5175/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5176testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005177 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005178
Harald Welte883340c2018-02-28 18:59:29 +01005179 /* Activate PDCH */
5180 f_TC_pcu_act_req(0, 0, 7, true);
5181 f_sleep(1.0);
5182 /* and De-Activate again */
5183 f_TC_pcu_deact_req(0, 0, 7);
5184}
5185
5186/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5187testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005188 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005189
Harald Welte883340c2018-02-28 18:59:29 +01005190 f_TC_pcu_deact_req(0, 0, 1);
5191}
5192
5193/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005194function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005195 var PCUIF_send_data sd;
5196 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005197 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005198
5199 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005200 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005201
Harald Welte883340c2018-02-28 18:59:29 +01005202 T.start;
5203 alt {
5204 [] 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 +01005205 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005206 setverdict(pass);
5207 } else {
5208 repeat;
5209 }
5210 }
5211 [] PCU.receive { repeat; }
5212 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005214 }
5215 }
5216}
5217
Philipp Maier94c08482021-02-01 17:36:05 +01005218/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5219testcase TC_pcu_ver_si1() runs on test_CT {
5220 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5221 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5222}
5223
5224/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5225testcase TC_pcu_ver_si3() runs on test_CT {
5226 const octetstring si3 := '49012223242526272929AABBCC'O;
5227 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5228}
5229
5230/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5231testcase TC_pcu_ver_si13() runs on test_CT {
5232 const octetstring si13 := '01010203040506070909'O;
5233 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5234}
5235
Harald Welte883340c2018-02-28 18:59:29 +01005236private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5237
5238/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005239friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005240 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5241runs on test_CT
5242{
5243 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5244 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5245}
5246
5247/* 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 +02005248friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5249 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005250runs on test_CT
5251{
5252 var PCUIF_send_data sd;
5253
5254 timer T := 3.0;
5255 T.start;
5256 alt {
5257 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5258 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5259 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5260 sd.data.u.rts_req.fn, sapi, data);
5261 }
5262 [] PCU.receive { repeat; }
5263 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005265 }
5266 }
5267}
5268
5269/* Send DATA.req on invalid BTS */
5270testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005271 var TfiUsfArr tua := f_TfiUsfArrInit();
5272 var octetstring data := '0000'O & f_rnd_octstring(21);
5273
5274 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005275
Harald Welte883340c2018-02-28 18:59:29 +01005276 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005277 f_TfiUsfArrSet(tua, 7, 0);
5278 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5279 f_sleep(1.0);
5280
5281 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005282}
5283
5284/* Send DATA.req on invalid TRX */
5285testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005286 var TfiUsfArr tua := f_TfiUsfArrInit();
5287 var octetstring data := '0000'O & f_rnd_octstring(21);
5288
5289 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005290
Harald Welte883340c2018-02-28 18:59:29 +01005291 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005292 f_TfiUsfArrSet(tua, 7, 0);
5293 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5294 f_sleep(1.0);
5295
5296 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005297}
5298
5299/* Send DATA.req on invalid timeslot */
5300testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005301 var TfiUsfArr tua := f_TfiUsfArrInit();
5302 var octetstring data := '0000'O & f_rnd_octstring(21);
5303
5304 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005305
Harald Welte883340c2018-02-28 18:59:29 +01005306 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005307 f_TfiUsfArrSet(tua, 7, 0);
5308 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5309 f_sleep(1.0);
5310
5311 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005312}
5313
5314/* Send DATA.req on timeslot that hasn't been activated */
5315testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005316 var TfiUsfArr tua := f_TfiUsfArrInit();
5317 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005318
Harald Welte7162a612019-05-26 12:56:09 +02005319 f_virtphy_common();
5320
5321 f_TfiUsfArrSet(tua, 7, 0);
5322 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5323 f_sleep(1.0);
5324
5325 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005326}
5327
Harald Weltead033dc2019-05-25 17:28:16 +02005328private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005329 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5330 boolean wait_rts := true)
5331runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005332 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005333 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005334
5335 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005336 if (wait_rts) {
5337 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5338 } else {
5339 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5340 }
Harald Weltead033dc2019-05-25 17:28:16 +02005341
5342 T.start;
5343 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005344 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005345 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5346 setverdict(pass);
5347 }
Harald Welte7162a612019-05-26 12:56:09 +02005348 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5349 setverdict(fail, "Received unexpected ", rx_dl);
5350 }
Harald Weltead033dc2019-05-25 17:28:16 +02005351 [] L1CTL.receive {
5352 repeat;
5353 }
Harald Welte7162a612019-05-26 12:56:09 +02005354 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005355 setverdict(fail, "Timeout waiting for ", data);
5356 }
Harald Welte7162a612019-05-26 12:56:09 +02005357 [not expect_data] T.timeout {
5358 setverdict(pass);
5359 }
Harald Weltead033dc2019-05-25 17:28:16 +02005360 }
5361}
5362
5363private function f_disable_dynamic_ts() runs on test_CT
5364{
5365 f_init_vty_bsc();
5366 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5367 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5368 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5369 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005370 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005371}
5372
5373private function f_virtphy_common() runs on test_CT {
5374 f_disable_dynamic_ts();
5375 f_init_l1ctl();
5376 f_l1_tune(L1CTL);
5377}
5378
5379testcase TC_pcu_data_req_pdtch() runs on test_CT {
5380 var TfiUsfArr tua := f_TfiUsfArrInit();
5381 var octetstring data := '0000'O & f_rnd_octstring(21);
5382
5383 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005384
Harald Welte883340c2018-02-28 18:59:29 +01005385 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005386 f_TfiUsfArrSet(tua, 7, 0);
5387 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5388 f_sleep(1.0);
5389
5390 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005391}
5392
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005393/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005394testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005395 var TfiUsfArr tua := f_TfiUsfArrInit();
5396 var octetstring data := '0000'O & f_rnd_octstring(21);
5397
5398 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005399
Harald Welte883340c2018-02-28 18:59:29 +01005400 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005401 f_TfiUsfArrSet(tua, 7, 0);
5402 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5403 f_sleep(1.0);
5404
5405 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005406}
5407
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005408private function f_TC_pcu_ptcch_ul(uint16_t ra)
5409runs on test_CT {
5410 var template PCUIF_Message pcu_rach_ind;
5411 var PCUIF_send_data sd;
5412 var GsmFrameNumber fn;
5413 timer T;
5414
5415 /* Send an Access Burst on PTCCH/U over the Um-interface */
5416 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5417 chan_nr := ts_RslChanNr_PDCH(7),
5418 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5419
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005420 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5421 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005422
5423 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5424 T.start(52.0 * 4.615 / 1000.0);
5425 alt {
5426 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5427 log("Rx an Access Burst on the PCU interface: ", sd.data);
5428 setverdict(pass);
5429 T.stop;
5430 }
5431 [] PCU.receive { repeat; }
5432 [] T.timeout {
5433 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5434 /* Keep going, that's not the end of the world */
5435 }
5436 }
5437}
5438
5439testcase TC_pcu_ptcch() runs on test_CT {
5440 var L1ctlDlMessage dl;
5441 var octetstring data;
5442 timer T;
5443
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005444 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005445 f_init_l1ctl();
5446 f_l1_tune(L1CTL);
5447
5448 /* Activate PDCH channel on TS7 */
5449 f_TC_pcu_act_req(0, 0, 7, true);
5450
5451 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005452 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005453 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005454 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005455 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005456
5457 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5458 for (var integer i := 0; i < 16; i := i + 1) {
5459 log("Sending an Access Burst towards the L1CTL interface");
5460 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5461 }
5462
5463 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5464 data := f_rnd_octstring(23);
5465
5466 /* Verify PTCCH/D: send a random data block, make sure it's received */
5467 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5468 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5469
5470 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5471 * let's give it more time in case if we miss the beginning. */
5472 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5473 alt {
5474 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5475 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5476 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5477 frame := data)) -> value dl {
5478 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5479 setverdict(pass);
5480 T.stop;
5481 }
5482 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5483 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5484 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5485 l2_data := data)) -> value dl {
5486 log("Rx PTCCH/D data block on L1CTL: ", dl);
5487 setverdict(pass);
5488 T.stop;
5489 }
5490 [] L1CTL.receive { repeat; }
5491 [] T.timeout {
5492 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5493 }
5494 }
5495}
5496
Harald Welte883340c2018-02-28 18:59:29 +01005497/* Send AGCH from PCU; check it appears on Um side */
5498testcase TC_pcu_data_req_agch() runs on test_CT {
5499 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005500 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005501 f_init_l1ctl();
5502 f_l1_tune(L1CTL);
5503
5504 f_TC_pcu_act_req(0, 0, 7, true);
5505 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5506
5507 T.start;
5508 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005509 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005510 setverdict(pass);
5511 }
5512 [] L1CTL.receive { repeat; }
5513 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005515 }
5516 }
5517}
5518
Harald Welte928622b2019-05-26 13:22:59 +02005519/* Send AGCH from PCU; check it appears on Um side */
5520testcase TC_pcu_data_req_pch() runs on test_CT {
5521 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005522 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005523 f_init_l1ctl();
5524 f_l1_tune(L1CTL);
5525
5526 f_TC_pcu_act_req(0, 0, 7, true);
5527 /* three characters prefix: last 3 digits of IMSI as ASCII */
5528 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5529
5530 T.start;
5531 alt {
5532 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5533 setverdict(pass);
5534 }
5535 [] L1CTL.receive { repeat; }
5536 [] T.timeout {
5537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5538 }
5539 }
5540}
5541
Harald Welte883340c2018-02-28 18:59:29 +01005542/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5543testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5544 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005545 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005546 f_init_l1ctl();
5547 f_l1_tune(L1CTL);
5548
5549 /* append 3 last imsi digits so BTS can compute pagng group */
5550 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5551
5552 timer T := 0.5;
5553 T.start;
5554 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005555 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005556 /* TODO: verify paging group */
5557 setverdict(pass);
5558 }
5559 [] L1CTL.receive { repeat; }
5560 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005562 }
5563 }
5564}
5565
5566/* Send RACH from Um side, expect it to show up on PCU socket */
5567testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005568 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005569 f_init_l1ctl();
5570 f_l1_tune(L1CTL);
5571
5572 var GsmFrameNumber fn_last := 0;
5573 for (var integer i := 0; i < 1000; i := i+1) {
5574 var OCT1 ra := f_rnd_ra_ps();
5575 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5576 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005578 }
5579 fn_last := fn;
5580
5581 timer T := 2.0;
5582 T.start;
5583 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005584 [] 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 +01005585 T.stop;
5586 }
5587 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005589 }
5590 [] PCU.receive { repeat; }
5591 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005593 }
5594 }
5595 }
5596 setverdict(pass);
5597}
5598
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005599/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5600 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5601testcase TC_pcu_ext_rach_content() runs on test_CT {
5602 var template PCUIF_Message pcu_rach_ind;
5603 var GsmFrameNumber fn_last := 0;
5604 var L1ctlRachSynchSeq synch_seq;
5605 var PCUIF_BurstType pcu_bt;
5606 var GsmFrameNumber fn;
5607 var BIT11 ra11;
5608
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005609 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005610 f_init_l1ctl();
5611 f_l1_tune(L1CTL);
5612
5613 for (var integer i := 0; i < 1000; i := i+1) {
5614 /* We need to test both TS1 & TS2 */
5615 if (i rem 2 == 0) {
5616 synch_seq := RACH_SYNCH_SEQ_TS1;
5617 pcu_bt := BURST_TYPE_1;
5618 } else {
5619 synch_seq := RACH_SYNCH_SEQ_TS2;
5620 pcu_bt := BURST_TYPE_2;
5621 }
5622
5623 ra11 := f_rnd_ra11_ps();
5624 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5625 if (fn == fn_last) {
5626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5627 "Two RACH in same FN?!?");
5628 }
5629 fn_last := fn;
5630
5631 /* Compose the expected message */
5632 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005633 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005634 ra := bit2int(ra11),
5635 is_11bit := 1,
5636 burst_type := pcu_bt,
5637 fn := fn);
5638
5639 timer T := 2.0;
5640 T.start;
5641 alt {
5642 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5643 T.stop;
5644 }
5645 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5647 }
5648 [] PCU.receive { repeat; }
5649 [] T.timeout {
5650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5651 }
5652 }
5653 }
5654 setverdict(pass);
5655}
5656
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005657private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5658runs on test_CT {
5659 var template PCUIF_send_data sdt;
5660 var PCUIF_send_data sd;
5661 var int16_t lqual_cb;
5662 timer T := 1.0;
5663
5664 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5665 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5666
5667 /* Send a random PDTCH frame over Um */
5668 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5669 '0000'O & f_rnd_octstring(21)));
5670
5671 T.start;
5672 alt {
5673 /* If expected link quality is above the threshold */
5674 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5675 lqual_cb := sd.data.u.data_ind.lqual_cb;
5676 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5677
5678 /* Make sure the actual link quality matches the expected value */
5679 if (not match(lqual_cb, lqual_cb_exp)) {
5680 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5681 "expected value ", lqual_cb_exp));
5682 } else {
5683 setverdict(pass);
5684 }
5685 }
5686 /* If expected link quality is below the threshold */
5687 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5689 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5690 }
5691 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5692 [] PCU.receive { repeat; }
5693 [lqual_cb_exp < thresh] T.timeout {
5694 log("Rx nothing, as expected");
5695 setverdict(pass);
5696 }
5697 [lqual_cb_exp >= thresh] T.timeout {
5698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5699 "Timeout waiting for PCUIF_DATA.ind");
5700 }
5701 }
5702}
5703
5704/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5705testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005706 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005707 PCU.clear;
5708
5709 f_init_l1ctl();
5710 f_l1_tune(L1CTL);
5711
5712 /* Activate a PDCH channel on TS7 */
5713 f_TC_pcu_act_req(0, 0, 7, true);
5714
5715 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005716 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005717 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005718 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005719 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005720
5721 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5722 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5723 var TrxcMessage ret;
5724
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005725 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005726
5727 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5728 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5729 }
5730}
5731
Harald Welte883340c2018-02-28 18:59:29 +01005732/* Send PAGING via RSL, expect it to shw up on PCU socket */
5733testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005734 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005735
5736 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005737 var MobileIdentityLV mi_lv;
5738 var octetstring mi_lv_enc;
5739 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005740 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005741
Harald Welte883340c2018-02-28 18:59:29 +01005742 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005743 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005744 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005745 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005746 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005747
5748 /* Fancy encoding for PCUIF */
5749 mi_lv := valueof(ts_MI_LV(mi));
5750 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5751 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005752
5753 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005754 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005755 T.start;
5756 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005757 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005758 }
5759 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005761 }
5762 [] PCU.receive { repeat; }
5763 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005765 }
5766 }
5767 }
5768 setverdict(pass);
5769}
5770
Harald Welted66c9b82019-05-25 09:03:15 +02005771/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5772testcase TC_pcu_time_ind() runs on test_CT {
5773 var PCUIF_send_data pcu_sd;
5774 var integer num_time_ind := 0;
5775 var integer first_fn, last_fn;
5776 var float test_duration := 5.0;
5777 timer T;
5778
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005779 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005780 f_TC_pcu_act_req(0, 0, 7, true);
5781
5782 PCU.clear;
5783 T.start(test_duration);
5784 alt {
5785 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5786 num_time_ind := num_time_ind + 1;
5787 if (not isbound(first_fn)) {
5788 first_fn := pcu_sd.data.u.time_ind.fn;
5789 }
5790 last_fn := pcu_sd.data.u.time_ind.fn;
5791 repeat;
5792 }
5793 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5794 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5795 repeat;
5796 }
5797 [] PCU.receive {
5798 repeat;
5799 }
5800 [] T.timeout {}
5801 }
5802 var integer fn_expired := last_fn - first_fn;
5803 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5804
5805 /* verify the number of frames expired matches our expectation */
5806 const float c_GSM_FN_DURATION_MS := 4.61538;
5807 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005808 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005809 if (not match(fn_expired, t_fn_expected)) {
5810 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5811 }
5812
5813 /* There are three TIME.ind in every fn MOD 13 */
5814 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5815 /* Add some tolerance */
5816 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5817 if (not match(num_time_ind, t_time_ind_exp)) {
5818 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5819 }
5820
5821 setverdict(pass);
5822}
5823
Harald Welte4832c862019-05-25 14:57:18 +02005824/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5825testcase TC_pcu_rts_req() runs on test_CT {
5826 var PCUIF_send_data pcu_sd;
5827 var integer first_fn, last_fn;
5828 var integer num_rts_pdtch := 0;
5829 var integer num_rts_ptcch := 0;
5830 var float test_duration := 5.0;
5831 timer T;
5832
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005833 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005834 f_TC_pcu_act_req(0, 0, 7, true);
5835
5836 PCU.clear;
5837 T.start(test_duration);
5838 alt {
5839 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5840 -> value pcu_sd {
5841 num_rts_pdtch := num_rts_pdtch + 1;
5842 if (not isbound(first_fn)) {
5843 first_fn := pcu_sd.data.u.rts_req.fn;
5844 }
5845 last_fn := pcu_sd.data.u.rts_req.fn;
5846 repeat;
5847 }
5848 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5849 -> value pcu_sd {
5850 num_rts_ptcch := num_rts_ptcch + 1;
5851 if (not isbound(first_fn)) {
5852 first_fn := pcu_sd.data.u.rts_req.fn;
5853 }
5854 last_fn := pcu_sd.data.u.rts_req.fn;
5855 repeat;
5856 }
5857 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5858 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5859 repeat;
5860 }
5861 [] PCU.receive {
5862 repeat;
5863 }
5864 [] T.timeout {}
5865 }
5866 var integer fn_expired := last_fn - first_fn;
5867 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5868 ", num_rts_ptcch=", num_rts_ptcch);
5869
5870 /* verify the number of frames expired matches our expectation */
5871 const float c_GSM_FN_DURATION_MS := 4.61538;
5872 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005873 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005874 if (not match(fn_expired, t_fn_expected)) {
5875 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5876 }
5877
5878 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5879 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5880 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5881 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5882 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5883 t_ptcch_exp);
5884 }
5885
5886 /* We have 12 PDTCH blocks every 52-multiframe */
5887 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5888 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5889 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5890 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5891 t_pdtch_exp);
5892 }
5893
5894 setverdict(pass);
5895}
5896
Harald Welte07bd2d22019-05-25 11:03:30 +02005897/* test for generating Abis side OML ALERT from the PCU */
5898testcase TC_pcu_oml_alert() runs on test_CT {
5899 var PCUIF_send_data pcu_sd;
5900 var integer num_time_ind := 0;
5901 var integer first_fn, last_fn;
5902 var float test_duration := 5.0;
5903 timer T;
5904
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005905 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005906 f_TC_pcu_act_req(0, 0, 7, true);
5907
5908 /* re-connect CTRL port from BTS to BSC */
5909 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005910 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005911
5912 /* Send that OML Alert */
5913 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5914
5915 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5916 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5917 setverdict(pass);
5918}
5919
Harald Welteeaa9a862019-05-26 23:01:08 +02005920/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5921private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5922 var PCUIF_Message first_info;
5923 var integer pcu_conn_id := -1;
5924 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5925 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5926 var OCT4 tlli := '01020304'O;
5927 var OCT1 cause := '23'O;
5928 timer T := 5.0;
5929
5930 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5931
5932 f_l1_tune(L1CTL);
5933 RSL.clear;
5934
5935 f_est_dchan();
5936 L1CTL.clear;
5937
5938 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5939
5940 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5941 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5942 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5943
5944 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5945 T.start;
5946 alt {
5947 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5948 setverdict(pass);
5949 }
5950 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5951 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5952 }
5953 [] PCU.receive {
5954 repeat;
5955 }
5956 [] T.timeout {
5957 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5958 }
5959 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005960
5961 /* release the channel */
5962 f_rsl_chan_deact();
5963 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5964 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005965}
5966testcase TC_pcu_rr_suspend() runs on test_CT {
5967 var ConnHdlrPars pars;
5968 var ConnHdlr vc_conn;
5969
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005970 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005971
5972 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5973 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5974 vc_conn.done;
5975}
Harald Welte07bd2d22019-05-25 11:03:30 +02005976
Harald Weltea2e0e942019-05-27 18:12:53 +02005977/* Ensure that PCUIF socket can accept only a single connection */
5978testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005979 var boolean connected := false;
5980 var UD_connect_result cr;
5981 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005982 timer T := 5.0;
5983
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005984 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5985 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5986
Harald Weltea2e0e942019-05-27 18:12:53 +02005987 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005988 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005989
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005990 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005991 PCU.send(UD_connect:{mp_pcu_socket, -1});
5992 T.start;
5993 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005994 /* the IUT will first accept() the new connection, and close() it immediately */
5995 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5996 log("BTS has accept()ed connection");
5997 connected := true;
5998 cid := cr.id;
5999 repeat;
6000 }
6001 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6002 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006003 setverdict(pass);
6004 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006005 /* ignore other messages related to the first connection */
6006 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006007 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006008 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006009 }
6010 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006011
Harald Weltea2e0e942019-05-27 18:12:53 +02006012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6013}
6014
Harald Weltec8effb72019-05-27 18:23:04 +02006015/* Ensure that PCUIF socket can disconnect + reconnect */
6016testcase TC_pcu_socket_reconnect() runs on test_CT {
6017 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006018 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006019
6020 f_sleep(1.0);
6021
6022 f_pcuif_close(PCU, g_pcu_conn_id);
6023 g_pcu_conn_id := -1;
6024
6025 f_sleep(1.0);
6026
6027 /* re-connect */
6028 PCU.clear;
6029 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6030 setverdict(pass);
6031
6032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6033}
6034
Harald Weltebe030482019-05-27 22:29:35 +02006035/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006036private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6037runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006038 var L1ctlDlMessage l1_dl;
6039 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006040 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006041 timer T := 5.0;
6042 T.start;
6043 alt {
6044 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006045 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6046 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006047 repeat;
6048 }
6049 }
6050 [] pt.receive {
6051 repeat;
6052 }
6053 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6055 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006056 }
6057 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006058 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006059}
6060
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006061/* Check if GPRS Indicator is present in RR System Information of a given type */
6062private function f_si_has_gprs_indicator(RrMessageType si_type)
6063runs on test_CT return boolean {
6064 var SystemInformation si := f_get_si(L1CTL, si_type);
6065
6066 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006067 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006068 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006069 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006070 }
6071
6072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6073 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006074}
6075
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006076/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6077private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6078runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006079 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006080 f_init_l1ctl();
6081 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006082 f_sleep(2.0);
6083 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006084
6085 if (f_si_has_gprs_indicator(si_type)) {
6086 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006087 } else {
6088 setverdict(pass);
6089 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006090
Harald Weltebe030482019-05-27 22:29:35 +02006091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6092}
6093
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006094testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6095 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6096}
Harald Weltebe030482019-05-27 22:29:35 +02006097
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006098testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6099 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6100}
6101
6102/* Ensure that GPRS capability is advertised after PCU socket connect */
6103private function f_TC_pcu_socket_connect(RrMessageType si_type)
6104runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006105 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006106 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006107 f_init_l1ctl();
6108 f_l1_tune(L1CTL);
6109
6110 f_sleep(2.0);
6111 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006112
6113 if (not f_si_has_gprs_indicator(si_type)) {
6114 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006115 } else {
6116 setverdict(pass);
6117 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006118
Harald Weltebe030482019-05-27 22:29:35 +02006119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6120}
6121
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006122testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6123 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6124}
Harald Weltebe030482019-05-27 22:29:35 +02006125
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006126testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6127 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6128}
6129
6130/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6131private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6132runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006133 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006134 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006135 f_init_l1ctl();
6136 f_l1_tune(L1CTL);
6137
6138 f_pcuif_close(PCU, g_pcu_conn_id);
6139 g_pcu_conn_id := -1;
6140
6141 f_sleep(1.0);
6142
6143 /* re-connect */
6144 PCU.clear;
6145 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6146
6147 f_sleep(2.0);
6148 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006149
6150 if (f_si_has_gprs_indicator(si_type)) {
6151 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006152 } else {
6153 setverdict(pass);
6154 }
6155
6156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6157}
6158
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006159testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6160 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6161}
6162
6163testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6164 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6165}
6166
Oliver Smithf5239c72019-08-28 10:01:25 +02006167/* 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) */
6168testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6169 var SystemInformation si3 := valueof(ts_SI3_default);
6170
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006171 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006172
Harald Welte76220222020-10-11 20:32:44 +02006173 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6174 * information */
6175 timer T := 2.0;
6176 T.start;
6177 alt {
6178 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6179 [] T.timeout {}
6180 }
6181
Oliver Smithf5239c72019-08-28 10:01:25 +02006182 /* Verify cell_id */
6183 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6184 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6185 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006186 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6187 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6188 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006189 }
6190
6191 /* Verify LAC */
6192 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6193 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6194 if (lac_si3 != lac_pcu) {
6195 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6196 }
6197
6198 setverdict(pass);
6199}
Harald Welted66c9b82019-05-25 09:03:15 +02006200
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006201/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6202testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6203 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006204 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006205
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006206 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006207
6208 info_ind := g_pcu_last_info.u.info_ind;
6209
6210 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6211 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006212 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006213 /* Skip inactive timeslots */
6214 continue;
6215 }
6216
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006217 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006218 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006219 else
6220 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006221
6222 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006223 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006224 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006225 hsn := fhp.maio_hsn.hsn,
6226 maio := fhp.maio_hsn.maio,
6227 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006228 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006229 } else {
6230 tr_ts := tr_PCUIF_InfoTrxTsH0;
6231 }
6232
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006233 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006234 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6235 if (not match(ts, tr_ts)) {
6236 setverdict(fail, "Hopping parameters do not match: ",
6237 "received ", ts, " vs expected ", tr_ts);
6238 } else {
6239 setverdict(pass);
6240 }
6241 }
6242 }
6243}
6244
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006245/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006246testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6247 f_init_vty_bsc();
6248 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6249 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6250
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006251 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006252
6253 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006254 var template PCUIF_RemoteAddr tr_remote_addr := {
6255 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006256 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006257 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006258
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006259 if (not match(remote_addr, tr_remote_addr)) {
6260 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006261 }
6262
6263 setverdict(pass);
6264}
6265
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006266/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006267testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6268 f_init_vty_bsc();
6269 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6270
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006271 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006272
6273 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006274 var template PCUIF_RemoteAddr tr_remote_addr := {
6275 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6276 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6277 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006278
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006279 if (not match(remote_addr, tr_remote_addr)) {
6280 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006281 }
6282
6283 setverdict(pass);
6284}
6285
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006286/* Verify coding of two NSVCs in the INFO.ind message */
6287testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6288 f_init_vty_bsc();
6289
6290 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6291 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6292 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6293 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6294
6295 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6296 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6297 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6298 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6299
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006300 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006301
6302 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6303 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6304 var template PCUIF_RemoteAddr tr_remote_addr := {
6305 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006306 addr := {
6307 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6308 f_inet6_addr("fd00::ca:ff:ee")
6309 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006310 };
6311
6312 if (not match(info_ind.nsvci, { 1234, 5678 }))
6313 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6314 if (not match(remote_addr, tr_remote_addr))
6315 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6316 if (not match(info_ind.local_port, { 1234, 5678 }))
6317 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6318 if (not match(info_ind.remote_port, { 1234, 5678 }))
6319 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6320
6321 setverdict(pass);
6322}
6323
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006324/* Verify periodic interference reports on PDCH */
6325testcase TC_pcu_interf_ind() runs on test_CT {
6326 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006327 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006328 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006329 var PCUIF_send_data sd;
6330 timer T;
6331
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006332 /* Set the averaging/reporting period to 480ms */
6333 f_init_vty_bsc();
6334 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6335 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6336
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006337 f_init_with_pcuif();
6338 f_TC_pcu_act_req(0, 0, 7, true);
6339
6340 /* We need trxcon for NOPE indications */
6341 f_init_l1ctl();
6342 f_l1_tune(L1CTL);
6343
6344 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006345 tr_interf_ind := tr_PCUIF_INTERF_IND(
6346 bts_nr := 0,
6347 trx_nr := 0,
6348 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006349 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006350 );
6351
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006352 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006353 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006354 /* The first interference report may contain unreliable values, so we ignore it */
6355 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6356 /* 4 SACCH periods => 4 reports (plus some guard time) */
6357 T.start(0.480 * 4.0 + 0.480 / 2.0);
6358 first := false;
6359 repeat;
6360 }
6361 /* Subsequent interference reports shall match our expectations */
6362 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006363 /* Check TDMA frame number period */
6364 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6365 setverdict(fail, "Odd TDMA frame number := ",
6366 sd.data.u.interf_ind.fn);
6367 }
6368 interf_ind_num := interf_ind_num + 1;
6369 if (interf_ind_num < 4)
6370 { repeat; }
6371 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006372 [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 +02006373 setverdict(fail, "Received unexpected interference report: ", sd.data);
6374 }
6375 [] PCU.receive { repeat; }
6376 [] T.timeout {
6377 setverdict(fail, "Timeout waiting for interference reports");
6378 }
6379 }
6380
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006381 /* Reset the averaging/reporting period back to default */
6382 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6383
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6385}
6386
Harald Welte3d04ae62018-04-04 20:29:05 +02006387/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006388 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006389 ***********************************************************************/
6390
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006391private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6392 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006393runs on ConnHdlr {
6394 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006395
6396 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006397 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006398 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6399 repeat;
6400 }
6401 }
6402}
6403
6404private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6405runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006406 /* Expect BTS to immediately acknowledge activation as PDCH */
6407 PCU.clear;
6408 f_rsl_chan_act(g_pars.chan_mode);
6409 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006410 timer T_wait := 2.0;
6411 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006412 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006413 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006414 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006415 [] T_wait.timeout {
6416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6417 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6418 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006419 }
6420 /* try to activate this PDCH from the PCU point of view */
6421 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6422 /* FIXME: is there a response? */
6423}
6424
6425private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6426runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006427 /* Send RSL CHAN REL (deactivate) */
6428 PCU.clear;
6429 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6430 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006431 timer T_wait := 2.0;
6432 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006433 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006434 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006435 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006436 [] T_wait.timeout {
6437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6438 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6439 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006440 }
6441 /* Emulate PCU asking BTS to deactivate PDCH */
6442 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6443 alt {
6444 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6445 setverdict(pass);
6446 }
6447 [] RSL.receive { repeat; }
6448 }
6449}
6450
6451/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006452private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006453 var PCUIF_Message first_info;
6454 var integer ts_nr := g_chan_nr.tn;
6455 var integer trx_nr := 0;
6456 var integer bts_nr := 0;
6457 var integer pcu_conn_id := -1;
6458
6459 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6460
6461 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6462 f_sleep(3.0);
6463 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6464 setverdict(pass);
6465}
6466testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6467 var ConnHdlrPars pars;
6468 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006469 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006470
6471 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6472 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6473 vc_conn.done;
6474}
6475
6476/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006477private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006478 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006479 var integer pcu_conn_id := -1;
6480
6481 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6482
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006483 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6484 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6485 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006486 setverdict(pass);
6487}
6488testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6489 var ConnHdlrPars pars;
6490 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006491 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006492
6493 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6494 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6495 vc_conn.done;
6496}
6497
6498/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006499private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006500 var PCUIF_Message first_info;
6501 var integer ts_nr := g_chan_nr.tn;
6502 var integer trx_nr := 0;
6503 var integer bts_nr := 0;
6504 var integer pcu_conn_id := -1;
6505
6506 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6507
6508 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006509 /* Send a second Chan Activ and expect it to be NACKed */
6510 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6511 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006512 setverdict(pass);
6513}
6514testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6515 var ConnHdlrPars pars;
6516 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006517 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006518
6519 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6520 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6521 vc_conn.done;
6522}
6523
6524/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006525private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006526 var PCUIF_Message first_info;
6527 var integer ts_nr := g_chan_nr.tn;
6528 var integer trx_nr := 0;
6529 var integer bts_nr := 0;
6530 var integer pcu_conn_id := -1;
6531 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6532
6533 /* register for the TCH/F channel number */
6534 f_rslem_register(0, chan_nr);
6535
6536 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6537
6538 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6539 "RSL CHAN ACT");
6540 setverdict(pass);
6541}
6542testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6543 var ConnHdlrPars pars;
6544 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006545 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006546
6547 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6548 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6549 vc_conn.done;
6550}
6551
6552/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006553private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006554 var PCUIF_Message first_info;
6555 var integer ts_nr := g_chan_nr.tn;
6556 var integer trx_nr := 0;
6557 var integer bts_nr := 0;
6558 var integer pcu_conn_id := -1;
6559 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6560 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6561
6562 /* register for the TCH/H channel numbers */
6563 f_rslem_register(0, chan_nr[0]);
6564 f_rslem_register(0, chan_nr[1]);
6565
6566 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6567
6568 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6569 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6570 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6571 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6572 setverdict(pass);
6573}
6574testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6575 var ConnHdlrPars pars;
6576 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006577 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006578
6579 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6580 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6581 vc_conn.done;
6582}
6583
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006584/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6585private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6586 var PCUIF_Message first_info;
6587 var integer ts_nr := g_chan_nr.tn;
6588 var integer trx_nr := 0;
6589 var integer bts_nr := 0;
6590 var integer pcu_conn_id := -1;
6591 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6592 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6593 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6594 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6595 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6596 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6597 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6598 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6599
6600 /* register for the TCH/H channel numbers */
6601 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6602 f_rslem_register(0, chan_nr[i]);
6603 }
6604
6605 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6606
6607 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6608 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6609 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6610 }
6611 setverdict(pass);
6612}
6613testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6614 var ConnHdlrPars pars;
6615 var ConnHdlr vc_conn;
6616 f_init();
6617
6618 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6619 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6620 vc_conn.done;
6621}
6622
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006623/* Reproduce a race condition described in OS#5245 */
6624private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6625 f_rsl_chan_act(g_pars.chan_mode);
6626 f_sleep(1.0);
6627 f_rsl_chan_deact();
6628 setverdict(pass);
6629}
6630testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6631 var ConnHdlrPars pars[2];
6632 var ConnHdlr vc_conn[2];
6633 var TrxcMessage rsp;
6634
6635 f_init();
6636
6637 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6638 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6639 ts_TRXC_FAKE_TRXC_DELAY(200));
6640
6641 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6642 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6643 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6644 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6645 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6646 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6647 pars[i], l1ctl := false);
6648 }
6649
6650 /* Wait for all components to finish */
6651 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6652 vc_conn[i].done;
6653 }
6654
6655 /* Disable the artificial delay for TRXC RSP messages */
6656 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6657 ts_TRXC_FAKE_TRXC_DELAY(0));
6658}
6659testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6660 var ConnHdlrPars pars[8];
6661 var ConnHdlr vc_conn[8];
6662 var TrxcMessage rsp;
6663
6664 f_init();
6665
6666 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6667 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6668 ts_TRXC_FAKE_TRXC_DELAY(200));
6669
6670 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6671 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6672 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6673 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6674 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6675 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6676 pars[i], l1ctl := false);
6677 }
6678
6679 /* Wait for all components to finish */
6680 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6681 vc_conn[i].done;
6682 }
6683
6684 /* Disable the artificial delay for TRXC RSP messages */
6685 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6686 ts_TRXC_FAKE_TRXC_DELAY(0));
6687}
6688
Harald Welte9bbbfb52018-04-05 09:33:19 +02006689/***********************************************************************
6690 * IPA Style Dynamic Timeslot Support
6691 ***********************************************************************/
6692
6693private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6694runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006695 /* Expect BTS to immediately acknowledge activation as PDCH */
6696 PCU.clear;
6697 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6698 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006699 timer T_wait := 2.0;
6700 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006701 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006702 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006703 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006704 [] T_wait.timeout {
6705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6706 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6707 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006708 }
6709 /* try to activate this PDCH from the PCU point of view */
6710 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6711 /* FIXME: is there a response? */
6712
6713 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6714}
6715
6716private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6717runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006718 /* Send RSL CHAN REL (deactivate) */
6719 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6720 PCU.clear;
6721 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006722 timer T_wait := 2.0;
6723 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006724 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006725 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006726 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006727 [] T_wait.timeout {
6728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6729 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6730 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006731 }
6732 /* Emulate PCU asking BTS to deactivate PDCH */
6733 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6734 alt {
6735 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6736 setverdict(pass);
6737 }
6738 [] RSL.receive { repeat; }
6739 }
6740}
6741
6742/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006743private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006744 var PCUIF_Message first_info;
6745 var integer ts_nr := g_chan_nr.tn;
6746 var integer trx_nr := 0;
6747 var integer bts_nr := 0;
6748 var integer pcu_conn_id := -1;
6749
6750 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6751
6752 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6753 f_sleep(3.0);
6754 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6755
6756 setverdict(pass);
6757
6758}
6759testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6760 var ConnHdlrPars pars;
6761 var ConnHdlr vc_conn;
6762 f_init();
6763
6764 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6765 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6766 vc_conn.done;
6767}
6768
6769/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006770private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006771 var PCUIF_Message first_info;
6772 var integer ts_nr := g_chan_nr.tn;
6773 var integer trx_nr := 0;
6774 var integer bts_nr := 0;
6775 var integer pcu_conn_id := -1;
6776
6777 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6778
6779 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6780 "RSL CHAN ACT");
6781 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6782 "RF CHAN REL", true);
6783 setverdict(pass);
6784}
6785testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6786 var ConnHdlrPars pars;
6787 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006788 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006789
6790 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6791 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6792 vc_conn.done;
6793}
6794
6795/* 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 +07006796private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006797 var PCUIF_Message first_info;
6798 var integer ts_nr := g_chan_nr.tn;
6799 var integer trx_nr := 0;
6800 var integer bts_nr := 0;
6801 var integer pcu_conn_id := -1;
6802
6803 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6804
6805 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6806 "RSL CHAN ACT");
6807
6808 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6809 alt {
6810 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6811 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006813 }
6814 [] RSL.receive { repeat; }
6815 }
6816
6817 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6818 "RF CHAN REL", true);
6819 setverdict(pass);
6820}
6821testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6822 var ConnHdlrPars pars;
6823 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006824 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006825
6826 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6827 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6828 vc_conn.done;
6829}
6830
6831/* 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 +07006832private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006833 var PCUIF_Message first_info;
6834 var integer ts_nr := g_chan_nr.tn;
6835 var integer trx_nr := 0;
6836 var integer bts_nr := 0;
6837 var integer pcu_conn_id := -1;
6838
6839 /* register for the TCH/F channel number */
6840 f_rslem_register(0, g_chan_nr);
6841
6842 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6843
6844 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6845
6846 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6847 "RSL CHAN ACT");
6848
6849 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6850
6851 setverdict(pass);
6852}
6853testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6854 var ConnHdlrPars pars;
6855 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006856 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006857
6858 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6859 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6860 vc_conn.done;
6861}
6862
6863
Harald Welte0472ab42018-03-12 15:02:26 +01006864/***********************************************************************
6865 * LAPDm / RLL related
6866 ***********************************************************************/
6867
6868private function f_tx_lapdm(template (value) LapdmFrame l,
6869 template (value) RslLinkId link_id) runs on ConnHdlr {
6870 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006871 var template (value) SacchL1Header l1h;
6872
6873 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006874 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006875 /* Compose dummy L1 header */
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07006876 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006877 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 +02006878 } else {
6879 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006880 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 +01006881 }
Harald Welte0472ab42018-03-12 15:02:26 +01006882}
6883
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006884friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006885 uint3_t sapi,
6886 RslLinkId link_id,
6887 octetstring l3,
6888 boolean exp
6889}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006890friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006891friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6892 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006893 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006894 sapi := sapi,
6895 link_id := id,
6896 l3 := l3,
6897 exp := exp
6898}
6899
6900/* execute the same callback function with a set of different parameters (tcs) on a
6901 * variety of logical channels */
6902private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6903 var ConnHdlrPars pars;
6904 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006905 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006906
6907 /* test on each of the channels we have */
6908 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6909 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6910
6911 /* test each of the test cases on the current channel */
6912 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6913 pars.spec.rll := tcs[j];
6914 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6915 vc_conn := f_start_handler(fn, pars);
6916 vc_conn.done;
6917 }
6918 }
6919
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006921}
6922
6923/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6924private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6925 var RllTestCase tc := g_pars.spec.rll;
6926 timer T := 3.0;
6927
6928 f_l1_tune(L1CTL);
6929 RSL.clear;
6930
6931 /* activate the logical channel */
6932 f_est_dchan();
6933 L1CTL.clear;
6934
6935 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6936 T.start;
6937 alt {
6938 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6939 if (tc.exp) {
6940 setverdict(pass);
6941 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006943 }
6944 }
6945 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6946 if (tc.exp) {
6947 setverdict(pass);
6948 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006950 }
6951 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006952 /* We also expect to receive the measurements */
6953 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006954 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006956 }
6957 [not tc.exp] T.timeout {
6958 setverdict(pass);
6959 }
6960 }
6961
6962 f_rsl_chan_deact();
6963 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6964 f_rslem_unregister(0, g_chan_nr);
6965}
6966testcase TC_rll_est_ind() runs on test_CT {
6967 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006968 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006969 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006970 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006971 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006972 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006973 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6974 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006975 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006976 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006977 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006978 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006979 };
6980 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6981}
6982
6983/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6984private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6985 var RllTestCase tc := g_pars.spec.rll;
6986 var L1ctlDlMessage dl;
6987 timer T := 3.0;
6988
6989 f_l1_tune(L1CTL);
6990 RSL.clear;
6991
6992 /* activate the logical channel */
6993 f_est_dchan();
6994 L1CTL.clear;
6995
6996 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6997 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6998 T.start;
6999 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007000 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007001 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007003 }
7004 }
7005
7006 f_rsl_chan_deact();
7007 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7008 f_rslem_unregister(0, g_chan_nr);
7009}
7010testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7011 var RllTestCases tcs := {
7012 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007013 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007014 };
7015 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7016}
7017testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7018 var RllTestCases tcs := {
7019 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007020 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007021 }
7022 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7023}
7024
7025/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007026friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007027 var L1ctlDlMessage dl;
7028 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7029 var LapdmFrame lapdm;
7030 var octetstring l2 := dl.payload.data_ind.payload;
7031 if (dl.dl_info.link_id.c == SACCH) {
7032 /* remove L1 header */
7033 l2 := substr(l2, 2, lengthof(l2)-2);
7034 }
7035 if (ischosen(exp.ab)) {
7036 lapdm.ab := dec_LapdmFrameAB(l2);
7037 } else if (ischosen(exp.b4)) {
7038 lapdm.b4 := dec_LapdmFrameB4(l2);
7039 } else if (ischosen(exp.bbis)) {
7040 lapdm.bbis := dec_LapdmFrameBbis(l2);
7041 }
7042 log("Rx LAPDm ", lapdm);
7043 if (match(lapdm, exp)) {
7044 setverdict(pass);
7045 } else {
7046 repeat;
7047 }
7048 }
7049 [] L1CTL.receive { repeat; }
7050}
7051private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7052 timer T := t;
7053 T.start;
7054 alt {
7055 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007057 }
7058 [] as_l1_exp_lapdm(exp);
7059 }
7060}
7061
7062/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7063private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007064 timer T := 2.0;
Harald Welte0472ab42018-03-12 15:02:26 +01007065 /* send SABM from MS -> BTS */
7066 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7067 /* expect RLL EST IND on Abis */
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007068 T.start;
Harald Welte0472ab42018-03-12 15:02:26 +01007069 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; }
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007076 [] T.timeout {
7077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RLL EST IND");
7078 }
Harald Welte0472ab42018-03-12 15:02:26 +01007079 }
7080 /* expect UA from BTS -> MS */
7081 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7082}
7083
7084/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7085private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7086 var RllTestCase tc := g_pars.spec.rll;
7087
7088 f_l1_tune(L1CTL);
7089 RSL.clear;
7090
7091 /* activate the logical channel */
7092 f_est_dchan();
7093 L1CTL.clear;
7094
7095 /* first establish the link-layer */
7096 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7097
7098 /* then send the DISC */
7099 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7100 /* ... and expect the REL IND on the RSL side */
7101 alt {
7102 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7103 setverdict(pass);
7104 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007105 /* We also expect to receive the measurements */
7106 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007107 }
7108
7109 /* release the channel */
7110 f_rsl_chan_deact();
7111 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7112 f_rslem_unregister(0, g_chan_nr);
7113}
7114testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7115 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007116 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007117 };
7118 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7119}
7120
7121testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7122 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007123 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007124 };
7125 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7126}
7127testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7128 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007129 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007130 };
7131 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7132}
7133testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7134 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007135 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007136 };
7137 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7138}
7139
7140/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7141private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7142 var RllTestCase tc := g_pars.spec.rll;
7143 f_l1_tune(L1CTL);
7144 RSL.clear;
7145
7146 /* activate the logical channel */
7147 f_est_dchan();
7148 L1CTL.clear;
7149
7150 /* first establish the link-layer */
7151 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7152
7153 /* then send the REL REQ via RSL */
7154 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7155 /* ... and expect the DISC on the Um side */
7156 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007157 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007158 /* FIXME: send a UA in resposne to the DISC */
7159 }
7160 }
7161
7162 /* release the channel */
7163 f_rsl_chan_deact();
7164 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7165 f_rslem_unregister(0, g_chan_nr);
7166}
7167testcase TC_rll_rel_req() runs on test_CT {
7168 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007169 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7170 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7171 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7172 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007173 };
7174 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7175}
7176
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007177/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007178testcase TC_rll_data_req() runs on test_CT {
7179}
7180
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007181/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007182testcase TC_rll_data_ind() runs on test_CT {
7183}
7184
7185/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7186private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7187 var RllTestCase tc := g_pars.spec.rll;
7188
7189 f_l1_tune(L1CTL);
7190 RSL.clear;
7191
7192 f_est_dchan();
7193 L1CTL.clear;
7194
7195 /* Send UNITDATA REQ on RSL side */
7196 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7197 /* Expect it to arrive on the other side */
7198 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007199 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007200 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007201 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007202 }
7203
7204 /* release the channel */
7205 f_rsl_chan_deact();
7206 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7207 f_rslem_unregister(0, g_chan_nr);
7208}
7209testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7210 var octetstring l3 := f_rnd_octstring(15);
7211 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007212 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7213 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007214 };
7215 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7216}
7217testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7218 var octetstring l3 := f_rnd_octstring(19);
7219 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007220 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7221 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007222 };
7223 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7224}
7225
7226/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7227private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7228 var RllTestCase tc := g_pars.spec.rll;
7229
7230 f_l1_tune(L1CTL);
7231 RSL.clear;
7232
7233 f_est_dchan();
7234 L1CTL.clear;
7235
7236 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007237 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007238 /* Expdct RLL UNITDATA IND on RSL side */
7239 alt {
7240 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7241 setverdict(pass);
7242 }
7243 [] RSL.receive { repeat; }
7244 }
7245
7246 /* release the channel */
7247 f_rsl_chan_deact();
7248 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7249 f_rslem_unregister(0, g_chan_nr);
7250}
7251testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007252 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007253 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007254 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7255 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007256 };
7257 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7258}
7259testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7260 var octetstring l3 := f_rnd_octstring(18);
7261 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007262 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7263 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007264 };
7265 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7266}
7267
Harald Weltee613f962018-04-18 22:38:16 +02007268/***********************************************************************
7269 * Encryption Related
7270 ***********************************************************************/
7271
7272/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007273private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007274 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7275 if (link_id.c == SACCH) {
7276 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7277 } else {
7278 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7279 }
7280}
7281
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007282/* Expect (or not expect) other kinds of messages */
7283private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7284 [exp_any] RSL.receive { repeat; }
7285 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007287 }
7288}
7289
Harald Weltee613f962018-04-18 22:38:16 +02007290/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007291private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007292 RslLinkId link_id,
7293 octetstring l3,
7294 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007295 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007296) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007297 timer T := 3.0;
7298 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7299 T.start;
7300 /* Expect RLL UNITDATA IND on RSL side */
7301 alt {
7302 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7303 setverdict(pass);
7304 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007305 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007306 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007307 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007309 }
Harald Weltee613f962018-04-18 22:38:16 +02007310 }
7311}
7312
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007313/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7314private function f_data_mo(
7315 RslLinkId link_id,
7316 boolean p, uint3_t nr, uint3_t ns,
7317 octetstring l3,
7318 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007319 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007320) runs on ConnHdlr {
7321 timer T := 3.0;
7322 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7323 T.start;
7324 /* Expect RLL DATA IND on RSL side */
7325 alt {
7326 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7327 setverdict(pass);
7328 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007329 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007330 [] as_rsl_any_ind(exp_any);
7331 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007333 }
7334 }
7335}
7336
Harald Weltee613f962018-04-18 22:38:16 +02007337/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007338private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007339 f_l1_tune(L1CTL);
7340 f_est_dchan(true);
7341
7342 /* now we actually need to transmit some data both ways to check if the encryption works */
7343 var L1ctlDlMessage dl;
7344
Stefan Sperling603d98e2018-07-25 16:47:28 +02007345 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007346 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7347
7348 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7349 f_unitdata_mt(link_id, l3);
7350
7351 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7352 f_unitdata_mo(link_id, l3);
7353
7354 /* release the channel */
7355 f_rsl_chan_deact();
7356 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7357 f_rslem_unregister(0, g_chan_nr);
7358}
7359testcase TC_chan_act_a51() runs on test_CT {
7360 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7361 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7362 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7363}
7364testcase TC_chan_act_a52() runs on test_CT {
7365 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7366 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7367 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7368}
7369testcase TC_chan_act_a53() runs on test_CT {
7370 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7371 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7372 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7373}
Eric Wildb9260392021-05-15 19:48:22 +02007374testcase TC_chan_act_a54() runs on test_CT {
7375 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7376 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7377 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7378}
Harald Weltee613f962018-04-18 22:38:16 +02007379
Eric Wildf1827a72019-05-28 17:37:35 +02007380/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7381 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 +07007382private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007383 f_l1_tune(L1CTL);
7384 f_est_dchan(true);
7385
7386 /* now we actually need to transmit some data both ways to check if the encryption works */
7387 var L1ctlDlMessage dl;
7388
7389 var octetstring l3 := f_rnd_octstring(20);
7390 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7391
7392 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7393 f_unitdata_mt(link_id, l3);
7394
7395 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7396 f_unitdata_mo(link_id, l3);
7397
7398 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007399 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007400
7401 /* modify key to break proper encryption */
7402 g_pars.encr.key := f_rnd_octstring(8);
7403 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7404 rsl.ies := rsl.ies & { ei };
7405 RSL.send(rsl);
7406
7407 timer T0 := 1.0;
7408 T0.start;
7409 /* Expect RSL MODIFY ACK */
7410 alt {
7411 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7412 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7414 }
7415 [] T0.timeout {
7416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7417 }
7418 }
7419
7420 var octetstring l3msg := f_rnd_octstring(15);
7421 timer T1 := 3.0;
7422 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7423 due to broken encryption */
7424 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7425 T1.start;
7426 alt {
7427 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7429 }
7430 [] T1.timeout {
7431 setverdict(pass);
7432 }
7433 }
7434
7435 /* release the channel */
7436 f_rsl_chan_deact();
7437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7438 f_rslem_unregister(0, g_chan_nr);
7439}
7440testcase TC_rsl_modify_encr() runs on test_CT {
7441 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7442 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7443 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7444}
Harald Weltee613f962018-04-18 22:38:16 +02007445
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007446/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007447private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007448runs on test_CT {
7449 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7450 var ASP_RSL_Unitdata ud;
7451 timer T;
7452
7453 /* Intave is 6 SACCH periods by default */
7454 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7455
7456 T.start(Tval);
7457 alt {
7458 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7459 setverdict(pass);
7460 }
7461 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7462 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7463 }
7464 [] RSL_CCHAN.receive { repeat; }
7465 [] T.timeout {
7466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7467 "Timeout waiting for RF RESource INDication");
7468 }
7469 }
7470}
7471testcase TC_rsl_rf_resource_ind() runs on test_CT {
7472 var RSL_ResourceInfo info := { };
7473
7474 f_init(trx_nr := 0);
7475
7476 f_init_l1ctl();
7477 f_l1_tune(L1CTL);
7478
7479 /* g_AllChannels contains all logical channels */
7480 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7481 var RslChannelNr chan_nr := g_AllChannels[i];
7482
7483 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7484 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7485 { continue; }
7486
7487 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7488 }
7489
7490 /* Align to the first interference report */
7491 f_TC_rsl_rf_resource_ind(?);
7492
7493 /* Test 4 consecutive messages */
7494 for (var integer i := 0; i < 4; i := i + 1) {
7495 f_TC_rsl_rf_resource_ind(info);
7496 }
7497
7498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7499}
7500
Harald Weltee613f962018-04-18 22:38:16 +02007501/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007502private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007503 /* L3 payload doesn't matter, as it is passed transparently */
7504 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7505 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7506 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7507
7508 f_l1_tune(L1CTL);
7509
7510 /* first establish a dedicated channel in the clear */
7511 f_est_dchan(false);
7512
7513 /* Establish ABM */
7514 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7515
7516 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7517 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7518 /* expect the L3 to arrive still unencrypted on the MS side */
7519 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7520
7521 /* configure L1 to apply ciphering */
7522 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7523 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7524
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007525 /* send first ciphered I-frame in response and expect it on RSL */
7526 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007527
7528 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7529 * and hence enable encryption also on the downlink */
7530
7531 /* expect bi-directional communication work in encrypted mode */
7532 f_unitdata_mo(link_id, f_rnd_octstring(15));
7533 f_unitdata_mt(link_id, f_rnd_octstring(15));
7534
7535 /* release the channel */
7536 f_rsl_chan_deact();
7537 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7538 f_rslem_unregister(0, g_chan_nr);
7539}
7540testcase TC_encr_cmd_a51() runs on test_CT {
7541 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7542 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7543 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7544}
7545testcase TC_encr_cmd_a52() runs on test_CT {
7546 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7547 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7548 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7549}
7550testcase TC_encr_cmd_a53() runs on test_CT {
7551 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7552 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7553 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7554}
Eric Wildb9260392021-05-15 19:48:22 +02007555testcase TC_encr_cmd_a54() runs on test_CT {
7556 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7557 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7558 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7559}
Harald Weltee613f962018-04-18 22:38:16 +02007560
7561private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7562 var LapdmFrame lf;
7563 var octetstring reenc;
7564
7565 /* decode the LAPDm frame */
7566 if (ischosen(exp_match.ab)) {
7567 lf.ab := dec_LapdmFrameAB(enc);
7568 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007570 }
7571
7572 /* check if decoder result matches expectation */
7573 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007575 } else {
7576 log(name, ": matched");
7577 setverdict(pass);
7578 }
7579
7580 /* test if re-encoded frame equals original input */
7581 reenc := enc_LapdmFrame(lf);
7582 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007584 } else {
7585 setverdict(pass);
7586 }
7587}
7588
7589testcase TC_lapdm_selftest() runs on test_CT {
7590 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7591 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7592 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7593 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7594 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7595 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7596 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7597}
7598
Stefan Sperling4880be42018-08-07 18:12:59 +02007599/***********************************************************************
7600 * DTX Related (see GSM 05.08, section 8.3)
7601 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007602private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007603 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007604 var GsmFrameNumber first_fn;
7605 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007606 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007607 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007608 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7609 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007610 const integer frame_dtx_tchf_mod := 104;
7611 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7612 * which operates in terms of blocks rather than frames. */
7613 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7614 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007615 timer T := 5.0;
7616
7617 f_l1_tune(L1CTL);
7618 RSL.clear;
7619 L1CTL.clear;
7620
7621 /* activate TCHF signalling channel */
7622 f_est_dchan(false);
7623
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007624 /* A template for matching dummy LAPDm func=UA frames */
7625 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7626 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7627 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7628
Stefan Sperling4880be42018-08-07 18:12:59 +02007629 T.start;
7630 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007631 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007632 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007633
7634 if (is_first_frame) {
7635 is_first_frame := false;
7636 first_fn := dl.dl_info.frame_nr;
7637 }
7638
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007639 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007640 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007641 T.stop;
7642 f_rsl_chan_deact();
7643 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007644
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007645 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7646 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007647
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007648 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007649 setverdict(fail, "Not enough fill frames received: ",
7650 nfill_frames, " out of ", expected_fill_frames);
7651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007652 } else {
7653 setverdict(pass);
7654 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007655 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007656 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7657 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7658 * we should only see the subset of frames numbers which correspond to a block boundary.
7659 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7660 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7661 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007662 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007663 repeat;
7664 }
7665 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007666 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7667 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7668 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007669 f_rsl_chan_deact();
7670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007671 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007672 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007673 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007674 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007675 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007676
7677 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007678 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7679 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007680 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7681 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7682 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007683 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7684 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007685 case else {
7686 /* This shall not happen, just to be sure */
7687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7688 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007689 }
7690
7691 f_rsl_chan_deact();
7692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007693
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007694 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007695 setverdict(pass);
7696 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007697 setverdict(fail, "Not enough fill frames received: ",
7698 nfill_frames, " out of ", expected_fill_frames);
7699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007700 }
7701 } else {
7702 repeat;
7703 }
7704 }
7705 }
7706 [] L1CTL.receive { repeat; }
7707 [] T.timeout {
7708 f_rsl_chan_deact();
7709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007711 }
7712 }
7713}
7714
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007715private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007716 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007717 var ConnHdlr vc_conn;
7718 var ConnHdlrPars pars;
7719 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007720 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007721 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007722 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007723 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007724 if (dtxd) {
7725 if (i >= 4) { /* DTX is only allowed on TCH/F */
7726 break;
7727 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007728 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007729 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007730 vc_conn.done;
7731 }
7732}
7733
7734/* Verify that L2 fill frames are sent on TCH in signaling mode if
7735 * there is nothing to transmit while DTX is disabled on downlink. */
7736testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7737 f_tch_sign_l2_fill_frame(false);
7738}
7739
7740/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7741 * there is nothing to transmit while DTX is enabled on downlink. */
7742testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7743 f_tch_sign_l2_fill_frame(true);
7744}
Harald Welte0472ab42018-03-12 15:02:26 +01007745
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007746testcase TC_chopped_ipa_ping() runs on test_CT {
7747 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7748}
7749
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007750testcase TC_chopped_ipa_payload() runs on test_CT {
7751 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7752}
7753
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007754
7755/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7756 * Return value: Measurement Report to be sent (encoded octetstring). */
7757type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7758 runs on ConnHdlr return octetstring;
7759
7760private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7761runs on ConnHdlr {
7762 var L1ctlDlMessage l1_dl;
7763 var SacchL1Header l1h;
7764 var octetstring l2;
7765
7766 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7767 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7768 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7769 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7770
7771 /* Pass it to the user specified call-back function */
7772 l2 := cb.apply(l1h, num_blocks);
7773 /* Send a Measurement Report generated by the call-back */
7774 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7775 l1_dl.dl_info.link_id,
7776 l1h, l2));
7777
7778 /* Shall we keep going? */
7779 num_blocks := num_blocks - 1;
7780 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7781 if (num_blocks > 0) { repeat; }
7782 }
7783 [] L1CTL.receive { repeat; }
7784}
7785
7786private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7787runs on ConnHdlr return octetstring {
7788 /* Command the L1 to apply received parameters */
7789 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7790
7791 /* Dummy measurement report (the results are invalid) */
7792 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7793}
7794
7795private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7796runs on ConnHdlr return octetstring {
7797 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7798 setverdict(fail, "Unexpected MS Power level change: ",
7799 g_pars.l1_pars.ms_power_level, " -> ",
7800 l1h.ms_power_lvl);
7801 }
7802
7803 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7804}
7805
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007806private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7807runs on ConnHdlr return octetstring {
7808 /* UL RSSI oscillation driven by SACCH block number */
7809 if (num_blocks rem 2 == 0) {
7810 f_trxc_fake_rssi(-100);
7811 } else {
7812 f_trxc_fake_rssi(-50);
7813 }
7814
7815 /* Make sure that MS power level remains constant */
7816 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7817}
7818
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007819/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7820private function f_TC_ms_pwr_ctrl_constant(charstring id)
7821runs on ConnHdlr {
7822 var integer num_blocks := 8;
7823 timer T := int2float(num_blocks);
7824
7825 f_l1_tune(L1CTL);
7826 RSL.clear;
7827
7828 /* These IEs are needed for autonomous MS power control */
7829 var template (value) RSL_IE_List ies := {
7830 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7831 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7832 }),
7833 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7834 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7835 })
7836 };
7837
7838 /* Ensure that 'rx-current' equals 'rx-target' */
7839 f_trxc_fake_rssi(mp_uplink_power_target);
7840
7841 /* Establish a dedicated channel */
7842 f_est_dchan(more_ies := valueof(ies));
7843
7844 L1CTL.clear;
7845 T.start;
7846 alt {
7847 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7848 [] T.timeout {
7849 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7850 num_blocks, " were not handled");
7851 }
7852 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007853
7854 /* Release the channel */
7855 f_rsl_chan_deact();
7856 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007857}
7858testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7859 var ConnHdlr vc_conn;
7860 var ConnHdlrPars pars;
7861
7862 f_init();
7863
7864 /* Explicitly configure the Uplink power target (in dBm) */
7865 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7866
7867 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7868 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7869 log(testcasename(), ": starting on ", pars.chan_nr);
7870
7871 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7872 pars, trxc_comp := true);
7873 vc_conn.done;
7874 }
7875
7876 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7878}
7879
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007880/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7881private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7882runs on ConnHdlr {
7883 var integer num_blocks := 16;
7884 timer T := int2float(num_blocks);
7885
7886 f_l1_tune(L1CTL);
7887 RSL.clear;
7888
7889 /* These IEs are needed for autonomous MS power control */
7890 var template (value) RSL_IE_List ies := {
7891 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7892 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7893 }),
7894 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7895 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7896 })
7897 };
7898
7899 /* Ensure that 'rx-current' equals 'rx-target' */
7900 f_trxc_fake_rssi(mp_uplink_power_target);
7901
7902 /* Establish a dedicated channel */
7903 f_est_dchan(more_ies := valueof(ies));
7904
7905 L1CTL.clear;
7906 T.start;
7907 alt {
7908 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7909 [] T.timeout {
7910 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7911 num_blocks, " were not handled");
7912 }
7913 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007914
7915 /* Release the channel */
7916 f_rsl_chan_deact();
7917 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007918}
7919testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7920 var ConnHdlr vc_conn;
7921 var ConnHdlrPars pars;
7922
7923 f_init();
7924
7925 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7926 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7927 /* Explicitly configure the Uplink power range (target and delte) */
7928 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7929 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7930
7931 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7932 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7933 log(testcasename(), ": starting on ", pars.chan_nr);
7934
7935 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7936 pars, trxc_comp := true);
7937 vc_conn.done;
7938 }
7939
7940 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7941 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7942}
7943
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007944private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7945 var template L1ctlDlMessage tr_bad_frame;
7946 var L1ctlDlMessage l1_dl;
7947 timer T := 8.0;
7948
7949 f_l1_tune(L1CTL);
7950 RSL.clear;
7951
7952 f_est_dchan();
7953
7954 /* There may be a few errors right after the channel activation */
7955 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7956 L1CTL.clear;
7957
7958 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7959 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7960 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7961 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7962 tr_bad_frame.payload := ?;
7963
7964 T.start;
7965 alt {
7966 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7967 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7968 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7969 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7970 }
7971 [] as_l1_sacch();
7972 [] L1CTL.receive { repeat; }
7973 [] T.timeout {
7974 /* We're done, break the loop */
7975 setverdict(pass);
7976 }
7977 }
7978
7979 f_rsl_chan_deact();
7980 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7981}
7982testcase TC_speech_no_rtp_tchf() runs on test_CT {
7983 var ConnHdlr vc_conn;
7984 var ConnHdlrPars pars;
7985
7986 f_init();
7987
7988 /* TS1, TCH/F, V1 (FR codec) */
7989 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7990 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7991 vc_conn.done;
7992}
7993testcase TC_speech_no_rtp_tchh() runs on test_CT {
7994 var ConnHdlr vc_conn;
7995 var ConnHdlrPars pars;
7996
7997 f_init();
7998
7999 /* TS5, TCH/H, V1 (HR codec) */
8000 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8001 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8002 vc_conn.done;
8003}
8004
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008005/* Verify handling of Downlink and Uplink speech frames */
8006private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8007 var L1ctlDlMessage l1_dl;
8008 var PDU_RTP rtp_pdu;
8009 var octetstring pl;
8010 timer Td, Tu;
8011
8012 f_l1_tune(L1CTL);
8013 f_est_dchan();
8014
8015 /* Activate the RTP emulation */
8016 pl := f_rnd_octstring(6);
8017 f_rtpem_activate(pl);
8018
8019 /* Give the scheduler some time to fill up the buffers */
8020 f_sleep(2.0);
8021 L1CTL.clear;
8022 RSL.clear;
8023
8024 /* Make sure that Downlink frames are received at the UE */
8025 Td.start(2.0);
8026 alt {
8027 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8028 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8029 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8030 l1_dl.payload.traffic_ind.data));
8031 setverdict(pass);
8032 }
8033 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8034 setverdict(fail, "Rx unexpected Downlink speech frame ",
8035 "(", l1_dl.payload.traffic_ind.data, ") ",
8036 "expected (", pl, ")");
8037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8038 }
8039 [] as_l1_sacch();
8040 [] L1CTL.receive { repeat; }
8041 [] Td.timeout {
8042 setverdict(fail, "Timeout waiting for Downlink speech frames");
8043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8044 }
8045 }
8046
8047 /* Make sure that Uplink frames are received at the BTS */
8048 RTPEM_DATA.clear;
8049 Tu.start(2.0);
8050 alt {
8051 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8052 if (rtp_pdu.data != pl)
8053 { repeat; }
8054 }
8055 [] RTPEM_DATA.receive { repeat; }
8056 [] Tu.timeout {
8057 setverdict(fail, "Timeout waiting for Uplink speech frames");
8058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8059 }
8060 }
8061
8062 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8063 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8064 f_rsl_chan_deact();
8065 f_rslem_unregister(0, g_chan_nr);
8066}
8067testcase TC_speech_rtp_tchf() runs on test_CT {
8068 var ConnHdlr vc_conn;
8069 var ConnHdlrPars pars;
8070
8071 f_init();
8072
8073 /* TS1, TCH/F, V1 (FR codec) */
8074 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8075 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8076 vc_conn.done;
8077
8078 /* TS1, TCH/F, V2 (EFR codec) */
8079 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8080 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8081 vc_conn.done;
8082
8083 /* TODO: also test V3 (AMR codec) */
8084
8085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8086}
8087testcase TC_speech_rtp_tchh() runs on test_CT {
8088 var ConnHdlr vc_conn;
8089 var ConnHdlrPars pars;
8090
8091 f_init();
8092
8093 /* TS5, TCH/H0, V1 (HR codec) */
8094 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8095 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8096 vc_conn.done;
8097
8098 /* TODO: also test V3 (AMR codec) */
8099
8100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8101}
8102
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008103private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8104 var GsmFrameNumber fn;
8105 var ChannelDescription ch_desc;
8106 var integer ra := 23;
8107
8108 f_l1_tune(L1CTL);
8109 RSL.clear;
8110
8111 /* Send RACH request and wait for ChanReq */
8112 fn := f_rach_req_wait_chan_rqd(ra);
8113
8114 /* The BSC already sends the Immediate Assignment, before the channel is active.
8115 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8116 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8117 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8118 if (g_pars.fhp.enabled) {
8119 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8120 } else {
8121 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8122 }
8123 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8124 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8125
8126 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8127 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8128 var L1ctlDlMessage dl;
8129 var GsmRrMessage rr;
8130
8131 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8132 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8133 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8134 rr_imm_ass.payload.imm_ass.chan_desc := *;
8135
8136 timer T := 1.0;
8137 T.start;
8138 alt {
8139 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8140 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8141 if (match(rr, rr_imm_ass)) {
8142 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8143 mtc.stop;
8144 } else {
8145 repeat;
8146 }
8147 }
8148 [] L1CTL.receive { repeat; }
8149 [] T.timeout;
8150 }
8151 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8152 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8153
8154 /* Now expect the IMM ASS on Um */
8155 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8156 setverdict(pass);
8157
8158 /* Release the channel */
8159 f_rsl_chan_deact();
8160 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8161}
8162
8163testcase TC_early_immediate_assignment() runs on test_CT {
8164 var ConnHdlr vc_conn;
8165 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8166 f_init();
8167 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8168 vc_conn.done;
8169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8170}
8171
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008172private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8173 var integer ra := oct2int(f_rnd_ra_cs());
8174 var ChannelDescription ch_desc;
8175
8176 /* Tune the MS to BCCH */
8177 f_l1_tune(L1CTL);
8178
8179 /* Send RACH request and wait for ChanReq */
8180 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8181
8182 /* Activate channel on the BTS side */
8183 f_rsl_chan_act(g_pars.chan_mode);
8184
8185 /* Craft channel description (with or without frequency hopping parameters) */
8186 if (g_pars.fhp.enabled) {
8187 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8188 } else {
8189 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8190 }
8191
8192 /* Send IMM.ASS via CCHAN */
8193 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8194 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8195
8196 /* Receive IMM.ASS on the MS side */
8197 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8198
8199 /* Match the Channel Description IE in received IMM.ASS */
8200 if (not match(imm_ass.chan_desc, ch_desc)) {
8201 setverdict(fail, "Channel Description IE does not match");
8202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8203 }
8204
8205 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8206 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8207
8208 /* Expect SACCH frames on Downlink */
8209 L1CTL.clear;
8210 f_exp_sacch(true);
8211
8212 /* We're done, deactivate and release */
8213 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8214 f_rsl_chan_deact();
8215}
8216testcase TC_est_dchan() runs on test_CT {
8217 var ConnHdlr vc_conn;
8218 var ConnHdlrPars pars;
8219
8220 f_init();
8221
8222 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8223 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8224 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8225 vc_conn.done;
8226 }
8227
8228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8229}
8230
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008231private type record TopTestCase {
8232 RSL_IE_BS_Power bs_power,
8233 RSL_IE_OSMO_TopAcchCap top_cap,
8234 record of TopTestStep steps
8235};
8236private type record TopTestStep {
8237 MeasurementResults meas_res optional,
8238 GsmRxLev overpower_sacch,
8239 GsmRxLev overpower_facch
8240};
8241
8242private function f_rxlev_match(template (present) RslLinkId link_id,
8243 template (present) GsmRxLev rxlev)
8244runs on ConnHdlr {
8245 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8246 if (not match(dl.dl_info.rx_level, rxlev)) {
8247 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8248 " does not match expected RxLev := ", rxlev);
8249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8250 }
8251}
8252
8253private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8254 var TopTestCase tc := g_pars.spec.top;
8255 var GsmRxLev rxlev_dcch;
8256 var L1ctlDlMessage dl;
8257
8258 /* Wait for Pau ramping to complete */
8259 f_sleep(6.0);
8260
8261 f_l1_tune(L1CTL);
8262 L1CTL.clear;
8263 RSL.clear;
8264
8265 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8266 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8267 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8268
8269 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8270 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8271
8272 /* Additional IEs for the CHANnel ACTIVation message */
8273 var template (value) RSL_IE_List ies := {
8274 /* Employ BS power control in static mode */
8275 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8276 bs_power := tc.bs_power
8277 }),
8278 /* Indicate the given Temporary Overpower capability */
8279 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8280 top_acch_cap := tc.top_cap
8281 })
8282 };
8283
8284 /* Establish a dedicated channel */
8285 f_est_dchan(more_ies := valueof(ies));
8286
8287 /* Give it some time to stabilize */
8288 f_sleep(0.480 * 2.0);
8289 L1CTL.clear;
8290 RSL.clear;
8291
8292 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8293 var TopTestStep step := tc.steps[i];
8294 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8295 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8296
8297 log("Executing step[", i, "] := ", step);
8298
8299 /* Send RR Measurement Report (if present) */
8300 if (ispresent(step.meas_res)) {
8301 f_transceive_meas_rep(step.meas_res);
8302 f_sleep(0.480 * 2.0);
8303 L1CTL.clear;
8304 }
8305
8306 /* Check RxLev on both FACCH and SACCH */
8307 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8308 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8309
8310 setverdict(pass);
8311 }
8312}
8313testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8314 var ConnHdlrPars pars;
8315 var ConnHdlr vc_conn;
8316
8317 f_init();
8318
8319 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008320 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008321 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8322 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8323 steps := {
8324 /* Channel established, no overpower */
8325 { meas_res := omit,
8326 overpower_sacch := 0, overpower_facch := 0 },
8327
8328 /* Worst possible RxQual value, overpower of 4dB */
8329 { meas_res := ts_MeasurementResults(rxq_f := 7),
8330 overpower_sacch := 4, overpower_facch := 4 },
8331 /* Worst possible RxQual value, disabling overpower */
8332 { meas_res := ts_MeasurementResults(rxq_f := 0),
8333 overpower_sacch := 0, overpower_facch := 0 },
8334
8335 /* Lower threshold not reached, no overpower */
8336 { meas_res := ts_MeasurementResults(rxq_f := 1),
8337 overpower_sacch := 0, overpower_facch := 0 },
8338 /* Lower threshold not reached, no overpower */
8339 { meas_res := ts_MeasurementResults(rxq_f := 2),
8340 overpower_sacch := 0, overpower_facch := 0 },
8341 /* Lower threshold reached, overpower of 4dB */
8342 { meas_res := ts_MeasurementResults(rxq_f := 4),
8343 overpower_sacch := 4, overpower_facch := 4 },
8344 /* Upper threshold not reached, keeping overpower */
8345 { meas_res := ts_MeasurementResults(rxq_f := 3),
8346 overpower_sacch := 4, overpower_facch := 4 },
8347 /* Upper threshold reached, disabling overpower */
8348 { meas_res := ts_MeasurementResults(rxq_f := 2),
8349 overpower_sacch := 0, overpower_facch := 0 }
8350 }
8351 };
8352
8353 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8354 spec := { top := top }, trx_nr := 1));
8355 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8356 vc_conn.done;
8357
8358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8359}
8360testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8361 var ConnHdlrPars pars;
8362 var ConnHdlr vc_conn;
8363
8364 f_init();
8365
8366 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008367 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008368 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8369 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8370 steps := {
8371 /* Channel established, no overpower */
8372 { meas_res := omit,
8373 overpower_sacch := 0, overpower_facch := 0 },
8374
8375 /* Invalid measurement results, no overpower */
8376 { meas_res := ts_MeasurementResults(rxq_f := 7,
8377 rxq_s := 7,
8378 valid := false),
8379 overpower_sacch := 0, overpower_facch := 0 },
8380
8381 /* DTXu was in use, no overpower */
8382 { meas_res := ts_MeasurementResults(rxq_f := 7,
8383 rxq_s := 0,
8384 dtx_used := true),
8385 overpower_sacch := 0, overpower_facch := 0 },
8386 /* DTXu was in use, overpower of 4 dB */
8387 { meas_res := ts_MeasurementResults(rxq_f := 0,
8388 rxq_s := 7,
8389 dtx_used := true),
8390 overpower_sacch := 4, overpower_facch := 4 }
8391 }
8392 };
8393
8394 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8395 spec := { top := top }, trx_nr := 1));
8396 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8397 vc_conn.done;
8398
8399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8400}
8401testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8402 var ConnHdlrPars pars;
8403 var ConnHdlr vc_conn;
8404
8405 f_init();
8406
8407 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008408 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008409 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8410 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8411 rxqual := 0, /* always on */
8412 sacch_enable := false),
8413 steps := {
8414 /* Channel established, FACCH overpower */
8415 { meas_res := omit,
8416 overpower_sacch := 0, overpower_facch := 4 },
8417 /* MS indicates good RxQual, no difference */
8418 { meas_res := ts_MeasurementResults(rxq_f := 0),
8419 overpower_sacch := 0, overpower_facch := 4 },
8420 /* MS indicates bad RxQual, no difference */
8421 { meas_res := ts_MeasurementResults(rxq_f := 7),
8422 overpower_sacch := 0, overpower_facch := 4 }
8423 }
8424 };
8425
8426 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8427 spec := { top := top }, trx_nr := 1));
8428 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8429 vc_conn.done;
8430
8431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8432}
8433testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8434 var ConnHdlrPars pars;
8435 var ConnHdlr vc_conn;
8436
8437 f_init();
8438
8439 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008440 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008441 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8442 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8443 rxqual := 0, /* always on */
8444 facch_enable := false),
8445 steps := {
8446 /* Channel established, SACCH overpower */
8447 { meas_res := omit,
8448 overpower_sacch := 4, overpower_facch := 0 },
8449 /* MS indicates good RxQual, no difference */
8450 { meas_res := ts_MeasurementResults(rxq_f := 0),
8451 overpower_sacch := 4, overpower_facch := 0 },
8452 /* MS indicates bad RxQual, no difference */
8453 { meas_res := ts_MeasurementResults(rxq_f := 7),
8454 overpower_sacch := 4, overpower_facch := 0 }
8455 }
8456 };
8457
8458 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8459 spec := { top := top }, trx_nr := 1));
8460 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8461 vc_conn.done;
8462
8463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8464}
8465testcase TC_acch_overpower_limit() runs on test_CT {
8466 var ConnHdlrPars pars;
8467 var ConnHdlr vc_conn;
8468
8469 f_init();
8470
8471 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008472 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008473 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8474 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8475 rxqual := 0 /* always on */),
8476 steps := {
8477 /* Channel established, ACCH overpower of 2dB */
8478 { meas_res := omit,
8479 overpower_sacch := 2, overpower_facch := 2 },
8480 /* MS indicates good RxQual, no difference */
8481 { meas_res := ts_MeasurementResults(rxq_f := 0),
8482 overpower_sacch := 2, overpower_facch := 2 },
8483 /* MS indicates bad RxQual, no difference */
8484 { meas_res := ts_MeasurementResults(rxq_f := 7),
8485 overpower_sacch := 2, overpower_facch := 2 }
8486 }
8487 };
8488
8489 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8490 spec := { top := top }, trx_nr := 1));
8491 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8492 vc_conn.done;
8493
8494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8495}
8496
Harald Welte0472ab42018-03-12 15:02:26 +01008497/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8498/* protocol error as per 44.006 */
8499/* link layer failure (repetition of I-frame N200 times without ACK */
8500/* repetition of SABM or DISC N200 times without ACK */
8501/* receptiom of SABM in multi-frame established state */
8502
8503
Harald Welte68e495b2018-02-25 00:05:57 +01008504/* TODO Areas:
8505
8506* channel activation
8507** with BS_Power / MS_Power, bypassing power control loop
8508** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008509** with timing advance from initial activation on
8510* mode modify
8511** encryption
8512** multirate
8513* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008514** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008515* BS Power Control
8516* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008517* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008518** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008519* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008520** DATA_IND from BTS->PCU
8521** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008522
8523*/
Harald Welte70767382018-02-21 12:16:40 +01008524
8525control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008526 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008527 execute( TC_chan_act_stress() );
8528 execute( TC_chan_act_react() );
8529 execute( TC_chan_deact_not_active() );
8530 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008531 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008532 execute( TC_sacch_filling() );
8533 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008534 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008535 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008536 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008537 execute( TC_sacch_chan_act_ho_async() );
8538 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008539 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008540 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008541 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008542 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008543 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008544 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008545 execute( TC_rach_load_idle_thresh0() );
8546 execute( TC_rach_load_idle_below_thresh() );
8547 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008548 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008549 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008550 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008551 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008552 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008553 execute( TC_meas_res_sign_tchf() );
8554 execute( TC_meas_res_sign_tchh() );
8555 execute( TC_meas_res_sign_sdcch4() );
8556 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008557 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008558 execute( TC_meas_res_speech_tchf_sapi3() );
8559 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008560 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008561 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008562 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008563 execute( TC_rsl_bs_pwr_static_ass() );
8564 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008565 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008566 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008567 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008568 execute( TC_rsl_ms_pwr_dyn_up() );
8569 execute( TC_rsl_ms_pwr_dyn_down() );
8570 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8571 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008572 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008573 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008574 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008575 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008576 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008577 execute( TC_paging_imsi_80percent() );
8578 execute( TC_paging_tmsi_80percent() );
8579 execute( TC_paging_imsi_200percent() );
8580 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008581 execute( TC_rsl_protocol_error() );
8582 execute( TC_rsl_mand_ie_error() );
8583 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008584 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008585 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008586 execute( TC_si_sched_2bis() );
8587 execute( TC_si_sched_2ter() );
8588 execute( TC_si_sched_2ter_2bis() );
8589 execute( TC_si_sched_2quater() );
8590 execute( TC_si_sched_13() );
8591 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008592 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008593 execute( TC_ipa_crcx_twice_not_active() );
8594 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008595 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008596 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008597 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008598
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008599 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008600 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008601 execute( TC_pcu_act_req() );
8602 execute( TC_pcu_act_req_wrong_ts() );
8603 execute( TC_pcu_act_req_wrong_bts() );
8604 execute( TC_pcu_act_req_wrong_trx() );
8605 execute( TC_pcu_deact_req() );
8606 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008607 execute( TC_pcu_ver_si1() );
8608 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008609 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008610 if (mp_l1_supports_gprs) {
8611 execute( TC_pcu_data_req_pdtch() );
8612 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008613 execute( TC_pcu_data_req_wrong_bts() );
8614 execute( TC_pcu_data_req_wrong_trx() );
8615 execute( TC_pcu_data_req_wrong_ts() );
8616 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008617 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008618 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008619 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008620 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008621 execute( TC_pcu_data_req_imm_ass_pch() );
8622 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008623 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008624 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008625 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008626 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008627 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008628 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008629 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008630 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008631 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008632 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008633 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008634 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008635 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008636 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008637 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008638 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008639 execute( TC_dyn_osmo_pdch_act_deact() );
8640 execute( TC_dyn_osmo_pdch_double_act() );
8641 execute( TC_dyn_ipa_pdch_act_deact() );
8642 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008643 execute( TC_pcu_info_ind_fh_params() );
8644 execute( TC_pcu_socket_nsvc_ipv4() );
8645 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008646 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008647 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008648 } else {
8649 log("PCU socket path not available, skipping PCU tests");
8650 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008651
Harald Welte3d04ae62018-04-04 20:29:05 +02008652 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008653 execute( TC_dyn_osmo_pdch_tchf_act() );
8654 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008655 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008656 execute( TC_dyn_ipa_pdch_tchf_act() );
8657 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008658
8659 execute( TC_rll_est_ind() );
8660 execute( TC_rll_est_req_DCCH_3() );
8661 execute( TC_rll_est_req_ACCH_3() );
8662 execute( TC_rll_rel_ind_DCCH_0() );
8663 execute( TC_rll_rel_ind_DCCH_3() );
8664 execute( TC_rll_rel_ind_ACCH_0() );
8665 execute( TC_rll_rel_ind_ACCH_3() );
8666 execute( TC_rll_rel_req() );
8667 execute( TC_rll_unit_data_req_DCCH() );
8668 execute( TC_rll_unit_data_req_ACCH() );
8669 execute( TC_rll_unit_data_ind_DCCH() );
8670 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008671
8672 execute( TC_chan_act_a51() );
8673 execute( TC_chan_act_a52() );
8674 execute( TC_chan_act_a53() );
8675 execute( TC_encr_cmd_a51() );
8676 execute( TC_encr_cmd_a52() );
8677 execute( TC_encr_cmd_a53() );
8678
Harald Welteee25aae2019-05-19 14:32:37 +02008679 execute( TC_err_rep_wrong_mdisc() );
8680 execute( TC_err_rep_wrong_msg_type() );
8681 execute( TC_err_rep_wrong_sequence() );
8682
Harald Weltee613f962018-04-18 22:38:16 +02008683 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008684
8685 execute( TC_tch_sign_l2_fill_frame() );
8686 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008687
8688 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008689 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008690
8691 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008692 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008693
8694 execute( TC_speech_no_rtp_tchf() );
8695 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008696 execute( TC_speech_rtp_tchf() );
8697 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008698
8699 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008700
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008701 execute( TC_acch_overpower_rxqual_thresh() );
8702 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8703 execute( TC_acch_overpower_always_on_facch() );
8704 execute( TC_acch_overpower_always_on_sacch() );
8705 execute( TC_acch_overpower_limit() );
8706
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008707 /* BEWARE: these test cases can potentially break the IUT or cause
8708 * weird/unexpected behavior. Ensure that they are executed last. */
8709 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8710 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008711}
8712
8713
8714}