blob: 646e5bf9867c8d8fb323e63001a69d85d2f6bd5c [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,
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +0200310 RSL_IE_MultirateCfg mr_conf optional,
Harald Welte70767382018-02-21 12:16:40 +0100311 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100312 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200313 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200314 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700315 BtsBand bts0_band optional,
316
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700317 /* Training Sequence Code */
318 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700319 /* Frequency hopping parameters */
320 FreqHopPars fhp
321};
Harald Welte0472ab42018-03-12 15:02:26 +0100322
323/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200324friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300325 RllTestCase rll,
326 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100327}
328
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700329private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100330 max_retrans := RACH_MAX_RETRANS_7,
331 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100332 cell_barr_access := false,
333 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100334 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100335};
336
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700337private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100338 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200339 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100340 acs := '0'B,
341 neci := true,
342 rxlev_access_min := 0
343}
344
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700345private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100346 mcc_mnc := '262F42'H,
347 lac := 42
348}
349
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700350private template (value) GPRSIndicator ts_GPRSIndicator_def := {
351 ra_colour := 0,
352 si13_pos := '0'B
353}
354
355private template (value) SI3RestOctets ts_SI3RestOctets_def
356modifies ts_SI3RestOctets := {
357 gprs_ind := {
358 presence := CSN1_H,
359 ind := ts_GPRSIndicator_def
360 }
361}
362
363private template (value) SI4RestOctets ts_SI4RestOctets_def
364modifies ts_SI4RestOctets := {
365 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700366 presence := CSN1_H,
367 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700368 }
369}
370
Harald Welte7484fc42018-02-24 14:09:45 +0100371/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700372private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100373 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100374 payload := {
375 si3 := {
376 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100377 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100378 ctrl_chan_desc := {
379 msc_r99 := true,
380 att := true,
381 bs_ag_blks_res := 1,
382 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100383 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100384 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
385 spare := '00'B,
386 bs_pa_mfrms := 0, /* 2 multiframes */
387 t3212 := 1 /* 6 minutes */
388 },
Harald Welte82ccef72018-02-25 16:17:33 +0100389 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100390 dn_ind := false,
391 pwrc := false,
392 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100393 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100394 },
Harald Weltef10153f2018-02-25 16:34:05 +0100395 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100396 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200397 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100398 }
399 }
400}
Harald Welte70767382018-02-21 12:16:40 +0100401
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700402private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100403 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100404 payload := {
405 si2 := {
406 bcch_freq_list := '00000000000000000000000000000000'O,
407 ncc_permitted := '11111111'B,
408 rach_control := ts_RachCtrl_default
409 }
410 }
411}
412
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700413private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100414 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100415 payload := {
416 si4 := {
417 lai := ts_LAI_default,
418 cell_sel_par := ts_CellSelPar_default,
419 rach_control := ts_RachCtrl_default,
420 cbch_chan_desc := omit,
421 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200422 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100423 }
424 }
425}
426
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700427private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100428runs on test_CT {
429 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700430 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100431}
432
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700433private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100434runs on test_CT {
435 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
436 log("Setting ", rsl_si_type, ": ", si_dec);
437 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
438}
439
Harald Welte505cf9b2018-09-15 17:47:23 +0300440friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100441 map(self:BTSVTY, system:BTSVTY);
442 f_vty_set_prompts(BTSVTY);
443 f_vty_transceive(BTSVTY, "enable");
444}
445
Harald Welte505cf9b2018-09-15 17:47:23 +0300446friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200447 map(self:BSCVTY, system:BSCVTY);
448 f_vty_set_prompts(BSCVTY, "OsmoBSC");
449 f_vty_transceive(BSCVTY, "enable");
450}
451
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200452friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
453 map(self:BSCVTY, system:BSCVTY);
454 f_vty_set_prompts(BSCVTY, "OsmoBSC");
455 f_vty_transceive(BSCVTY, "enable");
456}
457
Harald Welte883340c2018-02-28 18:59:29 +0100458/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200459friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100461 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200462 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
463 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100464 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200465 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100467 }
468}
469
Harald Weltef26de0b2018-04-04 20:28:05 +0200470private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
471 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100472 timer T := 2.0;
473 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100474 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200475 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100476 return;
477 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200478 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100479
480 T.start;
481 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200482 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100483 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100485 }
486 }
487}
488
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700489private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
490 out integer trxc_conn_id) {
491 var Result res;
492
493 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
494 "", -1, -1, { udp := {} }, {});
495 if (not ispresent(res.connId)) {
496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
497 "Could not connect to the control (TRXC) interface " &
498 "of FakeTRX, check your configuration");
499 }
500 trxc_conn_id := res.connId;
501}
502
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100503/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700504friend function f_init(uint8_t trx_nr := 0)
505runs on test_CT
506{
507 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200508 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100509
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700510 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
511 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700512 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200513 g_AllChanTypes := {
514 /* TS 1..4: TCH/F */
515 valueof(ts_RslChanNr_Bm(1)),
516 /* TS 5: TCH/H */
517 valueof(ts_RslChanNr_Lm(5,1)),
518 /* TS 0: SDCCH/4 */
519 valueof(ts_RslChanNr_SDCCH4(0,2)),
520 /* TS 6: SDCCH/8 */
521 valueof(ts_RslChanNr_SDCCH8(6,4))
522 };
523 } else {
524 g_AllChanTypes := {
525 /* TS 1..4: TCH/F */
526 valueof(ts_RslChanNr_Bm(1)),
527 /* TS 0: SDCCH/4 */
528 valueof(ts_RslChanNr_SDCCH4(0,2)),
529 /* TS 6: SDCCH/8 */
530 valueof(ts_RslChanNr_SDCCH8(6,4))
531 };
532 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700533
534 g_AllChannels := { };
535
536 /* Generate list of all logical channels from module parameters */
537 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
538 select (trx_pars.ts[tn].config) {
539 case (GSM_PCHAN_CCCH_SDCCH4) {
540 g_AllChannels := g_AllChannels &
541 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
542 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
543 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
544 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
545 }
546 case (GSM_PCHAN_SDCCH8) {
547 g_AllChannels := g_AllChannels &
548 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
551 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
552 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
553 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
554 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
555 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
556 }
557 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
558 g_AllChannels := g_AllChannels &
559 { valueof(ts_RslChanNr_Lm(tn, 0)),
560 valueof(ts_RslChanNr_Lm(tn, 1)),
561 valueof(ts_RslChanNr_Bm(tn)) };
562 }
563 case (GSM_PCHAN_TCHH) {
564 g_AllChannels := g_AllChannels &
565 { valueof(ts_RslChanNr_Lm(tn, 0)),
566 valueof(ts_RslChanNr_Lm(tn, 1)) };
567 }
568 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
569 g_AllChannels := g_AllChannels &
570 { valueof(ts_RslChanNr_Bm(tn)) };
571 }
572 }
573 }
574
Harald Welte70767382018-02-21 12:16:40 +0100575 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100576 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100577 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100578 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100579
580 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100581 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
582 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
583 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
584 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100585
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700586 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100587 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700588
589 /* Init TRXC interface to FakeTRX */
590 map(self:BTS_TRXC, system:BTS_TRXC);
591 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
592
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700593 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600594 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
595 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700596 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600597 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100598 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200599
600 /* Wait some extra time to make sure the BTS emits a stable carrier.
601 * (this is only relevant when running the tests with a physical BTS.) */
602 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100603}
604
Harald Welte68e495b2018-02-25 00:05:57 +0100605/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700606friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100607 map(self:L1CTL, system:L1CTL);
608 f_connect_reset(L1CTL);
609}
610
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200611friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100612
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700613private type record length(8) of FreqHopGroups FreqHopConfig;
614
615private type record of FreqHopGroup FreqHopGroups;
616private type record FreqHopGroup {
617 uint6_t hsn,
618 FreqHopGroupItems trx_maio
619};
620
621private type record of FreqHopGroupItem FreqHopGroupItems;
622private type record FreqHopGroupItem {
623 uint8_t trx_nr,
624 uint6_t maio
625};
626
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700627friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
628 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700629{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700630 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700631 var integer i, j;
632
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700633 fhp.enabled := false;
634
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700635 for (i := 0; i < lengthof(groups); i := i + 1) {
636 var FreqHopGroup g := groups[i];
637 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
638 var FreqHopGroupItem gi := g.trx_maio[j];
639 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700640 fhp.maio_hsn.maio := gi.maio;
641 fhp.maio_hsn.hsn := g.hsn;
642 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700643 break;
644 }
645 }
646
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700647 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700648 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700649 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
650 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
651 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700652
653 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700654 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
655 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700656 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700657 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700658 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700659 }
660
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700661 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700662 break; /* We're done */
663 }
664 }
665}
666
Harald Welte70767382018-02-21 12:16:40 +0100667/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700668friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
669 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200670 boolean trxc_comp := false,
671 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100672runs on test_CT return ConnHdlr {
673 var charstring id := testcasename();
674 var ConnHdlr vc_conn;
675
676 vc_conn := ConnHdlr.create(id);
677 /* connect to RSL Emulation main component */
678 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
679 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700680
681 /* The ConnHdlr component may want to talk to some ports directly,
682 * so we disconnect it from the test_CT and connect it to the component.
683 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200684 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200685 unmap(self:PCU, system:PCU);
686 map(vc_conn:PCU, system:PCU);
687 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700688 if (trxc_comp) {
689 unmap(self:BTS_TRXC, system:BTS_TRXC);
690 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
691 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200692 if (l1ctl) {
693 map(vc_conn:L1CTL, system:L1CTL);
694 }
Harald Welte70767382018-02-21 12:16:40 +0100695
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700696 /* Obtain frequency hopping parameters for a given timeslot */
697 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700698 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700699 }
700
Harald Welte70767382018-02-21 12:16:40 +0100701 vc_conn.start(f_handler_init(fn, id, pars));
702 return vc_conn;
703}
704
Harald Welte70767382018-02-21 12:16:40 +0100705private altstep as_Tguard() runs on ConnHdlr {
706 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100708 }
709}
710
Harald Welte990a3612019-05-27 14:02:13 +0200711friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700712 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700713 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100714}
715
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700716private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100717 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600718 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100719}
720
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700721private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100722 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600723 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100724}
725
726/* first function started in ConnHdlr component */
727private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
728runs on ConnHdlr {
729 g_pars := pars;
730 g_chan_nr := pars.chan_nr;
731
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200732 if (L1CTL.checkstate("Mapped")) {
733 f_connect_reset(L1CTL);
734 }
Harald Welte70767382018-02-21 12:16:40 +0100735
Harald Welted48c0c72019-06-05 10:01:15 +0200736 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700737 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100738 }
Harald Welte70767382018-02-21 12:16:40 +0100739
740 g_Tguard.start(pars.t_guard);
741 activate(as_Tguard());
742
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700743 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100744
745 /* call the user-supplied test case function */
746 fn.apply(id);
747}
748
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700749private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
750 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200751runs on ConnHdlr return RSL_Message {
752 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100753 timer T := 3.0;
754 RSL.send(tx);
755 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100756 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200757 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100758 T.stop;
759 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100760 }
Harald Welte1eba3742018-02-25 12:48:14 +0100761 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200762 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100763 }
Harald Welte21240e62018-03-11 21:43:35 +0100764 [not ignore_other] as_l1_sacch();
765 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700766 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700767 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100768 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100770 }
Harald Welte21240e62018-03-11 21:43:35 +0100771 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100772 }
Harald Welteb1726c92018-03-30 11:56:38 +0200773 return rx;
774}
775
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700776friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
777 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200778runs on ConnHdlr {
779 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100780}
781
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700782/* Send the given measurement results to the IUT over the Um interface */
783friend function f_send_meas_rep(template (value) MeasurementResults meas_res)
784runs on ConnHdlr {
785 var template (value) SacchL1Header l1h;
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +0700786
787 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
788 f_send_meas_rep_l1h(meas_res, l1h);
789}
790
791/* Send the given measurement results and L1H to the IUT over the Um interface */
792friend function f_send_meas_rep_l1h(template (value) MeasurementResults meas_res,
793 template (value) SacchL1Header l1h)
794runs on ConnHdlr {
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700795 var octetstring l2;
796
797 /* RR Measurement Report to be sent */
798 var GsmRrL3Message meas_rep := {
799 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
800 payload := { meas_rep := { meas_res := valueof(meas_res) } }
801 };
802
803 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
804 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +0700805
806 log(%definitionId, "(): Tx SACCH L1 header: ", l1h);
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700807
808 /* Send RR Measurement Report over the Um interface */
809 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
810}
811
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300812/* Send the given measurement results to the IUT over the Um interface,
813 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
814friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
815runs on ConnHdlr {
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700816 var octetstring l3;
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300817 timer T;
818
819 /* RR Measurement Report to be sent */
820 var GsmRrL3Message meas_rep := {
821 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
822 payload := { meas_rep := { meas_res := valueof(meas_res) } }
823 };
824
825 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
826 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300827
Vadim Yanitskiy9dd880f2022-08-01 19:22:18 +0700828 f_send_meas_rep(meas_res);
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300829
830 /* Expect MEASurement RESult on the A-bis/RSL interface */
831 T.start(2.0);
832 alt {
833 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
834 setverdict(pass);
835 }
836 [] RSL.receive { repeat; }
837 [] T.timeout {
838 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
840 }
841 }
842}
843
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700844friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
845 boolean encr_enable := false,
846 RSL_IE_List more_ies := {},
847 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
848runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200849 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200850 if (encr_enable) {
851 /* append encryption related IEs, if requested */
852 var RSL_IE_EncryptionInfo encr_info;
853 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
854 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
855encr_info})) };
856 }
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +0200857 if (mode.coding_alg_rate == RSL_CMOD_SP_GSM3) {
858 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_MR_CONFIG,
859 RSL_IE_Body:{multirate_cfg := g_pars.mr_conf})) };
860 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200861 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200862 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100863}
864
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700865friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100866 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 +0100867 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100868}
869
Harald Welte2f2b2b72019-05-31 22:24:57 +0200870friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200871 template RSL_IE_ChannelMode chan_mode,
872 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700873 uint8_t trx_nr := 0, float t_guard := 20.0) := {
874 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100875 chan_nr := valueof(chan_nr),
876 chan_mode := valueof(chan_mode),
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +0200877 mr_conf := omit,
Harald Welte70767382018-02-21 12:16:40 +0100878 t_guard := t_guard,
879 l1_pars := {
880 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100881 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100882 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100883 meas_ul := {
884 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200885 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100886 rxqual := 0
887 },
888 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200889 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100890 rxqual := 0
891 }
892 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200893 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100894 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200895 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200896 ms_actual_ta := mp_ms_actual_ta_exp,
897 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100898 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200899 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200900 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700901 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700902 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700903 fhp := {
904 enabled := false,
905 maio_hsn := ts_HsnMaio(0, 0),
906 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700907 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700908 }
Harald Welte70767382018-02-21 12:16:40 +0100909}
910
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300911/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
912 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
913private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
914 template (present) octetstring tr_data := ?,
915 template (present) RslChannelNr chan_nr := ?,
916 template (present) RslLinkId link_id := ?)
917runs on ConnHdlr {
918 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
919}
920
921/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
922 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
923private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
924 template (present) RslLinkId link_id := ?,
925 template (present) LapdmSapi sapi := ?,
926 boolean do_repeat := true)
927runs on ConnHdlr {
928 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
929 var L1ctlDlMessage dl_msg;
930
931 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
932 if (do_repeat) {
933 repeat;
934 }
935 }
936}
937
938/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
939 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
940private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
941 template (present) LapdmFrameAB tr_frame := ?,
942 template (present) RslLinkId link_id := ?)
943runs on ConnHdlr {
944 var L1ctlDlMessage dl_msg;
945
946 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
947 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
948 }
949}
950
Vadim Yanitskiya144e3c2022-03-14 23:56:40 +0300951/* This altstep triggers on receipt of a Downlink SACCH containing a L2 payload
952 * that matches the given LAPDm frame, as well as the given SACCH L1 header. */
953private altstep as_dl_sacch_lapdm_ab(out SacchL1Header l1h, out LapdmFrameAB frame,
954 template (present) LapdmFrameAB tr_frame := ?,
955 template (present) SacchL1Header tr_l1h := ?,
956 template (present) GsmSapi sapi := ?)
957runs on ConnHdlr {
958 var L1ctlDlMessage dl_msg;
959 template (present) RslLinkId link_id := tr_RslLinkID_SACCH(sapi);
960 template (present) L1ctlDataReq tr_data := {
961 l1header := tr_l1h,
962 l2_payload := decmatch tr_frame
963 };
964
965 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_data, g_chan_nr, link_id) {
966 var octetstring data := dl_msg.payload.data_ind.payload;
967 l1h := dec_SacchL1Header(substr(data, 0, 2));
968 frame := dec_LapdmFrameAB(substr(data, 2, lengthof(data) - 2));
969 }
970}
971
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300972/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
973 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
974 * payload is treated as PDU_ML3_NW_MS. */
975private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
976 template (present) PDU_ML3_NW_MS tr_pdu := ?,
977 template (present) GsmSapi sapi := 0)
978runs on ConnHdlr {
979 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
980 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
981 var LapdmFrameAB lapdm_frame;
982
983 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
984 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
985 }
986}
987
Harald Welte93640c62018-02-25 16:59:33 +0100988/***********************************************************************
989 * Channel Activation / Deactivation
990 ***********************************************************************/
991
Harald Welte70767382018-02-21 12:16:40 +0100992/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700993private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100994 for (var integer i := 0; i < 500; i := i+1) {
995 f_rsl_chan_act(g_pars.chan_mode);
996 f_rsl_chan_deact();
997 }
998 setverdict(pass);
999}
1000testcase TC_chan_act_stress() runs on test_CT {
1001 var ConnHdlr vc_conn;
1002 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02001003 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001004 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
1005 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001007}
1008
1009/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001010private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001011 f_rsl_chan_act(g_pars.chan_mode);
1012 /* attempt to activate the same lchan again -> expect reject */
1013 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1014 alt {
1015 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +01001017 }
1018 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1019 setverdict(pass);
1020 }
1021 }
1022 f_rsl_chan_deact();
1023}
1024testcase TC_chan_act_react() runs on test_CT {
1025 var ConnHdlr vc_conn;
1026 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001027 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001028 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
1029 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001031}
1032
1033/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001034private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001035 timer T := 3.0;
1036 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
1037 T.start;
1038 alt {
1039 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
1040 setverdict(pass);
1041 }
1042 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +01001044 }
1045 }
1046}
1047testcase TC_chan_deact_not_active() runs on test_CT {
1048 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +01001049 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001050 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
1051 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001053}
1054
1055/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001056private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001057 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1058 alt {
1059 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001061 }
1062 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1063 setverdict(pass);
1064 }
1065 }
1066}
1067private type record WrongChanNrCase {
1068 RslChannelNr chan_nr,
1069 charstring description
1070}
1071private type record of WrongChanNrCase WrongChanNrCases;
1072private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1073 chan_nr := chan_nr,
1074 description := desc
1075}
1076
1077testcase TC_chan_act_wrong_nr() runs on test_CT {
1078 var ConnHdlr vc_conn;
1079 var ConnHdlrPars pars;
1080
Harald Welte294b0a22018-03-10 23:26:48 +01001081 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001082
1083 var WrongChanNrCases wrong := {
1084 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1085 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1086 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1087 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1088 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1089 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1090 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1091 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1092 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1093 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1094 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1095 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1096 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1097 };
1098
1099 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1100 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1101 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1102 vc_conn.done;
1103 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001105}
1106
Harald Weltee613f962018-04-18 22:38:16 +02001107/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001108friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001109 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001110 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001111
1112 /* test on each of the channels we have */
1113 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1114 pars.chan_nr := valueof(g_AllChanTypes[i]);
1115
1116 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1117 vc_conn := f_start_handler(fn, pars);
1118 vc_conn.done;
1119 }
1120
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001122}
1123
Harald Welte93640c62018-02-25 16:59:33 +01001124/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001125 * SACCH handling
1126 ***********************************************************************/
1127
1128private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1129 timer T_sacch := 3.0;
1130 T_sacch.start;
1131 alt {
1132 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001134 }
1135 [not exp] T_sacch.timeout {
1136 setverdict(pass);
1137 }
1138 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1139 setverdict(pass);
1140 }
1141 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001143 }
1144 [] L1CTL.receive { repeat; }
1145 [] RSL.receive { repeat; }
1146 }
1147}
1148
1149/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1150private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1151 f_l1_tune(L1CTL);
1152 RSL.clear;
1153
1154 /* activate the logical channel */
1155 f_est_dchan();
1156 L1CTL.clear;
1157
1158 /* check that SACCH actually are received as expected */
1159 f_exp_sacch(true);
1160
1161 /* deactivate SACCH on the logical channel */
1162 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1163 f_sleep(1.0);
1164 L1CTL.clear;
1165
1166 /* check that no SACCH are received anymore */
1167 f_exp_sacch(false);
1168
1169 /* release the channel */
1170 f_rsl_chan_deact();
1171 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1172}
1173testcase TC_deact_sacch() runs on test_CT {
1174 var ConnHdlr vc_conn;
1175 var ConnHdlrPars pars;
1176 f_init();
1177 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1178 //for (var integer i := 0; i < 1; i := i+1) {
1179 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1180 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1181 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1182 vc_conn.done;
1183 }
1184 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001186}
1187
Harald Welte55700662018-03-12 13:15:43 +01001188/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001189private function f_sacch_present(template octetstring l3_exp,
1190 boolean do_fail := true)
1191runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001192 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001193 timer T_sacch := 3.0;
1194 L1CTL.clear;
1195 T_sacch.start;
1196 alt {
1197 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1198 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1199 if (match(l3, l3_exp)) {
1200 setverdict(pass);
1201 } else {
1202 repeat;
1203 }
1204 }
1205 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001206 [not do_fail] T_sacch.timeout {
1207 log("Timeout waiting for SACCH ", l3_exp);
1208 }
1209 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001210 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001212 }
1213 }
1214}
1215
Harald Welte55700662018-03-12 13:15:43 +01001216/* verify that given SACCH payload is not present */
1217private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1218 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001219 timer T_sacch := 3.0;
1220 L1CTL.clear;
1221 T_sacch.start;
1222 alt {
1223 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1224 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1225 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001226 setverdict(fail, "Received unexpected SACCH ", dl);
1227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001228 } else {
1229 repeat;
1230 }
1231 }
1232 [] L1CTL.receive { repeat; }
1233 [] T_sacch.timeout {
1234 setverdict(pass);
1235 }
1236 }
1237}
1238
Harald Welte629cc6b2018-03-11 17:19:05 +01001239/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001240private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1241 /* Set a known default SACCH filling for SI5 */
1242 var octetstring si5 := f_rnd_octstring(19);
1243 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1244
1245 f_l1_tune(L1CTL);
1246 RSL.clear;
1247
1248 /* activate the logical channel */
1249 f_est_dchan();
1250
1251 /* check that the specified SI5 value is actually sent */
1252 f_sacch_present(si5);
1253
1254 /* release the channel */
1255 RSL.clear;
1256 f_rsl_chan_deact();
1257 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1258}
1259testcase TC_sacch_filling() runs on test_CT {
1260 var ConnHdlr vc_conn;
1261 var ConnHdlrPars pars;
1262 f_init();
1263 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1264 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1265 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1266 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1267 vc_conn.done;
1268 }
1269 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001271}
1272
Harald Welte629cc6b2018-03-11 17:19:05 +01001273/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001274private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1275 /* Set a known default SACCH filling for SI5 */
1276 var octetstring si5 := f_rnd_octstring(19);
1277 var octetstring si5_diff := f_rnd_octstring(19);
1278 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1279
1280 f_l1_tune(L1CTL);
1281 RSL.clear;
1282
1283 log("Activating channel, expecting standard SI5");
1284 /* activate the logical channel */
1285 f_est_dchan();
1286 /* check that the specified SI5 value is actually sent */
1287 f_sacch_present(si5);
1288
1289 /* set channel-specific different SI5 */
1290 log("Setting channel specific SACCH INFO, expecting it");
1291 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1292 /* check that the specified lchan-specific value is now used */
1293 f_sacch_present(si5_diff);
1294
1295 /* deactivate the channel and re-activate it, this should result in default SI5 */
1296 log("De-activating and re-activating channel, expecting standard SI5");
1297 f_rsl_chan_deact();
1298 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1299 /* Verify that the TRX-wide default SACCH filling is present again */
1300 f_sacch_present(si5);
1301
1302 /* release the channel */
1303 RSL.clear;
1304 f_rsl_chan_deact();
1305 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1306}
1307testcase TC_sacch_info_mod() runs on test_CT {
1308 var ConnHdlr vc_conn;
1309 var ConnHdlrPars pars;
1310 f_init();
1311 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1312 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1313 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1314 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1315 vc_conn.done;
1316 }
1317 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001319}
1320
Harald Welte075d84c2018-03-12 13:07:24 +01001321/* Test SACCH scheduling of multiple different SI message types */
1322private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1323 var octetstring si5 := f_rnd_octstring(19);
1324 var octetstring si5bis := f_rnd_octstring(19);
1325 var octetstring si5ter := f_rnd_octstring(19);
1326 var octetstring si6 := f_rnd_octstring(19);
1327
1328 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1329 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1330 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1331 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1332
1333 f_l1_tune(L1CTL);
1334 RSL.clear;
1335
1336 /* activate the logical channel */
1337 f_est_dchan();
1338 L1CTL.clear;
1339
1340 /* check that SACCH actually are received as expected */
1341 f_sacch_present(si5);
1342 f_sacch_present(si5bis);
1343 f_sacch_present(si5ter);
1344 f_sacch_present(si6);
1345
1346 /* release the channel */
1347 f_rsl_chan_deact();
1348 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1349}
1350testcase TC_sacch_multi() runs on test_CT {
1351 var ConnHdlr vc_conn;
1352 var ConnHdlrPars pars;
1353 f_init();
1354 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1355 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1356 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1357 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1358 vc_conn.done;
1359 }
1360 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001362}
1363
Harald Welte55700662018-03-12 13:15:43 +01001364/* Test if SACH information is modified as expected */
1365private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1366 var octetstring si5 := f_rnd_octstring(19);
1367 var octetstring si6 := f_rnd_octstring(19);
1368
1369 /* First, configure both SI5 and SI6 to be transmitted */
1370 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1371 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1372
1373 f_l1_tune(L1CTL);
1374 RSL.clear;
1375
1376 /* activate the logical channel */
1377 f_est_dchan();
1378 L1CTL.clear;
1379
1380 /* check that SACCH actually are received as expected */
1381 f_sacch_present(si5);
1382 f_sacch_present(si6);
1383
1384 /* disable SI6 */
1385 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1386
1387 /* check that SI5 is still transmitted */
1388 f_sacch_present(si5);
1389 /* check if SI6 is now gone */
1390 f_sacch_missing(si6);
1391
1392 /* release the channel */
1393 f_rsl_chan_deact();
1394 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1395}
1396testcase TC_sacch_multi_chg() runs on test_CT {
1397 var ConnHdlr vc_conn;
1398 var ConnHdlrPars pars;
1399 f_init();
1400 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1401 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1402 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1403 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1404 vc_conn.done;
1405 }
1406 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001408}
1409
Harald Weltec8d363c2019-05-19 20:36:48 +02001410/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1411private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1412 var octetstring si5 := f_rnd_octstring(19);
1413 var octetstring si6 := f_rnd_octstring(19);
1414 var octetstring si5_specific := f_rnd_octstring(19);
1415 var octetstring si6_specific := f_rnd_octstring(19);
1416
1417 /* First, configure both SI5 and SI6 to be transmitted */
1418 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1419 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1420
1421 f_l1_tune(L1CTL);
1422 RSL.clear;
1423
1424 /* activate channel with different SACCH filling */
1425 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1426 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1427 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1428 }));
1429 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1430 RSL_IE_Body:{sacch_info := sacch_info})) };
1431 f_est_dchan(more_ies := addl_ies);
1432
1433 /* check that SACCH actually are received as expected */
1434 f_sacch_present(si5_specific);
1435 f_sacch_present(si6_specific);
1436
1437 /* release the channel */
1438 f_rsl_chan_deact();
1439 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1440}
1441testcase TC_sacch_chan_act() runs on test_CT {
1442 var ConnHdlr vc_conn;
1443 var ConnHdlrPars pars;
1444 f_init();
1445
1446 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1447 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1448 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1449 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1450 vc_conn.done;
1451 }
1452 /* TODO: do the above in parallel, rather than sequentially? */
1453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1454}
1455
Harald Welte8b01c792019-05-19 22:51:25 +02001456/* verify that SACCH DL transmission is started only if MS power IE present
1457 * see section 4.1.3 of 3GPP TS 48.058 */
1458private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1459 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001460 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001461
1462 f_l1_tune(L1CTL);
1463 RSL.clear;
1464
1465 /* Step 1: Activate ASYNC HO channel without MS power IE */
1466
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001467 var integer ho_ref := oct2int(f_rnd_octstring(1));
1468 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1469 RSL_IE_Body:{ handover_ref := ho_ref }));
1470 var RSL_IE_List addl_ies := {
1471 ho_ref_ie
1472 };
1473
Harald Welte8b01c792019-05-19 22:51:25 +02001474 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001475 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 +02001476 /* don't perform immediate assignment here, as we're testing non-IA case */
1477 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001478 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001479
1480 /* Verify that no DL SACCH is being received */
1481 f_sacch_missing(?);
1482
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001483 /* Send handover Access Burst and expect SACCH to start */
1484 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1485
1486 f_sacch_present(si5);
1487
Harald Welte8b01c792019-05-19 22:51:25 +02001488 f_rsl_chan_deact();
1489 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1490
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001491 /* Tune back to CCCH/BCCH */
1492 f_l1_tune(L1CTL);
1493
Harald Welte8b01c792019-05-19 22:51:25 +02001494
1495 /* Step 2: Activate ASYNC HO channel with MS power IE */
1496
1497 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001498 addl_ies := {
1499 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001500 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1501 };
1502 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1503 /* don't perform immediate assignment here, as we're testing non-IA case */
1504 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001505 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001506
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001507 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1508 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1509 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001510
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001511 /* Send handover Access Burst and expect SACCH to remain present */
1512 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1513
1514 f_sacch_present(si5);
1515
Harald Welte8b01c792019-05-19 22:51:25 +02001516 f_rsl_chan_deact();
1517 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1518}
1519testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1520 var ConnHdlr vc_conn;
1521 var ConnHdlrPars pars;
1522 f_init();
1523
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001524 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1525 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1526 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001527 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1528 vc_conn.done;
1529 }
1530 /* TODO: do the above in parallel, rather than sequentially? */
1531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1532}
1533
1534/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1535 * see section 4.1.4 of 3GPP TS 48.058 */
1536private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1537 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001538 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1539
Harald Welte8b01c792019-05-19 22:51:25 +02001540 var RSL_IE_List addl_ies;
1541
1542 f_l1_tune(L1CTL);
1543 RSL.clear;
1544
1545 /* Step 1: Activate SYNC HO channel without MS power IE */
1546
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001547 var integer ho_ref := oct2int(f_rnd_octstring(1));
1548 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1549 RSL_IE_Body:{ handover_ref := ho_ref }));
1550 addl_ies := {
1551 ho_ref_ie
1552 };
1553
Harald Welte8b01c792019-05-19 22:51:25 +02001554 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001555 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 +02001556 /* don't perform immediate assignment here, as we're testing non-IA case */
1557 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001558 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001559
1560 /* Verify that no DL SACCH is being received */
1561 f_sacch_missing(?);
1562
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001563 /* Send handover Access Burst and expect SACCH to start */
1564 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1565
1566 f_sacch_present(si5);
1567
Harald Welte8b01c792019-05-19 22:51:25 +02001568 f_rsl_chan_deact();
1569 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1570
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001571 /* Tune back to CCCH/BCCH */
1572 f_l1_tune(L1CTL);
1573
Harald Welte8b01c792019-05-19 22:51:25 +02001574
1575 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1576
1577 /* Activate channel on BTS side */
1578 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001579 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001580 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1581 };
1582 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1583 /* don't perform immediate assignment here, as we're testing non-IA case */
1584 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001585 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001586
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001587 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1588 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1589 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001590
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001591 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001592 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1593
1594 f_sacch_present(si5);
1595
Harald Welte8b01c792019-05-19 22:51:25 +02001596 f_rsl_chan_deact();
1597 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1598
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001599 /* Tune back to CCCH/BCCH */
1600 f_l1_tune(L1CTL);
1601
Harald Welte8b01c792019-05-19 22:51:25 +02001602
1603 /* Step 2b: Activate SYNC HO channel with TA IE */
1604
1605 /* Activate channel on BTS side */
1606 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001607 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001608 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1609 };
1610 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1611 /* don't perform immediate assignment here, as we're testing non-IA case */
1612 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001613 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001614
1615 /* Verify that no DL SACCH is being received */
1616 f_sacch_missing(?);
1617
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001618 /* Send handover Access Burst and expect SACCH to start */
1619 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1620
1621 f_sacch_present(si5);
1622
Harald Welte8b01c792019-05-19 22:51:25 +02001623 f_rsl_chan_deact();
1624 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1625
Vadim Yanitskiye3351bb2022-07-29 05:22:51 +07001626 /* Tune back to CCCH/BCCH */
1627 f_l1_tune(L1CTL);
1628
Harald Welte8b01c792019-05-19 22:51:25 +02001629
1630 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1631
1632 /* Activate channel on BTS side */
1633 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001634 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001635 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1636 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1637 };
1638 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1639 /* don't perform immediate assignment here, as we're testing non-IA case */
1640 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001641 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001642
1643 /* Verify that DL SACCH is being received */
1644 f_sacch_present(si5);
1645
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001646 /* Send handover Access Burst and expect SACCH to remain present */
1647 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1648
1649 f_sacch_present(si5);
1650
Harald Welte8b01c792019-05-19 22:51:25 +02001651 f_rsl_chan_deact();
1652 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1653}
1654testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1655 var ConnHdlr vc_conn;
1656 var ConnHdlrPars pars;
1657 f_init();
1658
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001659 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1660 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1661 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001662 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1663 vc_conn.done;
1664 }
1665 /* TODO: do the above in parallel, rather than sequentially? */
1666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1667}
Harald Welte629cc6b2018-03-11 17:19:05 +01001668
1669
1670/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001671 * RACH Handling
1672 ***********************************************************************/
1673
Harald Welte8c24c2b2018-02-26 08:31:31 +01001674/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001675private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001676 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001677 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001678 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001679
Harald Welte8c24c2b2018-02-26 08:31:31 +01001680 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001681 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001682 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001683 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001684 if (emerg == true) {
1685 ra := f_rnd_ra_emerg();
1686 } else {
1687 ra := f_rnd_ra_cs();
1688 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001689 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1690 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001692 }
1693 fn_last := fn;
1694
1695 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001696 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001697 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001698 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001699 T.stop;
1700 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001701 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001703 }
1704 [] RSL_CCHAN.receive { repeat; }
1705 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001706 test_failed := true;
1707 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001708 }
1709 }
1710 }
Maxba06feb2019-03-05 10:52:46 +01001711 if (test_failed) {
1712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001713 }
Maxba06feb2019-03-05 10:52:46 +01001714 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001716}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001717
Philipp Maier16ade782020-07-08 21:36:00 +02001718/* Normal variant */
1719testcase TC_rach_content() runs on test_CT {
1720 f_TC_rach_content(emerg := false);
1721}
1722
1723/* Emergency call variant */
1724testcase TC_rach_content_emerg() runs on test_CT {
1725 f_TC_rach_content(emerg := true);
1726}
1727
Harald Welte8c24c2b2018-02-26 08:31:31 +01001728/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1729testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001730 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001731 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001732 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001733 f_l1_tune(L1CTL);
1734
1735 var GsmFrameNumber fn_last := 0;
1736 for (var integer i := 0; i < 1000; i := i+1) {
1737 var OCT1 ra := f_rnd_ra_cs();
1738 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1739 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001741 }
1742 fn_last := fn;
1743 }
1744 var integer rsl_chrqd := 0;
1745 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001746 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001747 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001748 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001749 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001750 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001751 repeat;
1752 }
1753 [] RSL_CCHAN.receive { repeat; }
1754 [] T.timeout { }
1755 }
1756 if (rsl_chrqd == 1000) {
1757 setverdict(pass);
1758 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001760 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001762}
1763
Harald Welte3453ab42019-05-24 21:19:58 +02001764private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1765 var charstring bts_str := "bts " & int2str(bts_nr);
1766 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1767}
1768
1769/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1770private template integer tr_rach_slots_per_interval := (90 .. 130);
1771
1772/* Expect 0 RACH load on an idle BTS that has just started up */
1773testcase TC_rach_load_idle_thresh0() runs on test_CT {
1774 var ASP_RSL_Unitdata rx_ud;
1775
1776 f_init_vty_bsc();
1777 /* send load indications even at 0% load */
1778 f_vty_load_ind_thresh(0);
1779 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1780 f_sleep(2.0);
1781
1782 f_init();
1783
Harald Weltee37f9a52020-10-11 20:45:23 +02001784 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1785 alt {
1786 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1787 [] RSL_CCHAN.receive { repeat }
1788 }
1789
Harald Welte3453ab42019-05-24 21:19:58 +02001790 timer T := 5.0;
1791 T.start;
1792 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001793 [] 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 +02001794 setverdict(pass);
1795 repeat;
1796 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001797 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001798 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1799 repeat;
1800 }
1801 [] RSL_CCHAN.receive {
1802 repeat;
1803 }
1804 [] T.timeout { }
1805 }
1806
1807 f_vty_load_ind_thresh(10);
1808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1809}
1810
1811/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1812testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1813 var ASP_RSL_Unitdata rx_ud;
1814
1815 f_init_vty_bsc();
1816 f_init();
1817
1818 timer T := 5.0;
1819 T.start;
1820 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001821 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001822 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1823 repeat;
1824 }
1825 [] RSL_CCHAN.receive {
1826 repeat;
1827 }
1828 [] T.timeout {
1829 setverdict(pass);
1830 }
1831 }
1832
1833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1834}
1835
1836/* Expect 0 RACH load on an idle BTS that has just started up */
1837testcase TC_rach_load_count() runs on test_CT {
1838 var ASP_RSL_Unitdata rx_ud;
1839 var integer load_access_count := 0;
1840
1841 f_init_vty_bsc();
1842 /* send load indications even at 0% load */
1843 f_vty_load_ind_thresh(0);
1844 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1845 f_sleep(2.0);
1846 f_init();
1847
1848 f_init_l1ctl();
1849 f_sleep(1.0);
1850 f_l1_tune(L1CTL);
1851
Harald Welte52ae1682020-10-11 20:45:55 +02001852 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1853 alt {
1854 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1855 [] RSL_CCHAN.receive { repeat }
1856 }
1857
Harald Welte3453ab42019-05-24 21:19:58 +02001858 var GsmFrameNumber fn_last := 0;
1859 for (var integer i := 0; i < 1000; i := i+1) {
1860 var OCT1 ra := f_rnd_ra_cs();
1861 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1862 if (fn == fn_last) {
1863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1864 }
1865 fn_last := fn;
1866 }
1867
1868 timer T := 5.0;
1869 T.start;
1870 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001871 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001872 -> value rx_ud {
1873 var RSL_IE_Body ie;
1874 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1875 load_access_count := load_access_count + ie.rach_load.access_count;
1876 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1877 setverdict(fail, "Access count cannot be < Busy count");
1878 }
1879 repeat;
1880 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001881 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001882 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1883 repeat;
1884 }
1885 [] RSL_CCHAN.receive {
1886 repeat;
1887 }
1888 [] T.timeout { }
1889 }
1890 if (load_access_count == 1000) {
1891 setverdict(pass);
1892 } else {
1893 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1894 }
1895
1896 f_vty_load_ind_thresh(10);
1897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1898}
1899
Harald Welte54a2a2d2018-02-26 09:14:05 +01001900private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001901 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001902 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001903 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001904 f_sleep(0.5);
1905
1906 /* Transmit RACH request + wait for confirmation */
1907 var OCT1 ra := f_rnd_ra_cs();
1908 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1909
1910 /* Check for expected result */
1911 timer T := 1.5;
1912 T.start;
1913 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001914 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001915 setverdict(pass);
1916 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001917 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001919 }
1920 [] RSL_CCHAN.receive { repeat; }
1921 [not expect_pass] T.timeout {
1922 setverdict(pass);
1923 }
1924 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001926 }
1927 }
1928}
1929
1930/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1931testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001932 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001933 f_init_l1ctl();
1934 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001935 f_sleep(1.0);
1936
1937 /* default max-ta is 63 (full range of GSM timing advance */
1938
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001939 /* We allow early arrival up to 2 symbols */
1940 f_rach_toffs(-1*256, true);
1941 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001942 f_rach_toffs(-10*256, false);
1943
1944 /* 0 / 32 / 63 bits is legal / permitted */
1945 f_rach_toffs(0, true);
1946 f_rach_toffs(32*256, true);
1947 f_rach_toffs(63*256, true);
1948
1949 /* more than 63 bits is not legal / permitted */
1950 f_rach_toffs(64*256, false);
1951 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001953}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001954
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001955private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001956 var GsmFrameNumber fn;
1957 var RSL_Message rm;
1958
1959 f_l1_tune(L1CTL);
1960 RSL.clear;
1961
1962 /* Generate a random Handover Reference */
1963 var integer ho_ref := oct2int(f_rnd_octstring(1));
1964
1965 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1966 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1967 RSL_IE_Body:{ handover_ref := ho_ref }));
1968
1969 /* Activate a channel on the BTS side (no encryption) */
1970 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1971 act_type := t_RSL_IE_ActType_HO_SYNC);
1972
1973 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1974 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001975 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001976
1977 /* Send handover Access Burst */
1978 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1979
1980 /* TODO: test mismatching Handover Reference, and missing IE */
1981
1982 /* Wait for handover detection */
1983 timer T := 3.0;
1984 T.start;
1985 alt {
1986 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1987 log("Handover RACH has been detected: ", rm);
1988 setverdict(pass);
1989 }
1990 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1992 log2str("RSL_CHAN_RQD was not expected: ", rm));
1993 }
1994 [] RSL.receive { repeat; }
1995 [] T.timeout {
1996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1997 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1998 }
1999 }
2000
2001 /* Release the channel */
2002 f_rsl_chan_deact();
2003 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2004}
2005
2006/* Test handover RACH detection */
2007testcase TC_ho_rach() runs on test_CT {
2008 var ConnHdlrPars pars;
2009 var ConnHdlr vc_conn;
2010
2011 f_init();
2012
2013 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
2014 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
2015 log(testcasename(), ": Starting for ", g_AllChannels[i]);
2016 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
2017 vc_conn.done;
2018 }
2019
2020 /* TODO: do the above in parallel, rather than sequentially? */
2021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2022}
2023
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03002024/* Test sending of the RR Physical Information message on DCCH */
2025private function f_TC_ho_physical_info(charstring id) runs on ConnHdlr {
2026 var PDU_ML3_NW_MS dcch_pdu;
2027 var integer count := 0;
2028 var L1ctlDlMessage dl;
2029 timer T;
2030
2031 f_l1_tune(L1CTL);
2032 RSL.clear;
2033
2034 /* Generate a random Handover Reference */
2035 var integer ho_ref := oct2int(f_rnd_octstring(1));
2036
2037 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
2038 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
2039 RSL_IE_Body:{ handover_ref := ho_ref }));
2040
2041 /* Activate a channel on the BTS side (no encryption) */
2042 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
2043 act_type := t_RSL_IE_ActType_HO_SYNC);
2044
2045 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
2046 * waiting for Immediate Assignment and sending of an Access Burst. */
2047 f_l1ctl_est_dchan(L1CTL, g_pars); /* FIXME: disable Uplink Tx */
2048
2049 /* Expect nothing to be transmitted on Downlink DCCH. Nothing in this
2050 * context means any L2 frames, not only the RR Physical Information. */
2051 T.start(2.0);
2052 L1CTL.clear;
2053 alt {
2054 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value dl {
2055 setverdict(fail, "Rx unexpected Downlink DCCH (before handover RACH): ", dl);
2056 T.stop;
2057 }
2058 [] L1CTL.receive { repeat; }
2059 [] T.timeout { setverdict(pass); }
2060 }
2061
2062 /* Send handover Access Burst */
2063 log("Sending handover Access Burst");
2064 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
2065
2066 /* Expect RR Physical Information being sent on Downlink DCCH Ny1 times */
2067 T.start(int2float(mp_ho_t3105_ms * mp_ho_ny1) / 1000.0 + 1.0);
2068 L1CTL.clear;
2069 alt {
2070 [] as_dl_lapdm_dummy(); /* Ignore empty LAPDm func=UI frames */
2071 [] as_dl_dcch_pdu(dcch_pdu, tr_RRM_PhysicalInfo) {
2072 log("Rx RR Physical Information: ", dcch_pdu);
2073 /* Wait until the count reaches Ny1 */
2074 count := count + 1;
2075 if (count < mp_ho_ny1)
2076 { repeat; }
2077 setverdict(pass);
2078 }
2079 [] as_dl_dcch_pdu(dcch_pdu, ?) {
2080 setverdict(fail, "Rx unexpected DCCH PDU: ", dcch_pdu);
2081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2082 }
2083 [] L1CTL.receive { repeat; }
2084 [] T.timeout {
2085 setverdict(fail, "Timeout waiting for RR Physical Information");
2086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2087 }
2088 }
2089
2090 /* Release the channel */
2091 f_rsl_chan_deact();
2092 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2093}
2094testcase TC_ho_physical_info() runs on test_CT {
2095 var ConnHdlrPars pars;
2096 var ConnHdlr vc_conn;
2097
2098 f_init();
2099
2100 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
2101 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
2102 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
2103 vc_conn := f_start_handler(refers(f_TC_ho_physical_info), pars);
2104 vc_conn.done;
2105 }
2106
2107 /* TODO: do the above in parallel, rather than sequentially? */
2108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2109}
2110
Harald Welte93640c62018-02-25 16:59:33 +01002111/***********************************************************************
2112 * Measurement Processing / Reporting
2113 ***********************************************************************/
2114
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002115private template (value) LapdmAddressField
2116ts_LapdmAddr(template (value) LapdmSapi sapi,
2117 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01002118 spare := '0'B,
2119 lpd := 0,
2120 sapi := sapi,
2121 c_r := c_r,
2122 ea := true
2123}
2124
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002125private template (value) LapdmFrameAB
2126ts_LAPDm_AB(template (value) LapdmSapi sapi,
2127 template (value) GsmRrL3Message l3,
2128 template (value) boolean c_r := false,
2129 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01002130 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002131 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01002132 len := 0, /* overwritten */
2133 m := false,
2134 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03002135 payload := enc_GsmRrL3Message(valueof(l3)),
2136 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01002137}
2138
2139/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002140private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002141 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01002142 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002143
Harald Weltef8df4cb2018-03-10 15:15:08 +01002144 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002145 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07002146
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002147 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07002148 g_pars.l1_pars.meas_ul.full.rxlev,
2149 g_pars.l1_pars.meas_ul.sub.rxlev,
2150 g_pars.l1_pars.meas_ul.full.rxqual,
2151 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01002152 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02002153
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002154 var template (value) SacchL1Header l1h := ts_SacchL1Header(
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07002155 g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002156
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002157 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2158 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002159
2160 log("Sending Measurement Report: ", l1h, l2);
2161 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002162 repeat;
2163 }
2164}
2165
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002166/* handle incoming downlink SACCH, decode the L1 header into the given record */
2167private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2168 boolean do_apply := true)
2169runs on ConnHdlr
2170{
2171 var L1ctlDlMessage l1_dl;
2172
2173 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2174 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2175 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2176 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2177
2178 if (do_apply) {
2179 /* Update TA and MS power to follow what BTS requests */
2180 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2181 }
2182 }
2183}
2184
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002185private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002186 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002187 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002188 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2189 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002190 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2191 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002192 repeat;
2193 }
2194}
2195
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002196private altstep as_l1_tch_loop() runs on ConnHdlr {
2197 var L1ctlDlMessage l1_dl;
2198 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2199 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002200
2201 /* occasionaly inject FACCH frames into the uplink */
2202 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2203 var octetstring pl := '010301'O;
2204 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2205 f_pad_oct(pl, 23, '2B'O)));
2206 } else {
2207 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2208 l1_dl.payload.traffic_ind.data));
2209 }
2210
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002211 repeat;
2212 }
2213}
2214
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002215private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002216 uint6_t rxlev,
2217 uint3_t rxqual
2218}
2219
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002220private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002221 MeasElem full,
2222 MeasElem sub
2223}
2224
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002225private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002226 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002227 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002228 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002229 MeasElemFS meas_ul,
2230 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002231 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002232 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002233 uint8_t ms_actual_ta,
2234 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002235}
2236
2237/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2238private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2239 return 63 + (toffs256s/256);
2240}
2241
Harald Welted5684392018-03-10 18:22:04 +01002242private function f_max(integer a, integer b) return integer {
2243 if (a > b) {
2244 return a;
2245 } else {
2246 return b;
2247 }
2248}
2249
2250private function f_min(integer a, integer b) return integer {
2251 if (a < b) {
2252 return a;
2253 } else {
2254 return b;
2255 }
2256}
2257
2258/* compute negative tolerance val-tolerance, ensure >= min */
2259private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2260 val := val - tolerance;
2261 return f_max(val, min);
2262}
2263
2264/* compute positive tolerance val+tolerance, ensure <= max */
2265private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2266 val := val + tolerance;
2267 return f_min(val, max);
2268}
2269
2270/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2271private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2272return template integer {
2273 var template integer ret;
2274 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2275 return ret;
2276}
2277
2278
Harald Welte70767382018-02-21 12:16:40 +01002279/* build a template for matching measurement results against */
2280private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2281 var ConnL1Pars l1p := g_pars.l1_pars;
2282 var template RSL_IE_UplinkMeas ul_meas := {
2283 len := 3,
2284 rfu := '0'B,
2285 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002286 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002287 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002288 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002289 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002290 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2291 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002292 supp_meas_info := omit
2293 };
Harald Welte685d5982018-02-27 20:42:05 +01002294 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002295 ul_meas.len := (3+8);
2296 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002297 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002298 toa256_min := ?,
2299 toa256_max := ?,
2300 toa256_std_dev := ?
2301 }
Harald Welte685d5982018-02-27 20:42:05 +01002302 }
Harald Welte70767382018-02-21 12:16:40 +01002303 var template RSL_IE_BS_Power bs_power := {
2304 reserved := 0,
2305 epc := false,
2306 fpc := false,
2307 power_level := l1p.bs_power_level
2308 };
2309 var template RSL_IE_L1Info l1_info := {
2310 ms_power_lvl := l1p.ms_power_level,
2311 fpc := false,
2312 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002313 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002314 };
2315 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002316 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002317 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2318 ?, t_toffs);
2319}
2320
Philipp Maierdd841d32019-12-17 14:44:54 +01002321/* build a template for matching measurement results that do not contain any
2322 * MS related measurement (l1_info, l3_info and ms timing offset). */
2323private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2324 var ConnL1Pars l1p := g_pars.l1_pars;
2325 var template RSL_IE_UplinkMeas ul_meas := {
2326 len := 3,
2327 rfu := '0'B,
2328 dtx_d := l1p.dtx_enabled,
2329 rxlev_f_u := ?,
2330 reserved1 := '00'B,
2331 rxlev_s_u := ?,
2332 reserved2 := '00'B,
2333 rxq_f_u := ?,
2334 rxq_s_u := ?,
2335 supp_meas_info := omit
2336 };
2337 if (l1p.toa256_enabled) {
2338 ul_meas.len := (3+8);
2339 ul_meas.supp_meas_info := {
2340 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2341 toa256_min := ?,
2342 toa256_max := ?,
2343 toa256_std_dev := ?
2344 }
2345 }
2346 var template RSL_IE_BS_Power bs_power := {
2347 reserved := 0,
2348 epc := false,
2349 fpc := false,
2350 power_level := l1p.bs_power_level
2351 };
2352
2353 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2354}
2355
Harald Welte70767382018-02-21 12:16:40 +01002356/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002357private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002358 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002359 var boolean chan_est := false;
2360
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002361 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002362
2363 /* Receive osmocom specific measurement reports. This is the normal
2364 * case. Here we verify that the measurement reports we sent are
2365 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002366 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2367 /* increment counter of next to-be-expected meas rep */
2368 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2369 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002370 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002371
2372 /* The following two cases may only happen in the beginning
2373 * of the channel establishment phase. Once we have received
2374 * the "our" measurement report the first time, the channel
2375 * is established and empty or hardcoded TRXCON reports must
2376 * not occur anymore. */
2377 chan_est := true;
2378
2379 repeat;
2380 }
2381
2382 /* When the BTS has established the channel, the MS might need slightly
2383 * more time to establish the channel and actually start sending. The
2384 * result is then a measurement report that just lacks the measurement
2385 * information of the MS. This is normal and we tolerate this behavior. */
2386 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2387 /* increment counter of next to-be-expected meas rep */
2388 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2389 /* Re-start the timer expecting the next MEAS RES */
2390 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002391 repeat;
2392 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002393
2394 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2395 * measurements if the TTCN3 side does not supply measurement input in
2396 * time. In those cases TRXCON will either use a cached measurement
2397 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2398 * report the templates above will not match. We tolerate this
2399 * behavior, but only once. */
2400 [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 +01002401 /* increment counter of next to-be-expected meas rep */
2402 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2403 if (g_first_meas_res) {
2404 g_first_meas_res := false;
2405 repeat;
2406 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002408 }
Harald Welte70767382018-02-21 12:16:40 +01002409 }
2410 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002412 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002413 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002415 }
2416}
2417
Harald Weltee613f962018-04-18 22:38:16 +02002418private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2419 select (rsl_alg_id) {
2420 case (RSL_ALG_ID_A5_0) { return 0; }
2421 case (RSL_ALG_ID_A5_1) { return 1; }
2422 case (RSL_ALG_ID_A5_2) { return 2; }
2423 case (RSL_ALG_ID_A5_3) { return 3; }
2424 case (RSL_ALG_ID_A5_4) { return 4; }
2425 case (RSL_ALG_ID_A5_5) { return 5; }
2426 case (RSL_ALG_ID_A5_6) { return 6; }
2427 case (RSL_ALG_ID_A5_7) { return 7; }
2428 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2430 /* Make compiler happy by calling mtc.stop here. It is already
2431 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002432 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002433 }
2434 }
2435}
2436
2437private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2438 select (rsl_alg_id) {
2439 case (RSL_ALG_ID_A5_1) { return '000'B; }
2440 case (RSL_ALG_ID_A5_2) { return '001'B; }
2441 case (RSL_ALG_ID_A5_3) { return '010'B; }
2442 case (RSL_ALG_ID_A5_4) { return '011'B; }
2443 case (RSL_ALG_ID_A5_5) { return '100'B; }
2444 case (RSL_ALG_ID_A5_6) { return '101'B; }
2445 case (RSL_ALG_ID_A5_7) { return '110'B; }
2446 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2448 /* Make compiler happy by calling mtc.stop here. It is already
2449 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002450 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002451 }
2452 }
2453}
2454
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002455/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2456private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2457 var GsmFrameNumber fn;
2458 timer T := 8.0;
2459
2460 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2461 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2462
2463 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2464 /* Send the actual RACH */
2465 fn := f_L1CTL_RACH(L1CTL, ra);
2466
2467 T.start;
2468 alt {
2469 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2470 [] T.timeout {
2471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2472 }
2473 }
2474 T.stop
2475 return fn;
2476}
Harald Weltee613f962018-04-18 22:38:16 +02002477
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002478/* Tune to a dedicated channel: L1CTL only */
2479private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002480 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002481 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002482 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002483 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002484 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002485 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002486 pars.fhp.maio_hsn.hsn,
2487 pars.fhp.maio_hsn.maio,
2488 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002489 }
2490}
2491
Harald Welte70767382018-02-21 12:16:40 +01002492/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002493private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002494 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002495
2496 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002497 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002498
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002499 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002500 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002501 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002502 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002503 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2504 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002505 }
2506
Harald Welte70767382018-02-21 12:16:40 +01002507 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002508 f_l1ctl_est_dchan(L1CTL, g_pars);
2509
Harald Weltee613f962018-04-18 22:38:16 +02002510 /* enable encryption, if requested */
2511 if (encr_enable) {
2512 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2513 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2514 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002515
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002516 /* Send TCH Mode Request to the L1 if needed */
2517 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2518 var L1ctlTchMode tch_mode;
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +02002519 var uint8_t amr_start_codec := 0;
2520 var BIT8 amr_codecs_bitmask := '00000000'B;
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002521
2522 select (g_pars.chan_mode.coding_alg_rate) {
2523 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2524 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2525 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +02002526 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3;
2527 amr_codecs_bitmask := g_pars.mr_conf.amr_codec_modes;
2528 }
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002529 case else {
2530 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2531 " is not supported by the L1, falling back to signalling");
2532 tch_mode := L1CTL_CHAN_MODE_SIGN;
2533 }
2534 }
2535
Pau Espin Pedrol440e1dc2022-09-02 16:35:49 +02002536 f_L1CTL_TCH_MODE(L1CTL,
2537 ts_L1CTL_TCH_MODE_REQ(tch_mode,
2538 amr_start_codec := amr_start_codec,
2539 amr_codecs_bitmask := amr_codecs_bitmask));
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002540 }
2541
Harald Weltefa45e9e2018-03-10 18:59:03 +01002542 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002543}
2544
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002545/* Initialize and start the RTP emulation component for a ConnHdlr */
2546friend function f_rtpem_activate(inout octetstring payload,
2547 RtpemConfig cfg := c_RtpemDefaultCfg,
2548 RtpemMode mode := RTPEM_MODE_BIDIR)
2549runs on ConnHdlr {
2550 /* Step 0: initialize, connect and start the emulation component */
2551 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2552 map(vc_RTPEM:RTP, system:RTP);
2553 map(vc_RTPEM:RTCP, system:RTCP);
2554 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2555 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2556 vc_RTPEM.start(RTP_Emulation.f_main());
2557
2558 /* Step 1: configure the RTP parameters */
2559 var integer payload_len := 0;
2560 var octetstring hdr := ''O;
2561
2562 select (g_pars.chan_mode) {
2563 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2564 { payload_len := 33; hdr := 'D0'O; }
2565 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2566 { payload_len := 15; hdr := '00'O; }
2567 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2568 { payload_len := 31; hdr := 'C0'O; }
2569 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2570 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2572 }
2573 }
2574
2575 /* Pad the payload to conform the expected length */
2576 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2577 cfg.tx_fixed_payload := payload;
2578 f_rtpem_configure(RTPEM_CTRL, cfg);
2579
2580 /* Step 2: bind the RTP emulation to the configured address */
2581 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2582 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2583
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002584 /* Step 3a: send CRCX to create an RTP connection at the IUT */
2585 var RSL_Message crcx_ack := f_rsl_transceive_ret(
2586 /* FIXME (OS#5242): do not include Remote IP/Port IEs because
2587 * osmo-bts would respond with nonsense listen addr='0.0.0.0'. */
2588 ts_RSL_IPA_CRCX(g_chan_nr, omit, omit),
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002589 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2590 "IPA CRCX ACK");
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002591 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002592
Vadim Yanitskiy0dd96e92022-05-01 01:36:12 +03002593 /* Step 3b: send MDCX with the configured address/port to the IUT */
2594 var RSL_Message mdcx_ack := f_rsl_transceive_ret(
2595 ts_RSL_IPA_MDCX(g_chan_nr, conn_id,
2596 remote_ip := f_inet_addr(mp_rtpem_bind_ip),
2597 remote_port := rtpem_bind_port,
2598 rtp_pt2 := 0),
2599 tr_RSL_IPA_MDCX_ACK(g_chan_nr, conn_id, ?, ?, ?),
2600 "IPA MDCX ACK");
2601
2602 /* Step 4: connect to the IUT's address/port parsed from MDCX ACK */
2603 var HostName bts_bind_ip := f_inet_ntoa(mdcx_ack.ies[2].body.ipa_local_ip);
2604 var PortNumber bts_bind_port := mdcx_ack.ies[3].body.ipa_local_port;
2605 f_rtpem_connect(RTPEM_CTRL, bts_bind_ip, bts_bind_port);
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002606
2607 /* Step 5: set the given RTP emulation mode */
2608 f_rtpem_mode(RTPEM_CTRL, mode);
2609}
2610
Harald Welte70767382018-02-21 12:16:40 +01002611/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002612private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002613 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002614 RSL.clear;
2615
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002616 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002617 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002618 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002619 }
Harald Welte70767382018-02-21 12:16:40 +01002620
2621 f_est_dchan();
2622
2623 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2624 * RSL measurement reports on Abis side */
2625 timer T := 8.0;
2626 T.start;
2627 alt {
2628 [] as_l1_sacch();
2629 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002630 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002631 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002632 [] L1CTL.receive { repeat; }
2633 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002634 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002635 * of any earlier errors, so if we reach this timeout, we're good */
2636 setverdict(pass);
2637 }
2638 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002640 }
2641 }
2642 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002643 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002644}
Harald Welte0472ab42018-03-12 15:02:26 +01002645
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002646/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2647private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002648 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002649 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2650 timer Tup := 10.0;
2651 Tup.start;
2652 alt {
2653 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2654 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2655 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002656
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002657 if (rx_lvl != max_rx_lvl) {
2658 repeat;
2659 }
2660 Tup.stop;
2661 }
2662 [] L1CTL.receive { repeat; }
2663 [] Tup.timeout {
2664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2665 log2str("Didn't reach full power ", max_rx_lvl));
2666 }
2667 }
2668 return max_rx_lvl;
2669}
2670
2671/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2672private function f_verify_ramp_up() runs on ConnHdlr {
2673 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002674 var integer initial_rx_lvl := -1;
2675 var integer last_rx_lvl := -1;
2676 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2677
2678 timer T := 2.0;
2679 alt {
2680 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2681 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2682 log("Received rx_level=", rx_lvl);
2683 if (initial_rx_lvl == -1) {
2684 initial_rx_lvl := rx_lvl;
2685 last_rx_lvl := rx_lvl;
2686
2687 /* Expect a somehow low value during first received messages */
2688 if (initial_rx_lvl >= max_rx_lvl / 2) {
2689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2690 log2str("Detected high initial tx power during ramp up: ",
2691 initial_rx_lvl , ", full power is", max_rx_lvl));
2692 }
2693 }
2694
2695 /* received Rx level bigger than maximum allowed power by CN */
2696 if (rx_lvl > max_rx_lvl) {
2697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2698 log2str("Detected Tx power higher than full power: ",
2699 rx_lvl , " > ", max_rx_lvl));
2700 }
2701
2702 /* Make sure it never decreases, since we are rumping up */
2703 if (last_rx_lvl > rx_lvl) {
2704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2705 log2str("Detected Tx power decrease during ramp up: ",
2706 last_rx_lvl , " -> ", rx_lvl));
2707 }
2708
2709 if (rx_lvl == max_rx_lvl and not T.running) {
2710 /* We reached the maximum power, start timer and receive
2711 /* a few more to make sure we don't surpass it */
2712 log("Reached full power, wating a bit more until success");
2713 T.start;
2714 }
2715
2716 last_rx_lvl := rx_lvl;
2717 repeat;
2718 }
2719 [] L1CTL.receive { repeat; }
2720 [] T.timeout { }
2721 }
2722
2723 /* We didn't increase tx power during ramp up */
2724 if (initial_rx_lvl < last_rx_lvl) {
2725 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2726 } else {
2727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2728 log2str("No Tx power increase during whole ramp up: ",
2729 initial_rx_lvl , " -> ", last_rx_lvl));
2730 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002731}
2732
2733/* verify BTS ramps power down to rx_level 0 */
2734private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2735 var L1ctlDlMessage l1_dl;
2736 var integer last_rx_lvl := max_rx_lvl;
2737
2738 timer Tdown := 5.0;
2739 Tdown.start;
2740 alt {
2741 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2742 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2743 log("Received rx_level=", rx_lvl);
2744
2745 /* received Rx level bigger than maximum allowed power by CN */
2746 if (rx_lvl > max_rx_lvl) {
2747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2748 log2str("Detected Tx power higher than full power: ",
2749 rx_lvl , " > ", max_rx_lvl));
2750 }
2751
2752 /* Make sure it never increases, since we are rumping down */
2753 if (last_rx_lvl < rx_lvl) {
2754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2755 log2str("Detected Tx power increase during ramp up: ",
2756 last_rx_lvl , " -> ", rx_lvl));
2757 }
2758
2759 last_rx_lvl := rx_lvl;
2760 if (last_rx_lvl != 0) {
2761 repeat;
2762 }
2763 /* we reached power level 0, we are done */
2764 Tdown.stop;
2765 }
2766 [] L1CTL.receive { repeat; }
2767 [] Tdown.timeout { }
2768 }
2769
2770 /* We didn't increase tx power during ramp down */
2771 if (max_rx_lvl > last_rx_lvl) {
2772 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2773 } else {
2774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2775 log2str("No Tx power decrease during whole ramp down: ",
2776 max_rx_lvl , " -> ", last_rx_lvl));
2777 }
2778}
2779
2780/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002781private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002782 f_l1_tune(L1CTL);
2783 RSL.clear;
2784
2785 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002786
2787 setverdict(pass);
2788}
2789testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2790 var ConnHdlr vc_conn;
2791 var ConnHdlrPars pars;
2792 f_init();
2793 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2794 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2795 pcu_comp := false, trxc_comp := true);
2796 vc_conn.done;
2797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2798}
2799
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002800/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002801private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002802 f_connhdlr_init_vty_bsc();
2803
2804 f_l1_tune(L1CTL);
2805 RSL.clear;
2806
2807 /* Wait until BTS is started and at full power */
2808 var integer max_rx_lvl := f_wait_ramp_up();
2809 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2810
2811 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2812 f_verify_ramp_down(max_rx_lvl);
2813
2814 setverdict(pass);
2815}
2816testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2817 var ConnHdlr vc_conn;
2818 var ConnHdlrPars pars;
2819 f_init();
2820 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2821 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2822 pcu_comp := false, trxc_comp := true);
2823 vc_conn.done;
2824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2825}
2826
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002827/* Verify Tx power:
2828 * + ramping down during ADM state UNLOCKED->LOCKED
2829 * + ramping up during ADM state LOCKED->UNLOCKED
2830 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002831private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002832 var L1ctlDlMessage l1_dl;
2833 var integer last_rx_lvl;
2834
2835 f_connhdlr_init_vty_bsc();
2836
2837 f_l1_tune(L1CTL);
2838 RSL.clear;
2839
2840 /* Wait until BTS is started and at full power */
2841 var integer max_rx_lvl := f_wait_ramp_up();
2842 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2843
2844 log("ADM STATE UNLOCKED->LOCKED");
2845 f_vty_enter_cfg_trx(BSCVTY);
2846 f_vty_transceive(BSCVTY, "rf_locked 1");
2847 last_rx_lvl := max_rx_lvl;
2848 f_verify_ramp_down(max_rx_lvl);
2849
2850 /* Let some time after we received 0dBm, then check we don't receive BCCH
2851 * anymore because scheduler has stopped after ramping down */
2852 f_sleep(2.0);
2853 L1CTL.clear;
2854 timer Tlocked := 2.0;
2855 Tlocked.start;
2856 alt {
2857 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2859 log2str("Received data_ind during rf_locked: ", l1_dl));
2860 }
2861 [] L1CTL.receive { repeat; }
2862 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2863 }
2864
2865 log("ADM STATE LOCKED->UNLOCKED");
2866 f_vty_transceive(BSCVTY, "rf_locked 0");
2867 f_verify_ramp_up();
2868 setverdict(pass);
2869}
2870testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2871 var ConnHdlr vc_conn;
2872 var ConnHdlrPars pars;
2873 f_init();
2874 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2875 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2876 pcu_comp := false, trxc_comp := true);
2877 vc_conn.done;
2878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2879}
2880
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002881private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002882 timer T := 8.0;
2883 T.start;
2884 var RSL_Message rsl;
2885 alt {
2886 [] as_l1_sacch();
2887 [] L1CTL.receive { repeat; }
2888 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2889 if (rsl.ies[3].body.bs_power.power_level == level) {
2890 setverdict(pass)
2891 } else {
2892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2893 }
2894 }
2895 [] T.timeout {
2896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2897 }
2898 }
2899}
2900
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002901/* See if the RSL MEASurement RESult contains expeced BS power level
2902 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002903private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002904 f_l1_tune(L1CTL);
2905 RSL.clear;
2906
2907 if (mp_bts_trxc_port != -1) {
2908 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2909 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2910 }
2911
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002912 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002913 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2914 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2915
2916 f_est_dchan(more_ies :={valueof(pwr)});
2917
2918 f_check_meas_bs_power_level(pwr_var);
2919
2920 f_rsl_chan_deact();
2921 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2922}
2923
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002924/* See if the RSL MEASurement RESult contains expeced BS power level
2925 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002926private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002927 f_l1_tune(L1CTL);
2928 RSL.clear;
2929
2930 if (mp_bts_trxc_port != -1) {
2931 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2932 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2933 }
2934
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002935 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002936 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2937
2938 f_est_dchan();
2939
2940 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2941
2942 f_check_meas_bs_power_level(pwr_var);
2943
2944 f_rsl_chan_deact();
2945 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2946}
2947
2948testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2949 var ConnHdlr vc_conn;
2950 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002951
Eric Wildae8f2622019-06-18 17:05:11 +02002952 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002953
2954 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2955 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2956 pcu_comp := false, trxc_comp := true);
2957 vc_conn.done;
2958
Eric Wildae8f2622019-06-18 17:05:11 +02002959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2960}
2961
2962testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2963 var ConnHdlr vc_conn;
2964 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002965
Eric Wildae8f2622019-06-18 17:05:11 +02002966 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002967
2968 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2969 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2970 pcu_comp := false, trxc_comp := true);
2971 vc_conn.done;
2972
Eric Wildae8f2622019-06-18 17:05:11 +02002973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2974}
2975
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002976/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2977 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2978 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002979private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002980 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002981 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002982
2983 f_trxc_fake_rssi(rxlev2dbm(10));
2984 f_l1_tune(L1CTL);
2985 RSL.clear;
2986
2987 var RSL_IE_List addl_ies;
2988 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2989
2990 addl_ies := {
2991 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2992 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2993 };
2994
2995 /* establish with power parameters */
2996 f_est_dchan(more_ies := addl_ies);
2997
2998 /* set a high value to ensure L1 power control level increases */
2999 f_trxc_fake_rssi(rxlev2dbm(20));
3000
3001 timer T2 := 6.0;
3002 T2.start;
3003 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003004 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +07003005 f_send_meas_rep_l1h(ts_MeasurementResults, l1h);
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003006
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003007 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003008 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01003009 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003010 T2.stop;
3011 }
3012 [] L1CTL.receive { repeat; }
3013 [] T2.timeout {
3014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3015 "Power Level in L1 header has not increased sufficiently");
3016 }
3017 }
3018
3019 /* set a low value to ensure L1 power control level decreases */
3020 f_trxc_fake_rssi(rxlev2dbm(0));
3021
3022 timer T4 := 6.0;
3023 T4.start;
3024 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003025 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +07003026 f_send_meas_rep_l1h(ts_MeasurementResults, l1h);
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003027
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003028 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003029 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01003030 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003031 T4.stop;
3032 setverdict(pass, "Power level in L1 decreased/increased as expected");
3033 }
3034 [] L1CTL.receive { repeat; }
3035 [] T4.timeout {
3036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3037 "Power Level in L1 header has not decreased sufficiently");
3038 }
3039 }
3040
3041 f_rsl_chan_deact();
3042 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3043
3044}
3045
3046/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003047private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02003048 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003049 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003050
3051 /* set a low value to ensure power increases */
3052 f_trxc_fake_rssi(rxlev2dbm(10));
3053 f_l1_tune(L1CTL);
3054 RSL.clear;
3055
3056 var RSL_IE_List addl_ies;
3057 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
3058
3059 addl_ies := {
3060 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
3061 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
3062 };
3063
3064 /* establish with power parameters */
3065 f_est_dchan(more_ies := addl_ies);
3066
3067 timer T1 := 10.0;
3068 T1.start;
3069 alt {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003070 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +07003071 f_send_meas_rep_l1h(ts_MeasurementResults, l1h);
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003072 repeat;
3073 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003074 [] L1CTL.receive { repeat; }
3075 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003076 if (not isbound(l1h)) {
3077 setverdict(fail, "No SACCH blocks were received");
3078 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003079 setverdict(fail, "Power level in L1 header should not have changed");
3080 }
3081 }
3082 }
3083
3084 f_rsl_chan_deact();
3085 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3086
3087}
3088
3089/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003090private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003091 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003092 var uint5_t pwr_var := 15;
3093 var uint5_t pwr_max_var := f_get_max_power_from_band();
3094
3095 /* set a low value to ensure power increases */
3096 f_trxc_fake_rssi(rxlev2dbm(10));
3097 f_l1_tune(L1CTL);
3098 RSL.clear;
3099
3100 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3101 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3102
3103 /* establish with fixed power level */
3104 f_est_dchan(more_ies :={valueof(pwr)});
3105
3106 /* check our initial power level */
3107 f_wait_for_l1_power_level(pwr_var);
3108
3109 /* update power param to enable power loop
3110 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
3111 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
3112
Vadim Yanitskiy93ad8142022-04-08 01:52:13 +03003113 /* By default, the MS power loop gets triggered every 4th SACCH block (1.92s).
3114 * We need 9 * 4 dB steps to get from 0 dBm to 33 dBm, so 9 * 1.92s total.
3115 * Add an extra offset to avoid race conditions: +1.92s. */
3116 timer T1 := 9.0 * 1.92 + 1.92;
Eric Wild61edb7e2019-06-03 12:38:31 +02003117 T1.start;
3118 alt {
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003119 [] as_l1_sacch_l1h(l1h) {
Vadim Yanitskiya2cd8932022-08-10 17:56:25 +07003120 f_send_meas_rep_l1h(ts_MeasurementResults, l1h);
Vadim Yanitskiy39994912022-07-30 18:06:13 +07003121 repeat;
3122 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003123 [] L1CTL.receive { repeat; }
3124 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003125 if (not isbound(l1h)) {
3126 setverdict(fail, "No SACCH blocks were received");
3127 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003128 setverdict(pass, "Power level in L1 header reduced as expected");
3129 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003130 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
3131 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02003132 }
3133 }
3134 }
3135
3136 f_rsl_chan_deact();
3137 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3138
3139}
3140
3141/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003142private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003143 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003144
3145 /* set a high value to ensure power decreases */
3146 f_trxc_fake_rssi(rxlev2dbm(50));
3147 f_l1_tune(L1CTL);
3148 RSL.clear;
3149
3150 var uint5_t pwr_var := 5;
3151 var uint5_t pwr_target_val := 15;
3152
3153 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3154 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3155
3156 /* establish with fixed power level */
3157 f_est_dchan(more_ies :={valueof(pwr)});
3158
3159 /* check our initial power level */
3160 f_wait_for_l1_power_level(pwr_var);
3161
3162 /* update power param to enable power loop
3163 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01003164 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02003165
3166 /* wait, then check that our power level was increased */
3167 timer T1 := 10.0;
3168 T1.start;
3169 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003170 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02003171 [] L1CTL.receive { repeat; }
3172 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003173 if (not isbound(l1h)) {
3174 setverdict(fail, "No SACCH blocks were received");
3175 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
3176 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003177 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003178 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02003179 }
3180 }
3181 }
3182
3183 f_rsl_chan_deact();
3184 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3185
3186}
3187
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003188/* See if the power level remains constant when MS Power Parameters IE
3189 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003190private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003191 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003192
3193 /* set a high value to ensure power decreases */
3194 f_trxc_fake_rssi(rxlev2dbm(50));
3195 f_l1_tune(L1CTL);
3196 RSL.clear;
3197
3198 var uint5_t pwr_var := 5;
3199
3200 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3201 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3202
3203 /* establish with fixed power level */
3204 f_est_dchan(more_ies :={valueof(pwr)});
3205
3206 /* check our initial power level */
3207 f_wait_for_l1_power_level(pwr_var);
3208
3209 /* wait, then check that our power level did not change */
3210 timer T1 := 10.0;
3211 T1.start;
3212 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003213 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3214 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3216 "BS power control should not be active unless we receive a power parameters IE!");
3217 }
3218 repeat;
3219 }
3220 [] L1CTL.receive { repeat; }
3221 [] T1.timeout { setverdict(pass); }
3222 }
3223
3224 f_rsl_chan_deact();
3225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3226
3227}
3228
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003229/* See if the power level remains constant when MS Power Parameters IE
3230 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003231private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003232 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003233
3234 /* set a high value to ensure power decreases */
3235 f_trxc_fake_rssi(rxlev2dbm(50));
3236 f_l1_tune(L1CTL);
3237 RSL.clear;
3238
3239 var uint5_t pwr_var := 5;
3240
3241 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3242 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3243
3244 /* establish with fixed power level */
3245 f_est_dchan(more_ies :={valueof(pwr)});
3246
3247 /* check our initial power level */
3248 f_wait_for_l1_power_level(pwr_var);
3249
3250 /* pwr control without power params IE, should NOT activate MS power control*/
3251 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3252
3253 /* wait, then check that our power level did not change */
3254 timer T1 := 10.0;
3255 T1.start;
3256 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003257 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3258 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3260 "BS power control should not be active unless we receive a power parameters IE!");
3261 }
3262 repeat;
3263 }
3264 [] L1CTL.receive { repeat; }
3265 [] T1.timeout { setverdict(pass); }
3266 }
3267
3268 f_rsl_chan_deact();
3269 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3270
3271}
3272
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003273private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003274 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003275 timer T0 := 10.0;
3276 T0.start;
3277 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003278 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3279 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3281 "Power level in L1 header != signaled (RSL) power level.");
3282 }
3283 }
3284 [] L1CTL.receive { repeat; }
3285 [] T0.timeout {
3286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3287 "Timeout waiting for initial power level");
3288 }
3289 }
3290 T0.stop;
3291}
3292
3293private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3294 var IntegerRecord min_dbm_level;
3295 var IntegerRecord max_dbm_level;
3296 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3297
3298 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3299 if (min_dbm_level[i] == level) {
3300 return true;
3301 }
3302 }
3303 return false;
3304}
3305
3306private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3307 var IntegerRecord min_dbm_level;
3308 var IntegerRecord max_dbm_level;
3309 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3310
3311 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3312 if (max_dbm_level[i] == level) {
3313 return true;
3314 }
3315 }
3316 return false;
3317}
3318
3319private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3320 var IntegerRecord min_dbm_level;
3321 var IntegerRecord max_dbm_level;
3322 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3323 return max_dbm_level[0];
3324}
3325
3326type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003327private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003328private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3329 // 45.005 4.1.1
3330 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3331 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3332 2, 1, 0};
3333 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3334 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3335 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3336 var IntegerRecord rv;
3337
3338 select(band){
3339 case (BtsBand_allGSM){
3340 rv := gsm_power;
3341 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3342 max_dbm_level := {2, 1, 0};
3343 }
3344 case("DCS1800"){
3345 rv := dcs_power;
3346 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3347 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3348 }
3349 case("PCS1900"){
3350 rv := pcs_power;
3351 min_dbm_level := {15};
3352 max_dbm_level := {30};
3353 }
Harald Welte194b6912020-10-11 21:01:55 +02003354 case else {
3355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3356 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003357 }
3358
3359 return rv;
3360}
3361
3362private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003363 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 +02003364}
3365
3366testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3367 var ConnHdlr vc_conn;
3368 var ConnHdlrPars pars;
3369 f_init();
3370 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3371 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3372 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3373 pars.bts0_band := f_vty_get_bts0_band();
3374 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3375 vc_conn.done;
3376 }
3377 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3379}
3380
3381testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3382 var ConnHdlr vc_conn;
3383 var ConnHdlrPars pars;
3384 f_init();
3385 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3386 for (var integer tn := 1; tn <= 1; tn := tn+1) {
Vadim Yanitskiyc78aeb72022-07-30 17:56:39 +07003387 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN, t_guard := 30.0));
Eric Wild61edb7e2019-06-03 12:38:31 +02003388 pars.bts0_band := f_vty_get_bts0_band();
3389 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3390 vc_conn.done;
3391 }
3392 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3394}
3395
3396testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3397 var ConnHdlr vc_conn;
3398 var ConnHdlrPars pars;
3399 f_init();
3400 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3401 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3402 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3403 pars.bts0_band := f_vty_get_bts0_band();
3404 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3405 vc_conn.done;
3406 }
3407 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3409}
3410
3411testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3412 var ConnHdlr vc_conn;
3413 var ConnHdlrPars pars;
3414 f_init();
3415 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3416 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3417 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3418 pars.bts0_band := f_vty_get_bts0_band();
3419 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3420 vc_conn.done;
3421 }
3422 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3424}
3425
Eric Wild280ccb82019-06-17 11:11:52 +02003426testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3427 var ConnHdlr vc_conn;
3428 var ConnHdlrPars pars;
3429 f_init();
3430 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3431 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3432 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3433 pars.bts0_band := f_vty_get_bts0_band();
3434 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3435 vc_conn.done;
3436 }
3437 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3439}
3440
Eric Wild095024b2019-06-17 15:08:57 +02003441testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3442 var ConnHdlr vc_conn;
3443 var ConnHdlrPars pars;
3444 f_init();
3445 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3446 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3447 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3448 pars.bts0_band := f_vty_get_bts0_band();
3449 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3450 vc_conn.done;
3451 }
3452 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3454}
3455
Philipp Maier149c3922020-10-22 17:29:36 +02003456function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003457 var template RSL_IE_ChannelMode ch_mode;
3458 var ConnHdlr vc_conn;
3459 var ConnHdlrPars pars;
3460 f_init();
3461 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3462 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3463 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003464 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003465 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3466 pcu_comp := false, trxc_comp := true);
3467 vc_conn.done;
3468 }
3469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3470}
Philipp Maier149c3922020-10-22 17:29:36 +02003471
3472testcase TC_meas_res_speech_tchf() runs on test_CT {
3473 f_TC_meas_res_speech_tchf(false);
3474}
3475
3476testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3477 f_TC_meas_res_speech_tchf(true);
3478}
3479
3480function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003481 var template RSL_IE_ChannelMode ch_mode;
3482 var ConnHdlr vc_conn;
3483 var ConnHdlrPars pars;
3484 f_init();
3485 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3486 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3487 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003488 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003489 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3490 pcu_comp := false, trxc_comp := true);
3491 vc_conn.done;
3492 }
3493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3494}
Philipp Maier149c3922020-10-22 17:29:36 +02003495
3496testcase TC_meas_res_speech_tchh() runs on test_CT {
3497 f_TC_meas_res_speech_tchh(false)
3498}
3499
3500testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3501 f_TC_meas_res_speech_tchh(true)
3502}
3503
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003504testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3505 var template RSL_IE_ChannelMode ch_mode;
3506 var ConnHdlr vc_conn;
3507 var ConnHdlrPars pars;
3508 f_init();
3509 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3510 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3511 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3512 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3513 pars.l1_pars.toa256_enabled := true;
3514 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3515 pcu_comp := false, trxc_comp := true);
3516 vc_conn.done;
3517 }
3518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3519}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003520
Harald Welte70767382018-02-21 12:16:40 +01003521testcase TC_meas_res_sign_tchf() runs on test_CT {
3522 var ConnHdlr vc_conn;
3523 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003524 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003525 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003526 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003527 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003528 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3529 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003530 vc_conn.done;
3531 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003533}
3534testcase TC_meas_res_sign_tchh() runs on test_CT {
3535 var ConnHdlr vc_conn;
3536 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003537 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003538 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003539 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003540 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003541 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3542 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003543 vc_conn.done;
3544 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003546}
3547testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3548 var ConnHdlr vc_conn;
3549 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003550 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003551 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003552 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3553 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003554 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3555 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003556 vc_conn.done;
3557 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003559}
3560testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3561 var ConnHdlr vc_conn;
3562 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003563 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003564 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003565 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3566 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003567 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3568 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003569 vc_conn.done;
3570 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003572}
Harald Welte685d5982018-02-27 20:42:05 +01003573testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3574 var ConnHdlr vc_conn;
3575 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003576 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003577 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3578 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003579 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003580 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003581 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3582 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003583 vc_conn.done;
3584 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003586}
3587
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003588/* Make sure that we always get RSL MEASurement RESult messages regardless
3589 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3590private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3591 timer Texec := 8.0;
3592 timer Timpf := 2.0;
3593 timer Tmr;
3594
3595 f_l1_tune(L1CTL);
3596 RSL.clear;
3597
3598 f_est_dchan();
3599 L1CTL.clear;
3600
3601 /* Establish the main SAPI=0 link on DCCH first */
3602 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3603
3604 /* Give more time for the first RSL MEASurement RESult */
3605 Tmr.start(0.480 * 2.0);
3606 Texec.start; /* EXECution timer */
3607 Timpf.start; /* IMPFung timer */
3608
3609 alt {
3610 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3611 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3612 /* Reschedule the MEAS RES timer */
3613 Tmr.start(0.480 + 0.120);
3614 repeat;
3615 }
3616 [] RSL.receive { repeat; }
3617 [] Tmr.timeout {
3618 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3619 }
3620 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3621 [] Timpf.timeout {
3622 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3623 log("Injected SAPI=3 traffic on SACCH");
3624 Timpf.start;
3625 repeat;
3626 }
3627 /* We're good if survived so far */
3628 [] Texec.timeout {
3629 setverdict(pass);
3630 }
3631 }
3632
3633 f_rsl_chan_deact();
3634 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3635 f_rslem_unregister(0, g_chan_nr);
3636}
3637testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3638 var template RSL_IE_ChannelMode ch_mode;
3639 var template ConnHdlrPars pars;
3640 var ConnHdlr vc_conn;
3641
3642 f_init();
3643
3644 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3645 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3646
3647 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3648 vc_conn.done;
3649
3650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3651}
3652testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3653 var template RSL_IE_ChannelMode ch_mode;
3654 var template ConnHdlrPars pars;
3655 var ConnHdlr vc_conn;
3656
3657 f_init();
3658
3659 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3660 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3661
3662 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3663 vc_conn.done;
3664
3665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3666}
3667
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003668/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3669 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003670private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003671 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003672 var RSL_IE_MS_Power ms_power;
3673 var RSL_Message rsl;
3674 var uint5_t power_level := 0;
3675
3676 f_l1_tune(L1CTL);
3677 RSL.clear;
3678
3679 f_est_dchan();
3680
3681 ms_power.reserved := 0;
3682 ms_power.fpc_epc := false;
3683
3684 /* Send the first power control command. This will disable any BTS/TRX
3685 * internal power control and switch the MS (which is not in scope of
3686 * this test) to a constant power level. We start with a power level
3687 * of 0 */
3688 ms_power.power_level := power_level;
3689 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3690 RSL.send(rsl);
3691
3692 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003693 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3694 if (l1h.ms_power_lvl != power_level) {
3695 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3696 "match the signaled (RSL) power level := ", power_level);
3697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003698 }
3699
3700 /* Signal a new power level via RSL for the next turn. */
3701 if (power_level < 31) {
3702 power_level := power_level + 1;
3703 ms_power.power_level := power_level;
3704 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3705 RSL.send(rsl);
3706 repeat;
3707 }
3708
3709 }
3710
3711 /* Ignore all other blocks */
3712 [] L1CTL.receive { repeat; }
3713
3714 }
3715
3716 f_rsl_chan_deact();
3717 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3718
3719 setverdict(pass);
3720}
3721
3722testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3723 var ConnHdlr vc_conn;
3724 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003725 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003726
3727 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3728 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3729 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3730 vc_conn.done;
3731 }
3732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3733}
Harald Welte70767382018-02-21 12:16:40 +01003734
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003735/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003736TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003737private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003738 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003739 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003740
3741 f_l1_tune(L1CTL);
3742 RSL.clear;
3743
3744 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003745 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003746
3747 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3748
3749
3750 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003751 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3752 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003753 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3754 }
3755
3756 }
3757
3758 /* Ignore all other blocks */
3759 [] L1CTL.receive { repeat; }
3760
3761 }
3762
3763 f_rsl_chan_deact();
3764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3765
3766 setverdict(pass);
3767}
3768
3769testcase TC_rsl_chan_initial_ta() runs on test_CT {
3770 var ConnHdlr vc_conn;
3771 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003772 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003773 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003774 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3775 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003776 vc_conn.done;
3777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3778}
3779
Eric Wilde57e1a62019-05-28 13:30:55 +02003780/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003781private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003782 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003783 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003784
3785 var RSL_IE_MS_Power ms_power;
3786 ms_power.reserved := 0;
3787 ms_power.fpc_epc := false;
3788 ms_power.power_level := ms_power_level;
3789
3790 f_l1_tune(L1CTL);
3791 RSL.clear;
3792
3793 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3794
3795 timer T := 1.0;
3796 T.start;
3797 alt {
3798 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003799 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3800 if (l1h.ms_power_lvl != ms_power_level) {
3801 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3802 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003803 }
3804 }
3805 /* Ignore all other blocks */
3806 [] L1CTL.receive { repeat; }
3807 [] T.timeout {
3808 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3809 }
3810 }
3811
3812 f_rsl_chan_deact();
3813 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3814 setverdict(pass);
3815}
3816
3817testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3818 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3819 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3820}
3821
Harald Welte0472ab42018-03-12 15:02:26 +01003822/* 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 +01003823private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003824 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003825 RSL.clear;
3826
3827 f_est_dchan();
3828 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003829 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003830
3831 timer T := 40.0;
3832 T.start;
3833 alt {
3834 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3835 setverdict(pass)
3836 }
3837 [] RSL.receive { repeat };
3838 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003840 }
3841 }
3842 f_rsl_chan_deact();
3843}
3844testcase TC_conn_fail_crit() runs on test_CT {
3845 var ConnHdlr vc_conn;
3846 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003847 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003848 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3849 pars.t_guard := 60.0;
3850 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3851 vc_conn.done;
3852}
3853
Harald Welte93640c62018-02-25 16:59:33 +01003854/***********************************************************************
3855 * Paging
3856 ***********************************************************************/
3857
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003858private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003859 if (tmsi == 'FFFFFFFF'O) {
3860 return true;
3861 } else {
3862 return false;
3863 }
3864}
Harald Welte70767382018-02-21 12:16:40 +01003865
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003866private type record allowedFn { integer frame_nr }
3867private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3868private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3869private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3870private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3871private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3872private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3873private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3874private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3875private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003876{
3877 var integer frame_nr_51;
3878 frame_nr_51 := frame_nr mod 51
3879
3880 var allowedFn fn_check;
3881 fn_check.frame_nr := frame_nr_51;
3882
3883 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003885 return;
3886 }
3887
3888 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3889 return;
3890 }
3891 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3892 return;
3893 }
3894 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3895 return;
3896 }
3897 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3898 return;
3899 }
3900 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3901 return;
3902 }
3903 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3904 return;
3905 }
3906 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3907 return;
3908 }
3909 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3910 return;
3911 }
3912
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003914 return;
3915}
3916
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003917private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3918 inout integer num_paging_rcv_ids,
3919 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003920runs on test_CT {
3921 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003922 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003923 repeat;
3924 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003925 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003926 var octetstring without_plen :=
3927 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3928 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003929
3930 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3931
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003932 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3933 /* Ignore empty RR Paging Request (PCH filling) messages.
3934 * TODO: does it make sense to count them? */
3935 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003936 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3937 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003938 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003939 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3940 }
3941 } else if (match(rr, tr_PAGING_REQ2)) {
3942 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3943 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3944 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3945 }
3946 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3947 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3948 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003949 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003950 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3951 }
3952 } else if (match(rr, tr_PAGING_REQ3)) {
3953 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3954 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3955 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3956 }
3957 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3958 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3959 }
3960 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3961 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3962 }
3963 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3964 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3965 }
3966 }
3967 repeat;
3968 }
3969}
3970
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003971private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003972 boolean combined_ccch,
3973 integer bs_ag_blks_res,
3974 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003975 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3976 * paging command that is issued via RSL. */
3977 integer ps_load_modulus,
3978 /* Wait until the paging queue inside the BTS is congested before starting to add
3979 * pagings via the PCU socket (0 = disabled) */
3980 boolean ps_wait_cong,
3981 /* Maximum time to wait until the paging queue is drained at the end of the test.
3982 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3983 * to set this value to 18s, however the draining process may take significantly
3984 * longer when the queue contains paging requests for PS as those are implemented
3985 * as immediate assignments and require an entire MAC block alone. */
3986 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003987 boolean exp_load_ind,
3988 boolean exp_overload,
3989 boolean use_tmsi
3990}
3991
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003992private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003993 integer num_paging_sent,
3994 integer num_paging_rcv_msgs,
3995 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003996 integer num_overload,
3997 /* When free space inside the paging queue reaches more than 2 thirds
3998 * of its capacity cong_detected is set to true. */
3999 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01004000}
4001
Harald Welte68e495b2018-02-25 00:05:57 +01004002/* Helper function for paging related testing */
4003private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02004004 /* Using the PCU socket affects the timing of the paging processing. We only
4005 * activate the PCU socket if we do paging load tests that include additional
4006 * paging load that is introduced through the PCU socket. */
4007 if (cfg.ps_load_modulus > 0) {
4008 f_init_with_pcuif();
4009 } else {
4010 f_init();
4011 }
Harald Welte68e495b2018-02-25 00:05:57 +01004012 f_init_l1ctl();
4013 f_l1_tune(L1CTL);
4014
Philipp Maierca058272021-06-23 10:35:23 +02004015 var octetstring imm_ass := f_rnd_octstring(23);
4016 var ASP_RSL_Unitdata load_ind;
4017
Harald Welte68e495b2018-02-25 00:05:57 +01004018 var PagingTestState st := {
4019 num_paging_sent := 0,
4020 num_paging_rcv_msgs := 0,
4021 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02004022 num_overload := 0,
4023 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01004024 };
4025
4026 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
4027 var float max_pch_imsi_per_sec;
4028 if (cfg.use_tmsi) {
4029 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
4030 } else {
4031 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
4032 }
4033 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
4034 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004035 var float time_total := 20.0;
4036 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
4037 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01004038
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004039 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
4040 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01004041
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004042 timer T_itv := 0.0;
4043 T_itv.start;
4044 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01004045 alt {
4046 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004047 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01004048 st.num_overload := st.num_overload + 1;
4049 repeat;
4050 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004051 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01004053 }
Philipp Maierca058272021-06-23 10:35:23 +02004054 [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 +01004055 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02004056
4057 /* Detect paging congestion: The logic inside the BTS will diagnose the
4058 * paging queue as congested when the fill state is more than 66% (which
4059 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
4060 * paging congestion is detected pagings that are issued through the PCU
4061 * socket (PS) are dropped in order to prefer the CS related pagings. */
4062 if (load_ind.rsl.ies[1].body.paging_load < 66) {
4063 st.cong_detected := true;
4064 }
4065
Harald Welte68e495b2018-02-25 00:05:57 +01004066 /* FIXME: analyze/verify interval + contents */
4067 repeat;
4068 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004069 /* ignore other RSL messages like RF RESource INDication */
4070 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004071 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02004072 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004073 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004074 /* Only relevant when testing including with PCU sock connected */
4075 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004076 [] T_itv.timeout {
4077 /* Send paging cmds based on elapsed time */
4078 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
4079 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004080 var MobileIdentityV mi;
4081
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004082 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004083 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004084 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004085 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004086 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004087 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004088
4089 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004090 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 +02004091
Philipp Maierca058272021-06-23 10:35:23 +02004092 /* Add additional pagings through the PCU socket interface. */
4093 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
4094 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
4095 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
4096 }
4097 }
4098
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004099 st.num_paging_sent := st.num_paging_sent + 1;
4100 }
4101 if (st.num_paging_sent < pkt_total) {
4102 /* Wait for interval to next PAGING COMMAND */
4103 var float time_now := T_total.read;
4104 var float next_sched := int2float(st.num_paging_sent)*interval;
4105 if (next_sched > time_now) {
4106 T_itv.start(next_sched - time_now);
4107 } else {
4108 T_itv.start(0.0);
4109 }
4110 } else {
4111 /* We are done, no need to keep counting */
4112 T_total.stop;
4113 }
4114 }
4115 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01004116 }
4117 }
4118
Philipp Maierca058272021-06-23 10:35:23 +02004119 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01004120 T_wait.start;
4121 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02004122 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01004123 [] L1CTL.receive { repeat; }
4124 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004125 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02004126 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02004127 /* ignore other RSL messages like RF RESource INDication */
4128 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02004129 /* Only relevant when testing including with PCU sock connected */
4130 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01004131 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02004132 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 +01004133 }
Harald Welte68e495b2018-02-25 00:05:57 +01004134 }
4135
4136 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
4137 " rcvd_ids=", st.num_paging_rcv_ids);
4138 return st;
4139}
4140
4141/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
4142 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4143 * - that CCCH LOAD IND (PCH) are being generated
4144 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4145testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004146 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004147 var PagingTestCfg cfg := {
4148 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004149 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004150 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004151 ps_load_modulus := 0,
4152 ps_wait_cong := false,
4153 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004154 exp_load_ind := true,
4155 exp_overload := false,
4156 use_tmsi := false
4157 };
4158 var PagingTestState st := f_TC_paging(cfg);
4159 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4161 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004162 } else {
4163 setverdict(pass);
4164 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004166}
4167
4168/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
4169 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
4170 * - that CCCH LOAD IND (PCH) are being generated
4171 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4172testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004173 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004174 var PagingTestCfg cfg := {
4175 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004176 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004177 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02004178 ps_load_modulus := 0,
4179 ps_wait_cong := false,
4180 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004181 exp_load_ind := true,
4182 exp_overload := false,
4183 use_tmsi := true
4184 };
4185 var PagingTestState st := f_TC_paging(cfg);
4186 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4188 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004189 } else {
4190 setverdict(pass);
4191 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004193}
4194
4195/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4196 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4197 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4198 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4199testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004200 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004201 var PagingTestCfg cfg := {
4202 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004203 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004204 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004205 ps_load_modulus := 0,
4206 ps_wait_cong := false,
4207 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004208 exp_load_ind := true,
4209 exp_overload := true,
4210 use_tmsi := false
4211 };
4212 var PagingTestState st := f_TC_paging(cfg);
4213 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4214 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004215 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004216 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004217 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 +01004218 } else {
4219 setverdict(pass);
4220 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004222}
4223
4224/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4225 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4226 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4227 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4228testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004229 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004230 var PagingTestCfg cfg := {
4231 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004232 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004233 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004234 ps_load_modulus := 0,
4235 ps_wait_cong := false,
4236 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004237 exp_load_ind := true,
4238 exp_overload := true,
4239 use_tmsi := true
4240 };
4241 var PagingTestState st := f_TC_paging(cfg);
4242 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4243 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004244 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004245 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004246 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 +01004247 } else {
4248 setverdict(pass);
4249 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004251}
4252
Philipp Maierca058272021-06-23 10:35:23 +02004253/* Same as above, but with additional paging load created by PS pagings that
4254 * are issued through the PCU socket. The additional load is introduced when
4255 * the paging queue is already two thirds full. Since the BTS implements a
4256 * prioritization logic that drops the pagings from the PCU under in those
4257 * congestive sitautions the behaviour on the PS side is expected to be
4258 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4259testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4260 var SystemInformation si3 := valueof(ts_SI3_default);
4261 var PagingTestCfg cfg := {
4262 combined_ccch := true,
4263 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4264 load_factor := 2.0,
4265 ps_load_modulus := 16,
4266 ps_wait_cong := true,
4267 queue_drain_timeout := 18.0,
4268 exp_load_ind := true,
4269 exp_overload := true,
4270 use_tmsi := false
4271 };
4272 var PagingTestState st := f_TC_paging(cfg);
4273 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4274 * slots and will fully drain that buffer before returning */
4275 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4276 if (not match(st.num_paging_rcv_ids, tpl)) {
4277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4278 } else {
4279 setverdict(pass);
4280 }
4281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4282}
4283
4284
Harald Welte68e495b2018-02-25 00:05:57 +01004285
Harald Welte93640c62018-02-25 16:59:33 +01004286/***********************************************************************
4287 * Immediate Assignment / AGCH
4288 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004289private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004290 len := 0,
4291 ma := ''B
4292}
Harald Welte93640c62018-02-25 16:59:33 +01004293
Harald Weltee8d750e2018-06-10 21:41:35 +02004294private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4295 return int2str(num_tx) & " sent, "
4296 & int2str(num_rx) & " received, "
4297 & int2str(num_del) & " deleted";
4298}
4299
4300private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4301 var L1ctlDlMessage l1_dl;
4302 timer T := 10.0;
4303 var integer num_tx := 0;
4304 var integer num_rx := 0;
4305 var integer num_del := 0;
4306 var charstring res_str;
4307 var float rx_ratio;
4308
Harald Welte10474062019-05-30 16:48:17 +02004309 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004310 f_init_l1ctl();
4311 f_l1_tune(L1CTL);
4312
4313 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004314 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004315 mp_trx_pars[0].arfcn,
4316 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004317 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4318 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004319 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004320 num_tx := num_tx+1;
4321 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004322 }
4323 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004324 T.start;
4325 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004326 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004327 num_del := num_del+1;
4328 repeat;
4329 }
4330 [] RSL_CCHAN.receive {
4331 repeat;
4332 }
4333 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004334 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4335 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4336 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004337 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004338 } else {
4339 num_rx := num_rx+1;
4340 }
4341 repeat;
4342 }
4343 [] L1CTL.receive { repeat; }
4344 [] T.timeout { }
4345 }
4346 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4347 log("AGCH test: " & res_str);
4348 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004350 }
4351 rx_ratio := int2float(num_rx) / int2float(num_tx);
4352 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004353 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 +02004354 } else {
4355 setverdict(pass);
4356 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004358}
4359
Harald Weltee8d750e2018-06-10 21:41:35 +02004360/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4361testcase TC_imm_ass_1000_20ms() runs on test_CT {
4362 f_TC_imm_ass(1000, 0.02, 0.25);
4363}
4364
4365/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4366testcase TC_imm_ass_200_0ms() runs on test_CT {
4367 f_TC_imm_ass(200, 0.0, 0.05);
4368}
4369
4370/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4371testcase TC_imm_ass_200_76ms() runs on test_CT {
4372 f_TC_imm_ass(150, 0.076, 1.00);
4373}
4374
4375
4376
Harald Welte48494ca2018-02-25 16:59:50 +01004377/***********************************************************************
4378 * BCCH
4379 ***********************************************************************/
4380
4381/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004382private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004383 GsmFrameNumber frame_number,
4384 SystemInformation si
4385}
4386
4387/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004388private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004389
4390/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004391private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004392
4393/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004394private function f_si_vecslot_contains(SystemInformationVector arr,
4395 RrMessageType key,
4396 boolean bcch_ext := false)
4397return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004398 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4399 var integer fn_mod51 := arr[i].frame_number mod 51;
4400 if (not bcch_ext and fn_mod51 == 2 or
4401 bcch_ext and fn_mod51 == 6) {
4402 if (arr[i].si.header.message_type == key) {
4403 return true;
4404 }
4405 }
4406 }
4407 return false;
4408}
4409
4410/* 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 +07004411private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4412 integer tc, RrMessageType key,
4413 boolean ext_bcch := false)
4414{
Harald Welte48494ca2018-02-25 16:59:50 +01004415 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004417 }
4418}
4419
4420/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004421private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4422 RrMessageType key)
4423return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004424 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4425 if (f_si_vecslot_contains(arr[tc], key) or
4426 f_si_vecslot_contains(arr[tc], key, true)) {
4427 return true;
4428 }
4429 }
4430 return false;
4431}
4432
4433/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004434private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4435 RrMessageType key,
4436 boolean bcch_ext := false,
4437 integer n := 1, integer m := 4)
4438return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004439 var integer count := 0;
4440 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4442 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004443 }
4444 for (var integer i:= 0; i < m; i := i + 1) {
4445 var integer fn_mod51 := arr[i].frame_number mod 51;
4446 if (not bcch_ext and fn_mod51 == 2 or
4447 bcch_ext and fn_mod51 == 6) {
4448 if (arr[i].si.header.message_type == key) {
4449 count := count + 1;
4450 }
4451 }
4452 }
4453 if (count >= n) {
4454 return true;
4455 } else {
4456 return false;
4457 }
4458}
4459
4460/* 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 +07004461private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4462 integer tc, RrMessageType key,
4463 boolean ext_bcch := false,
4464 integer n, integer m)
4465{
Harald Welte48494ca2018-02-25 16:59:50 +01004466 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004468 }
4469}
4470
4471/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004472private function f_si_vecslot_contains_only(SystemInformationVector arr,
4473 RrMessageType key,
4474 boolean bcch_ext := false)
4475return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004476 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4477 var integer fn_mod51 := arr[i].frame_number mod 51;
4478 if (not bcch_ext and fn_mod51 == 2 or
4479 bcch_ext and fn_mod51 == 6) {
4480 if (arr[i].si.header.message_type != key) {
4481 return false;
4482 }
4483 }
4484 }
4485 return true;
4486}
4487
4488/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004489private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4490 integer tc, RrMessageType key,
4491 boolean ext_bcch := false)
4492{
Harald Welte48494ca2018-02-25 16:59:50 +01004493 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004495 }
4496}
4497
4498/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004499private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004500 boolean bcch_extended,
4501 boolean si1_present,
4502 boolean si2bis_present,
4503 boolean si2ter_present,
4504 boolean si2quater_present,
4505 boolean si7_present,
4506 boolean si8_present,
4507 boolean si9_present,
4508 boolean si13_present,
4509 boolean si13alt_present,
4510 boolean si15_present,
4511 boolean si16_present,
4512 boolean si17_present,
4513 boolean si2n_present,
4514 boolean si21_present,
4515 boolean si22_present
4516}
4517
4518/* 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 +07004519private function f_validate_si_scheduling(SystemInformationConfig cfg,
4520 SystemInformationVectorPerTc si_per_tc)
4521{
Harald Welte48494ca2018-02-25 16:59:50 +01004522 var integer i;
4523 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4524 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004526 }
4527 }
4528 if (cfg.si1_present) {
4529 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4530 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4531 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4532 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4533 /* make sure *ALL* contain SI1 */
4534 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4535 }
4536 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4537 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4538 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4539 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4540 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4541 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4542
4543 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4544 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4545 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4546 * consecutive occurrences of TC = 4. */
4547 if (cfg.si2bis_present and not cfg.si2ter_present) {
4548 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4549 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4550 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4551 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4552 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4553 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4554 }
4555
4556 if (cfg.si7_present or cfg.si8_present) {
4557 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4558 * if System Information type 4 does not contain all information needed for cell
4559 * selection and reselection. */
4560 if (not cfg.bcch_extended) {
4561 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4562 }
4563 if (cfg.si7_present) {
4564 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4565 }
4566 if (cfg.si8_present) {
4567 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4568 }
4569 }
4570
4571 if (cfg.si2quater_present) {
4572 /* iii) System information type 2 quater is sent if needed, as determined by the system
4573 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4574 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4575 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4576 * within any of 4 consecutive occurrences of TC = 5. */
4577 if (not (cfg.bcch_extended)) {
4578 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4579 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4580 } else {
4581 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4582 }
4583 } else {
4584 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4585 }
4586 }
4587 if (cfg.si9_present) {
4588 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4589 * in system information type 3 as defined in 3GPP TS 44.018. */
4590 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4591 }
4592 if (cfg.si13_present) {
4593 /* vii) System Information type 13 is only related to the GPRS service. System Information
4594 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4595 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4596 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4597 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4598 * within any of 4 consecutive occurrences of TC=4. */
4599 if (not cfg.bcch_extended) {
4600 log("not-bccch-extended");
4601 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4602 } else {
4603 log("bccch-extended");
4604 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4605 }
4606 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004608 }
4609 }
4610 if (cfg.si16_present or cfg.si17_present) {
4611 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4612 * should not be sent in a cell where network sharing is used (see rule xv). */
4613 if (cfg.si22_present) {
4614 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4615 }
4616 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004618 }
4619 if (not cfg.bcch_extended) {
4620 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4621 }
4622 if (cfg.si16_present) {
4623 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4624 }
4625 if (cfg.si17_present) {
4626 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4627 }
4628 }
4629
4630 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4631 * broadcast information. The frequency with which they are sent is determined by the
4632 * system operator. System Information type 9 identifies the scheduling of System
4633 * Information type 18 and 20 messages. */
4634
4635 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4636 * Information Type 19 is present, then its scheduling shall be indicated in System
4637 * Information Type 9. */
4638
4639 if (cfg.si15_present) {
4640 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4641 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4642 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4643 * 4 consecutive occurrences of TC = 1. */
4644 if (not cfg.bcch_extended) {
4645 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4646 } else {
4647 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4648 }
4649 }
4650 if (cfg.si13alt_present) {
4651 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4652 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4653 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4654 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4655 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4656 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4657 * of TC = 4. */
4658 if (cfg.si13_present) {
4659 testcase.stop("Error: Cannot have SI13alt and SI13");
4660 }
4661 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004663 }
4664 if (not cfg.bcch_extended) {
4665 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4666 } else {
4667 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4668 }
4669 }
4670 if (cfg.si2n_present) {
4671 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4672 * as determined by the system operator. In the case that the message is sent on the
4673 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4674 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4675 * consecutive occurrences of TC = 4. */
4676 if (not cfg.bcch_extended) {
4677 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4678 } else {
4679 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4680 }
4681 }
4682 if (cfg.si21_present) {
4683 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4684 * determined by the system operator. If Extended Access Barring is in use in the cell
4685 * then this message is sent at least once within any of 4 consecutive occurrences of
4686 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4687 * cell then this message shall only be sent on BCCH Ext. */
4688 if (not cfg.bcch_extended) {
4689 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4690 } else {
4691 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4692 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004694 }
4695 }
4696 }
4697 if (cfg.si22_present) {
4698 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4699 * should not be sent in a cell where SoLSA is used (see rule viii). System
4700 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4701 * =2 and TC=6. */
4702 if (cfg.si16_present or cfg.si17_present) {
4703 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4704 }
4705 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4706 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004708 }
4709 if (not cfg.bcch_extended) {
4710 testcase.stop("Error: SI22 requires BCCH Extd!");
4711 } else {
4712 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4713 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4714 }
4715 }
4716}
4717
4718/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004719private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4720return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004721 timer T := duration;
4722 var SystemInformationVectorPerTc si_per_tc;
4723 var L1ctlDlMessage l1_dl;
4724
4725 /* initialize all per-TC vectors empty */
4726 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4727 si_per_tc[i] := {};
4728 }
4729
4730 /* flush all previous L1 queued msgs */
4731 pt.clear;
4732
4733 T.start;
4734 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004735 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004736 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4737 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4738 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004739 repeat;
4740 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004741
Harald Welte48494ca2018-02-25 16:59:50 +01004742 var integer tc := f_gsm_compute_tc(sig.frame_number);
4743 log("SI received at TC=", tc, ": ", sig.si);
4744 /* append to the per-TC bucket */
4745 si_per_tc[tc] := si_per_tc[tc] & { sig };
4746 repeat;
4747 }
4748 [] pt.receive { repeat; }
4749 [] T.timeout { }
4750 }
4751
4752 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4753 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4754 }
4755 log("si_per_tc=", si_per_tc);
4756 return si_per_tc;
4757}
4758
4759/* helper function: Set given SI via RSL + validate scheduling.
4760 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004761private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004762 var SystemInformationVectorPerTc si_per_tc;
4763 f_init_l1ctl();
4764 f_l1_tune(L1CTL);
4765
4766 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004767 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004768 f_validate_si_scheduling(si_cfg, si_per_tc);
4769
4770 setverdict(pass);
4771}
4772
4773testcase TC_si_sched_default() runs on test_CT {
4774 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004775 /* 2+3+4 are mandatory and set in f_init() */
4776 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004778}
4779
4780testcase TC_si_sched_1() runs on test_CT {
4781 f_init();
4782 si_cfg.si1_present := true;
4783 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004784 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004786}
4787
4788testcase TC_si_sched_2bis() runs on test_CT {
4789 f_init();
4790 si_cfg.si2bis_present := true;
4791 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4792 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004794}
4795
4796testcase TC_si_sched_2ter() runs on test_CT {
4797 f_init();
4798 si_cfg.si2ter_present := true;
4799 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4800 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004802}
4803
4804testcase TC_si_sched_2ter_2bis() runs on test_CT {
4805 f_init();
4806 si_cfg.si2bis_present := true;
4807 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4808 si_cfg.si2ter_present := true;
4809 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4810 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004812}
4813
4814testcase TC_si_sched_2quater() runs on test_CT {
4815 f_init();
4816 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004817 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004818 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004820}
4821
4822testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004823 /* NOTE: PCUIF connection is not used in this test case, but
4824 * without it the IUT would not broadcast SI13 (see OS#3075). */
4825 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004826 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004827 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004828 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004830}
4831
4832testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004833 /* NOTE: PCUIF connection is not used in this test case, but
4834 * without it the IUT would not broadcast SI13 (see OS#3075). */
4835 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004836 si_cfg.si2bis_present := true;
4837 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4838 si_cfg.si2ter_present := true;
4839 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4840 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004841 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004842 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004843 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004844 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004846}
4847
4848
Harald Welte68e495b2018-02-25 00:05:57 +01004849testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004850 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004851 /* FIXME: enable / disable individual BCCH info */
4852 //ts_RSL_BCCH_INFO(si_type, info);
4853 /* expect no ERROR REPORT after either of them *
4854 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004856}
4857
Harald Welte93640c62018-02-25 16:59:33 +01004858/***********************************************************************
4859 * Low-Level Protocol Errors / ERROR REPORT
4860 ***********************************************************************/
4861
Harald Welte01d982c2018-02-25 01:31:40 +01004862private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4863 timer T := 5.0;
4864 T.start;
4865 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004866 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004867 setverdict(pass);
4868 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004869 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004871 }
4872 [] RSL_CCHAN.receive {
4873 repeat;
4874 }
4875 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004877 }
4878 }
4879}
4880
4881/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4882testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004883 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004884 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4885 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004886 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004887
4888 f_exp_err_rep(RSL_ERR_PROTO);
4889}
4890
4891/* Provoke a mandatory IE error and match on ERROR REPORT */
4892testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004893 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004894
4895 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4896 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004897 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004898
4899 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4900}
4901
4902/* Provoke an IE content error and match on ERROR REPORT */
4903testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004904 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004905 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4906 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004907 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004908
4909 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4910}
4911
Harald Welteee25aae2019-05-19 14:32:37 +02004912/* attempt to activate channel with wrong RSL Message Discriminator IE */
4913function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4914 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4915 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4916 RSL.send(rsl);
4917 f_rslem_unregister(0, g_chan_nr);
4918}
4919testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4920 var ConnHdlr vc_conn;
4921 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4922
Harald Welte10474062019-05-30 16:48:17 +02004923 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004924
4925 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4926 vc_conn.done;
4927 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4928
4929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4930}
4931
4932/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004933private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004934 var template (value) RSL_Message rsl_tx;
4935 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4936 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4937 RSL.send(rsl_tx);
4938 f_rslem_unregister(0, g_chan_nr);
4939}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004940private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004941 var template (value) RSL_Message rsl_tx;
4942 /* we first have to activate the dedicated channel */
4943 f_rsl_chan_act(g_pars.chan_mode);
4944 /* ... to then send an invalid RLL message */
4945 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4946 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4947 RSL.send(rsl_tx);
4948 f_rslem_unregister(0, g_chan_nr);
4949}
4950testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4951 var ConnHdlr vc_conn;
4952 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4953 var template (value) RSL_Message rsl_tx;
4954
Harald Welte10474062019-05-30 16:48:17 +02004955 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004956
4957 /* Common Channel with wrong message type */
4958 RSL_CCHAN.clear;
4959 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4960 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004961 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004962 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4963
4964 /* TRX Management */
4965 RSL_CCHAN.clear;
4966 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4967 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004968 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004969 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4970
4971 /* Dedicated Channel */
4972 RSL_CCHAN.clear;
4973 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4974 vc_conn.done;
4975 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4976
4977 /* RLL */
4978 RSL_CCHAN.clear;
4979 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4980 vc_conn.done;
4981 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4982}
4983
4984/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004985private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004986 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4987 f_rslem_unregister(0, g_chan_nr);
4988}
4989testcase TC_err_rep_wrong_sequence() runs on test_CT {
4990 var ConnHdlr vc_conn;
4991 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4992
Harald Welte10474062019-05-30 16:48:17 +02004993 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004994
4995 RSL_CCHAN.clear;
4996 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4997 vc_conn.done;
4998 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4999}
5000
Harald Welte93640c62018-02-25 16:59:33 +01005001/***********************************************************************
5002 * IPA CRCX/MDCX/DLCS media stream handling
5003 ***********************************************************************/
5004
Harald Weltea871a382018-02-25 02:03:14 +01005005/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005006private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01005007 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5008 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01005009}
5010testcase TC_ipa_dlcx_not_active() runs on test_CT {
5011 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005012 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01005013 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
5014 vc_conn.done;
5015}
Harald Welte68e495b2018-02-25 00:05:57 +01005016
Harald Weltea3f1df92018-02-25 12:49:55 +01005017/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005018private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01005019 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5020 "IPA CRCX ACK");
5021 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
5022 "IPA CRCX NACK");
5023}
5024testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
5025 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005026 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01005027 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
5028 vc_conn.done;
5029}
5030
5031/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005032private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01005033 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5034 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005035 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01005036 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5037 var uint7_t rtp_pt2 := f_rnd_int(127);
5038 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5039 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5040 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5041 "IPA MDCX ACK");
5042 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5043 "IPA DLCX ACK");
5044}
5045testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
5046 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005047 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01005048 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
5049 vc_conn.done;
5050}
5051
Harald Welte3ae11da2018-02-25 13:36:06 +01005052/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005053private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01005054 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5055 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005056 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005057 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
5058 var uint7_t rtp_pt2 := f_rnd_int(127);
5059 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
5060 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5061 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5062 "IPA MDCX ACK");
5063 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02005064 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01005065 remote_port := f_rnd_int(c_UINT16_MAX);
5066 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
5067 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
5068 "IPA MDCX ACK");
5069 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5070 "IPA DLCX ACK");
5071}
5072testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
5073 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02005074 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01005075 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
5076 vc_conn.done;
5077}
5078
Harald Welte9912eb52018-02-25 13:30:15 +01005079/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005080private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01005081 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
5082 "IPA CRCX NACK");
5083}
5084testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
5085 var ConnHdlrPars pars;
5086 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005087 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01005088
5089 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
5090 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5091 vc_conn.done;
5092
5093 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
5094 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
5095 vc_conn.done;
5096}
5097
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03005098/* Make sure that CRCX ACK contains a valid listen address (see OS#5242) */
5099private function f_TC_ipa_crcx_ack_addr(charstring id) runs on ConnHdlr {
5100 var OCT4 bind_ip := f_inet_addr("192.168.1.1");
5101 var PortNumber bind_port := 16811;
5102 var RSL_Message crcx_ack;
5103
5104 crcx_ack := f_rsl_transceive_ret(ts_RSL_IPA_CRCX(g_chan_nr, bind_ip, bind_port),
5105 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
5106 "IPA CRCX ACK");
5107 var HostName bts_bind_ip := f_inet_ntoa(crcx_ack.ies[2].body.ipa_local_ip);
5108 if (match(bts_bind_ip, "0.0.0.0")) {
5109 setverdict(fail, "CRCX ACK indicates nonsense addr ", bts_bind_ip);
5110 }
5111
5112 var uint16_t conn_id := crcx_ack.ies[1].body.ipa_conn_id;
5113 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, conn_id),
5114 tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
5115 "IPA DLCX ACK");
5116}
5117testcase TC_ipa_crcx_ack_addr() runs on test_CT {
5118 var ConnHdlrPars pars;
5119 var ConnHdlr vc_conn;
5120 f_init();
5121
5122 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
5123 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5124 vc_conn.done;
5125
5126 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
5127 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_ack_addr), pars);
5128 vc_conn.done;
5129}
5130
Harald Weltea3f1df92018-02-25 12:49:55 +01005131
Harald Welte883340c2018-02-28 18:59:29 +01005132/***********************************************************************
5133 * PCU Socket related tests
5134 ***********************************************************************/
5135
Harald Welte07bd2d22019-05-25 11:03:30 +02005136/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005137friend 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 +01005138runs on test_CT {
5139 timer T := 3.0;
5140
5141 /* we don't expect any RTS.req before PDCH are active */
5142 T.start;
5143 alt {
5144 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01005146 }
5147 [] PCU.receive { repeat; }
5148 [] T.timeout { }
5149 }
5150
5151 /* Send PDCH activate request for known PDCH timeslot */
5152 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
5153
5154 /* we now expect RTS.req for this timeslot (only) */
5155 T.start;
5156 alt {
5157 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
5158 setverdict(pass);
5159 }
5160 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5161 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01005163 }
5164 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01005166 }
5167 [] PCU.receive { repeat; }
5168 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005170 }
5171 [not exp_success] T.timeout {
5172 setverdict(pass);
5173 }
5174 }
5175}
5176
Harald Welte07bd2d22019-05-25 11:03:30 +02005177/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02005178friend 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 +01005179runs on test_CT {
5180 timer T := 3.0;
5181
5182 /* Send PDCH activate request for known PDCH timeslot */
5183 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 +02005184 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
5185 * when it will actually have been executed in the BTS */
5186 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01005187 PCU.clear;
5188 /* we now expect no RTS.req for this timeslot */
5189 T.start;
5190 alt {
5191 [] 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 +02005192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01005193 }
5194 [] PCU.receive { repeat; }
5195 [] T.timeout {
5196 setverdict(pass);
5197 }
5198 }
5199}
5200
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005201friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005202 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005203 map(self:PCU, system:PCU);
5204 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01005205 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
5206}
5207
Harald Welte883340c2018-02-28 18:59:29 +01005208/* PDCH activation via PCU socket; check for presence of RTS.req */
5209testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005210 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005211
Harald Welte883340c2018-02-28 18:59:29 +01005212 f_TC_pcu_act_req(0, 0, 7, true);
5213}
5214
5215/* PDCH activation via PCU socket on non-PDCU timeslot */
5216testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005217 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005218
Harald Welte883340c2018-02-28 18:59:29 +01005219 f_TC_pcu_act_req(0, 0, 1, false);
5220}
5221
5222/* PDCH activation via PCU socket on wrong BTS */
5223testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005224 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005225
Harald Welte883340c2018-02-28 18:59:29 +01005226 f_TC_pcu_act_req(23, 0, 7, false);
5227}
5228
5229/* PDCH activation via PCU socket on wrong TRX */
5230testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005231 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005232
Harald Welte883340c2018-02-28 18:59:29 +01005233 f_TC_pcu_act_req(0, 23, 7, false);
5234}
5235
5236/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5237testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005238 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005239
Harald Welte883340c2018-02-28 18:59:29 +01005240 /* Activate PDCH */
5241 f_TC_pcu_act_req(0, 0, 7, true);
5242 f_sleep(1.0);
5243 /* and De-Activate again */
5244 f_TC_pcu_deact_req(0, 0, 7);
5245}
5246
5247/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5248testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005249 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005250
Harald Welte883340c2018-02-28 18:59:29 +01005251 f_TC_pcu_deact_req(0, 0, 1);
5252}
5253
5254/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005255function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005256 var PCUIF_send_data sd;
5257 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005258 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005259
5260 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005261 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005262
Harald Welte883340c2018-02-28 18:59:29 +01005263 T.start;
5264 alt {
5265 [] 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 +01005266 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005267 setverdict(pass);
5268 } else {
5269 repeat;
5270 }
5271 }
5272 [] PCU.receive { repeat; }
5273 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005275 }
5276 }
5277}
5278
Philipp Maier94c08482021-02-01 17:36:05 +01005279/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5280testcase TC_pcu_ver_si1() runs on test_CT {
5281 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5282 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5283}
5284
5285/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5286testcase TC_pcu_ver_si3() runs on test_CT {
5287 const octetstring si3 := '49012223242526272929AABBCC'O;
5288 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5289}
5290
5291/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5292testcase TC_pcu_ver_si13() runs on test_CT {
5293 const octetstring si13 := '01010203040506070909'O;
5294 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5295}
5296
Harald Welte883340c2018-02-28 18:59:29 +01005297private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5298
5299/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005300friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005301 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5302runs on test_CT
5303{
5304 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5305 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5306}
5307
5308/* 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 +02005309friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5310 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005311runs on test_CT
5312{
5313 var PCUIF_send_data sd;
5314
5315 timer T := 3.0;
5316 T.start;
5317 alt {
5318 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5319 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5320 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5321 sd.data.u.rts_req.fn, sapi, data);
5322 }
5323 [] PCU.receive { repeat; }
5324 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005326 }
5327 }
5328}
5329
5330/* Send DATA.req on invalid BTS */
5331testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005332 var TfiUsfArr tua := f_TfiUsfArrInit();
5333 var octetstring data := '0000'O & f_rnd_octstring(21);
5334
5335 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005336
Harald Welte883340c2018-02-28 18:59:29 +01005337 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005338 f_TfiUsfArrSet(tua, 7, 0);
5339 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5340 f_sleep(1.0);
5341
5342 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005343}
5344
5345/* Send DATA.req on invalid TRX */
5346testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005347 var TfiUsfArr tua := f_TfiUsfArrInit();
5348 var octetstring data := '0000'O & f_rnd_octstring(21);
5349
5350 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005351
Harald Welte883340c2018-02-28 18:59:29 +01005352 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005353 f_TfiUsfArrSet(tua, 7, 0);
5354 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5355 f_sleep(1.0);
5356
5357 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005358}
5359
5360/* Send DATA.req on invalid timeslot */
5361testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005362 var TfiUsfArr tua := f_TfiUsfArrInit();
5363 var octetstring data := '0000'O & f_rnd_octstring(21);
5364
5365 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005366
Harald Welte883340c2018-02-28 18:59:29 +01005367 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005368 f_TfiUsfArrSet(tua, 7, 0);
5369 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5370 f_sleep(1.0);
5371
5372 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005373}
5374
5375/* Send DATA.req on timeslot that hasn't been activated */
5376testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005377 var TfiUsfArr tua := f_TfiUsfArrInit();
5378 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005379
Harald Welte7162a612019-05-26 12:56:09 +02005380 f_virtphy_common();
5381
5382 f_TfiUsfArrSet(tua, 7, 0);
5383 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5384 f_sleep(1.0);
5385
5386 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005387}
5388
Harald Weltead033dc2019-05-25 17:28:16 +02005389private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005390 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5391 boolean wait_rts := true)
5392runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005393 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005394 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005395
5396 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005397 if (wait_rts) {
5398 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5399 } else {
5400 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5401 }
Harald Weltead033dc2019-05-25 17:28:16 +02005402
5403 T.start;
5404 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005405 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005406 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5407 setverdict(pass);
5408 }
Harald Welte7162a612019-05-26 12:56:09 +02005409 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5410 setverdict(fail, "Received unexpected ", rx_dl);
5411 }
Harald Weltead033dc2019-05-25 17:28:16 +02005412 [] L1CTL.receive {
5413 repeat;
5414 }
Harald Welte7162a612019-05-26 12:56:09 +02005415 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005416 setverdict(fail, "Timeout waiting for ", data);
5417 }
Harald Welte7162a612019-05-26 12:56:09 +02005418 [not expect_data] T.timeout {
5419 setverdict(pass);
5420 }
Harald Weltead033dc2019-05-25 17:28:16 +02005421 }
5422}
5423
5424private function f_disable_dynamic_ts() runs on test_CT
5425{
5426 f_init_vty_bsc();
5427 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5428 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5429 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5430 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005431 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005432}
5433
5434private function f_virtphy_common() runs on test_CT {
5435 f_disable_dynamic_ts();
5436 f_init_l1ctl();
5437 f_l1_tune(L1CTL);
5438}
5439
5440testcase TC_pcu_data_req_pdtch() runs on test_CT {
5441 var TfiUsfArr tua := f_TfiUsfArrInit();
5442 var octetstring data := '0000'O & f_rnd_octstring(21);
5443
5444 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005445
Harald Welte883340c2018-02-28 18:59:29 +01005446 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005447 f_TfiUsfArrSet(tua, 7, 0);
5448 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5449 f_sleep(1.0);
5450
5451 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005452}
5453
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005454/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005455testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005456 var TfiUsfArr tua := f_TfiUsfArrInit();
5457 var octetstring data := '0000'O & f_rnd_octstring(21);
5458
5459 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005460
Harald Welte883340c2018-02-28 18:59:29 +01005461 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005462 f_TfiUsfArrSet(tua, 7, 0);
5463 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5464 f_sleep(1.0);
5465
5466 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005467}
5468
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005469private function f_TC_pcu_ptcch_ul(uint16_t ra)
5470runs on test_CT {
5471 var template PCUIF_Message pcu_rach_ind;
5472 var PCUIF_send_data sd;
5473 var GsmFrameNumber fn;
5474 timer T;
5475
5476 /* Send an Access Burst on PTCCH/U over the Um-interface */
5477 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5478 chan_nr := ts_RslChanNr_PDCH(7),
5479 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5480
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005481 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5482 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005483
5484 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5485 T.start(52.0 * 4.615 / 1000.0);
5486 alt {
5487 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5488 log("Rx an Access Burst on the PCU interface: ", sd.data);
5489 setverdict(pass);
5490 T.stop;
5491 }
5492 [] PCU.receive { repeat; }
5493 [] T.timeout {
5494 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5495 /* Keep going, that's not the end of the world */
5496 }
5497 }
5498}
5499
5500testcase TC_pcu_ptcch() runs on test_CT {
5501 var L1ctlDlMessage dl;
5502 var octetstring data;
5503 timer T;
5504
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005505 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005506 f_init_l1ctl();
5507 f_l1_tune(L1CTL);
5508
5509 /* Activate PDCH channel on TS7 */
5510 f_TC_pcu_act_req(0, 0, 7, true);
5511
5512 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005513 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005514 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005515 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005516 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005517
5518 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5519 for (var integer i := 0; i < 16; i := i + 1) {
5520 log("Sending an Access Burst towards the L1CTL interface");
5521 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5522 }
5523
5524 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5525 data := f_rnd_octstring(23);
5526
5527 /* Verify PTCCH/D: send a random data block, make sure it's received */
5528 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5529 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5530
5531 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5532 * let's give it more time in case if we miss the beginning. */
5533 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5534 alt {
5535 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5536 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5537 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5538 frame := data)) -> value dl {
5539 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5540 setverdict(pass);
5541 T.stop;
5542 }
5543 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5544 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5545 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5546 l2_data := data)) -> value dl {
5547 log("Rx PTCCH/D data block on L1CTL: ", dl);
5548 setverdict(pass);
5549 T.stop;
5550 }
5551 [] L1CTL.receive { repeat; }
5552 [] T.timeout {
5553 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5554 }
5555 }
5556}
5557
Harald Welte883340c2018-02-28 18:59:29 +01005558/* Send AGCH from PCU; check it appears on Um side */
5559testcase TC_pcu_data_req_agch() runs on test_CT {
5560 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005561 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005562 f_init_l1ctl();
5563 f_l1_tune(L1CTL);
5564
5565 f_TC_pcu_act_req(0, 0, 7, true);
5566 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5567
5568 T.start;
5569 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005570 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005571 setverdict(pass);
5572 }
5573 [] L1CTL.receive { repeat; }
5574 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005576 }
5577 }
5578}
5579
Harald Welte928622b2019-05-26 13:22:59 +02005580/* Send AGCH from PCU; check it appears on Um side */
5581testcase TC_pcu_data_req_pch() runs on test_CT {
5582 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005583 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005584 f_init_l1ctl();
5585 f_l1_tune(L1CTL);
5586
5587 f_TC_pcu_act_req(0, 0, 7, true);
5588 /* three characters prefix: last 3 digits of IMSI as ASCII */
5589 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5590
5591 T.start;
5592 alt {
5593 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5594 setverdict(pass);
5595 }
5596 [] L1CTL.receive { repeat; }
5597 [] T.timeout {
5598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5599 }
5600 }
5601}
5602
Harald Welte883340c2018-02-28 18:59:29 +01005603/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5604testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5605 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005606 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005607 f_init_l1ctl();
5608 f_l1_tune(L1CTL);
5609
5610 /* append 3 last imsi digits so BTS can compute pagng group */
5611 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5612
5613 timer T := 0.5;
5614 T.start;
5615 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005616 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005617 /* TODO: verify paging group */
5618 setverdict(pass);
5619 }
5620 [] L1CTL.receive { repeat; }
5621 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005623 }
5624 }
5625}
5626
5627/* Send RACH from Um side, expect it to show up on PCU socket */
5628testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005629 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005630 f_init_l1ctl();
5631 f_l1_tune(L1CTL);
5632
5633 var GsmFrameNumber fn_last := 0;
5634 for (var integer i := 0; i < 1000; i := i+1) {
5635 var OCT1 ra := f_rnd_ra_ps();
5636 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5637 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005639 }
5640 fn_last := fn;
5641
5642 timer T := 2.0;
5643 T.start;
5644 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005645 [] 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 +01005646 T.stop;
5647 }
5648 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005650 }
5651 [] PCU.receive { repeat; }
5652 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005654 }
5655 }
5656 }
5657 setverdict(pass);
5658}
5659
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005660/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5661 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5662testcase TC_pcu_ext_rach_content() runs on test_CT {
5663 var template PCUIF_Message pcu_rach_ind;
5664 var GsmFrameNumber fn_last := 0;
5665 var L1ctlRachSynchSeq synch_seq;
5666 var PCUIF_BurstType pcu_bt;
5667 var GsmFrameNumber fn;
5668 var BIT11 ra11;
5669
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005670 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005671 f_init_l1ctl();
5672 f_l1_tune(L1CTL);
5673
5674 for (var integer i := 0; i < 1000; i := i+1) {
5675 /* We need to test both TS1 & TS2 */
5676 if (i rem 2 == 0) {
5677 synch_seq := RACH_SYNCH_SEQ_TS1;
5678 pcu_bt := BURST_TYPE_1;
5679 } else {
5680 synch_seq := RACH_SYNCH_SEQ_TS2;
5681 pcu_bt := BURST_TYPE_2;
5682 }
5683
5684 ra11 := f_rnd_ra11_ps();
5685 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5686 if (fn == fn_last) {
5687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5688 "Two RACH in same FN?!?");
5689 }
5690 fn_last := fn;
5691
5692 /* Compose the expected message */
5693 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005694 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005695 ra := bit2int(ra11),
5696 is_11bit := 1,
5697 burst_type := pcu_bt,
5698 fn := fn);
5699
5700 timer T := 2.0;
5701 T.start;
5702 alt {
5703 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5704 T.stop;
5705 }
5706 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5708 }
5709 [] PCU.receive { repeat; }
5710 [] T.timeout {
5711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5712 }
5713 }
5714 }
5715 setverdict(pass);
5716}
5717
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005718private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5719runs on test_CT {
5720 var template PCUIF_send_data sdt;
5721 var PCUIF_send_data sd;
5722 var int16_t lqual_cb;
5723 timer T := 1.0;
5724
5725 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5726 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5727
5728 /* Send a random PDTCH frame over Um */
5729 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5730 '0000'O & f_rnd_octstring(21)));
5731
5732 T.start;
5733 alt {
5734 /* If expected link quality is above the threshold */
5735 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5736 lqual_cb := sd.data.u.data_ind.lqual_cb;
5737 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5738
5739 /* Make sure the actual link quality matches the expected value */
5740 if (not match(lqual_cb, lqual_cb_exp)) {
5741 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5742 "expected value ", lqual_cb_exp));
5743 } else {
5744 setverdict(pass);
5745 }
5746 }
5747 /* If expected link quality is below the threshold */
5748 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5750 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5751 }
5752 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5753 [] PCU.receive { repeat; }
5754 [lqual_cb_exp < thresh] T.timeout {
5755 log("Rx nothing, as expected");
5756 setverdict(pass);
5757 }
5758 [lqual_cb_exp >= thresh] T.timeout {
5759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5760 "Timeout waiting for PCUIF_DATA.ind");
5761 }
5762 }
5763}
5764
5765/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5766testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005767 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005768 PCU.clear;
5769
5770 f_init_l1ctl();
5771 f_l1_tune(L1CTL);
5772
5773 /* Activate a PDCH channel on TS7 */
5774 f_TC_pcu_act_req(0, 0, 7, true);
5775
5776 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005777 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005778 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005779 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005780 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005781
5782 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5783 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5784 var TrxcMessage ret;
5785
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005786 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005787
5788 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5789 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5790 }
5791}
5792
Harald Welte883340c2018-02-28 18:59:29 +01005793/* Send PAGING via RSL, expect it to shw up on PCU socket */
5794testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005795 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005796
5797 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005798 var MobileIdentityLV mi_lv;
5799 var octetstring mi_lv_enc;
5800 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005801 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005802
Harald Welte883340c2018-02-28 18:59:29 +01005803 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005804 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005805 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005806 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005807 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005808
5809 /* Fancy encoding for PCUIF */
5810 mi_lv := valueof(ts_MI_LV(mi));
5811 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5812 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005813
5814 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005815 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005816 T.start;
5817 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005818 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005819 }
5820 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005822 }
5823 [] PCU.receive { repeat; }
5824 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005826 }
5827 }
5828 }
5829 setverdict(pass);
5830}
5831
Harald Welted66c9b82019-05-25 09:03:15 +02005832/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5833testcase TC_pcu_time_ind() runs on test_CT {
5834 var PCUIF_send_data pcu_sd;
5835 var integer num_time_ind := 0;
5836 var integer first_fn, last_fn;
5837 var float test_duration := 5.0;
5838 timer T;
5839
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005840 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005841 f_TC_pcu_act_req(0, 0, 7, true);
5842
5843 PCU.clear;
5844 T.start(test_duration);
5845 alt {
5846 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5847 num_time_ind := num_time_ind + 1;
5848 if (not isbound(first_fn)) {
5849 first_fn := pcu_sd.data.u.time_ind.fn;
5850 }
5851 last_fn := pcu_sd.data.u.time_ind.fn;
5852 repeat;
5853 }
5854 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5855 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5856 repeat;
5857 }
5858 [] PCU.receive {
5859 repeat;
5860 }
5861 [] T.timeout {}
5862 }
5863 var integer fn_expired := last_fn - first_fn;
5864 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5865
5866 /* verify the number of frames expired matches our expectation */
5867 const float c_GSM_FN_DURATION_MS := 4.61538;
5868 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005869 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005870 if (not match(fn_expired, t_fn_expected)) {
5871 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5872 }
5873
5874 /* There are three TIME.ind in every fn MOD 13 */
5875 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5876 /* Add some tolerance */
5877 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5878 if (not match(num_time_ind, t_time_ind_exp)) {
5879 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5880 }
5881
5882 setverdict(pass);
5883}
5884
Harald Welte4832c862019-05-25 14:57:18 +02005885/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5886testcase TC_pcu_rts_req() runs on test_CT {
5887 var PCUIF_send_data pcu_sd;
5888 var integer first_fn, last_fn;
5889 var integer num_rts_pdtch := 0;
5890 var integer num_rts_ptcch := 0;
5891 var float test_duration := 5.0;
5892 timer T;
5893
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005894 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005895 f_TC_pcu_act_req(0, 0, 7, true);
5896
5897 PCU.clear;
5898 T.start(test_duration);
5899 alt {
5900 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5901 -> value pcu_sd {
5902 num_rts_pdtch := num_rts_pdtch + 1;
5903 if (not isbound(first_fn)) {
5904 first_fn := pcu_sd.data.u.rts_req.fn;
5905 }
5906 last_fn := pcu_sd.data.u.rts_req.fn;
5907 repeat;
5908 }
5909 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5910 -> value pcu_sd {
5911 num_rts_ptcch := num_rts_ptcch + 1;
5912 if (not isbound(first_fn)) {
5913 first_fn := pcu_sd.data.u.rts_req.fn;
5914 }
5915 last_fn := pcu_sd.data.u.rts_req.fn;
5916 repeat;
5917 }
5918 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5919 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5920 repeat;
5921 }
5922 [] PCU.receive {
5923 repeat;
5924 }
5925 [] T.timeout {}
5926 }
5927 var integer fn_expired := last_fn - first_fn;
5928 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5929 ", num_rts_ptcch=", num_rts_ptcch);
5930
5931 /* verify the number of frames expired matches our expectation */
5932 const float c_GSM_FN_DURATION_MS := 4.61538;
5933 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005934 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005935 if (not match(fn_expired, t_fn_expected)) {
5936 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5937 }
5938
5939 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5940 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5941 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5942 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5943 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5944 t_ptcch_exp);
5945 }
5946
5947 /* We have 12 PDTCH blocks every 52-multiframe */
5948 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5949 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5950 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5951 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5952 t_pdtch_exp);
5953 }
5954
5955 setverdict(pass);
5956}
5957
Harald Welte07bd2d22019-05-25 11:03:30 +02005958/* test for generating Abis side OML ALERT from the PCU */
5959testcase TC_pcu_oml_alert() runs on test_CT {
5960 var PCUIF_send_data pcu_sd;
5961 var integer num_time_ind := 0;
5962 var integer first_fn, last_fn;
5963 var float test_duration := 5.0;
5964 timer T;
5965
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005966 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005967 f_TC_pcu_act_req(0, 0, 7, true);
5968
5969 /* re-connect CTRL port from BTS to BSC */
5970 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005971 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005972
5973 /* Send that OML Alert */
5974 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5975
5976 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5977 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5978 setverdict(pass);
5979}
5980
Harald Welteeaa9a862019-05-26 23:01:08 +02005981/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5982private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5983 var PCUIF_Message first_info;
5984 var integer pcu_conn_id := -1;
5985 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5986 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5987 var OCT4 tlli := '01020304'O;
5988 var OCT1 cause := '23'O;
5989 timer T := 5.0;
5990
5991 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5992
5993 f_l1_tune(L1CTL);
5994 RSL.clear;
5995
5996 f_est_dchan();
5997 L1CTL.clear;
5998
5999 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6000
6001 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
6002 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
6003 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
6004
6005 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
6006 T.start;
6007 alt {
6008 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
6009 setverdict(pass);
6010 }
6011 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
6012 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
6013 }
6014 [] PCU.receive {
6015 repeat;
6016 }
6017 [] T.timeout {
6018 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
6019 }
6020 }
Alexander Couzensa0634832019-06-07 00:28:56 +02006021
6022 /* release the channel */
6023 f_rsl_chan_deact();
6024 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6025 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02006026}
6027testcase TC_pcu_rr_suspend() runs on test_CT {
6028 var ConnHdlrPars pars;
6029 var ConnHdlr vc_conn;
6030
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006031 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02006032
6033 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
6034 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
6035 vc_conn.done;
6036}
Harald Welte07bd2d22019-05-25 11:03:30 +02006037
Harald Weltea2e0e942019-05-27 18:12:53 +02006038/* Ensure that PCUIF socket can accept only a single connection */
6039testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006040 var boolean connected := false;
6041 var UD_connect_result cr;
6042 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02006043 timer T := 5.0;
6044
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006045 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
6046 var template UD_Result tr_err := { result_code := ERROR, err := ? };
6047
Harald Weltea2e0e942019-05-27 18:12:53 +02006048 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006049 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02006050
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006051 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02006052 PCU.send(UD_connect:{mp_pcu_socket, -1});
6053 T.start;
6054 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006055 /* the IUT will first accept() the new connection, and close() it immediately */
6056 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
6057 log("BTS has accept()ed connection");
6058 connected := true;
6059 cid := cr.id;
6060 repeat;
6061 }
6062 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
6063 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02006064 setverdict(pass);
6065 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006066 /* ignore other messages related to the first connection */
6067 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02006068 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006069 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02006070 }
6071 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01006072
Harald Weltea2e0e942019-05-27 18:12:53 +02006073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6074}
6075
Harald Weltec8effb72019-05-27 18:23:04 +02006076/* Ensure that PCUIF socket can disconnect + reconnect */
6077testcase TC_pcu_socket_reconnect() runs on test_CT {
6078 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006079 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02006080
6081 f_sleep(1.0);
6082
6083 f_pcuif_close(PCU, g_pcu_conn_id);
6084 g_pcu_conn_id := -1;
6085
6086 f_sleep(1.0);
6087
6088 /* re-connect */
6089 PCU.clear;
6090 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6091 setverdict(pass);
6092
6093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6094}
6095
Harald Weltebe030482019-05-27 22:29:35 +02006096/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006097private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
6098runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02006099 var L1ctlDlMessage l1_dl;
6100 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006101 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02006102 timer T := 5.0;
6103 T.start;
6104 alt {
6105 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07006106 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
6107 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02006108 repeat;
6109 }
6110 }
6111 [] pt.receive {
6112 repeat;
6113 }
6114 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6116 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02006117 }
6118 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07006119 return si;
Harald Weltebe030482019-05-27 22:29:35 +02006120}
6121
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006122/* Check if GPRS Indicator is present in RR System Information of a given type */
6123private function f_si_has_gprs_indicator(RrMessageType si_type)
6124runs on test_CT return boolean {
6125 var SystemInformation si := f_get_si(L1CTL, si_type);
6126
6127 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006128 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006129 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02006130 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006131 }
6132
6133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
6134 return false;
Harald Weltebe030482019-05-27 22:29:35 +02006135}
6136
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006137/* Make sure that GPRS Indicator is absent when the PCU is not connected */
6138private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
6139runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006140 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02006141 f_init_l1ctl();
6142 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02006143 f_sleep(2.0);
6144 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006145
6146 if (f_si_has_gprs_indicator(si_type)) {
6147 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006148 } else {
6149 setverdict(pass);
6150 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006151
Harald Weltebe030482019-05-27 22:29:35 +02006152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6153}
6154
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006155testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
6156 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
6157}
Harald Weltebe030482019-05-27 22:29:35 +02006158
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006159testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
6160 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
6161}
6162
6163/* Ensure that GPRS capability is advertised after PCU socket connect */
6164private function f_TC_pcu_socket_connect(RrMessageType si_type)
6165runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006166 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006167 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006168 f_init_l1ctl();
6169 f_l1_tune(L1CTL);
6170
6171 f_sleep(2.0);
6172 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006173
6174 if (not f_si_has_gprs_indicator(si_type)) {
6175 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02006176 } else {
6177 setverdict(pass);
6178 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006179
Harald Weltebe030482019-05-27 22:29:35 +02006180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6181}
6182
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006183testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
6184 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
6185}
Harald Weltebe030482019-05-27 22:29:35 +02006186
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006187testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
6188 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
6189}
6190
6191/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
6192private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
6193runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02006194 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006195 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02006196 f_init_l1ctl();
6197 f_l1_tune(L1CTL);
6198
6199 f_pcuif_close(PCU, g_pcu_conn_id);
6200 g_pcu_conn_id := -1;
6201
6202 f_sleep(1.0);
6203
6204 /* re-connect */
6205 PCU.clear;
6206 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
6207
6208 f_sleep(2.0);
6209 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006210
6211 if (f_si_has_gprs_indicator(si_type)) {
6212 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02006213 } else {
6214 setverdict(pass);
6215 }
6216
6217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6218}
6219
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006220testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6221 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6222}
6223
6224testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6225 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6226}
6227
Oliver Smithf5239c72019-08-28 10:01:25 +02006228/* 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) */
6229testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6230 var SystemInformation si3 := valueof(ts_SI3_default);
6231
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006232 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006233
Harald Welte76220222020-10-11 20:32:44 +02006234 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6235 * information */
6236 timer T := 2.0;
6237 T.start;
6238 alt {
6239 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6240 [] T.timeout {}
6241 }
6242
Oliver Smithf5239c72019-08-28 10:01:25 +02006243 /* Verify cell_id */
6244 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6245 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6246 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006247 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6248 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6249 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006250 }
6251
6252 /* Verify LAC */
6253 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6254 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6255 if (lac_si3 != lac_pcu) {
6256 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6257 }
6258
6259 setverdict(pass);
6260}
Harald Welted66c9b82019-05-25 09:03:15 +02006261
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006262/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6263testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6264 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006265 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006266
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006267 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006268
6269 info_ind := g_pcu_last_info.u.info_ind;
6270
6271 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6272 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006273 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006274 /* Skip inactive timeslots */
6275 continue;
6276 }
6277
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006278 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006279 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006280 else
6281 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006282
6283 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006284 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006285 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006286 hsn := fhp.maio_hsn.hsn,
6287 maio := fhp.maio_hsn.maio,
6288 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006289 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006290 } else {
6291 tr_ts := tr_PCUIF_InfoTrxTsH0;
6292 }
6293
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006294 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006295 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6296 if (not match(ts, tr_ts)) {
6297 setverdict(fail, "Hopping parameters do not match: ",
6298 "received ", ts, " vs expected ", tr_ts);
6299 } else {
6300 setverdict(pass);
6301 }
6302 }
6303 }
6304}
6305
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006306/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006307testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6308 f_init_vty_bsc();
6309 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6310 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6311
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006312 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006313
6314 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006315 var template PCUIF_RemoteAddr tr_remote_addr := {
6316 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006317 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006318 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006319
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006320 if (not match(remote_addr, tr_remote_addr)) {
6321 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006322 }
6323
6324 setverdict(pass);
6325}
6326
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006327/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006328testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6329 f_init_vty_bsc();
6330 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6331
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006332 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006333
6334 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006335 var template PCUIF_RemoteAddr tr_remote_addr := {
6336 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6337 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6338 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006339
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006340 if (not match(remote_addr, tr_remote_addr)) {
6341 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006342 }
6343
6344 setverdict(pass);
6345}
6346
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006347/* Verify coding of two NSVCs in the INFO.ind message */
6348testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6349 f_init_vty_bsc();
6350
6351 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6352 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6353 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6354 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6355
6356 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6357 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6358 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6359 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6360
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006361 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006362
6363 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6364 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6365 var template PCUIF_RemoteAddr tr_remote_addr := {
6366 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006367 addr := {
6368 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6369 f_inet6_addr("fd00::ca:ff:ee")
6370 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006371 };
6372
6373 if (not match(info_ind.nsvci, { 1234, 5678 }))
6374 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6375 if (not match(remote_addr, tr_remote_addr))
6376 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6377 if (not match(info_ind.local_port, { 1234, 5678 }))
6378 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6379 if (not match(info_ind.remote_port, { 1234, 5678 }))
6380 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6381
6382 setverdict(pass);
6383}
6384
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006385/* Verify periodic interference reports on PDCH */
6386testcase TC_pcu_interf_ind() runs on test_CT {
6387 var template PCUIF_Message tr_interf_ind;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006388 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006389 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006390 var PCUIF_send_data sd;
6391 timer T;
6392
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006393 /* Set the averaging/reporting period to 480ms */
6394 f_init_vty_bsc();
6395 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6396 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6397
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006398 f_init_with_pcuif();
6399 f_TC_pcu_act_req(0, 0, 7, true);
6400
6401 /* We need trxcon for NOPE indications */
6402 f_init_l1ctl();
6403 f_l1_tune(L1CTL);
6404
6405 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006406 tr_interf_ind := tr_PCUIF_INTERF_IND(
6407 bts_nr := 0,
6408 trx_nr := 0,
6409 fn := ?,
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03006410 interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) }
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006411 );
6412
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006413 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006414 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006415 /* The first interference report may contain unreliable values, so we ignore it */
6416 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6417 /* 4 SACCH periods => 4 reports (plus some guard time) */
6418 T.start(0.480 * 4.0 + 0.480 / 2.0);
6419 first := false;
6420 repeat;
6421 }
6422 /* Subsequent interference reports shall match our expectations */
6423 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006424 /* Check TDMA frame number period */
6425 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6426 setverdict(fail, "Odd TDMA frame number := ",
6427 sd.data.u.interf_ind.fn);
6428 }
6429 interf_ind_num := interf_ind_num + 1;
6430 if (interf_ind_num < 4)
6431 { repeat; }
6432 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006433 [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 +02006434 setverdict(fail, "Received unexpected interference report: ", sd.data);
6435 }
6436 [] PCU.receive { repeat; }
6437 [] T.timeout {
6438 setverdict(fail, "Timeout waiting for interference reports");
6439 }
6440 }
6441
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006442 /* Reset the averaging/reporting period back to default */
6443 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6444
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6446}
6447
Harald Welte3d04ae62018-04-04 20:29:05 +02006448/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006449 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006450 ***********************************************************************/
6451
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006452private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6453 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006454runs on ConnHdlr {
6455 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006456
6457 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006458 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006459 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6460 repeat;
6461 }
6462 }
6463}
6464
6465private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6466runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006467 /* Expect BTS to immediately acknowledge activation as PDCH */
6468 PCU.clear;
6469 f_rsl_chan_act(g_pars.chan_mode);
6470 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006471 timer T_wait := 2.0;
6472 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006473 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006474 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006475 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006476 [] T_wait.timeout {
6477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6478 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6479 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006480 }
6481 /* try to activate this PDCH from the PCU point of view */
6482 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6483 /* FIXME: is there a response? */
6484}
6485
6486private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6487runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006488 /* Send RSL CHAN REL (deactivate) */
6489 PCU.clear;
6490 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6491 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006492 timer T_wait := 2.0;
6493 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006494 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006495 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006496 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006497 [] T_wait.timeout {
6498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6499 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6500 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006501 }
6502 /* Emulate PCU asking BTS to deactivate PDCH */
6503 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6504 alt {
6505 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6506 setverdict(pass);
6507 }
6508 [] RSL.receive { repeat; }
6509 }
6510}
6511
6512/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006513private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006514 var PCUIF_Message first_info;
6515 var integer ts_nr := g_chan_nr.tn;
6516 var integer trx_nr := 0;
6517 var integer bts_nr := 0;
6518 var integer pcu_conn_id := -1;
6519
6520 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6521
6522 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6523 f_sleep(3.0);
6524 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6525 setverdict(pass);
6526}
6527testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6528 var ConnHdlrPars pars;
6529 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006530 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006531
6532 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6533 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6534 vc_conn.done;
6535}
6536
6537/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006538private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006539 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006540 var integer pcu_conn_id := -1;
6541
6542 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6543
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006544 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6545 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6546 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006547 setverdict(pass);
6548}
6549testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6550 var ConnHdlrPars pars;
6551 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006552 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006553
6554 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6555 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6556 vc_conn.done;
6557}
6558
6559/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006560private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006561 var PCUIF_Message first_info;
6562 var integer ts_nr := g_chan_nr.tn;
6563 var integer trx_nr := 0;
6564 var integer bts_nr := 0;
6565 var integer pcu_conn_id := -1;
6566
6567 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6568
6569 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006570 /* Send a second Chan Activ and expect it to be NACKed */
6571 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6572 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006573 setverdict(pass);
6574}
6575testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6576 var ConnHdlrPars pars;
6577 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006578 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006579
6580 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6581 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6582 vc_conn.done;
6583}
6584
6585/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006586private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006587 var PCUIF_Message first_info;
6588 var integer ts_nr := g_chan_nr.tn;
6589 var integer trx_nr := 0;
6590 var integer bts_nr := 0;
6591 var integer pcu_conn_id := -1;
6592 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6593
6594 /* register for the TCH/F channel number */
6595 f_rslem_register(0, chan_nr);
6596
6597 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6598
6599 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6600 "RSL CHAN ACT");
6601 setverdict(pass);
6602}
6603testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6604 var ConnHdlrPars pars;
6605 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006606 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006607
6608 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6609 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6610 vc_conn.done;
6611}
6612
6613/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006614private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006615 var PCUIF_Message first_info;
6616 var integer ts_nr := g_chan_nr.tn;
6617 var integer trx_nr := 0;
6618 var integer bts_nr := 0;
6619 var integer pcu_conn_id := -1;
6620 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6621 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6622
6623 /* register for the TCH/H channel numbers */
6624 f_rslem_register(0, chan_nr[0]);
6625 f_rslem_register(0, chan_nr[1]);
6626
6627 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6628
6629 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6630 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6631 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6632 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6633 setverdict(pass);
6634}
6635testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6636 var ConnHdlrPars pars;
6637 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006638 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006639
6640 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6641 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6642 vc_conn.done;
6643}
6644
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006645/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6646private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6647 var PCUIF_Message first_info;
6648 var integer ts_nr := g_chan_nr.tn;
6649 var integer trx_nr := 0;
6650 var integer bts_nr := 0;
6651 var integer pcu_conn_id := -1;
6652 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6653 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6654 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6655 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6656 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6657 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6658 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6659 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6660
6661 /* register for the TCH/H channel numbers */
6662 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6663 f_rslem_register(0, chan_nr[i]);
6664 }
6665
6666 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6667
6668 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6669 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6670 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6671 }
6672 setverdict(pass);
6673}
6674testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6675 var ConnHdlrPars pars;
6676 var ConnHdlr vc_conn;
6677 f_init();
6678
6679 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6680 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6681 vc_conn.done;
6682}
6683
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006684/* Reproduce a race condition described in OS#5245 */
6685private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6686 f_rsl_chan_act(g_pars.chan_mode);
6687 f_sleep(1.0);
6688 f_rsl_chan_deact();
6689 setverdict(pass);
6690}
6691testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6692 var ConnHdlrPars pars[2];
6693 var ConnHdlr vc_conn[2];
6694 var TrxcMessage rsp;
6695
6696 f_init();
6697
6698 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6699 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6700 ts_TRXC_FAKE_TRXC_DELAY(200));
6701
6702 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6703 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6704 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6705 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6706 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6707 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6708 pars[i], l1ctl := false);
6709 }
6710
6711 /* Wait for all components to finish */
6712 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6713 vc_conn[i].done;
6714 }
6715
6716 /* Disable the artificial delay for TRXC RSP messages */
6717 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6718 ts_TRXC_FAKE_TRXC_DELAY(0));
6719}
6720testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6721 var ConnHdlrPars pars[8];
6722 var ConnHdlr vc_conn[8];
6723 var TrxcMessage rsp;
6724
6725 f_init();
6726
6727 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6728 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6729 ts_TRXC_FAKE_TRXC_DELAY(200));
6730
6731 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6732 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6733 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6734 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6735 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6736 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6737 pars[i], l1ctl := false);
6738 }
6739
6740 /* Wait for all components to finish */
6741 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6742 vc_conn[i].done;
6743 }
6744
6745 /* Disable the artificial delay for TRXC RSP messages */
6746 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6747 ts_TRXC_FAKE_TRXC_DELAY(0));
6748}
6749
Harald Welte9bbbfb52018-04-05 09:33:19 +02006750/***********************************************************************
6751 * IPA Style Dynamic Timeslot Support
6752 ***********************************************************************/
6753
6754private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6755runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006756 /* Expect BTS to immediately acknowledge activation as PDCH */
6757 PCU.clear;
6758 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6759 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006760 timer T_wait := 2.0;
6761 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006762 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006763 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006764 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006765 [] T_wait.timeout {
6766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6767 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6768 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006769 }
6770 /* try to activate this PDCH from the PCU point of view */
6771 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6772 /* FIXME: is there a response? */
6773
6774 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6775}
6776
6777private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6778runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006779 /* Send RSL CHAN REL (deactivate) */
6780 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6781 PCU.clear;
6782 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006783 timer T_wait := 2.0;
6784 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006785 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006786 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006787 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006788 [] T_wait.timeout {
6789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6790 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6791 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006792 }
6793 /* Emulate PCU asking BTS to deactivate PDCH */
6794 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6795 alt {
6796 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6797 setverdict(pass);
6798 }
6799 [] RSL.receive { repeat; }
6800 }
6801}
6802
6803/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006804private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006805 var PCUIF_Message first_info;
6806 var integer ts_nr := g_chan_nr.tn;
6807 var integer trx_nr := 0;
6808 var integer bts_nr := 0;
6809 var integer pcu_conn_id := -1;
6810
6811 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6812
6813 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6814 f_sleep(3.0);
6815 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6816
6817 setverdict(pass);
6818
6819}
6820testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6821 var ConnHdlrPars pars;
6822 var ConnHdlr vc_conn;
6823 f_init();
6824
6825 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6826 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6827 vc_conn.done;
6828}
6829
6830/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006831private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006832 var PCUIF_Message first_info;
6833 var integer ts_nr := g_chan_nr.tn;
6834 var integer trx_nr := 0;
6835 var integer bts_nr := 0;
6836 var integer pcu_conn_id := -1;
6837
6838 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6839
6840 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6841 "RSL CHAN ACT");
6842 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6843 "RF CHAN REL", true);
6844 setverdict(pass);
6845}
6846testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6847 var ConnHdlrPars pars;
6848 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006849 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006850
6851 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6852 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6853 vc_conn.done;
6854}
6855
6856/* 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 +07006857private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006858 var PCUIF_Message first_info;
6859 var integer ts_nr := g_chan_nr.tn;
6860 var integer trx_nr := 0;
6861 var integer bts_nr := 0;
6862 var integer pcu_conn_id := -1;
6863
6864 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6865
6866 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6867 "RSL CHAN ACT");
6868
6869 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6870 alt {
6871 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6872 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006874 }
6875 [] RSL.receive { repeat; }
6876 }
6877
6878 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6879 "RF CHAN REL", true);
6880 setverdict(pass);
6881}
6882testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6883 var ConnHdlrPars pars;
6884 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006885 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006886
6887 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6888 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6889 vc_conn.done;
6890}
6891
6892/* 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 +07006893private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006894 var PCUIF_Message first_info;
6895 var integer ts_nr := g_chan_nr.tn;
6896 var integer trx_nr := 0;
6897 var integer bts_nr := 0;
6898 var integer pcu_conn_id := -1;
6899
6900 /* register for the TCH/F channel number */
6901 f_rslem_register(0, g_chan_nr);
6902
6903 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6904
6905 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6906
6907 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6908 "RSL CHAN ACT");
6909
6910 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6911
6912 setverdict(pass);
6913}
6914testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6915 var ConnHdlrPars pars;
6916 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006917 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006918
6919 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6920 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6921 vc_conn.done;
6922}
6923
6924
Harald Welte0472ab42018-03-12 15:02:26 +01006925/***********************************************************************
6926 * LAPDm / RLL related
6927 ***********************************************************************/
6928
6929private function f_tx_lapdm(template (value) LapdmFrame l,
6930 template (value) RslLinkId link_id) runs on ConnHdlr {
6931 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006932 var template (value) SacchL1Header l1h;
6933
6934 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006935 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006936 /* Compose dummy L1 header */
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +07006937 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, g_pars.l1_pars.ms_actual_ta);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006938 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 +02006939 } else {
6940 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006941 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 +01006942 }
Harald Welte0472ab42018-03-12 15:02:26 +01006943}
6944
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006945friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006946 uint3_t sapi,
6947 RslLinkId link_id,
6948 octetstring l3,
6949 boolean exp
6950}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006951friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006952friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6953 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006954 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006955 sapi := sapi,
6956 link_id := id,
6957 l3 := l3,
6958 exp := exp
6959}
6960
6961/* execute the same callback function with a set of different parameters (tcs) on a
6962 * variety of logical channels */
6963private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6964 var ConnHdlrPars pars;
6965 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006966 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006967
6968 /* test on each of the channels we have */
6969 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6970 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6971
6972 /* test each of the test cases on the current channel */
6973 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6974 pars.spec.rll := tcs[j];
6975 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6976 vc_conn := f_start_handler(fn, pars);
6977 vc_conn.done;
6978 }
6979 }
6980
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006982}
6983
6984/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6985private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6986 var RllTestCase tc := g_pars.spec.rll;
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 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6997 T.start;
6998 alt {
6999 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
7000 if (tc.exp) {
7001 setverdict(pass);
7002 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01007004 }
7005 }
7006 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
7007 if (tc.exp) {
7008 setverdict(pass);
7009 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01007011 }
7012 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007013 /* We also expect to receive the measurements */
7014 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007015 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007017 }
7018 [not tc.exp] T.timeout {
7019 setverdict(pass);
7020 }
7021 }
7022
7023 f_rsl_chan_deact();
7024 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7025 f_rslem_unregister(0, g_chan_nr);
7026}
7027testcase TC_rll_est_ind() runs on test_CT {
7028 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02007029 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007030 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02007031 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007032 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007033 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007034 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
7035 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01007036 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007037 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01007038 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007039 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007040 };
7041 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
7042}
7043
7044/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
7045private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
7046 var RllTestCase tc := g_pars.spec.rll;
7047 var L1ctlDlMessage dl;
7048 timer T := 3.0;
7049
7050 f_l1_tune(L1CTL);
7051 RSL.clear;
7052
7053 /* activate the logical channel */
7054 f_est_dchan();
7055 L1CTL.clear;
7056
7057 /* Send a RSL EST REQ for SAPI3 on main DCCH */
7058 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
7059 T.start;
7060 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02007061 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01007062 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01007064 }
7065 }
7066
7067 f_rsl_chan_deact();
7068 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7069 f_rslem_unregister(0, g_chan_nr);
7070}
7071testcase TC_rll_est_req_DCCH_3() runs on test_CT {
7072 var RllTestCases tcs := {
7073 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007074 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01007075 };
7076 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7077}
7078testcase TC_rll_est_req_ACCH_3() runs on test_CT {
7079 var RllTestCases tcs := {
7080 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007081 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007082 }
7083 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
7084}
7085
7086/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02007087friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01007088 var L1ctlDlMessage dl;
7089 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
7090 var LapdmFrame lapdm;
7091 var octetstring l2 := dl.payload.data_ind.payload;
7092 if (dl.dl_info.link_id.c == SACCH) {
7093 /* remove L1 header */
7094 l2 := substr(l2, 2, lengthof(l2)-2);
7095 }
7096 if (ischosen(exp.ab)) {
7097 lapdm.ab := dec_LapdmFrameAB(l2);
7098 } else if (ischosen(exp.b4)) {
7099 lapdm.b4 := dec_LapdmFrameB4(l2);
7100 } else if (ischosen(exp.bbis)) {
7101 lapdm.bbis := dec_LapdmFrameBbis(l2);
7102 }
7103 log("Rx LAPDm ", lapdm);
7104 if (match(lapdm, exp)) {
7105 setverdict(pass);
7106 } else {
7107 repeat;
7108 }
7109 }
7110 [] L1CTL.receive { repeat; }
7111}
7112private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
7113 timer T := t;
7114 T.start;
7115 alt {
7116 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01007118 }
7119 [] as_l1_exp_lapdm(exp);
7120 }
7121}
7122
7123/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
7124private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007125 timer T := 2.0;
Harald Welte0472ab42018-03-12 15:02:26 +01007126 /* send SABM from MS -> BTS */
7127 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
7128 /* expect RLL EST IND on Abis */
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007129 T.start;
Harald Welte0472ab42018-03-12 15:02:26 +01007130 alt {
7131 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
7132 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
7133 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01007135 }
7136 [] RSL.receive { repeat; }
Vadim Yanitskiy25341352022-07-25 06:13:12 +07007137 [] T.timeout {
7138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RLL EST IND");
7139 }
Harald Welte0472ab42018-03-12 15:02:26 +01007140 }
7141 /* expect UA from BTS -> MS */
7142 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
7143}
7144
7145/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
7146private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
7147 var RllTestCase tc := g_pars.spec.rll;
7148
7149 f_l1_tune(L1CTL);
7150 RSL.clear;
7151
7152 /* activate the logical channel */
7153 f_est_dchan();
7154 L1CTL.clear;
7155
7156 /* first establish the link-layer */
7157 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7158
7159 /* then send the DISC */
7160 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
7161 /* ... and expect the REL IND on the RSL side */
7162 alt {
7163 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
7164 setverdict(pass);
7165 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07007166 /* We also expect to receive the measurements */
7167 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01007168 }
7169
7170 /* release the channel */
7171 f_rsl_chan_deact();
7172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7173 f_rslem_unregister(0, g_chan_nr);
7174}
7175testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
7176 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007177 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007178 };
7179 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7180}
7181
7182testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
7183 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007184 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007185 };
7186 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7187}
7188testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
7189 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007190 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007191 };
7192 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7193}
7194testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
7195 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007196 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007197 };
7198 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
7199}
7200
7201/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
7202private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
7203 var RllTestCase tc := g_pars.spec.rll;
7204 f_l1_tune(L1CTL);
7205 RSL.clear;
7206
7207 /* activate the logical channel */
7208 f_est_dchan();
7209 L1CTL.clear;
7210
7211 /* first establish the link-layer */
7212 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
7213
7214 /* then send the REL REQ via RSL */
7215 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
7216 /* ... and expect the DISC on the Um side */
7217 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02007218 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01007219 /* FIXME: send a UA in resposne to the DISC */
7220 }
7221 }
7222
7223 /* release the channel */
7224 f_rsl_chan_deact();
7225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7226 f_rslem_unregister(0, g_chan_nr);
7227}
7228testcase TC_rll_rel_req() runs on test_CT {
7229 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007230 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7231 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7232 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7233 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007234 };
7235 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7236}
7237
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007238/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007239testcase TC_rll_data_req() runs on test_CT {
7240}
7241
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007242/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007243testcase TC_rll_data_ind() runs on test_CT {
7244}
7245
7246/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7247private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7248 var RllTestCase tc := g_pars.spec.rll;
7249
7250 f_l1_tune(L1CTL);
7251 RSL.clear;
7252
7253 f_est_dchan();
7254 L1CTL.clear;
7255
7256 /* Send UNITDATA REQ on RSL side */
7257 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7258 /* Expect it to arrive on the other side */
7259 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007260 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007261 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007262 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007263 }
7264
7265 /* release the channel */
7266 f_rsl_chan_deact();
7267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7268 f_rslem_unregister(0, g_chan_nr);
7269}
7270testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7271 var octetstring l3 := f_rnd_octstring(15);
7272 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007273 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7274 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007275 };
7276 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7277}
7278testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7279 var octetstring l3 := f_rnd_octstring(19);
7280 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007281 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7282 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007283 };
7284 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7285}
7286
7287/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7288private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7289 var RllTestCase tc := g_pars.spec.rll;
7290
7291 f_l1_tune(L1CTL);
7292 RSL.clear;
7293
7294 f_est_dchan();
7295 L1CTL.clear;
7296
7297 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007298 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007299 /* Expdct RLL UNITDATA IND on RSL side */
7300 alt {
7301 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7302 setverdict(pass);
7303 }
7304 [] RSL.receive { repeat; }
7305 }
7306
7307 /* release the channel */
7308 f_rsl_chan_deact();
7309 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7310 f_rslem_unregister(0, g_chan_nr);
7311}
7312testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007313 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007314 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007315 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7316 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007317 };
7318 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7319}
7320testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7321 var octetstring l3 := f_rnd_octstring(18);
7322 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007323 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7324 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007325 };
7326 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7327}
7328
Harald Weltee613f962018-04-18 22:38:16 +02007329/***********************************************************************
7330 * Encryption Related
7331 ***********************************************************************/
7332
7333/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007334private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007335 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7336 if (link_id.c == SACCH) {
7337 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7338 } else {
7339 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7340 }
7341}
7342
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007343/* Expect (or not expect) other kinds of messages */
7344private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7345 [exp_any] RSL.receive { repeat; }
7346 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007348 }
7349}
7350
Harald Weltee613f962018-04-18 22:38:16 +02007351/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007352private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007353 RslLinkId link_id,
7354 octetstring l3,
7355 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007356 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007357) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007358 timer T := 3.0;
7359 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7360 T.start;
7361 /* Expect RLL UNITDATA IND on RSL side */
7362 alt {
7363 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7364 setverdict(pass);
7365 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007366 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007367 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007368 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007370 }
Harald Weltee613f962018-04-18 22:38:16 +02007371 }
7372}
7373
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007374/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7375private function f_data_mo(
7376 RslLinkId link_id,
7377 boolean p, uint3_t nr, uint3_t ns,
7378 octetstring l3,
7379 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007380 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007381) runs on ConnHdlr {
7382 timer T := 3.0;
7383 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7384 T.start;
7385 /* Expect RLL DATA IND on RSL side */
7386 alt {
7387 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7388 setverdict(pass);
7389 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007390 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007391 [] as_rsl_any_ind(exp_any);
7392 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007394 }
7395 }
7396}
7397
Harald Weltee613f962018-04-18 22:38:16 +02007398/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007399private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007400 f_l1_tune(L1CTL);
7401 f_est_dchan(true);
7402
7403 /* now we actually need to transmit some data both ways to check if the encryption works */
7404 var L1ctlDlMessage dl;
7405
Stefan Sperling603d98e2018-07-25 16:47:28 +02007406 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007407 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7408
7409 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7410 f_unitdata_mt(link_id, l3);
7411
7412 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7413 f_unitdata_mo(link_id, l3);
7414
7415 /* release the channel */
7416 f_rsl_chan_deact();
7417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7418 f_rslem_unregister(0, g_chan_nr);
7419}
7420testcase TC_chan_act_a51() runs on test_CT {
7421 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7422 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7423 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7424}
7425testcase TC_chan_act_a52() runs on test_CT {
7426 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7427 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7428 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7429}
7430testcase TC_chan_act_a53() runs on test_CT {
7431 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7432 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7433 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7434}
Eric Wildb9260392021-05-15 19:48:22 +02007435testcase TC_chan_act_a54() runs on test_CT {
7436 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7437 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7438 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7439}
Harald Weltee613f962018-04-18 22:38:16 +02007440
Eric Wildf1827a72019-05-28 17:37:35 +02007441/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7442 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 +07007443private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007444 f_l1_tune(L1CTL);
7445 f_est_dchan(true);
7446
7447 /* now we actually need to transmit some data both ways to check if the encryption works */
7448 var L1ctlDlMessage dl;
7449
7450 var octetstring l3 := f_rnd_octstring(20);
7451 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7452
7453 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7454 f_unitdata_mt(link_id, l3);
7455
7456 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7457 f_unitdata_mo(link_id, l3);
7458
7459 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007460 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007461
7462 /* modify key to break proper encryption */
7463 g_pars.encr.key := f_rnd_octstring(8);
7464 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7465 rsl.ies := rsl.ies & { ei };
7466 RSL.send(rsl);
7467
7468 timer T0 := 1.0;
7469 T0.start;
7470 /* Expect RSL MODIFY ACK */
7471 alt {
7472 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7473 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7475 }
7476 [] T0.timeout {
7477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7478 }
7479 }
7480
7481 var octetstring l3msg := f_rnd_octstring(15);
7482 timer T1 := 3.0;
7483 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7484 due to broken encryption */
7485 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7486 T1.start;
7487 alt {
7488 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7490 }
7491 [] T1.timeout {
7492 setverdict(pass);
7493 }
7494 }
7495
7496 /* release the channel */
7497 f_rsl_chan_deact();
7498 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7499 f_rslem_unregister(0, g_chan_nr);
7500}
7501testcase TC_rsl_modify_encr() runs on test_CT {
7502 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7503 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7504 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7505}
Harald Weltee613f962018-04-18 22:38:16 +02007506
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007507/* Verify RF RESource INDication messages (periodically sent over the RSL) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03007508private function f_TC_rsl_rf_resource_ind(template (present) RSL_ResourceInfo info)
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007509runs on test_CT {
7510 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7511 var ASP_RSL_Unitdata ud;
7512 timer T;
7513
7514 /* Intave is 6 SACCH periods by default */
7515 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7516
7517 T.start(Tval);
7518 alt {
7519 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7520 setverdict(pass);
7521 }
7522 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7523 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7524 }
7525 [] RSL_CCHAN.receive { repeat; }
7526 [] T.timeout {
7527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7528 "Timeout waiting for RF RESource INDication");
7529 }
7530 }
7531}
7532testcase TC_rsl_rf_resource_ind() runs on test_CT {
7533 var RSL_ResourceInfo info := { };
7534
7535 f_init(trx_nr := 0);
7536
7537 f_init_l1ctl();
7538 f_l1_tune(L1CTL);
7539
7540 /* g_AllChannels contains all logical channels */
7541 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7542 var RslChannelNr chan_nr := g_AllChannels[i];
7543
7544 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7545 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7546 { continue; }
7547
7548 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7549 }
7550
7551 /* Align to the first interference report */
7552 f_TC_rsl_rf_resource_ind(?);
7553
7554 /* Test 4 consecutive messages */
7555 for (var integer i := 0; i < 4; i := i + 1) {
7556 f_TC_rsl_rf_resource_ind(info);
7557 }
7558
7559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7560}
7561
Harald Weltee613f962018-04-18 22:38:16 +02007562/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007563private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007564 /* L3 payload doesn't matter, as it is passed transparently */
7565 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7566 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7567 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7568
7569 f_l1_tune(L1CTL);
7570
7571 /* first establish a dedicated channel in the clear */
7572 f_est_dchan(false);
7573
7574 /* Establish ABM */
7575 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7576
7577 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7578 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7579 /* expect the L3 to arrive still unencrypted on the MS side */
7580 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7581
7582 /* configure L1 to apply ciphering */
7583 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7584 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7585
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007586 /* send first ciphered I-frame in response and expect it on RSL */
7587 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007588
7589 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7590 * and hence enable encryption also on the downlink */
7591
7592 /* expect bi-directional communication work in encrypted mode */
7593 f_unitdata_mo(link_id, f_rnd_octstring(15));
7594 f_unitdata_mt(link_id, f_rnd_octstring(15));
7595
7596 /* release the channel */
7597 f_rsl_chan_deact();
7598 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7599 f_rslem_unregister(0, g_chan_nr);
7600}
7601testcase TC_encr_cmd_a51() runs on test_CT {
7602 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7603 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7604 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7605}
7606testcase TC_encr_cmd_a52() runs on test_CT {
7607 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7608 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7609 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7610}
7611testcase TC_encr_cmd_a53() runs on test_CT {
7612 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7613 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7614 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7615}
Eric Wildb9260392021-05-15 19:48:22 +02007616testcase TC_encr_cmd_a54() runs on test_CT {
7617 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7618 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7619 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7620}
Harald Weltee613f962018-04-18 22:38:16 +02007621
7622private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7623 var LapdmFrame lf;
7624 var octetstring reenc;
7625
7626 /* decode the LAPDm frame */
7627 if (ischosen(exp_match.ab)) {
7628 lf.ab := dec_LapdmFrameAB(enc);
7629 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007631 }
7632
7633 /* check if decoder result matches expectation */
7634 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007636 } else {
7637 log(name, ": matched");
7638 setverdict(pass);
7639 }
7640
7641 /* test if re-encoded frame equals original input */
7642 reenc := enc_LapdmFrame(lf);
7643 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007645 } else {
7646 setverdict(pass);
7647 }
7648}
7649
7650testcase TC_lapdm_selftest() runs on test_CT {
7651 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7652 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7653 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7654 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7655 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7656 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7657 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7658}
7659
Stefan Sperling4880be42018-08-07 18:12:59 +02007660/***********************************************************************
7661 * DTX Related (see GSM 05.08, section 8.3)
7662 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007663private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007664 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007665 var GsmFrameNumber first_fn;
7666 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007667 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007668 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007669 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7670 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007671 const integer frame_dtx_tchf_mod := 104;
7672 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7673 * which operates in terms of blocks rather than frames. */
7674 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7675 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007676 timer T := 5.0;
7677
7678 f_l1_tune(L1CTL);
7679 RSL.clear;
7680 L1CTL.clear;
7681
7682 /* activate TCHF signalling channel */
7683 f_est_dchan(false);
7684
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007685 /* A template for matching dummy LAPDm func=UA frames */
7686 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7687 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7688 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7689
Stefan Sperling4880be42018-08-07 18:12:59 +02007690 T.start;
7691 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007692 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007693 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007694
7695 if (is_first_frame) {
7696 is_first_frame := false;
7697 first_fn := dl.dl_info.frame_nr;
7698 }
7699
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007700 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007701 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007702 T.stop;
7703 f_rsl_chan_deact();
7704 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007705
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007706 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7707 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007708
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007709 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007710 setverdict(fail, "Not enough fill frames received: ",
7711 nfill_frames, " out of ", expected_fill_frames);
7712 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007713 } else {
7714 setverdict(pass);
7715 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007716 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007717 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7718 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7719 * we should only see the subset of frames numbers which correspond to a block boundary.
7720 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7721 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7722 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007723 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007724 repeat;
7725 }
7726 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007727 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7728 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7729 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007730 f_rsl_chan_deact();
7731 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007732 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007733 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007734 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007735 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007736 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007737
7738 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007739 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7740 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007741 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7742 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7743 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007744 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7745 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007746 case else {
7747 /* This shall not happen, just to be sure */
7748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7749 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007750 }
7751
7752 f_rsl_chan_deact();
7753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007754
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007755 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007756 setverdict(pass);
7757 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007758 setverdict(fail, "Not enough fill frames received: ",
7759 nfill_frames, " out of ", expected_fill_frames);
7760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007761 }
7762 } else {
7763 repeat;
7764 }
7765 }
7766 }
7767 [] L1CTL.receive { repeat; }
7768 [] T.timeout {
7769 f_rsl_chan_deact();
7770 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007772 }
7773 }
7774}
7775
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007776private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007777 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007778 var ConnHdlr vc_conn;
7779 var ConnHdlrPars pars;
7780 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007781 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007782 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007783 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007784 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007785 if (dtxd) {
7786 if (i >= 4) { /* DTX is only allowed on TCH/F */
7787 break;
7788 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007789 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007790 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007791 vc_conn.done;
7792 }
7793}
7794
7795/* Verify that L2 fill frames are sent on TCH in signaling mode if
7796 * there is nothing to transmit while DTX is disabled on downlink. */
7797testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7798 f_tch_sign_l2_fill_frame(false);
7799}
7800
7801/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7802 * there is nothing to transmit while DTX is enabled on downlink. */
7803testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7804 f_tch_sign_l2_fill_frame(true);
7805}
Harald Welte0472ab42018-03-12 15:02:26 +01007806
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007807testcase TC_chopped_ipa_ping() runs on test_CT {
7808 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7809}
7810
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007811testcase TC_chopped_ipa_payload() runs on test_CT {
7812 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7813}
7814
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007815
7816/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7817 * Return value: Measurement Report to be sent (encoded octetstring). */
7818type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7819 runs on ConnHdlr return octetstring;
7820
7821private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7822runs on ConnHdlr {
7823 var L1ctlDlMessage l1_dl;
7824 var SacchL1Header l1h;
7825 var octetstring l2;
7826
7827 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7828 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7829 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7830 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7831
7832 /* Pass it to the user specified call-back function */
7833 l2 := cb.apply(l1h, num_blocks);
7834 /* Send a Measurement Report generated by the call-back */
7835 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7836 l1_dl.dl_info.link_id,
7837 l1h, l2));
7838
7839 /* Shall we keep going? */
7840 num_blocks := num_blocks - 1;
7841 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7842 if (num_blocks > 0) { repeat; }
7843 }
7844 [] L1CTL.receive { repeat; }
7845}
7846
7847private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7848runs on ConnHdlr return octetstring {
7849 /* Command the L1 to apply received parameters */
7850 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7851
7852 /* Dummy measurement report (the results are invalid) */
7853 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7854}
7855
7856private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7857runs on ConnHdlr return octetstring {
7858 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7859 setverdict(fail, "Unexpected MS Power level change: ",
7860 g_pars.l1_pars.ms_power_level, " -> ",
7861 l1h.ms_power_lvl);
7862 }
7863
7864 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7865}
7866
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007867private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7868runs on ConnHdlr return octetstring {
7869 /* UL RSSI oscillation driven by SACCH block number */
7870 if (num_blocks rem 2 == 0) {
7871 f_trxc_fake_rssi(-100);
7872 } else {
7873 f_trxc_fake_rssi(-50);
7874 }
7875
7876 /* Make sure that MS power level remains constant */
7877 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7878}
7879
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007880/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7881private function f_TC_ms_pwr_ctrl_constant(charstring id)
7882runs on ConnHdlr {
7883 var integer num_blocks := 8;
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
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007902 /* Populate SACCH cache with a Measurement Report */
Vadim Yanitskiye2003d02022-08-10 17:38:07 +07007903 f_send_meas_rep(ts_MeasurementResults);
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007904
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007905 /* Establish a dedicated channel */
7906 f_est_dchan(more_ies := valueof(ies));
7907
7908 L1CTL.clear;
7909 T.start;
7910 alt {
7911 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7912 [] T.timeout {
7913 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7914 num_blocks, " were not handled");
7915 }
7916 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007917
7918 /* Release the channel */
7919 f_rsl_chan_deact();
7920 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007921}
7922testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7923 var ConnHdlr vc_conn;
7924 var ConnHdlrPars pars;
7925
7926 f_init();
7927
7928 /* Explicitly configure the Uplink power target (in dBm) */
7929 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
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_constant),
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 Yanitskiy652e60e2020-10-18 19:43:27 +07007944/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7945private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7946runs on ConnHdlr {
7947 var integer num_blocks := 16;
7948 timer T := int2float(num_blocks);
7949
7950 f_l1_tune(L1CTL);
7951 RSL.clear;
7952
7953 /* These IEs are needed for autonomous MS power control */
7954 var template (value) RSL_IE_List ies := {
7955 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7956 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7957 }),
7958 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7959 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7960 })
7961 };
7962
7963 /* Ensure that 'rx-current' equals 'rx-target' */
7964 f_trxc_fake_rssi(mp_uplink_power_target);
7965
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007966 /* Populate SACCH cache with a Measurement Report */
Vadim Yanitskiye2003d02022-08-10 17:38:07 +07007967 f_send_meas_rep(ts_MeasurementResults);
Vadim Yanitskiy8a1685d2022-07-30 23:56:18 +07007968
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007969 /* Establish a dedicated channel */
7970 f_est_dchan(more_ies := valueof(ies));
7971
7972 L1CTL.clear;
7973 T.start;
7974 alt {
7975 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7976 [] T.timeout {
7977 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7978 num_blocks, " were not handled");
7979 }
7980 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007981
7982 /* Release the channel */
7983 f_rsl_chan_deact();
7984 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007985}
7986testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7987 var ConnHdlr vc_conn;
7988 var ConnHdlrPars pars;
7989
7990 f_init();
7991
7992 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7993 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7994 /* Explicitly configure the Uplink power range (target and delte) */
7995 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7996 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7997
7998 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7999 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
8000 log(testcasename(), ": starting on ", pars.chan_nr);
8001
8002 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
8003 pars, trxc_comp := true);
8004 vc_conn.done;
8005 }
8006
8007 /* No need to reset Uplink power parameters - the IUT restarts anyway */
8008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8009}
8010
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008011private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
8012 var template L1ctlDlMessage tr_bad_frame;
8013 var L1ctlDlMessage l1_dl;
8014 timer T := 8.0;
8015
8016 f_l1_tune(L1CTL);
8017 RSL.clear;
8018
8019 f_est_dchan();
8020
8021 /* There may be a few errors right after the channel activation */
8022 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
8023 L1CTL.clear;
8024
8025 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
8026 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
8027 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
8028 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
8029 tr_bad_frame.payload := ?;
8030
8031 T.start;
8032 alt {
8033 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
8034 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
8035 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
8036 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
8037 }
8038 [] as_l1_sacch();
8039 [] L1CTL.receive { repeat; }
8040 [] T.timeout {
8041 /* We're done, break the loop */
8042 setverdict(pass);
8043 }
8044 }
8045
8046 f_rsl_chan_deact();
8047 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8048}
8049testcase TC_speech_no_rtp_tchf() runs on test_CT {
8050 var ConnHdlr vc_conn;
8051 var ConnHdlrPars pars;
8052
8053 f_init();
8054
8055 /* TS1, TCH/F, V1 (FR codec) */
8056 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8057 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8058 vc_conn.done;
8059}
8060testcase TC_speech_no_rtp_tchh() runs on test_CT {
8061 var ConnHdlr vc_conn;
8062 var ConnHdlrPars pars;
8063
8064 f_init();
8065
8066 /* TS5, TCH/H, V1 (HR codec) */
8067 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8068 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
8069 vc_conn.done;
8070}
8071
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008072/* Verify handling of Downlink and Uplink speech frames */
8073private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
8074 var L1ctlDlMessage l1_dl;
8075 var PDU_RTP rtp_pdu;
8076 var octetstring pl;
8077 timer Td, Tu;
8078
8079 f_l1_tune(L1CTL);
8080 f_est_dchan();
8081
8082 /* Activate the RTP emulation */
8083 pl := f_rnd_octstring(6);
8084 f_rtpem_activate(pl);
8085
8086 /* Give the scheduler some time to fill up the buffers */
8087 f_sleep(2.0);
8088 L1CTL.clear;
8089 RSL.clear;
8090
8091 /* Make sure that Downlink frames are received at the UE */
8092 Td.start(2.0);
8093 alt {
8094 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
8095 log("TCH received: ", l1_dl.payload.traffic_ind.data);
8096 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
8097 l1_dl.payload.traffic_ind.data));
8098 setverdict(pass);
8099 }
8100 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
8101 setverdict(fail, "Rx unexpected Downlink speech frame ",
8102 "(", l1_dl.payload.traffic_ind.data, ") ",
8103 "expected (", pl, ")");
8104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8105 }
8106 [] as_l1_sacch();
8107 [] L1CTL.receive { repeat; }
8108 [] Td.timeout {
8109 setverdict(fail, "Timeout waiting for Downlink speech frames");
8110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8111 }
8112 }
8113
8114 /* Make sure that Uplink frames are received at the BTS */
8115 RTPEM_DATA.clear;
8116 Tu.start(2.0);
8117 alt {
8118 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
8119 if (rtp_pdu.data != pl)
8120 { repeat; }
8121 }
8122 [] RTPEM_DATA.receive { repeat; }
8123 [] Tu.timeout {
8124 setverdict(fail, "Timeout waiting for Uplink speech frames");
8125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8126 }
8127 }
8128
8129 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
8130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8131 f_rsl_chan_deact();
8132 f_rslem_unregister(0, g_chan_nr);
8133}
8134testcase TC_speech_rtp_tchf() runs on test_CT {
8135 var ConnHdlr vc_conn;
8136 var ConnHdlrPars pars;
8137
8138 f_init();
8139
8140 /* TS1, TCH/F, V1 (FR codec) */
8141 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
8142 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8143 vc_conn.done;
8144
8145 /* TS1, TCH/F, V2 (EFR codec) */
8146 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
8147 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8148 vc_conn.done;
8149
8150 /* TODO: also test V3 (AMR codec) */
8151
8152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8153}
8154testcase TC_speech_rtp_tchh() runs on test_CT {
8155 var ConnHdlr vc_conn;
8156 var ConnHdlrPars pars;
8157
8158 f_init();
8159
8160 /* TS5, TCH/H0, V1 (HR codec) */
8161 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
8162 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
8163 vc_conn.done;
8164
8165 /* TODO: also test V3 (AMR codec) */
8166
8167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8168}
8169
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008170private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
8171 var GsmFrameNumber fn;
8172 var ChannelDescription ch_desc;
8173 var integer ra := 23;
8174
8175 f_l1_tune(L1CTL);
8176 RSL.clear;
8177
8178 /* Send RACH request and wait for ChanReq */
8179 fn := f_rach_req_wait_chan_rqd(ra);
8180
8181 /* The BSC already sends the Immediate Assignment, before the channel is active.
8182 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
8183 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
8184 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
8185 if (g_pars.fhp.enabled) {
8186 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8187 } else {
8188 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8189 }
8190 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8191 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8192
8193 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
8194 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
8195 var L1ctlDlMessage dl;
8196 var GsmRrMessage rr;
8197
8198 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
8199 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
8200 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
8201 rr_imm_ass.payload.imm_ass.chan_desc := *;
8202
8203 timer T := 1.0;
8204 T.start;
8205 alt {
8206 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
8207 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
8208 if (match(rr, rr_imm_ass)) {
8209 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
8210 mtc.stop;
8211 } else {
8212 repeat;
8213 }
8214 }
8215 [] L1CTL.receive { repeat; }
8216 [] T.timeout;
8217 }
8218 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
8219 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
8220
8221 /* Now expect the IMM ASS on Um */
8222 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8223 setverdict(pass);
8224
8225 /* Release the channel */
8226 f_rsl_chan_deact();
8227 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8228}
8229
8230testcase TC_early_immediate_assignment() runs on test_CT {
8231 var ConnHdlr vc_conn;
8232 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8233 f_init();
8234 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8235 vc_conn.done;
8236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8237}
8238
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008239private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8240 var integer ra := oct2int(f_rnd_ra_cs());
8241 var ChannelDescription ch_desc;
8242
8243 /* Tune the MS to BCCH */
8244 f_l1_tune(L1CTL);
8245
8246 /* Send RACH request and wait for ChanReq */
8247 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8248
8249 /* Activate channel on the BTS side */
8250 f_rsl_chan_act(g_pars.chan_mode);
8251
8252 /* Craft channel description (with or without frequency hopping parameters) */
8253 if (g_pars.fhp.enabled) {
8254 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8255 } else {
8256 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8257 }
8258
8259 /* Send IMM.ASS via CCHAN */
8260 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8261 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8262
8263 /* Receive IMM.ASS on the MS side */
8264 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8265
8266 /* Match the Channel Description IE in received IMM.ASS */
8267 if (not match(imm_ass.chan_desc, ch_desc)) {
8268 setverdict(fail, "Channel Description IE does not match");
8269 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8270 }
8271
8272 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8273 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8274
8275 /* Expect SACCH frames on Downlink */
8276 L1CTL.clear;
8277 f_exp_sacch(true);
8278
8279 /* We're done, deactivate and release */
8280 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8281 f_rsl_chan_deact();
8282}
8283testcase TC_est_dchan() runs on test_CT {
8284 var ConnHdlr vc_conn;
8285 var ConnHdlrPars pars;
8286
8287 f_init();
8288
8289 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8290 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8291 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8292 vc_conn.done;
8293 }
8294
8295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8296}
8297
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008298private type record TopTestCase {
8299 RSL_IE_BS_Power bs_power,
8300 RSL_IE_OSMO_TopAcchCap top_cap,
8301 record of TopTestStep steps
8302};
8303private type record TopTestStep {
8304 MeasurementResults meas_res optional,
8305 GsmRxLev overpower_sacch,
8306 GsmRxLev overpower_facch
8307};
8308
8309private function f_rxlev_match(template (present) RslLinkId link_id,
8310 template (present) GsmRxLev rxlev)
8311runs on ConnHdlr {
8312 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8313 if (not match(dl.dl_info.rx_level, rxlev)) {
8314 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8315 " does not match expected RxLev := ", rxlev);
8316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8317 }
8318}
8319
8320private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8321 var TopTestCase tc := g_pars.spec.top;
8322 var GsmRxLev rxlev_dcch;
8323 var L1ctlDlMessage dl;
8324
8325 /* Wait for Pau ramping to complete */
8326 f_sleep(6.0);
8327
8328 f_l1_tune(L1CTL);
8329 L1CTL.clear;
8330 RSL.clear;
8331
8332 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8333 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8334 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8335
8336 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8337 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8338
8339 /* Additional IEs for the CHANnel ACTIVation message */
8340 var template (value) RSL_IE_List ies := {
8341 /* Employ BS power control in static mode */
8342 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8343 bs_power := tc.bs_power
8344 }),
8345 /* Indicate the given Temporary Overpower capability */
8346 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8347 top_acch_cap := tc.top_cap
8348 })
8349 };
8350
8351 /* Establish a dedicated channel */
8352 f_est_dchan(more_ies := valueof(ies));
8353
8354 /* Give it some time to stabilize */
8355 f_sleep(0.480 * 2.0);
8356 L1CTL.clear;
8357 RSL.clear;
8358
8359 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8360 var TopTestStep step := tc.steps[i];
8361 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8362 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8363
8364 log("Executing step[", i, "] := ", step);
8365
8366 /* Send RR Measurement Report (if present) */
8367 if (ispresent(step.meas_res)) {
8368 f_transceive_meas_rep(step.meas_res);
8369 f_sleep(0.480 * 2.0);
8370 L1CTL.clear;
8371 }
8372
8373 /* Check RxLev on both FACCH and SACCH */
8374 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8375 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8376
8377 setverdict(pass);
8378 }
8379}
8380testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8381 var ConnHdlrPars pars;
8382 var ConnHdlr vc_conn;
8383
8384 f_init();
8385
8386 /* Verify lower and upper RxQual thresholds */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008387 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008388 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8389 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8390 steps := {
8391 /* Channel established, no overpower */
8392 { meas_res := omit,
8393 overpower_sacch := 0, overpower_facch := 0 },
8394
8395 /* Worst possible RxQual value, overpower of 4dB */
8396 { meas_res := ts_MeasurementResults(rxq_f := 7),
8397 overpower_sacch := 4, overpower_facch := 4 },
8398 /* Worst possible RxQual value, disabling overpower */
8399 { meas_res := ts_MeasurementResults(rxq_f := 0),
8400 overpower_sacch := 0, overpower_facch := 0 },
8401
8402 /* Lower threshold not reached, no overpower */
8403 { meas_res := ts_MeasurementResults(rxq_f := 1),
8404 overpower_sacch := 0, overpower_facch := 0 },
8405 /* Lower threshold not reached, no overpower */
8406 { meas_res := ts_MeasurementResults(rxq_f := 2),
8407 overpower_sacch := 0, overpower_facch := 0 },
8408 /* Lower threshold reached, overpower of 4dB */
8409 { meas_res := ts_MeasurementResults(rxq_f := 4),
8410 overpower_sacch := 4, overpower_facch := 4 },
8411 /* Upper threshold not reached, keeping overpower */
8412 { meas_res := ts_MeasurementResults(rxq_f := 3),
8413 overpower_sacch := 4, overpower_facch := 4 },
8414 /* Upper threshold reached, disabling overpower */
8415 { meas_res := ts_MeasurementResults(rxq_f := 2),
8416 overpower_sacch := 0, overpower_facch := 0 }
8417 }
8418 };
8419
8420 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8421 spec := { top := top }, trx_nr := 1));
8422 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8423 vc_conn.done;
8424
8425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8426}
8427testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8428 var ConnHdlrPars pars;
8429 var ConnHdlr vc_conn;
8430
8431 f_init();
8432
8433 /* Verify handling of FULL and SUB values */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008434 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008435 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8436 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8437 steps := {
8438 /* Channel established, no overpower */
8439 { meas_res := omit,
8440 overpower_sacch := 0, overpower_facch := 0 },
8441
8442 /* Invalid measurement results, no overpower */
8443 { meas_res := ts_MeasurementResults(rxq_f := 7,
8444 rxq_s := 7,
8445 valid := false),
8446 overpower_sacch := 0, overpower_facch := 0 },
8447
8448 /* DTXu was in use, no overpower */
8449 { meas_res := ts_MeasurementResults(rxq_f := 7,
8450 rxq_s := 0,
8451 dtx_used := true),
8452 overpower_sacch := 0, overpower_facch := 0 },
8453 /* DTXu was in use, overpower of 4 dB */
8454 { meas_res := ts_MeasurementResults(rxq_f := 0,
8455 rxq_s := 7,
8456 dtx_used := true),
8457 overpower_sacch := 4, overpower_facch := 4 }
8458 }
8459 };
8460
8461 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8462 spec := { top := top }, trx_nr := 1));
8463 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8464 vc_conn.done;
8465
8466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8467}
8468testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8469 var ConnHdlrPars pars;
8470 var ConnHdlr vc_conn;
8471
8472 f_init();
8473
8474 /* Overpower is always on, SACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008475 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008476 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8477 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8478 rxqual := 0, /* always on */
8479 sacch_enable := false),
8480 steps := {
8481 /* Channel established, FACCH overpower */
8482 { meas_res := omit,
8483 overpower_sacch := 0, overpower_facch := 4 },
8484 /* MS indicates good RxQual, no difference */
8485 { meas_res := ts_MeasurementResults(rxq_f := 0),
8486 overpower_sacch := 0, overpower_facch := 4 },
8487 /* MS indicates bad RxQual, no difference */
8488 { meas_res := ts_MeasurementResults(rxq_f := 7),
8489 overpower_sacch := 0, overpower_facch := 4 }
8490 }
8491 };
8492
8493 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8494 spec := { top := top }, trx_nr := 1));
8495 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8496 vc_conn.done;
8497
8498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8499}
8500testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8501 var ConnHdlrPars pars;
8502 var ConnHdlr vc_conn;
8503
8504 f_init();
8505
8506 /* Overpower is always on, FACCH disabled */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008507 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008508 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8509 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8510 rxqual := 0, /* always on */
8511 facch_enable := false),
8512 steps := {
8513 /* Channel established, SACCH overpower */
8514 { meas_res := omit,
8515 overpower_sacch := 4, overpower_facch := 0 },
8516 /* MS indicates good RxQual, no difference */
8517 { meas_res := ts_MeasurementResults(rxq_f := 0),
8518 overpower_sacch := 4, overpower_facch := 0 },
8519 /* MS indicates bad RxQual, no difference */
8520 { meas_res := ts_MeasurementResults(rxq_f := 7),
8521 overpower_sacch := 4, overpower_facch := 0 }
8522 }
8523 };
8524
8525 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8526 spec := { top := top }, trx_nr := 1));
8527 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8528 vc_conn.done;
8529
8530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8531}
8532testcase TC_acch_overpower_limit() runs on test_CT {
8533 var ConnHdlrPars pars;
8534 var ConnHdlr vc_conn;
8535
8536 f_init();
8537
8538 /* Overpower higher than current power reduction level (2dB) */
Vadim Yanitskiyd12db412022-03-12 18:05:18 +03008539 var template (value) TopTestCase top := {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008540 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8541 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8542 rxqual := 0 /* always on */),
8543 steps := {
8544 /* Channel established, ACCH overpower of 2dB */
8545 { meas_res := omit,
8546 overpower_sacch := 2, overpower_facch := 2 },
8547 /* MS indicates good RxQual, no difference */
8548 { meas_res := ts_MeasurementResults(rxq_f := 0),
8549 overpower_sacch := 2, overpower_facch := 2 },
8550 /* MS indicates bad RxQual, no difference */
8551 { meas_res := ts_MeasurementResults(rxq_f := 7),
8552 overpower_sacch := 2, overpower_facch := 2 }
8553 }
8554 };
8555
8556 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8557 spec := { top := top }, trx_nr := 1));
8558 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8559 vc_conn.done;
8560
8561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8562}
8563
Harald Welte0472ab42018-03-12 15:02:26 +01008564/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8565/* protocol error as per 44.006 */
8566/* link layer failure (repetition of I-frame N200 times without ACK */
8567/* repetition of SABM or DISC N200 times without ACK */
8568/* receptiom of SABM in multi-frame established state */
8569
8570
Harald Welte68e495b2018-02-25 00:05:57 +01008571/* TODO Areas:
8572
8573* channel activation
8574** with BS_Power / MS_Power, bypassing power control loop
8575** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008576** with timing advance from initial activation on
8577* mode modify
8578** encryption
8579** multirate
8580* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008581** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008582* BS Power Control
8583* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008584* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008585** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008586* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008587** DATA_IND from BTS->PCU
8588** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008589
8590*/
Harald Welte70767382018-02-21 12:16:40 +01008591
8592control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008593 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008594 execute( TC_chan_act_stress() );
8595 execute( TC_chan_act_react() );
8596 execute( TC_chan_deact_not_active() );
8597 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008598 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008599 execute( TC_sacch_filling() );
8600 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008601 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008602 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008603 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008604 execute( TC_sacch_chan_act_ho_async() );
8605 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008606 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008607 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008608 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008609 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008610 execute( TC_ho_rach() );
Vadim Yanitskiy1ab332f2022-03-12 15:31:23 +03008611 execute( TC_ho_physical_info() );
Harald Welte3453ab42019-05-24 21:19:58 +02008612 execute( TC_rach_load_idle_thresh0() );
8613 execute( TC_rach_load_idle_below_thresh() );
8614 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008615 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008616 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008617 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008618 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008619 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008620 execute( TC_meas_res_sign_tchf() );
8621 execute( TC_meas_res_sign_tchh() );
8622 execute( TC_meas_res_sign_sdcch4() );
8623 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008624 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008625 execute( TC_meas_res_speech_tchf_sapi3() );
8626 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008627 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008628 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008629 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008630 execute( TC_rsl_bs_pwr_static_ass() );
8631 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008632 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008633 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008634 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008635 execute( TC_rsl_ms_pwr_dyn_up() );
8636 execute( TC_rsl_ms_pwr_dyn_down() );
8637 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8638 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008639 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008640 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008641 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008642 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008643 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008644 execute( TC_paging_imsi_80percent() );
8645 execute( TC_paging_tmsi_80percent() );
8646 execute( TC_paging_imsi_200percent() );
8647 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008648 execute( TC_rsl_protocol_error() );
8649 execute( TC_rsl_mand_ie_error() );
8650 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008651 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008652 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008653 execute( TC_si_sched_2bis() );
8654 execute( TC_si_sched_2ter() );
8655 execute( TC_si_sched_2ter_2bis() );
8656 execute( TC_si_sched_2quater() );
8657 execute( TC_si_sched_13() );
8658 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008659 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008660 execute( TC_ipa_crcx_twice_not_active() );
8661 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008662 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008663 execute( TC_ipa_crcx_sdcch_not_active() );
Vadim Yanitskiy866afc22022-05-01 16:08:30 +03008664 execute( TC_ipa_crcx_ack_addr() );
Harald Welte883340c2018-02-28 18:59:29 +01008665
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008666 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008667 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008668 execute( TC_pcu_act_req() );
8669 execute( TC_pcu_act_req_wrong_ts() );
8670 execute( TC_pcu_act_req_wrong_bts() );
8671 execute( TC_pcu_act_req_wrong_trx() );
8672 execute( TC_pcu_deact_req() );
8673 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008674 execute( TC_pcu_ver_si1() );
8675 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008676 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008677 if (mp_l1_supports_gprs) {
8678 execute( TC_pcu_data_req_pdtch() );
8679 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008680 execute( TC_pcu_data_req_wrong_bts() );
8681 execute( TC_pcu_data_req_wrong_trx() );
8682 execute( TC_pcu_data_req_wrong_ts() );
8683 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008684 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008685 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008686 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008687 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008688 execute( TC_pcu_data_req_imm_ass_pch() );
8689 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008690 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008691 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008692 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008693 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008694 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008695 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008696 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008697 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008698 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008699 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008700 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008701 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008702 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008703 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008704 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008705 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008706 execute( TC_dyn_osmo_pdch_act_deact() );
8707 execute( TC_dyn_osmo_pdch_double_act() );
8708 execute( TC_dyn_ipa_pdch_act_deact() );
8709 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008710 execute( TC_pcu_info_ind_fh_params() );
8711 execute( TC_pcu_socket_nsvc_ipv4() );
8712 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008713 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008714 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008715 } else {
8716 log("PCU socket path not available, skipping PCU tests");
8717 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008718
Harald Welte3d04ae62018-04-04 20:29:05 +02008719 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008720 execute( TC_dyn_osmo_pdch_tchf_act() );
8721 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008722 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008723 execute( TC_dyn_ipa_pdch_tchf_act() );
8724 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008725
8726 execute( TC_rll_est_ind() );
8727 execute( TC_rll_est_req_DCCH_3() );
8728 execute( TC_rll_est_req_ACCH_3() );
8729 execute( TC_rll_rel_ind_DCCH_0() );
8730 execute( TC_rll_rel_ind_DCCH_3() );
8731 execute( TC_rll_rel_ind_ACCH_0() );
8732 execute( TC_rll_rel_ind_ACCH_3() );
8733 execute( TC_rll_rel_req() );
8734 execute( TC_rll_unit_data_req_DCCH() );
8735 execute( TC_rll_unit_data_req_ACCH() );
8736 execute( TC_rll_unit_data_ind_DCCH() );
8737 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008738
8739 execute( TC_chan_act_a51() );
8740 execute( TC_chan_act_a52() );
8741 execute( TC_chan_act_a53() );
Vadim Yanitskiy8b4e0462022-08-27 19:18:17 +07008742 execute( TC_chan_act_a54() );
Harald Weltee613f962018-04-18 22:38:16 +02008743 execute( TC_encr_cmd_a51() );
8744 execute( TC_encr_cmd_a52() );
8745 execute( TC_encr_cmd_a53() );
Vadim Yanitskiy8b4e0462022-08-27 19:18:17 +07008746 execute( TC_encr_cmd_a54() );
Harald Weltee613f962018-04-18 22:38:16 +02008747
Harald Welteee25aae2019-05-19 14:32:37 +02008748 execute( TC_err_rep_wrong_mdisc() );
8749 execute( TC_err_rep_wrong_msg_type() );
8750 execute( TC_err_rep_wrong_sequence() );
8751
Harald Weltee613f962018-04-18 22:38:16 +02008752 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008753
8754 execute( TC_tch_sign_l2_fill_frame() );
8755 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008756
8757 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008758 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008759
8760 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008761 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008762
8763 execute( TC_speech_no_rtp_tchf() );
8764 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008765 execute( TC_speech_rtp_tchf() );
8766 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008767
8768 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008769
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008770 execute( TC_acch_overpower_rxqual_thresh() );
8771 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8772 execute( TC_acch_overpower_always_on_facch() );
8773 execute( TC_acch_overpower_always_on_sacch() );
8774 execute( TC_acch_overpower_limit() );
8775
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008776 /* BEWARE: these test cases can potentially break the IUT or cause
8777 * weird/unexpected behavior. Ensure that they are executed last. */
8778 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8779 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008780}
8781
8782
8783}