blob: 39dca7acdaa1a128ce772a52cb9897fa86787614 [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;
Harald Welte70767382018-02-21 12:16:40 +0100138}
139
Harald Welte629cc6b2018-03-11 17:19:05 +0100140type record of RslChannelNr ChannelNrs;
141
Harald Welte70767382018-02-21 12:16:40 +0100142type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100143 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100144 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100145 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100146 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100148 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100149
150 /* L1CTL port (for classic tests) */
151 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100152
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700153 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700154 port TRXC_CODEC_PT BTS_TRXC;
155 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100156
Harald Weltef50e3ae2018-09-10 10:27:56 +0200157 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100158 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200159 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100160
Harald Welte883340c2018-02-28 18:59:29 +0100161 /* PCU Interface of BTS */
162 port PCUIF_CODEC_PT PCU;
163 var integer g_pcu_conn_id;
164 /* Last PCU INFO IND we received */
165 var PCUIF_Message g_pcu_last_info;
166
Harald Welte48494ca2018-02-25 16:59:50 +0100167 /* SI configuration */
168 var SystemInformationConfig si_cfg := {
169 bcch_extended := false,
170 si1_present := false,
171 si2bis_present := false,
172 si2ter_present := false,
173 si2quater_present := false,
174 si7_present := false,
175 si8_present := false,
176 si9_present := false,
177 si13_present := false,
178 si13alt_present := false,
179 si15_present := false,
180 si16_present := false,
181 si17_present := false,
182 si2n_present := false,
183 si21_present := false,
184 si22_present := false
185 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100186
187 /* all logical channels available on the BTS */
188 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100189 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100190}
191
192/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200193type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100194 port L1CTL_PT L1CTL;
195
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700196 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700197 port TRXC_CODEC_PT BTS_TRXC;
198 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100199
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200200 /* port to be initialized optionally to access BSC VTY */
201 port TELNETasp_PT BSCVTY;
202
Harald Welte70767382018-02-21 12:16:40 +0100203 timer g_Tguard;
204 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
205
206 var ConnHdlrPars g_pars;
207 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100208 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200209
210 /* PCU Interface of BTS */
211 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200212
213 var RTP_Emulation_CT vc_RTPEM;
214 port RTPEM_CTRL_PT RTPEM_CTRL;
215 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100216}
217
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700218private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200220 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200222 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 timer T;
226
Harald Welte70767382018-02-21 12:16:40 +0100227 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
228 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
229
230 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
231 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
232 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
233
234 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
235 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700236
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700237 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700238 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700239 T.start(mp_ipa_up_timeout);
240 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700241 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700242 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
243 /* Make sure that all transceivers use unique stream ID */
244 if (trx_mask[enum2int(ev.sid)] == '1'B) {
245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
246 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
247 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700248
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 trx_mask[enum2int(ev.sid)] := '1'B;
250 trx_count := trx_count + 1;
251
252 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200253 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700254 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200255 /* This message (RF RESource INDication) is sent by the IUT itself */
256 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
257 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
259 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
260 }
261 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
264 }
265
266 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
267 rfind_count := rfind_count + 1;
268 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
269 if (rfind_count < mp_transceiver_num) { repeat; }
270 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700271 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
272 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
273 [] T.timeout {
274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
275 "Timeout waiting for RSL bring up");
276 }
277 }
Harald Welte70767382018-02-21 12:16:40 +0100278}
279
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700280friend type record length(1 .. 256) of TrxParsItem TrxPars;
281friend type record TrxParsItem {
282 GsmArfcn arfcn,
283 TrxTsPars ts
284};
285
286friend type record length(8) of TrxTsParsItem TrxTsPars;
287friend type record TrxTsParsItem {
288 PchanConfig config
289};
290
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700291friend type record FreqHopPars {
292 /* Whether frequency hopping is in use */
293 boolean enabled,
294 /* Mobile Allocation Index Offset / Hopping Sequence Number */
295 MaioHsn maio_hsn,
296 /* MA bitmap to be indicated in RR Immediate Assignment */
297 MobileAllocationLV ma_map,
298 /* The actual Mobile Allocation (ARFCN list) to be used */
299 L1ctlMA ma
300};
301
Harald Welte70767382018-02-21 12:16:40 +0100302type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700303 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100304 RslChannelNr chan_nr,
305 RSL_IE_ChannelMode chan_mode,
306 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100307 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200308 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200309 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700310 BtsBand bts0_band optional,
311
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700312 /* Training Sequence Code */
313 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700314 /* Frequency hopping parameters */
315 FreqHopPars fhp
316};
Harald Welte0472ab42018-03-12 15:02:26 +0100317
318/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200319friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300320 RllTestCase rll,
321 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100322}
323
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700324private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100325 max_retrans := RACH_MAX_RETRANS_7,
326 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100327 cell_barr_access := false,
328 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100329 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100330};
331
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700332private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100333 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200334 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 acs := '0'B,
336 neci := true,
337 rxlev_access_min := 0
338}
339
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700340private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100341 mcc_mnc := '262F42'H,
342 lac := 42
343}
344
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700345private template (value) GPRSIndicator ts_GPRSIndicator_def := {
346 ra_colour := 0,
347 si13_pos := '0'B
348}
349
350private template (value) SI3RestOctets ts_SI3RestOctets_def
351modifies ts_SI3RestOctets := {
352 gprs_ind := {
353 presence := CSN1_H,
354 ind := ts_GPRSIndicator_def
355 }
356}
357
358private template (value) SI4RestOctets ts_SI4RestOctets_def
359modifies ts_SI4RestOctets := {
360 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700361 presence := CSN1_H,
362 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700363 }
364}
365
Harald Welte7484fc42018-02-24 14:09:45 +0100366/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700367private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100368 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100369 payload := {
370 si3 := {
371 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100372 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100373 ctrl_chan_desc := {
374 msc_r99 := true,
375 att := true,
376 bs_ag_blks_res := 1,
377 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100378 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100379 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
380 spare := '00'B,
381 bs_pa_mfrms := 0, /* 2 multiframes */
382 t3212 := 1 /* 6 minutes */
383 },
Harald Welte82ccef72018-02-25 16:17:33 +0100384 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100385 dn_ind := false,
386 pwrc := false,
387 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100388 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100389 },
Harald Weltef10153f2018-02-25 16:34:05 +0100390 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100391 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200392 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100393 }
394 }
395}
Harald Welte70767382018-02-21 12:16:40 +0100396
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700397private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100398 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100399 payload := {
400 si2 := {
401 bcch_freq_list := '00000000000000000000000000000000'O,
402 ncc_permitted := '11111111'B,
403 rach_control := ts_RachCtrl_default
404 }
405 }
406}
407
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700408private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100409 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100410 payload := {
411 si4 := {
412 lai := ts_LAI_default,
413 cell_sel_par := ts_CellSelPar_default,
414 rach_control := ts_RachCtrl_default,
415 cbch_chan_desc := omit,
416 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200417 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100418 }
419 }
420}
421
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700422private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100423runs on test_CT {
424 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700425 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100426}
427
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700428private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100429runs on test_CT {
430 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
431 log("Setting ", rsl_si_type, ": ", si_dec);
432 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
433}
434
Harald Welte505cf9b2018-09-15 17:47:23 +0300435friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100436 map(self:BTSVTY, system:BTSVTY);
437 f_vty_set_prompts(BTSVTY);
438 f_vty_transceive(BTSVTY, "enable");
439}
440
Harald Welte505cf9b2018-09-15 17:47:23 +0300441friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200442 map(self:BSCVTY, system:BSCVTY);
443 f_vty_set_prompts(BSCVTY, "OsmoBSC");
444 f_vty_transceive(BSCVTY, "enable");
445}
446
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200447friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
448 map(self:BSCVTY, system:BSCVTY);
449 f_vty_set_prompts(BSCVTY, "OsmoBSC");
450 f_vty_transceive(BSCVTY, "enable");
451}
452
Harald Welte883340c2018-02-28 18:59:29 +0100453/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200454friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100456 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200457 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
458 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100459 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100462 }
463}
464
Harald Weltef26de0b2018-04-04 20:28:05 +0200465private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
466 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100467 timer T := 2.0;
468 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100469 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200470 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100471 return;
472 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200473 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100474
475 T.start;
476 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100478 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100480 }
481 }
482}
483
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700484private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
485 out integer trxc_conn_id) {
486 var Result res;
487
488 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
489 "", -1, -1, { udp := {} }, {});
490 if (not ispresent(res.connId)) {
491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
492 "Could not connect to the control (TRXC) interface " &
493 "of FakeTRX, check your configuration");
494 }
495 trxc_conn_id := res.connId;
496}
497
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100498/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700499friend function f_init(uint8_t trx_nr := 0)
500runs on test_CT
501{
502 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200503 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100504
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700505 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
506 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700507 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200508 g_AllChanTypes := {
509 /* TS 1..4: TCH/F */
510 valueof(ts_RslChanNr_Bm(1)),
511 /* TS 5: TCH/H */
512 valueof(ts_RslChanNr_Lm(5,1)),
513 /* TS 0: SDCCH/4 */
514 valueof(ts_RslChanNr_SDCCH4(0,2)),
515 /* TS 6: SDCCH/8 */
516 valueof(ts_RslChanNr_SDCCH8(6,4))
517 };
518 } else {
519 g_AllChanTypes := {
520 /* TS 1..4: TCH/F */
521 valueof(ts_RslChanNr_Bm(1)),
522 /* TS 0: SDCCH/4 */
523 valueof(ts_RslChanNr_SDCCH4(0,2)),
524 /* TS 6: SDCCH/8 */
525 valueof(ts_RslChanNr_SDCCH8(6,4))
526 };
527 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700528
529 g_AllChannels := { };
530
531 /* Generate list of all logical channels from module parameters */
532 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
533 select (trx_pars.ts[tn].config) {
534 case (GSM_PCHAN_CCCH_SDCCH4) {
535 g_AllChannels := g_AllChannels &
536 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
537 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
538 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
539 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
540 }
541 case (GSM_PCHAN_SDCCH8) {
542 g_AllChannels := g_AllChannels &
543 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
544 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
545 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
546 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
547 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
551 }
552 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
553 g_AllChannels := g_AllChannels &
554 { valueof(ts_RslChanNr_Lm(tn, 0)),
555 valueof(ts_RslChanNr_Lm(tn, 1)),
556 valueof(ts_RslChanNr_Bm(tn)) };
557 }
558 case (GSM_PCHAN_TCHH) {
559 g_AllChannels := g_AllChannels &
560 { valueof(ts_RslChanNr_Lm(tn, 0)),
561 valueof(ts_RslChanNr_Lm(tn, 1)) };
562 }
563 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
564 g_AllChannels := g_AllChannels &
565 { valueof(ts_RslChanNr_Bm(tn)) };
566 }
567 }
568 }
569
Harald Welte70767382018-02-21 12:16:40 +0100570 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100571 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100572 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100573 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100574
575 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100576 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
577 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
578 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
579 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100580
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700581 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100582 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700583
584 /* Init TRXC interface to FakeTRX */
585 map(self:BTS_TRXC, system:BTS_TRXC);
586 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
587
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700588 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600589 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
590 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700591 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600592 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100593 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200594
595 /* Wait some extra time to make sure the BTS emits a stable carrier.
596 * (this is only relevant when running the tests with a physical BTS.) */
597 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
Harald Welte68e495b2018-02-25 00:05:57 +0100600/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700601friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100602 map(self:L1CTL, system:L1CTL);
603 f_connect_reset(L1CTL);
604}
605
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200606friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100607
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700608private type record length(8) of FreqHopGroups FreqHopConfig;
609
610private type record of FreqHopGroup FreqHopGroups;
611private type record FreqHopGroup {
612 uint6_t hsn,
613 FreqHopGroupItems trx_maio
614};
615
616private type record of FreqHopGroupItem FreqHopGroupItems;
617private type record FreqHopGroupItem {
618 uint8_t trx_nr,
619 uint6_t maio
620};
621
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700622friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
623 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700625 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700626 var integer i, j;
627
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700628 fhp.enabled := false;
629
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 for (i := 0; i < lengthof(groups); i := i + 1) {
631 var FreqHopGroup g := groups[i];
632 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
633 var FreqHopGroupItem gi := g.trx_maio[j];
634 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700635 fhp.maio_hsn.maio := gi.maio;
636 fhp.maio_hsn.hsn := g.hsn;
637 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700638 break;
639 }
640 }
641
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700642 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700643 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700644 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
645 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
646 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647
648 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700649 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
650 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700651 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700652 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700653 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700654 }
655
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700656 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700657 break; /* We're done */
658 }
659 }
660}
661
Harald Welte70767382018-02-21 12:16:40 +0100662/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700663friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
664 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200665 boolean trxc_comp := false,
666 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100667runs on test_CT return ConnHdlr {
668 var charstring id := testcasename();
669 var ConnHdlr vc_conn;
670
671 vc_conn := ConnHdlr.create(id);
672 /* connect to RSL Emulation main component */
673 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
674 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700675
676 /* The ConnHdlr component may want to talk to some ports directly,
677 * so we disconnect it from the test_CT and connect it to the component.
678 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200679 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200680 unmap(self:PCU, system:PCU);
681 map(vc_conn:PCU, system:PCU);
682 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700683 if (trxc_comp) {
684 unmap(self:BTS_TRXC, system:BTS_TRXC);
685 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
686 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200687 if (l1ctl) {
688 map(vc_conn:L1CTL, system:L1CTL);
689 }
Harald Welte70767382018-02-21 12:16:40 +0100690
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700691 /* Obtain frequency hopping parameters for a given timeslot */
692 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700693 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700694 }
695
Harald Welte70767382018-02-21 12:16:40 +0100696 vc_conn.start(f_handler_init(fn, id, pars));
697 return vc_conn;
698}
699
Harald Welte70767382018-02-21 12:16:40 +0100700private altstep as_Tguard() runs on ConnHdlr {
701 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100703 }
704}
705
Harald Welte990a3612019-05-27 14:02:13 +0200706friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700707 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700708 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100709}
710
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700711private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100712 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600713 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100714}
715
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700716private function f_trxc_fake_toffs256(int16_t toffs256) 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_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100719}
720
721/* first function started in ConnHdlr component */
722private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
723runs on ConnHdlr {
724 g_pars := pars;
725 g_chan_nr := pars.chan_nr;
726
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200727 if (L1CTL.checkstate("Mapped")) {
728 f_connect_reset(L1CTL);
729 }
Harald Welte70767382018-02-21 12:16:40 +0100730
Harald Welted48c0c72019-06-05 10:01:15 +0200731 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700732 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
735 g_Tguard.start(pars.t_guard);
736 activate(as_Tguard());
737
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700738 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100739
740 /* call the user-supplied test case function */
741 fn.apply(id);
742}
743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700744private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
745 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200746runs on ConnHdlr return RSL_Message {
747 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100748 timer T := 3.0;
749 RSL.send(tx);
750 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100751 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200752 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100753 T.stop;
754 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100755 }
Harald Welte1eba3742018-02-25 12:48:14 +0100756 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100758 }
Harald Welte21240e62018-03-11 21:43:35 +0100759 [not ignore_other] as_l1_sacch();
760 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700761 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700762 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100765 }
Harald Welte21240e62018-03-11 21:43:35 +0100766 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100767 }
Harald Welteb1726c92018-03-30 11:56:38 +0200768 return rx;
769}
770
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700771friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
772 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200773runs on ConnHdlr {
774 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100775}
776
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300777/* Send the given measurement results to the IUT over the Um interface,
778 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
779friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
780runs on ConnHdlr {
781 var template (value) SacchL1Header l1h;
782 var octetstring l2, l3;
783 timer T;
784
785 /* RR Measurement Report to be sent */
786 var GsmRrL3Message meas_rep := {
787 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
788 payload := { meas_rep := { meas_res := valueof(meas_res) } }
789 };
790
791 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
792 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
793 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
794 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
795 g_pars.l1_pars.ms_actual_ta);
796
797 /* Send RR Measurement Report over the Um interface */
798 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
799
800 /* Expect MEASurement RESult on the A-bis/RSL interface */
801 T.start(2.0);
802 alt {
803 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
804 setverdict(pass);
805 }
806 [] RSL.receive { repeat; }
807 [] T.timeout {
808 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
810 }
811 }
812}
813
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700814friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
815 boolean encr_enable := false,
816 RSL_IE_List more_ies := {},
817 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
818runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200819 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200820 if (encr_enable) {
821 /* append encryption related IEs, if requested */
822 var RSL_IE_EncryptionInfo encr_info;
823 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
824 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
825encr_info})) };
826 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200827 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200828 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100829}
830
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700831friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100832 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 +0100833 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100834}
835
Harald Welte2f2b2b72019-05-31 22:24:57 +0200836friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200837 template RSL_IE_ChannelMode chan_mode,
838 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700839 uint8_t trx_nr := 0, float t_guard := 20.0) := {
840 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100841 chan_nr := valueof(chan_nr),
842 chan_mode := valueof(chan_mode),
843 t_guard := t_guard,
844 l1_pars := {
845 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100846 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100847 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100848 meas_ul := {
849 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200850 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100851 rxqual := 0
852 },
853 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 }
857 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200858 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200860 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200861 ms_actual_ta := mp_ms_actual_ta_exp,
862 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100863 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200864 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200865 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700866 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700867 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700868 fhp := {
869 enabled := false,
870 maio_hsn := ts_HsnMaio(0, 0),
871 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700872 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700873 }
Harald Welte70767382018-02-21 12:16:40 +0100874}
875
Vadim Yanitskiyf8a9df52022-03-12 13:29:26 +0300876/* This altstep triggers on receipt of a L1CTL DATA.ind matching the given
877 * RSL chan_nr/link_id and data templates. Used as a base for other altsteps. */
878private altstep as_l1ctl_dl_msg(out L1ctlDlMessage msg,
879 template (present) octetstring tr_data := ?,
880 template (present) RslChannelNr chan_nr := ?,
881 template (present) RslLinkId link_id := ?)
882runs on ConnHdlr {
883 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr, link_id, tr_data)) -> value msg;
884}
885
886/* This altstep is built on top of as_l1ctl_dl_msg(), and triggers on receipt
887 * of dummy LAPDm func=UI frames with empty payload. Repeats by default. */
888private altstep as_dl_lapdm_dummy(template (present) RslChannelNr chan_nr := ?,
889 template (present) RslLinkId link_id := ?,
890 template (present) LapdmSapi sapi := ?,
891 boolean do_repeat := true)
892runs on ConnHdlr {
893 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, ''O);
894 var L1ctlDlMessage dl_msg;
895
896 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, chan_nr, link_id) {
897 if (do_repeat) {
898 repeat;
899 }
900 }
901}
902
903/* This altstep triggers on receipt of a Downlink DCCH containing a L2 payload
904 * that matches the given LAPDm frame. The L2 is treated as LapdmFrameAB. */
905private altstep as_dl_dcch_lapdm_ab(out LapdmFrameAB frame,
906 template (present) LapdmFrameAB tr_frame := ?,
907 template (present) RslLinkId link_id := ?)
908runs on ConnHdlr {
909 var L1ctlDlMessage dl_msg;
910
911 [] as_l1ctl_dl_msg(dl_msg, decmatch tr_frame, g_chan_nr, link_id) {
912 frame := dec_LapdmFrameAB(dl_msg.payload.data_ind.payload);
913 }
914}
915
916/* This altstep is built on top of as_dl_dcch_lapdm_ab(), and triggers on receipt
917 * of a LAPDm AB frame with a L3 payload matching the given template. The L3
918 * payload is treated as PDU_ML3_NW_MS. */
919private altstep as_dl_dcch_pdu(out PDU_ML3_NW_MS pdu,
920 template (present) PDU_ML3_NW_MS tr_pdu := ?,
921 template (present) GsmSapi sapi := 0)
922runs on ConnHdlr {
923 template (present) LapdmFrame tr_frame := tr_LAPDm_UI(sapi, true, decmatch tr_pdu);
924 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(sapi);
925 var LapdmFrameAB lapdm_frame;
926
927 [] as_dl_dcch_lapdm_ab(lapdm_frame, tr_frame.ab, link_id) {
928 pdu := dec_PDU_ML3_NW_MS(lapdm_frame.payload);
929 }
930}
931
Harald Welte93640c62018-02-25 16:59:33 +0100932/***********************************************************************
933 * Channel Activation / Deactivation
934 ***********************************************************************/
935
Harald Welte70767382018-02-21 12:16:40 +0100936/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700937private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100938 for (var integer i := 0; i < 500; i := i+1) {
939 f_rsl_chan_act(g_pars.chan_mode);
940 f_rsl_chan_deact();
941 }
942 setverdict(pass);
943}
944testcase TC_chan_act_stress() runs on test_CT {
945 var ConnHdlr vc_conn;
946 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200947 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100948 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
949 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100951}
952
953/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700954private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100955 f_rsl_chan_act(g_pars.chan_mode);
956 /* attempt to activate the same lchan again -> expect reject */
957 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
958 alt {
959 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100961 }
962 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
963 setverdict(pass);
964 }
965 }
966 f_rsl_chan_deact();
967}
968testcase TC_chan_act_react() runs on test_CT {
969 var ConnHdlr vc_conn;
970 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100971 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100972 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
973 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100975}
976
977/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700978private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100979 timer T := 3.0;
980 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
981 T.start;
982 alt {
983 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
984 setverdict(pass);
985 }
986 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100988 }
989 }
990}
991testcase TC_chan_deact_not_active() runs on test_CT {
992 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100993 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100994 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
995 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100997}
998
999/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001000private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001001 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
1002 alt {
1003 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +01001005 }
1006 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
1007 setverdict(pass);
1008 }
1009 }
1010}
1011private type record WrongChanNrCase {
1012 RslChannelNr chan_nr,
1013 charstring description
1014}
1015private type record of WrongChanNrCase WrongChanNrCases;
1016private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
1017 chan_nr := chan_nr,
1018 description := desc
1019}
1020
1021testcase TC_chan_act_wrong_nr() runs on test_CT {
1022 var ConnHdlr vc_conn;
1023 var ConnHdlrPars pars;
1024
Harald Welte294b0a22018-03-10 23:26:48 +01001025 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001026
1027 var WrongChanNrCases wrong := {
1028 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
1029 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
1030 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
1031 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
1032 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
1033 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
1034 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
1035 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
1036 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
1037 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
1038 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
1039 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
1040 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
1041 };
1042
1043 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
1044 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
1045 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
1046 vc_conn.done;
1047 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001049}
1050
Harald Weltee613f962018-04-18 22:38:16 +02001051/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +02001052friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +02001053 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02001054 f_init();
Harald Weltee613f962018-04-18 22:38:16 +02001055
1056 /* test on each of the channels we have */
1057 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1058 pars.chan_nr := valueof(g_AllChanTypes[i]);
1059
1060 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1061 vc_conn := f_start_handler(fn, pars);
1062 vc_conn.done;
1063 }
1064
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001066}
1067
Harald Welte93640c62018-02-25 16:59:33 +01001068/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001069 * SACCH handling
1070 ***********************************************************************/
1071
1072private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1073 timer T_sacch := 3.0;
1074 T_sacch.start;
1075 alt {
1076 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001078 }
1079 [not exp] T_sacch.timeout {
1080 setverdict(pass);
1081 }
1082 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1083 setverdict(pass);
1084 }
1085 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001087 }
1088 [] L1CTL.receive { repeat; }
1089 [] RSL.receive { repeat; }
1090 }
1091}
1092
1093/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1094private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1095 f_l1_tune(L1CTL);
1096 RSL.clear;
1097
1098 /* activate the logical channel */
1099 f_est_dchan();
1100 L1CTL.clear;
1101
1102 /* check that SACCH actually are received as expected */
1103 f_exp_sacch(true);
1104
1105 /* deactivate SACCH on the logical channel */
1106 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1107 f_sleep(1.0);
1108 L1CTL.clear;
1109
1110 /* check that no SACCH are received anymore */
1111 f_exp_sacch(false);
1112
1113 /* release the channel */
1114 f_rsl_chan_deact();
1115 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1116}
1117testcase TC_deact_sacch() runs on test_CT {
1118 var ConnHdlr vc_conn;
1119 var ConnHdlrPars pars;
1120 f_init();
1121 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1122 //for (var integer i := 0; i < 1; i := i+1) {
1123 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1124 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1125 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1126 vc_conn.done;
1127 }
1128 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001130}
1131
Harald Welte55700662018-03-12 13:15:43 +01001132/* verify that given SACCH payload is present */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001133private function f_sacch_present(template octetstring l3_exp,
1134 boolean do_fail := true)
1135runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001136 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001137 timer T_sacch := 3.0;
1138 L1CTL.clear;
1139 T_sacch.start;
1140 alt {
1141 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1142 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1143 if (match(l3, l3_exp)) {
1144 setverdict(pass);
1145 } else {
1146 repeat;
1147 }
1148 }
1149 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001150 [not do_fail] T_sacch.timeout {
1151 log("Timeout waiting for SACCH ", l3_exp);
1152 }
1153 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001154 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001156 }
1157 }
1158}
1159
Harald Welte55700662018-03-12 13:15:43 +01001160/* verify that given SACCH payload is not present */
1161private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1162 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001163 timer T_sacch := 3.0;
1164 L1CTL.clear;
1165 T_sacch.start;
1166 alt {
1167 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1168 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1169 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001170 setverdict(fail, "Received unexpected SACCH ", dl);
1171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001172 } else {
1173 repeat;
1174 }
1175 }
1176 [] L1CTL.receive { repeat; }
1177 [] T_sacch.timeout {
1178 setverdict(pass);
1179 }
1180 }
1181}
1182
Harald Welte629cc6b2018-03-11 17:19:05 +01001183/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001184private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1185 /* Set a known default SACCH filling for SI5 */
1186 var octetstring si5 := f_rnd_octstring(19);
1187 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1188
1189 f_l1_tune(L1CTL);
1190 RSL.clear;
1191
1192 /* activate the logical channel */
1193 f_est_dchan();
1194
1195 /* check that the specified SI5 value is actually sent */
1196 f_sacch_present(si5);
1197
1198 /* release the channel */
1199 RSL.clear;
1200 f_rsl_chan_deact();
1201 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1202}
1203testcase TC_sacch_filling() runs on test_CT {
1204 var ConnHdlr vc_conn;
1205 var ConnHdlrPars pars;
1206 f_init();
1207 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1208 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1209 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1210 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1211 vc_conn.done;
1212 }
1213 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001215}
1216
Harald Welte629cc6b2018-03-11 17:19:05 +01001217/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001218private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1219 /* Set a known default SACCH filling for SI5 */
1220 var octetstring si5 := f_rnd_octstring(19);
1221 var octetstring si5_diff := f_rnd_octstring(19);
1222 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1223
1224 f_l1_tune(L1CTL);
1225 RSL.clear;
1226
1227 log("Activating channel, expecting standard SI5");
1228 /* activate the logical channel */
1229 f_est_dchan();
1230 /* check that the specified SI5 value is actually sent */
1231 f_sacch_present(si5);
1232
1233 /* set channel-specific different SI5 */
1234 log("Setting channel specific SACCH INFO, expecting it");
1235 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1236 /* check that the specified lchan-specific value is now used */
1237 f_sacch_present(si5_diff);
1238
1239 /* deactivate the channel and re-activate it, this should result in default SI5 */
1240 log("De-activating and re-activating channel, expecting standard SI5");
1241 f_rsl_chan_deact();
1242 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1243 /* Verify that the TRX-wide default SACCH filling is present again */
1244 f_sacch_present(si5);
1245
1246 /* release the channel */
1247 RSL.clear;
1248 f_rsl_chan_deact();
1249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1250}
1251testcase TC_sacch_info_mod() runs on test_CT {
1252 var ConnHdlr vc_conn;
1253 var ConnHdlrPars pars;
1254 f_init();
1255 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1256 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1257 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1258 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1259 vc_conn.done;
1260 }
1261 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001263}
1264
Harald Welte075d84c2018-03-12 13:07:24 +01001265/* Test SACCH scheduling of multiple different SI message types */
1266private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1267 var octetstring si5 := f_rnd_octstring(19);
1268 var octetstring si5bis := f_rnd_octstring(19);
1269 var octetstring si5ter := f_rnd_octstring(19);
1270 var octetstring si6 := f_rnd_octstring(19);
1271
1272 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1273 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1274 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1275 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1276
1277 f_l1_tune(L1CTL);
1278 RSL.clear;
1279
1280 /* activate the logical channel */
1281 f_est_dchan();
1282 L1CTL.clear;
1283
1284 /* check that SACCH actually are received as expected */
1285 f_sacch_present(si5);
1286 f_sacch_present(si5bis);
1287 f_sacch_present(si5ter);
1288 f_sacch_present(si6);
1289
1290 /* release the channel */
1291 f_rsl_chan_deact();
1292 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1293}
1294testcase TC_sacch_multi() runs on test_CT {
1295 var ConnHdlr vc_conn;
1296 var ConnHdlrPars pars;
1297 f_init();
1298 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1299 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1300 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1301 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1302 vc_conn.done;
1303 }
1304 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001306}
1307
Harald Welte55700662018-03-12 13:15:43 +01001308/* Test if SACH information is modified as expected */
1309private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1310 var octetstring si5 := f_rnd_octstring(19);
1311 var octetstring si6 := f_rnd_octstring(19);
1312
1313 /* First, configure both SI5 and SI6 to be transmitted */
1314 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1315 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1316
1317 f_l1_tune(L1CTL);
1318 RSL.clear;
1319
1320 /* activate the logical channel */
1321 f_est_dchan();
1322 L1CTL.clear;
1323
1324 /* check that SACCH actually are received as expected */
1325 f_sacch_present(si5);
1326 f_sacch_present(si6);
1327
1328 /* disable SI6 */
1329 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1330
1331 /* check that SI5 is still transmitted */
1332 f_sacch_present(si5);
1333 /* check if SI6 is now gone */
1334 f_sacch_missing(si6);
1335
1336 /* release the channel */
1337 f_rsl_chan_deact();
1338 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1339}
1340testcase TC_sacch_multi_chg() runs on test_CT {
1341 var ConnHdlr vc_conn;
1342 var ConnHdlrPars pars;
1343 f_init();
1344 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1345 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1346 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1347 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1348 vc_conn.done;
1349 }
1350 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001352}
1353
Harald Weltec8d363c2019-05-19 20:36:48 +02001354/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1355private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1356 var octetstring si5 := f_rnd_octstring(19);
1357 var octetstring si6 := f_rnd_octstring(19);
1358 var octetstring si5_specific := f_rnd_octstring(19);
1359 var octetstring si6_specific := f_rnd_octstring(19);
1360
1361 /* First, configure both SI5 and SI6 to be transmitted */
1362 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1363 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1364
1365 f_l1_tune(L1CTL);
1366 RSL.clear;
1367
1368 /* activate channel with different SACCH filling */
1369 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1370 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1371 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1372 }));
1373 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1374 RSL_IE_Body:{sacch_info := sacch_info})) };
1375 f_est_dchan(more_ies := addl_ies);
1376
1377 /* check that SACCH actually are received as expected */
1378 f_sacch_present(si5_specific);
1379 f_sacch_present(si6_specific);
1380
1381 /* release the channel */
1382 f_rsl_chan_deact();
1383 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1384}
1385testcase TC_sacch_chan_act() runs on test_CT {
1386 var ConnHdlr vc_conn;
1387 var ConnHdlrPars pars;
1388 f_init();
1389
1390 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1391 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1392 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1393 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1394 vc_conn.done;
1395 }
1396 /* TODO: do the above in parallel, rather than sequentially? */
1397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1398}
1399
Harald Welte8b01c792019-05-19 22:51:25 +02001400/* verify that SACCH DL transmission is started only if MS power IE present
1401 * see section 4.1.3 of 3GPP TS 48.058 */
1402private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1403 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001404 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001405
1406 f_l1_tune(L1CTL);
1407 RSL.clear;
1408
1409 /* Step 1: Activate ASYNC HO channel without MS power IE */
1410
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001411 var integer ho_ref := oct2int(f_rnd_octstring(1));
1412 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1413 RSL_IE_Body:{ handover_ref := ho_ref }));
1414 var RSL_IE_List addl_ies := {
1415 ho_ref_ie
1416 };
1417
Harald Welte8b01c792019-05-19 22:51:25 +02001418 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001419 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 +02001420 /* don't perform immediate assignment here, as we're testing non-IA case */
1421 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001422 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001423
1424 /* Verify that no DL SACCH is being received */
1425 f_sacch_missing(?);
1426
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001427 /* Send handover Access Burst and expect SACCH to start */
1428 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1429
1430 f_sacch_present(si5);
1431
Harald Welte8b01c792019-05-19 22:51:25 +02001432 f_rsl_chan_deact();
1433 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1434
1435
1436 /* Step 2: Activate ASYNC HO channel with MS power IE */
1437
1438 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001439 addl_ies := {
1440 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001441 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1442 };
1443 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1444 /* don't perform immediate assignment here, as we're testing non-IA case */
1445 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001446 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001447
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001448 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1449 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1450 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to remain present */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459}
1460testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1461 var ConnHdlr vc_conn;
1462 var ConnHdlrPars pars;
1463 f_init();
1464
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001465 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1466 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1467 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001468 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1469 vc_conn.done;
1470 }
1471 /* TODO: do the above in parallel, rather than sequentially? */
1472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1473}
1474
1475/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1476 * see section 4.1.4 of 3GPP TS 48.058 */
1477private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1478 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001479 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1480
Harald Welte8b01c792019-05-19 22:51:25 +02001481 var RSL_IE_List addl_ies;
1482
1483 f_l1_tune(L1CTL);
1484 RSL.clear;
1485
1486 /* Step 1: Activate SYNC HO channel without MS power IE */
1487
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001488 var integer ho_ref := oct2int(f_rnd_octstring(1));
1489 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1490 RSL_IE_Body:{ handover_ref := ho_ref }));
1491 addl_ies := {
1492 ho_ref_ie
1493 };
1494
Harald Welte8b01c792019-05-19 22:51:25 +02001495 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001496 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 +02001497 /* don't perform immediate assignment here, as we're testing non-IA case */
1498 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001499 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001500
1501 /* Verify that no DL SACCH is being received */
1502 f_sacch_missing(?);
1503
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001504 /* Send handover Access Burst and expect SACCH to start */
1505 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1506
1507 f_sacch_present(si5);
1508
Harald Welte8b01c792019-05-19 22:51:25 +02001509 f_rsl_chan_deact();
1510 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1511
1512
1513 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1514
1515 /* Activate channel on BTS side */
1516 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001517 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001518 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1519 };
1520 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1521 /* don't perform immediate assignment here, as we're testing non-IA case */
1522 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001523 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001524
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001525 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1526 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1527 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001528
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001529 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001530 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1531
1532 f_sacch_present(si5);
1533
Harald Welte8b01c792019-05-19 22:51:25 +02001534 f_rsl_chan_deact();
1535 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1536
1537
1538 /* Step 2b: Activate SYNC HO channel with TA IE */
1539
1540 /* Activate channel on BTS side */
1541 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001542 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001543 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1544 };
1545 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1546 /* don't perform immediate assignment here, as we're testing non-IA case */
1547 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001548 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001549
1550 /* Verify that no DL SACCH is being received */
1551 f_sacch_missing(?);
1552
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001553 /* Send handover Access Burst and expect SACCH to start */
1554 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1555
1556 f_sacch_present(si5);
1557
Harald Welte8b01c792019-05-19 22:51:25 +02001558 f_rsl_chan_deact();
1559 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1560
1561
1562 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1563
1564 /* Activate channel on BTS side */
1565 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001566 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001567 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1568 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1569 };
1570 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1571 /* don't perform immediate assignment here, as we're testing non-IA case */
1572 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001573 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001574
1575 /* Verify that DL SACCH is being received */
1576 f_sacch_present(si5);
1577
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001578 /* Send handover Access Burst and expect SACCH to remain present */
1579 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1580
1581 f_sacch_present(si5);
1582
Harald Welte8b01c792019-05-19 22:51:25 +02001583 f_rsl_chan_deact();
1584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1585}
1586testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1587 var ConnHdlr vc_conn;
1588 var ConnHdlrPars pars;
1589 f_init();
1590
Vadim Yanitskiyce96d352022-03-11 15:32:07 +03001591 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1592 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
1593 log(testcasename(), ": Starting for ", g_AllChanTypes[i]);
Harald Welte8b01c792019-05-19 22:51:25 +02001594 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1595 vc_conn.done;
1596 }
1597 /* TODO: do the above in parallel, rather than sequentially? */
1598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1599}
Harald Welte629cc6b2018-03-11 17:19:05 +01001600
1601
1602/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001603 * RACH Handling
1604 ***********************************************************************/
1605
Harald Welte8c24c2b2018-02-26 08:31:31 +01001606/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001607private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001608 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001609 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001610 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001611
Harald Welte8c24c2b2018-02-26 08:31:31 +01001612 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001613 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001614 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001615 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001616 if (emerg == true) {
1617 ra := f_rnd_ra_emerg();
1618 } else {
1619 ra := f_rnd_ra_cs();
1620 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001621 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1622 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001624 }
1625 fn_last := fn;
1626
1627 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001628 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001629 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001630 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001631 T.stop;
1632 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001633 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001635 }
1636 [] RSL_CCHAN.receive { repeat; }
1637 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001638 test_failed := true;
1639 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001640 }
1641 }
1642 }
Maxba06feb2019-03-05 10:52:46 +01001643 if (test_failed) {
1644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001645 }
Maxba06feb2019-03-05 10:52:46 +01001646 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001648}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001649
Philipp Maier16ade782020-07-08 21:36:00 +02001650/* Normal variant */
1651testcase TC_rach_content() runs on test_CT {
1652 f_TC_rach_content(emerg := false);
1653}
1654
1655/* Emergency call variant */
1656testcase TC_rach_content_emerg() runs on test_CT {
1657 f_TC_rach_content(emerg := true);
1658}
1659
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1661testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001662 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001663 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001664 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001665 f_l1_tune(L1CTL);
1666
1667 var GsmFrameNumber fn_last := 0;
1668 for (var integer i := 0; i < 1000; i := i+1) {
1669 var OCT1 ra := f_rnd_ra_cs();
1670 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1671 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001673 }
1674 fn_last := fn;
1675 }
1676 var integer rsl_chrqd := 0;
1677 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001678 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001679 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001680 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001681 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001682 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001683 repeat;
1684 }
1685 [] RSL_CCHAN.receive { repeat; }
1686 [] T.timeout { }
1687 }
1688 if (rsl_chrqd == 1000) {
1689 setverdict(pass);
1690 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001692 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001694}
1695
Harald Welte3453ab42019-05-24 21:19:58 +02001696private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1697 var charstring bts_str := "bts " & int2str(bts_nr);
1698 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1699}
1700
1701/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1702private template integer tr_rach_slots_per_interval := (90 .. 130);
1703
1704/* Expect 0 RACH load on an idle BTS that has just started up */
1705testcase TC_rach_load_idle_thresh0() runs on test_CT {
1706 var ASP_RSL_Unitdata rx_ud;
1707
1708 f_init_vty_bsc();
1709 /* send load indications even at 0% load */
1710 f_vty_load_ind_thresh(0);
1711 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1712 f_sleep(2.0);
1713
1714 f_init();
1715
Harald Weltee37f9a52020-10-11 20:45:23 +02001716 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1717 alt {
1718 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1719 [] RSL_CCHAN.receive { repeat }
1720 }
1721
Harald Welte3453ab42019-05-24 21:19:58 +02001722 timer T := 5.0;
1723 T.start;
1724 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001725 [] 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 +02001726 setverdict(pass);
1727 repeat;
1728 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001729 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001730 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1731 repeat;
1732 }
1733 [] RSL_CCHAN.receive {
1734 repeat;
1735 }
1736 [] T.timeout { }
1737 }
1738
1739 f_vty_load_ind_thresh(10);
1740 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1741}
1742
1743/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1744testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1745 var ASP_RSL_Unitdata rx_ud;
1746
1747 f_init_vty_bsc();
1748 f_init();
1749
1750 timer T := 5.0;
1751 T.start;
1752 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001753 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001754 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1755 repeat;
1756 }
1757 [] RSL_CCHAN.receive {
1758 repeat;
1759 }
1760 [] T.timeout {
1761 setverdict(pass);
1762 }
1763 }
1764
1765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1766}
1767
1768/* Expect 0 RACH load on an idle BTS that has just started up */
1769testcase TC_rach_load_count() runs on test_CT {
1770 var ASP_RSL_Unitdata rx_ud;
1771 var integer load_access_count := 0;
1772
1773 f_init_vty_bsc();
1774 /* send load indications even at 0% load */
1775 f_vty_load_ind_thresh(0);
1776 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1777 f_sleep(2.0);
1778 f_init();
1779
1780 f_init_l1ctl();
1781 f_sleep(1.0);
1782 f_l1_tune(L1CTL);
1783
Harald Welte52ae1682020-10-11 20:45:55 +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 var GsmFrameNumber fn_last := 0;
1791 for (var integer i := 0; i < 1000; i := i+1) {
1792 var OCT1 ra := f_rnd_ra_cs();
1793 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1794 if (fn == fn_last) {
1795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1796 }
1797 fn_last := fn;
1798 }
1799
1800 timer T := 5.0;
1801 T.start;
1802 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001803 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001804 -> value rx_ud {
1805 var RSL_IE_Body ie;
1806 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1807 load_access_count := load_access_count + ie.rach_load.access_count;
1808 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1809 setverdict(fail, "Access count cannot be < Busy count");
1810 }
1811 repeat;
1812 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001813 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001814 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1815 repeat;
1816 }
1817 [] RSL_CCHAN.receive {
1818 repeat;
1819 }
1820 [] T.timeout { }
1821 }
1822 if (load_access_count == 1000) {
1823 setverdict(pass);
1824 } else {
1825 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1826 }
1827
1828 f_vty_load_ind_thresh(10);
1829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1830}
1831
Harald Welte54a2a2d2018-02-26 09:14:05 +01001832private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001833 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001834 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001835 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001836 f_sleep(0.5);
1837
1838 /* Transmit RACH request + wait for confirmation */
1839 var OCT1 ra := f_rnd_ra_cs();
1840 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1841
1842 /* Check for expected result */
1843 timer T := 1.5;
1844 T.start;
1845 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001846 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001847 setverdict(pass);
1848 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001849 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001851 }
1852 [] RSL_CCHAN.receive { repeat; }
1853 [not expect_pass] T.timeout {
1854 setverdict(pass);
1855 }
1856 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001858 }
1859 }
1860}
1861
1862/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1863testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001864 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001865 f_init_l1ctl();
1866 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001867 f_sleep(1.0);
1868
1869 /* default max-ta is 63 (full range of GSM timing advance */
1870
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001871 /* We allow early arrival up to 2 symbols */
1872 f_rach_toffs(-1*256, true);
1873 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001874 f_rach_toffs(-10*256, false);
1875
1876 /* 0 / 32 / 63 bits is legal / permitted */
1877 f_rach_toffs(0, true);
1878 f_rach_toffs(32*256, true);
1879 f_rach_toffs(63*256, true);
1880
1881 /* more than 63 bits is not legal / permitted */
1882 f_rach_toffs(64*256, false);
1883 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001885}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001886
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001887private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001888 var GsmFrameNumber fn;
1889 var RSL_Message rm;
1890
1891 f_l1_tune(L1CTL);
1892 RSL.clear;
1893
1894 /* Generate a random Handover Reference */
1895 var integer ho_ref := oct2int(f_rnd_octstring(1));
1896
1897 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1898 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1899 RSL_IE_Body:{ handover_ref := ho_ref }));
1900
1901 /* Activate a channel on the BTS side (no encryption) */
1902 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1903 act_type := t_RSL_IE_ActType_HO_SYNC);
1904
1905 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1906 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001907 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001908
1909 /* Send handover Access Burst */
1910 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1911
1912 /* TODO: test mismatching Handover Reference, and missing IE */
1913
1914 /* Wait for handover detection */
1915 timer T := 3.0;
1916 T.start;
1917 alt {
1918 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1919 log("Handover RACH has been detected: ", rm);
1920 setverdict(pass);
1921 }
1922 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1924 log2str("RSL_CHAN_RQD was not expected: ", rm));
1925 }
1926 [] RSL.receive { repeat; }
1927 [] T.timeout {
1928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1929 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1930 }
1931 }
1932
1933 /* Release the channel */
1934 f_rsl_chan_deact();
1935 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1936}
1937
1938/* Test handover RACH detection */
1939testcase TC_ho_rach() runs on test_CT {
1940 var ConnHdlrPars pars;
1941 var ConnHdlr vc_conn;
1942
1943 f_init();
1944
1945 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1946 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1947 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1948 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1949 vc_conn.done;
1950 }
1951
1952 /* TODO: do the above in parallel, rather than sequentially? */
1953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1954}
1955
Harald Welte93640c62018-02-25 16:59:33 +01001956/***********************************************************************
1957 * Measurement Processing / Reporting
1958 ***********************************************************************/
1959
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001960private template (value) LapdmAddressField
1961ts_LapdmAddr(template (value) LapdmSapi sapi,
1962 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001963 spare := '0'B,
1964 lpd := 0,
1965 sapi := sapi,
1966 c_r := c_r,
1967 ea := true
1968}
1969
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001970private template (value) LapdmFrameAB
1971ts_LAPDm_AB(template (value) LapdmSapi sapi,
1972 template (value) GsmRrL3Message l3,
1973 template (value) boolean c_r := false,
1974 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001975 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001976 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001977 len := 0, /* overwritten */
1978 m := false,
1979 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03001980 payload := enc_GsmRrL3Message(valueof(l3)),
1981 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01001982}
1983
1984/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001985private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001986 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001987 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001988
Harald Weltef8df4cb2018-03-10 15:15:08 +01001989 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001990 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001991
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001992 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001993 g_pars.l1_pars.meas_ul.full.rxlev,
1994 g_pars.l1_pars.meas_ul.sub.rxlev,
1995 g_pars.l1_pars.meas_ul.full.rxqual,
1996 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001997 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001998
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001999 var template (value) SacchL1Header l1h := ts_SacchL1Header(
2000 g_pars.l1_pars.ms_power_level, false,
2001 g_pars.l1_pars.ms_actual_ta);
2002
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01002003 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
2004 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07002005
2006 log("Sending Measurement Report: ", l1h, l2);
2007 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01002008 repeat;
2009 }
2010}
2011
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002012/* handle incoming downlink SACCH, decode the L1 header into the given record */
2013private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
2014 boolean do_apply := true)
2015runs on ConnHdlr
2016{
2017 var L1ctlDlMessage l1_dl;
2018
2019 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2020 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
2021 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
2022 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
2023
2024 if (do_apply) {
2025 /* Update TA and MS power to follow what BTS requests */
2026 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
2027 }
2028 }
2029}
2030
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002031private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002032 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002033 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01002034 log("DCCH received: ", l1_dl.payload.data_ind.payload);
2035 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07002036 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2037 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01002038 repeat;
2039 }
2040}
2041
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002042private altstep as_l1_tch_loop() runs on ConnHdlr {
2043 var L1ctlDlMessage l1_dl;
2044 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
2045 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02002046
2047 /* occasionaly inject FACCH frames into the uplink */
2048 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
2049 var octetstring pl := '010301'O;
2050 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
2051 f_pad_oct(pl, 23, '2B'O)));
2052 } else {
2053 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
2054 l1_dl.payload.traffic_ind.data));
2055 }
2056
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002057 repeat;
2058 }
2059}
2060
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002061private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002062 uint6_t rxlev,
2063 uint3_t rxqual
2064}
2065
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002066private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002067 MeasElem full,
2068 MeasElem sub
2069}
2070
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002071private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002072 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002073 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002074 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002075 MeasElemFS meas_ul,
2076 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002077 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002078 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002079 uint8_t ms_actual_ta,
2080 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002081}
2082
2083/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2084private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2085 return 63 + (toffs256s/256);
2086}
2087
Harald Welted5684392018-03-10 18:22:04 +01002088private function f_max(integer a, integer b) return integer {
2089 if (a > b) {
2090 return a;
2091 } else {
2092 return b;
2093 }
2094}
2095
2096private function f_min(integer a, integer b) return integer {
2097 if (a < b) {
2098 return a;
2099 } else {
2100 return b;
2101 }
2102}
2103
2104/* compute negative tolerance val-tolerance, ensure >= min */
2105private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2106 val := val - tolerance;
2107 return f_max(val, min);
2108}
2109
2110/* compute positive tolerance val+tolerance, ensure <= max */
2111private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2112 val := val + tolerance;
2113 return f_min(val, max);
2114}
2115
2116/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2117private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2118return template integer {
2119 var template integer ret;
2120 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2121 return ret;
2122}
2123
2124
Harald Welte70767382018-02-21 12:16:40 +01002125/* build a template for matching measurement results against */
2126private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2127 var ConnL1Pars l1p := g_pars.l1_pars;
2128 var template RSL_IE_UplinkMeas ul_meas := {
2129 len := 3,
2130 rfu := '0'B,
2131 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002132 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002133 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002134 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002135 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002136 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2137 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002138 supp_meas_info := omit
2139 };
Harald Welte685d5982018-02-27 20:42:05 +01002140 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002141 ul_meas.len := (3+8);
2142 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002143 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002144 toa256_min := ?,
2145 toa256_max := ?,
2146 toa256_std_dev := ?
2147 }
Harald Welte685d5982018-02-27 20:42:05 +01002148 }
Harald Welte70767382018-02-21 12:16:40 +01002149 var template RSL_IE_BS_Power bs_power := {
2150 reserved := 0,
2151 epc := false,
2152 fpc := false,
2153 power_level := l1p.bs_power_level
2154 };
2155 var template RSL_IE_L1Info l1_info := {
2156 ms_power_lvl := l1p.ms_power_level,
2157 fpc := false,
2158 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002159 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002160 };
2161 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002162 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002163 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2164 ?, t_toffs);
2165}
2166
Philipp Maierdd841d32019-12-17 14:44:54 +01002167/* build a template for matching measurement results that do not contain any
2168 * MS related measurement (l1_info, l3_info and ms timing offset). */
2169private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2170 var ConnL1Pars l1p := g_pars.l1_pars;
2171 var template RSL_IE_UplinkMeas ul_meas := {
2172 len := 3,
2173 rfu := '0'B,
2174 dtx_d := l1p.dtx_enabled,
2175 rxlev_f_u := ?,
2176 reserved1 := '00'B,
2177 rxlev_s_u := ?,
2178 reserved2 := '00'B,
2179 rxq_f_u := ?,
2180 rxq_s_u := ?,
2181 supp_meas_info := omit
2182 };
2183 if (l1p.toa256_enabled) {
2184 ul_meas.len := (3+8);
2185 ul_meas.supp_meas_info := {
2186 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2187 toa256_min := ?,
2188 toa256_max := ?,
2189 toa256_std_dev := ?
2190 }
2191 }
2192 var template RSL_IE_BS_Power bs_power := {
2193 reserved := 0,
2194 epc := false,
2195 fpc := false,
2196 power_level := l1p.bs_power_level
2197 };
2198
2199 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2200}
2201
Harald Welte70767382018-02-21 12:16:40 +01002202/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002203private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002204 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002205 var boolean chan_est := false;
2206
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002207 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002208
2209 /* Receive osmocom specific measurement reports. This is the normal
2210 * case. Here we verify that the measurement reports we sent are
2211 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002212 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2213 /* increment counter of next to-be-expected meas rep */
2214 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2215 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002216 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002217
2218 /* The following two cases may only happen in the beginning
2219 * of the channel establishment phase. Once we have received
2220 * the "our" measurement report the first time, the channel
2221 * is established and empty or hardcoded TRXCON reports must
2222 * not occur anymore. */
2223 chan_est := true;
2224
2225 repeat;
2226 }
2227
2228 /* When the BTS has established the channel, the MS might need slightly
2229 * more time to establish the channel and actually start sending. The
2230 * result is then a measurement report that just lacks the measurement
2231 * information of the MS. This is normal and we tolerate this behavior. */
2232 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2233 /* increment counter of next to-be-expected meas rep */
2234 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2235 /* Re-start the timer expecting the next MEAS RES */
2236 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002237 repeat;
2238 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002239
2240 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2241 * measurements if the TTCN3 side does not supply measurement input in
2242 * time. In those cases TRXCON will either use a cached measurement
2243 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2244 * report the templates above will not match. We tolerate this
2245 * behavior, but only once. */
2246 [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 +01002247 /* increment counter of next to-be-expected meas rep */
2248 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2249 if (g_first_meas_res) {
2250 g_first_meas_res := false;
2251 repeat;
2252 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002254 }
Harald Welte70767382018-02-21 12:16:40 +01002255 }
2256 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002258 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002259 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002261 }
2262}
2263
Harald Weltee613f962018-04-18 22:38:16 +02002264private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2265 select (rsl_alg_id) {
2266 case (RSL_ALG_ID_A5_0) { return 0; }
2267 case (RSL_ALG_ID_A5_1) { return 1; }
2268 case (RSL_ALG_ID_A5_2) { return 2; }
2269 case (RSL_ALG_ID_A5_3) { return 3; }
2270 case (RSL_ALG_ID_A5_4) { return 4; }
2271 case (RSL_ALG_ID_A5_5) { return 5; }
2272 case (RSL_ALG_ID_A5_6) { return 6; }
2273 case (RSL_ALG_ID_A5_7) { return 7; }
2274 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2276 /* Make compiler happy by calling mtc.stop here. It is already
2277 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002278 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002279 }
2280 }
2281}
2282
2283private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2284 select (rsl_alg_id) {
2285 case (RSL_ALG_ID_A5_1) { return '000'B; }
2286 case (RSL_ALG_ID_A5_2) { return '001'B; }
2287 case (RSL_ALG_ID_A5_3) { return '010'B; }
2288 case (RSL_ALG_ID_A5_4) { return '011'B; }
2289 case (RSL_ALG_ID_A5_5) { return '100'B; }
2290 case (RSL_ALG_ID_A5_6) { return '101'B; }
2291 case (RSL_ALG_ID_A5_7) { return '110'B; }
2292 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2294 /* Make compiler happy by calling mtc.stop here. It is already
2295 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002296 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002297 }
2298 }
2299}
2300
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002301/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2302private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2303 var GsmFrameNumber fn;
2304 timer T := 8.0;
2305
2306 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2307 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2308
2309 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2310 /* Send the actual RACH */
2311 fn := f_L1CTL_RACH(L1CTL, ra);
2312
2313 T.start;
2314 alt {
2315 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2316 [] T.timeout {
2317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2318 }
2319 }
2320 T.stop
2321 return fn;
2322}
Harald Weltee613f962018-04-18 22:38:16 +02002323
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002324/* Tune to a dedicated channel: L1CTL only */
2325private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002326 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002327 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002328 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002329 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002330 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002331 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002332 pars.fhp.maio_hsn.hsn,
2333 pars.fhp.maio_hsn.maio,
2334 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002335 }
2336}
2337
Harald Welte70767382018-02-21 12:16:40 +01002338/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002339private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002340 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002341
2342 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002343 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002344
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002345 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002346 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002347 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002348 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002349 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2350 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002351 }
2352
Harald Welte70767382018-02-21 12:16:40 +01002353 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002354 f_l1ctl_est_dchan(L1CTL, g_pars);
2355
Harald Weltee613f962018-04-18 22:38:16 +02002356 /* enable encryption, if requested */
2357 if (encr_enable) {
2358 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2359 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2360 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002361
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002362 /* Send TCH Mode Request to the L1 if needed */
2363 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2364 var L1ctlTchMode tch_mode;
2365
2366 select (g_pars.chan_mode.coding_alg_rate) {
2367 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2368 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2369 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2370 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2371 case else {
2372 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2373 " is not supported by the L1, falling back to signalling");
2374 tch_mode := L1CTL_CHAN_MODE_SIGN;
2375 }
2376 }
2377
2378 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2379 }
2380
Harald Weltefa45e9e2018-03-10 18:59:03 +01002381 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002382}
2383
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002384/* Initialize and start the RTP emulation component for a ConnHdlr */
2385friend function f_rtpem_activate(inout octetstring payload,
2386 RtpemConfig cfg := c_RtpemDefaultCfg,
2387 RtpemMode mode := RTPEM_MODE_BIDIR)
2388runs on ConnHdlr {
2389 /* Step 0: initialize, connect and start the emulation component */
2390 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2391 map(vc_RTPEM:RTP, system:RTP);
2392 map(vc_RTPEM:RTCP, system:RTCP);
2393 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2394 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2395 vc_RTPEM.start(RTP_Emulation.f_main());
2396
2397 /* Step 1: configure the RTP parameters */
2398 var integer payload_len := 0;
2399 var octetstring hdr := ''O;
2400
2401 select (g_pars.chan_mode) {
2402 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2403 { payload_len := 33; hdr := 'D0'O; }
2404 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2405 { payload_len := 15; hdr := '00'O; }
2406 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2407 { payload_len := 31; hdr := 'C0'O; }
2408 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2409 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2411 }
2412 }
2413
2414 /* Pad the payload to conform the expected length */
2415 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2416 cfg.tx_fixed_payload := payload;
2417 f_rtpem_configure(RTPEM_CTRL, cfg);
2418
2419 /* Step 2: bind the RTP emulation to the configured address */
2420 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2421 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2422
2423 /* Step 3: send CRCX with the configured address/port to the IUT */
2424 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2425 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2426 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2427 "IPA CRCX ACK");
2428
2429 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2430 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2431 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2432 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2433
2434 /* Step 5: set the given RTP emulation mode */
2435 f_rtpem_mode(RTPEM_CTRL, mode);
2436}
2437
Harald Welte70767382018-02-21 12:16:40 +01002438/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002439private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002440 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002441 RSL.clear;
2442
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002443 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002444 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002445 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002446 }
Harald Welte70767382018-02-21 12:16:40 +01002447
2448 f_est_dchan();
2449
2450 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2451 * RSL measurement reports on Abis side */
2452 timer T := 8.0;
2453 T.start;
2454 alt {
2455 [] as_l1_sacch();
2456 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002457 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002458 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002459 [] L1CTL.receive { repeat; }
2460 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002461 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002462 * of any earlier errors, so if we reach this timeout, we're good */
2463 setverdict(pass);
2464 }
2465 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002467 }
2468 }
2469 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002470 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002471}
Harald Welte0472ab42018-03-12 15:02:26 +01002472
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002473/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2474private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002475 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002476 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2477 timer Tup := 10.0;
2478 Tup.start;
2479 alt {
2480 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2481 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2482 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002483
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002484 if (rx_lvl != max_rx_lvl) {
2485 repeat;
2486 }
2487 Tup.stop;
2488 }
2489 [] L1CTL.receive { repeat; }
2490 [] Tup.timeout {
2491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2492 log2str("Didn't reach full power ", max_rx_lvl));
2493 }
2494 }
2495 return max_rx_lvl;
2496}
2497
2498/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2499private function f_verify_ramp_up() runs on ConnHdlr {
2500 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002501 var integer initial_rx_lvl := -1;
2502 var integer last_rx_lvl := -1;
2503 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2504
2505 timer T := 2.0;
2506 alt {
2507 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2508 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2509 log("Received rx_level=", rx_lvl);
2510 if (initial_rx_lvl == -1) {
2511 initial_rx_lvl := rx_lvl;
2512 last_rx_lvl := rx_lvl;
2513
2514 /* Expect a somehow low value during first received messages */
2515 if (initial_rx_lvl >= max_rx_lvl / 2) {
2516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2517 log2str("Detected high initial tx power during ramp up: ",
2518 initial_rx_lvl , ", full power is", max_rx_lvl));
2519 }
2520 }
2521
2522 /* received Rx level bigger than maximum allowed power by CN */
2523 if (rx_lvl > max_rx_lvl) {
2524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2525 log2str("Detected Tx power higher than full power: ",
2526 rx_lvl , " > ", max_rx_lvl));
2527 }
2528
2529 /* Make sure it never decreases, since we are rumping up */
2530 if (last_rx_lvl > rx_lvl) {
2531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2532 log2str("Detected Tx power decrease during ramp up: ",
2533 last_rx_lvl , " -> ", rx_lvl));
2534 }
2535
2536 if (rx_lvl == max_rx_lvl and not T.running) {
2537 /* We reached the maximum power, start timer and receive
2538 /* a few more to make sure we don't surpass it */
2539 log("Reached full power, wating a bit more until success");
2540 T.start;
2541 }
2542
2543 last_rx_lvl := rx_lvl;
2544 repeat;
2545 }
2546 [] L1CTL.receive { repeat; }
2547 [] T.timeout { }
2548 }
2549
2550 /* We didn't increase tx power during ramp up */
2551 if (initial_rx_lvl < last_rx_lvl) {
2552 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2553 } else {
2554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2555 log2str("No Tx power increase during whole ramp up: ",
2556 initial_rx_lvl , " -> ", last_rx_lvl));
2557 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002558}
2559
2560/* verify BTS ramps power down to rx_level 0 */
2561private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2562 var L1ctlDlMessage l1_dl;
2563 var integer last_rx_lvl := max_rx_lvl;
2564
2565 timer Tdown := 5.0;
2566 Tdown.start;
2567 alt {
2568 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2569 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2570 log("Received rx_level=", rx_lvl);
2571
2572 /* received Rx level bigger than maximum allowed power by CN */
2573 if (rx_lvl > max_rx_lvl) {
2574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2575 log2str("Detected Tx power higher than full power: ",
2576 rx_lvl , " > ", max_rx_lvl));
2577 }
2578
2579 /* Make sure it never increases, since we are rumping down */
2580 if (last_rx_lvl < rx_lvl) {
2581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2582 log2str("Detected Tx power increase during ramp up: ",
2583 last_rx_lvl , " -> ", rx_lvl));
2584 }
2585
2586 last_rx_lvl := rx_lvl;
2587 if (last_rx_lvl != 0) {
2588 repeat;
2589 }
2590 /* we reached power level 0, we are done */
2591 Tdown.stop;
2592 }
2593 [] L1CTL.receive { repeat; }
2594 [] Tdown.timeout { }
2595 }
2596
2597 /* We didn't increase tx power during ramp down */
2598 if (max_rx_lvl > last_rx_lvl) {
2599 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2600 } else {
2601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2602 log2str("No Tx power decrease during whole ramp down: ",
2603 max_rx_lvl , " -> ", last_rx_lvl));
2604 }
2605}
2606
2607/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002608private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002609 f_l1_tune(L1CTL);
2610 RSL.clear;
2611
2612 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002613
2614 setverdict(pass);
2615}
2616testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2617 var ConnHdlr vc_conn;
2618 var ConnHdlrPars pars;
2619 f_init();
2620 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2621 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2622 pcu_comp := false, trxc_comp := true);
2623 vc_conn.done;
2624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2625}
2626
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002627/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002628private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002629 f_connhdlr_init_vty_bsc();
2630
2631 f_l1_tune(L1CTL);
2632 RSL.clear;
2633
2634 /* Wait until BTS is started and at full power */
2635 var integer max_rx_lvl := f_wait_ramp_up();
2636 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2637
2638 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2639 f_verify_ramp_down(max_rx_lvl);
2640
2641 setverdict(pass);
2642}
2643testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2644 var ConnHdlr vc_conn;
2645 var ConnHdlrPars pars;
2646 f_init();
2647 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2648 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2649 pcu_comp := false, trxc_comp := true);
2650 vc_conn.done;
2651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2652}
2653
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002654/* Verify Tx power:
2655 * + ramping down during ADM state UNLOCKED->LOCKED
2656 * + ramping up during ADM state LOCKED->UNLOCKED
2657 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002658private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002659 var L1ctlDlMessage l1_dl;
2660 var integer last_rx_lvl;
2661
2662 f_connhdlr_init_vty_bsc();
2663
2664 f_l1_tune(L1CTL);
2665 RSL.clear;
2666
2667 /* Wait until BTS is started and at full power */
2668 var integer max_rx_lvl := f_wait_ramp_up();
2669 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2670
2671 log("ADM STATE UNLOCKED->LOCKED");
2672 f_vty_enter_cfg_trx(BSCVTY);
2673 f_vty_transceive(BSCVTY, "rf_locked 1");
2674 last_rx_lvl := max_rx_lvl;
2675 f_verify_ramp_down(max_rx_lvl);
2676
2677 /* Let some time after we received 0dBm, then check we don't receive BCCH
2678 * anymore because scheduler has stopped after ramping down */
2679 f_sleep(2.0);
2680 L1CTL.clear;
2681 timer Tlocked := 2.0;
2682 Tlocked.start;
2683 alt {
2684 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2686 log2str("Received data_ind during rf_locked: ", l1_dl));
2687 }
2688 [] L1CTL.receive { repeat; }
2689 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2690 }
2691
2692 log("ADM STATE LOCKED->UNLOCKED");
2693 f_vty_transceive(BSCVTY, "rf_locked 0");
2694 f_verify_ramp_up();
2695 setverdict(pass);
2696}
2697testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2698 var ConnHdlr vc_conn;
2699 var ConnHdlrPars pars;
2700 f_init();
2701 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2702 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2703 pcu_comp := false, trxc_comp := true);
2704 vc_conn.done;
2705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2706}
2707
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002708private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002709 timer T := 8.0;
2710 T.start;
2711 var RSL_Message rsl;
2712 alt {
2713 [] as_l1_sacch();
2714 [] L1CTL.receive { repeat; }
2715 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2716 if (rsl.ies[3].body.bs_power.power_level == level) {
2717 setverdict(pass)
2718 } else {
2719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2720 }
2721 }
2722 [] T.timeout {
2723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2724 }
2725 }
2726}
2727
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002728/* See if the RSL MEASurement RESult contains expeced BS power level
2729 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002730private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002731 f_l1_tune(L1CTL);
2732 RSL.clear;
2733
2734 if (mp_bts_trxc_port != -1) {
2735 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2736 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2737 }
2738
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002739 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002740 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2741 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2742
2743 f_est_dchan(more_ies :={valueof(pwr)});
2744
2745 f_check_meas_bs_power_level(pwr_var);
2746
2747 f_rsl_chan_deact();
2748 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2749}
2750
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002751/* See if the RSL MEASurement RESult contains expeced BS power level
2752 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002753private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002754 f_l1_tune(L1CTL);
2755 RSL.clear;
2756
2757 if (mp_bts_trxc_port != -1) {
2758 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2759 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2760 }
2761
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002762 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002763 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2764
2765 f_est_dchan();
2766
2767 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2768
2769 f_check_meas_bs_power_level(pwr_var);
2770
2771 f_rsl_chan_deact();
2772 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2773}
2774
2775testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2776 var ConnHdlr vc_conn;
2777 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002778
Eric Wildae8f2622019-06-18 17:05:11 +02002779 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002780
2781 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2782 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2783 pcu_comp := false, trxc_comp := true);
2784 vc_conn.done;
2785
Eric Wildae8f2622019-06-18 17:05:11 +02002786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2787}
2788
2789testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2790 var ConnHdlr vc_conn;
2791 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002792
Eric Wildae8f2622019-06-18 17:05:11 +02002793 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002794
2795 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2796 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2797 pcu_comp := false, trxc_comp := true);
2798 vc_conn.done;
2799
Eric Wildae8f2622019-06-18 17:05:11 +02002800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2801}
2802
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002803/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2804 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2805 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002806private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002807 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002808 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002809
2810 f_trxc_fake_rssi(rxlev2dbm(10));
2811 f_l1_tune(L1CTL);
2812 RSL.clear;
2813
2814 var RSL_IE_List addl_ies;
2815 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2816
2817 addl_ies := {
2818 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2819 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2820 };
2821
2822 /* establish with power parameters */
2823 f_est_dchan(more_ies := addl_ies);
2824
2825 /* set a high value to ensure L1 power control level increases */
2826 f_trxc_fake_rssi(rxlev2dbm(20));
2827
2828 timer T2 := 6.0;
2829 T2.start;
2830 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002831 [] as_l1_sacch_l1h(l1h) {
2832 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002833 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002834 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002835 T2.stop;
2836 }
2837 [] L1CTL.receive { repeat; }
2838 [] T2.timeout {
2839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2840 "Power Level in L1 header has not increased sufficiently");
2841 }
2842 }
2843
2844 /* set a low value to ensure L1 power control level decreases */
2845 f_trxc_fake_rssi(rxlev2dbm(0));
2846
2847 timer T4 := 6.0;
2848 T4.start;
2849 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002850 [] as_l1_sacch_l1h(l1h) {
2851 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002852 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002853 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002854 T4.stop;
2855 setverdict(pass, "Power level in L1 decreased/increased as expected");
2856 }
2857 [] L1CTL.receive { repeat; }
2858 [] T4.timeout {
2859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2860 "Power Level in L1 header has not decreased sufficiently");
2861 }
2862 }
2863
2864 f_rsl_chan_deact();
2865 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2866
2867}
2868
2869/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002870private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002871 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002872 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002873
2874 /* set a low value to ensure power increases */
2875 f_trxc_fake_rssi(rxlev2dbm(10));
2876 f_l1_tune(L1CTL);
2877 RSL.clear;
2878
2879 var RSL_IE_List addl_ies;
2880 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2881
2882 addl_ies := {
2883 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2884 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2885 };
2886
2887 /* establish with power parameters */
2888 f_est_dchan(more_ies := addl_ies);
2889
2890 timer T1 := 10.0;
2891 T1.start;
2892 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002893 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002894 [] L1CTL.receive { repeat; }
2895 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002896 if (not isbound(l1h)) {
2897 setverdict(fail, "No SACCH blocks were received");
2898 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002899 setverdict(fail, "Power level in L1 header should not have changed");
2900 }
2901 }
2902 }
2903
2904 f_rsl_chan_deact();
2905 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2906
2907}
2908
2909/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002910private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002911 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002912 var uint5_t pwr_var := 15;
2913 var uint5_t pwr_max_var := f_get_max_power_from_band();
2914
2915 /* set a low value to ensure power increases */
2916 f_trxc_fake_rssi(rxlev2dbm(10));
2917 f_l1_tune(L1CTL);
2918 RSL.clear;
2919
2920 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2921 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2922
2923 /* establish with fixed power level */
2924 f_est_dchan(more_ies :={valueof(pwr)});
2925
2926 /* check our initial power level */
2927 f_wait_for_l1_power_level(pwr_var);
2928
2929 /* update power param to enable power loop
2930 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2931 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2932
2933 /* wait, then check that our power level was reduced */
2934 timer T1 := 10.0;
2935 T1.start;
2936 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002937 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002938 [] L1CTL.receive { repeat; }
2939 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002940 if (not isbound(l1h)) {
2941 setverdict(fail, "No SACCH blocks were received");
2942 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002943 setverdict(pass, "Power level in L1 header reduced as expected");
2944 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002945 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2946 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002947 }
2948 }
2949 }
2950
2951 f_rsl_chan_deact();
2952 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2953
2954}
2955
2956/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002957private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002958 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002959
2960 /* set a high value to ensure power decreases */
2961 f_trxc_fake_rssi(rxlev2dbm(50));
2962 f_l1_tune(L1CTL);
2963 RSL.clear;
2964
2965 var uint5_t pwr_var := 5;
2966 var uint5_t pwr_target_val := 15;
2967
2968 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2969 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2970
2971 /* establish with fixed power level */
2972 f_est_dchan(more_ies :={valueof(pwr)});
2973
2974 /* check our initial power level */
2975 f_wait_for_l1_power_level(pwr_var);
2976
2977 /* update power param to enable power loop
2978 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002979 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002980
2981 /* wait, then check that our power level was increased */
2982 timer T1 := 10.0;
2983 T1.start;
2984 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002985 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002986 [] L1CTL.receive { repeat; }
2987 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002988 if (not isbound(l1h)) {
2989 setverdict(fail, "No SACCH blocks were received");
2990 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2991 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002992 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002993 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002994 }
2995 }
2996 }
2997
2998 f_rsl_chan_deact();
2999 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3000
3001}
3002
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003003/* See if the power level remains constant when MS Power Parameters IE
3004 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003005private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003006 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02003007
3008 /* set a high value to ensure power decreases */
3009 f_trxc_fake_rssi(rxlev2dbm(50));
3010 f_l1_tune(L1CTL);
3011 RSL.clear;
3012
3013 var uint5_t pwr_var := 5;
3014
3015 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3016 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3017
3018 /* establish with fixed power level */
3019 f_est_dchan(more_ies :={valueof(pwr)});
3020
3021 /* check our initial power level */
3022 f_wait_for_l1_power_level(pwr_var);
3023
3024 /* wait, then check that our power level did not change */
3025 timer T1 := 10.0;
3026 T1.start;
3027 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003028 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3029 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02003030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3031 "BS power control should not be active unless we receive a power parameters IE!");
3032 }
3033 repeat;
3034 }
3035 [] L1CTL.receive { repeat; }
3036 [] T1.timeout { setverdict(pass); }
3037 }
3038
3039 f_rsl_chan_deact();
3040 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3041
3042}
3043
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02003044/* See if the power level remains constant when MS Power Parameters IE
3045 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003046private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003047 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02003048
3049 /* set a high value to ensure power decreases */
3050 f_trxc_fake_rssi(rxlev2dbm(50));
3051 f_l1_tune(L1CTL);
3052 RSL.clear;
3053
3054 var uint5_t pwr_var := 5;
3055
3056 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3057 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3058
3059 /* establish with fixed power level */
3060 f_est_dchan(more_ies :={valueof(pwr)});
3061
3062 /* check our initial power level */
3063 f_wait_for_l1_power_level(pwr_var);
3064
3065 /* pwr control without power params IE, should NOT activate MS power control*/
3066 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3067
3068 /* wait, then check that our power level did not change */
3069 timer T1 := 10.0;
3070 T1.start;
3071 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003072 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3073 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3075 "BS power control should not be active unless we receive a power parameters IE!");
3076 }
3077 repeat;
3078 }
3079 [] L1CTL.receive { repeat; }
3080 [] T1.timeout { setverdict(pass); }
3081 }
3082
3083 f_rsl_chan_deact();
3084 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3085
3086}
3087
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003088private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003089 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003090 timer T0 := 10.0;
3091 T0.start;
3092 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003093 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3094 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3096 "Power level in L1 header != signaled (RSL) power level.");
3097 }
3098 }
3099 [] L1CTL.receive { repeat; }
3100 [] T0.timeout {
3101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3102 "Timeout waiting for initial power level");
3103 }
3104 }
3105 T0.stop;
3106}
3107
3108private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3109 var IntegerRecord min_dbm_level;
3110 var IntegerRecord max_dbm_level;
3111 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3112
3113 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3114 if (min_dbm_level[i] == level) {
3115 return true;
3116 }
3117 }
3118 return false;
3119}
3120
3121private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3122 var IntegerRecord min_dbm_level;
3123 var IntegerRecord max_dbm_level;
3124 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3125
3126 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3127 if (max_dbm_level[i] == level) {
3128 return true;
3129 }
3130 }
3131 return false;
3132}
3133
3134private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3135 var IntegerRecord min_dbm_level;
3136 var IntegerRecord max_dbm_level;
3137 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3138 return max_dbm_level[0];
3139}
3140
3141type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003142private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003143private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3144 // 45.005 4.1.1
3145 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3146 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3147 2, 1, 0};
3148 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3149 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3150 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3151 var IntegerRecord rv;
3152
3153 select(band){
3154 case (BtsBand_allGSM){
3155 rv := gsm_power;
3156 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3157 max_dbm_level := {2, 1, 0};
3158 }
3159 case("DCS1800"){
3160 rv := dcs_power;
3161 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3162 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3163 }
3164 case("PCS1900"){
3165 rv := pcs_power;
3166 min_dbm_level := {15};
3167 max_dbm_level := {30};
3168 }
Harald Welte194b6912020-10-11 21:01:55 +02003169 case else {
3170 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3171 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003172 }
3173
3174 return rv;
3175}
3176
3177private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003178 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 +02003179}
3180
3181testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3182 var ConnHdlr vc_conn;
3183 var ConnHdlrPars pars;
3184 f_init();
3185 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3186 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3187 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3188 pars.bts0_band := f_vty_get_bts0_band();
3189 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3190 vc_conn.done;
3191 }
3192 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3194}
3195
3196testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3197 var ConnHdlr vc_conn;
3198 var ConnHdlrPars pars;
3199 f_init();
3200 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3201 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3202 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3203 pars.bts0_band := f_vty_get_bts0_band();
3204 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3205 vc_conn.done;
3206 }
3207 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3209}
3210
3211testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3212 var ConnHdlr vc_conn;
3213 var ConnHdlrPars pars;
3214 f_init();
3215 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3216 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3217 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3218 pars.bts0_band := f_vty_get_bts0_band();
3219 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3220 vc_conn.done;
3221 }
3222 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3224}
3225
3226testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3227 var ConnHdlr vc_conn;
3228 var ConnHdlrPars pars;
3229 f_init();
3230 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3231 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3232 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3233 pars.bts0_band := f_vty_get_bts0_band();
3234 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3235 vc_conn.done;
3236 }
3237 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3239}
3240
Eric Wild280ccb82019-06-17 11:11:52 +02003241testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3242 var ConnHdlr vc_conn;
3243 var ConnHdlrPars pars;
3244 f_init();
3245 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3246 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3247 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3248 pars.bts0_band := f_vty_get_bts0_band();
3249 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3250 vc_conn.done;
3251 }
3252 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3254}
3255
Eric Wild095024b2019-06-17 15:08:57 +02003256testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3257 var ConnHdlr vc_conn;
3258 var ConnHdlrPars pars;
3259 f_init();
3260 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3261 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3262 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3263 pars.bts0_band := f_vty_get_bts0_band();
3264 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3265 vc_conn.done;
3266 }
3267 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3269}
3270
Philipp Maier149c3922020-10-22 17:29:36 +02003271function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003272 var template RSL_IE_ChannelMode ch_mode;
3273 var ConnHdlr vc_conn;
3274 var ConnHdlrPars pars;
3275 f_init();
3276 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3277 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3278 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003279 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003280 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3281 pcu_comp := false, trxc_comp := true);
3282 vc_conn.done;
3283 }
3284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3285}
Philipp Maier149c3922020-10-22 17:29:36 +02003286
3287testcase TC_meas_res_speech_tchf() runs on test_CT {
3288 f_TC_meas_res_speech_tchf(false);
3289}
3290
3291testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3292 f_TC_meas_res_speech_tchf(true);
3293}
3294
3295function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003296 var template RSL_IE_ChannelMode ch_mode;
3297 var ConnHdlr vc_conn;
3298 var ConnHdlrPars pars;
3299 f_init();
3300 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3301 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3302 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003303 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003304 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3305 pcu_comp := false, trxc_comp := true);
3306 vc_conn.done;
3307 }
3308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3309}
Philipp Maier149c3922020-10-22 17:29:36 +02003310
3311testcase TC_meas_res_speech_tchh() runs on test_CT {
3312 f_TC_meas_res_speech_tchh(false)
3313}
3314
3315testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3316 f_TC_meas_res_speech_tchh(true)
3317}
3318
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003319testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3320 var template RSL_IE_ChannelMode ch_mode;
3321 var ConnHdlr vc_conn;
3322 var ConnHdlrPars pars;
3323 f_init();
3324 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3325 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3326 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3327 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3328 pars.l1_pars.toa256_enabled := true;
3329 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3330 pcu_comp := false, trxc_comp := true);
3331 vc_conn.done;
3332 }
3333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3334}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003335
Harald Welte70767382018-02-21 12:16:40 +01003336testcase TC_meas_res_sign_tchf() runs on test_CT {
3337 var ConnHdlr vc_conn;
3338 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003339 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003340 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003341 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003342 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003343 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3344 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003345 vc_conn.done;
3346 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003348}
3349testcase TC_meas_res_sign_tchh() runs on test_CT {
3350 var ConnHdlr vc_conn;
3351 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003352 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003353 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003354 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003355 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003356 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3357 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003358 vc_conn.done;
3359 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003361}
3362testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3363 var ConnHdlr vc_conn;
3364 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003365 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003366 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003367 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3368 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003369 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3370 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003371 vc_conn.done;
3372 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003374}
3375testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3376 var ConnHdlr vc_conn;
3377 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003378 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003379 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003380 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3381 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003382 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3383 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003384 vc_conn.done;
3385 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003387}
Harald Welte685d5982018-02-27 20:42:05 +01003388testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3389 var ConnHdlr vc_conn;
3390 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003391 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003392 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3393 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003394 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003395 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003396 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3397 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003398 vc_conn.done;
3399 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003401}
3402
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003403/* Make sure that we always get RSL MEASurement RESult messages regardless
3404 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3405private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3406 timer Texec := 8.0;
3407 timer Timpf := 2.0;
3408 timer Tmr;
3409
3410 f_l1_tune(L1CTL);
3411 RSL.clear;
3412
3413 f_est_dchan();
3414 L1CTL.clear;
3415
3416 /* Establish the main SAPI=0 link on DCCH first */
3417 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3418
3419 /* Give more time for the first RSL MEASurement RESult */
3420 Tmr.start(0.480 * 2.0);
3421 Texec.start; /* EXECution timer */
3422 Timpf.start; /* IMPFung timer */
3423
3424 alt {
3425 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3426 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3427 /* Reschedule the MEAS RES timer */
3428 Tmr.start(0.480 + 0.120);
3429 repeat;
3430 }
3431 [] RSL.receive { repeat; }
3432 [] Tmr.timeout {
3433 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3434 }
3435 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3436 [] Timpf.timeout {
3437 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3438 log("Injected SAPI=3 traffic on SACCH");
3439 Timpf.start;
3440 repeat;
3441 }
3442 /* We're good if survived so far */
3443 [] Texec.timeout {
3444 setverdict(pass);
3445 }
3446 }
3447
3448 f_rsl_chan_deact();
3449 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3450 f_rslem_unregister(0, g_chan_nr);
3451}
3452testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3453 var template RSL_IE_ChannelMode ch_mode;
3454 var template ConnHdlrPars pars;
3455 var ConnHdlr vc_conn;
3456
3457 f_init();
3458
3459 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3460 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3461
3462 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3463 vc_conn.done;
3464
3465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3466}
3467testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3468 var template RSL_IE_ChannelMode ch_mode;
3469 var template ConnHdlrPars pars;
3470 var ConnHdlr vc_conn;
3471
3472 f_init();
3473
3474 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3475 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3476
3477 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3478 vc_conn.done;
3479
3480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3481}
3482
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003483/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3484 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003485private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003486 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003487 var RSL_IE_MS_Power ms_power;
3488 var RSL_Message rsl;
3489 var uint5_t power_level := 0;
3490
3491 f_l1_tune(L1CTL);
3492 RSL.clear;
3493
3494 f_est_dchan();
3495
3496 ms_power.reserved := 0;
3497 ms_power.fpc_epc := false;
3498
3499 /* Send the first power control command. This will disable any BTS/TRX
3500 * internal power control and switch the MS (which is not in scope of
3501 * this test) to a constant power level. We start with a power level
3502 * of 0 */
3503 ms_power.power_level := power_level;
3504 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3505 RSL.send(rsl);
3506
3507 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003508 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3509 if (l1h.ms_power_lvl != power_level) {
3510 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3511 "match the signaled (RSL) power level := ", power_level);
3512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003513 }
3514
3515 /* Signal a new power level via RSL for the next turn. */
3516 if (power_level < 31) {
3517 power_level := power_level + 1;
3518 ms_power.power_level := power_level;
3519 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3520 RSL.send(rsl);
3521 repeat;
3522 }
3523
3524 }
3525
3526 /* Ignore all other blocks */
3527 [] L1CTL.receive { repeat; }
3528
3529 }
3530
3531 f_rsl_chan_deact();
3532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3533
3534 setverdict(pass);
3535}
3536
3537testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3538 var ConnHdlr vc_conn;
3539 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003540 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003541
3542 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3543 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3544 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3545 vc_conn.done;
3546 }
3547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3548}
Harald Welte70767382018-02-21 12:16:40 +01003549
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003550/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003551TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003552private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003553 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003554 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003555
3556 f_l1_tune(L1CTL);
3557 RSL.clear;
3558
3559 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003560 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003561
3562 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3563
3564
3565 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003566 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3567 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003568 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3569 }
3570
3571 }
3572
3573 /* Ignore all other blocks */
3574 [] L1CTL.receive { repeat; }
3575
3576 }
3577
3578 f_rsl_chan_deact();
3579 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3580
3581 setverdict(pass);
3582}
3583
3584testcase TC_rsl_chan_initial_ta() runs on test_CT {
3585 var ConnHdlr vc_conn;
3586 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003587 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003588 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003589 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3590 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003591 vc_conn.done;
3592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3593}
3594
Eric Wilde57e1a62019-05-28 13:30:55 +02003595/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003596private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003597 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003598 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003599
3600 var RSL_IE_MS_Power ms_power;
3601 ms_power.reserved := 0;
3602 ms_power.fpc_epc := false;
3603 ms_power.power_level := ms_power_level;
3604
3605 f_l1_tune(L1CTL);
3606 RSL.clear;
3607
3608 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3609
3610 timer T := 1.0;
3611 T.start;
3612 alt {
3613 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003614 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3615 if (l1h.ms_power_lvl != ms_power_level) {
3616 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3617 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003618 }
3619 }
3620 /* Ignore all other blocks */
3621 [] L1CTL.receive { repeat; }
3622 [] T.timeout {
3623 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3624 }
3625 }
3626
3627 f_rsl_chan_deact();
3628 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3629 setverdict(pass);
3630}
3631
3632testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3633 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3634 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3635}
3636
Harald Welte0472ab42018-03-12 15:02:26 +01003637/* 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 +01003638private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003639 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003640 RSL.clear;
3641
3642 f_est_dchan();
3643 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003644 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003645
3646 timer T := 40.0;
3647 T.start;
3648 alt {
3649 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3650 setverdict(pass)
3651 }
3652 [] RSL.receive { repeat };
3653 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003655 }
3656 }
3657 f_rsl_chan_deact();
3658}
3659testcase TC_conn_fail_crit() runs on test_CT {
3660 var ConnHdlr vc_conn;
3661 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003662 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003663 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3664 pars.t_guard := 60.0;
3665 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3666 vc_conn.done;
3667}
3668
Harald Welte93640c62018-02-25 16:59:33 +01003669/***********************************************************************
3670 * Paging
3671 ***********************************************************************/
3672
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003673private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003674 if (tmsi == 'FFFFFFFF'O) {
3675 return true;
3676 } else {
3677 return false;
3678 }
3679}
Harald Welte70767382018-02-21 12:16:40 +01003680
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003681private type record allowedFn { integer frame_nr }
3682private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3683private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3684private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3685private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3686private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3687private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3688private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3689private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3690private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003691{
3692 var integer frame_nr_51;
3693 frame_nr_51 := frame_nr mod 51
3694
3695 var allowedFn fn_check;
3696 fn_check.frame_nr := frame_nr_51;
3697
3698 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003700 return;
3701 }
3702
3703 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3704 return;
3705 }
3706 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3707 return;
3708 }
3709 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3710 return;
3711 }
3712 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3713 return;
3714 }
3715 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3716 return;
3717 }
3718 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3719 return;
3720 }
3721 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3722 return;
3723 }
3724 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3725 return;
3726 }
3727
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003729 return;
3730}
3731
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003732private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3733 inout integer num_paging_rcv_ids,
3734 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003735runs on test_CT {
3736 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003737 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003738 repeat;
3739 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003740 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003741 var octetstring without_plen :=
3742 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3743 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003744
3745 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3746
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003747 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3748 /* Ignore empty RR Paging Request (PCH filling) messages.
3749 * TODO: does it make sense to count them? */
3750 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003751 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3752 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003753 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003754 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3755 }
3756 } else if (match(rr, tr_PAGING_REQ2)) {
3757 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3758 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3759 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3760 }
3761 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3762 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3763 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003764 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003765 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3766 }
3767 } else if (match(rr, tr_PAGING_REQ3)) {
3768 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3769 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3770 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3771 }
3772 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3773 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3774 }
3775 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3776 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3777 }
3778 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3779 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3780 }
3781 }
3782 repeat;
3783 }
3784}
3785
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003786private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003787 boolean combined_ccch,
3788 integer bs_ag_blks_res,
3789 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003790 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3791 * paging command that is issued via RSL. */
3792 integer ps_load_modulus,
3793 /* Wait until the paging queue inside the BTS is congested before starting to add
3794 * pagings via the PCU socket (0 = disabled) */
3795 boolean ps_wait_cong,
3796 /* Maximum time to wait until the paging queue is drained at the end of the test.
3797 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3798 * to set this value to 18s, however the draining process may take significantly
3799 * longer when the queue contains paging requests for PS as those are implemented
3800 * as immediate assignments and require an entire MAC block alone. */
3801 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003802 boolean exp_load_ind,
3803 boolean exp_overload,
3804 boolean use_tmsi
3805}
3806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003807private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003808 integer num_paging_sent,
3809 integer num_paging_rcv_msgs,
3810 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003811 integer num_overload,
3812 /* When free space inside the paging queue reaches more than 2 thirds
3813 * of its capacity cong_detected is set to true. */
3814 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003815}
3816
Harald Welte68e495b2018-02-25 00:05:57 +01003817/* Helper function for paging related testing */
3818private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003819 /* Using the PCU socket affects the timing of the paging processing. We only
3820 * activate the PCU socket if we do paging load tests that include additional
3821 * paging load that is introduced through the PCU socket. */
3822 if (cfg.ps_load_modulus > 0) {
3823 f_init_with_pcuif();
3824 } else {
3825 f_init();
3826 }
Harald Welte68e495b2018-02-25 00:05:57 +01003827 f_init_l1ctl();
3828 f_l1_tune(L1CTL);
3829
Philipp Maierca058272021-06-23 10:35:23 +02003830 var octetstring imm_ass := f_rnd_octstring(23);
3831 var ASP_RSL_Unitdata load_ind;
3832
Harald Welte68e495b2018-02-25 00:05:57 +01003833 var PagingTestState st := {
3834 num_paging_sent := 0,
3835 num_paging_rcv_msgs := 0,
3836 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003837 num_overload := 0,
3838 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003839 };
3840
3841 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3842 var float max_pch_imsi_per_sec;
3843 if (cfg.use_tmsi) {
3844 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3845 } else {
3846 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3847 }
3848 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3849 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003850 var float time_total := 20.0;
3851 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3852 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003853
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003854 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3855 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003856
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003857 timer T_itv := 0.0;
3858 T_itv.start;
3859 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003860 alt {
3861 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003862 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003863 st.num_overload := st.num_overload + 1;
3864 repeat;
3865 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003866 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003868 }
Philipp Maierca058272021-06-23 10:35:23 +02003869 [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 +01003870 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003871
3872 /* Detect paging congestion: The logic inside the BTS will diagnose the
3873 * paging queue as congested when the fill state is more than 66% (which
3874 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3875 * paging congestion is detected pagings that are issued through the PCU
3876 * socket (PS) are dropped in order to prefer the CS related pagings. */
3877 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3878 st.cong_detected := true;
3879 }
3880
Harald Welte68e495b2018-02-25 00:05:57 +01003881 /* FIXME: analyze/verify interval + contents */
3882 repeat;
3883 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003884 /* ignore other RSL messages like RF RESource INDication */
3885 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003886 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003887 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003888 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003889 /* Only relevant when testing including with PCU sock connected */
3890 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003891 [] T_itv.timeout {
3892 /* Send paging cmds based on elapsed time */
3893 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3894 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003895 var MobileIdentityV mi;
3896
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003897 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003898 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003899 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003900 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003901 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003902 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003903
3904 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003905 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 +02003906
Philipp Maierca058272021-06-23 10:35:23 +02003907 /* Add additional pagings through the PCU socket interface. */
3908 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3909 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3910 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3911 }
3912 }
3913
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003914 st.num_paging_sent := st.num_paging_sent + 1;
3915 }
3916 if (st.num_paging_sent < pkt_total) {
3917 /* Wait for interval to next PAGING COMMAND */
3918 var float time_now := T_total.read;
3919 var float next_sched := int2float(st.num_paging_sent)*interval;
3920 if (next_sched > time_now) {
3921 T_itv.start(next_sched - time_now);
3922 } else {
3923 T_itv.start(0.0);
3924 }
3925 } else {
3926 /* We are done, no need to keep counting */
3927 T_total.stop;
3928 }
3929 }
3930 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003931 }
3932 }
3933
Philipp Maierca058272021-06-23 10:35:23 +02003934 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003935 T_wait.start;
3936 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003937 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003938 [] L1CTL.receive { repeat; }
3939 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003940 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003941 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003942 /* ignore other RSL messages like RF RESource INDication */
3943 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003944 /* Only relevant when testing including with PCU sock connected */
3945 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003946 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003947 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 +01003948 }
Harald Welte68e495b2018-02-25 00:05:57 +01003949 }
3950
3951 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3952 " rcvd_ids=", st.num_paging_rcv_ids);
3953 return st;
3954}
3955
3956/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3957 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3958 * - that CCCH LOAD IND (PCH) are being generated
3959 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3960testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003961 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003962 var PagingTestCfg cfg := {
3963 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003964 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003965 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003966 ps_load_modulus := 0,
3967 ps_wait_cong := false,
3968 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003969 exp_load_ind := true,
3970 exp_overload := false,
3971 use_tmsi := false
3972 };
3973 var PagingTestState st := f_TC_paging(cfg);
3974 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3976 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003977 } else {
3978 setverdict(pass);
3979 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003981}
3982
3983/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3984 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3985 * - that CCCH LOAD IND (PCH) are being generated
3986 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3987testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003988 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003989 var PagingTestCfg cfg := {
3990 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003991 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003992 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003993 ps_load_modulus := 0,
3994 ps_wait_cong := false,
3995 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003996 exp_load_ind := true,
3997 exp_overload := false,
3998 use_tmsi := true
3999 };
4000 var PagingTestState st := f_TC_paging(cfg);
4001 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
4003 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01004004 } else {
4005 setverdict(pass);
4006 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004008}
4009
4010/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
4011 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4012 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4013 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4014testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004015 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004016 var PagingTestCfg cfg := {
4017 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004018 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004019 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004020 ps_load_modulus := 0,
4021 ps_wait_cong := false,
4022 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004023 exp_load_ind := true,
4024 exp_overload := true,
4025 use_tmsi := false
4026 };
4027 var PagingTestState st := f_TC_paging(cfg);
4028 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4029 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004030 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004031 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004032 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 +01004033 } else {
4034 setverdict(pass);
4035 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004037}
4038
4039/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
4040 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
4041 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
4042 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
4043testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02004044 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01004045 var PagingTestCfg cfg := {
4046 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02004047 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01004048 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02004049 ps_load_modulus := 0,
4050 ps_wait_cong := false,
4051 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01004052 exp_load_ind := true,
4053 exp_overload := true,
4054 use_tmsi := true
4055 };
4056 var PagingTestState st := f_TC_paging(cfg);
4057 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4058 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004059 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004060 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004061 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 +01004062 } else {
4063 setverdict(pass);
4064 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004066}
4067
Philipp Maierca058272021-06-23 10:35:23 +02004068/* Same as above, but with additional paging load created by PS pagings that
4069 * are issued through the PCU socket. The additional load is introduced when
4070 * the paging queue is already two thirds full. Since the BTS implements a
4071 * prioritization logic that drops the pagings from the PCU under in those
4072 * congestive sitautions the behaviour on the PS side is expected to be
4073 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4074testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4075 var SystemInformation si3 := valueof(ts_SI3_default);
4076 var PagingTestCfg cfg := {
4077 combined_ccch := true,
4078 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4079 load_factor := 2.0,
4080 ps_load_modulus := 16,
4081 ps_wait_cong := true,
4082 queue_drain_timeout := 18.0,
4083 exp_load_ind := true,
4084 exp_overload := true,
4085 use_tmsi := false
4086 };
4087 var PagingTestState st := f_TC_paging(cfg);
4088 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4089 * slots and will fully drain that buffer before returning */
4090 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4091 if (not match(st.num_paging_rcv_ids, tpl)) {
4092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4093 } else {
4094 setverdict(pass);
4095 }
4096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4097}
4098
4099
Harald Welte68e495b2018-02-25 00:05:57 +01004100
Harald Welte93640c62018-02-25 16:59:33 +01004101/***********************************************************************
4102 * Immediate Assignment / AGCH
4103 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004104private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004105 len := 0,
4106 ma := ''B
4107}
Harald Welte93640c62018-02-25 16:59:33 +01004108
Harald Weltee8d750e2018-06-10 21:41:35 +02004109private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4110 return int2str(num_tx) & " sent, "
4111 & int2str(num_rx) & " received, "
4112 & int2str(num_del) & " deleted";
4113}
4114
4115private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4116 var L1ctlDlMessage l1_dl;
4117 timer T := 10.0;
4118 var integer num_tx := 0;
4119 var integer num_rx := 0;
4120 var integer num_del := 0;
4121 var charstring res_str;
4122 var float rx_ratio;
4123
Harald Welte10474062019-05-30 16:48:17 +02004124 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004125 f_init_l1ctl();
4126 f_l1_tune(L1CTL);
4127
4128 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004129 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004130 mp_trx_pars[0].arfcn,
4131 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004132 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4133 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004134 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004135 num_tx := num_tx+1;
4136 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004137 }
4138 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004139 T.start;
4140 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004141 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004142 num_del := num_del+1;
4143 repeat;
4144 }
4145 [] RSL_CCHAN.receive {
4146 repeat;
4147 }
4148 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004149 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4150 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4151 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004152 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004153 } else {
4154 num_rx := num_rx+1;
4155 }
4156 repeat;
4157 }
4158 [] L1CTL.receive { repeat; }
4159 [] T.timeout { }
4160 }
4161 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4162 log("AGCH test: " & res_str);
4163 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004165 }
4166 rx_ratio := int2float(num_rx) / int2float(num_tx);
4167 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004168 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 +02004169 } else {
4170 setverdict(pass);
4171 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004173}
4174
Harald Weltee8d750e2018-06-10 21:41:35 +02004175/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4176testcase TC_imm_ass_1000_20ms() runs on test_CT {
4177 f_TC_imm_ass(1000, 0.02, 0.25);
4178}
4179
4180/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4181testcase TC_imm_ass_200_0ms() runs on test_CT {
4182 f_TC_imm_ass(200, 0.0, 0.05);
4183}
4184
4185/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4186testcase TC_imm_ass_200_76ms() runs on test_CT {
4187 f_TC_imm_ass(150, 0.076, 1.00);
4188}
4189
4190
4191
Harald Welte48494ca2018-02-25 16:59:50 +01004192/***********************************************************************
4193 * BCCH
4194 ***********************************************************************/
4195
4196/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004197private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004198 GsmFrameNumber frame_number,
4199 SystemInformation si
4200}
4201
4202/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004203private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004204
4205/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004206private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004207
4208/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004209private function f_si_vecslot_contains(SystemInformationVector arr,
4210 RrMessageType key,
4211 boolean bcch_ext := false)
4212return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004213 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4214 var integer fn_mod51 := arr[i].frame_number mod 51;
4215 if (not bcch_ext and fn_mod51 == 2 or
4216 bcch_ext and fn_mod51 == 6) {
4217 if (arr[i].si.header.message_type == key) {
4218 return true;
4219 }
4220 }
4221 }
4222 return false;
4223}
4224
4225/* 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 +07004226private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4227 integer tc, RrMessageType key,
4228 boolean ext_bcch := false)
4229{
Harald Welte48494ca2018-02-25 16:59:50 +01004230 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004232 }
4233}
4234
4235/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004236private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4237 RrMessageType key)
4238return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004239 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4240 if (f_si_vecslot_contains(arr[tc], key) or
4241 f_si_vecslot_contains(arr[tc], key, true)) {
4242 return true;
4243 }
4244 }
4245 return false;
4246}
4247
4248/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004249private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4250 RrMessageType key,
4251 boolean bcch_ext := false,
4252 integer n := 1, integer m := 4)
4253return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004254 var integer count := 0;
4255 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4257 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004258 }
4259 for (var integer i:= 0; i < m; i := i + 1) {
4260 var integer fn_mod51 := arr[i].frame_number mod 51;
4261 if (not bcch_ext and fn_mod51 == 2 or
4262 bcch_ext and fn_mod51 == 6) {
4263 if (arr[i].si.header.message_type == key) {
4264 count := count + 1;
4265 }
4266 }
4267 }
4268 if (count >= n) {
4269 return true;
4270 } else {
4271 return false;
4272 }
4273}
4274
4275/* 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 +07004276private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4277 integer tc, RrMessageType key,
4278 boolean ext_bcch := false,
4279 integer n, integer m)
4280{
Harald Welte48494ca2018-02-25 16:59:50 +01004281 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004283 }
4284}
4285
4286/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004287private function f_si_vecslot_contains_only(SystemInformationVector arr,
4288 RrMessageType key,
4289 boolean bcch_ext := false)
4290return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004291 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4292 var integer fn_mod51 := arr[i].frame_number mod 51;
4293 if (not bcch_ext and fn_mod51 == 2 or
4294 bcch_ext and fn_mod51 == 6) {
4295 if (arr[i].si.header.message_type != key) {
4296 return false;
4297 }
4298 }
4299 }
4300 return true;
4301}
4302
4303/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004304private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4305 integer tc, RrMessageType key,
4306 boolean ext_bcch := false)
4307{
Harald Welte48494ca2018-02-25 16:59:50 +01004308 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004310 }
4311}
4312
4313/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004314private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004315 boolean bcch_extended,
4316 boolean si1_present,
4317 boolean si2bis_present,
4318 boolean si2ter_present,
4319 boolean si2quater_present,
4320 boolean si7_present,
4321 boolean si8_present,
4322 boolean si9_present,
4323 boolean si13_present,
4324 boolean si13alt_present,
4325 boolean si15_present,
4326 boolean si16_present,
4327 boolean si17_present,
4328 boolean si2n_present,
4329 boolean si21_present,
4330 boolean si22_present
4331}
4332
4333/* 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 +07004334private function f_validate_si_scheduling(SystemInformationConfig cfg,
4335 SystemInformationVectorPerTc si_per_tc)
4336{
Harald Welte48494ca2018-02-25 16:59:50 +01004337 var integer i;
4338 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4339 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004341 }
4342 }
4343 if (cfg.si1_present) {
4344 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4345 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4346 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4347 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4348 /* make sure *ALL* contain SI1 */
4349 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4350 }
4351 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4352 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4353 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4354 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4355 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4356 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4357
4358 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4359 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4360 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4361 * consecutive occurrences of TC = 4. */
4362 if (cfg.si2bis_present and not cfg.si2ter_present) {
4363 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4364 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4365 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4366 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4367 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4368 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4369 }
4370
4371 if (cfg.si7_present or cfg.si8_present) {
4372 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4373 * if System Information type 4 does not contain all information needed for cell
4374 * selection and reselection. */
4375 if (not cfg.bcch_extended) {
4376 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4377 }
4378 if (cfg.si7_present) {
4379 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4380 }
4381 if (cfg.si8_present) {
4382 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4383 }
4384 }
4385
4386 if (cfg.si2quater_present) {
4387 /* iii) System information type 2 quater is sent if needed, as determined by the system
4388 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4389 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4390 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4391 * within any of 4 consecutive occurrences of TC = 5. */
4392 if (not (cfg.bcch_extended)) {
4393 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4394 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4395 } else {
4396 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4397 }
4398 } else {
4399 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4400 }
4401 }
4402 if (cfg.si9_present) {
4403 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4404 * in system information type 3 as defined in 3GPP TS 44.018. */
4405 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4406 }
4407 if (cfg.si13_present) {
4408 /* vii) System Information type 13 is only related to the GPRS service. System Information
4409 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4410 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4411 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4412 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4413 * within any of 4 consecutive occurrences of TC=4. */
4414 if (not cfg.bcch_extended) {
4415 log("not-bccch-extended");
4416 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4417 } else {
4418 log("bccch-extended");
4419 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4420 }
4421 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004423 }
4424 }
4425 if (cfg.si16_present or cfg.si17_present) {
4426 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4427 * should not be sent in a cell where network sharing is used (see rule xv). */
4428 if (cfg.si22_present) {
4429 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4430 }
4431 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004433 }
4434 if (not cfg.bcch_extended) {
4435 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4436 }
4437 if (cfg.si16_present) {
4438 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4439 }
4440 if (cfg.si17_present) {
4441 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4442 }
4443 }
4444
4445 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4446 * broadcast information. The frequency with which they are sent is determined by the
4447 * system operator. System Information type 9 identifies the scheduling of System
4448 * Information type 18 and 20 messages. */
4449
4450 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4451 * Information Type 19 is present, then its scheduling shall be indicated in System
4452 * Information Type 9. */
4453
4454 if (cfg.si15_present) {
4455 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4456 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4457 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4458 * 4 consecutive occurrences of TC = 1. */
4459 if (not cfg.bcch_extended) {
4460 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4461 } else {
4462 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4463 }
4464 }
4465 if (cfg.si13alt_present) {
4466 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4467 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4468 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4469 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4470 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4471 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4472 * of TC = 4. */
4473 if (cfg.si13_present) {
4474 testcase.stop("Error: Cannot have SI13alt and SI13");
4475 }
4476 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004478 }
4479 if (not cfg.bcch_extended) {
4480 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4481 } else {
4482 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4483 }
4484 }
4485 if (cfg.si2n_present) {
4486 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4487 * as determined by the system operator. In the case that the message is sent on the
4488 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4489 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4490 * consecutive occurrences of TC = 4. */
4491 if (not cfg.bcch_extended) {
4492 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4493 } else {
4494 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4495 }
4496 }
4497 if (cfg.si21_present) {
4498 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4499 * determined by the system operator. If Extended Access Barring is in use in the cell
4500 * then this message is sent at least once within any of 4 consecutive occurrences of
4501 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4502 * cell then this message shall only be sent on BCCH Ext. */
4503 if (not cfg.bcch_extended) {
4504 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4505 } else {
4506 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4507 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004509 }
4510 }
4511 }
4512 if (cfg.si22_present) {
4513 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4514 * should not be sent in a cell where SoLSA is used (see rule viii). System
4515 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4516 * =2 and TC=6. */
4517 if (cfg.si16_present or cfg.si17_present) {
4518 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4519 }
4520 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4521 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004523 }
4524 if (not cfg.bcch_extended) {
4525 testcase.stop("Error: SI22 requires BCCH Extd!");
4526 } else {
4527 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4528 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4529 }
4530 }
4531}
4532
4533/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004534private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4535return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004536 timer T := duration;
4537 var SystemInformationVectorPerTc si_per_tc;
4538 var L1ctlDlMessage l1_dl;
4539
4540 /* initialize all per-TC vectors empty */
4541 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4542 si_per_tc[i] := {};
4543 }
4544
4545 /* flush all previous L1 queued msgs */
4546 pt.clear;
4547
4548 T.start;
4549 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004550 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004551 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4552 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4553 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004554 repeat;
4555 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004556
Harald Welte48494ca2018-02-25 16:59:50 +01004557 var integer tc := f_gsm_compute_tc(sig.frame_number);
4558 log("SI received at TC=", tc, ": ", sig.si);
4559 /* append to the per-TC bucket */
4560 si_per_tc[tc] := si_per_tc[tc] & { sig };
4561 repeat;
4562 }
4563 [] pt.receive { repeat; }
4564 [] T.timeout { }
4565 }
4566
4567 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4568 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4569 }
4570 log("si_per_tc=", si_per_tc);
4571 return si_per_tc;
4572}
4573
4574/* helper function: Set given SI via RSL + validate scheduling.
4575 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004576private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004577 var SystemInformationVectorPerTc si_per_tc;
4578 f_init_l1ctl();
4579 f_l1_tune(L1CTL);
4580
4581 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004582 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004583 f_validate_si_scheduling(si_cfg, si_per_tc);
4584
4585 setverdict(pass);
4586}
4587
4588testcase TC_si_sched_default() runs on test_CT {
4589 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004590 /* 2+3+4 are mandatory and set in f_init() */
4591 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004593}
4594
4595testcase TC_si_sched_1() runs on test_CT {
4596 f_init();
4597 si_cfg.si1_present := true;
4598 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004599 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004601}
4602
4603testcase TC_si_sched_2bis() runs on test_CT {
4604 f_init();
4605 si_cfg.si2bis_present := true;
4606 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4607 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004609}
4610
4611testcase TC_si_sched_2ter() runs on test_CT {
4612 f_init();
4613 si_cfg.si2ter_present := true;
4614 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4615 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004617}
4618
4619testcase TC_si_sched_2ter_2bis() runs on test_CT {
4620 f_init();
4621 si_cfg.si2bis_present := true;
4622 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4623 si_cfg.si2ter_present := true;
4624 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4625 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004627}
4628
4629testcase TC_si_sched_2quater() runs on test_CT {
4630 f_init();
4631 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004632 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004633 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004635}
4636
4637testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004638 /* NOTE: PCUIF connection is not used in this test case, but
4639 * without it the IUT would not broadcast SI13 (see OS#3075). */
4640 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004641 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004642 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004643 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004645}
4646
4647testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004648 /* NOTE: PCUIF connection is not used in this test case, but
4649 * without it the IUT would not broadcast SI13 (see OS#3075). */
4650 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004651 si_cfg.si2bis_present := true;
4652 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4653 si_cfg.si2ter_present := true;
4654 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4655 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004656 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004657 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004658 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004659 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004661}
4662
4663
Harald Welte68e495b2018-02-25 00:05:57 +01004664testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004665 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004666 /* FIXME: enable / disable individual BCCH info */
4667 //ts_RSL_BCCH_INFO(si_type, info);
4668 /* expect no ERROR REPORT after either of them *
4669 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004671}
4672
Harald Welte93640c62018-02-25 16:59:33 +01004673/***********************************************************************
4674 * Low-Level Protocol Errors / ERROR REPORT
4675 ***********************************************************************/
4676
Harald Welte01d982c2018-02-25 01:31:40 +01004677private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4678 timer T := 5.0;
4679 T.start;
4680 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004681 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004682 setverdict(pass);
4683 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004684 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004686 }
4687 [] RSL_CCHAN.receive {
4688 repeat;
4689 }
4690 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004692 }
4693 }
4694}
4695
4696/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4697testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004698 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004699 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4700 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004701 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004702
4703 f_exp_err_rep(RSL_ERR_PROTO);
4704}
4705
4706/* Provoke a mandatory IE error and match on ERROR REPORT */
4707testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004708 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004709
4710 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4711 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004712 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004713
4714 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4715}
4716
4717/* Provoke an IE content error and match on ERROR REPORT */
4718testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004719 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004720 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4721 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004722 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004723
4724 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4725}
4726
Harald Welteee25aae2019-05-19 14:32:37 +02004727/* attempt to activate channel with wrong RSL Message Discriminator IE */
4728function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4729 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4730 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4731 RSL.send(rsl);
4732 f_rslem_unregister(0, g_chan_nr);
4733}
4734testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4735 var ConnHdlr vc_conn;
4736 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4737
Harald Welte10474062019-05-30 16:48:17 +02004738 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004739
4740 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4741 vc_conn.done;
4742 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4743
4744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4745}
4746
4747/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004748private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004749 var template (value) RSL_Message rsl_tx;
4750 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4751 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4752 RSL.send(rsl_tx);
4753 f_rslem_unregister(0, g_chan_nr);
4754}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004755private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004756 var template (value) RSL_Message rsl_tx;
4757 /* we first have to activate the dedicated channel */
4758 f_rsl_chan_act(g_pars.chan_mode);
4759 /* ... to then send an invalid RLL message */
4760 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4761 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4762 RSL.send(rsl_tx);
4763 f_rslem_unregister(0, g_chan_nr);
4764}
4765testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4766 var ConnHdlr vc_conn;
4767 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4768 var template (value) RSL_Message rsl_tx;
4769
Harald Welte10474062019-05-30 16:48:17 +02004770 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004771
4772 /* Common Channel with wrong message type */
4773 RSL_CCHAN.clear;
4774 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4775 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004776 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004777 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4778
4779 /* TRX Management */
4780 RSL_CCHAN.clear;
4781 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4782 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004783 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004784 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4785
4786 /* Dedicated Channel */
4787 RSL_CCHAN.clear;
4788 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4789 vc_conn.done;
4790 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4791
4792 /* RLL */
4793 RSL_CCHAN.clear;
4794 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4795 vc_conn.done;
4796 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4797}
4798
4799/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004800private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004801 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4802 f_rslem_unregister(0, g_chan_nr);
4803}
4804testcase TC_err_rep_wrong_sequence() runs on test_CT {
4805 var ConnHdlr vc_conn;
4806 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4807
Harald Welte10474062019-05-30 16:48:17 +02004808 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004809
4810 RSL_CCHAN.clear;
4811 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4812 vc_conn.done;
4813 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4814}
4815
Harald Welte93640c62018-02-25 16:59:33 +01004816/***********************************************************************
4817 * IPA CRCX/MDCX/DLCS media stream handling
4818 ***********************************************************************/
4819
Harald Weltea871a382018-02-25 02:03:14 +01004820/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004821private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004822 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4823 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004824}
4825testcase TC_ipa_dlcx_not_active() runs on test_CT {
4826 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004827 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004828 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4829 vc_conn.done;
4830}
Harald Welte68e495b2018-02-25 00:05:57 +01004831
Harald Weltea3f1df92018-02-25 12:49:55 +01004832/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004833private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004834 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4835 "IPA CRCX ACK");
4836 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4837 "IPA CRCX NACK");
4838}
4839testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4840 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004841 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004842 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4843 vc_conn.done;
4844}
4845
4846/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004847private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004848 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4849 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004850 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004851 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4852 var uint7_t rtp_pt2 := f_rnd_int(127);
4853 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4854 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4855 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4856 "IPA MDCX ACK");
4857 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4858 "IPA DLCX ACK");
4859}
4860testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4861 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004862 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004863 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4864 vc_conn.done;
4865}
4866
Harald Welte3ae11da2018-02-25 13:36:06 +01004867/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004868private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004869 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4870 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004871 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004872 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4873 var uint7_t rtp_pt2 := f_rnd_int(127);
4874 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4875 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4876 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4877 "IPA MDCX ACK");
4878 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004879 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004880 remote_port := f_rnd_int(c_UINT16_MAX);
4881 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4882 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4883 "IPA MDCX ACK");
4884 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4885 "IPA DLCX ACK");
4886}
4887testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4888 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004889 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004890 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4891 vc_conn.done;
4892}
4893
Harald Welte9912eb52018-02-25 13:30:15 +01004894/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004895private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004896 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4897 "IPA CRCX NACK");
4898}
4899testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4900 var ConnHdlrPars pars;
4901 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004902 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004903
4904 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4905 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4906 vc_conn.done;
4907
4908 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4909 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4910 vc_conn.done;
4911}
4912
Harald Weltea3f1df92018-02-25 12:49:55 +01004913
Harald Welte883340c2018-02-28 18:59:29 +01004914/***********************************************************************
4915 * PCU Socket related tests
4916 ***********************************************************************/
4917
Harald Welte07bd2d22019-05-25 11:03:30 +02004918/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004919friend 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 +01004920runs on test_CT {
4921 timer T := 3.0;
4922
4923 /* we don't expect any RTS.req before PDCH are active */
4924 T.start;
4925 alt {
4926 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004928 }
4929 [] PCU.receive { repeat; }
4930 [] T.timeout { }
4931 }
4932
4933 /* Send PDCH activate request for known PDCH timeslot */
4934 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4935
4936 /* we now expect RTS.req for this timeslot (only) */
4937 T.start;
4938 alt {
4939 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4940 setverdict(pass);
4941 }
4942 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4943 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004945 }
4946 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004948 }
4949 [] PCU.receive { repeat; }
4950 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004952 }
4953 [not exp_success] T.timeout {
4954 setverdict(pass);
4955 }
4956 }
4957}
4958
Harald Welte07bd2d22019-05-25 11:03:30 +02004959/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004960friend 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 +01004961runs on test_CT {
4962 timer T := 3.0;
4963
4964 /* Send PDCH activate request for known PDCH timeslot */
4965 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 +02004966 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4967 * when it will actually have been executed in the BTS */
4968 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004969 PCU.clear;
4970 /* we now expect no RTS.req for this timeslot */
4971 T.start;
4972 alt {
4973 [] 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 +02004974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004975 }
4976 [] PCU.receive { repeat; }
4977 [] T.timeout {
4978 setverdict(pass);
4979 }
4980 }
4981}
4982
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004983friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004984 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004985 map(self:PCU, system:PCU);
4986 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004987 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4988}
4989
Harald Welte883340c2018-02-28 18:59:29 +01004990/* PDCH activation via PCU socket; check for presence of RTS.req */
4991testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004992 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004993
Harald Welte883340c2018-02-28 18:59:29 +01004994 f_TC_pcu_act_req(0, 0, 7, true);
4995}
4996
4997/* PDCH activation via PCU socket on non-PDCU timeslot */
4998testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004999 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005000
Harald Welte883340c2018-02-28 18:59:29 +01005001 f_TC_pcu_act_req(0, 0, 1, false);
5002}
5003
5004/* PDCH activation via PCU socket on wrong BTS */
5005testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005006 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005007
Harald Welte883340c2018-02-28 18:59:29 +01005008 f_TC_pcu_act_req(23, 0, 7, false);
5009}
5010
5011/* PDCH activation via PCU socket on wrong TRX */
5012testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005013 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005014
Harald Welte883340c2018-02-28 18:59:29 +01005015 f_TC_pcu_act_req(0, 23, 7, false);
5016}
5017
5018/* PDCH deactivation via PCU socket; check for absence of RTS.req */
5019testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005020 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005021
Harald Welte883340c2018-02-28 18:59:29 +01005022 /* Activate PDCH */
5023 f_TC_pcu_act_req(0, 0, 7, true);
5024 f_sleep(1.0);
5025 /* and De-Activate again */
5026 f_TC_pcu_deact_req(0, 0, 7);
5027}
5028
5029/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
5030testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005031 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01005032
Harald Welte883340c2018-02-28 18:59:29 +01005033 f_TC_pcu_deact_req(0, 0, 1);
5034}
5035
5036/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01005037function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01005038 var PCUIF_send_data sd;
5039 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005040 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005041
5042 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01005043 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01005044
Harald Welte883340c2018-02-28 18:59:29 +01005045 T.start;
5046 alt {
5047 [] 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 +01005048 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01005049 setverdict(pass);
5050 } else {
5051 repeat;
5052 }
5053 }
5054 [] PCU.receive { repeat; }
5055 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005057 }
5058 }
5059}
5060
Philipp Maier94c08482021-02-01 17:36:05 +01005061/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5062testcase TC_pcu_ver_si1() runs on test_CT {
5063 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5064 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5065}
5066
5067/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5068testcase TC_pcu_ver_si3() runs on test_CT {
5069 const octetstring si3 := '49012223242526272929AABBCC'O;
5070 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5071}
5072
5073/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5074testcase TC_pcu_ver_si13() runs on test_CT {
5075 const octetstring si13 := '01010203040506070909'O;
5076 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5077}
5078
Harald Welte883340c2018-02-28 18:59:29 +01005079private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5080
5081/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005082friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005083 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5084runs on test_CT
5085{
5086 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5087 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5088}
5089
5090/* 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 +02005091friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5092 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005093runs on test_CT
5094{
5095 var PCUIF_send_data sd;
5096
5097 timer T := 3.0;
5098 T.start;
5099 alt {
5100 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5101 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5102 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5103 sd.data.u.rts_req.fn, sapi, data);
5104 }
5105 [] PCU.receive { repeat; }
5106 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005108 }
5109 }
5110}
5111
5112/* Send DATA.req on invalid BTS */
5113testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005114 var TfiUsfArr tua := f_TfiUsfArrInit();
5115 var octetstring data := '0000'O & f_rnd_octstring(21);
5116
5117 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005118
Harald Welte883340c2018-02-28 18:59:29 +01005119 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005120 f_TfiUsfArrSet(tua, 7, 0);
5121 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5122 f_sleep(1.0);
5123
5124 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005125}
5126
5127/* Send DATA.req on invalid TRX */
5128testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005129 var TfiUsfArr tua := f_TfiUsfArrInit();
5130 var octetstring data := '0000'O & f_rnd_octstring(21);
5131
5132 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005133
Harald Welte883340c2018-02-28 18:59:29 +01005134 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005135 f_TfiUsfArrSet(tua, 7, 0);
5136 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5137 f_sleep(1.0);
5138
5139 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005140}
5141
5142/* Send DATA.req on invalid timeslot */
5143testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005144 var TfiUsfArr tua := f_TfiUsfArrInit();
5145 var octetstring data := '0000'O & f_rnd_octstring(21);
5146
5147 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005148
Harald Welte883340c2018-02-28 18:59:29 +01005149 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005150 f_TfiUsfArrSet(tua, 7, 0);
5151 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5152 f_sleep(1.0);
5153
5154 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005155}
5156
5157/* Send DATA.req on timeslot that hasn't been activated */
5158testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005159 var TfiUsfArr tua := f_TfiUsfArrInit();
5160 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005161
Harald Welte7162a612019-05-26 12:56:09 +02005162 f_virtphy_common();
5163
5164 f_TfiUsfArrSet(tua, 7, 0);
5165 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5166 f_sleep(1.0);
5167
5168 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005169}
5170
Harald Weltead033dc2019-05-25 17:28:16 +02005171private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005172 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5173 boolean wait_rts := true)
5174runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005175 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005176 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005177
5178 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005179 if (wait_rts) {
5180 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5181 } else {
5182 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5183 }
Harald Weltead033dc2019-05-25 17:28:16 +02005184
5185 T.start;
5186 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005187 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005188 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5189 setverdict(pass);
5190 }
Harald Welte7162a612019-05-26 12:56:09 +02005191 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5192 setverdict(fail, "Received unexpected ", rx_dl);
5193 }
Harald Weltead033dc2019-05-25 17:28:16 +02005194 [] L1CTL.receive {
5195 repeat;
5196 }
Harald Welte7162a612019-05-26 12:56:09 +02005197 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005198 setverdict(fail, "Timeout waiting for ", data);
5199 }
Harald Welte7162a612019-05-26 12:56:09 +02005200 [not expect_data] T.timeout {
5201 setverdict(pass);
5202 }
Harald Weltead033dc2019-05-25 17:28:16 +02005203 }
5204}
5205
5206private function f_disable_dynamic_ts() runs on test_CT
5207{
5208 f_init_vty_bsc();
5209 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5210 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5211 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5212 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005213 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005214}
5215
5216private function f_virtphy_common() runs on test_CT {
5217 f_disable_dynamic_ts();
5218 f_init_l1ctl();
5219 f_l1_tune(L1CTL);
5220}
5221
5222testcase TC_pcu_data_req_pdtch() runs on test_CT {
5223 var TfiUsfArr tua := f_TfiUsfArrInit();
5224 var octetstring data := '0000'O & f_rnd_octstring(21);
5225
5226 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005227
Harald Welte883340c2018-02-28 18:59:29 +01005228 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005229 f_TfiUsfArrSet(tua, 7, 0);
5230 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5231 f_sleep(1.0);
5232
5233 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005234}
5235
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005236/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005237testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005238 var TfiUsfArr tua := f_TfiUsfArrInit();
5239 var octetstring data := '0000'O & f_rnd_octstring(21);
5240
5241 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005242
Harald Welte883340c2018-02-28 18:59:29 +01005243 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005244 f_TfiUsfArrSet(tua, 7, 0);
5245 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5246 f_sleep(1.0);
5247
5248 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005249}
5250
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005251private function f_TC_pcu_ptcch_ul(uint16_t ra)
5252runs on test_CT {
5253 var template PCUIF_Message pcu_rach_ind;
5254 var PCUIF_send_data sd;
5255 var GsmFrameNumber fn;
5256 timer T;
5257
5258 /* Send an Access Burst on PTCCH/U over the Um-interface */
5259 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5260 chan_nr := ts_RslChanNr_PDCH(7),
5261 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5262
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005263 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5264 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005265
5266 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5267 T.start(52.0 * 4.615 / 1000.0);
5268 alt {
5269 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5270 log("Rx an Access Burst on the PCU interface: ", sd.data);
5271 setverdict(pass);
5272 T.stop;
5273 }
5274 [] PCU.receive { repeat; }
5275 [] T.timeout {
5276 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5277 /* Keep going, that's not the end of the world */
5278 }
5279 }
5280}
5281
5282testcase TC_pcu_ptcch() runs on test_CT {
5283 var L1ctlDlMessage dl;
5284 var octetstring data;
5285 timer T;
5286
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005287 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005288 f_init_l1ctl();
5289 f_l1_tune(L1CTL);
5290
5291 /* Activate PDCH channel on TS7 */
5292 f_TC_pcu_act_req(0, 0, 7, true);
5293
5294 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005295 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005296 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005297 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005298 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005299
5300 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5301 for (var integer i := 0; i < 16; i := i + 1) {
5302 log("Sending an Access Burst towards the L1CTL interface");
5303 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5304 }
5305
5306 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5307 data := f_rnd_octstring(23);
5308
5309 /* Verify PTCCH/D: send a random data block, make sure it's received */
5310 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5311 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5312
5313 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5314 * let's give it more time in case if we miss the beginning. */
5315 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5316 alt {
5317 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5318 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5319 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5320 frame := data)) -> value dl {
5321 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5322 setverdict(pass);
5323 T.stop;
5324 }
5325 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5326 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5327 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5328 l2_data := data)) -> value dl {
5329 log("Rx PTCCH/D data block on L1CTL: ", dl);
5330 setverdict(pass);
5331 T.stop;
5332 }
5333 [] L1CTL.receive { repeat; }
5334 [] T.timeout {
5335 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5336 }
5337 }
5338}
5339
Harald Welte883340c2018-02-28 18:59:29 +01005340/* Send AGCH from PCU; check it appears on Um side */
5341testcase TC_pcu_data_req_agch() runs on test_CT {
5342 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005343 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005344 f_init_l1ctl();
5345 f_l1_tune(L1CTL);
5346
5347 f_TC_pcu_act_req(0, 0, 7, true);
5348 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5349
5350 T.start;
5351 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005352 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005353 setverdict(pass);
5354 }
5355 [] L1CTL.receive { repeat; }
5356 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005358 }
5359 }
5360}
5361
Harald Welte928622b2019-05-26 13:22:59 +02005362/* Send AGCH from PCU; check it appears on Um side */
5363testcase TC_pcu_data_req_pch() runs on test_CT {
5364 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005365 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005366 f_init_l1ctl();
5367 f_l1_tune(L1CTL);
5368
5369 f_TC_pcu_act_req(0, 0, 7, true);
5370 /* three characters prefix: last 3 digits of IMSI as ASCII */
5371 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5372
5373 T.start;
5374 alt {
5375 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5376 setverdict(pass);
5377 }
5378 [] L1CTL.receive { repeat; }
5379 [] T.timeout {
5380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5381 }
5382 }
5383}
5384
Harald Welte883340c2018-02-28 18:59:29 +01005385/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5386testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5387 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005388 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005389 f_init_l1ctl();
5390 f_l1_tune(L1CTL);
5391
5392 /* append 3 last imsi digits so BTS can compute pagng group */
5393 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5394
5395 timer T := 0.5;
5396 T.start;
5397 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005398 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005399 /* TODO: verify paging group */
5400 setverdict(pass);
5401 }
5402 [] L1CTL.receive { repeat; }
5403 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005405 }
5406 }
5407}
5408
5409/* Send RACH from Um side, expect it to show up on PCU socket */
5410testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005411 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005412 f_init_l1ctl();
5413 f_l1_tune(L1CTL);
5414
5415 var GsmFrameNumber fn_last := 0;
5416 for (var integer i := 0; i < 1000; i := i+1) {
5417 var OCT1 ra := f_rnd_ra_ps();
5418 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5419 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005421 }
5422 fn_last := fn;
5423
5424 timer T := 2.0;
5425 T.start;
5426 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005427 [] 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 +01005428 T.stop;
5429 }
5430 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005432 }
5433 [] PCU.receive { repeat; }
5434 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005436 }
5437 }
5438 }
5439 setverdict(pass);
5440}
5441
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005442/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5443 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5444testcase TC_pcu_ext_rach_content() runs on test_CT {
5445 var template PCUIF_Message pcu_rach_ind;
5446 var GsmFrameNumber fn_last := 0;
5447 var L1ctlRachSynchSeq synch_seq;
5448 var PCUIF_BurstType pcu_bt;
5449 var GsmFrameNumber fn;
5450 var BIT11 ra11;
5451
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005452 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005453 f_init_l1ctl();
5454 f_l1_tune(L1CTL);
5455
5456 for (var integer i := 0; i < 1000; i := i+1) {
5457 /* We need to test both TS1 & TS2 */
5458 if (i rem 2 == 0) {
5459 synch_seq := RACH_SYNCH_SEQ_TS1;
5460 pcu_bt := BURST_TYPE_1;
5461 } else {
5462 synch_seq := RACH_SYNCH_SEQ_TS2;
5463 pcu_bt := BURST_TYPE_2;
5464 }
5465
5466 ra11 := f_rnd_ra11_ps();
5467 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5468 if (fn == fn_last) {
5469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5470 "Two RACH in same FN?!?");
5471 }
5472 fn_last := fn;
5473
5474 /* Compose the expected message */
5475 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005476 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005477 ra := bit2int(ra11),
5478 is_11bit := 1,
5479 burst_type := pcu_bt,
5480 fn := fn);
5481
5482 timer T := 2.0;
5483 T.start;
5484 alt {
5485 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5486 T.stop;
5487 }
5488 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5490 }
5491 [] PCU.receive { repeat; }
5492 [] T.timeout {
5493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5494 }
5495 }
5496 }
5497 setverdict(pass);
5498}
5499
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005500private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5501runs on test_CT {
5502 var template PCUIF_send_data sdt;
5503 var PCUIF_send_data sd;
5504 var int16_t lqual_cb;
5505 timer T := 1.0;
5506
5507 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5508 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5509
5510 /* Send a random PDTCH frame over Um */
5511 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5512 '0000'O & f_rnd_octstring(21)));
5513
5514 T.start;
5515 alt {
5516 /* If expected link quality is above the threshold */
5517 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5518 lqual_cb := sd.data.u.data_ind.lqual_cb;
5519 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5520
5521 /* Make sure the actual link quality matches the expected value */
5522 if (not match(lqual_cb, lqual_cb_exp)) {
5523 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5524 "expected value ", lqual_cb_exp));
5525 } else {
5526 setverdict(pass);
5527 }
5528 }
5529 /* If expected link quality is below the threshold */
5530 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5532 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5533 }
5534 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5535 [] PCU.receive { repeat; }
5536 [lqual_cb_exp < thresh] T.timeout {
5537 log("Rx nothing, as expected");
5538 setverdict(pass);
5539 }
5540 [lqual_cb_exp >= thresh] T.timeout {
5541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5542 "Timeout waiting for PCUIF_DATA.ind");
5543 }
5544 }
5545}
5546
5547/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5548testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005549 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005550 PCU.clear;
5551
5552 f_init_l1ctl();
5553 f_l1_tune(L1CTL);
5554
5555 /* Activate a PDCH channel on TS7 */
5556 f_TC_pcu_act_req(0, 0, 7, true);
5557
5558 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005559 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005560 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005561 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005562 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005563
5564 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5565 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5566 var TrxcMessage ret;
5567
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005568 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005569
5570 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5571 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5572 }
5573}
5574
Harald Welte883340c2018-02-28 18:59:29 +01005575/* Send PAGING via RSL, expect it to shw up on PCU socket */
5576testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005577 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005578
5579 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005580 var MobileIdentityLV mi_lv;
5581 var octetstring mi_lv_enc;
5582 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005583 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005584
Harald Welte883340c2018-02-28 18:59:29 +01005585 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005586 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005587 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005588 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005589 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005590
5591 /* Fancy encoding for PCUIF */
5592 mi_lv := valueof(ts_MI_LV(mi));
5593 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5594 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005595
5596 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005597 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005598 T.start;
5599 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005600 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005601 }
5602 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005604 }
5605 [] PCU.receive { repeat; }
5606 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005608 }
5609 }
5610 }
5611 setverdict(pass);
5612}
5613
Harald Welted66c9b82019-05-25 09:03:15 +02005614/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5615testcase TC_pcu_time_ind() runs on test_CT {
5616 var PCUIF_send_data pcu_sd;
5617 var integer num_time_ind := 0;
5618 var integer first_fn, last_fn;
5619 var float test_duration := 5.0;
5620 timer T;
5621
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005622 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005623 f_TC_pcu_act_req(0, 0, 7, true);
5624
5625 PCU.clear;
5626 T.start(test_duration);
5627 alt {
5628 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5629 num_time_ind := num_time_ind + 1;
5630 if (not isbound(first_fn)) {
5631 first_fn := pcu_sd.data.u.time_ind.fn;
5632 }
5633 last_fn := pcu_sd.data.u.time_ind.fn;
5634 repeat;
5635 }
5636 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5637 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5638 repeat;
5639 }
5640 [] PCU.receive {
5641 repeat;
5642 }
5643 [] T.timeout {}
5644 }
5645 var integer fn_expired := last_fn - first_fn;
5646 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5647
5648 /* verify the number of frames expired matches our expectation */
5649 const float c_GSM_FN_DURATION_MS := 4.61538;
5650 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005651 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005652 if (not match(fn_expired, t_fn_expected)) {
5653 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5654 }
5655
5656 /* There are three TIME.ind in every fn MOD 13 */
5657 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5658 /* Add some tolerance */
5659 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5660 if (not match(num_time_ind, t_time_ind_exp)) {
5661 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5662 }
5663
5664 setverdict(pass);
5665}
5666
Harald Welte4832c862019-05-25 14:57:18 +02005667/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5668testcase TC_pcu_rts_req() runs on test_CT {
5669 var PCUIF_send_data pcu_sd;
5670 var integer first_fn, last_fn;
5671 var integer num_rts_pdtch := 0;
5672 var integer num_rts_ptcch := 0;
5673 var float test_duration := 5.0;
5674 timer T;
5675
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005676 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005677 f_TC_pcu_act_req(0, 0, 7, true);
5678
5679 PCU.clear;
5680 T.start(test_duration);
5681 alt {
5682 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5683 -> value pcu_sd {
5684 num_rts_pdtch := num_rts_pdtch + 1;
5685 if (not isbound(first_fn)) {
5686 first_fn := pcu_sd.data.u.rts_req.fn;
5687 }
5688 last_fn := pcu_sd.data.u.rts_req.fn;
5689 repeat;
5690 }
5691 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5692 -> value pcu_sd {
5693 num_rts_ptcch := num_rts_ptcch + 1;
5694 if (not isbound(first_fn)) {
5695 first_fn := pcu_sd.data.u.rts_req.fn;
5696 }
5697 last_fn := pcu_sd.data.u.rts_req.fn;
5698 repeat;
5699 }
5700 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5701 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5702 repeat;
5703 }
5704 [] PCU.receive {
5705 repeat;
5706 }
5707 [] T.timeout {}
5708 }
5709 var integer fn_expired := last_fn - first_fn;
5710 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5711 ", num_rts_ptcch=", num_rts_ptcch);
5712
5713 /* verify the number of frames expired matches our expectation */
5714 const float c_GSM_FN_DURATION_MS := 4.61538;
5715 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005716 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005717 if (not match(fn_expired, t_fn_expected)) {
5718 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5719 }
5720
5721 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5722 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5723 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5724 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5725 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5726 t_ptcch_exp);
5727 }
5728
5729 /* We have 12 PDTCH blocks every 52-multiframe */
5730 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5731 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5732 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5733 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5734 t_pdtch_exp);
5735 }
5736
5737 setverdict(pass);
5738}
5739
Harald Welte07bd2d22019-05-25 11:03:30 +02005740/* test for generating Abis side OML ALERT from the PCU */
5741testcase TC_pcu_oml_alert() runs on test_CT {
5742 var PCUIF_send_data pcu_sd;
5743 var integer num_time_ind := 0;
5744 var integer first_fn, last_fn;
5745 var float test_duration := 5.0;
5746 timer T;
5747
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005748 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005749 f_TC_pcu_act_req(0, 0, 7, true);
5750
5751 /* re-connect CTRL port from BTS to BSC */
5752 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005753 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005754
5755 /* Send that OML Alert */
5756 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5757
5758 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5759 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5760 setverdict(pass);
5761}
5762
Harald Welteeaa9a862019-05-26 23:01:08 +02005763/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5764private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5765 var PCUIF_Message first_info;
5766 var integer pcu_conn_id := -1;
5767 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5768 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5769 var OCT4 tlli := '01020304'O;
5770 var OCT1 cause := '23'O;
5771 timer T := 5.0;
5772
5773 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5774
5775 f_l1_tune(L1CTL);
5776 RSL.clear;
5777
5778 f_est_dchan();
5779 L1CTL.clear;
5780
5781 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5782
5783 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5784 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5785 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5786
5787 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5788 T.start;
5789 alt {
5790 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5791 setverdict(pass);
5792 }
5793 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5794 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5795 }
5796 [] PCU.receive {
5797 repeat;
5798 }
5799 [] T.timeout {
5800 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5801 }
5802 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005803
5804 /* release the channel */
5805 f_rsl_chan_deact();
5806 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5807 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005808}
5809testcase TC_pcu_rr_suspend() runs on test_CT {
5810 var ConnHdlrPars pars;
5811 var ConnHdlr vc_conn;
5812
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005813 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005814
5815 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5816 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5817 vc_conn.done;
5818}
Harald Welte07bd2d22019-05-25 11:03:30 +02005819
Harald Weltea2e0e942019-05-27 18:12:53 +02005820/* Ensure that PCUIF socket can accept only a single connection */
5821testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005822 var boolean connected := false;
5823 var UD_connect_result cr;
5824 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005825 timer T := 5.0;
5826
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005827 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5828 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5829
Harald Weltea2e0e942019-05-27 18:12:53 +02005830 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005831 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005832
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005833 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005834 PCU.send(UD_connect:{mp_pcu_socket, -1});
5835 T.start;
5836 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005837 /* the IUT will first accept() the new connection, and close() it immediately */
5838 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5839 log("BTS has accept()ed connection");
5840 connected := true;
5841 cid := cr.id;
5842 repeat;
5843 }
5844 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5845 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005846 setverdict(pass);
5847 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005848 /* ignore other messages related to the first connection */
5849 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005850 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005851 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005852 }
5853 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005854
Harald Weltea2e0e942019-05-27 18:12:53 +02005855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5856}
5857
Harald Weltec8effb72019-05-27 18:23:04 +02005858/* Ensure that PCUIF socket can disconnect + reconnect */
5859testcase TC_pcu_socket_reconnect() runs on test_CT {
5860 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005861 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005862
5863 f_sleep(1.0);
5864
5865 f_pcuif_close(PCU, g_pcu_conn_id);
5866 g_pcu_conn_id := -1;
5867
5868 f_sleep(1.0);
5869
5870 /* re-connect */
5871 PCU.clear;
5872 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5873 setverdict(pass);
5874
5875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5876}
5877
Harald Weltebe030482019-05-27 22:29:35 +02005878/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005879private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5880runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005881 var L1ctlDlMessage l1_dl;
5882 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005883 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005884 timer T := 5.0;
5885 T.start;
5886 alt {
5887 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005888 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5889 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005890 repeat;
5891 }
5892 }
5893 [] pt.receive {
5894 repeat;
5895 }
5896 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5898 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005899 }
5900 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005901 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005902}
5903
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005904/* Check if GPRS Indicator is present in RR System Information of a given type */
5905private function f_si_has_gprs_indicator(RrMessageType si_type)
5906runs on test_CT return boolean {
5907 var SystemInformation si := f_get_si(L1CTL, si_type);
5908
5909 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005910 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005911 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005912 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005913 }
5914
5915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5916 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005917}
5918
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005919/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5920private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5921runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005922 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005923 f_init_l1ctl();
5924 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005925 f_sleep(2.0);
5926 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005927
5928 if (f_si_has_gprs_indicator(si_type)) {
5929 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005930 } else {
5931 setverdict(pass);
5932 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005933
Harald Weltebe030482019-05-27 22:29:35 +02005934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5935}
5936
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005937testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5938 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5939}
Harald Weltebe030482019-05-27 22:29:35 +02005940
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005941testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5942 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5943}
5944
5945/* Ensure that GPRS capability is advertised after PCU socket connect */
5946private function f_TC_pcu_socket_connect(RrMessageType si_type)
5947runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005948 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005949 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005950 f_init_l1ctl();
5951 f_l1_tune(L1CTL);
5952
5953 f_sleep(2.0);
5954 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005955
5956 if (not f_si_has_gprs_indicator(si_type)) {
5957 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005958 } else {
5959 setverdict(pass);
5960 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005961
Harald Weltebe030482019-05-27 22:29:35 +02005962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5963}
5964
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005965testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5966 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5967}
Harald Weltebe030482019-05-27 22:29:35 +02005968
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005969testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5970 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5971}
5972
5973/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5974private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5975runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005976 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005977 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005978 f_init_l1ctl();
5979 f_l1_tune(L1CTL);
5980
5981 f_pcuif_close(PCU, g_pcu_conn_id);
5982 g_pcu_conn_id := -1;
5983
5984 f_sleep(1.0);
5985
5986 /* re-connect */
5987 PCU.clear;
5988 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5989
5990 f_sleep(2.0);
5991 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005992
5993 if (f_si_has_gprs_indicator(si_type)) {
5994 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005995 } else {
5996 setverdict(pass);
5997 }
5998
5999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6000}
6001
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006002testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
6003 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
6004}
6005
6006testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
6007 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
6008}
6009
Oliver Smithf5239c72019-08-28 10:01:25 +02006010/* 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) */
6011testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
6012 var SystemInformation si3 := valueof(ts_SI3_default);
6013
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006014 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02006015
Harald Welte76220222020-10-11 20:32:44 +02006016 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
6017 * information */
6018 timer T := 2.0;
6019 T.start;
6020 alt {
6021 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
6022 [] T.timeout {}
6023 }
6024
Oliver Smithf5239c72019-08-28 10:01:25 +02006025 /* Verify cell_id */
6026 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
6027 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
6028 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02006029 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
6030 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
6031 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02006032 }
6033
6034 /* Verify LAC */
6035 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
6036 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
6037 if (lac_si3 != lac_pcu) {
6038 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
6039 }
6040
6041 setverdict(pass);
6042}
Harald Welted66c9b82019-05-25 09:03:15 +02006043
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006044/* Verify hopping parameters in the INFO.ind message (version >= 10) */
6045testcase TC_pcu_info_ind_fh_params() runs on test_CT {
6046 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006047 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006048
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006049 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006050
6051 info_ind := g_pcu_last_info.u.info_ind;
6052
6053 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
6054 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006055 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006056 /* Skip inactive timeslots */
6057 continue;
6058 }
6059
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006060 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006061 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006062 else
6063 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006064
6065 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006066 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006067 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006068 hsn := fhp.maio_hsn.hsn,
6069 maio := fhp.maio_hsn.maio,
6070 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006071 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006072 } else {
6073 tr_ts := tr_PCUIF_InfoTrxTsH0;
6074 }
6075
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006076 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006077 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6078 if (not match(ts, tr_ts)) {
6079 setverdict(fail, "Hopping parameters do not match: ",
6080 "received ", ts, " vs expected ", tr_ts);
6081 } else {
6082 setverdict(pass);
6083 }
6084 }
6085 }
6086}
6087
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006088/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006089testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6090 f_init_vty_bsc();
6091 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6092 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6093
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006094 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006095
6096 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006097 var template PCUIF_RemoteAddr tr_remote_addr := {
6098 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006099 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006100 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006101
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006102 if (not match(remote_addr, tr_remote_addr)) {
6103 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006104 }
6105
6106 setverdict(pass);
6107}
6108
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006109/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006110testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6111 f_init_vty_bsc();
6112 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6113
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006114 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006115
6116 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006117 var template PCUIF_RemoteAddr tr_remote_addr := {
6118 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6119 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6120 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006121
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006122 if (not match(remote_addr, tr_remote_addr)) {
6123 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006124 }
6125
6126 setverdict(pass);
6127}
6128
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006129/* Verify coding of two NSVCs in the INFO.ind message */
6130testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6131 f_init_vty_bsc();
6132
6133 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6134 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6135 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6136 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6137
6138 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6139 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6140 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6141 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6142
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006143 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006144
6145 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6146 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6147 var template PCUIF_RemoteAddr tr_remote_addr := {
6148 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006149 addr := {
6150 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6151 f_inet6_addr("fd00::ca:ff:ee")
6152 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006153 };
6154
6155 if (not match(info_ind.nsvci, { 1234, 5678 }))
6156 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6157 if (not match(remote_addr, tr_remote_addr))
6158 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6159 if (not match(info_ind.local_port, { 1234, 5678 }))
6160 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6161 if (not match(info_ind.remote_port, { 1234, 5678 }))
6162 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6163
6164 setverdict(pass);
6165}
6166
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006167/* Verify periodic interference reports on PDCH */
6168testcase TC_pcu_interf_ind() runs on test_CT {
6169 var template PCUIF_Message tr_interf_ind;
6170 var template PCUIF_interf ts_interf;
6171 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006172 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006173 var PCUIF_send_data sd;
6174 timer T;
6175
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006176 /* Set the averaging/reporting period to 480ms */
6177 f_init_vty_bsc();
6178 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6179 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6180
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006181 f_init_with_pcuif();
6182 f_TC_pcu_act_req(0, 0, 7, true);
6183
6184 /* We need trxcon for NOPE indications */
6185 f_init_l1ctl();
6186 f_l1_tune(L1CTL);
6187
6188 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6189 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6190 tr_interf_ind := tr_PCUIF_INTERF_IND(
6191 bts_nr := 0,
6192 trx_nr := 0,
6193 fn := ?,
6194 interf := ts_interf
6195 );
6196
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006197 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006198 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006199 /* The first interference report may contain unreliable values, so we ignore it */
6200 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6201 /* 4 SACCH periods => 4 reports (plus some guard time) */
6202 T.start(0.480 * 4.0 + 0.480 / 2.0);
6203 first := false;
6204 repeat;
6205 }
6206 /* Subsequent interference reports shall match our expectations */
6207 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006208 /* Check TDMA frame number period */
6209 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6210 setverdict(fail, "Odd TDMA frame number := ",
6211 sd.data.u.interf_ind.fn);
6212 }
6213 interf_ind_num := interf_ind_num + 1;
6214 if (interf_ind_num < 4)
6215 { repeat; }
6216 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006217 [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 +02006218 setverdict(fail, "Received unexpected interference report: ", sd.data);
6219 }
6220 [] PCU.receive { repeat; }
6221 [] T.timeout {
6222 setverdict(fail, "Timeout waiting for interference reports");
6223 }
6224 }
6225
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006226 /* Reset the averaging/reporting period back to default */
6227 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6228
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6230}
6231
Harald Welte3d04ae62018-04-04 20:29:05 +02006232/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006233 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006234 ***********************************************************************/
6235
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006236private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6237 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006238runs on ConnHdlr {
6239 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006240
6241 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006242 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006243 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6244 repeat;
6245 }
6246 }
6247}
6248
6249private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6250runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006251 /* Expect BTS to immediately acknowledge activation as PDCH */
6252 PCU.clear;
6253 f_rsl_chan_act(g_pars.chan_mode);
6254 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006255 timer T_wait := 2.0;
6256 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006257 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006258 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006259 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006260 [] T_wait.timeout {
6261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6262 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6263 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006264 }
6265 /* try to activate this PDCH from the PCU point of view */
6266 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6267 /* FIXME: is there a response? */
6268}
6269
6270private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6271runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006272 /* Send RSL CHAN REL (deactivate) */
6273 PCU.clear;
6274 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6275 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006276 timer T_wait := 2.0;
6277 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006278 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006279 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006280 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006281 [] T_wait.timeout {
6282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6283 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6284 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006285 }
6286 /* Emulate PCU asking BTS to deactivate PDCH */
6287 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6288 alt {
6289 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6290 setverdict(pass);
6291 }
6292 [] RSL.receive { repeat; }
6293 }
6294}
6295
6296/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006297private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006298 var PCUIF_Message first_info;
6299 var integer ts_nr := g_chan_nr.tn;
6300 var integer trx_nr := 0;
6301 var integer bts_nr := 0;
6302 var integer pcu_conn_id := -1;
6303
6304 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6305
6306 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6307 f_sleep(3.0);
6308 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6309 setverdict(pass);
6310}
6311testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6312 var ConnHdlrPars pars;
6313 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006314 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006315
6316 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6317 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6318 vc_conn.done;
6319}
6320
6321/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006322private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006323 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006324 var integer pcu_conn_id := -1;
6325
6326 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6327
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006328 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6329 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6330 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006331 setverdict(pass);
6332}
6333testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6334 var ConnHdlrPars pars;
6335 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006336 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006337
6338 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6339 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6340 vc_conn.done;
6341}
6342
6343/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006344private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006345 var PCUIF_Message first_info;
6346 var integer ts_nr := g_chan_nr.tn;
6347 var integer trx_nr := 0;
6348 var integer bts_nr := 0;
6349 var integer pcu_conn_id := -1;
6350
6351 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6352
6353 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006354 /* Send a second Chan Activ and expect it to be NACKed */
6355 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6356 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006357 setverdict(pass);
6358}
6359testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6360 var ConnHdlrPars pars;
6361 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006362 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006363
6364 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6365 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6366 vc_conn.done;
6367}
6368
6369/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006370private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006371 var PCUIF_Message first_info;
6372 var integer ts_nr := g_chan_nr.tn;
6373 var integer trx_nr := 0;
6374 var integer bts_nr := 0;
6375 var integer pcu_conn_id := -1;
6376 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6377
6378 /* register for the TCH/F channel number */
6379 f_rslem_register(0, chan_nr);
6380
6381 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6382
6383 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6384 "RSL CHAN ACT");
6385 setverdict(pass);
6386}
6387testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6388 var ConnHdlrPars pars;
6389 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006390 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006391
6392 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6393 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6394 vc_conn.done;
6395}
6396
6397/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006398private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006399 var PCUIF_Message first_info;
6400 var integer ts_nr := g_chan_nr.tn;
6401 var integer trx_nr := 0;
6402 var integer bts_nr := 0;
6403 var integer pcu_conn_id := -1;
6404 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6405 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6406
6407 /* register for the TCH/H channel numbers */
6408 f_rslem_register(0, chan_nr[0]);
6409 f_rslem_register(0, chan_nr[1]);
6410
6411 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6412
6413 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6414 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6415 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6416 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6417 setverdict(pass);
6418}
6419testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6420 var ConnHdlrPars pars;
6421 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006422 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006423
6424 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6425 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6426 vc_conn.done;
6427}
6428
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006429/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6430private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6431 var PCUIF_Message first_info;
6432 var integer ts_nr := g_chan_nr.tn;
6433 var integer trx_nr := 0;
6434 var integer bts_nr := 0;
6435 var integer pcu_conn_id := -1;
6436 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6437 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6438 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6439 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6440 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6441 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6442 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6443 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6444
6445 /* register for the TCH/H channel numbers */
6446 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6447 f_rslem_register(0, chan_nr[i]);
6448 }
6449
6450 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6451
6452 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6453 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6454 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6455 }
6456 setverdict(pass);
6457}
6458testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6459 var ConnHdlrPars pars;
6460 var ConnHdlr vc_conn;
6461 f_init();
6462
6463 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6464 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6465 vc_conn.done;
6466}
6467
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006468/* Reproduce a race condition described in OS#5245 */
6469private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6470 f_rsl_chan_act(g_pars.chan_mode);
6471 f_sleep(1.0);
6472 f_rsl_chan_deact();
6473 setverdict(pass);
6474}
6475testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6476 var ConnHdlrPars pars[2];
6477 var ConnHdlr vc_conn[2];
6478 var TrxcMessage rsp;
6479
6480 f_init();
6481
6482 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6483 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6484 ts_TRXC_FAKE_TRXC_DELAY(200));
6485
6486 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6487 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6488 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6489 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6490 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6491 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6492 pars[i], l1ctl := false);
6493 }
6494
6495 /* Wait for all components to finish */
6496 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6497 vc_conn[i].done;
6498 }
6499
6500 /* Disable the artificial delay for TRXC RSP messages */
6501 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6502 ts_TRXC_FAKE_TRXC_DELAY(0));
6503}
6504testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6505 var ConnHdlrPars pars[8];
6506 var ConnHdlr vc_conn[8];
6507 var TrxcMessage rsp;
6508
6509 f_init();
6510
6511 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6512 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6513 ts_TRXC_FAKE_TRXC_DELAY(200));
6514
6515 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6516 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6517 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6518 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6519 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6520 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6521 pars[i], l1ctl := false);
6522 }
6523
6524 /* Wait for all components to finish */
6525 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6526 vc_conn[i].done;
6527 }
6528
6529 /* Disable the artificial delay for TRXC RSP messages */
6530 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6531 ts_TRXC_FAKE_TRXC_DELAY(0));
6532}
6533
Harald Welte9bbbfb52018-04-05 09:33:19 +02006534/***********************************************************************
6535 * IPA Style Dynamic Timeslot Support
6536 ***********************************************************************/
6537
6538private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6539runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006540 /* Expect BTS to immediately acknowledge activation as PDCH */
6541 PCU.clear;
6542 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6543 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006544 timer T_wait := 2.0;
6545 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006546 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006547 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006548 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006549 [] T_wait.timeout {
6550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6551 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6552 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006553 }
6554 /* try to activate this PDCH from the PCU point of view */
6555 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6556 /* FIXME: is there a response? */
6557
6558 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6559}
6560
6561private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6562runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006563 /* Send RSL CHAN REL (deactivate) */
6564 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6565 PCU.clear;
6566 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006567 timer T_wait := 2.0;
6568 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006569 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006570 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006571 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006572 [] T_wait.timeout {
6573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6574 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6575 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006576 }
6577 /* Emulate PCU asking BTS to deactivate PDCH */
6578 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6579 alt {
6580 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6581 setverdict(pass);
6582 }
6583 [] RSL.receive { repeat; }
6584 }
6585}
6586
6587/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006588private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006589 var PCUIF_Message first_info;
6590 var integer ts_nr := g_chan_nr.tn;
6591 var integer trx_nr := 0;
6592 var integer bts_nr := 0;
6593 var integer pcu_conn_id := -1;
6594
6595 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6596
6597 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6598 f_sleep(3.0);
6599 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6600
6601 setverdict(pass);
6602
6603}
6604testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6605 var ConnHdlrPars pars;
6606 var ConnHdlr vc_conn;
6607 f_init();
6608
6609 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6610 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6611 vc_conn.done;
6612}
6613
6614/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006615private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006616 var PCUIF_Message first_info;
6617 var integer ts_nr := g_chan_nr.tn;
6618 var integer trx_nr := 0;
6619 var integer bts_nr := 0;
6620 var integer pcu_conn_id := -1;
6621
6622 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6623
6624 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6625 "RSL CHAN ACT");
6626 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6627 "RF CHAN REL", true);
6628 setverdict(pass);
6629}
6630testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6631 var ConnHdlrPars pars;
6632 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006633 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006634
6635 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6636 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6637 vc_conn.done;
6638}
6639
6640/* 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 +07006641private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006642 var PCUIF_Message first_info;
6643 var integer ts_nr := g_chan_nr.tn;
6644 var integer trx_nr := 0;
6645 var integer bts_nr := 0;
6646 var integer pcu_conn_id := -1;
6647
6648 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6649
6650 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6651 "RSL CHAN ACT");
6652
6653 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6654 alt {
6655 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6656 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006658 }
6659 [] RSL.receive { repeat; }
6660 }
6661
6662 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6663 "RF CHAN REL", true);
6664 setverdict(pass);
6665}
6666testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6667 var ConnHdlrPars pars;
6668 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006669 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006670
6671 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6672 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6673 vc_conn.done;
6674}
6675
6676/* 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 +07006677private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006678 var PCUIF_Message first_info;
6679 var integer ts_nr := g_chan_nr.tn;
6680 var integer trx_nr := 0;
6681 var integer bts_nr := 0;
6682 var integer pcu_conn_id := -1;
6683
6684 /* register for the TCH/F channel number */
6685 f_rslem_register(0, g_chan_nr);
6686
6687 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6688
6689 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6690
6691 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6692 "RSL CHAN ACT");
6693
6694 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6695
6696 setverdict(pass);
6697}
6698testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6699 var ConnHdlrPars pars;
6700 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006701 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006702
6703 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6704 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6705 vc_conn.done;
6706}
6707
6708
Harald Welte0472ab42018-03-12 15:02:26 +01006709/***********************************************************************
6710 * LAPDm / RLL related
6711 ***********************************************************************/
6712
6713private function f_tx_lapdm(template (value) LapdmFrame l,
6714 template (value) RslLinkId link_id) runs on ConnHdlr {
6715 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006716 var template (value) SacchL1Header l1h;
6717
6718 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006719 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006720 /* Compose dummy L1 header */
6721 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6722 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 +02006723 } else {
6724 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006725 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 +01006726 }
Harald Welte0472ab42018-03-12 15:02:26 +01006727}
6728
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006729friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006730 uint3_t sapi,
6731 RslLinkId link_id,
6732 octetstring l3,
6733 boolean exp
6734}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006735friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006736friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6737 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006738 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006739 sapi := sapi,
6740 link_id := id,
6741 l3 := l3,
6742 exp := exp
6743}
6744
6745/* execute the same callback function with a set of different parameters (tcs) on a
6746 * variety of logical channels */
6747private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6748 var ConnHdlrPars pars;
6749 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006750 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006751
6752 /* test on each of the channels we have */
6753 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6754 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6755
6756 /* test each of the test cases on the current channel */
6757 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6758 pars.spec.rll := tcs[j];
6759 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6760 vc_conn := f_start_handler(fn, pars);
6761 vc_conn.done;
6762 }
6763 }
6764
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006766}
6767
6768/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6769private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6770 var RllTestCase tc := g_pars.spec.rll;
6771 timer T := 3.0;
6772
6773 f_l1_tune(L1CTL);
6774 RSL.clear;
6775
6776 /* activate the logical channel */
6777 f_est_dchan();
6778 L1CTL.clear;
6779
6780 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6781 T.start;
6782 alt {
6783 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6784 if (tc.exp) {
6785 setverdict(pass);
6786 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006788 }
6789 }
6790 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6791 if (tc.exp) {
6792 setverdict(pass);
6793 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006795 }
6796 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006797 /* We also expect to receive the measurements */
6798 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006799 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006801 }
6802 [not tc.exp] T.timeout {
6803 setverdict(pass);
6804 }
6805 }
6806
6807 f_rsl_chan_deact();
6808 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6809 f_rslem_unregister(0, g_chan_nr);
6810}
6811testcase TC_rll_est_ind() runs on test_CT {
6812 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006813 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006814 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006815 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006816 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006817 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006818 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6819 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006820 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006821 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006822 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006823 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006824 };
6825 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6826}
6827
6828/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6829private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6830 var RllTestCase tc := g_pars.spec.rll;
6831 var L1ctlDlMessage dl;
6832 timer T := 3.0;
6833
6834 f_l1_tune(L1CTL);
6835 RSL.clear;
6836
6837 /* activate the logical channel */
6838 f_est_dchan();
6839 L1CTL.clear;
6840
6841 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6842 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6843 T.start;
6844 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006845 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006846 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006848 }
6849 }
6850
6851 f_rsl_chan_deact();
6852 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6853 f_rslem_unregister(0, g_chan_nr);
6854}
6855testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6856 var RllTestCases tcs := {
6857 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006858 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006859 };
6860 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6861}
6862testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6863 var RllTestCases tcs := {
6864 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006865 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006866 }
6867 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6868}
6869
6870/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006871friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006872 var L1ctlDlMessage dl;
6873 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6874 var LapdmFrame lapdm;
6875 var octetstring l2 := dl.payload.data_ind.payload;
6876 if (dl.dl_info.link_id.c == SACCH) {
6877 /* remove L1 header */
6878 l2 := substr(l2, 2, lengthof(l2)-2);
6879 }
6880 if (ischosen(exp.ab)) {
6881 lapdm.ab := dec_LapdmFrameAB(l2);
6882 } else if (ischosen(exp.b4)) {
6883 lapdm.b4 := dec_LapdmFrameB4(l2);
6884 } else if (ischosen(exp.bbis)) {
6885 lapdm.bbis := dec_LapdmFrameBbis(l2);
6886 }
6887 log("Rx LAPDm ", lapdm);
6888 if (match(lapdm, exp)) {
6889 setverdict(pass);
6890 } else {
6891 repeat;
6892 }
6893 }
6894 [] L1CTL.receive { repeat; }
6895}
6896private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6897 timer T := t;
6898 T.start;
6899 alt {
6900 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006902 }
6903 [] as_l1_exp_lapdm(exp);
6904 }
6905}
6906
6907/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6908private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6909 /* send SABM from MS -> BTS */
6910 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6911 /* expect RLL EST IND on Abis */
6912 alt {
6913 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6914 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6915 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006917 }
6918 [] RSL.receive { repeat; }
6919 }
6920 /* expect UA from BTS -> MS */
6921 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6922}
6923
6924/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6925private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6926 var RllTestCase tc := g_pars.spec.rll;
6927
6928 f_l1_tune(L1CTL);
6929 RSL.clear;
6930
6931 /* activate the logical channel */
6932 f_est_dchan();
6933 L1CTL.clear;
6934
6935 /* first establish the link-layer */
6936 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6937
6938 /* then send the DISC */
6939 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6940 /* ... and expect the REL IND on the RSL side */
6941 alt {
6942 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6943 setverdict(pass);
6944 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006945 /* We also expect to receive the measurements */
6946 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006947 }
6948
6949 /* release the channel */
6950 f_rsl_chan_deact();
6951 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6952 f_rslem_unregister(0, g_chan_nr);
6953}
6954testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6955 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006956 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006957 };
6958 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6959}
6960
6961testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6962 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006963 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006964 };
6965 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6966}
6967testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6968 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006969 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006970 };
6971 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6972}
6973testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6974 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006975 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006976 };
6977 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6978}
6979
6980/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6981private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6982 var RllTestCase tc := g_pars.spec.rll;
6983 f_l1_tune(L1CTL);
6984 RSL.clear;
6985
6986 /* activate the logical channel */
6987 f_est_dchan();
6988 L1CTL.clear;
6989
6990 /* first establish the link-layer */
6991 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6992
6993 /* then send the REL REQ via RSL */
6994 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6995 /* ... and expect the DISC on the Um side */
6996 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006997 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006998 /* FIXME: send a UA in resposne to the DISC */
6999 }
7000 }
7001
7002 /* release the channel */
7003 f_rsl_chan_deact();
7004 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7005 f_rslem_unregister(0, g_chan_nr);
7006}
7007testcase TC_rll_rel_req() runs on test_CT {
7008 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007009 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
7010 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
7011 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
7012 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007013 };
7014 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
7015}
7016
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007017/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01007018testcase TC_rll_data_req() runs on test_CT {
7019}
7020
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07007021/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01007022testcase TC_rll_data_ind() runs on test_CT {
7023}
7024
7025/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
7026private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
7027 var RllTestCase tc := g_pars.spec.rll;
7028
7029 f_l1_tune(L1CTL);
7030 RSL.clear;
7031
7032 f_est_dchan();
7033 L1CTL.clear;
7034
7035 /* Send UNITDATA REQ on RSL side */
7036 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
7037 /* Expect it to arrive on the other side */
7038 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02007039 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007040 } else {
Harald Weltee613f962018-04-18 22:38:16 +02007041 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01007042 }
7043
7044 /* release the channel */
7045 f_rsl_chan_deact();
7046 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7047 f_rslem_unregister(0, g_chan_nr);
7048}
7049testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
7050 var octetstring l3 := f_rnd_octstring(15);
7051 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007052 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7053 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007054 };
7055 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7056}
7057testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7058 var octetstring l3 := f_rnd_octstring(19);
7059 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007060 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7061 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007062 };
7063 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7064}
7065
7066/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7067private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7068 var RllTestCase tc := g_pars.spec.rll;
7069
7070 f_l1_tune(L1CTL);
7071 RSL.clear;
7072
7073 f_est_dchan();
7074 L1CTL.clear;
7075
7076 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007077 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007078 /* Expdct RLL UNITDATA IND on RSL side */
7079 alt {
7080 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7081 setverdict(pass);
7082 }
7083 [] RSL.receive { repeat; }
7084 }
7085
7086 /* release the channel */
7087 f_rsl_chan_deact();
7088 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7089 f_rslem_unregister(0, g_chan_nr);
7090}
7091testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007092 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007093 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007094 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7095 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007096 };
7097 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7098}
7099testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7100 var octetstring l3 := f_rnd_octstring(18);
7101 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007102 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7103 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007104 };
7105 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7106}
7107
Harald Weltee613f962018-04-18 22:38:16 +02007108/***********************************************************************
7109 * Encryption Related
7110 ***********************************************************************/
7111
7112/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007113private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007114 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7115 if (link_id.c == SACCH) {
7116 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7117 } else {
7118 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7119 }
7120}
7121
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007122/* Expect (or not expect) other kinds of messages */
7123private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7124 [exp_any] RSL.receive { repeat; }
7125 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007127 }
7128}
7129
Harald Weltee613f962018-04-18 22:38:16 +02007130/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007131private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007132 RslLinkId link_id,
7133 octetstring l3,
7134 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007135 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007136) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007137 timer T := 3.0;
7138 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7139 T.start;
7140 /* Expect RLL UNITDATA IND on RSL side */
7141 alt {
7142 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7143 setverdict(pass);
7144 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007145 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007146 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007147 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007149 }
Harald Weltee613f962018-04-18 22:38:16 +02007150 }
7151}
7152
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007153/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7154private function f_data_mo(
7155 RslLinkId link_id,
7156 boolean p, uint3_t nr, uint3_t ns,
7157 octetstring l3,
7158 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007159 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007160) runs on ConnHdlr {
7161 timer T := 3.0;
7162 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7163 T.start;
7164 /* Expect RLL DATA IND on RSL side */
7165 alt {
7166 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7167 setverdict(pass);
7168 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007169 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007170 [] as_rsl_any_ind(exp_any);
7171 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007173 }
7174 }
7175}
7176
Harald Weltee613f962018-04-18 22:38:16 +02007177/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007178private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007179 f_l1_tune(L1CTL);
7180 f_est_dchan(true);
7181
7182 /* now we actually need to transmit some data both ways to check if the encryption works */
7183 var L1ctlDlMessage dl;
7184
Stefan Sperling603d98e2018-07-25 16:47:28 +02007185 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007186 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7187
7188 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7189 f_unitdata_mt(link_id, l3);
7190
7191 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7192 f_unitdata_mo(link_id, l3);
7193
7194 /* release the channel */
7195 f_rsl_chan_deact();
7196 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7197 f_rslem_unregister(0, g_chan_nr);
7198}
7199testcase TC_chan_act_a51() runs on test_CT {
7200 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7201 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7202 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7203}
7204testcase TC_chan_act_a52() runs on test_CT {
7205 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7206 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7207 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7208}
7209testcase TC_chan_act_a53() runs on test_CT {
7210 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7211 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7212 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7213}
Eric Wildb9260392021-05-15 19:48:22 +02007214testcase TC_chan_act_a54() runs on test_CT {
7215 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7216 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7217 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7218}
Harald Weltee613f962018-04-18 22:38:16 +02007219
Eric Wildf1827a72019-05-28 17:37:35 +02007220/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7221 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 +07007222private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007223 f_l1_tune(L1CTL);
7224 f_est_dchan(true);
7225
7226 /* now we actually need to transmit some data both ways to check if the encryption works */
7227 var L1ctlDlMessage dl;
7228
7229 var octetstring l3 := f_rnd_octstring(20);
7230 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7231
7232 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7233 f_unitdata_mt(link_id, l3);
7234
7235 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7236 f_unitdata_mo(link_id, l3);
7237
7238 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007239 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007240
7241 /* modify key to break proper encryption */
7242 g_pars.encr.key := f_rnd_octstring(8);
7243 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7244 rsl.ies := rsl.ies & { ei };
7245 RSL.send(rsl);
7246
7247 timer T0 := 1.0;
7248 T0.start;
7249 /* Expect RSL MODIFY ACK */
7250 alt {
7251 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7252 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7254 }
7255 [] T0.timeout {
7256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7257 }
7258 }
7259
7260 var octetstring l3msg := f_rnd_octstring(15);
7261 timer T1 := 3.0;
7262 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7263 due to broken encryption */
7264 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7265 T1.start;
7266 alt {
7267 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7269 }
7270 [] T1.timeout {
7271 setverdict(pass);
7272 }
7273 }
7274
7275 /* release the channel */
7276 f_rsl_chan_deact();
7277 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7278 f_rslem_unregister(0, g_chan_nr);
7279}
7280testcase TC_rsl_modify_encr() runs on test_CT {
7281 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7282 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7283 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7284}
Harald Weltee613f962018-04-18 22:38:16 +02007285
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007286/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7287private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7288runs on test_CT {
7289 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7290 var ASP_RSL_Unitdata ud;
7291 timer T;
7292
7293 /* Intave is 6 SACCH periods by default */
7294 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7295
7296 T.start(Tval);
7297 alt {
7298 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7299 setverdict(pass);
7300 }
7301 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7302 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7303 }
7304 [] RSL_CCHAN.receive { repeat; }
7305 [] T.timeout {
7306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7307 "Timeout waiting for RF RESource INDication");
7308 }
7309 }
7310}
7311testcase TC_rsl_rf_resource_ind() runs on test_CT {
7312 var RSL_ResourceInfo info := { };
7313
7314 f_init(trx_nr := 0);
7315
7316 f_init_l1ctl();
7317 f_l1_tune(L1CTL);
7318
7319 /* g_AllChannels contains all logical channels */
7320 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7321 var RslChannelNr chan_nr := g_AllChannels[i];
7322
7323 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7324 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7325 { continue; }
7326
7327 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7328 }
7329
7330 /* Align to the first interference report */
7331 f_TC_rsl_rf_resource_ind(?);
7332
7333 /* Test 4 consecutive messages */
7334 for (var integer i := 0; i < 4; i := i + 1) {
7335 f_TC_rsl_rf_resource_ind(info);
7336 }
7337
7338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7339}
7340
Harald Weltee613f962018-04-18 22:38:16 +02007341/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007342private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007343 /* L3 payload doesn't matter, as it is passed transparently */
7344 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7345 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7346 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7347
7348 f_l1_tune(L1CTL);
7349
7350 /* first establish a dedicated channel in the clear */
7351 f_est_dchan(false);
7352
7353 /* Establish ABM */
7354 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7355
7356 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7357 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7358 /* expect the L3 to arrive still unencrypted on the MS side */
7359 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7360
7361 /* configure L1 to apply ciphering */
7362 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7363 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7364
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007365 /* send first ciphered I-frame in response and expect it on RSL */
7366 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007367
7368 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7369 * and hence enable encryption also on the downlink */
7370
7371 /* expect bi-directional communication work in encrypted mode */
7372 f_unitdata_mo(link_id, f_rnd_octstring(15));
7373 f_unitdata_mt(link_id, f_rnd_octstring(15));
7374
7375 /* release the channel */
7376 f_rsl_chan_deact();
7377 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7378 f_rslem_unregister(0, g_chan_nr);
7379}
7380testcase TC_encr_cmd_a51() runs on test_CT {
7381 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7382 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7383 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7384}
7385testcase TC_encr_cmd_a52() runs on test_CT {
7386 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7387 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7388 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7389}
7390testcase TC_encr_cmd_a53() runs on test_CT {
7391 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7392 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7393 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7394}
Eric Wildb9260392021-05-15 19:48:22 +02007395testcase TC_encr_cmd_a54() runs on test_CT {
7396 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7397 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7398 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7399}
Harald Weltee613f962018-04-18 22:38:16 +02007400
7401private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7402 var LapdmFrame lf;
7403 var octetstring reenc;
7404
7405 /* decode the LAPDm frame */
7406 if (ischosen(exp_match.ab)) {
7407 lf.ab := dec_LapdmFrameAB(enc);
7408 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007410 }
7411
7412 /* check if decoder result matches expectation */
7413 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007415 } else {
7416 log(name, ": matched");
7417 setverdict(pass);
7418 }
7419
7420 /* test if re-encoded frame equals original input */
7421 reenc := enc_LapdmFrame(lf);
7422 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007424 } else {
7425 setverdict(pass);
7426 }
7427}
7428
7429testcase TC_lapdm_selftest() runs on test_CT {
7430 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7431 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7432 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7433 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7434 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7435 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7436 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7437}
7438
Stefan Sperling4880be42018-08-07 18:12:59 +02007439/***********************************************************************
7440 * DTX Related (see GSM 05.08, section 8.3)
7441 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007442private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007443 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007444 var GsmFrameNumber first_fn;
7445 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007446 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007447 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007448 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7449 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007450 const integer frame_dtx_tchf_mod := 104;
7451 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7452 * which operates in terms of blocks rather than frames. */
7453 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7454 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007455 timer T := 5.0;
7456
7457 f_l1_tune(L1CTL);
7458 RSL.clear;
7459 L1CTL.clear;
7460
7461 /* activate TCHF signalling channel */
7462 f_est_dchan(false);
7463
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007464 /* A template for matching dummy LAPDm func=UA frames */
7465 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7466 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7467 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7468
Stefan Sperling4880be42018-08-07 18:12:59 +02007469 T.start;
7470 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007471 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007472 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007473
7474 if (is_first_frame) {
7475 is_first_frame := false;
7476 first_fn := dl.dl_info.frame_nr;
7477 }
7478
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007479 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007480 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007481 T.stop;
7482 f_rsl_chan_deact();
7483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007484
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007485 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7486 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007487
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007488 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007489 setverdict(fail, "Not enough fill frames received: ",
7490 nfill_frames, " out of ", expected_fill_frames);
7491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007492 } else {
7493 setverdict(pass);
7494 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007495 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007496 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7497 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7498 * we should only see the subset of frames numbers which correspond to a block boundary.
7499 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7500 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7501 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007502 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007503 repeat;
7504 }
7505 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007506 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7507 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7508 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007509 f_rsl_chan_deact();
7510 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007511 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007512 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007513 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007514 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007515 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007516
7517 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007518 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7519 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007520 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7521 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7522 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007523 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7524 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007525 case else {
7526 /* This shall not happen, just to be sure */
7527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7528 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007529 }
7530
7531 f_rsl_chan_deact();
7532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007533
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007534 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007535 setverdict(pass);
7536 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007537 setverdict(fail, "Not enough fill frames received: ",
7538 nfill_frames, " out of ", expected_fill_frames);
7539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007540 }
7541 } else {
7542 repeat;
7543 }
7544 }
7545 }
7546 [] L1CTL.receive { repeat; }
7547 [] T.timeout {
7548 f_rsl_chan_deact();
7549 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007551 }
7552 }
7553}
7554
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007555private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007556 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007557 var ConnHdlr vc_conn;
7558 var ConnHdlrPars pars;
7559 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007560 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007561 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007562 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007563 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007564 if (dtxd) {
7565 if (i >= 4) { /* DTX is only allowed on TCH/F */
7566 break;
7567 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007568 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007569 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007570 vc_conn.done;
7571 }
7572}
7573
7574/* Verify that L2 fill frames are sent on TCH in signaling mode if
7575 * there is nothing to transmit while DTX is disabled on downlink. */
7576testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7577 f_tch_sign_l2_fill_frame(false);
7578}
7579
7580/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7581 * there is nothing to transmit while DTX is enabled on downlink. */
7582testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7583 f_tch_sign_l2_fill_frame(true);
7584}
Harald Welte0472ab42018-03-12 15:02:26 +01007585
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007586testcase TC_chopped_ipa_ping() runs on test_CT {
7587 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7588}
7589
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007590testcase TC_chopped_ipa_payload() runs on test_CT {
7591 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7592}
7593
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007594
7595/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7596 * Return value: Measurement Report to be sent (encoded octetstring). */
7597type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7598 runs on ConnHdlr return octetstring;
7599
7600private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7601runs on ConnHdlr {
7602 var L1ctlDlMessage l1_dl;
7603 var SacchL1Header l1h;
7604 var octetstring l2;
7605
7606 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7607 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7608 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7609 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7610
7611 /* Pass it to the user specified call-back function */
7612 l2 := cb.apply(l1h, num_blocks);
7613 /* Send a Measurement Report generated by the call-back */
7614 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7615 l1_dl.dl_info.link_id,
7616 l1h, l2));
7617
7618 /* Shall we keep going? */
7619 num_blocks := num_blocks - 1;
7620 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7621 if (num_blocks > 0) { repeat; }
7622 }
7623 [] L1CTL.receive { repeat; }
7624}
7625
7626private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7627runs on ConnHdlr return octetstring {
7628 /* Command the L1 to apply received parameters */
7629 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7630
7631 /* Dummy measurement report (the results are invalid) */
7632 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7633}
7634
7635private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7636runs on ConnHdlr return octetstring {
7637 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7638 setverdict(fail, "Unexpected MS Power level change: ",
7639 g_pars.l1_pars.ms_power_level, " -> ",
7640 l1h.ms_power_lvl);
7641 }
7642
7643 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7644}
7645
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007646private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7647runs on ConnHdlr return octetstring {
7648 /* UL RSSI oscillation driven by SACCH block number */
7649 if (num_blocks rem 2 == 0) {
7650 f_trxc_fake_rssi(-100);
7651 } else {
7652 f_trxc_fake_rssi(-50);
7653 }
7654
7655 /* Make sure that MS power level remains constant */
7656 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7657}
7658
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007659/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7660private function f_TC_ms_pwr_ctrl_constant(charstring id)
7661runs on ConnHdlr {
7662 var integer num_blocks := 8;
7663 timer T := int2float(num_blocks);
7664
7665 f_l1_tune(L1CTL);
7666 RSL.clear;
7667
7668 /* These IEs are needed for autonomous MS power control */
7669 var template (value) RSL_IE_List ies := {
7670 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7671 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7672 }),
7673 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7674 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7675 })
7676 };
7677
7678 /* Ensure that 'rx-current' equals 'rx-target' */
7679 f_trxc_fake_rssi(mp_uplink_power_target);
7680
7681 /* Establish a dedicated channel */
7682 f_est_dchan(more_ies := valueof(ies));
7683
7684 L1CTL.clear;
7685 T.start;
7686 alt {
7687 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7688 [] T.timeout {
7689 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7690 num_blocks, " were not handled");
7691 }
7692 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007693
7694 /* Release the channel */
7695 f_rsl_chan_deact();
7696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007697}
7698testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7699 var ConnHdlr vc_conn;
7700 var ConnHdlrPars pars;
7701
7702 f_init();
7703
7704 /* Explicitly configure the Uplink power target (in dBm) */
7705 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7706
7707 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7708 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7709 log(testcasename(), ": starting on ", pars.chan_nr);
7710
7711 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7712 pars, trxc_comp := true);
7713 vc_conn.done;
7714 }
7715
7716 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7718}
7719
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007720/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7721private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7722runs on ConnHdlr {
7723 var integer num_blocks := 16;
7724 timer T := int2float(num_blocks);
7725
7726 f_l1_tune(L1CTL);
7727 RSL.clear;
7728
7729 /* These IEs are needed for autonomous MS power control */
7730 var template (value) RSL_IE_List ies := {
7731 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7732 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7733 }),
7734 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7735 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7736 })
7737 };
7738
7739 /* Ensure that 'rx-current' equals 'rx-target' */
7740 f_trxc_fake_rssi(mp_uplink_power_target);
7741
7742 /* Establish a dedicated channel */
7743 f_est_dchan(more_ies := valueof(ies));
7744
7745 L1CTL.clear;
7746 T.start;
7747 alt {
7748 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7749 [] T.timeout {
7750 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7751 num_blocks, " were not handled");
7752 }
7753 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007754
7755 /* Release the channel */
7756 f_rsl_chan_deact();
7757 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007758}
7759testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7760 var ConnHdlr vc_conn;
7761 var ConnHdlrPars pars;
7762
7763 f_init();
7764
7765 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7766 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7767 /* Explicitly configure the Uplink power range (target and delte) */
7768 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7769 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7770
7771 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7772 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7773 log(testcasename(), ": starting on ", pars.chan_nr);
7774
7775 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7776 pars, trxc_comp := true);
7777 vc_conn.done;
7778 }
7779
7780 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7782}
7783
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007784private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7785 var template L1ctlDlMessage tr_bad_frame;
7786 var L1ctlDlMessage l1_dl;
7787 timer T := 8.0;
7788
7789 f_l1_tune(L1CTL);
7790 RSL.clear;
7791
7792 f_est_dchan();
7793
7794 /* There may be a few errors right after the channel activation */
7795 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7796 L1CTL.clear;
7797
7798 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7799 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7800 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7801 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7802 tr_bad_frame.payload := ?;
7803
7804 T.start;
7805 alt {
7806 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7807 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7808 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7809 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7810 }
7811 [] as_l1_sacch();
7812 [] L1CTL.receive { repeat; }
7813 [] T.timeout {
7814 /* We're done, break the loop */
7815 setverdict(pass);
7816 }
7817 }
7818
7819 f_rsl_chan_deact();
7820 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7821}
7822testcase TC_speech_no_rtp_tchf() runs on test_CT {
7823 var ConnHdlr vc_conn;
7824 var ConnHdlrPars pars;
7825
7826 f_init();
7827
7828 /* TS1, TCH/F, V1 (FR codec) */
7829 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7830 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7831 vc_conn.done;
7832}
7833testcase TC_speech_no_rtp_tchh() runs on test_CT {
7834 var ConnHdlr vc_conn;
7835 var ConnHdlrPars pars;
7836
7837 f_init();
7838
7839 /* TS5, TCH/H, V1 (HR codec) */
7840 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7841 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7842 vc_conn.done;
7843}
7844
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007845/* Verify handling of Downlink and Uplink speech frames */
7846private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7847 var L1ctlDlMessage l1_dl;
7848 var PDU_RTP rtp_pdu;
7849 var octetstring pl;
7850 timer Td, Tu;
7851
7852 f_l1_tune(L1CTL);
7853 f_est_dchan();
7854
7855 /* Activate the RTP emulation */
7856 pl := f_rnd_octstring(6);
7857 f_rtpem_activate(pl);
7858
7859 /* Give the scheduler some time to fill up the buffers */
7860 f_sleep(2.0);
7861 L1CTL.clear;
7862 RSL.clear;
7863
7864 /* Make sure that Downlink frames are received at the UE */
7865 Td.start(2.0);
7866 alt {
7867 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7868 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7869 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7870 l1_dl.payload.traffic_ind.data));
7871 setverdict(pass);
7872 }
7873 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7874 setverdict(fail, "Rx unexpected Downlink speech frame ",
7875 "(", l1_dl.payload.traffic_ind.data, ") ",
7876 "expected (", pl, ")");
7877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7878 }
7879 [] as_l1_sacch();
7880 [] L1CTL.receive { repeat; }
7881 [] Td.timeout {
7882 setverdict(fail, "Timeout waiting for Downlink speech frames");
7883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7884 }
7885 }
7886
7887 /* Make sure that Uplink frames are received at the BTS */
7888 RTPEM_DATA.clear;
7889 Tu.start(2.0);
7890 alt {
7891 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7892 if (rtp_pdu.data != pl)
7893 { repeat; }
7894 }
7895 [] RTPEM_DATA.receive { repeat; }
7896 [] Tu.timeout {
7897 setverdict(fail, "Timeout waiting for Uplink speech frames");
7898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7899 }
7900 }
7901
7902 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7903 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7904 f_rsl_chan_deact();
7905 f_rslem_unregister(0, g_chan_nr);
7906}
7907testcase TC_speech_rtp_tchf() runs on test_CT {
7908 var ConnHdlr vc_conn;
7909 var ConnHdlrPars pars;
7910
7911 f_init();
7912
7913 /* TS1, TCH/F, V1 (FR codec) */
7914 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7915 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7916 vc_conn.done;
7917
7918 /* TS1, TCH/F, V2 (EFR codec) */
7919 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7920 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7921 vc_conn.done;
7922
7923 /* TODO: also test V3 (AMR codec) */
7924
7925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7926}
7927testcase TC_speech_rtp_tchh() runs on test_CT {
7928 var ConnHdlr vc_conn;
7929 var ConnHdlrPars pars;
7930
7931 f_init();
7932
7933 /* TS5, TCH/H0, V1 (HR codec) */
7934 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7935 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7936 vc_conn.done;
7937
7938 /* TODO: also test V3 (AMR codec) */
7939
7940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7941}
7942
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007943private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7944 var GsmFrameNumber fn;
7945 var ChannelDescription ch_desc;
7946 var integer ra := 23;
7947
7948 f_l1_tune(L1CTL);
7949 RSL.clear;
7950
7951 /* Send RACH request and wait for ChanReq */
7952 fn := f_rach_req_wait_chan_rqd(ra);
7953
7954 /* The BSC already sends the Immediate Assignment, before the channel is active.
7955 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7956 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7957 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7958 if (g_pars.fhp.enabled) {
7959 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7960 } else {
7961 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7962 }
7963 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7964 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7965
7966 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7967 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7968 var L1ctlDlMessage dl;
7969 var GsmRrMessage rr;
7970
7971 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7972 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7973 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7974 rr_imm_ass.payload.imm_ass.chan_desc := *;
7975
7976 timer T := 1.0;
7977 T.start;
7978 alt {
7979 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7980 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7981 if (match(rr, rr_imm_ass)) {
7982 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7983 mtc.stop;
7984 } else {
7985 repeat;
7986 }
7987 }
7988 [] L1CTL.receive { repeat; }
7989 [] T.timeout;
7990 }
7991 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7992 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7993
7994 /* Now expect the IMM ASS on Um */
7995 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7996 setverdict(pass);
7997
7998 /* Release the channel */
7999 f_rsl_chan_deact();
8000 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8001}
8002
8003testcase TC_early_immediate_assignment() runs on test_CT {
8004 var ConnHdlr vc_conn;
8005 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
8006 f_init();
8007 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
8008 vc_conn.done;
8009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8010}
8011
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008012private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
8013 var integer ra := oct2int(f_rnd_ra_cs());
8014 var ChannelDescription ch_desc;
8015
8016 /* Tune the MS to BCCH */
8017 f_l1_tune(L1CTL);
8018
8019 /* Send RACH request and wait for ChanReq */
8020 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
8021
8022 /* Activate channel on the BTS side */
8023 f_rsl_chan_act(g_pars.chan_mode);
8024
8025 /* Craft channel description (with or without frequency hopping parameters) */
8026 if (g_pars.fhp.enabled) {
8027 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
8028 } else {
8029 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
8030 }
8031
8032 /* Send IMM.ASS via CCHAN */
8033 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
8034 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
8035
8036 /* Receive IMM.ASS on the MS side */
8037 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
8038
8039 /* Match the Channel Description IE in received IMM.ASS */
8040 if (not match(imm_ass.chan_desc, ch_desc)) {
8041 setverdict(fail, "Channel Description IE does not match");
8042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8043 }
8044
8045 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
8046 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
8047
8048 /* Expect SACCH frames on Downlink */
8049 L1CTL.clear;
8050 f_exp_sacch(true);
8051
8052 /* We're done, deactivate and release */
8053 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
8054 f_rsl_chan_deact();
8055}
8056testcase TC_est_dchan() runs on test_CT {
8057 var ConnHdlr vc_conn;
8058 var ConnHdlrPars pars;
8059
8060 f_init();
8061
8062 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8063 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8064 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8065 vc_conn.done;
8066 }
8067
8068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8069}
8070
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008071private type record TopTestCase {
8072 RSL_IE_BS_Power bs_power,
8073 RSL_IE_OSMO_TopAcchCap top_cap,
8074 record of TopTestStep steps
8075};
8076private type record TopTestStep {
8077 MeasurementResults meas_res optional,
8078 GsmRxLev overpower_sacch,
8079 GsmRxLev overpower_facch
8080};
8081
8082private function f_rxlev_match(template (present) RslLinkId link_id,
8083 template (present) GsmRxLev rxlev)
8084runs on ConnHdlr {
8085 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8086 if (not match(dl.dl_info.rx_level, rxlev)) {
8087 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8088 " does not match expected RxLev := ", rxlev);
8089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8090 }
8091}
8092
8093private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8094 var TopTestCase tc := g_pars.spec.top;
8095 var GsmRxLev rxlev_dcch;
8096 var L1ctlDlMessage dl;
8097
8098 /* Wait for Pau ramping to complete */
8099 f_sleep(6.0);
8100
8101 f_l1_tune(L1CTL);
8102 L1CTL.clear;
8103 RSL.clear;
8104
8105 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8106 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8107 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8108
8109 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8110 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8111
8112 /* Additional IEs for the CHANnel ACTIVation message */
8113 var template (value) RSL_IE_List ies := {
8114 /* Employ BS power control in static mode */
8115 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8116 bs_power := tc.bs_power
8117 }),
8118 /* Indicate the given Temporary Overpower capability */
8119 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8120 top_acch_cap := tc.top_cap
8121 })
8122 };
8123
8124 /* Establish a dedicated channel */
8125 f_est_dchan(more_ies := valueof(ies));
8126
8127 /* Give it some time to stabilize */
8128 f_sleep(0.480 * 2.0);
8129 L1CTL.clear;
8130 RSL.clear;
8131
8132 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8133 var TopTestStep step := tc.steps[i];
8134 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8135 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8136
8137 log("Executing step[", i, "] := ", step);
8138
8139 /* Send RR Measurement Report (if present) */
8140 if (ispresent(step.meas_res)) {
8141 f_transceive_meas_rep(step.meas_res);
8142 f_sleep(0.480 * 2.0);
8143 L1CTL.clear;
8144 }
8145
8146 /* Check RxLev on both FACCH and SACCH */
8147 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8148 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8149
8150 setverdict(pass);
8151 }
8152}
8153testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8154 var ConnHdlrPars pars;
8155 var ConnHdlr vc_conn;
8156
8157 f_init();
8158
8159 /* Verify lower and upper RxQual thresholds */
8160 var template TopTestCase top := {
8161 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8162 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8163 steps := {
8164 /* Channel established, no overpower */
8165 { meas_res := omit,
8166 overpower_sacch := 0, overpower_facch := 0 },
8167
8168 /* Worst possible RxQual value, overpower of 4dB */
8169 { meas_res := ts_MeasurementResults(rxq_f := 7),
8170 overpower_sacch := 4, overpower_facch := 4 },
8171 /* Worst possible RxQual value, disabling overpower */
8172 { meas_res := ts_MeasurementResults(rxq_f := 0),
8173 overpower_sacch := 0, overpower_facch := 0 },
8174
8175 /* Lower threshold not reached, no overpower */
8176 { meas_res := ts_MeasurementResults(rxq_f := 1),
8177 overpower_sacch := 0, overpower_facch := 0 },
8178 /* Lower threshold not reached, no overpower */
8179 { meas_res := ts_MeasurementResults(rxq_f := 2),
8180 overpower_sacch := 0, overpower_facch := 0 },
8181 /* Lower threshold reached, overpower of 4dB */
8182 { meas_res := ts_MeasurementResults(rxq_f := 4),
8183 overpower_sacch := 4, overpower_facch := 4 },
8184 /* Upper threshold not reached, keeping overpower */
8185 { meas_res := ts_MeasurementResults(rxq_f := 3),
8186 overpower_sacch := 4, overpower_facch := 4 },
8187 /* Upper threshold reached, disabling overpower */
8188 { meas_res := ts_MeasurementResults(rxq_f := 2),
8189 overpower_sacch := 0, overpower_facch := 0 }
8190 }
8191 };
8192
8193 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8194 spec := { top := top }, trx_nr := 1));
8195 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8196 vc_conn.done;
8197
8198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8199}
8200testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8201 var ConnHdlrPars pars;
8202 var ConnHdlr vc_conn;
8203
8204 f_init();
8205
8206 /* Verify handling of FULL and SUB values */
8207 var template TopTestCase top := {
8208 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8209 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8210 steps := {
8211 /* Channel established, no overpower */
8212 { meas_res := omit,
8213 overpower_sacch := 0, overpower_facch := 0 },
8214
8215 /* Invalid measurement results, no overpower */
8216 { meas_res := ts_MeasurementResults(rxq_f := 7,
8217 rxq_s := 7,
8218 valid := false),
8219 overpower_sacch := 0, overpower_facch := 0 },
8220
8221 /* DTXu was in use, no overpower */
8222 { meas_res := ts_MeasurementResults(rxq_f := 7,
8223 rxq_s := 0,
8224 dtx_used := true),
8225 overpower_sacch := 0, overpower_facch := 0 },
8226 /* DTXu was in use, overpower of 4 dB */
8227 { meas_res := ts_MeasurementResults(rxq_f := 0,
8228 rxq_s := 7,
8229 dtx_used := true),
8230 overpower_sacch := 4, overpower_facch := 4 }
8231 }
8232 };
8233
8234 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8235 spec := { top := top }, trx_nr := 1));
8236 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8237 vc_conn.done;
8238
8239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8240}
8241testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8242 var ConnHdlrPars pars;
8243 var ConnHdlr vc_conn;
8244
8245 f_init();
8246
8247 /* Overpower is always on, SACCH disabled */
8248 var template TopTestCase top := {
8249 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8250 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8251 rxqual := 0, /* always on */
8252 sacch_enable := false),
8253 steps := {
8254 /* Channel established, FACCH overpower */
8255 { meas_res := omit,
8256 overpower_sacch := 0, overpower_facch := 4 },
8257 /* MS indicates good RxQual, no difference */
8258 { meas_res := ts_MeasurementResults(rxq_f := 0),
8259 overpower_sacch := 0, overpower_facch := 4 },
8260 /* MS indicates bad RxQual, no difference */
8261 { meas_res := ts_MeasurementResults(rxq_f := 7),
8262 overpower_sacch := 0, overpower_facch := 4 }
8263 }
8264 };
8265
8266 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8267 spec := { top := top }, trx_nr := 1));
8268 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8269 vc_conn.done;
8270
8271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8272}
8273testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8274 var ConnHdlrPars pars;
8275 var ConnHdlr vc_conn;
8276
8277 f_init();
8278
8279 /* Overpower is always on, FACCH disabled */
8280 var template TopTestCase top := {
8281 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8282 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8283 rxqual := 0, /* always on */
8284 facch_enable := false),
8285 steps := {
8286 /* Channel established, SACCH overpower */
8287 { meas_res := omit,
8288 overpower_sacch := 4, overpower_facch := 0 },
8289 /* MS indicates good RxQual, no difference */
8290 { meas_res := ts_MeasurementResults(rxq_f := 0),
8291 overpower_sacch := 4, overpower_facch := 0 },
8292 /* MS indicates bad RxQual, no difference */
8293 { meas_res := ts_MeasurementResults(rxq_f := 7),
8294 overpower_sacch := 4, overpower_facch := 0 }
8295 }
8296 };
8297
8298 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8299 spec := { top := top }, trx_nr := 1));
8300 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8301 vc_conn.done;
8302
8303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8304}
8305testcase TC_acch_overpower_limit() runs on test_CT {
8306 var ConnHdlrPars pars;
8307 var ConnHdlr vc_conn;
8308
8309 f_init();
8310
8311 /* Overpower higher than current power reduction level (2dB) */
8312 var template TopTestCase top := {
8313 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8314 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8315 rxqual := 0 /* always on */),
8316 steps := {
8317 /* Channel established, ACCH overpower of 2dB */
8318 { meas_res := omit,
8319 overpower_sacch := 2, overpower_facch := 2 },
8320 /* MS indicates good RxQual, no difference */
8321 { meas_res := ts_MeasurementResults(rxq_f := 0),
8322 overpower_sacch := 2, overpower_facch := 2 },
8323 /* MS indicates bad RxQual, no difference */
8324 { meas_res := ts_MeasurementResults(rxq_f := 7),
8325 overpower_sacch := 2, overpower_facch := 2 }
8326 }
8327 };
8328
8329 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8330 spec := { top := top }, trx_nr := 1));
8331 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8332 vc_conn.done;
8333
8334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8335}
8336
Harald Welte0472ab42018-03-12 15:02:26 +01008337/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8338/* protocol error as per 44.006 */
8339/* link layer failure (repetition of I-frame N200 times without ACK */
8340/* repetition of SABM or DISC N200 times without ACK */
8341/* receptiom of SABM in multi-frame established state */
8342
8343
Harald Welte68e495b2018-02-25 00:05:57 +01008344/* TODO Areas:
8345
8346* channel activation
8347** with BS_Power / MS_Power, bypassing power control loop
8348** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008349** with timing advance from initial activation on
8350* mode modify
8351** encryption
8352** multirate
8353* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008354** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008355* BS Power Control
8356* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008357* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008358** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008359* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008360** DATA_IND from BTS->PCU
8361** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008362
8363*/
Harald Welte70767382018-02-21 12:16:40 +01008364
8365control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008366 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008367 execute( TC_chan_act_stress() );
8368 execute( TC_chan_act_react() );
8369 execute( TC_chan_deact_not_active() );
8370 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008371 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008372 execute( TC_sacch_filling() );
8373 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008374 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008375 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008376 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008377 execute( TC_sacch_chan_act_ho_async() );
8378 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008379 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008380 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008381 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008382 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008383 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008384 execute( TC_rach_load_idle_thresh0() );
8385 execute( TC_rach_load_idle_below_thresh() );
8386 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008387 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008388 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008389 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008390 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008391 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008392 execute( TC_meas_res_sign_tchf() );
8393 execute( TC_meas_res_sign_tchh() );
8394 execute( TC_meas_res_sign_sdcch4() );
8395 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008396 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008397 execute( TC_meas_res_speech_tchf_sapi3() );
8398 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008399 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008400 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008401 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008402 execute( TC_rsl_bs_pwr_static_ass() );
8403 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008404 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008405 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008406 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008407 execute( TC_rsl_ms_pwr_dyn_up() );
8408 execute( TC_rsl_ms_pwr_dyn_down() );
8409 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8410 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008411 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008412 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008413 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008414 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008415 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008416 execute( TC_paging_imsi_80percent() );
8417 execute( TC_paging_tmsi_80percent() );
8418 execute( TC_paging_imsi_200percent() );
8419 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008420 execute( TC_rsl_protocol_error() );
8421 execute( TC_rsl_mand_ie_error() );
8422 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008423 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008424 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008425 execute( TC_si_sched_2bis() );
8426 execute( TC_si_sched_2ter() );
8427 execute( TC_si_sched_2ter_2bis() );
8428 execute( TC_si_sched_2quater() );
8429 execute( TC_si_sched_13() );
8430 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008431 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008432 execute( TC_ipa_crcx_twice_not_active() );
8433 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008434 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008435 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008436
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008437 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008438 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008439 execute( TC_pcu_act_req() );
8440 execute( TC_pcu_act_req_wrong_ts() );
8441 execute( TC_pcu_act_req_wrong_bts() );
8442 execute( TC_pcu_act_req_wrong_trx() );
8443 execute( TC_pcu_deact_req() );
8444 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008445 execute( TC_pcu_ver_si1() );
8446 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008447 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008448 if (mp_l1_supports_gprs) {
8449 execute( TC_pcu_data_req_pdtch() );
8450 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008451 execute( TC_pcu_data_req_wrong_bts() );
8452 execute( TC_pcu_data_req_wrong_trx() );
8453 execute( TC_pcu_data_req_wrong_ts() );
8454 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008455 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008456 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008457 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008458 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008459 execute( TC_pcu_data_req_imm_ass_pch() );
8460 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008461 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008462 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008463 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008464 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008465 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008466 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008467 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008468 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008469 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008470 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008471 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008472 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008473 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008474 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008475 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008476 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008477 execute( TC_dyn_osmo_pdch_act_deact() );
8478 execute( TC_dyn_osmo_pdch_double_act() );
8479 execute( TC_dyn_ipa_pdch_act_deact() );
8480 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008481 execute( TC_pcu_info_ind_fh_params() );
8482 execute( TC_pcu_socket_nsvc_ipv4() );
8483 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008484 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008485 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008486 } else {
8487 log("PCU socket path not available, skipping PCU tests");
8488 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008489
Harald Welte3d04ae62018-04-04 20:29:05 +02008490 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008491 execute( TC_dyn_osmo_pdch_tchf_act() );
8492 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008493 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008494 execute( TC_dyn_ipa_pdch_tchf_act() );
8495 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008496
8497 execute( TC_rll_est_ind() );
8498 execute( TC_rll_est_req_DCCH_3() );
8499 execute( TC_rll_est_req_ACCH_3() );
8500 execute( TC_rll_rel_ind_DCCH_0() );
8501 execute( TC_rll_rel_ind_DCCH_3() );
8502 execute( TC_rll_rel_ind_ACCH_0() );
8503 execute( TC_rll_rel_ind_ACCH_3() );
8504 execute( TC_rll_rel_req() );
8505 execute( TC_rll_unit_data_req_DCCH() );
8506 execute( TC_rll_unit_data_req_ACCH() );
8507 execute( TC_rll_unit_data_ind_DCCH() );
8508 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008509
8510 execute( TC_chan_act_a51() );
8511 execute( TC_chan_act_a52() );
8512 execute( TC_chan_act_a53() );
8513 execute( TC_encr_cmd_a51() );
8514 execute( TC_encr_cmd_a52() );
8515 execute( TC_encr_cmd_a53() );
8516
Harald Welteee25aae2019-05-19 14:32:37 +02008517 execute( TC_err_rep_wrong_mdisc() );
8518 execute( TC_err_rep_wrong_msg_type() );
8519 execute( TC_err_rep_wrong_sequence() );
8520
Harald Weltee613f962018-04-18 22:38:16 +02008521 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008522
8523 execute( TC_tch_sign_l2_fill_frame() );
8524 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008525
8526 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008527 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008528
8529 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008530 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008531
8532 execute( TC_speech_no_rtp_tchf() );
8533 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008534 execute( TC_speech_rtp_tchf() );
8535 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008536
8537 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008538
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008539 execute( TC_acch_overpower_rxqual_thresh() );
8540 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8541 execute( TC_acch_overpower_always_on_facch() );
8542 execute( TC_acch_overpower_always_on_sacch() );
8543 execute( TC_acch_overpower_limit() );
8544
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008545 /* BEWARE: these test cases can potentially break the IUT or cause
8546 * weird/unexpected behavior. Ensure that they are executed last. */
8547 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8548 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008549}
8550
8551
8552}