blob: 7476a0cb43c269cbdfb4bd0f25d01df7907574ed [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 {
Harald Welte0472ab42018-03-12 15:02:26 +0100320 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100321}
322
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700323private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100324 max_retrans := RACH_MAX_RETRANS_7,
325 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100326 cell_barr_access := false,
327 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100328 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100329};
330
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100332 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200333 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100334 acs := '0'B,
335 neci := true,
336 rxlev_access_min := 0
337}
338
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700339private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100340 mcc_mnc := '262F42'H,
341 lac := 42
342}
343
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700344private template (value) GPRSIndicator ts_GPRSIndicator_def := {
345 ra_colour := 0,
346 si13_pos := '0'B
347}
348
349private template (value) SI3RestOctets ts_SI3RestOctets_def
350modifies ts_SI3RestOctets := {
351 gprs_ind := {
352 presence := CSN1_H,
353 ind := ts_GPRSIndicator_def
354 }
355}
356
357private template (value) SI4RestOctets ts_SI4RestOctets_def
358modifies ts_SI4RestOctets := {
359 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700360 presence := CSN1_H,
361 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700362 }
363}
364
Harald Welte7484fc42018-02-24 14:09:45 +0100365/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700366private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100367 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100368 payload := {
369 si3 := {
370 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100371 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100372 ctrl_chan_desc := {
373 msc_r99 := true,
374 att := true,
375 bs_ag_blks_res := 1,
376 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100377 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100378 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
379 spare := '00'B,
380 bs_pa_mfrms := 0, /* 2 multiframes */
381 t3212 := 1 /* 6 minutes */
382 },
Harald Welte82ccef72018-02-25 16:17:33 +0100383 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100384 dn_ind := false,
385 pwrc := false,
386 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100387 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100388 },
Harald Weltef10153f2018-02-25 16:34:05 +0100389 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100390 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200391 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100392 }
393 }
394}
Harald Welte70767382018-02-21 12:16:40 +0100395
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700396private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100397 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100398 payload := {
399 si2 := {
400 bcch_freq_list := '00000000000000000000000000000000'O,
401 ncc_permitted := '11111111'B,
402 rach_control := ts_RachCtrl_default
403 }
404 }
405}
406
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700407private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100408 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100409 payload := {
410 si4 := {
411 lai := ts_LAI_default,
412 cell_sel_par := ts_CellSelPar_default,
413 rach_control := ts_RachCtrl_default,
414 cbch_chan_desc := omit,
415 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200416 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100417 }
418 }
419}
420
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700421private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100422runs on test_CT {
423 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700424 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100425}
426
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700427private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100428runs on test_CT {
429 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
430 log("Setting ", rsl_si_type, ": ", si_dec);
431 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
432}
433
Harald Welte505cf9b2018-09-15 17:47:23 +0300434friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100435 map(self:BTSVTY, system:BTSVTY);
436 f_vty_set_prompts(BTSVTY);
437 f_vty_transceive(BTSVTY, "enable");
438}
439
Harald Welte505cf9b2018-09-15 17:47:23 +0300440friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200441 map(self:BSCVTY, system:BSCVTY);
442 f_vty_set_prompts(BSCVTY, "OsmoBSC");
443 f_vty_transceive(BSCVTY, "enable");
444}
445
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200446friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
447 map(self:BSCVTY, system:BSCVTY);
448 f_vty_set_prompts(BSCVTY, "OsmoBSC");
449 f_vty_transceive(BSCVTY, "enable");
450}
451
Harald Welte883340c2018-02-28 18:59:29 +0100452/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200453friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200454 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100455 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200456 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
457 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100458 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100461 }
462}
463
Harald Weltef26de0b2018-04-04 20:28:05 +0200464private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
465 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100466 timer T := 2.0;
467 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100468 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200469 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100470 return;
471 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200472 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100473
474 T.start;
475 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200476 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100477 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100479 }
480 }
481}
482
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700483private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
484 out integer trxc_conn_id) {
485 var Result res;
486
487 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
488 "", -1, -1, { udp := {} }, {});
489 if (not ispresent(res.connId)) {
490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
491 "Could not connect to the control (TRXC) interface " &
492 "of FakeTRX, check your configuration");
493 }
494 trxc_conn_id := res.connId;
495}
496
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100497/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700498friend function f_init(uint8_t trx_nr := 0)
499runs on test_CT
500{
501 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200502 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100503
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700504 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
505 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700506 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200507 g_AllChanTypes := {
508 /* TS 1..4: TCH/F */
509 valueof(ts_RslChanNr_Bm(1)),
510 /* TS 5: TCH/H */
511 valueof(ts_RslChanNr_Lm(5,1)),
512 /* TS 0: SDCCH/4 */
513 valueof(ts_RslChanNr_SDCCH4(0,2)),
514 /* TS 6: SDCCH/8 */
515 valueof(ts_RslChanNr_SDCCH8(6,4))
516 };
517 } else {
518 g_AllChanTypes := {
519 /* TS 1..4: TCH/F */
520 valueof(ts_RslChanNr_Bm(1)),
521 /* TS 0: SDCCH/4 */
522 valueof(ts_RslChanNr_SDCCH4(0,2)),
523 /* TS 6: SDCCH/8 */
524 valueof(ts_RslChanNr_SDCCH8(6,4))
525 };
526 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700527
528 g_AllChannels := { };
529
530 /* Generate list of all logical channels from module parameters */
531 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
532 select (trx_pars.ts[tn].config) {
533 case (GSM_PCHAN_CCCH_SDCCH4) {
534 g_AllChannels := g_AllChannels &
535 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
536 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
537 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
538 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
539 }
540 case (GSM_PCHAN_SDCCH8) {
541 g_AllChannels := g_AllChannels &
542 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
543 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
544 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
545 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
546 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
547 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
550 }
551 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
552 g_AllChannels := g_AllChannels &
553 { valueof(ts_RslChanNr_Lm(tn, 0)),
554 valueof(ts_RslChanNr_Lm(tn, 1)),
555 valueof(ts_RslChanNr_Bm(tn)) };
556 }
557 case (GSM_PCHAN_TCHH) {
558 g_AllChannels := g_AllChannels &
559 { valueof(ts_RslChanNr_Lm(tn, 0)),
560 valueof(ts_RslChanNr_Lm(tn, 1)) };
561 }
562 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
563 g_AllChannels := g_AllChannels &
564 { valueof(ts_RslChanNr_Bm(tn)) };
565 }
566 }
567 }
568
Harald Welte70767382018-02-21 12:16:40 +0100569 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100570 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100571 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100572 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100573
574 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100575 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
576 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
577 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
578 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100579
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700580 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100581 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700582
583 /* Init TRXC interface to FakeTRX */
584 map(self:BTS_TRXC, system:BTS_TRXC);
585 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
586
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700587 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600588 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
589 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700590 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600591 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100592 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200593
594 /* Wait some extra time to make sure the BTS emits a stable carrier.
595 * (this is only relevant when running the tests with a physical BTS.) */
596 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100597}
598
Harald Welte68e495b2018-02-25 00:05:57 +0100599/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700600friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100601 map(self:L1CTL, system:L1CTL);
602 f_connect_reset(L1CTL);
603}
604
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200605friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100606
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700607private type record length(8) of FreqHopGroups FreqHopConfig;
608
609private type record of FreqHopGroup FreqHopGroups;
610private type record FreqHopGroup {
611 uint6_t hsn,
612 FreqHopGroupItems trx_maio
613};
614
615private type record of FreqHopGroupItem FreqHopGroupItems;
616private type record FreqHopGroupItem {
617 uint8_t trx_nr,
618 uint6_t maio
619};
620
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700621friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
622 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700623{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 var integer i, j;
626
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700627 fhp.enabled := false;
628
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700629 for (i := 0; i < lengthof(groups); i := i + 1) {
630 var FreqHopGroup g := groups[i];
631 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
632 var FreqHopGroupItem gi := g.trx_maio[j];
633 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700634 fhp.maio_hsn.maio := gi.maio;
635 fhp.maio_hsn.hsn := g.hsn;
636 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700637 break;
638 }
639 }
640
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700641 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700642 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700643 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
644 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
645 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700646
647 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700648 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
649 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700650 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700651 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700652 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700653 }
654
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700655 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700656 break; /* We're done */
657 }
658 }
659}
660
Harald Welte70767382018-02-21 12:16:40 +0100661/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700662friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
663 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200664 boolean trxc_comp := false,
665 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100666runs on test_CT return ConnHdlr {
667 var charstring id := testcasename();
668 var ConnHdlr vc_conn;
669
670 vc_conn := ConnHdlr.create(id);
671 /* connect to RSL Emulation main component */
672 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
673 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700674
675 /* The ConnHdlr component may want to talk to some ports directly,
676 * so we disconnect it from the test_CT and connect it to the component.
677 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200678 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200679 unmap(self:PCU, system:PCU);
680 map(vc_conn:PCU, system:PCU);
681 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700682 if (trxc_comp) {
683 unmap(self:BTS_TRXC, system:BTS_TRXC);
684 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
685 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200686 if (l1ctl) {
687 map(vc_conn:L1CTL, system:L1CTL);
688 }
Harald Welte70767382018-02-21 12:16:40 +0100689
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700690 /* Obtain frequency hopping parameters for a given timeslot */
691 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700692 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700693 }
694
Harald Welte70767382018-02-21 12:16:40 +0100695 vc_conn.start(f_handler_init(fn, id, pars));
696 return vc_conn;
697}
698
Harald Welte70767382018-02-21 12:16:40 +0100699private altstep as_Tguard() runs on ConnHdlr {
700 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100702 }
703}
704
Harald Welte990a3612019-05-27 14:02:13 +0200705friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700706 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700707 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100708}
709
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700710private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100711 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600712 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100713}
714
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700715private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100716 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600717 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
720/* first function started in ConnHdlr component */
721private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
722runs on ConnHdlr {
723 g_pars := pars;
724 g_chan_nr := pars.chan_nr;
725
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200726 if (L1CTL.checkstate("Mapped")) {
727 f_connect_reset(L1CTL);
728 }
Harald Welte70767382018-02-21 12:16:40 +0100729
Harald Welted48c0c72019-06-05 10:01:15 +0200730 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700731 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100732 }
Harald Welte70767382018-02-21 12:16:40 +0100733
734 g_Tguard.start(pars.t_guard);
735 activate(as_Tguard());
736
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700737 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100738
739 /* call the user-supplied test case function */
740 fn.apply(id);
741}
742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700743private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
744 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200745runs on ConnHdlr return RSL_Message {
746 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100747 timer T := 3.0;
748 RSL.send(tx);
749 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100750 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200751 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100752 T.stop;
753 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100754 }
Harald Welte1eba3742018-02-25 12:48:14 +0100755 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100757 }
Harald Welte21240e62018-03-11 21:43:35 +0100758 [not ignore_other] as_l1_sacch();
759 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700760 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700761 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100762 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100764 }
Harald Welte21240e62018-03-11 21:43:35 +0100765 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100766 }
Harald Welteb1726c92018-03-30 11:56:38 +0200767 return rx;
768}
769
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700770friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
771 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200772runs on ConnHdlr {
773 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100774}
775
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700776friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
777 boolean encr_enable := false,
778 RSL_IE_List more_ies := {},
779 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
780runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200781 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200782 if (encr_enable) {
783 /* append encryption related IEs, if requested */
784 var RSL_IE_EncryptionInfo encr_info;
785 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
786 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
787encr_info})) };
788 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200789 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200790 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100791}
792
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700793friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100794 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 +0100795 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100796}
797
Harald Welte2f2b2b72019-05-31 22:24:57 +0200798friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200799 template RSL_IE_ChannelMode chan_mode,
800 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700801 uint8_t trx_nr := 0, float t_guard := 20.0) := {
802 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100803 chan_nr := valueof(chan_nr),
804 chan_mode := valueof(chan_mode),
805 t_guard := t_guard,
806 l1_pars := {
807 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100808 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100809 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100810 meas_ul := {
811 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200812 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100813 rxqual := 0
814 },
815 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200816 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100817 rxqual := 0
818 }
819 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200820 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100821 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200822 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200823 ms_actual_ta := mp_ms_actual_ta_exp,
824 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100825 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200826 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200827 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700828 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700829 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700830 fhp := {
831 enabled := false,
832 maio_hsn := ts_HsnMaio(0, 0),
833 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700834 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700835 }
Harald Welte70767382018-02-21 12:16:40 +0100836}
837
Harald Welte93640c62018-02-25 16:59:33 +0100838/***********************************************************************
839 * Channel Activation / Deactivation
840 ***********************************************************************/
841
Harald Welte70767382018-02-21 12:16:40 +0100842/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700843private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100844 for (var integer i := 0; i < 500; i := i+1) {
845 f_rsl_chan_act(g_pars.chan_mode);
846 f_rsl_chan_deact();
847 }
848 setverdict(pass);
849}
850testcase TC_chan_act_stress() runs on test_CT {
851 var ConnHdlr vc_conn;
852 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200853 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100854 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
855 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100857}
858
859/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700860private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100861 f_rsl_chan_act(g_pars.chan_mode);
862 /* attempt to activate the same lchan again -> expect reject */
863 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
864 alt {
865 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100867 }
868 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
869 setverdict(pass);
870 }
871 }
872 f_rsl_chan_deact();
873}
874testcase TC_chan_act_react() runs on test_CT {
875 var ConnHdlr vc_conn;
876 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100877 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100878 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
879 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100881}
882
883/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700884private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100885 timer T := 3.0;
886 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
887 T.start;
888 alt {
889 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
890 setverdict(pass);
891 }
892 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100894 }
895 }
896}
897testcase TC_chan_deact_not_active() runs on test_CT {
898 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100899 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100900 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
901 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100903}
904
905/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700906private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100907 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
908 alt {
909 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100911 }
912 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
913 setverdict(pass);
914 }
915 }
916}
917private type record WrongChanNrCase {
918 RslChannelNr chan_nr,
919 charstring description
920}
921private type record of WrongChanNrCase WrongChanNrCases;
922private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
923 chan_nr := chan_nr,
924 description := desc
925}
926
927testcase TC_chan_act_wrong_nr() runs on test_CT {
928 var ConnHdlr vc_conn;
929 var ConnHdlrPars pars;
930
Harald Welte294b0a22018-03-10 23:26:48 +0100931 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100932
933 var WrongChanNrCases wrong := {
934 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
935 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
936 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
937 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
938 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
939 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
940 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
941 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
942 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
943 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
944 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
945 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
946 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
947 };
948
949 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
950 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
951 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
952 vc_conn.done;
953 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100955}
956
Harald Weltee613f962018-04-18 22:38:16 +0200957/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200958friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200959 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200960 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200961
962 /* test on each of the channels we have */
963 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
964 pars.chan_nr := valueof(g_AllChanTypes[i]);
965
966 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
967 vc_conn := f_start_handler(fn, pars);
968 vc_conn.done;
969 }
970
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200972}
973
Harald Welte93640c62018-02-25 16:59:33 +0100974/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100975 * SACCH handling
976 ***********************************************************************/
977
978private function f_exp_sacch(boolean exp) runs on ConnHdlr {
979 timer T_sacch := 3.0;
980 T_sacch.start;
981 alt {
982 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100984 }
985 [not exp] T_sacch.timeout {
986 setverdict(pass);
987 }
988 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
989 setverdict(pass);
990 }
991 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100993 }
994 [] L1CTL.receive { repeat; }
995 [] RSL.receive { repeat; }
996 }
997}
998
999/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1000private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1001 f_l1_tune(L1CTL);
1002 RSL.clear;
1003
1004 /* activate the logical channel */
1005 f_est_dchan();
1006 L1CTL.clear;
1007
1008 /* check that SACCH actually are received as expected */
1009 f_exp_sacch(true);
1010
1011 /* deactivate SACCH on the logical channel */
1012 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1013 f_sleep(1.0);
1014 L1CTL.clear;
1015
1016 /* check that no SACCH are received anymore */
1017 f_exp_sacch(false);
1018
1019 /* release the channel */
1020 f_rsl_chan_deact();
1021 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1022}
1023testcase TC_deact_sacch() runs on test_CT {
1024 var ConnHdlr vc_conn;
1025 var ConnHdlrPars pars;
1026 f_init();
1027 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1028 //for (var integer i := 0; i < 1; i := i+1) {
1029 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1030 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1031 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1032 vc_conn.done;
1033 }
1034 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001036}
1037
Harald Welte55700662018-03-12 13:15:43 +01001038/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001039private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1040 var L1ctlDlMessage dl;
1041 /* check that the specified SI5 value is actually sent */
1042 timer T_sacch := 3.0;
1043 L1CTL.clear;
1044 T_sacch.start;
1045 alt {
1046 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1047 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1048 if (match(l3, l3_exp)) {
1049 setverdict(pass);
1050 } else {
1051 repeat;
1052 }
1053 }
1054 [] L1CTL.receive { repeat; }
1055 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001057 }
1058 }
1059}
1060
Harald Welte55700662018-03-12 13:15:43 +01001061/* verify that given SACCH payload is not present */
1062private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1063 var L1ctlDlMessage dl;
1064 /* check that the specified SI5 value is actually sent */
1065 timer T_sacch := 3.0;
1066 L1CTL.clear;
1067 T_sacch.start;
1068 alt {
1069 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1070 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1071 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001073 } else {
1074 repeat;
1075 }
1076 }
1077 [] L1CTL.receive { repeat; }
1078 [] T_sacch.timeout {
1079 setverdict(pass);
1080 }
1081 }
1082}
1083
Harald Welte629cc6b2018-03-11 17:19:05 +01001084/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001085private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1086 /* Set a known default SACCH filling for SI5 */
1087 var octetstring si5 := f_rnd_octstring(19);
1088 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1089
1090 f_l1_tune(L1CTL);
1091 RSL.clear;
1092
1093 /* activate the logical channel */
1094 f_est_dchan();
1095
1096 /* check that the specified SI5 value is actually sent */
1097 f_sacch_present(si5);
1098
1099 /* release the channel */
1100 RSL.clear;
1101 f_rsl_chan_deact();
1102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1103}
1104testcase TC_sacch_filling() runs on test_CT {
1105 var ConnHdlr vc_conn;
1106 var ConnHdlrPars pars;
1107 f_init();
1108 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1109 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1110 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1111 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1112 vc_conn.done;
1113 }
1114 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001116}
1117
Harald Welte629cc6b2018-03-11 17:19:05 +01001118/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001119private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1120 /* Set a known default SACCH filling for SI5 */
1121 var octetstring si5 := f_rnd_octstring(19);
1122 var octetstring si5_diff := f_rnd_octstring(19);
1123 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1124
1125 f_l1_tune(L1CTL);
1126 RSL.clear;
1127
1128 log("Activating channel, expecting standard SI5");
1129 /* activate the logical channel */
1130 f_est_dchan();
1131 /* check that the specified SI5 value is actually sent */
1132 f_sacch_present(si5);
1133
1134 /* set channel-specific different SI5 */
1135 log("Setting channel specific SACCH INFO, expecting it");
1136 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1137 /* check that the specified lchan-specific value is now used */
1138 f_sacch_present(si5_diff);
1139
1140 /* deactivate the channel and re-activate it, this should result in default SI5 */
1141 log("De-activating and re-activating channel, expecting standard SI5");
1142 f_rsl_chan_deact();
1143 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1144 /* Verify that the TRX-wide default SACCH filling is present again */
1145 f_sacch_present(si5);
1146
1147 /* release the channel */
1148 RSL.clear;
1149 f_rsl_chan_deact();
1150 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1151}
1152testcase TC_sacch_info_mod() runs on test_CT {
1153 var ConnHdlr vc_conn;
1154 var ConnHdlrPars pars;
1155 f_init();
1156 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1157 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1158 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1159 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1160 vc_conn.done;
1161 }
1162 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001164}
1165
Harald Welte075d84c2018-03-12 13:07:24 +01001166/* Test SACCH scheduling of multiple different SI message types */
1167private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1168 var octetstring si5 := f_rnd_octstring(19);
1169 var octetstring si5bis := f_rnd_octstring(19);
1170 var octetstring si5ter := f_rnd_octstring(19);
1171 var octetstring si6 := f_rnd_octstring(19);
1172
1173 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1174 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1175 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1176 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1177
1178 f_l1_tune(L1CTL);
1179 RSL.clear;
1180
1181 /* activate the logical channel */
1182 f_est_dchan();
1183 L1CTL.clear;
1184
1185 /* check that SACCH actually are received as expected */
1186 f_sacch_present(si5);
1187 f_sacch_present(si5bis);
1188 f_sacch_present(si5ter);
1189 f_sacch_present(si6);
1190
1191 /* release the channel */
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_multi() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1200 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1201 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1202 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1203 vc_conn.done;
1204 }
1205 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001207}
1208
Harald Welte55700662018-03-12 13:15:43 +01001209/* Test if SACH information is modified as expected */
1210private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1211 var octetstring si5 := f_rnd_octstring(19);
1212 var octetstring si6 := f_rnd_octstring(19);
1213
1214 /* First, configure both SI5 and SI6 to be transmitted */
1215 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1216 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1217
1218 f_l1_tune(L1CTL);
1219 RSL.clear;
1220
1221 /* activate the logical channel */
1222 f_est_dchan();
1223 L1CTL.clear;
1224
1225 /* check that SACCH actually are received as expected */
1226 f_sacch_present(si5);
1227 f_sacch_present(si6);
1228
1229 /* disable SI6 */
1230 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1231
1232 /* check that SI5 is still transmitted */
1233 f_sacch_present(si5);
1234 /* check if SI6 is now gone */
1235 f_sacch_missing(si6);
1236
1237 /* release the channel */
1238 f_rsl_chan_deact();
1239 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1240}
1241testcase TC_sacch_multi_chg() runs on test_CT {
1242 var ConnHdlr vc_conn;
1243 var ConnHdlrPars pars;
1244 f_init();
1245 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1246 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1247 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1248 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1249 vc_conn.done;
1250 }
1251 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001253}
1254
Harald Weltec8d363c2019-05-19 20:36:48 +02001255/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1256private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1257 var octetstring si5 := f_rnd_octstring(19);
1258 var octetstring si6 := f_rnd_octstring(19);
1259 var octetstring si5_specific := f_rnd_octstring(19);
1260 var octetstring si6_specific := f_rnd_octstring(19);
1261
1262 /* First, configure both SI5 and SI6 to be transmitted */
1263 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1264 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1265
1266 f_l1_tune(L1CTL);
1267 RSL.clear;
1268
1269 /* activate channel with different SACCH filling */
1270 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1271 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1272 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1273 }));
1274 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1275 RSL_IE_Body:{sacch_info := sacch_info})) };
1276 f_est_dchan(more_ies := addl_ies);
1277
1278 /* check that SACCH actually are received as expected */
1279 f_sacch_present(si5_specific);
1280 f_sacch_present(si6_specific);
1281
1282 /* release the channel */
1283 f_rsl_chan_deact();
1284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1285}
1286testcase TC_sacch_chan_act() runs on test_CT {
1287 var ConnHdlr vc_conn;
1288 var ConnHdlrPars pars;
1289 f_init();
1290
1291 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1292 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1293 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1294 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1295 vc_conn.done;
1296 }
1297 /* TODO: do the above in parallel, rather than sequentially? */
1298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1299}
1300
Harald Welte8b01c792019-05-19 22:51:25 +02001301/* verify that SACCH DL transmission is started only if MS power IE present
1302 * see section 4.1.3 of 3GPP TS 48.058 */
1303private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1304 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001305 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001306
1307 f_l1_tune(L1CTL);
1308 RSL.clear;
1309
1310 /* Step 1: Activate ASYNC HO channel without MS power IE */
1311
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001312 var integer ho_ref := oct2int(f_rnd_octstring(1));
1313 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1314 RSL_IE_Body:{ handover_ref := ho_ref }));
1315 var RSL_IE_List addl_ies := {
1316 ho_ref_ie
1317 };
1318
Harald Welte8b01c792019-05-19 22:51:25 +02001319 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001320 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 +02001321 /* don't perform immediate assignment here, as we're testing non-IA case */
1322 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001323 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001324
1325 /* Verify that no DL SACCH is being received */
1326 f_sacch_missing(?);
1327
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001328 /* Send handover Access Burst and expect SACCH to start */
1329 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1330
1331 f_sacch_present(si5);
1332
Harald Welte8b01c792019-05-19 22:51:25 +02001333 f_rsl_chan_deact();
1334 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1335
1336
1337 /* Step 2: Activate ASYNC HO channel with MS power IE */
1338
1339 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001340 addl_ies := {
1341 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001342 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1343 };
1344 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1345 /* don't perform immediate assignment here, as we're testing non-IA case */
1346 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001347 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001348
1349 /* Verify that DL SACCH is being received */
1350 f_sacch_present(si5);
1351
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001352 /* Send handover Access Burst and expect SACCH to remain present */
1353 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1354
1355 f_sacch_present(si5);
1356
Harald Welte8b01c792019-05-19 22:51:25 +02001357 f_rsl_chan_deact();
1358 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1359}
1360testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1361 var ConnHdlr vc_conn;
1362 var ConnHdlrPars pars;
1363 f_init();
1364
1365 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1366 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1367 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1368 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1369 vc_conn.done;
1370 }
1371 /* TODO: do the above in parallel, rather than sequentially? */
1372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1373}
1374
1375/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1376 * see section 4.1.4 of 3GPP TS 48.058 */
1377private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1378 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001379 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1380
Harald Welte8b01c792019-05-19 22:51:25 +02001381 var RSL_IE_List addl_ies;
1382
1383 f_l1_tune(L1CTL);
1384 RSL.clear;
1385
1386 /* Step 1: Activate SYNC HO channel without MS power IE */
1387
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001388 var integer ho_ref := oct2int(f_rnd_octstring(1));
1389 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1390 RSL_IE_Body:{ handover_ref := ho_ref }));
1391 addl_ies := {
1392 ho_ref_ie
1393 };
1394
Harald Welte8b01c792019-05-19 22:51:25 +02001395 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001396 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 +02001397 /* don't perform immediate assignment here, as we're testing non-IA case */
1398 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001399 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001400
1401 /* Verify that no DL SACCH is being received */
1402 f_sacch_missing(?);
1403
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001404 /* Send handover Access Burst and expect SACCH to start */
1405 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1406
1407 f_sacch_present(si5);
1408
Harald Welte8b01c792019-05-19 22:51:25 +02001409 f_rsl_chan_deact();
1410 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1411
1412
1413 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1414
1415 /* Activate channel on BTS side */
1416 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001417 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001418 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1419 };
1420 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1421 /* don't perform immediate assignment here, as we're testing non-IA case */
1422 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001423 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001424
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001425 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1426 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001427
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001428 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001429 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1430
1431 f_sacch_present(si5);
1432
Harald Welte8b01c792019-05-19 22:51:25 +02001433 f_rsl_chan_deact();
1434 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1435
1436
1437 /* Step 2b: Activate SYNC HO channel with TA IE */
1438
1439 /* Activate channel on BTS side */
1440 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001441 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001442 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1443 };
1444 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1445 /* don't perform immediate assignment here, as we're testing non-IA case */
1446 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001447 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001448
1449 /* Verify that no DL SACCH is being received */
1450 f_sacch_missing(?);
1451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to start */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459
1460
1461 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1462
1463 /* Activate channel on BTS side */
1464 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001465 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001466 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1467 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1468 };
1469 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1470 /* don't perform immediate assignment here, as we're testing non-IA case */
1471 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001472 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001473
1474 /* Verify that DL SACCH is being received */
1475 f_sacch_present(si5);
1476
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001477 /* Send handover Access Burst and expect SACCH to remain present */
1478 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1479
1480 f_sacch_present(si5);
1481
Harald Welte8b01c792019-05-19 22:51:25 +02001482 f_rsl_chan_deact();
1483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1484}
1485testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init();
1489
1490 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1491 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1492 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1493 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1494 vc_conn.done;
1495 }
1496 /* TODO: do the above in parallel, rather than sequentially? */
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
Harald Welte629cc6b2018-03-11 17:19:05 +01001499
1500
1501/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001502 * RACH Handling
1503 ***********************************************************************/
1504
Harald Welte8c24c2b2018-02-26 08:31:31 +01001505/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001506private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001507 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001508 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001509 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001510
Harald Welte8c24c2b2018-02-26 08:31:31 +01001511 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001512 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001513 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001514 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001515 if (emerg == true) {
1516 ra := f_rnd_ra_emerg();
1517 } else {
1518 ra := f_rnd_ra_cs();
1519 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001520 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1521 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001523 }
1524 fn_last := fn;
1525
1526 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001527 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001528 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001529 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001530 T.stop;
1531 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001532 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001534 }
1535 [] RSL_CCHAN.receive { repeat; }
1536 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001537 test_failed := true;
1538 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001539 }
1540 }
1541 }
Maxba06feb2019-03-05 10:52:46 +01001542 if (test_failed) {
1543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001544 }
Maxba06feb2019-03-05 10:52:46 +01001545 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001547}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001548
Philipp Maier16ade782020-07-08 21:36:00 +02001549/* Normal variant */
1550testcase TC_rach_content() runs on test_CT {
1551 f_TC_rach_content(emerg := false);
1552}
1553
1554/* Emergency call variant */
1555testcase TC_rach_content_emerg() runs on test_CT {
1556 f_TC_rach_content(emerg := true);
1557}
1558
Harald Welte8c24c2b2018-02-26 08:31:31 +01001559/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1560testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001561 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001562 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001563 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001564 f_l1_tune(L1CTL);
1565
1566 var GsmFrameNumber fn_last := 0;
1567 for (var integer i := 0; i < 1000; i := i+1) {
1568 var OCT1 ra := f_rnd_ra_cs();
1569 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1570 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001572 }
1573 fn_last := fn;
1574 }
1575 var integer rsl_chrqd := 0;
1576 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001577 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001580 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001581 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001582 repeat;
1583 }
1584 [] RSL_CCHAN.receive { repeat; }
1585 [] T.timeout { }
1586 }
1587 if (rsl_chrqd == 1000) {
1588 setverdict(pass);
1589 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001591 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001593}
1594
Harald Welte3453ab42019-05-24 21:19:58 +02001595private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1596 var charstring bts_str := "bts " & int2str(bts_nr);
1597 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1598}
1599
1600/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1601private template integer tr_rach_slots_per_interval := (90 .. 130);
1602
1603/* Expect 0 RACH load on an idle BTS that has just started up */
1604testcase TC_rach_load_idle_thresh0() runs on test_CT {
1605 var ASP_RSL_Unitdata rx_ud;
1606
1607 f_init_vty_bsc();
1608 /* send load indications even at 0% load */
1609 f_vty_load_ind_thresh(0);
1610 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1611 f_sleep(2.0);
1612
1613 f_init();
1614
Harald Weltee37f9a52020-10-11 20:45:23 +02001615 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1616 alt {
1617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1618 [] RSL_CCHAN.receive { repeat }
1619 }
1620
Harald Welte3453ab42019-05-24 21:19:58 +02001621 timer T := 5.0;
1622 T.start;
1623 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [] 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 +02001625 setverdict(pass);
1626 repeat;
1627 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001628 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001629 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1630 repeat;
1631 }
1632 [] RSL_CCHAN.receive {
1633 repeat;
1634 }
1635 [] T.timeout { }
1636 }
1637
1638 f_vty_load_ind_thresh(10);
1639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1640}
1641
1642/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1643testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1644 var ASP_RSL_Unitdata rx_ud;
1645
1646 f_init_vty_bsc();
1647 f_init();
1648
1649 timer T := 5.0;
1650 T.start;
1651 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001652 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001653 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1654 repeat;
1655 }
1656 [] RSL_CCHAN.receive {
1657 repeat;
1658 }
1659 [] T.timeout {
1660 setverdict(pass);
1661 }
1662 }
1663
1664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1665}
1666
1667/* Expect 0 RACH load on an idle BTS that has just started up */
1668testcase TC_rach_load_count() runs on test_CT {
1669 var ASP_RSL_Unitdata rx_ud;
1670 var integer load_access_count := 0;
1671
1672 f_init_vty_bsc();
1673 /* send load indications even at 0% load */
1674 f_vty_load_ind_thresh(0);
1675 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1676 f_sleep(2.0);
1677 f_init();
1678
1679 f_init_l1ctl();
1680 f_sleep(1.0);
1681 f_l1_tune(L1CTL);
1682
Harald Welte52ae1682020-10-11 20:45:55 +02001683 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1684 alt {
1685 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1686 [] RSL_CCHAN.receive { repeat }
1687 }
1688
Harald Welte3453ab42019-05-24 21:19:58 +02001689 var GsmFrameNumber fn_last := 0;
1690 for (var integer i := 0; i < 1000; i := i+1) {
1691 var OCT1 ra := f_rnd_ra_cs();
1692 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1693 if (fn == fn_last) {
1694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1695 }
1696 fn_last := fn;
1697 }
1698
1699 timer T := 5.0;
1700 T.start;
1701 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001702 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001703 -> value rx_ud {
1704 var RSL_IE_Body ie;
1705 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1706 load_access_count := load_access_count + ie.rach_load.access_count;
1707 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1708 setverdict(fail, "Access count cannot be < Busy count");
1709 }
1710 repeat;
1711 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001712 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001713 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1714 repeat;
1715 }
1716 [] RSL_CCHAN.receive {
1717 repeat;
1718 }
1719 [] T.timeout { }
1720 }
1721 if (load_access_count == 1000) {
1722 setverdict(pass);
1723 } else {
1724 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1725 }
1726
1727 f_vty_load_ind_thresh(10);
1728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1729}
1730
Harald Welte54a2a2d2018-02-26 09:14:05 +01001731private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001732 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001733 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001734 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001735 f_sleep(0.5);
1736
1737 /* Transmit RACH request + wait for confirmation */
1738 var OCT1 ra := f_rnd_ra_cs();
1739 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1740
1741 /* Check for expected result */
1742 timer T := 1.5;
1743 T.start;
1744 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001745 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001746 setverdict(pass);
1747 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001748 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001750 }
1751 [] RSL_CCHAN.receive { repeat; }
1752 [not expect_pass] T.timeout {
1753 setverdict(pass);
1754 }
1755 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001757 }
1758 }
1759}
1760
1761/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1762testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001763 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001764 f_init_l1ctl();
1765 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001766 f_sleep(1.0);
1767
1768 /* default max-ta is 63 (full range of GSM timing advance */
1769
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001770 /* We allow early arrival up to 2 symbols */
1771 f_rach_toffs(-1*256, true);
1772 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001773 f_rach_toffs(-10*256, false);
1774
1775 /* 0 / 32 / 63 bits is legal / permitted */
1776 f_rach_toffs(0, true);
1777 f_rach_toffs(32*256, true);
1778 f_rach_toffs(63*256, true);
1779
1780 /* more than 63 bits is not legal / permitted */
1781 f_rach_toffs(64*256, false);
1782 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001784}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001785
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001786private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001787 var GsmFrameNumber fn;
1788 var RSL_Message rm;
1789
1790 f_l1_tune(L1CTL);
1791 RSL.clear;
1792
1793 /* Generate a random Handover Reference */
1794 var integer ho_ref := oct2int(f_rnd_octstring(1));
1795
1796 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1797 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1798 RSL_IE_Body:{ handover_ref := ho_ref }));
1799
1800 /* Activate a channel on the BTS side (no encryption) */
1801 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1802 act_type := t_RSL_IE_ActType_HO_SYNC);
1803
1804 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1805 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001806 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001807
1808 /* Send handover Access Burst */
1809 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1810
1811 /* TODO: test mismatching Handover Reference, and missing IE */
1812
1813 /* Wait for handover detection */
1814 timer T := 3.0;
1815 T.start;
1816 alt {
1817 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1818 log("Handover RACH has been detected: ", rm);
1819 setverdict(pass);
1820 }
1821 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1823 log2str("RSL_CHAN_RQD was not expected: ", rm));
1824 }
1825 [] RSL.receive { repeat; }
1826 [] T.timeout {
1827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1828 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1829 }
1830 }
1831
1832 /* Release the channel */
1833 f_rsl_chan_deact();
1834 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1835}
1836
1837/* Test handover RACH detection */
1838testcase TC_ho_rach() runs on test_CT {
1839 var ConnHdlrPars pars;
1840 var ConnHdlr vc_conn;
1841
1842 f_init();
1843
1844 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1845 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1846 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1847 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1848 vc_conn.done;
1849 }
1850
1851 /* TODO: do the above in parallel, rather than sequentially? */
1852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1853}
1854
Harald Welte93640c62018-02-25 16:59:33 +01001855/***********************************************************************
1856 * Measurement Processing / Reporting
1857 ***********************************************************************/
1858
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001859private template (value) LapdmAddressField
1860ts_LapdmAddr(template (value) LapdmSapi sapi,
1861 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001862 spare := '0'B,
1863 lpd := 0,
1864 sapi := sapi,
1865 c_r := c_r,
1866 ea := true
1867}
1868
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001869private template (value) LapdmFrameAB
1870ts_LAPDm_AB(template (value) LapdmSapi sapi,
1871 template (value) GsmRrL3Message l3,
1872 template (value) boolean c_r := false,
1873 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001874 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001875 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001876 len := 0, /* overwritten */
1877 m := false,
1878 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001879 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001880}
1881
1882/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001883private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001884 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001885 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001886
Harald Weltef8df4cb2018-03-10 15:15:08 +01001887 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001888 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001889
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001890 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001891 g_pars.l1_pars.meas_ul.full.rxlev,
1892 g_pars.l1_pars.meas_ul.sub.rxlev,
1893 g_pars.l1_pars.meas_ul.full.rxqual,
1894 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001895 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001896
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001897 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1898 g_pars.l1_pars.ms_power_level, false,
1899 g_pars.l1_pars.ms_actual_ta);
1900
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001901 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1902 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001903
1904 log("Sending Measurement Report: ", l1h, l2);
1905 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001906 repeat;
1907 }
1908}
1909
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001910/* handle incoming downlink SACCH, decode the L1 header into the given record */
1911private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1912 boolean do_apply := true)
1913runs on ConnHdlr
1914{
1915 var L1ctlDlMessage l1_dl;
1916
1917 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1918 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1919 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1920 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1921
1922 if (do_apply) {
1923 /* Update TA and MS power to follow what BTS requests */
1924 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1925 }
1926 }
1927}
1928
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001929private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001930 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001931 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001932 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1933 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001934 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1935 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001936 repeat;
1937 }
1938}
1939
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001940private altstep as_l1_tch_loop() runs on ConnHdlr {
1941 var L1ctlDlMessage l1_dl;
1942 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1943 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001944
1945 /* occasionaly inject FACCH frames into the uplink */
1946 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1947 var octetstring pl := '010301'O;
1948 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1949 f_pad_oct(pl, 23, '2B'O)));
1950 } else {
1951 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1952 l1_dl.payload.traffic_ind.data));
1953 }
1954
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001955 repeat;
1956 }
1957}
1958
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001959private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001960 uint6_t rxlev,
1961 uint3_t rxqual
1962}
1963
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001964private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001965 MeasElem full,
1966 MeasElem sub
1967}
1968
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001969private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001970 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001971 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001972 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001973 MeasElemFS meas_ul,
1974 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001975 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001976 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001977 uint8_t ms_actual_ta,
1978 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001979}
1980
1981/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1982private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1983 return 63 + (toffs256s/256);
1984}
1985
Harald Welted5684392018-03-10 18:22:04 +01001986private function f_max(integer a, integer b) return integer {
1987 if (a > b) {
1988 return a;
1989 } else {
1990 return b;
1991 }
1992}
1993
1994private function f_min(integer a, integer b) return integer {
1995 if (a < b) {
1996 return a;
1997 } else {
1998 return b;
1999 }
2000}
2001
2002/* compute negative tolerance val-tolerance, ensure >= min */
2003private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2004 val := val - tolerance;
2005 return f_max(val, min);
2006}
2007
2008/* compute positive tolerance val+tolerance, ensure <= max */
2009private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2010 val := val + tolerance;
2011 return f_min(val, max);
2012}
2013
2014/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2015private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2016return template integer {
2017 var template integer ret;
2018 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2019 return ret;
2020}
2021
2022
Harald Welte70767382018-02-21 12:16:40 +01002023/* build a template for matching measurement results against */
2024private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2025 var ConnL1Pars l1p := g_pars.l1_pars;
2026 var template RSL_IE_UplinkMeas ul_meas := {
2027 len := 3,
2028 rfu := '0'B,
2029 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002030 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002031 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002032 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002033 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002034 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2035 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002036 supp_meas_info := omit
2037 };
Harald Welte685d5982018-02-27 20:42:05 +01002038 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002039 ul_meas.len := (3+8);
2040 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002041 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002042 toa256_min := ?,
2043 toa256_max := ?,
2044 toa256_std_dev := ?
2045 }
Harald Welte685d5982018-02-27 20:42:05 +01002046 }
Harald Welte70767382018-02-21 12:16:40 +01002047 var template RSL_IE_BS_Power bs_power := {
2048 reserved := 0,
2049 epc := false,
2050 fpc := false,
2051 power_level := l1p.bs_power_level
2052 };
2053 var template RSL_IE_L1Info l1_info := {
2054 ms_power_lvl := l1p.ms_power_level,
2055 fpc := false,
2056 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002057 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002058 };
2059 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002060 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002061 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2062 ?, t_toffs);
2063}
2064
Philipp Maierdd841d32019-12-17 14:44:54 +01002065/* build a template for matching measurement results that do not contain any
2066 * MS related measurement (l1_info, l3_info and ms timing offset). */
2067private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2068 var ConnL1Pars l1p := g_pars.l1_pars;
2069 var template RSL_IE_UplinkMeas ul_meas := {
2070 len := 3,
2071 rfu := '0'B,
2072 dtx_d := l1p.dtx_enabled,
2073 rxlev_f_u := ?,
2074 reserved1 := '00'B,
2075 rxlev_s_u := ?,
2076 reserved2 := '00'B,
2077 rxq_f_u := ?,
2078 rxq_s_u := ?,
2079 supp_meas_info := omit
2080 };
2081 if (l1p.toa256_enabled) {
2082 ul_meas.len := (3+8);
2083 ul_meas.supp_meas_info := {
2084 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2085 toa256_min := ?,
2086 toa256_max := ?,
2087 toa256_std_dev := ?
2088 }
2089 }
2090 var template RSL_IE_BS_Power bs_power := {
2091 reserved := 0,
2092 epc := false,
2093 fpc := false,
2094 power_level := l1p.bs_power_level
2095 };
2096
2097 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2098}
2099
Harald Welte70767382018-02-21 12:16:40 +01002100/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002101private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002102 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002103 var boolean chan_est := false;
2104
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002105 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002106
2107 /* Receive osmocom specific measurement reports. This is the normal
2108 * case. Here we verify that the measurement reports we sent are
2109 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002110 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2111 /* increment counter of next to-be-expected meas rep */
2112 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2113 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002114 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002115
2116 /* The following two cases may only happen in the beginning
2117 * of the channel establishment phase. Once we have received
2118 * the "our" measurement report the first time, the channel
2119 * is established and empty or hardcoded TRXCON reports must
2120 * not occur anymore. */
2121 chan_est := true;
2122
2123 repeat;
2124 }
2125
2126 /* When the BTS has established the channel, the MS might need slightly
2127 * more time to establish the channel and actually start sending. The
2128 * result is then a measurement report that just lacks the measurement
2129 * information of the MS. This is normal and we tolerate this behavior. */
2130 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2131 /* increment counter of next to-be-expected meas rep */
2132 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2133 /* Re-start the timer expecting the next MEAS RES */
2134 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002135 repeat;
2136 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002137
2138 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2139 * measurements if the TTCN3 side does not supply measurement input in
2140 * time. In those cases TRXCON will either use a cached measurement
2141 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2142 * report the templates above will not match. We tolerate this
2143 * behavior, but only once. */
2144 [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 +01002145 /* increment counter of next to-be-expected meas rep */
2146 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2147 if (g_first_meas_res) {
2148 g_first_meas_res := false;
2149 repeat;
2150 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002152 }
Harald Welte70767382018-02-21 12:16:40 +01002153 }
2154 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002156 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002157 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002159 }
2160}
2161
Harald Weltee613f962018-04-18 22:38:16 +02002162private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2163 select (rsl_alg_id) {
2164 case (RSL_ALG_ID_A5_0) { return 0; }
2165 case (RSL_ALG_ID_A5_1) { return 1; }
2166 case (RSL_ALG_ID_A5_2) { return 2; }
2167 case (RSL_ALG_ID_A5_3) { return 3; }
2168 case (RSL_ALG_ID_A5_4) { return 4; }
2169 case (RSL_ALG_ID_A5_5) { return 5; }
2170 case (RSL_ALG_ID_A5_6) { return 6; }
2171 case (RSL_ALG_ID_A5_7) { return 7; }
2172 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2174 /* Make compiler happy by calling mtc.stop here. It is already
2175 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002176 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002177 }
2178 }
2179}
2180
2181private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2182 select (rsl_alg_id) {
2183 case (RSL_ALG_ID_A5_1) { return '000'B; }
2184 case (RSL_ALG_ID_A5_2) { return '001'B; }
2185 case (RSL_ALG_ID_A5_3) { return '010'B; }
2186 case (RSL_ALG_ID_A5_4) { return '011'B; }
2187 case (RSL_ALG_ID_A5_5) { return '100'B; }
2188 case (RSL_ALG_ID_A5_6) { return '101'B; }
2189 case (RSL_ALG_ID_A5_7) { return '110'B; }
2190 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2192 /* Make compiler happy by calling mtc.stop here. It is already
2193 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002194 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002195 }
2196 }
2197}
2198
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002199/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2200private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2201 var GsmFrameNumber fn;
2202 timer T := 8.0;
2203
2204 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2205 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2206
2207 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2208 /* Send the actual RACH */
2209 fn := f_L1CTL_RACH(L1CTL, ra);
2210
2211 T.start;
2212 alt {
2213 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2214 [] T.timeout {
2215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2216 }
2217 }
2218 T.stop
2219 return fn;
2220}
Harald Weltee613f962018-04-18 22:38:16 +02002221
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002222/* Tune to a dedicated channel: L1CTL only */
2223private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002224 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002225 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002226 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002227 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002228 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002229 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002230 pars.fhp.maio_hsn.hsn,
2231 pars.fhp.maio_hsn.maio,
2232 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002233 }
2234}
2235
Harald Welte70767382018-02-21 12:16:40 +01002236/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002237private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002238 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002239
2240 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002241 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002242
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002243 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002244 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002245 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002246 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002247 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2248 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002249 }
2250
Harald Welte70767382018-02-21 12:16:40 +01002251 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002252 f_l1ctl_est_dchan(L1CTL, g_pars);
2253
Harald Weltee613f962018-04-18 22:38:16 +02002254 /* enable encryption, if requested */
2255 if (encr_enable) {
2256 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2257 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2258 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002259
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002260 /* Send TCH Mode Request to the L1 if needed */
2261 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2262 var L1ctlTchMode tch_mode;
2263
2264 select (g_pars.chan_mode.coding_alg_rate) {
2265 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2266 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2267 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2268 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2269 case else {
2270 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2271 " is not supported by the L1, falling back to signalling");
2272 tch_mode := L1CTL_CHAN_MODE_SIGN;
2273 }
2274 }
2275
2276 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2277 }
2278
Harald Weltefa45e9e2018-03-10 18:59:03 +01002279 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002280}
2281
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002282/* Initialize and start the RTP emulation component for a ConnHdlr */
2283friend function f_rtpem_activate(inout octetstring payload,
2284 RtpemConfig cfg := c_RtpemDefaultCfg,
2285 RtpemMode mode := RTPEM_MODE_BIDIR)
2286runs on ConnHdlr {
2287 /* Step 0: initialize, connect and start the emulation component */
2288 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2289 map(vc_RTPEM:RTP, system:RTP);
2290 map(vc_RTPEM:RTCP, system:RTCP);
2291 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2292 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2293 vc_RTPEM.start(RTP_Emulation.f_main());
2294
2295 /* Step 1: configure the RTP parameters */
2296 var integer payload_len := 0;
2297 var octetstring hdr := ''O;
2298
2299 select (g_pars.chan_mode) {
2300 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2301 { payload_len := 33; hdr := 'D0'O; }
2302 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2303 { payload_len := 15; hdr := '00'O; }
2304 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2305 { payload_len := 31; hdr := 'C0'O; }
2306 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2307 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2309 }
2310 }
2311
2312 /* Pad the payload to conform the expected length */
2313 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2314 cfg.tx_fixed_payload := payload;
2315 f_rtpem_configure(RTPEM_CTRL, cfg);
2316
2317 /* Step 2: bind the RTP emulation to the configured address */
2318 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2319 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2320
2321 /* Step 3: send CRCX with the configured address/port to the IUT */
2322 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2323 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2324 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2325 "IPA CRCX ACK");
2326
2327 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2328 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2329 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2330 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2331
2332 /* Step 5: set the given RTP emulation mode */
2333 f_rtpem_mode(RTPEM_CTRL, mode);
2334}
2335
Harald Welte70767382018-02-21 12:16:40 +01002336/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002337private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002338 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002339 RSL.clear;
2340
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002341 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002342 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002343 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002344 }
Harald Welte70767382018-02-21 12:16:40 +01002345
2346 f_est_dchan();
2347
2348 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2349 * RSL measurement reports on Abis side */
2350 timer T := 8.0;
2351 T.start;
2352 alt {
2353 [] as_l1_sacch();
2354 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002355 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002356 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002357 [] L1CTL.receive { repeat; }
2358 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002359 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002360 * of any earlier errors, so if we reach this timeout, we're good */
2361 setverdict(pass);
2362 }
2363 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002365 }
2366 }
2367 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002368 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002369}
Harald Welte0472ab42018-03-12 15:02:26 +01002370
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002371/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2372private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002373 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002374 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2375 timer Tup := 10.0;
2376 Tup.start;
2377 alt {
2378 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2379 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2380 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002381
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002382 if (rx_lvl != max_rx_lvl) {
2383 repeat;
2384 }
2385 Tup.stop;
2386 }
2387 [] L1CTL.receive { repeat; }
2388 [] Tup.timeout {
2389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2390 log2str("Didn't reach full power ", max_rx_lvl));
2391 }
2392 }
2393 return max_rx_lvl;
2394}
2395
2396/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2397private function f_verify_ramp_up() runs on ConnHdlr {
2398 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002399 var integer initial_rx_lvl := -1;
2400 var integer last_rx_lvl := -1;
2401 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2402
2403 timer T := 2.0;
2404 alt {
2405 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2406 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2407 log("Received rx_level=", rx_lvl);
2408 if (initial_rx_lvl == -1) {
2409 initial_rx_lvl := rx_lvl;
2410 last_rx_lvl := rx_lvl;
2411
2412 /* Expect a somehow low value during first received messages */
2413 if (initial_rx_lvl >= max_rx_lvl / 2) {
2414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2415 log2str("Detected high initial tx power during ramp up: ",
2416 initial_rx_lvl , ", full power is", max_rx_lvl));
2417 }
2418 }
2419
2420 /* received Rx level bigger than maximum allowed power by CN */
2421 if (rx_lvl > max_rx_lvl) {
2422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2423 log2str("Detected Tx power higher than full power: ",
2424 rx_lvl , " > ", max_rx_lvl));
2425 }
2426
2427 /* Make sure it never decreases, since we are rumping up */
2428 if (last_rx_lvl > rx_lvl) {
2429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2430 log2str("Detected Tx power decrease during ramp up: ",
2431 last_rx_lvl , " -> ", rx_lvl));
2432 }
2433
2434 if (rx_lvl == max_rx_lvl and not T.running) {
2435 /* We reached the maximum power, start timer and receive
2436 /* a few more to make sure we don't surpass it */
2437 log("Reached full power, wating a bit more until success");
2438 T.start;
2439 }
2440
2441 last_rx_lvl := rx_lvl;
2442 repeat;
2443 }
2444 [] L1CTL.receive { repeat; }
2445 [] T.timeout { }
2446 }
2447
2448 /* We didn't increase tx power during ramp up */
2449 if (initial_rx_lvl < last_rx_lvl) {
2450 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2451 } else {
2452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2453 log2str("No Tx power increase during whole ramp up: ",
2454 initial_rx_lvl , " -> ", last_rx_lvl));
2455 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002456}
2457
2458/* verify BTS ramps power down to rx_level 0 */
2459private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2460 var L1ctlDlMessage l1_dl;
2461 var integer last_rx_lvl := max_rx_lvl;
2462
2463 timer Tdown := 5.0;
2464 Tdown.start;
2465 alt {
2466 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2467 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2468 log("Received rx_level=", rx_lvl);
2469
2470 /* received Rx level bigger than maximum allowed power by CN */
2471 if (rx_lvl > max_rx_lvl) {
2472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2473 log2str("Detected Tx power higher than full power: ",
2474 rx_lvl , " > ", max_rx_lvl));
2475 }
2476
2477 /* Make sure it never increases, since we are rumping down */
2478 if (last_rx_lvl < rx_lvl) {
2479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2480 log2str("Detected Tx power increase during ramp up: ",
2481 last_rx_lvl , " -> ", rx_lvl));
2482 }
2483
2484 last_rx_lvl := rx_lvl;
2485 if (last_rx_lvl != 0) {
2486 repeat;
2487 }
2488 /* we reached power level 0, we are done */
2489 Tdown.stop;
2490 }
2491 [] L1CTL.receive { repeat; }
2492 [] Tdown.timeout { }
2493 }
2494
2495 /* We didn't increase tx power during ramp down */
2496 if (max_rx_lvl > last_rx_lvl) {
2497 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2498 } else {
2499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2500 log2str("No Tx power decrease during whole ramp down: ",
2501 max_rx_lvl , " -> ", last_rx_lvl));
2502 }
2503}
2504
2505/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002506private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002507 f_l1_tune(L1CTL);
2508 RSL.clear;
2509
2510 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002511
2512 setverdict(pass);
2513}
2514testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2515 var ConnHdlr vc_conn;
2516 var ConnHdlrPars pars;
2517 f_init();
2518 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2519 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2520 pcu_comp := false, trxc_comp := true);
2521 vc_conn.done;
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2523}
2524
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002525/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002526private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002527 f_connhdlr_init_vty_bsc();
2528
2529 f_l1_tune(L1CTL);
2530 RSL.clear;
2531
2532 /* Wait until BTS is started and at full power */
2533 var integer max_rx_lvl := f_wait_ramp_up();
2534 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2535
2536 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2537 f_verify_ramp_down(max_rx_lvl);
2538
2539 setverdict(pass);
2540}
2541testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2542 var ConnHdlr vc_conn;
2543 var ConnHdlrPars pars;
2544 f_init();
2545 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2546 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2547 pcu_comp := false, trxc_comp := true);
2548 vc_conn.done;
2549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2550}
2551
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002552/* Verify Tx power:
2553 * + ramping down during ADM state UNLOCKED->LOCKED
2554 * + ramping up during ADM state LOCKED->UNLOCKED
2555 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002556private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002557 var L1ctlDlMessage l1_dl;
2558 var integer last_rx_lvl;
2559
2560 f_connhdlr_init_vty_bsc();
2561
2562 f_l1_tune(L1CTL);
2563 RSL.clear;
2564
2565 /* Wait until BTS is started and at full power */
2566 var integer max_rx_lvl := f_wait_ramp_up();
2567 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2568
2569 log("ADM STATE UNLOCKED->LOCKED");
2570 f_vty_enter_cfg_trx(BSCVTY);
2571 f_vty_transceive(BSCVTY, "rf_locked 1");
2572 last_rx_lvl := max_rx_lvl;
2573 f_verify_ramp_down(max_rx_lvl);
2574
2575 /* Let some time after we received 0dBm, then check we don't receive BCCH
2576 * anymore because scheduler has stopped after ramping down */
2577 f_sleep(2.0);
2578 L1CTL.clear;
2579 timer Tlocked := 2.0;
2580 Tlocked.start;
2581 alt {
2582 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2584 log2str("Received data_ind during rf_locked: ", l1_dl));
2585 }
2586 [] L1CTL.receive { repeat; }
2587 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2588 }
2589
2590 log("ADM STATE LOCKED->UNLOCKED");
2591 f_vty_transceive(BSCVTY, "rf_locked 0");
2592 f_verify_ramp_up();
2593 setverdict(pass);
2594}
2595testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2596 var ConnHdlr vc_conn;
2597 var ConnHdlrPars pars;
2598 f_init();
2599 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2600 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2601 pcu_comp := false, trxc_comp := true);
2602 vc_conn.done;
2603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2604}
2605
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002606private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002607 timer T := 8.0;
2608 T.start;
2609 var RSL_Message rsl;
2610 alt {
2611 [] as_l1_sacch();
2612 [] L1CTL.receive { repeat; }
2613 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2614 if (rsl.ies[3].body.bs_power.power_level == level) {
2615 setverdict(pass)
2616 } else {
2617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2618 }
2619 }
2620 [] T.timeout {
2621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2622 }
2623 }
2624}
2625
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002626/* See if the RSL MEASurement RESult contains expeced BS power level
2627 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002628private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002629 f_l1_tune(L1CTL);
2630 RSL.clear;
2631
2632 if (mp_bts_trxc_port != -1) {
2633 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2634 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2635 }
2636
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002637 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002638 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2639 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2640
2641 f_est_dchan(more_ies :={valueof(pwr)});
2642
2643 f_check_meas_bs_power_level(pwr_var);
2644
2645 f_rsl_chan_deact();
2646 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2647}
2648
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002649/* See if the RSL MEASurement RESult contains expeced BS power level
2650 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002651private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002652 f_l1_tune(L1CTL);
2653 RSL.clear;
2654
2655 if (mp_bts_trxc_port != -1) {
2656 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2657 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2658 }
2659
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002660 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002661 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2662
2663 f_est_dchan();
2664
2665 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2666
2667 f_check_meas_bs_power_level(pwr_var);
2668
2669 f_rsl_chan_deact();
2670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2671}
2672
2673testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2674 var ConnHdlr vc_conn;
2675 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002676
Eric Wildae8f2622019-06-18 17:05:11 +02002677 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002678
2679 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2680 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2681 pcu_comp := false, trxc_comp := true);
2682 vc_conn.done;
2683
Eric Wildae8f2622019-06-18 17:05:11 +02002684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2685}
2686
2687testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2688 var ConnHdlr vc_conn;
2689 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002690
Eric Wildae8f2622019-06-18 17:05:11 +02002691 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002692
2693 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2694 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2695 pcu_comp := false, trxc_comp := true);
2696 vc_conn.done;
2697
Eric Wildae8f2622019-06-18 17:05:11 +02002698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2699}
2700
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002701/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2702 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2703 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002704private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002705 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002706 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002707
2708 f_trxc_fake_rssi(rxlev2dbm(10));
2709 f_l1_tune(L1CTL);
2710 RSL.clear;
2711
2712 var RSL_IE_List addl_ies;
2713 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2714
2715 addl_ies := {
2716 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2717 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2718 };
2719
2720 /* establish with power parameters */
2721 f_est_dchan(more_ies := addl_ies);
2722
2723 /* set a high value to ensure L1 power control level increases */
2724 f_trxc_fake_rssi(rxlev2dbm(20));
2725
2726 timer T2 := 6.0;
2727 T2.start;
2728 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002729 [] as_l1_sacch_l1h(l1h) {
2730 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002731 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002732 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002733 T2.stop;
2734 }
2735 [] L1CTL.receive { repeat; }
2736 [] T2.timeout {
2737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2738 "Power Level in L1 header has not increased sufficiently");
2739 }
2740 }
2741
2742 /* set a low value to ensure L1 power control level decreases */
2743 f_trxc_fake_rssi(rxlev2dbm(0));
2744
2745 timer T4 := 6.0;
2746 T4.start;
2747 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002748 [] as_l1_sacch_l1h(l1h) {
2749 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002750 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002751 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002752 T4.stop;
2753 setverdict(pass, "Power level in L1 decreased/increased as expected");
2754 }
2755 [] L1CTL.receive { repeat; }
2756 [] T4.timeout {
2757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2758 "Power Level in L1 header has not decreased sufficiently");
2759 }
2760 }
2761
2762 f_rsl_chan_deact();
2763 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2764
2765}
2766
2767/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002768private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002769 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002770 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002771
2772 /* set a low value to ensure power increases */
2773 f_trxc_fake_rssi(rxlev2dbm(10));
2774 f_l1_tune(L1CTL);
2775 RSL.clear;
2776
2777 var RSL_IE_List addl_ies;
2778 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2779
2780 addl_ies := {
2781 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2782 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2783 };
2784
2785 /* establish with power parameters */
2786 f_est_dchan(more_ies := addl_ies);
2787
2788 timer T1 := 10.0;
2789 T1.start;
2790 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002791 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002792 [] L1CTL.receive { repeat; }
2793 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002794 if (not isbound(l1h)) {
2795 setverdict(fail, "No SACCH blocks were received");
2796 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002797 setverdict(fail, "Power level in L1 header should not have changed");
2798 }
2799 }
2800 }
2801
2802 f_rsl_chan_deact();
2803 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2804
2805}
2806
2807/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002808private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002809 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002810 var uint5_t pwr_var := 15;
2811 var uint5_t pwr_max_var := f_get_max_power_from_band();
2812
2813 /* set a low value to ensure power increases */
2814 f_trxc_fake_rssi(rxlev2dbm(10));
2815 f_l1_tune(L1CTL);
2816 RSL.clear;
2817
2818 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2819 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2820
2821 /* establish with fixed power level */
2822 f_est_dchan(more_ies :={valueof(pwr)});
2823
2824 /* check our initial power level */
2825 f_wait_for_l1_power_level(pwr_var);
2826
2827 /* update power param to enable power loop
2828 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2829 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2830
2831 /* wait, then check that our power level was reduced */
2832 timer T1 := 10.0;
2833 T1.start;
2834 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002835 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002836 [] L1CTL.receive { repeat; }
2837 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002838 if (not isbound(l1h)) {
2839 setverdict(fail, "No SACCH blocks were received");
2840 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002841 setverdict(pass, "Power level in L1 header reduced as expected");
2842 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002843 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2844 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002845 }
2846 }
2847 }
2848
2849 f_rsl_chan_deact();
2850 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2851
2852}
2853
2854/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002855private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002856 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002857
2858 /* set a high value to ensure power decreases */
2859 f_trxc_fake_rssi(rxlev2dbm(50));
2860 f_l1_tune(L1CTL);
2861 RSL.clear;
2862
2863 var uint5_t pwr_var := 5;
2864 var uint5_t pwr_target_val := 15;
2865
2866 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2867 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2868
2869 /* establish with fixed power level */
2870 f_est_dchan(more_ies :={valueof(pwr)});
2871
2872 /* check our initial power level */
2873 f_wait_for_l1_power_level(pwr_var);
2874
2875 /* update power param to enable power loop
2876 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002877 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002878
2879 /* wait, then check that our power level was increased */
2880 timer T1 := 10.0;
2881 T1.start;
2882 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002883 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002884 [] L1CTL.receive { repeat; }
2885 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002886 if (not isbound(l1h)) {
2887 setverdict(fail, "No SACCH blocks were received");
2888 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2889 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002890 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002891 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002892 }
2893 }
2894 }
2895
2896 f_rsl_chan_deact();
2897 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2898
2899}
2900
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002901/* See if the power level remains constant when MS Power Parameters IE
2902 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002903private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002904 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002905
2906 /* set a high value to ensure power decreases */
2907 f_trxc_fake_rssi(rxlev2dbm(50));
2908 f_l1_tune(L1CTL);
2909 RSL.clear;
2910
2911 var uint5_t pwr_var := 5;
2912
2913 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2914 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2915
2916 /* establish with fixed power level */
2917 f_est_dchan(more_ies :={valueof(pwr)});
2918
2919 /* check our initial power level */
2920 f_wait_for_l1_power_level(pwr_var);
2921
2922 /* wait, then check that our power level did not change */
2923 timer T1 := 10.0;
2924 T1.start;
2925 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002926 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2927 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2929 "BS power control should not be active unless we receive a power parameters IE!");
2930 }
2931 repeat;
2932 }
2933 [] L1CTL.receive { repeat; }
2934 [] T1.timeout { setverdict(pass); }
2935 }
2936
2937 f_rsl_chan_deact();
2938 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2939
2940}
2941
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002942/* See if the power level remains constant when MS Power Parameters IE
2943 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002944private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002945 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002946
2947 /* set a high value to ensure power decreases */
2948 f_trxc_fake_rssi(rxlev2dbm(50));
2949 f_l1_tune(L1CTL);
2950 RSL.clear;
2951
2952 var uint5_t pwr_var := 5;
2953
2954 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2955 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2956
2957 /* establish with fixed power level */
2958 f_est_dchan(more_ies :={valueof(pwr)});
2959
2960 /* check our initial power level */
2961 f_wait_for_l1_power_level(pwr_var);
2962
2963 /* pwr control without power params IE, should NOT activate MS power control*/
2964 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2965
2966 /* wait, then check that our power level did not change */
2967 timer T1 := 10.0;
2968 T1.start;
2969 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002970 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2971 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2973 "BS power control should not be active unless we receive a power parameters IE!");
2974 }
2975 repeat;
2976 }
2977 [] L1CTL.receive { repeat; }
2978 [] T1.timeout { setverdict(pass); }
2979 }
2980
2981 f_rsl_chan_deact();
2982 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2983
2984}
2985
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002986private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002987 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002988 timer T0 := 10.0;
2989 T0.start;
2990 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002991 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2992 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2994 "Power level in L1 header != signaled (RSL) power level.");
2995 }
2996 }
2997 [] L1CTL.receive { repeat; }
2998 [] T0.timeout {
2999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3000 "Timeout waiting for initial power level");
3001 }
3002 }
3003 T0.stop;
3004}
3005
3006private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3007 var IntegerRecord min_dbm_level;
3008 var IntegerRecord max_dbm_level;
3009 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3010
3011 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3012 if (min_dbm_level[i] == level) {
3013 return true;
3014 }
3015 }
3016 return false;
3017}
3018
3019private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3020 var IntegerRecord min_dbm_level;
3021 var IntegerRecord max_dbm_level;
3022 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3023
3024 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3025 if (max_dbm_level[i] == level) {
3026 return true;
3027 }
3028 }
3029 return false;
3030}
3031
3032private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3033 var IntegerRecord min_dbm_level;
3034 var IntegerRecord max_dbm_level;
3035 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3036 return max_dbm_level[0];
3037}
3038
3039type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003040private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003041private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3042 // 45.005 4.1.1
3043 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3044 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3045 2, 1, 0};
3046 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3047 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3048 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3049 var IntegerRecord rv;
3050
3051 select(band){
3052 case (BtsBand_allGSM){
3053 rv := gsm_power;
3054 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3055 max_dbm_level := {2, 1, 0};
3056 }
3057 case("DCS1800"){
3058 rv := dcs_power;
3059 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3060 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3061 }
3062 case("PCS1900"){
3063 rv := pcs_power;
3064 min_dbm_level := {15};
3065 max_dbm_level := {30};
3066 }
Harald Welte194b6912020-10-11 21:01:55 +02003067 case else {
3068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3069 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003070 }
3071
3072 return rv;
3073}
3074
3075private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003076 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 +02003077}
3078
3079testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3080 var ConnHdlr vc_conn;
3081 var ConnHdlrPars pars;
3082 f_init();
3083 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3084 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3085 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3086 pars.bts0_band := f_vty_get_bts0_band();
3087 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3088 vc_conn.done;
3089 }
3090 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3092}
3093
3094testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3095 var ConnHdlr vc_conn;
3096 var ConnHdlrPars pars;
3097 f_init();
3098 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3099 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3100 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3101 pars.bts0_band := f_vty_get_bts0_band();
3102 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3103 vc_conn.done;
3104 }
3105 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3107}
3108
3109testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3110 var ConnHdlr vc_conn;
3111 var ConnHdlrPars pars;
3112 f_init();
3113 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3114 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3115 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3116 pars.bts0_band := f_vty_get_bts0_band();
3117 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3118 vc_conn.done;
3119 }
3120 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3122}
3123
3124testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3125 var ConnHdlr vc_conn;
3126 var ConnHdlrPars pars;
3127 f_init();
3128 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3129 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3130 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3131 pars.bts0_band := f_vty_get_bts0_band();
3132 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3133 vc_conn.done;
3134 }
3135 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3137}
3138
Eric Wild280ccb82019-06-17 11:11:52 +02003139testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3140 var ConnHdlr vc_conn;
3141 var ConnHdlrPars pars;
3142 f_init();
3143 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3144 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3145 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3146 pars.bts0_band := f_vty_get_bts0_band();
3147 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3148 vc_conn.done;
3149 }
3150 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3152}
3153
Eric Wild095024b2019-06-17 15:08:57 +02003154testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3155 var ConnHdlr vc_conn;
3156 var ConnHdlrPars pars;
3157 f_init();
3158 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3159 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3160 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3161 pars.bts0_band := f_vty_get_bts0_band();
3162 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3163 vc_conn.done;
3164 }
3165 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3167}
3168
Philipp Maier149c3922020-10-22 17:29:36 +02003169function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003170 var template RSL_IE_ChannelMode ch_mode;
3171 var ConnHdlr vc_conn;
3172 var ConnHdlrPars pars;
3173 f_init();
3174 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3175 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3176 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003177 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003178 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3179 pcu_comp := false, trxc_comp := true);
3180 vc_conn.done;
3181 }
3182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3183}
Philipp Maier149c3922020-10-22 17:29:36 +02003184
3185testcase TC_meas_res_speech_tchf() runs on test_CT {
3186 f_TC_meas_res_speech_tchf(false);
3187}
3188
3189testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3190 f_TC_meas_res_speech_tchf(true);
3191}
3192
3193function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003194 var template RSL_IE_ChannelMode ch_mode;
3195 var ConnHdlr vc_conn;
3196 var ConnHdlrPars pars;
3197 f_init();
3198 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3199 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3200 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003201 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003202 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3203 pcu_comp := false, trxc_comp := true);
3204 vc_conn.done;
3205 }
3206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3207}
Philipp Maier149c3922020-10-22 17:29:36 +02003208
3209testcase TC_meas_res_speech_tchh() runs on test_CT {
3210 f_TC_meas_res_speech_tchh(false)
3211}
3212
3213testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3214 f_TC_meas_res_speech_tchh(true)
3215}
3216
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003217testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3218 var template RSL_IE_ChannelMode ch_mode;
3219 var ConnHdlr vc_conn;
3220 var ConnHdlrPars pars;
3221 f_init();
3222 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3223 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3224 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3225 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3226 pars.l1_pars.toa256_enabled := true;
3227 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3228 pcu_comp := false, trxc_comp := true);
3229 vc_conn.done;
3230 }
3231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3232}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003233
Harald Welte70767382018-02-21 12:16:40 +01003234testcase TC_meas_res_sign_tchf() runs on test_CT {
3235 var ConnHdlr vc_conn;
3236 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003237 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003238 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003239 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003240 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003241 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3242 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003243 vc_conn.done;
3244 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003246}
3247testcase TC_meas_res_sign_tchh() runs on test_CT {
3248 var ConnHdlr vc_conn;
3249 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003250 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003251 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003252 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003253 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003254 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3255 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003256 vc_conn.done;
3257 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003259}
3260testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3261 var ConnHdlr vc_conn;
3262 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003263 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003264 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003265 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3266 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003267 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3268 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003269 vc_conn.done;
3270 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003272}
3273testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3274 var ConnHdlr vc_conn;
3275 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003276 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003277 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003278 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3279 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003280 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3281 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003282 vc_conn.done;
3283 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003285}
Harald Welte685d5982018-02-27 20:42:05 +01003286testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3287 var ConnHdlr vc_conn;
3288 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003289 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003290 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3291 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003292 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003293 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003294 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3295 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003296 vc_conn.done;
3297 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003299}
3300
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003301/* Make sure that we always get RSL MEASurement RESult messages regardless
3302 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3303private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3304 timer Texec := 8.0;
3305 timer Timpf := 2.0;
3306 timer Tmr;
3307
3308 f_l1_tune(L1CTL);
3309 RSL.clear;
3310
3311 f_est_dchan();
3312 L1CTL.clear;
3313
3314 /* Establish the main SAPI=0 link on DCCH first */
3315 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3316
3317 /* Give more time for the first RSL MEASurement RESult */
3318 Tmr.start(0.480 * 2.0);
3319 Texec.start; /* EXECution timer */
3320 Timpf.start; /* IMPFung timer */
3321
3322 alt {
3323 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3324 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3325 /* Reschedule the MEAS RES timer */
3326 Tmr.start(0.480 + 0.120);
3327 repeat;
3328 }
3329 [] RSL.receive { repeat; }
3330 [] Tmr.timeout {
3331 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3332 }
3333 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3334 [] Timpf.timeout {
3335 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3336 log("Injected SAPI=3 traffic on SACCH");
3337 Timpf.start;
3338 repeat;
3339 }
3340 /* We're good if survived so far */
3341 [] Texec.timeout {
3342 setverdict(pass);
3343 }
3344 }
3345
3346 f_rsl_chan_deact();
3347 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3348 f_rslem_unregister(0, g_chan_nr);
3349}
3350testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3351 var template RSL_IE_ChannelMode ch_mode;
3352 var template ConnHdlrPars pars;
3353 var ConnHdlr vc_conn;
3354
3355 f_init();
3356
3357 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3358 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3359
3360 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3361 vc_conn.done;
3362
3363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3364}
3365testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3366 var template RSL_IE_ChannelMode ch_mode;
3367 var template ConnHdlrPars pars;
3368 var ConnHdlr vc_conn;
3369
3370 f_init();
3371
3372 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3373 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3374
3375 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3376 vc_conn.done;
3377
3378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3379}
3380
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003381/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3382 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003383private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003384 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003385 var RSL_IE_MS_Power ms_power;
3386 var RSL_Message rsl;
3387 var uint5_t power_level := 0;
3388
3389 f_l1_tune(L1CTL);
3390 RSL.clear;
3391
3392 f_est_dchan();
3393
3394 ms_power.reserved := 0;
3395 ms_power.fpc_epc := false;
3396
3397 /* Send the first power control command. This will disable any BTS/TRX
3398 * internal power control and switch the MS (which is not in scope of
3399 * this test) to a constant power level. We start with a power level
3400 * of 0 */
3401 ms_power.power_level := power_level;
3402 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3403 RSL.send(rsl);
3404
3405 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003406 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3407 if (l1h.ms_power_lvl != power_level) {
3408 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3409 "match the signaled (RSL) power level := ", power_level);
3410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003411 }
3412
3413 /* Signal a new power level via RSL for the next turn. */
3414 if (power_level < 31) {
3415 power_level := power_level + 1;
3416 ms_power.power_level := power_level;
3417 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3418 RSL.send(rsl);
3419 repeat;
3420 }
3421
3422 }
3423
3424 /* Ignore all other blocks */
3425 [] L1CTL.receive { repeat; }
3426
3427 }
3428
3429 f_rsl_chan_deact();
3430 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3431
3432 setverdict(pass);
3433}
3434
3435testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3436 var ConnHdlr vc_conn;
3437 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003438 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003439
3440 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3441 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3442 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3443 vc_conn.done;
3444 }
3445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3446}
Harald Welte70767382018-02-21 12:16:40 +01003447
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003448/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003449TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003450private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003451 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003452 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003453
3454 f_l1_tune(L1CTL);
3455 RSL.clear;
3456
3457 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003458 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003459
3460 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3461
3462
3463 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003464 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3465 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003466 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3467 }
3468
3469 }
3470
3471 /* Ignore all other blocks */
3472 [] L1CTL.receive { repeat; }
3473
3474 }
3475
3476 f_rsl_chan_deact();
3477 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3478
3479 setverdict(pass);
3480}
3481
3482testcase TC_rsl_chan_initial_ta() runs on test_CT {
3483 var ConnHdlr vc_conn;
3484 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003485 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003486 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003487 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3488 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003489 vc_conn.done;
3490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3491}
3492
Eric Wilde57e1a62019-05-28 13:30:55 +02003493/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003494private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003495 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003496 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003497
3498 var RSL_IE_MS_Power ms_power;
3499 ms_power.reserved := 0;
3500 ms_power.fpc_epc := false;
3501 ms_power.power_level := ms_power_level;
3502
3503 f_l1_tune(L1CTL);
3504 RSL.clear;
3505
3506 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3507
3508 timer T := 1.0;
3509 T.start;
3510 alt {
3511 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003512 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3513 if (l1h.ms_power_lvl != ms_power_level) {
3514 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3515 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003516 }
3517 }
3518 /* Ignore all other blocks */
3519 [] L1CTL.receive { repeat; }
3520 [] T.timeout {
3521 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3522 }
3523 }
3524
3525 f_rsl_chan_deact();
3526 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3527 setverdict(pass);
3528}
3529
3530testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3531 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3532 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3533}
3534
Harald Welte0472ab42018-03-12 15:02:26 +01003535/* 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 +01003536private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003537 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003538 RSL.clear;
3539
3540 f_est_dchan();
3541 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003542 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003543
3544 timer T := 40.0;
3545 T.start;
3546 alt {
3547 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3548 setverdict(pass)
3549 }
3550 [] RSL.receive { repeat };
3551 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003553 }
3554 }
3555 f_rsl_chan_deact();
3556}
3557testcase TC_conn_fail_crit() runs on test_CT {
3558 var ConnHdlr vc_conn;
3559 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003560 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003561 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3562 pars.t_guard := 60.0;
3563 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3564 vc_conn.done;
3565}
3566
Harald Welte93640c62018-02-25 16:59:33 +01003567/***********************************************************************
3568 * Paging
3569 ***********************************************************************/
3570
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003571private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003572 if (tmsi == 'FFFFFFFF'O) {
3573 return true;
3574 } else {
3575 return false;
3576 }
3577}
Harald Welte70767382018-02-21 12:16:40 +01003578
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003579private type record allowedFn { integer frame_nr }
3580private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3581private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3582private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3583private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3584private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3585private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3586private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3587private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3588private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003589{
3590 var integer frame_nr_51;
3591 frame_nr_51 := frame_nr mod 51
3592
3593 var allowedFn fn_check;
3594 fn_check.frame_nr := frame_nr_51;
3595
3596 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003598 return;
3599 }
3600
3601 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3602 return;
3603 }
3604 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3605 return;
3606 }
3607 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3608 return;
3609 }
3610 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3611 return;
3612 }
3613 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3614 return;
3615 }
3616 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3617 return;
3618 }
3619 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3620 return;
3621 }
3622 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3623 return;
3624 }
3625
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003627 return;
3628}
3629
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003630private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3631 inout integer num_paging_rcv_ids,
3632 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003633runs on test_CT {
3634 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003635 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003636 repeat;
3637 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003638 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003639 var octetstring without_plen :=
3640 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3641 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003642
3643 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3644
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003645 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3646 /* Ignore empty RR Paging Request (PCH filling) messages.
3647 * TODO: does it make sense to count them? */
3648 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003649 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3650 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003651 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003652 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3653 }
3654 } else if (match(rr, tr_PAGING_REQ2)) {
3655 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3656 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3657 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3658 }
3659 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3660 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3661 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003662 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003663 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3664 }
3665 } else if (match(rr, tr_PAGING_REQ3)) {
3666 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3667 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3668 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3669 }
3670 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3671 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3672 }
3673 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3674 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3675 }
3676 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3677 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3678 }
3679 }
3680 repeat;
3681 }
3682}
3683
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003684private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003685 boolean combined_ccch,
3686 integer bs_ag_blks_res,
3687 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003688 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3689 * paging command that is issued via RSL. */
3690 integer ps_load_modulus,
3691 /* Wait until the paging queue inside the BTS is congested before starting to add
3692 * pagings via the PCU socket (0 = disabled) */
3693 boolean ps_wait_cong,
3694 /* Maximum time to wait until the paging queue is drained at the end of the test.
3695 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3696 * to set this value to 18s, however the draining process may take significantly
3697 * longer when the queue contains paging requests for PS as those are implemented
3698 * as immediate assignments and require an entire MAC block alone. */
3699 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003700 boolean exp_load_ind,
3701 boolean exp_overload,
3702 boolean use_tmsi
3703}
3704
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003705private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003706 integer num_paging_sent,
3707 integer num_paging_rcv_msgs,
3708 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003709 integer num_overload,
3710 /* When free space inside the paging queue reaches more than 2 thirds
3711 * of its capacity cong_detected is set to true. */
3712 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003713}
3714
Harald Welte68e495b2018-02-25 00:05:57 +01003715/* Helper function for paging related testing */
3716private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003717 /* Using the PCU socket affects the timing of the paging processing. We only
3718 * activate the PCU socket if we do paging load tests that include additional
3719 * paging load that is introduced through the PCU socket. */
3720 if (cfg.ps_load_modulus > 0) {
3721 f_init_with_pcuif();
3722 } else {
3723 f_init();
3724 }
Harald Welte68e495b2018-02-25 00:05:57 +01003725 f_init_l1ctl();
3726 f_l1_tune(L1CTL);
3727
Philipp Maierca058272021-06-23 10:35:23 +02003728 var octetstring imm_ass := f_rnd_octstring(23);
3729 var ASP_RSL_Unitdata load_ind;
3730
Harald Welte68e495b2018-02-25 00:05:57 +01003731 var PagingTestState st := {
3732 num_paging_sent := 0,
3733 num_paging_rcv_msgs := 0,
3734 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003735 num_overload := 0,
3736 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003737 };
3738
3739 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3740 var float max_pch_imsi_per_sec;
3741 if (cfg.use_tmsi) {
3742 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3743 } else {
3744 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3745 }
3746 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3747 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003748 var float time_total := 20.0;
3749 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3750 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003751
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003752 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3753 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003754
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003755 timer T_itv := 0.0;
3756 T_itv.start;
3757 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003758 alt {
3759 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003760 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003761 st.num_overload := st.num_overload + 1;
3762 repeat;
3763 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003764 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003766 }
Philipp Maierca058272021-06-23 10:35:23 +02003767 [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 +01003768 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003769
3770 /* Detect paging congestion: The logic inside the BTS will diagnose the
3771 * paging queue as congested when the fill state is more than 66% (which
3772 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3773 * paging congestion is detected pagings that are issued through the PCU
3774 * socket (PS) are dropped in order to prefer the CS related pagings. */
3775 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3776 st.cong_detected := true;
3777 }
3778
Harald Welte68e495b2018-02-25 00:05:57 +01003779 /* FIXME: analyze/verify interval + contents */
3780 repeat;
3781 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003782 /* ignore other RSL messages like RF RESource INDication */
3783 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003784 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003785 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003786 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003787 /* Only relevant when testing including with PCU sock connected */
3788 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003789 [] T_itv.timeout {
3790 /* Send paging cmds based on elapsed time */
3791 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3792 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003793 var MobileIdentityV mi;
3794
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003795 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003796 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003797 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003798 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003799 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003800 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003801
3802 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003803 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 +02003804
Philipp Maierca058272021-06-23 10:35:23 +02003805 /* Add additional pagings through the PCU socket interface. */
3806 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3807 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3808 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3809 }
3810 }
3811
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003812 st.num_paging_sent := st.num_paging_sent + 1;
3813 }
3814 if (st.num_paging_sent < pkt_total) {
3815 /* Wait for interval to next PAGING COMMAND */
3816 var float time_now := T_total.read;
3817 var float next_sched := int2float(st.num_paging_sent)*interval;
3818 if (next_sched > time_now) {
3819 T_itv.start(next_sched - time_now);
3820 } else {
3821 T_itv.start(0.0);
3822 }
3823 } else {
3824 /* We are done, no need to keep counting */
3825 T_total.stop;
3826 }
3827 }
3828 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003829 }
3830 }
3831
Philipp Maierca058272021-06-23 10:35:23 +02003832 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003833 T_wait.start;
3834 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003835 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003836 [] L1CTL.receive { repeat; }
3837 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003838 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003839 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003840 /* ignore other RSL messages like RF RESource INDication */
3841 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003842 /* Only relevant when testing including with PCU sock connected */
3843 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003844 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003845 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 +01003846 }
Harald Welte68e495b2018-02-25 00:05:57 +01003847 }
3848
3849 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3850 " rcvd_ids=", st.num_paging_rcv_ids);
3851 return st;
3852}
3853
3854/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3855 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3856 * - that CCCH LOAD IND (PCH) are being generated
3857 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3858testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003859 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003860 var PagingTestCfg cfg := {
3861 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003862 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003863 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003864 ps_load_modulus := 0,
3865 ps_wait_cong := false,
3866 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003867 exp_load_ind := true,
3868 exp_overload := false,
3869 use_tmsi := false
3870 };
3871 var PagingTestState st := f_TC_paging(cfg);
3872 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3874 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003875 } else {
3876 setverdict(pass);
3877 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003879}
3880
3881/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3882 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3883 * - that CCCH LOAD IND (PCH) are being generated
3884 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3885testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003886 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003887 var PagingTestCfg cfg := {
3888 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003889 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003890 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003891 ps_load_modulus := 0,
3892 ps_wait_cong := false,
3893 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003894 exp_load_ind := true,
3895 exp_overload := false,
3896 use_tmsi := true
3897 };
3898 var PagingTestState st := f_TC_paging(cfg);
3899 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3901 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003902 } else {
3903 setverdict(pass);
3904 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003906}
3907
3908/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3909 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3910 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3911 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3912testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003913 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003914 var PagingTestCfg cfg := {
3915 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003916 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003917 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003918 ps_load_modulus := 0,
3919 ps_wait_cong := false,
3920 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003921 exp_load_ind := true,
3922 exp_overload := true,
3923 use_tmsi := false
3924 };
3925 var PagingTestState st := f_TC_paging(cfg);
3926 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3927 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003928 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003929 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003930 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 +01003931 } else {
3932 setverdict(pass);
3933 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003935}
3936
3937/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3938 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3939 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3940 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3941testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003942 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003943 var PagingTestCfg cfg := {
3944 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003945 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003946 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003947 ps_load_modulus := 0,
3948 ps_wait_cong := false,
3949 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003950 exp_load_ind := true,
3951 exp_overload := true,
3952 use_tmsi := true
3953 };
3954 var PagingTestState st := f_TC_paging(cfg);
3955 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3956 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003957 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003958 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003959 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 +01003960 } else {
3961 setverdict(pass);
3962 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003964}
3965
Philipp Maierca058272021-06-23 10:35:23 +02003966/* Same as above, but with additional paging load created by PS pagings that
3967 * are issued through the PCU socket. The additional load is introduced when
3968 * the paging queue is already two thirds full. Since the BTS implements a
3969 * prioritization logic that drops the pagings from the PCU under in those
3970 * congestive sitautions the behaviour on the PS side is expected to be
3971 * unaffected and match the behavior of TC_paging_imsi_200percent() */
3972testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
3973 var SystemInformation si3 := valueof(ts_SI3_default);
3974 var PagingTestCfg cfg := {
3975 combined_ccch := true,
3976 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
3977 load_factor := 2.0,
3978 ps_load_modulus := 16,
3979 ps_wait_cong := true,
3980 queue_drain_timeout := 18.0,
3981 exp_load_ind := true,
3982 exp_overload := true,
3983 use_tmsi := false
3984 };
3985 var PagingTestState st := f_TC_paging(cfg);
3986 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3987 * slots and will fully drain that buffer before returning */
3988 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
3989 if (not match(st.num_paging_rcv_ids, tpl)) {
3990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
3991 } else {
3992 setverdict(pass);
3993 }
3994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3995}
3996
3997
Harald Welte68e495b2018-02-25 00:05:57 +01003998
Harald Welte93640c62018-02-25 16:59:33 +01003999/***********************************************************************
4000 * Immediate Assignment / AGCH
4001 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004002private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004003 len := 0,
4004 ma := ''B
4005}
Harald Welte93640c62018-02-25 16:59:33 +01004006
Harald Weltee8d750e2018-06-10 21:41:35 +02004007private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4008 return int2str(num_tx) & " sent, "
4009 & int2str(num_rx) & " received, "
4010 & int2str(num_del) & " deleted";
4011}
4012
4013private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4014 var L1ctlDlMessage l1_dl;
4015 timer T := 10.0;
4016 var integer num_tx := 0;
4017 var integer num_rx := 0;
4018 var integer num_del := 0;
4019 var charstring res_str;
4020 var float rx_ratio;
4021
Harald Welte10474062019-05-30 16:48:17 +02004022 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004023 f_init_l1ctl();
4024 f_l1_tune(L1CTL);
4025
4026 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004027 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004028 mp_trx_pars[0].arfcn,
4029 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004030 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4031 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004032 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004033 num_tx := num_tx+1;
4034 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004035 }
4036 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004037 T.start;
4038 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004039 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004040 num_del := num_del+1;
4041 repeat;
4042 }
4043 [] RSL_CCHAN.receive {
4044 repeat;
4045 }
4046 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004047 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4048 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4049 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004050 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004051 } else {
4052 num_rx := num_rx+1;
4053 }
4054 repeat;
4055 }
4056 [] L1CTL.receive { repeat; }
4057 [] T.timeout { }
4058 }
4059 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4060 log("AGCH test: " & res_str);
4061 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004063 }
4064 rx_ratio := int2float(num_rx) / int2float(num_tx);
4065 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004066 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 +02004067 } else {
4068 setverdict(pass);
4069 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004071}
4072
Harald Weltee8d750e2018-06-10 21:41:35 +02004073/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4074testcase TC_imm_ass_1000_20ms() runs on test_CT {
4075 f_TC_imm_ass(1000, 0.02, 0.25);
4076}
4077
4078/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4079testcase TC_imm_ass_200_0ms() runs on test_CT {
4080 f_TC_imm_ass(200, 0.0, 0.05);
4081}
4082
4083/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4084testcase TC_imm_ass_200_76ms() runs on test_CT {
4085 f_TC_imm_ass(150, 0.076, 1.00);
4086}
4087
4088
4089
Harald Welte48494ca2018-02-25 16:59:50 +01004090/***********************************************************************
4091 * BCCH
4092 ***********************************************************************/
4093
4094/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004095private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004096 GsmFrameNumber frame_number,
4097 SystemInformation si
4098}
4099
4100/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004101private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004102
4103/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004104private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004105
4106/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004107private function f_si_vecslot_contains(SystemInformationVector arr,
4108 RrMessageType key,
4109 boolean bcch_ext := false)
4110return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004111 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4112 var integer fn_mod51 := arr[i].frame_number mod 51;
4113 if (not bcch_ext and fn_mod51 == 2 or
4114 bcch_ext and fn_mod51 == 6) {
4115 if (arr[i].si.header.message_type == key) {
4116 return true;
4117 }
4118 }
4119 }
4120 return false;
4121}
4122
4123/* 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 +07004124private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4125 integer tc, RrMessageType key,
4126 boolean ext_bcch := false)
4127{
Harald Welte48494ca2018-02-25 16:59:50 +01004128 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004130 }
4131}
4132
4133/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004134private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4135 RrMessageType key)
4136return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004137 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4138 if (f_si_vecslot_contains(arr[tc], key) or
4139 f_si_vecslot_contains(arr[tc], key, true)) {
4140 return true;
4141 }
4142 }
4143 return false;
4144}
4145
4146/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004147private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4148 RrMessageType key,
4149 boolean bcch_ext := false,
4150 integer n := 1, integer m := 4)
4151return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004152 var integer count := 0;
4153 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4155 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004156 }
4157 for (var integer i:= 0; i < m; i := i + 1) {
4158 var integer fn_mod51 := arr[i].frame_number mod 51;
4159 if (not bcch_ext and fn_mod51 == 2 or
4160 bcch_ext and fn_mod51 == 6) {
4161 if (arr[i].si.header.message_type == key) {
4162 count := count + 1;
4163 }
4164 }
4165 }
4166 if (count >= n) {
4167 return true;
4168 } else {
4169 return false;
4170 }
4171}
4172
4173/* 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 +07004174private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4175 integer tc, RrMessageType key,
4176 boolean ext_bcch := false,
4177 integer n, integer m)
4178{
Harald Welte48494ca2018-02-25 16:59:50 +01004179 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004181 }
4182}
4183
4184/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004185private function f_si_vecslot_contains_only(SystemInformationVector arr,
4186 RrMessageType key,
4187 boolean bcch_ext := false)
4188return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004189 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4190 var integer fn_mod51 := arr[i].frame_number mod 51;
4191 if (not bcch_ext and fn_mod51 == 2 or
4192 bcch_ext and fn_mod51 == 6) {
4193 if (arr[i].si.header.message_type != key) {
4194 return false;
4195 }
4196 }
4197 }
4198 return true;
4199}
4200
4201/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004202private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4203 integer tc, RrMessageType key,
4204 boolean ext_bcch := false)
4205{
Harald Welte48494ca2018-02-25 16:59:50 +01004206 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004208 }
4209}
4210
4211/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004212private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004213 boolean bcch_extended,
4214 boolean si1_present,
4215 boolean si2bis_present,
4216 boolean si2ter_present,
4217 boolean si2quater_present,
4218 boolean si7_present,
4219 boolean si8_present,
4220 boolean si9_present,
4221 boolean si13_present,
4222 boolean si13alt_present,
4223 boolean si15_present,
4224 boolean si16_present,
4225 boolean si17_present,
4226 boolean si2n_present,
4227 boolean si21_present,
4228 boolean si22_present
4229}
4230
4231/* 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 +07004232private function f_validate_si_scheduling(SystemInformationConfig cfg,
4233 SystemInformationVectorPerTc si_per_tc)
4234{
Harald Welte48494ca2018-02-25 16:59:50 +01004235 var integer i;
4236 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4237 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004239 }
4240 }
4241 if (cfg.si1_present) {
4242 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4243 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4244 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4245 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4246 /* make sure *ALL* contain SI1 */
4247 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4248 }
4249 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4250 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4251 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4252 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4253 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4254 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4255
4256 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4257 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4258 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4259 * consecutive occurrences of TC = 4. */
4260 if (cfg.si2bis_present and not cfg.si2ter_present) {
4261 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4262 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4263 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4264 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4265 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4266 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4267 }
4268
4269 if (cfg.si7_present or cfg.si8_present) {
4270 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4271 * if System Information type 4 does not contain all information needed for cell
4272 * selection and reselection. */
4273 if (not cfg.bcch_extended) {
4274 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4275 }
4276 if (cfg.si7_present) {
4277 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4278 }
4279 if (cfg.si8_present) {
4280 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4281 }
4282 }
4283
4284 if (cfg.si2quater_present) {
4285 /* iii) System information type 2 quater is sent if needed, as determined by the system
4286 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4287 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4288 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4289 * within any of 4 consecutive occurrences of TC = 5. */
4290 if (not (cfg.bcch_extended)) {
4291 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4292 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4293 } else {
4294 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4295 }
4296 } else {
4297 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4298 }
4299 }
4300 if (cfg.si9_present) {
4301 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4302 * in system information type 3 as defined in 3GPP TS 44.018. */
4303 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4304 }
4305 if (cfg.si13_present) {
4306 /* vii) System Information type 13 is only related to the GPRS service. System Information
4307 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4308 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4309 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4310 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4311 * within any of 4 consecutive occurrences of TC=4. */
4312 if (not cfg.bcch_extended) {
4313 log("not-bccch-extended");
4314 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4315 } else {
4316 log("bccch-extended");
4317 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4318 }
4319 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004321 }
4322 }
4323 if (cfg.si16_present or cfg.si17_present) {
4324 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4325 * should not be sent in a cell where network sharing is used (see rule xv). */
4326 if (cfg.si22_present) {
4327 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4328 }
4329 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004331 }
4332 if (not cfg.bcch_extended) {
4333 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4334 }
4335 if (cfg.si16_present) {
4336 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4337 }
4338 if (cfg.si17_present) {
4339 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4340 }
4341 }
4342
4343 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4344 * broadcast information. The frequency with which they are sent is determined by the
4345 * system operator. System Information type 9 identifies the scheduling of System
4346 * Information type 18 and 20 messages. */
4347
4348 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4349 * Information Type 19 is present, then its scheduling shall be indicated in System
4350 * Information Type 9. */
4351
4352 if (cfg.si15_present) {
4353 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4354 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4355 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4356 * 4 consecutive occurrences of TC = 1. */
4357 if (not cfg.bcch_extended) {
4358 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4359 } else {
4360 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4361 }
4362 }
4363 if (cfg.si13alt_present) {
4364 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4365 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4366 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4367 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4368 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4369 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4370 * of TC = 4. */
4371 if (cfg.si13_present) {
4372 testcase.stop("Error: Cannot have SI13alt and SI13");
4373 }
4374 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004376 }
4377 if (not cfg.bcch_extended) {
4378 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4379 } else {
4380 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4381 }
4382 }
4383 if (cfg.si2n_present) {
4384 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4385 * as determined by the system operator. In the case that the message is sent on the
4386 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4387 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4388 * consecutive occurrences of TC = 4. */
4389 if (not cfg.bcch_extended) {
4390 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4391 } else {
4392 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4393 }
4394 }
4395 if (cfg.si21_present) {
4396 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4397 * determined by the system operator. If Extended Access Barring is in use in the cell
4398 * then this message is sent at least once within any of 4 consecutive occurrences of
4399 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4400 * cell then this message shall only be sent on BCCH Ext. */
4401 if (not cfg.bcch_extended) {
4402 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4403 } else {
4404 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4405 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004407 }
4408 }
4409 }
4410 if (cfg.si22_present) {
4411 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4412 * should not be sent in a cell where SoLSA is used (see rule viii). System
4413 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4414 * =2 and TC=6. */
4415 if (cfg.si16_present or cfg.si17_present) {
4416 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4417 }
4418 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4419 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004421 }
4422 if (not cfg.bcch_extended) {
4423 testcase.stop("Error: SI22 requires BCCH Extd!");
4424 } else {
4425 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4426 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4427 }
4428 }
4429}
4430
4431/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004432private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4433return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004434 timer T := duration;
4435 var SystemInformationVectorPerTc si_per_tc;
4436 var L1ctlDlMessage l1_dl;
4437
4438 /* initialize all per-TC vectors empty */
4439 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4440 si_per_tc[i] := {};
4441 }
4442
4443 /* flush all previous L1 queued msgs */
4444 pt.clear;
4445
4446 T.start;
4447 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004448 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004449 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4450 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4451 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004452 repeat;
4453 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004454
Harald Welte48494ca2018-02-25 16:59:50 +01004455 var integer tc := f_gsm_compute_tc(sig.frame_number);
4456 log("SI received at TC=", tc, ": ", sig.si);
4457 /* append to the per-TC bucket */
4458 si_per_tc[tc] := si_per_tc[tc] & { sig };
4459 repeat;
4460 }
4461 [] pt.receive { repeat; }
4462 [] T.timeout { }
4463 }
4464
4465 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4466 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4467 }
4468 log("si_per_tc=", si_per_tc);
4469 return si_per_tc;
4470}
4471
4472/* helper function: Set given SI via RSL + validate scheduling.
4473 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004474private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004475 var SystemInformationVectorPerTc si_per_tc;
4476 f_init_l1ctl();
4477 f_l1_tune(L1CTL);
4478
4479 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004480 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004481 f_validate_si_scheduling(si_cfg, si_per_tc);
4482
4483 setverdict(pass);
4484}
4485
4486testcase TC_si_sched_default() runs on test_CT {
4487 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004488 /* 2+3+4 are mandatory and set in f_init() */
4489 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004491}
4492
4493testcase TC_si_sched_1() runs on test_CT {
4494 f_init();
4495 si_cfg.si1_present := true;
4496 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004497 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004499}
4500
4501testcase TC_si_sched_2bis() runs on test_CT {
4502 f_init();
4503 si_cfg.si2bis_present := true;
4504 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4505 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004507}
4508
4509testcase TC_si_sched_2ter() runs on test_CT {
4510 f_init();
4511 si_cfg.si2ter_present := true;
4512 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4513 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004515}
4516
4517testcase TC_si_sched_2ter_2bis() runs on test_CT {
4518 f_init();
4519 si_cfg.si2bis_present := true;
4520 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4521 si_cfg.si2ter_present := true;
4522 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4523 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004525}
4526
4527testcase TC_si_sched_2quater() runs on test_CT {
4528 f_init();
4529 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004530 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004531 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004533}
4534
4535testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004536 /* NOTE: PCUIF connection is not used in this test case, but
4537 * without it the IUT would not broadcast SI13 (see OS#3075). */
4538 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004539 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004540 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004541 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004543}
4544
4545testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004546 /* NOTE: PCUIF connection is not used in this test case, but
4547 * without it the IUT would not broadcast SI13 (see OS#3075). */
4548 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004549 si_cfg.si2bis_present := true;
4550 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4551 si_cfg.si2ter_present := true;
4552 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4553 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004554 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004555 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004556 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004557 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004559}
4560
4561
Harald Welte68e495b2018-02-25 00:05:57 +01004562testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004563 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004564 /* FIXME: enable / disable individual BCCH info */
4565 //ts_RSL_BCCH_INFO(si_type, info);
4566 /* expect no ERROR REPORT after either of them *
4567 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004569}
4570
Harald Welte93640c62018-02-25 16:59:33 +01004571/***********************************************************************
4572 * Low-Level Protocol Errors / ERROR REPORT
4573 ***********************************************************************/
4574
Harald Welte01d982c2018-02-25 01:31:40 +01004575private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4576 timer T := 5.0;
4577 T.start;
4578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004580 setverdict(pass);
4581 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004582 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004584 }
4585 [] RSL_CCHAN.receive {
4586 repeat;
4587 }
4588 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004590 }
4591 }
4592}
4593
4594/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4595testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004596 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004597 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4598 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004599 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004600
4601 f_exp_err_rep(RSL_ERR_PROTO);
4602}
4603
4604/* Provoke a mandatory IE error and match on ERROR REPORT */
4605testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004606 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004607
4608 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4609 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004610 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004611
4612 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4613}
4614
4615/* Provoke an IE content error and match on ERROR REPORT */
4616testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004617 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004618 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4619 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004620 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004621
4622 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4623}
4624
Harald Welteee25aae2019-05-19 14:32:37 +02004625/* attempt to activate channel with wrong RSL Message Discriminator IE */
4626function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4627 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4628 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4629 RSL.send(rsl);
4630 f_rslem_unregister(0, g_chan_nr);
4631}
4632testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4633 var ConnHdlr vc_conn;
4634 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4635
Harald Welte10474062019-05-30 16:48:17 +02004636 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004637
4638 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4639 vc_conn.done;
4640 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4641
4642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4643}
4644
4645/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004646private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004647 var template (value) RSL_Message rsl_tx;
4648 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4649 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4650 RSL.send(rsl_tx);
4651 f_rslem_unregister(0, g_chan_nr);
4652}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004653private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004654 var template (value) RSL_Message rsl_tx;
4655 /* we first have to activate the dedicated channel */
4656 f_rsl_chan_act(g_pars.chan_mode);
4657 /* ... to then send an invalid RLL message */
4658 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4659 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4660 RSL.send(rsl_tx);
4661 f_rslem_unregister(0, g_chan_nr);
4662}
4663testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4664 var ConnHdlr vc_conn;
4665 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4666 var template (value) RSL_Message rsl_tx;
4667
Harald Welte10474062019-05-30 16:48:17 +02004668 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004669
4670 /* Common Channel with wrong message type */
4671 RSL_CCHAN.clear;
4672 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4673 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004674 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004675 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4676
4677 /* TRX Management */
4678 RSL_CCHAN.clear;
4679 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4680 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004681 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004682 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4683
4684 /* Dedicated Channel */
4685 RSL_CCHAN.clear;
4686 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4687 vc_conn.done;
4688 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4689
4690 /* RLL */
4691 RSL_CCHAN.clear;
4692 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4693 vc_conn.done;
4694 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4695}
4696
4697/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004698private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004699 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4700 f_rslem_unregister(0, g_chan_nr);
4701}
4702testcase TC_err_rep_wrong_sequence() runs on test_CT {
4703 var ConnHdlr vc_conn;
4704 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4705
Harald Welte10474062019-05-30 16:48:17 +02004706 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004707
4708 RSL_CCHAN.clear;
4709 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4710 vc_conn.done;
4711 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4712}
4713
Harald Welte93640c62018-02-25 16:59:33 +01004714/***********************************************************************
4715 * IPA CRCX/MDCX/DLCS media stream handling
4716 ***********************************************************************/
4717
Harald Weltea871a382018-02-25 02:03:14 +01004718/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004719private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004720 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4721 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004722}
4723testcase TC_ipa_dlcx_not_active() runs on test_CT {
4724 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004725 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004726 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4727 vc_conn.done;
4728}
Harald Welte68e495b2018-02-25 00:05:57 +01004729
Harald Weltea3f1df92018-02-25 12:49:55 +01004730/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004731private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004732 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4733 "IPA CRCX ACK");
4734 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4735 "IPA CRCX NACK");
4736}
4737testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4738 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004739 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004740 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4741 vc_conn.done;
4742}
4743
4744/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004745private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004746 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4747 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004748 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004749 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4750 var uint7_t rtp_pt2 := f_rnd_int(127);
4751 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4752 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4753 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4754 "IPA MDCX ACK");
4755 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4756 "IPA DLCX ACK");
4757}
4758testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4759 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004760 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004761 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4762 vc_conn.done;
4763}
4764
Harald Welte3ae11da2018-02-25 13:36:06 +01004765/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004766private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004767 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4768 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004769 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004770 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4771 var uint7_t rtp_pt2 := f_rnd_int(127);
4772 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4773 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4774 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4775 "IPA MDCX ACK");
4776 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004777 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004778 remote_port := f_rnd_int(c_UINT16_MAX);
4779 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4780 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4781 "IPA MDCX ACK");
4782 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4783 "IPA DLCX ACK");
4784}
4785testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4786 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004787 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004788 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4789 vc_conn.done;
4790}
4791
Harald Welte9912eb52018-02-25 13:30:15 +01004792/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004793private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004794 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4795 "IPA CRCX NACK");
4796}
4797testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4798 var ConnHdlrPars pars;
4799 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004800 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004801
4802 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4803 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4804 vc_conn.done;
4805
4806 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4807 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4808 vc_conn.done;
4809}
4810
Harald Weltea3f1df92018-02-25 12:49:55 +01004811
Harald Welte883340c2018-02-28 18:59:29 +01004812/***********************************************************************
4813 * PCU Socket related tests
4814 ***********************************************************************/
4815
Harald Welte07bd2d22019-05-25 11:03:30 +02004816/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004817friend 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 +01004818runs on test_CT {
4819 timer T := 3.0;
4820
4821 /* we don't expect any RTS.req before PDCH are active */
4822 T.start;
4823 alt {
4824 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004825 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004826 }
4827 [] PCU.receive { repeat; }
4828 [] T.timeout { }
4829 }
4830
4831 /* Send PDCH activate request for known PDCH timeslot */
4832 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4833
4834 /* we now expect RTS.req for this timeslot (only) */
4835 T.start;
4836 alt {
4837 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4838 setverdict(pass);
4839 }
4840 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4841 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004843 }
4844 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004846 }
4847 [] PCU.receive { repeat; }
4848 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004850 }
4851 [not exp_success] T.timeout {
4852 setverdict(pass);
4853 }
4854 }
4855}
4856
Harald Welte07bd2d22019-05-25 11:03:30 +02004857/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004858friend 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 +01004859runs on test_CT {
4860 timer T := 3.0;
4861
4862 /* Send PDCH activate request for known PDCH timeslot */
4863 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 +02004864 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4865 * when it will actually have been executed in the BTS */
4866 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004867 PCU.clear;
4868 /* we now expect no RTS.req for this timeslot */
4869 T.start;
4870 alt {
4871 [] 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 +02004872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004873 }
4874 [] PCU.receive { repeat; }
4875 [] T.timeout {
4876 setverdict(pass);
4877 }
4878 }
4879}
4880
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004881friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004882 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004883 map(self:PCU, system:PCU);
4884 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004885 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4886}
4887
Harald Welte883340c2018-02-28 18:59:29 +01004888/* PDCH activation via PCU socket; check for presence of RTS.req */
4889testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004890 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004891
Harald Welte883340c2018-02-28 18:59:29 +01004892 f_TC_pcu_act_req(0, 0, 7, true);
4893}
4894
4895/* PDCH activation via PCU socket on non-PDCU timeslot */
4896testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004897 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004898
Harald Welte883340c2018-02-28 18:59:29 +01004899 f_TC_pcu_act_req(0, 0, 1, false);
4900}
4901
4902/* PDCH activation via PCU socket on wrong BTS */
4903testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004904 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004905
Harald Welte883340c2018-02-28 18:59:29 +01004906 f_TC_pcu_act_req(23, 0, 7, false);
4907}
4908
4909/* PDCH activation via PCU socket on wrong TRX */
4910testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004911 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004912
Harald Welte883340c2018-02-28 18:59:29 +01004913 f_TC_pcu_act_req(0, 23, 7, false);
4914}
4915
4916/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4917testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004918 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004919
Harald Welte883340c2018-02-28 18:59:29 +01004920 /* Activate PDCH */
4921 f_TC_pcu_act_req(0, 0, 7, true);
4922 f_sleep(1.0);
4923 /* and De-Activate again */
4924 f_TC_pcu_deact_req(0, 0, 7);
4925}
4926
4927/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4928testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004929 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004930
Harald Welte883340c2018-02-28 18:59:29 +01004931 f_TC_pcu_deact_req(0, 0, 1);
4932}
4933
4934/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004935function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004936 var PCUIF_send_data sd;
4937 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004938 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004939
4940 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004941 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004942
Harald Welte883340c2018-02-28 18:59:29 +01004943 T.start;
4944 alt {
4945 [] 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 +01004946 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004947 setverdict(pass);
4948 } else {
4949 repeat;
4950 }
4951 }
4952 [] PCU.receive { repeat; }
4953 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004955 }
4956 }
4957}
4958
Philipp Maier94c08482021-02-01 17:36:05 +01004959/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4960testcase TC_pcu_ver_si1() runs on test_CT {
4961 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4962 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4963}
4964
4965/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4966testcase TC_pcu_ver_si3() runs on test_CT {
4967 const octetstring si3 := '49012223242526272929AABBCC'O;
4968 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4969}
4970
4971/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4972testcase TC_pcu_ver_si13() runs on test_CT {
4973 const octetstring si13 := '01010203040506070909'O;
4974 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4975}
4976
Harald Welte883340c2018-02-28 18:59:29 +01004977private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4978
4979/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004980friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004981 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4982runs on test_CT
4983{
4984 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4985 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4986}
4987
4988/* 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 +02004989friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4990 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004991runs on test_CT
4992{
4993 var PCUIF_send_data sd;
4994
4995 timer T := 3.0;
4996 T.start;
4997 alt {
4998 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4999 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5000 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5001 sd.data.u.rts_req.fn, sapi, data);
5002 }
5003 [] PCU.receive { repeat; }
5004 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005006 }
5007 }
5008}
5009
5010/* Send DATA.req on invalid BTS */
5011testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005012 var TfiUsfArr tua := f_TfiUsfArrInit();
5013 var octetstring data := '0000'O & f_rnd_octstring(21);
5014
5015 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005016
Harald Welte883340c2018-02-28 18:59:29 +01005017 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005018 f_TfiUsfArrSet(tua, 7, 0);
5019 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5020 f_sleep(1.0);
5021
5022 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005023}
5024
5025/* Send DATA.req on invalid TRX */
5026testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005027 var TfiUsfArr tua := f_TfiUsfArrInit();
5028 var octetstring data := '0000'O & f_rnd_octstring(21);
5029
5030 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005031
Harald Welte883340c2018-02-28 18:59:29 +01005032 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005033 f_TfiUsfArrSet(tua, 7, 0);
5034 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5035 f_sleep(1.0);
5036
5037 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005038}
5039
5040/* Send DATA.req on invalid timeslot */
5041testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005042 var TfiUsfArr tua := f_TfiUsfArrInit();
5043 var octetstring data := '0000'O & f_rnd_octstring(21);
5044
5045 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005046
Harald Welte883340c2018-02-28 18:59:29 +01005047 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005048 f_TfiUsfArrSet(tua, 7, 0);
5049 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5050 f_sleep(1.0);
5051
5052 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005053}
5054
5055/* Send DATA.req on timeslot that hasn't been activated */
5056testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005057 var TfiUsfArr tua := f_TfiUsfArrInit();
5058 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005059
Harald Welte7162a612019-05-26 12:56:09 +02005060 f_virtphy_common();
5061
5062 f_TfiUsfArrSet(tua, 7, 0);
5063 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5064 f_sleep(1.0);
5065
5066 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005067}
5068
Harald Weltead033dc2019-05-25 17:28:16 +02005069private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005070 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5071 boolean wait_rts := true)
5072runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005073 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005074 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005075
5076 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005077 if (wait_rts) {
5078 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5079 } else {
5080 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5081 }
Harald Weltead033dc2019-05-25 17:28:16 +02005082
5083 T.start;
5084 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005085 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005086 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5087 setverdict(pass);
5088 }
Harald Welte7162a612019-05-26 12:56:09 +02005089 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5090 setverdict(fail, "Received unexpected ", rx_dl);
5091 }
Harald Weltead033dc2019-05-25 17:28:16 +02005092 [] L1CTL.receive {
5093 repeat;
5094 }
Harald Welte7162a612019-05-26 12:56:09 +02005095 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005096 setverdict(fail, "Timeout waiting for ", data);
5097 }
Harald Welte7162a612019-05-26 12:56:09 +02005098 [not expect_data] T.timeout {
5099 setverdict(pass);
5100 }
Harald Weltead033dc2019-05-25 17:28:16 +02005101 }
5102}
5103
5104private function f_disable_dynamic_ts() runs on test_CT
5105{
5106 f_init_vty_bsc();
5107 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5108 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5109 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5110 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005111 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005112}
5113
5114private function f_virtphy_common() runs on test_CT {
5115 f_disable_dynamic_ts();
5116 f_init_l1ctl();
5117 f_l1_tune(L1CTL);
5118}
5119
5120testcase TC_pcu_data_req_pdtch() runs on test_CT {
5121 var TfiUsfArr tua := f_TfiUsfArrInit();
5122 var octetstring data := '0000'O & f_rnd_octstring(21);
5123
5124 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005125
Harald Welte883340c2018-02-28 18:59:29 +01005126 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005127 f_TfiUsfArrSet(tua, 7, 0);
5128 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5129 f_sleep(1.0);
5130
5131 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005132}
5133
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005134/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005135testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005136 var TfiUsfArr tua := f_TfiUsfArrInit();
5137 var octetstring data := '0000'O & f_rnd_octstring(21);
5138
5139 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005140
Harald Welte883340c2018-02-28 18:59:29 +01005141 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005142 f_TfiUsfArrSet(tua, 7, 0);
5143 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5144 f_sleep(1.0);
5145
5146 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005147}
5148
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005149private function f_TC_pcu_ptcch_ul(uint16_t ra)
5150runs on test_CT {
5151 var template PCUIF_Message pcu_rach_ind;
5152 var PCUIF_send_data sd;
5153 var GsmFrameNumber fn;
5154 timer T;
5155
5156 /* Send an Access Burst on PTCCH/U over the Um-interface */
5157 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5158 chan_nr := ts_RslChanNr_PDCH(7),
5159 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5160
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005161 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5162 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005163
5164 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5165 T.start(52.0 * 4.615 / 1000.0);
5166 alt {
5167 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5168 log("Rx an Access Burst on the PCU interface: ", sd.data);
5169 setverdict(pass);
5170 T.stop;
5171 }
5172 [] PCU.receive { repeat; }
5173 [] T.timeout {
5174 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5175 /* Keep going, that's not the end of the world */
5176 }
5177 }
5178}
5179
5180testcase TC_pcu_ptcch() runs on test_CT {
5181 var L1ctlDlMessage dl;
5182 var octetstring data;
5183 timer T;
5184
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005185 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005186 f_init_l1ctl();
5187 f_l1_tune(L1CTL);
5188
5189 /* Activate PDCH channel on TS7 */
5190 f_TC_pcu_act_req(0, 0, 7, true);
5191
5192 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005193 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005194 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005195 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005196 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005197
5198 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5199 for (var integer i := 0; i < 16; i := i + 1) {
5200 log("Sending an Access Burst towards the L1CTL interface");
5201 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5202 }
5203
5204 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5205 data := f_rnd_octstring(23);
5206
5207 /* Verify PTCCH/D: send a random data block, make sure it's received */
5208 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5209 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5210
5211 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5212 * let's give it more time in case if we miss the beginning. */
5213 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5214 alt {
5215 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5216 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5217 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5218 frame := data)) -> value dl {
5219 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5220 setverdict(pass);
5221 T.stop;
5222 }
5223 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5224 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5225 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5226 l2_data := data)) -> value dl {
5227 log("Rx PTCCH/D data block on L1CTL: ", dl);
5228 setverdict(pass);
5229 T.stop;
5230 }
5231 [] L1CTL.receive { repeat; }
5232 [] T.timeout {
5233 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5234 }
5235 }
5236}
5237
Harald Welte883340c2018-02-28 18:59:29 +01005238/* Send AGCH from PCU; check it appears on Um side */
5239testcase TC_pcu_data_req_agch() runs on test_CT {
5240 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005241 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005242 f_init_l1ctl();
5243 f_l1_tune(L1CTL);
5244
5245 f_TC_pcu_act_req(0, 0, 7, true);
5246 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5247
5248 T.start;
5249 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005250 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005251 setverdict(pass);
5252 }
5253 [] L1CTL.receive { repeat; }
5254 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005256 }
5257 }
5258}
5259
Harald Welte928622b2019-05-26 13:22:59 +02005260/* Send AGCH from PCU; check it appears on Um side */
5261testcase TC_pcu_data_req_pch() runs on test_CT {
5262 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005263 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005264 f_init_l1ctl();
5265 f_l1_tune(L1CTL);
5266
5267 f_TC_pcu_act_req(0, 0, 7, true);
5268 /* three characters prefix: last 3 digits of IMSI as ASCII */
5269 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5270
5271 T.start;
5272 alt {
5273 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5274 setverdict(pass);
5275 }
5276 [] L1CTL.receive { repeat; }
5277 [] T.timeout {
5278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5279 }
5280 }
5281}
5282
Harald Welte883340c2018-02-28 18:59:29 +01005283/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5284testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5285 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005286 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005287 f_init_l1ctl();
5288 f_l1_tune(L1CTL);
5289
5290 /* append 3 last imsi digits so BTS can compute pagng group */
5291 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5292
5293 timer T := 0.5;
5294 T.start;
5295 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005296 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005297 /* TODO: verify paging group */
5298 setverdict(pass);
5299 }
5300 [] L1CTL.receive { repeat; }
5301 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005303 }
5304 }
5305}
5306
5307/* Send RACH from Um side, expect it to show up on PCU socket */
5308testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005309 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005310 f_init_l1ctl();
5311 f_l1_tune(L1CTL);
5312
5313 var GsmFrameNumber fn_last := 0;
5314 for (var integer i := 0; i < 1000; i := i+1) {
5315 var OCT1 ra := f_rnd_ra_ps();
5316 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5317 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005319 }
5320 fn_last := fn;
5321
5322 timer T := 2.0;
5323 T.start;
5324 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005325 [] 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 +01005326 T.stop;
5327 }
5328 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005330 }
5331 [] PCU.receive { repeat; }
5332 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005334 }
5335 }
5336 }
5337 setverdict(pass);
5338}
5339
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005340/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5341 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5342testcase TC_pcu_ext_rach_content() runs on test_CT {
5343 var template PCUIF_Message pcu_rach_ind;
5344 var GsmFrameNumber fn_last := 0;
5345 var L1ctlRachSynchSeq synch_seq;
5346 var PCUIF_BurstType pcu_bt;
5347 var GsmFrameNumber fn;
5348 var BIT11 ra11;
5349
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005350 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005351 f_init_l1ctl();
5352 f_l1_tune(L1CTL);
5353
5354 for (var integer i := 0; i < 1000; i := i+1) {
5355 /* We need to test both TS1 & TS2 */
5356 if (i rem 2 == 0) {
5357 synch_seq := RACH_SYNCH_SEQ_TS1;
5358 pcu_bt := BURST_TYPE_1;
5359 } else {
5360 synch_seq := RACH_SYNCH_SEQ_TS2;
5361 pcu_bt := BURST_TYPE_2;
5362 }
5363
5364 ra11 := f_rnd_ra11_ps();
5365 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5366 if (fn == fn_last) {
5367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5368 "Two RACH in same FN?!?");
5369 }
5370 fn_last := fn;
5371
5372 /* Compose the expected message */
5373 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005374 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005375 ra := bit2int(ra11),
5376 is_11bit := 1,
5377 burst_type := pcu_bt,
5378 fn := fn);
5379
5380 timer T := 2.0;
5381 T.start;
5382 alt {
5383 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5384 T.stop;
5385 }
5386 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5388 }
5389 [] PCU.receive { repeat; }
5390 [] T.timeout {
5391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5392 }
5393 }
5394 }
5395 setverdict(pass);
5396}
5397
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005398private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5399runs on test_CT {
5400 var template PCUIF_send_data sdt;
5401 var PCUIF_send_data sd;
5402 var int16_t lqual_cb;
5403 timer T := 1.0;
5404
5405 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5406 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5407
5408 /* Send a random PDTCH frame over Um */
5409 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5410 '0000'O & f_rnd_octstring(21)));
5411
5412 T.start;
5413 alt {
5414 /* If expected link quality is above the threshold */
5415 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5416 lqual_cb := sd.data.u.data_ind.lqual_cb;
5417 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5418
5419 /* Make sure the actual link quality matches the expected value */
5420 if (not match(lqual_cb, lqual_cb_exp)) {
5421 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5422 "expected value ", lqual_cb_exp));
5423 } else {
5424 setverdict(pass);
5425 }
5426 }
5427 /* If expected link quality is below the threshold */
5428 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5430 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5431 }
5432 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5433 [] PCU.receive { repeat; }
5434 [lqual_cb_exp < thresh] T.timeout {
5435 log("Rx nothing, as expected");
5436 setverdict(pass);
5437 }
5438 [lqual_cb_exp >= thresh] T.timeout {
5439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5440 "Timeout waiting for PCUIF_DATA.ind");
5441 }
5442 }
5443}
5444
5445/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5446testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005447 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005448 PCU.clear;
5449
5450 f_init_l1ctl();
5451 f_l1_tune(L1CTL);
5452
5453 /* Activate a PDCH channel on TS7 */
5454 f_TC_pcu_act_req(0, 0, 7, true);
5455
5456 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005457 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005458 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005459 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005460 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005461
5462 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5463 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5464 var TrxcMessage ret;
5465
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005466 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005467
5468 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5469 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5470 }
5471}
5472
Harald Welte883340c2018-02-28 18:59:29 +01005473/* Send PAGING via RSL, expect it to shw up on PCU socket */
5474testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005475 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005476
5477 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005478 var MobileIdentityLV mi_lv;
5479 var octetstring mi_lv_enc;
5480 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005481 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005482
Harald Welte883340c2018-02-28 18:59:29 +01005483 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005484 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005485 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005486 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005487 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005488
5489 /* Fancy encoding for PCUIF */
5490 mi_lv := valueof(ts_MI_LV(mi));
5491 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5492 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005493
5494 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005495 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005496 T.start;
5497 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005498 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005499 }
5500 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005502 }
5503 [] PCU.receive { repeat; }
5504 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005506 }
5507 }
5508 }
5509 setverdict(pass);
5510}
5511
Harald Welted66c9b82019-05-25 09:03:15 +02005512/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5513testcase TC_pcu_time_ind() runs on test_CT {
5514 var PCUIF_send_data pcu_sd;
5515 var integer num_time_ind := 0;
5516 var integer first_fn, last_fn;
5517 var float test_duration := 5.0;
5518 timer T;
5519
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005520 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005521 f_TC_pcu_act_req(0, 0, 7, true);
5522
5523 PCU.clear;
5524 T.start(test_duration);
5525 alt {
5526 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5527 num_time_ind := num_time_ind + 1;
5528 if (not isbound(first_fn)) {
5529 first_fn := pcu_sd.data.u.time_ind.fn;
5530 }
5531 last_fn := pcu_sd.data.u.time_ind.fn;
5532 repeat;
5533 }
5534 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5535 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5536 repeat;
5537 }
5538 [] PCU.receive {
5539 repeat;
5540 }
5541 [] T.timeout {}
5542 }
5543 var integer fn_expired := last_fn - first_fn;
5544 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5545
5546 /* verify the number of frames expired matches our expectation */
5547 const float c_GSM_FN_DURATION_MS := 4.61538;
5548 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005549 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005550 if (not match(fn_expired, t_fn_expected)) {
5551 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5552 }
5553
5554 /* There are three TIME.ind in every fn MOD 13 */
5555 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5556 /* Add some tolerance */
5557 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5558 if (not match(num_time_ind, t_time_ind_exp)) {
5559 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5560 }
5561
5562 setverdict(pass);
5563}
5564
Harald Welte4832c862019-05-25 14:57:18 +02005565/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5566testcase TC_pcu_rts_req() runs on test_CT {
5567 var PCUIF_send_data pcu_sd;
5568 var integer first_fn, last_fn;
5569 var integer num_rts_pdtch := 0;
5570 var integer num_rts_ptcch := 0;
5571 var float test_duration := 5.0;
5572 timer T;
5573
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005574 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005575 f_TC_pcu_act_req(0, 0, 7, true);
5576
5577 PCU.clear;
5578 T.start(test_duration);
5579 alt {
5580 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5581 -> value pcu_sd {
5582 num_rts_pdtch := num_rts_pdtch + 1;
5583 if (not isbound(first_fn)) {
5584 first_fn := pcu_sd.data.u.rts_req.fn;
5585 }
5586 last_fn := pcu_sd.data.u.rts_req.fn;
5587 repeat;
5588 }
5589 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5590 -> value pcu_sd {
5591 num_rts_ptcch := num_rts_ptcch + 1;
5592 if (not isbound(first_fn)) {
5593 first_fn := pcu_sd.data.u.rts_req.fn;
5594 }
5595 last_fn := pcu_sd.data.u.rts_req.fn;
5596 repeat;
5597 }
5598 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5599 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5600 repeat;
5601 }
5602 [] PCU.receive {
5603 repeat;
5604 }
5605 [] T.timeout {}
5606 }
5607 var integer fn_expired := last_fn - first_fn;
5608 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5609 ", num_rts_ptcch=", num_rts_ptcch);
5610
5611 /* verify the number of frames expired matches our expectation */
5612 const float c_GSM_FN_DURATION_MS := 4.61538;
5613 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005614 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005615 if (not match(fn_expired, t_fn_expected)) {
5616 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5617 }
5618
5619 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5620 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5621 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5622 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5623 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5624 t_ptcch_exp);
5625 }
5626
5627 /* We have 12 PDTCH blocks every 52-multiframe */
5628 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5629 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5630 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5631 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5632 t_pdtch_exp);
5633 }
5634
5635 setverdict(pass);
5636}
5637
Harald Welte07bd2d22019-05-25 11:03:30 +02005638/* test for generating Abis side OML ALERT from the PCU */
5639testcase TC_pcu_oml_alert() runs on test_CT {
5640 var PCUIF_send_data pcu_sd;
5641 var integer num_time_ind := 0;
5642 var integer first_fn, last_fn;
5643 var float test_duration := 5.0;
5644 timer T;
5645
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005646 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005647 f_TC_pcu_act_req(0, 0, 7, true);
5648
5649 /* re-connect CTRL port from BTS to BSC */
5650 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005651 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005652
5653 /* Send that OML Alert */
5654 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5655
5656 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5657 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5658 setverdict(pass);
5659}
5660
Harald Welteeaa9a862019-05-26 23:01:08 +02005661/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5662private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5663 var PCUIF_Message first_info;
5664 var integer pcu_conn_id := -1;
5665 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5666 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5667 var OCT4 tlli := '01020304'O;
5668 var OCT1 cause := '23'O;
5669 timer T := 5.0;
5670
5671 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5672
5673 f_l1_tune(L1CTL);
5674 RSL.clear;
5675
5676 f_est_dchan();
5677 L1CTL.clear;
5678
5679 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5680
5681 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5682 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5683 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5684
5685 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5686 T.start;
5687 alt {
5688 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5689 setverdict(pass);
5690 }
5691 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5692 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5693 }
5694 [] PCU.receive {
5695 repeat;
5696 }
5697 [] T.timeout {
5698 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5699 }
5700 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005701
5702 /* release the channel */
5703 f_rsl_chan_deact();
5704 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5705 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005706}
5707testcase TC_pcu_rr_suspend() runs on test_CT {
5708 var ConnHdlrPars pars;
5709 var ConnHdlr vc_conn;
5710
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005711 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005712
5713 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5714 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5715 vc_conn.done;
5716}
Harald Welte07bd2d22019-05-25 11:03:30 +02005717
Harald Weltea2e0e942019-05-27 18:12:53 +02005718/* Ensure that PCUIF socket can accept only a single connection */
5719testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005720 var boolean connected := false;
5721 var UD_connect_result cr;
5722 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005723 timer T := 5.0;
5724
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005725 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5726 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5727
Harald Weltea2e0e942019-05-27 18:12:53 +02005728 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005729 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005730
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005731 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005732 PCU.send(UD_connect:{mp_pcu_socket, -1});
5733 T.start;
5734 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005735 /* the IUT will first accept() the new connection, and close() it immediately */
5736 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5737 log("BTS has accept()ed connection");
5738 connected := true;
5739 cid := cr.id;
5740 repeat;
5741 }
5742 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5743 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005744 setverdict(pass);
5745 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005746 /* ignore other messages related to the first connection */
5747 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005748 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005749 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005750 }
5751 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005752
Harald Weltea2e0e942019-05-27 18:12:53 +02005753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5754}
5755
Harald Weltec8effb72019-05-27 18:23:04 +02005756/* Ensure that PCUIF socket can disconnect + reconnect */
5757testcase TC_pcu_socket_reconnect() runs on test_CT {
5758 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005759 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005760
5761 f_sleep(1.0);
5762
5763 f_pcuif_close(PCU, g_pcu_conn_id);
5764 g_pcu_conn_id := -1;
5765
5766 f_sleep(1.0);
5767
5768 /* re-connect */
5769 PCU.clear;
5770 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5771 setverdict(pass);
5772
5773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5774}
5775
Harald Weltebe030482019-05-27 22:29:35 +02005776/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005777private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5778runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005779 var L1ctlDlMessage l1_dl;
5780 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005781 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005782 timer T := 5.0;
5783 T.start;
5784 alt {
5785 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005786 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5787 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005788 repeat;
5789 }
5790 }
5791 [] pt.receive {
5792 repeat;
5793 }
5794 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5796 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005797 }
5798 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005799 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005800}
5801
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005802/* Check if GPRS Indicator is present in RR System Information of a given type */
5803private function f_si_has_gprs_indicator(RrMessageType si_type)
5804runs on test_CT return boolean {
5805 var SystemInformation si := f_get_si(L1CTL, si_type);
5806
5807 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005808 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005809 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005810 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005811 }
5812
5813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5814 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005815}
5816
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005817/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5818private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5819runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005820 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005821 f_init_l1ctl();
5822 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005823 f_sleep(2.0);
5824 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005825
5826 if (f_si_has_gprs_indicator(si_type)) {
5827 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005828 } else {
5829 setverdict(pass);
5830 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005831
Harald Weltebe030482019-05-27 22:29:35 +02005832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5833}
5834
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005835testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5836 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5837}
Harald Weltebe030482019-05-27 22:29:35 +02005838
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005839testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5840 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5841}
5842
5843/* Ensure that GPRS capability is advertised after PCU socket connect */
5844private function f_TC_pcu_socket_connect(RrMessageType si_type)
5845runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005846 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005847 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005848 f_init_l1ctl();
5849 f_l1_tune(L1CTL);
5850
5851 f_sleep(2.0);
5852 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005853
5854 if (not f_si_has_gprs_indicator(si_type)) {
5855 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005856 } else {
5857 setverdict(pass);
5858 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005859
Harald Weltebe030482019-05-27 22:29:35 +02005860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5861}
5862
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005863testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5864 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5865}
Harald Weltebe030482019-05-27 22:29:35 +02005866
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005867testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5868 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5869}
5870
5871/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5872private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5873runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005874 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005875 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005876 f_init_l1ctl();
5877 f_l1_tune(L1CTL);
5878
5879 f_pcuif_close(PCU, g_pcu_conn_id);
5880 g_pcu_conn_id := -1;
5881
5882 f_sleep(1.0);
5883
5884 /* re-connect */
5885 PCU.clear;
5886 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5887
5888 f_sleep(2.0);
5889 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005890
5891 if (f_si_has_gprs_indicator(si_type)) {
5892 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005893 } else {
5894 setverdict(pass);
5895 }
5896
5897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5898}
5899
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005900testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5901 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5902}
5903
5904testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5905 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5906}
5907
Oliver Smithf5239c72019-08-28 10:01:25 +02005908/* 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) */
5909testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5910 var SystemInformation si3 := valueof(ts_SI3_default);
5911
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005912 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005913
Harald Welte76220222020-10-11 20:32:44 +02005914 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5915 * information */
5916 timer T := 2.0;
5917 T.start;
5918 alt {
5919 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5920 [] T.timeout {}
5921 }
5922
Oliver Smithf5239c72019-08-28 10:01:25 +02005923 /* Verify cell_id */
5924 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5925 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5926 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005927 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5928 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5929 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005930 }
5931
5932 /* Verify LAC */
5933 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5934 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5935 if (lac_si3 != lac_pcu) {
5936 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5937 }
5938
5939 setverdict(pass);
5940}
Harald Welted66c9b82019-05-25 09:03:15 +02005941
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005942/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5943testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5944 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005945 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005946
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005947 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005948
5949 info_ind := g_pcu_last_info.u.info_ind;
5950
5951 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5952 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005953 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005954 /* Skip inactive timeslots */
5955 continue;
5956 }
5957
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005958 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005959 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005960 else
5961 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005962
5963 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005964 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005965 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005966 hsn := fhp.maio_hsn.hsn,
5967 maio := fhp.maio_hsn.maio,
5968 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005969 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005970 } else {
5971 tr_ts := tr_PCUIF_InfoTrxTsH0;
5972 }
5973
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005974 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005975 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5976 if (not match(ts, tr_ts)) {
5977 setverdict(fail, "Hopping parameters do not match: ",
5978 "received ", ts, " vs expected ", tr_ts);
5979 } else {
5980 setverdict(pass);
5981 }
5982 }
5983 }
5984}
5985
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005986/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005987testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5988 f_init_vty_bsc();
5989 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5990 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5991
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005992 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005993
5994 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005995 var template PCUIF_RemoteAddr tr_remote_addr := {
5996 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005997 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005998 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005999
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006000 if (not match(remote_addr, tr_remote_addr)) {
6001 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006002 }
6003
6004 setverdict(pass);
6005}
6006
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006007/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006008testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6009 f_init_vty_bsc();
6010 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6011
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006012 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006013
6014 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006015 var template PCUIF_RemoteAddr tr_remote_addr := {
6016 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6017 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6018 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006019
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006020 if (not match(remote_addr, tr_remote_addr)) {
6021 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006022 }
6023
6024 setverdict(pass);
6025}
6026
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006027/* Verify coding of two NSVCs in the INFO.ind message */
6028testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6029 f_init_vty_bsc();
6030
6031 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6032 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6033 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6034 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6035
6036 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6037 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6038 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6039 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6040
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006041 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006042
6043 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6044 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6045 var template PCUIF_RemoteAddr tr_remote_addr := {
6046 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006047 addr := {
6048 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6049 f_inet6_addr("fd00::ca:ff:ee")
6050 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006051 };
6052
6053 if (not match(info_ind.nsvci, { 1234, 5678 }))
6054 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6055 if (not match(remote_addr, tr_remote_addr))
6056 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6057 if (not match(info_ind.local_port, { 1234, 5678 }))
6058 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6059 if (not match(info_ind.remote_port, { 1234, 5678 }))
6060 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6061
6062 setverdict(pass);
6063}
6064
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006065/* Verify periodic interference reports on PDCH */
6066testcase TC_pcu_interf_ind() runs on test_CT {
6067 var template PCUIF_Message tr_interf_ind;
6068 var template PCUIF_interf ts_interf;
6069 var integer interf_ind_num := 0;
6070 var PCUIF_send_data sd;
6071 timer T;
6072
6073 f_init_with_pcuif();
6074 f_TC_pcu_act_req(0, 0, 7, true);
6075
6076 /* We need trxcon for NOPE indications */
6077 f_init_l1ctl();
6078 f_l1_tune(L1CTL);
6079
6080 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6081 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6082 tr_interf_ind := tr_PCUIF_INTERF_IND(
6083 bts_nr := 0,
6084 trx_nr := 0,
6085 fn := ?,
6086 interf := ts_interf
6087 );
6088
6089 /* 4 SACCH periods => 4 reports (plus some guard time) */
6090 var float Tval := int2float(4 * 480) / 1000.0 + 0.5;
6091
6092 /* Let it some time to stabilize */
6093 f_sleep(0.5);
6094 PCU.clear;
6095
6096 T.start(Tval);
6097 alt {
6098 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
6099 /* Check TDMA frame number period */
6100 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6101 setverdict(fail, "Odd TDMA frame number := ",
6102 sd.data.u.interf_ind.fn);
6103 }
6104 interf_ind_num := interf_ind_num + 1;
6105 if (interf_ind_num < 4)
6106 { repeat; }
6107 }
6108 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
6109 setverdict(fail, "Received unexpected interference report: ", sd.data);
6110 }
6111 [] PCU.receive { repeat; }
6112 [] T.timeout {
6113 setverdict(fail, "Timeout waiting for interference reports");
6114 }
6115 }
6116
6117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6118}
6119
Harald Welte3d04ae62018-04-04 20:29:05 +02006120/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006121 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006122 ***********************************************************************/
6123
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006124private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6125 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006126runs on ConnHdlr {
6127 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006128
6129 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006130 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006131 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6132 repeat;
6133 }
6134 }
6135}
6136
6137private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6138runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006139 /* Expect BTS to immediately acknowledge activation as PDCH */
6140 PCU.clear;
6141 f_rsl_chan_act(g_pars.chan_mode);
6142 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006143 timer T_wait := 2.0;
6144 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006145 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006146 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006147 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006148 [] T_wait.timeout {
6149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6150 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6151 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006152 }
6153 /* try to activate this PDCH from the PCU point of view */
6154 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6155 /* FIXME: is there a response? */
6156}
6157
6158private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6159runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006160 /* Send RSL CHAN REL (deactivate) */
6161 PCU.clear;
6162 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6163 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006164 timer T_wait := 2.0;
6165 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006166 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006167 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006168 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006169 [] T_wait.timeout {
6170 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6171 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6172 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006173 }
6174 /* Emulate PCU asking BTS to deactivate PDCH */
6175 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6176 alt {
6177 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6178 setverdict(pass);
6179 }
6180 [] RSL.receive { repeat; }
6181 }
6182}
6183
6184/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006185private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006186 var PCUIF_Message first_info;
6187 var integer ts_nr := g_chan_nr.tn;
6188 var integer trx_nr := 0;
6189 var integer bts_nr := 0;
6190 var integer pcu_conn_id := -1;
6191
6192 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6193
6194 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6195 f_sleep(3.0);
6196 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6197 setverdict(pass);
6198}
6199testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6200 var ConnHdlrPars pars;
6201 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006202 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006203
6204 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6205 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6206 vc_conn.done;
6207}
6208
6209/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006210private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006211 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006212 var integer pcu_conn_id := -1;
6213
6214 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6215
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006216 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6217 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6218 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006219 setverdict(pass);
6220}
6221testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6222 var ConnHdlrPars pars;
6223 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006224 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006225
6226 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6227 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6228 vc_conn.done;
6229}
6230
6231/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006232private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006233 var PCUIF_Message first_info;
6234 var integer ts_nr := g_chan_nr.tn;
6235 var integer trx_nr := 0;
6236 var integer bts_nr := 0;
6237 var integer pcu_conn_id := -1;
6238
6239 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6240
6241 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006242 /* Send a second Chan Activ and expect it to be NACKed */
6243 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6244 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006245 setverdict(pass);
6246}
6247testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6248 var ConnHdlrPars pars;
6249 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006250 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006251
6252 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6253 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6254 vc_conn.done;
6255}
6256
6257/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006258private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006259 var PCUIF_Message first_info;
6260 var integer ts_nr := g_chan_nr.tn;
6261 var integer trx_nr := 0;
6262 var integer bts_nr := 0;
6263 var integer pcu_conn_id := -1;
6264 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6265
6266 /* register for the TCH/F channel number */
6267 f_rslem_register(0, chan_nr);
6268
6269 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6270
6271 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6272 "RSL CHAN ACT");
6273 setverdict(pass);
6274}
6275testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6276 var ConnHdlrPars pars;
6277 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006278 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006279
6280 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6281 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6282 vc_conn.done;
6283}
6284
6285/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006286private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006287 var PCUIF_Message first_info;
6288 var integer ts_nr := g_chan_nr.tn;
6289 var integer trx_nr := 0;
6290 var integer bts_nr := 0;
6291 var integer pcu_conn_id := -1;
6292 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6293 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6294
6295 /* register for the TCH/H channel numbers */
6296 f_rslem_register(0, chan_nr[0]);
6297 f_rslem_register(0, chan_nr[1]);
6298
6299 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6300
6301 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6302 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6303 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6304 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6305 setverdict(pass);
6306}
6307testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6308 var ConnHdlrPars pars;
6309 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006310 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006311
6312 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6313 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6314 vc_conn.done;
6315}
6316
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006317/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6318private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6319 var PCUIF_Message first_info;
6320 var integer ts_nr := g_chan_nr.tn;
6321 var integer trx_nr := 0;
6322 var integer bts_nr := 0;
6323 var integer pcu_conn_id := -1;
6324 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6325 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6326 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6327 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6328 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6329 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6330 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6331 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6332
6333 /* register for the TCH/H channel numbers */
6334 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6335 f_rslem_register(0, chan_nr[i]);
6336 }
6337
6338 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6339
6340 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6341 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6342 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6343 }
6344 setverdict(pass);
6345}
6346testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6347 var ConnHdlrPars pars;
6348 var ConnHdlr vc_conn;
6349 f_init();
6350
6351 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6352 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6353 vc_conn.done;
6354}
6355
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006356/* Reproduce a race condition described in OS#5245 */
6357private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6358 f_rsl_chan_act(g_pars.chan_mode);
6359 f_sleep(1.0);
6360 f_rsl_chan_deact();
6361 setverdict(pass);
6362}
6363testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6364 var ConnHdlrPars pars[2];
6365 var ConnHdlr vc_conn[2];
6366 var TrxcMessage rsp;
6367
6368 f_init();
6369
6370 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6371 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6372 ts_TRXC_FAKE_TRXC_DELAY(200));
6373
6374 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6375 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6376 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6377 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6378 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6379 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6380 pars[i], l1ctl := false);
6381 }
6382
6383 /* Wait for all components to finish */
6384 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6385 vc_conn[i].done;
6386 }
6387
6388 /* Disable the artificial delay for TRXC RSP messages */
6389 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6390 ts_TRXC_FAKE_TRXC_DELAY(0));
6391}
6392testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6393 var ConnHdlrPars pars[8];
6394 var ConnHdlr vc_conn[8];
6395 var TrxcMessage rsp;
6396
6397 f_init();
6398
6399 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6400 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6401 ts_TRXC_FAKE_TRXC_DELAY(200));
6402
6403 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6404 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6405 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6406 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6407 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6408 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6409 pars[i], l1ctl := false);
6410 }
6411
6412 /* Wait for all components to finish */
6413 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6414 vc_conn[i].done;
6415 }
6416
6417 /* Disable the artificial delay for TRXC RSP messages */
6418 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6419 ts_TRXC_FAKE_TRXC_DELAY(0));
6420}
6421
Harald Welte9bbbfb52018-04-05 09:33:19 +02006422/***********************************************************************
6423 * IPA Style Dynamic Timeslot Support
6424 ***********************************************************************/
6425
6426private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6427runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006428 /* Expect BTS to immediately acknowledge activation as PDCH */
6429 PCU.clear;
6430 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6431 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006432 timer T_wait := 2.0;
6433 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006434 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006435 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006436 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006437 [] T_wait.timeout {
6438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6439 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6440 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006441 }
6442 /* try to activate this PDCH from the PCU point of view */
6443 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6444 /* FIXME: is there a response? */
6445
6446 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6447}
6448
6449private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6450runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006451 /* Send RSL CHAN REL (deactivate) */
6452 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6453 PCU.clear;
6454 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006455 timer T_wait := 2.0;
6456 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006457 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006458 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006459 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006460 [] T_wait.timeout {
6461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6462 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6463 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006464 }
6465 /* Emulate PCU asking BTS to deactivate PDCH */
6466 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6467 alt {
6468 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6469 setverdict(pass);
6470 }
6471 [] RSL.receive { repeat; }
6472 }
6473}
6474
6475/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006476private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006477 var PCUIF_Message first_info;
6478 var integer ts_nr := g_chan_nr.tn;
6479 var integer trx_nr := 0;
6480 var integer bts_nr := 0;
6481 var integer pcu_conn_id := -1;
6482
6483 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6484
6485 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6486 f_sleep(3.0);
6487 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6488
6489 setverdict(pass);
6490
6491}
6492testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6493 var ConnHdlrPars pars;
6494 var ConnHdlr vc_conn;
6495 f_init();
6496
6497 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6498 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6499 vc_conn.done;
6500}
6501
6502/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006503private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006504 var PCUIF_Message first_info;
6505 var integer ts_nr := g_chan_nr.tn;
6506 var integer trx_nr := 0;
6507 var integer bts_nr := 0;
6508 var integer pcu_conn_id := -1;
6509
6510 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6511
6512 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6513 "RSL CHAN ACT");
6514 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6515 "RF CHAN REL", true);
6516 setverdict(pass);
6517}
6518testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6519 var ConnHdlrPars pars;
6520 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006521 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006522
6523 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6524 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6525 vc_conn.done;
6526}
6527
6528/* 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 +07006529private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006530 var PCUIF_Message first_info;
6531 var integer ts_nr := g_chan_nr.tn;
6532 var integer trx_nr := 0;
6533 var integer bts_nr := 0;
6534 var integer pcu_conn_id := -1;
6535
6536 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6537
6538 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6539 "RSL CHAN ACT");
6540
6541 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6542 alt {
6543 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6544 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006546 }
6547 [] RSL.receive { repeat; }
6548 }
6549
6550 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6551 "RF CHAN REL", true);
6552 setverdict(pass);
6553}
6554testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6555 var ConnHdlrPars pars;
6556 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006557 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006558
6559 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6560 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6561 vc_conn.done;
6562}
6563
6564/* 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 +07006565private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006566 var PCUIF_Message first_info;
6567 var integer ts_nr := g_chan_nr.tn;
6568 var integer trx_nr := 0;
6569 var integer bts_nr := 0;
6570 var integer pcu_conn_id := -1;
6571
6572 /* register for the TCH/F channel number */
6573 f_rslem_register(0, g_chan_nr);
6574
6575 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6576
6577 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6578
6579 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6580 "RSL CHAN ACT");
6581
6582 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6583
6584 setverdict(pass);
6585}
6586testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6587 var ConnHdlrPars pars;
6588 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006589 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006590
6591 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6592 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6593 vc_conn.done;
6594}
6595
6596
Harald Welte0472ab42018-03-12 15:02:26 +01006597/***********************************************************************
6598 * LAPDm / RLL related
6599 ***********************************************************************/
6600
6601private function f_tx_lapdm(template (value) LapdmFrame l,
6602 template (value) RslLinkId link_id) runs on ConnHdlr {
6603 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006604 var template (value) SacchL1Header l1h;
6605
6606 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006607 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006608 /* Compose dummy L1 header */
6609 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6610 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 +02006611 } else {
6612 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006613 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 +01006614 }
Harald Welte0472ab42018-03-12 15:02:26 +01006615}
6616
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006617friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006618 uint3_t sapi,
6619 RslLinkId link_id,
6620 octetstring l3,
6621 boolean exp
6622}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006623friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006624friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6625 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006626 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006627 sapi := sapi,
6628 link_id := id,
6629 l3 := l3,
6630 exp := exp
6631}
6632
6633/* execute the same callback function with a set of different parameters (tcs) on a
6634 * variety of logical channels */
6635private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6636 var ConnHdlrPars pars;
6637 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006638 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006639
6640 /* test on each of the channels we have */
6641 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6642 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6643
6644 /* test each of the test cases on the current channel */
6645 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6646 pars.spec.rll := tcs[j];
6647 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6648 vc_conn := f_start_handler(fn, pars);
6649 vc_conn.done;
6650 }
6651 }
6652
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006654}
6655
6656/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6657private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6658 var RllTestCase tc := g_pars.spec.rll;
6659 timer T := 3.0;
6660
6661 f_l1_tune(L1CTL);
6662 RSL.clear;
6663
6664 /* activate the logical channel */
6665 f_est_dchan();
6666 L1CTL.clear;
6667
6668 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6669 T.start;
6670 alt {
6671 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6672 if (tc.exp) {
6673 setverdict(pass);
6674 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006676 }
6677 }
6678 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6679 if (tc.exp) {
6680 setverdict(pass);
6681 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006683 }
6684 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006685 /* We also expect to receive the measurements */
6686 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006687 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006689 }
6690 [not tc.exp] T.timeout {
6691 setverdict(pass);
6692 }
6693 }
6694
6695 f_rsl_chan_deact();
6696 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6697 f_rslem_unregister(0, g_chan_nr);
6698}
6699testcase TC_rll_est_ind() runs on test_CT {
6700 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006701 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006702 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006703 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006704 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006705 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006706 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6707 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006708 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006709 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006710 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006711 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006712 };
6713 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6714}
6715
6716/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6717private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6718 var RllTestCase tc := g_pars.spec.rll;
6719 var L1ctlDlMessage dl;
6720 timer T := 3.0;
6721
6722 f_l1_tune(L1CTL);
6723 RSL.clear;
6724
6725 /* activate the logical channel */
6726 f_est_dchan();
6727 L1CTL.clear;
6728
6729 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6730 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6731 T.start;
6732 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006733 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006734 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006736 }
6737 }
6738
6739 f_rsl_chan_deact();
6740 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6741 f_rslem_unregister(0, g_chan_nr);
6742}
6743testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6744 var RllTestCases tcs := {
6745 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006746 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006747 };
6748 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6749}
6750testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6751 var RllTestCases tcs := {
6752 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006753 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006754 }
6755 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6756}
6757
6758/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006759friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006760 var L1ctlDlMessage dl;
6761 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6762 var LapdmFrame lapdm;
6763 var octetstring l2 := dl.payload.data_ind.payload;
6764 if (dl.dl_info.link_id.c == SACCH) {
6765 /* remove L1 header */
6766 l2 := substr(l2, 2, lengthof(l2)-2);
6767 }
6768 if (ischosen(exp.ab)) {
6769 lapdm.ab := dec_LapdmFrameAB(l2);
6770 } else if (ischosen(exp.b4)) {
6771 lapdm.b4 := dec_LapdmFrameB4(l2);
6772 } else if (ischosen(exp.bbis)) {
6773 lapdm.bbis := dec_LapdmFrameBbis(l2);
6774 }
6775 log("Rx LAPDm ", lapdm);
6776 if (match(lapdm, exp)) {
6777 setverdict(pass);
6778 } else {
6779 repeat;
6780 }
6781 }
6782 [] L1CTL.receive { repeat; }
6783}
6784private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6785 timer T := t;
6786 T.start;
6787 alt {
6788 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006790 }
6791 [] as_l1_exp_lapdm(exp);
6792 }
6793}
6794
6795/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6796private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6797 /* send SABM from MS -> BTS */
6798 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6799 /* expect RLL EST IND on Abis */
6800 alt {
6801 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6802 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6803 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006805 }
6806 [] RSL.receive { repeat; }
6807 }
6808 /* expect UA from BTS -> MS */
6809 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6810}
6811
6812/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6813private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6814 var RllTestCase tc := g_pars.spec.rll;
6815
6816 f_l1_tune(L1CTL);
6817 RSL.clear;
6818
6819 /* activate the logical channel */
6820 f_est_dchan();
6821 L1CTL.clear;
6822
6823 /* first establish the link-layer */
6824 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6825
6826 /* then send the DISC */
6827 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6828 /* ... and expect the REL IND on the RSL side */
6829 alt {
6830 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6831 setverdict(pass);
6832 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006833 /* We also expect to receive the measurements */
6834 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006835 }
6836
6837 /* release the channel */
6838 f_rsl_chan_deact();
6839 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6840 f_rslem_unregister(0, g_chan_nr);
6841}
6842testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6843 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006844 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006845 };
6846 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6847}
6848
6849testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6850 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006851 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006852 };
6853 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6854}
6855testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6856 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006857 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006858 };
6859 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6860}
6861testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6862 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006863 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006864 };
6865 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6866}
6867
6868/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6869private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6870 var RllTestCase tc := g_pars.spec.rll;
6871 f_l1_tune(L1CTL);
6872 RSL.clear;
6873
6874 /* activate the logical channel */
6875 f_est_dchan();
6876 L1CTL.clear;
6877
6878 /* first establish the link-layer */
6879 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6880
6881 /* then send the REL REQ via RSL */
6882 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6883 /* ... and expect the DISC on the Um side */
6884 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006885 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006886 /* FIXME: send a UA in resposne to the DISC */
6887 }
6888 }
6889
6890 /* release the channel */
6891 f_rsl_chan_deact();
6892 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6893 f_rslem_unregister(0, g_chan_nr);
6894}
6895testcase TC_rll_rel_req() runs on test_CT {
6896 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006897 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6898 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6899 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6900 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006901 };
6902 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6903}
6904
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006905/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006906testcase TC_rll_data_req() runs on test_CT {
6907}
6908
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006909/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006910testcase TC_rll_data_ind() runs on test_CT {
6911}
6912
6913/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6914private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6915 var RllTestCase tc := g_pars.spec.rll;
6916
6917 f_l1_tune(L1CTL);
6918 RSL.clear;
6919
6920 f_est_dchan();
6921 L1CTL.clear;
6922
6923 /* Send UNITDATA REQ on RSL side */
6924 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6925 /* Expect it to arrive on the other side */
6926 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006927 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006928 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006929 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006930 }
6931
6932 /* release the channel */
6933 f_rsl_chan_deact();
6934 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6935 f_rslem_unregister(0, g_chan_nr);
6936}
6937testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6938 var octetstring l3 := f_rnd_octstring(15);
6939 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006940 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6941 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006942 };
6943 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6944}
6945testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6946 var octetstring l3 := f_rnd_octstring(19);
6947 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006948 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6949 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006950 };
6951 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6952}
6953
6954/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6955private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6956 var RllTestCase tc := g_pars.spec.rll;
6957
6958 f_l1_tune(L1CTL);
6959 RSL.clear;
6960
6961 f_est_dchan();
6962 L1CTL.clear;
6963
6964 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006965 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006966 /* Expdct RLL UNITDATA IND on RSL side */
6967 alt {
6968 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6969 setverdict(pass);
6970 }
6971 [] RSL.receive { repeat; }
6972 }
6973
6974 /* release the channel */
6975 f_rsl_chan_deact();
6976 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6977 f_rslem_unregister(0, g_chan_nr);
6978}
6979testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006980 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006981 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006982 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6983 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006984 };
6985 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6986}
6987testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6988 var octetstring l3 := f_rnd_octstring(18);
6989 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006990 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6991 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006992 };
6993 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6994}
6995
Harald Weltee613f962018-04-18 22:38:16 +02006996/***********************************************************************
6997 * Encryption Related
6998 ***********************************************************************/
6999
7000/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007001private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007002 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7003 if (link_id.c == SACCH) {
7004 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7005 } else {
7006 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7007 }
7008}
7009
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007010/* Expect (or not expect) other kinds of messages */
7011private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7012 [exp_any] RSL.receive { repeat; }
7013 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007015 }
7016}
7017
Harald Weltee613f962018-04-18 22:38:16 +02007018/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007019private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007020 RslLinkId link_id,
7021 octetstring l3,
7022 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007023 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007024) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007025 timer T := 3.0;
7026 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7027 T.start;
7028 /* Expect RLL UNITDATA IND on RSL side */
7029 alt {
7030 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7031 setverdict(pass);
7032 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007033 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007034 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007035 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007037 }
Harald Weltee613f962018-04-18 22:38:16 +02007038 }
7039}
7040
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007041/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7042private function f_data_mo(
7043 RslLinkId link_id,
7044 boolean p, uint3_t nr, uint3_t ns,
7045 octetstring l3,
7046 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007047 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007048) runs on ConnHdlr {
7049 timer T := 3.0;
7050 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7051 T.start;
7052 /* Expect RLL DATA IND on RSL side */
7053 alt {
7054 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7055 setverdict(pass);
7056 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007057 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007058 [] as_rsl_any_ind(exp_any);
7059 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007061 }
7062 }
7063}
7064
Harald Weltee613f962018-04-18 22:38:16 +02007065/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007066private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007067 f_l1_tune(L1CTL);
7068 f_est_dchan(true);
7069
7070 /* now we actually need to transmit some data both ways to check if the encryption works */
7071 var L1ctlDlMessage dl;
7072
Stefan Sperling603d98e2018-07-25 16:47:28 +02007073 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007074 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7075
7076 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7077 f_unitdata_mt(link_id, l3);
7078
7079 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7080 f_unitdata_mo(link_id, l3);
7081
7082 /* release the channel */
7083 f_rsl_chan_deact();
7084 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7085 f_rslem_unregister(0, g_chan_nr);
7086}
7087testcase TC_chan_act_a51() runs on test_CT {
7088 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7089 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7090 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7091}
7092testcase TC_chan_act_a52() runs on test_CT {
7093 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7094 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7095 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7096}
7097testcase TC_chan_act_a53() runs on test_CT {
7098 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7099 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7100 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7101}
Eric Wildb9260392021-05-15 19:48:22 +02007102testcase TC_chan_act_a54() runs on test_CT {
7103 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7104 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7105 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7106}
Harald Weltee613f962018-04-18 22:38:16 +02007107
Eric Wildf1827a72019-05-28 17:37:35 +02007108/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7109 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 +07007110private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007111 f_l1_tune(L1CTL);
7112 f_est_dchan(true);
7113
7114 /* now we actually need to transmit some data both ways to check if the encryption works */
7115 var L1ctlDlMessage dl;
7116
7117 var octetstring l3 := f_rnd_octstring(20);
7118 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7119
7120 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7121 f_unitdata_mt(link_id, l3);
7122
7123 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7124 f_unitdata_mo(link_id, l3);
7125
7126 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007127 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007128
7129 /* modify key to break proper encryption */
7130 g_pars.encr.key := f_rnd_octstring(8);
7131 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7132 rsl.ies := rsl.ies & { ei };
7133 RSL.send(rsl);
7134
7135 timer T0 := 1.0;
7136 T0.start;
7137 /* Expect RSL MODIFY ACK */
7138 alt {
7139 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7140 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7142 }
7143 [] T0.timeout {
7144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7145 }
7146 }
7147
7148 var octetstring l3msg := f_rnd_octstring(15);
7149 timer T1 := 3.0;
7150 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7151 due to broken encryption */
7152 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7153 T1.start;
7154 alt {
7155 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7157 }
7158 [] T1.timeout {
7159 setverdict(pass);
7160 }
7161 }
7162
7163 /* release the channel */
7164 f_rsl_chan_deact();
7165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7166 f_rslem_unregister(0, g_chan_nr);
7167}
7168testcase TC_rsl_modify_encr() runs on test_CT {
7169 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7170 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7171 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7172}
Harald Weltee613f962018-04-18 22:38:16 +02007173
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007174/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7175private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7176runs on test_CT {
7177 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7178 var ASP_RSL_Unitdata ud;
7179 timer T;
7180
7181 /* Intave is 6 SACCH periods by default */
7182 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7183
7184 T.start(Tval);
7185 alt {
7186 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7187 setverdict(pass);
7188 }
7189 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7190 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7191 }
7192 [] RSL_CCHAN.receive { repeat; }
7193 [] T.timeout {
7194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7195 "Timeout waiting for RF RESource INDication");
7196 }
7197 }
7198}
7199testcase TC_rsl_rf_resource_ind() runs on test_CT {
7200 var RSL_ResourceInfo info := { };
7201
7202 f_init(trx_nr := 0);
7203
7204 f_init_l1ctl();
7205 f_l1_tune(L1CTL);
7206
7207 /* g_AllChannels contains all logical channels */
7208 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7209 var RslChannelNr chan_nr := g_AllChannels[i];
7210
7211 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7212 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7213 { continue; }
7214
7215 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7216 }
7217
7218 /* Align to the first interference report */
7219 f_TC_rsl_rf_resource_ind(?);
7220
7221 /* Test 4 consecutive messages */
7222 for (var integer i := 0; i < 4; i := i + 1) {
7223 f_TC_rsl_rf_resource_ind(info);
7224 }
7225
7226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7227}
7228
Harald Weltee613f962018-04-18 22:38:16 +02007229/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007230private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007231 /* L3 payload doesn't matter, as it is passed transparently */
7232 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7233 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7234 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7235
7236 f_l1_tune(L1CTL);
7237
7238 /* first establish a dedicated channel in the clear */
7239 f_est_dchan(false);
7240
7241 /* Establish ABM */
7242 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7243
7244 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7245 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7246 /* expect the L3 to arrive still unencrypted on the MS side */
7247 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7248
7249 /* configure L1 to apply ciphering */
7250 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7251 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7252
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007253 /* send first ciphered I-frame in response and expect it on RSL */
7254 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007255
7256 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7257 * and hence enable encryption also on the downlink */
7258
7259 /* expect bi-directional communication work in encrypted mode */
7260 f_unitdata_mo(link_id, f_rnd_octstring(15));
7261 f_unitdata_mt(link_id, f_rnd_octstring(15));
7262
7263 /* release the channel */
7264 f_rsl_chan_deact();
7265 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7266 f_rslem_unregister(0, g_chan_nr);
7267}
7268testcase TC_encr_cmd_a51() runs on test_CT {
7269 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7270 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7271 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7272}
7273testcase TC_encr_cmd_a52() runs on test_CT {
7274 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7275 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7276 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7277}
7278testcase TC_encr_cmd_a53() runs on test_CT {
7279 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7280 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7281 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7282}
Eric Wildb9260392021-05-15 19:48:22 +02007283testcase TC_encr_cmd_a54() runs on test_CT {
7284 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7285 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7286 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7287}
Harald Weltee613f962018-04-18 22:38:16 +02007288
7289private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7290 var LapdmFrame lf;
7291 var octetstring reenc;
7292
7293 /* decode the LAPDm frame */
7294 if (ischosen(exp_match.ab)) {
7295 lf.ab := dec_LapdmFrameAB(enc);
7296 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007298 }
7299
7300 /* check if decoder result matches expectation */
7301 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007303 } else {
7304 log(name, ": matched");
7305 setverdict(pass);
7306 }
7307
7308 /* test if re-encoded frame equals original input */
7309 reenc := enc_LapdmFrame(lf);
7310 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007312 } else {
7313 setverdict(pass);
7314 }
7315}
7316
7317testcase TC_lapdm_selftest() runs on test_CT {
7318 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7319 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7320 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7321 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7322 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7323 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7324 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7325}
7326
Stefan Sperling4880be42018-08-07 18:12:59 +02007327/***********************************************************************
7328 * DTX Related (see GSM 05.08, section 8.3)
7329 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007330private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007331 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007332 var GsmFrameNumber first_fn;
7333 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007334 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007335 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007336 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7337 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007338 const integer frame_dtx_tchf_mod := 104;
7339 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7340 * which operates in terms of blocks rather than frames. */
7341 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7342 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007343 timer T := 5.0;
7344
7345 f_l1_tune(L1CTL);
7346 RSL.clear;
7347 L1CTL.clear;
7348
7349 /* activate TCHF signalling channel */
7350 f_est_dchan(false);
7351
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007352 /* A template for matching dummy LAPDm func=UA frames */
7353 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7354 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7355 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7356
Stefan Sperling4880be42018-08-07 18:12:59 +02007357 T.start;
7358 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007359 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007360 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007361
7362 if (is_first_frame) {
7363 is_first_frame := false;
7364 first_fn := dl.dl_info.frame_nr;
7365 }
7366
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007367 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007368 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007369 T.stop;
7370 f_rsl_chan_deact();
7371 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007372
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007373 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7374 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007375
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007376 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007377 setverdict(fail, "Not enough fill frames received: ",
7378 nfill_frames, " out of ", expected_fill_frames);
7379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007380 } else {
7381 setverdict(pass);
7382 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007383 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007384 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7385 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7386 * we should only see the subset of frames numbers which correspond to a block boundary.
7387 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7388 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7389 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007390 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007391 repeat;
7392 }
7393 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007394 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7395 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7396 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007397 f_rsl_chan_deact();
7398 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007399 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007400 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007401 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007402 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007403 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007404
7405 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007406 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7407 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007408 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7409 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7410 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007411 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7412 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007413 case else {
7414 /* This shall not happen, just to be sure */
7415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7416 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007417 }
7418
7419 f_rsl_chan_deact();
7420 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007421
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007422 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007423 setverdict(pass);
7424 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007425 setverdict(fail, "Not enough fill frames received: ",
7426 nfill_frames, " out of ", expected_fill_frames);
7427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007428 }
7429 } else {
7430 repeat;
7431 }
7432 }
7433 }
7434 [] L1CTL.receive { repeat; }
7435 [] T.timeout {
7436 f_rsl_chan_deact();
7437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007439 }
7440 }
7441}
7442
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007443private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007444 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007445 var ConnHdlr vc_conn;
7446 var ConnHdlrPars pars;
7447 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007448 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007449 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007450 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007451 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007452 if (dtxd) {
7453 if (i >= 4) { /* DTX is only allowed on TCH/F */
7454 break;
7455 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007456 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007457 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007458 vc_conn.done;
7459 }
7460}
7461
7462/* Verify that L2 fill frames are sent on TCH in signaling mode if
7463 * there is nothing to transmit while DTX is disabled on downlink. */
7464testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7465 f_tch_sign_l2_fill_frame(false);
7466}
7467
7468/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7469 * there is nothing to transmit while DTX is enabled on downlink. */
7470testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7471 f_tch_sign_l2_fill_frame(true);
7472}
Harald Welte0472ab42018-03-12 15:02:26 +01007473
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007474testcase TC_chopped_ipa_ping() runs on test_CT {
7475 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7476}
7477
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007478testcase TC_chopped_ipa_payload() runs on test_CT {
7479 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7480}
7481
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007482
7483/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7484 * Return value: Measurement Report to be sent (encoded octetstring). */
7485type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7486 runs on ConnHdlr return octetstring;
7487
7488private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7489runs on ConnHdlr {
7490 var L1ctlDlMessage l1_dl;
7491 var SacchL1Header l1h;
7492 var octetstring l2;
7493
7494 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7495 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7496 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7497 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7498
7499 /* Pass it to the user specified call-back function */
7500 l2 := cb.apply(l1h, num_blocks);
7501 /* Send a Measurement Report generated by the call-back */
7502 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7503 l1_dl.dl_info.link_id,
7504 l1h, l2));
7505
7506 /* Shall we keep going? */
7507 num_blocks := num_blocks - 1;
7508 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7509 if (num_blocks > 0) { repeat; }
7510 }
7511 [] L1CTL.receive { repeat; }
7512}
7513
7514private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7515runs on ConnHdlr return octetstring {
7516 /* Command the L1 to apply received parameters */
7517 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7518
7519 /* Dummy measurement report (the results are invalid) */
7520 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7521}
7522
7523private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7524runs on ConnHdlr return octetstring {
7525 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7526 setverdict(fail, "Unexpected MS Power level change: ",
7527 g_pars.l1_pars.ms_power_level, " -> ",
7528 l1h.ms_power_lvl);
7529 }
7530
7531 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7532}
7533
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007534private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7535runs on ConnHdlr return octetstring {
7536 /* UL RSSI oscillation driven by SACCH block number */
7537 if (num_blocks rem 2 == 0) {
7538 f_trxc_fake_rssi(-100);
7539 } else {
7540 f_trxc_fake_rssi(-50);
7541 }
7542
7543 /* Make sure that MS power level remains constant */
7544 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7545}
7546
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007547/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7548private function f_TC_ms_pwr_ctrl_constant(charstring id)
7549runs on ConnHdlr {
7550 var integer num_blocks := 8;
7551 timer T := int2float(num_blocks);
7552
7553 f_l1_tune(L1CTL);
7554 RSL.clear;
7555
7556 /* These IEs are needed for autonomous MS power control */
7557 var template (value) RSL_IE_List ies := {
7558 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7559 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7560 }),
7561 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7562 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7563 })
7564 };
7565
7566 /* Ensure that 'rx-current' equals 'rx-target' */
7567 f_trxc_fake_rssi(mp_uplink_power_target);
7568
7569 /* Establish a dedicated channel */
7570 f_est_dchan(more_ies := valueof(ies));
7571
7572 L1CTL.clear;
7573 T.start;
7574 alt {
7575 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7576 [] T.timeout {
7577 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7578 num_blocks, " were not handled");
7579 }
7580 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007581
7582 /* Release the channel */
7583 f_rsl_chan_deact();
7584 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007585}
7586testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7587 var ConnHdlr vc_conn;
7588 var ConnHdlrPars pars;
7589
7590 f_init();
7591
7592 /* Explicitly configure the Uplink power target (in dBm) */
7593 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7594
7595 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7596 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7597 log(testcasename(), ": starting on ", pars.chan_nr);
7598
7599 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7600 pars, trxc_comp := true);
7601 vc_conn.done;
7602 }
7603
7604 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7606}
7607
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007608/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7609private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7610runs on ConnHdlr {
7611 var integer num_blocks := 16;
7612 timer T := int2float(num_blocks);
7613
7614 f_l1_tune(L1CTL);
7615 RSL.clear;
7616
7617 /* These IEs are needed for autonomous MS power control */
7618 var template (value) RSL_IE_List ies := {
7619 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7620 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7621 }),
7622 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7623 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7624 })
7625 };
7626
7627 /* Ensure that 'rx-current' equals 'rx-target' */
7628 f_trxc_fake_rssi(mp_uplink_power_target);
7629
7630 /* Establish a dedicated channel */
7631 f_est_dchan(more_ies := valueof(ies));
7632
7633 L1CTL.clear;
7634 T.start;
7635 alt {
7636 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7637 [] T.timeout {
7638 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7639 num_blocks, " were not handled");
7640 }
7641 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007642
7643 /* Release the channel */
7644 f_rsl_chan_deact();
7645 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007646}
7647testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7648 var ConnHdlr vc_conn;
7649 var ConnHdlrPars pars;
7650
7651 f_init();
7652
7653 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7654 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7655 /* Explicitly configure the Uplink power range (target and delte) */
7656 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7657 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7658
7659 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7660 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7661 log(testcasename(), ": starting on ", pars.chan_nr);
7662
7663 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7664 pars, trxc_comp := true);
7665 vc_conn.done;
7666 }
7667
7668 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7670}
7671
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007672private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7673 var template L1ctlDlMessage tr_bad_frame;
7674 var L1ctlDlMessage l1_dl;
7675 timer T := 8.0;
7676
7677 f_l1_tune(L1CTL);
7678 RSL.clear;
7679
7680 f_est_dchan();
7681
7682 /* There may be a few errors right after the channel activation */
7683 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7684 L1CTL.clear;
7685
7686 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7687 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7688 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7689 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7690 tr_bad_frame.payload := ?;
7691
7692 T.start;
7693 alt {
7694 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7695 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7696 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7697 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7698 }
7699 [] as_l1_sacch();
7700 [] L1CTL.receive { repeat; }
7701 [] T.timeout {
7702 /* We're done, break the loop */
7703 setverdict(pass);
7704 }
7705 }
7706
7707 f_rsl_chan_deact();
7708 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7709}
7710testcase TC_speech_no_rtp_tchf() runs on test_CT {
7711 var ConnHdlr vc_conn;
7712 var ConnHdlrPars pars;
7713
7714 f_init();
7715
7716 /* TS1, TCH/F, V1 (FR codec) */
7717 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7718 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7719 vc_conn.done;
7720}
7721testcase TC_speech_no_rtp_tchh() runs on test_CT {
7722 var ConnHdlr vc_conn;
7723 var ConnHdlrPars pars;
7724
7725 f_init();
7726
7727 /* TS5, TCH/H, V1 (HR codec) */
7728 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7729 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7730 vc_conn.done;
7731}
7732
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007733/* Verify handling of Downlink and Uplink speech frames */
7734private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7735 var L1ctlDlMessage l1_dl;
7736 var PDU_RTP rtp_pdu;
7737 var octetstring pl;
7738 timer Td, Tu;
7739
7740 f_l1_tune(L1CTL);
7741 f_est_dchan();
7742
7743 /* Activate the RTP emulation */
7744 pl := f_rnd_octstring(6);
7745 f_rtpem_activate(pl);
7746
7747 /* Give the scheduler some time to fill up the buffers */
7748 f_sleep(2.0);
7749 L1CTL.clear;
7750 RSL.clear;
7751
7752 /* Make sure that Downlink frames are received at the UE */
7753 Td.start(2.0);
7754 alt {
7755 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7756 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7757 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7758 l1_dl.payload.traffic_ind.data));
7759 setverdict(pass);
7760 }
7761 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7762 setverdict(fail, "Rx unexpected Downlink speech frame ",
7763 "(", l1_dl.payload.traffic_ind.data, ") ",
7764 "expected (", pl, ")");
7765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7766 }
7767 [] as_l1_sacch();
7768 [] L1CTL.receive { repeat; }
7769 [] Td.timeout {
7770 setverdict(fail, "Timeout waiting for Downlink speech frames");
7771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7772 }
7773 }
7774
7775 /* Make sure that Uplink frames are received at the BTS */
7776 RTPEM_DATA.clear;
7777 Tu.start(2.0);
7778 alt {
7779 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7780 if (rtp_pdu.data != pl)
7781 { repeat; }
7782 }
7783 [] RTPEM_DATA.receive { repeat; }
7784 [] Tu.timeout {
7785 setverdict(fail, "Timeout waiting for Uplink speech frames");
7786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7787 }
7788 }
7789
7790 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7791 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7792 f_rsl_chan_deact();
7793 f_rslem_unregister(0, g_chan_nr);
7794}
7795testcase TC_speech_rtp_tchf() runs on test_CT {
7796 var ConnHdlr vc_conn;
7797 var ConnHdlrPars pars;
7798
7799 f_init();
7800
7801 /* TS1, TCH/F, V1 (FR codec) */
7802 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7803 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7804 vc_conn.done;
7805
7806 /* TS1, TCH/F, V2 (EFR codec) */
7807 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7808 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7809 vc_conn.done;
7810
7811 /* TODO: also test V3 (AMR codec) */
7812
7813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7814}
7815testcase TC_speech_rtp_tchh() runs on test_CT {
7816 var ConnHdlr vc_conn;
7817 var ConnHdlrPars pars;
7818
7819 f_init();
7820
7821 /* TS5, TCH/H0, V1 (HR codec) */
7822 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7823 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7824 vc_conn.done;
7825
7826 /* TODO: also test V3 (AMR codec) */
7827
7828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7829}
7830
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007831private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7832 var GsmFrameNumber fn;
7833 var ChannelDescription ch_desc;
7834 var integer ra := 23;
7835
7836 f_l1_tune(L1CTL);
7837 RSL.clear;
7838
7839 /* Send RACH request and wait for ChanReq */
7840 fn := f_rach_req_wait_chan_rqd(ra);
7841
7842 /* The BSC already sends the Immediate Assignment, before the channel is active.
7843 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7844 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7845 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7846 if (g_pars.fhp.enabled) {
7847 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7848 } else {
7849 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7850 }
7851 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7852 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7853
7854 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7855 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7856 var L1ctlDlMessage dl;
7857 var GsmRrMessage rr;
7858
7859 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7860 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7861 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7862 rr_imm_ass.payload.imm_ass.chan_desc := *;
7863
7864 timer T := 1.0;
7865 T.start;
7866 alt {
7867 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7868 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7869 if (match(rr, rr_imm_ass)) {
7870 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7871 mtc.stop;
7872 } else {
7873 repeat;
7874 }
7875 }
7876 [] L1CTL.receive { repeat; }
7877 [] T.timeout;
7878 }
7879 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7880 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7881
7882 /* Now expect the IMM ASS on Um */
7883 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7884 setverdict(pass);
7885
7886 /* Release the channel */
7887 f_rsl_chan_deact();
7888 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7889}
7890
7891testcase TC_early_immediate_assignment() runs on test_CT {
7892 var ConnHdlr vc_conn;
7893 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7894 f_init();
7895 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
7896 vc_conn.done;
7897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7898}
7899
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007900private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
7901 var integer ra := oct2int(f_rnd_ra_cs());
7902 var ChannelDescription ch_desc;
7903
7904 /* Tune the MS to BCCH */
7905 f_l1_tune(L1CTL);
7906
7907 /* Send RACH request and wait for ChanReq */
7908 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
7909
7910 /* Activate channel on the BTS side */
7911 f_rsl_chan_act(g_pars.chan_mode);
7912
7913 /* Craft channel description (with or without frequency hopping parameters) */
7914 if (g_pars.fhp.enabled) {
7915 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7916 } else {
7917 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7918 }
7919
7920 /* Send IMM.ASS via CCHAN */
7921 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7922 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7923
7924 /* Receive IMM.ASS on the MS side */
7925 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7926
7927 /* Match the Channel Description IE in received IMM.ASS */
7928 if (not match(imm_ass.chan_desc, ch_desc)) {
7929 setverdict(fail, "Channel Description IE does not match");
7930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7931 }
7932
7933 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
7934 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
7935
7936 /* Expect SACCH frames on Downlink */
7937 L1CTL.clear;
7938 f_exp_sacch(true);
7939
7940 /* We're done, deactivate and release */
7941 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7942 f_rsl_chan_deact();
7943}
7944testcase TC_est_dchan() runs on test_CT {
7945 var ConnHdlr vc_conn;
7946 var ConnHdlrPars pars;
7947
7948 f_init();
7949
7950 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
7951 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
7952 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
7953 vc_conn.done;
7954 }
7955
7956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7957}
7958
Harald Welte0472ab42018-03-12 15:02:26 +01007959/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7960/* protocol error as per 44.006 */
7961/* link layer failure (repetition of I-frame N200 times without ACK */
7962/* repetition of SABM or DISC N200 times without ACK */
7963/* receptiom of SABM in multi-frame established state */
7964
7965
Harald Welte68e495b2018-02-25 00:05:57 +01007966/* TODO Areas:
7967
7968* channel activation
7969** with BS_Power / MS_Power, bypassing power control loop
7970** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007971** with timing advance from initial activation on
7972* mode modify
7973** encryption
7974** multirate
7975* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007976** unsupported algorithm
7977* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007978* BS Power Control
7979* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007980* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007981* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007982** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007983* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007984** DATA_IND from BTS->PCU
7985** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007986
7987*/
Harald Welte70767382018-02-21 12:16:40 +01007988
7989control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007990 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01007991 execute( TC_chan_act_stress() );
7992 execute( TC_chan_act_react() );
7993 execute( TC_chan_deact_not_active() );
7994 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007995 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007996 execute( TC_sacch_filling() );
7997 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007998 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007999 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008000 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008001 execute( TC_sacch_chan_act_ho_async() );
8002 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008003 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008004 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008005 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008006 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008007 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008008 execute( TC_rach_load_idle_thresh0() );
8009 execute( TC_rach_load_idle_below_thresh() );
8010 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008011 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008012 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008013 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008014 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008015 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008016 execute( TC_meas_res_sign_tchf() );
8017 execute( TC_meas_res_sign_tchh() );
8018 execute( TC_meas_res_sign_sdcch4() );
8019 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008020 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008021 execute( TC_meas_res_speech_tchf_sapi3() );
8022 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008023 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008024 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008025 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008026 execute( TC_rsl_bs_pwr_static_ass() );
8027 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008028 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008029 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008030 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008031 execute( TC_rsl_ms_pwr_dyn_up() );
8032 execute( TC_rsl_ms_pwr_dyn_down() );
8033 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8034 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008035 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008036 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008037 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008038 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008039 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008040 execute( TC_paging_imsi_80percent() );
8041 execute( TC_paging_tmsi_80percent() );
8042 execute( TC_paging_imsi_200percent() );
8043 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008044 execute( TC_rsl_protocol_error() );
8045 execute( TC_rsl_mand_ie_error() );
8046 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008047 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008048 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008049 execute( TC_si_sched_2bis() );
8050 execute( TC_si_sched_2ter() );
8051 execute( TC_si_sched_2ter_2bis() );
8052 execute( TC_si_sched_2quater() );
8053 execute( TC_si_sched_13() );
8054 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008055 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008056 execute( TC_ipa_crcx_twice_not_active() );
8057 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008058 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008059 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008060
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008061 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008062 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008063 execute( TC_pcu_act_req() );
8064 execute( TC_pcu_act_req_wrong_ts() );
8065 execute( TC_pcu_act_req_wrong_bts() );
8066 execute( TC_pcu_act_req_wrong_trx() );
8067 execute( TC_pcu_deact_req() );
8068 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008069 execute( TC_pcu_ver_si1() );
8070 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008071 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008072 if (mp_l1_supports_gprs) {
8073 execute( TC_pcu_data_req_pdtch() );
8074 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008075 execute( TC_pcu_data_req_wrong_bts() );
8076 execute( TC_pcu_data_req_wrong_trx() );
8077 execute( TC_pcu_data_req_wrong_ts() );
8078 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008079 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008080 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008081 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008082 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008083 execute( TC_pcu_data_req_imm_ass_pch() );
8084 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008085 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008086 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008087 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008088 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008089 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008090 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008091 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008092 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008093 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008094 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008095 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008096 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008097 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008098 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008099 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008100 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008101 execute( TC_dyn_osmo_pdch_act_deact() );
8102 execute( TC_dyn_osmo_pdch_double_act() );
8103 execute( TC_dyn_ipa_pdch_act_deact() );
8104 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008105 execute( TC_pcu_info_ind_fh_params() );
8106 execute( TC_pcu_socket_nsvc_ipv4() );
8107 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008108 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008109 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008110 } else {
8111 log("PCU socket path not available, skipping PCU tests");
8112 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008113
Harald Welte3d04ae62018-04-04 20:29:05 +02008114 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008115 execute( TC_dyn_osmo_pdch_tchf_act() );
8116 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008117 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008118 execute( TC_dyn_ipa_pdch_tchf_act() );
8119 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008120
8121 execute( TC_rll_est_ind() );
8122 execute( TC_rll_est_req_DCCH_3() );
8123 execute( TC_rll_est_req_ACCH_3() );
8124 execute( TC_rll_rel_ind_DCCH_0() );
8125 execute( TC_rll_rel_ind_DCCH_3() );
8126 execute( TC_rll_rel_ind_ACCH_0() );
8127 execute( TC_rll_rel_ind_ACCH_3() );
8128 execute( TC_rll_rel_req() );
8129 execute( TC_rll_unit_data_req_DCCH() );
8130 execute( TC_rll_unit_data_req_ACCH() );
8131 execute( TC_rll_unit_data_ind_DCCH() );
8132 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008133
8134 execute( TC_chan_act_a51() );
8135 execute( TC_chan_act_a52() );
8136 execute( TC_chan_act_a53() );
8137 execute( TC_encr_cmd_a51() );
8138 execute( TC_encr_cmd_a52() );
8139 execute( TC_encr_cmd_a53() );
8140
Harald Welteee25aae2019-05-19 14:32:37 +02008141 execute( TC_err_rep_wrong_mdisc() );
8142 execute( TC_err_rep_wrong_msg_type() );
8143 execute( TC_err_rep_wrong_sequence() );
8144
Harald Weltee613f962018-04-18 22:38:16 +02008145 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008146
8147 execute( TC_tch_sign_l2_fill_frame() );
8148 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008149
8150 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008151 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008152
8153 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008154 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008155
8156 execute( TC_speech_no_rtp_tchf() );
8157 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008158 execute( TC_speech_rtp_tchf() );
8159 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008160
8161 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008162
8163 /* BEWARE: these test cases can potentially break the IUT or cause
8164 * weird/unexpected behavior. Ensure that they are executed last. */
8165 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8166 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008167}
8168
8169
8170}