blob: 8300f8e0087f9359037a1b0a533f576b1bc736b6 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Harald Welte70767382018-02-21 12:16:40 +0100138}
139
Harald Welte629cc6b2018-03-11 17:19:05 +0100140type record of RslChannelNr ChannelNrs;
141
Harald Welte70767382018-02-21 12:16:40 +0100142type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100143 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100144 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100145 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100146 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100148 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100149
150 /* L1CTL port (for classic tests) */
151 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100152
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700153 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700154 port TRXC_CODEC_PT BTS_TRXC;
155 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100156
Harald Weltef50e3ae2018-09-10 10:27:56 +0200157 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100158 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200159 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100160
Harald Welte883340c2018-02-28 18:59:29 +0100161 /* PCU Interface of BTS */
162 port PCUIF_CODEC_PT PCU;
163 var integer g_pcu_conn_id;
164 /* Last PCU INFO IND we received */
165 var PCUIF_Message g_pcu_last_info;
166
Harald Welte48494ca2018-02-25 16:59:50 +0100167 /* SI configuration */
168 var SystemInformationConfig si_cfg := {
169 bcch_extended := false,
170 si1_present := false,
171 si2bis_present := false,
172 si2ter_present := false,
173 si2quater_present := false,
174 si7_present := false,
175 si8_present := false,
176 si9_present := false,
177 si13_present := false,
178 si13alt_present := false,
179 si15_present := false,
180 si16_present := false,
181 si17_present := false,
182 si2n_present := false,
183 si21_present := false,
184 si22_present := false
185 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100186
187 /* all logical channels available on the BTS */
188 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100189 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100190}
191
192/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200193type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100194 port L1CTL_PT L1CTL;
195
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700196 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700197 port TRXC_CODEC_PT BTS_TRXC;
198 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100199
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200200 /* port to be initialized optionally to access BSC VTY */
201 port TELNETasp_PT BSCVTY;
202
Harald Welte70767382018-02-21 12:16:40 +0100203 timer g_Tguard;
204 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
205
206 var ConnHdlrPars g_pars;
207 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100208 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200209
210 /* PCU Interface of BTS */
211 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200212
213 var RTP_Emulation_CT vc_RTPEM;
214 port RTPEM_CTRL_PT RTPEM_CTRL;
215 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100216}
217
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700218private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200220 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200222 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 timer T;
226
Harald Welte70767382018-02-21 12:16:40 +0100227 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
228 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
229
230 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
231 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
232 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
233
234 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
235 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700236
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700237 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700238 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700239 T.start(mp_ipa_up_timeout);
240 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700241 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700242 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
243 /* Make sure that all transceivers use unique stream ID */
244 if (trx_mask[enum2int(ev.sid)] == '1'B) {
245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
246 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
247 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700248
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 trx_mask[enum2int(ev.sid)] := '1'B;
250 trx_count := trx_count + 1;
251
252 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200253 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700254 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200255 /* This message (RF RESource INDication) is sent by the IUT itself */
256 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
257 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
259 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
260 }
261 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
264 }
265
266 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
267 rfind_count := rfind_count + 1;
268 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
269 if (rfind_count < mp_transceiver_num) { repeat; }
270 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700271 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
272 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
273 [] T.timeout {
274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
275 "Timeout waiting for RSL bring up");
276 }
277 }
Harald Welte70767382018-02-21 12:16:40 +0100278}
279
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700280friend type record length(1 .. 256) of TrxParsItem TrxPars;
281friend type record TrxParsItem {
282 GsmArfcn arfcn,
283 TrxTsPars ts
284};
285
286friend type record length(8) of TrxTsParsItem TrxTsPars;
287friend type record TrxTsParsItem {
288 PchanConfig config
289};
290
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700291friend type record FreqHopPars {
292 /* Whether frequency hopping is in use */
293 boolean enabled,
294 /* Mobile Allocation Index Offset / Hopping Sequence Number */
295 MaioHsn maio_hsn,
296 /* MA bitmap to be indicated in RR Immediate Assignment */
297 MobileAllocationLV ma_map,
298 /* The actual Mobile Allocation (ARFCN list) to be used */
299 L1ctlMA ma
300};
301
Harald Welte70767382018-02-21 12:16:40 +0100302type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700303 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100304 RslChannelNr chan_nr,
305 RSL_IE_ChannelMode chan_mode,
306 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100307 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200308 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200309 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700310 BtsBand bts0_band optional,
311
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700312 /* Training Sequence Code */
313 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700314 /* Frequency hopping parameters */
315 FreqHopPars fhp
316};
Harald Welte0472ab42018-03-12 15:02:26 +0100317
318/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200319friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300320 RllTestCase rll,
321 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100322}
323
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700324private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100325 max_retrans := RACH_MAX_RETRANS_7,
326 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100327 cell_barr_access := false,
328 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100329 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100330};
331
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700332private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100333 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200334 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 acs := '0'B,
336 neci := true,
337 rxlev_access_min := 0
338}
339
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700340private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100341 mcc_mnc := '262F42'H,
342 lac := 42
343}
344
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700345private template (value) GPRSIndicator ts_GPRSIndicator_def := {
346 ra_colour := 0,
347 si13_pos := '0'B
348}
349
350private template (value) SI3RestOctets ts_SI3RestOctets_def
351modifies ts_SI3RestOctets := {
352 gprs_ind := {
353 presence := CSN1_H,
354 ind := ts_GPRSIndicator_def
355 }
356}
357
358private template (value) SI4RestOctets ts_SI4RestOctets_def
359modifies ts_SI4RestOctets := {
360 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700361 presence := CSN1_H,
362 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700363 }
364}
365
Harald Welte7484fc42018-02-24 14:09:45 +0100366/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700367private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100368 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100369 payload := {
370 si3 := {
371 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100372 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100373 ctrl_chan_desc := {
374 msc_r99 := true,
375 att := true,
376 bs_ag_blks_res := 1,
377 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100378 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100379 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
380 spare := '00'B,
381 bs_pa_mfrms := 0, /* 2 multiframes */
382 t3212 := 1 /* 6 minutes */
383 },
Harald Welte82ccef72018-02-25 16:17:33 +0100384 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100385 dn_ind := false,
386 pwrc := false,
387 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100388 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100389 },
Harald Weltef10153f2018-02-25 16:34:05 +0100390 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100391 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200392 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100393 }
394 }
395}
Harald Welte70767382018-02-21 12:16:40 +0100396
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700397private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100398 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100399 payload := {
400 si2 := {
401 bcch_freq_list := '00000000000000000000000000000000'O,
402 ncc_permitted := '11111111'B,
403 rach_control := ts_RachCtrl_default
404 }
405 }
406}
407
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700408private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100409 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100410 payload := {
411 si4 := {
412 lai := ts_LAI_default,
413 cell_sel_par := ts_CellSelPar_default,
414 rach_control := ts_RachCtrl_default,
415 cbch_chan_desc := omit,
416 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200417 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100418 }
419 }
420}
421
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700422private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100423runs on test_CT {
424 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700425 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100426}
427
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700428private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100429runs on test_CT {
430 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
431 log("Setting ", rsl_si_type, ": ", si_dec);
432 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
433}
434
Harald Welte505cf9b2018-09-15 17:47:23 +0300435friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100436 map(self:BTSVTY, system:BTSVTY);
437 f_vty_set_prompts(BTSVTY);
438 f_vty_transceive(BTSVTY, "enable");
439}
440
Harald Welte505cf9b2018-09-15 17:47:23 +0300441friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200442 map(self:BSCVTY, system:BSCVTY);
443 f_vty_set_prompts(BSCVTY, "OsmoBSC");
444 f_vty_transceive(BSCVTY, "enable");
445}
446
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200447friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
448 map(self:BSCVTY, system:BSCVTY);
449 f_vty_set_prompts(BSCVTY, "OsmoBSC");
450 f_vty_transceive(BSCVTY, "enable");
451}
452
Harald Welte883340c2018-02-28 18:59:29 +0100453/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200454friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100456 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200457 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
458 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100459 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100462 }
463}
464
Harald Weltef26de0b2018-04-04 20:28:05 +0200465private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
466 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100467 timer T := 2.0;
468 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100469 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200470 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100471 return;
472 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200473 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100474
475 T.start;
476 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100478 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100480 }
481 }
482}
483
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700484private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
485 out integer trxc_conn_id) {
486 var Result res;
487
488 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
489 "", -1, -1, { udp := {} }, {});
490 if (not ispresent(res.connId)) {
491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
492 "Could not connect to the control (TRXC) interface " &
493 "of FakeTRX, check your configuration");
494 }
495 trxc_conn_id := res.connId;
496}
497
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100498/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700499friend function f_init(uint8_t trx_nr := 0)
500runs on test_CT
501{
502 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200503 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100504
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700505 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
506 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700507 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200508 g_AllChanTypes := {
509 /* TS 1..4: TCH/F */
510 valueof(ts_RslChanNr_Bm(1)),
511 /* TS 5: TCH/H */
512 valueof(ts_RslChanNr_Lm(5,1)),
513 /* TS 0: SDCCH/4 */
514 valueof(ts_RslChanNr_SDCCH4(0,2)),
515 /* TS 6: SDCCH/8 */
516 valueof(ts_RslChanNr_SDCCH8(6,4))
517 };
518 } else {
519 g_AllChanTypes := {
520 /* TS 1..4: TCH/F */
521 valueof(ts_RslChanNr_Bm(1)),
522 /* TS 0: SDCCH/4 */
523 valueof(ts_RslChanNr_SDCCH4(0,2)),
524 /* TS 6: SDCCH/8 */
525 valueof(ts_RslChanNr_SDCCH8(6,4))
526 };
527 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700528
529 g_AllChannels := { };
530
531 /* Generate list of all logical channels from module parameters */
532 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
533 select (trx_pars.ts[tn].config) {
534 case (GSM_PCHAN_CCCH_SDCCH4) {
535 g_AllChannels := g_AllChannels &
536 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
537 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
538 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
539 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
540 }
541 case (GSM_PCHAN_SDCCH8) {
542 g_AllChannels := g_AllChannels &
543 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
544 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
545 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
546 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
547 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
551 }
552 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
553 g_AllChannels := g_AllChannels &
554 { valueof(ts_RslChanNr_Lm(tn, 0)),
555 valueof(ts_RslChanNr_Lm(tn, 1)),
556 valueof(ts_RslChanNr_Bm(tn)) };
557 }
558 case (GSM_PCHAN_TCHH) {
559 g_AllChannels := g_AllChannels &
560 { valueof(ts_RslChanNr_Lm(tn, 0)),
561 valueof(ts_RslChanNr_Lm(tn, 1)) };
562 }
563 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
564 g_AllChannels := g_AllChannels &
565 { valueof(ts_RslChanNr_Bm(tn)) };
566 }
567 }
568 }
569
Harald Welte70767382018-02-21 12:16:40 +0100570 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100571 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100572 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100573 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100574
575 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100576 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
577 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
578 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
579 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100580
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700581 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100582 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700583
584 /* Init TRXC interface to FakeTRX */
585 map(self:BTS_TRXC, system:BTS_TRXC);
586 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
587
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700588 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600589 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
590 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700591 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600592 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100593 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200594
595 /* Wait some extra time to make sure the BTS emits a stable carrier.
596 * (this is only relevant when running the tests with a physical BTS.) */
597 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
Harald Welte68e495b2018-02-25 00:05:57 +0100600/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700601friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100602 map(self:L1CTL, system:L1CTL);
603 f_connect_reset(L1CTL);
604}
605
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200606friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100607
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700608private type record length(8) of FreqHopGroups FreqHopConfig;
609
610private type record of FreqHopGroup FreqHopGroups;
611private type record FreqHopGroup {
612 uint6_t hsn,
613 FreqHopGroupItems trx_maio
614};
615
616private type record of FreqHopGroupItem FreqHopGroupItems;
617private type record FreqHopGroupItem {
618 uint8_t trx_nr,
619 uint6_t maio
620};
621
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700622friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
623 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700625 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700626 var integer i, j;
627
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700628 fhp.enabled := false;
629
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 for (i := 0; i < lengthof(groups); i := i + 1) {
631 var FreqHopGroup g := groups[i];
632 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
633 var FreqHopGroupItem gi := g.trx_maio[j];
634 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700635 fhp.maio_hsn.maio := gi.maio;
636 fhp.maio_hsn.hsn := g.hsn;
637 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700638 break;
639 }
640 }
641
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700642 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700643 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700644 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
645 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
646 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647
648 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700649 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
650 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700651 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700652 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700653 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700654 }
655
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700656 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700657 break; /* We're done */
658 }
659 }
660}
661
Harald Welte70767382018-02-21 12:16:40 +0100662/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700663friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
664 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200665 boolean trxc_comp := false,
666 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100667runs on test_CT return ConnHdlr {
668 var charstring id := testcasename();
669 var ConnHdlr vc_conn;
670
671 vc_conn := ConnHdlr.create(id);
672 /* connect to RSL Emulation main component */
673 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
674 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700675
676 /* The ConnHdlr component may want to talk to some ports directly,
677 * so we disconnect it from the test_CT and connect it to the component.
678 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200679 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200680 unmap(self:PCU, system:PCU);
681 map(vc_conn:PCU, system:PCU);
682 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700683 if (trxc_comp) {
684 unmap(self:BTS_TRXC, system:BTS_TRXC);
685 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
686 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200687 if (l1ctl) {
688 map(vc_conn:L1CTL, system:L1CTL);
689 }
Harald Welte70767382018-02-21 12:16:40 +0100690
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700691 /* Obtain frequency hopping parameters for a given timeslot */
692 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700693 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700694 }
695
Harald Welte70767382018-02-21 12:16:40 +0100696 vc_conn.start(f_handler_init(fn, id, pars));
697 return vc_conn;
698}
699
Harald Welte70767382018-02-21 12:16:40 +0100700private altstep as_Tguard() runs on ConnHdlr {
701 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100703 }
704}
705
Harald Welte990a3612019-05-27 14:02:13 +0200706friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700707 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700708 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100709}
710
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700711private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100712 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600713 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100714}
715
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700716private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100717 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600718 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100719}
720
721/* first function started in ConnHdlr component */
722private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
723runs on ConnHdlr {
724 g_pars := pars;
725 g_chan_nr := pars.chan_nr;
726
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200727 if (L1CTL.checkstate("Mapped")) {
728 f_connect_reset(L1CTL);
729 }
Harald Welte70767382018-02-21 12:16:40 +0100730
Harald Welted48c0c72019-06-05 10:01:15 +0200731 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700732 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
735 g_Tguard.start(pars.t_guard);
736 activate(as_Tguard());
737
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700738 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100739
740 /* call the user-supplied test case function */
741 fn.apply(id);
742}
743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700744private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
745 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200746runs on ConnHdlr return RSL_Message {
747 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100748 timer T := 3.0;
749 RSL.send(tx);
750 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100751 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200752 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100753 T.stop;
754 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100755 }
Harald Welte1eba3742018-02-25 12:48:14 +0100756 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100758 }
Harald Welte21240e62018-03-11 21:43:35 +0100759 [not ignore_other] as_l1_sacch();
760 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700761 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700762 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100765 }
Harald Welte21240e62018-03-11 21:43:35 +0100766 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100767 }
Harald Welteb1726c92018-03-30 11:56:38 +0200768 return rx;
769}
770
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700771friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
772 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200773runs on ConnHdlr {
774 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100775}
776
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300777/* Send the given measurement results to the IUT over the Um interface,
778 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
779friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
780runs on ConnHdlr {
781 var template (value) SacchL1Header l1h;
782 var octetstring l2, l3;
783 timer T;
784
785 /* RR Measurement Report to be sent */
786 var GsmRrL3Message meas_rep := {
787 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
788 payload := { meas_rep := { meas_res := valueof(meas_res) } }
789 };
790
791 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
792 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
793 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
794 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
795 g_pars.l1_pars.ms_actual_ta);
796
797 /* Send RR Measurement Report over the Um interface */
798 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
799
800 /* Expect MEASurement RESult on the A-bis/RSL interface */
801 T.start(2.0);
802 alt {
803 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
804 setverdict(pass);
805 }
806 [] RSL.receive { repeat; }
807 [] T.timeout {
808 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
810 }
811 }
812}
813
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700814friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
815 boolean encr_enable := false,
816 RSL_IE_List more_ies := {},
817 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
818runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200819 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200820 if (encr_enable) {
821 /* append encryption related IEs, if requested */
822 var RSL_IE_EncryptionInfo encr_info;
823 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
824 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
825encr_info})) };
826 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200827 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200828 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100829}
830
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700831friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100832 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100833 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100834}
835
Harald Welte2f2b2b72019-05-31 22:24:57 +0200836friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200837 template RSL_IE_ChannelMode chan_mode,
838 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700839 uint8_t trx_nr := 0, float t_guard := 20.0) := {
840 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100841 chan_nr := valueof(chan_nr),
842 chan_mode := valueof(chan_mode),
843 t_guard := t_guard,
844 l1_pars := {
845 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100846 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100847 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100848 meas_ul := {
849 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200850 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100851 rxqual := 0
852 },
853 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 }
857 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200858 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200860 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200861 ms_actual_ta := mp_ms_actual_ta_exp,
862 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100863 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200864 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200865 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700866 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700867 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700868 fhp := {
869 enabled := false,
870 maio_hsn := ts_HsnMaio(0, 0),
871 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700872 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700873 }
Harald Welte70767382018-02-21 12:16:40 +0100874}
875
Harald Welte93640c62018-02-25 16:59:33 +0100876/***********************************************************************
877 * Channel Activation / Deactivation
878 ***********************************************************************/
879
Harald Welte70767382018-02-21 12:16:40 +0100880/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700881private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100882 for (var integer i := 0; i < 500; i := i+1) {
883 f_rsl_chan_act(g_pars.chan_mode);
884 f_rsl_chan_deact();
885 }
886 setverdict(pass);
887}
888testcase TC_chan_act_stress() runs on test_CT {
889 var ConnHdlr vc_conn;
890 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200891 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100892 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
893 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100895}
896
897/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700898private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100899 f_rsl_chan_act(g_pars.chan_mode);
900 /* attempt to activate the same lchan again -> expect reject */
901 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
902 alt {
903 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100905 }
906 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
907 setverdict(pass);
908 }
909 }
910 f_rsl_chan_deact();
911}
912testcase TC_chan_act_react() runs on test_CT {
913 var ConnHdlr vc_conn;
914 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100915 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100916 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
917 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100919}
920
921/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700922private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100923 timer T := 3.0;
924 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
925 T.start;
926 alt {
927 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
928 setverdict(pass);
929 }
930 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100932 }
933 }
934}
935testcase TC_chan_deact_not_active() runs on test_CT {
936 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100937 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100938 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
939 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100941}
942
943/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700944private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100945 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
946 alt {
947 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100949 }
950 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
951 setverdict(pass);
952 }
953 }
954}
955private type record WrongChanNrCase {
956 RslChannelNr chan_nr,
957 charstring description
958}
959private type record of WrongChanNrCase WrongChanNrCases;
960private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
961 chan_nr := chan_nr,
962 description := desc
963}
964
965testcase TC_chan_act_wrong_nr() runs on test_CT {
966 var ConnHdlr vc_conn;
967 var ConnHdlrPars pars;
968
Harald Welte294b0a22018-03-10 23:26:48 +0100969 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100970
971 var WrongChanNrCases wrong := {
972 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
973 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
974 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
975 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
976 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
977 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
978 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
979 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
980 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
981 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
982 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
983 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
984 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
985 };
986
987 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
988 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
989 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
990 vc_conn.done;
991 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100993}
994
Harald Weltee613f962018-04-18 22:38:16 +0200995/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200996friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200997 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200998 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200999
1000 /* test on each of the channels we have */
1001 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1002 pars.chan_nr := valueof(g_AllChanTypes[i]);
1003
1004 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1005 vc_conn := f_start_handler(fn, pars);
1006 vc_conn.done;
1007 }
1008
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001010}
1011
Harald Welte93640c62018-02-25 16:59:33 +01001012/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001013 * SACCH handling
1014 ***********************************************************************/
1015
1016private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1017 timer T_sacch := 3.0;
1018 T_sacch.start;
1019 alt {
1020 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001022 }
1023 [not exp] T_sacch.timeout {
1024 setverdict(pass);
1025 }
1026 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1027 setverdict(pass);
1028 }
1029 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001031 }
1032 [] L1CTL.receive { repeat; }
1033 [] RSL.receive { repeat; }
1034 }
1035}
1036
1037/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1038private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1039 f_l1_tune(L1CTL);
1040 RSL.clear;
1041
1042 /* activate the logical channel */
1043 f_est_dchan();
1044 L1CTL.clear;
1045
1046 /* check that SACCH actually are received as expected */
1047 f_exp_sacch(true);
1048
1049 /* deactivate SACCH on the logical channel */
1050 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1051 f_sleep(1.0);
1052 L1CTL.clear;
1053
1054 /* check that no SACCH are received anymore */
1055 f_exp_sacch(false);
1056
1057 /* release the channel */
1058 f_rsl_chan_deact();
1059 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1060}
1061testcase TC_deact_sacch() runs on test_CT {
1062 var ConnHdlr vc_conn;
1063 var ConnHdlrPars pars;
1064 f_init();
1065 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1066 //for (var integer i := 0; i < 1; i := i+1) {
1067 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1068 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1069 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1070 vc_conn.done;
1071 }
1072 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001074}
1075
Harald Welte55700662018-03-12 13:15:43 +01001076/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001077private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1078 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001079 timer T_sacch := 3.0;
1080 L1CTL.clear;
1081 T_sacch.start;
1082 alt {
1083 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1084 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1085 if (match(l3, l3_exp)) {
1086 setverdict(pass);
1087 } else {
1088 repeat;
1089 }
1090 }
1091 [] L1CTL.receive { repeat; }
1092 [] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001093 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001095 }
1096 }
1097}
1098
Harald Welte55700662018-03-12 13:15:43 +01001099/* verify that given SACCH payload is not present */
1100private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1101 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001102 timer T_sacch := 3.0;
1103 L1CTL.clear;
1104 T_sacch.start;
1105 alt {
1106 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1107 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1108 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001109 setverdict(fail, "Received unexpected SACCH ", dl);
1110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001111 } else {
1112 repeat;
1113 }
1114 }
1115 [] L1CTL.receive { repeat; }
1116 [] T_sacch.timeout {
1117 setverdict(pass);
1118 }
1119 }
1120}
1121
Harald Welte629cc6b2018-03-11 17:19:05 +01001122/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001123private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1124 /* Set a known default SACCH filling for SI5 */
1125 var octetstring si5 := f_rnd_octstring(19);
1126 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1127
1128 f_l1_tune(L1CTL);
1129 RSL.clear;
1130
1131 /* activate the logical channel */
1132 f_est_dchan();
1133
1134 /* check that the specified SI5 value is actually sent */
1135 f_sacch_present(si5);
1136
1137 /* release the channel */
1138 RSL.clear;
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_sacch_filling() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1148 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1149 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1150 vc_conn.done;
1151 }
1152 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001154}
1155
Harald Welte629cc6b2018-03-11 17:19:05 +01001156/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001157private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1158 /* Set a known default SACCH filling for SI5 */
1159 var octetstring si5 := f_rnd_octstring(19);
1160 var octetstring si5_diff := f_rnd_octstring(19);
1161 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1162
1163 f_l1_tune(L1CTL);
1164 RSL.clear;
1165
1166 log("Activating channel, expecting standard SI5");
1167 /* activate the logical channel */
1168 f_est_dchan();
1169 /* check that the specified SI5 value is actually sent */
1170 f_sacch_present(si5);
1171
1172 /* set channel-specific different SI5 */
1173 log("Setting channel specific SACCH INFO, expecting it");
1174 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1175 /* check that the specified lchan-specific value is now used */
1176 f_sacch_present(si5_diff);
1177
1178 /* deactivate the channel and re-activate it, this should result in default SI5 */
1179 log("De-activating and re-activating channel, expecting standard SI5");
1180 f_rsl_chan_deact();
1181 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1182 /* Verify that the TRX-wide default SACCH filling is present again */
1183 f_sacch_present(si5);
1184
1185 /* release the channel */
1186 RSL.clear;
1187 f_rsl_chan_deact();
1188 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1189}
1190testcase TC_sacch_info_mod() runs on test_CT {
1191 var ConnHdlr vc_conn;
1192 var ConnHdlrPars pars;
1193 f_init();
1194 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1195 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1196 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1197 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1198 vc_conn.done;
1199 }
1200 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001202}
1203
Harald Welte075d84c2018-03-12 13:07:24 +01001204/* Test SACCH scheduling of multiple different SI message types */
1205private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1206 var octetstring si5 := f_rnd_octstring(19);
1207 var octetstring si5bis := f_rnd_octstring(19);
1208 var octetstring si5ter := f_rnd_octstring(19);
1209 var octetstring si6 := f_rnd_octstring(19);
1210
1211 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1212 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1213 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1214 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1215
1216 f_l1_tune(L1CTL);
1217 RSL.clear;
1218
1219 /* activate the logical channel */
1220 f_est_dchan();
1221 L1CTL.clear;
1222
1223 /* check that SACCH actually are received as expected */
1224 f_sacch_present(si5);
1225 f_sacch_present(si5bis);
1226 f_sacch_present(si5ter);
1227 f_sacch_present(si6);
1228
1229 /* release the channel */
1230 f_rsl_chan_deact();
1231 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1232}
1233testcase TC_sacch_multi() runs on test_CT {
1234 var ConnHdlr vc_conn;
1235 var ConnHdlrPars pars;
1236 f_init();
1237 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1238 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1239 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1240 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1241 vc_conn.done;
1242 }
1243 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001245}
1246
Harald Welte55700662018-03-12 13:15:43 +01001247/* Test if SACH information is modified as expected */
1248private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1249 var octetstring si5 := f_rnd_octstring(19);
1250 var octetstring si6 := f_rnd_octstring(19);
1251
1252 /* First, configure both SI5 and SI6 to be transmitted */
1253 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1254 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1255
1256 f_l1_tune(L1CTL);
1257 RSL.clear;
1258
1259 /* activate the logical channel */
1260 f_est_dchan();
1261 L1CTL.clear;
1262
1263 /* check that SACCH actually are received as expected */
1264 f_sacch_present(si5);
1265 f_sacch_present(si6);
1266
1267 /* disable SI6 */
1268 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1269
1270 /* check that SI5 is still transmitted */
1271 f_sacch_present(si5);
1272 /* check if SI6 is now gone */
1273 f_sacch_missing(si6);
1274
1275 /* release the channel */
1276 f_rsl_chan_deact();
1277 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1278}
1279testcase TC_sacch_multi_chg() runs on test_CT {
1280 var ConnHdlr vc_conn;
1281 var ConnHdlrPars pars;
1282 f_init();
1283 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1284 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1285 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1286 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1287 vc_conn.done;
1288 }
1289 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001291}
1292
Harald Weltec8d363c2019-05-19 20:36:48 +02001293/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1294private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1295 var octetstring si5 := f_rnd_octstring(19);
1296 var octetstring si6 := f_rnd_octstring(19);
1297 var octetstring si5_specific := f_rnd_octstring(19);
1298 var octetstring si6_specific := f_rnd_octstring(19);
1299
1300 /* First, configure both SI5 and SI6 to be transmitted */
1301 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1302 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1303
1304 f_l1_tune(L1CTL);
1305 RSL.clear;
1306
1307 /* activate channel with different SACCH filling */
1308 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1309 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1310 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1311 }));
1312 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1313 RSL_IE_Body:{sacch_info := sacch_info})) };
1314 f_est_dchan(more_ies := addl_ies);
1315
1316 /* check that SACCH actually are received as expected */
1317 f_sacch_present(si5_specific);
1318 f_sacch_present(si6_specific);
1319
1320 /* release the channel */
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323}
1324testcase TC_sacch_chan_act() runs on test_CT {
1325 var ConnHdlr vc_conn;
1326 var ConnHdlrPars pars;
1327 f_init();
1328
1329 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1330 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1331 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1332 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1333 vc_conn.done;
1334 }
1335 /* TODO: do the above in parallel, rather than sequentially? */
1336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1337}
1338
Harald Welte8b01c792019-05-19 22:51:25 +02001339/* verify that SACCH DL transmission is started only if MS power IE present
1340 * see section 4.1.3 of 3GPP TS 48.058 */
1341private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1342 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001343 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001344
1345 f_l1_tune(L1CTL);
1346 RSL.clear;
1347
1348 /* Step 1: Activate ASYNC HO channel without MS power IE */
1349
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001350 var integer ho_ref := oct2int(f_rnd_octstring(1));
1351 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1352 RSL_IE_Body:{ handover_ref := ho_ref }));
1353 var RSL_IE_List addl_ies := {
1354 ho_ref_ie
1355 };
1356
Harald Welte8b01c792019-05-19 22:51:25 +02001357 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001358 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 +02001359 /* don't perform immediate assignment here, as we're testing non-IA case */
1360 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001361 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001362
1363 /* Verify that no DL SACCH is being received */
1364 f_sacch_missing(?);
1365
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001366 /* Send handover Access Burst and expect SACCH to start */
1367 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1368
1369 f_sacch_present(si5);
1370
Harald Welte8b01c792019-05-19 22:51:25 +02001371 f_rsl_chan_deact();
1372 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1373
1374
1375 /* Step 2: Activate ASYNC HO channel with MS power IE */
1376
1377 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001378 addl_ies := {
1379 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001380 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1381 };
1382 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1383 /* don't perform immediate assignment here, as we're testing non-IA case */
1384 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001385 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001386
1387 /* Verify that DL SACCH is being received */
1388 f_sacch_present(si5);
1389
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001390 /* Send handover Access Burst and expect SACCH to remain present */
1391 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1392
1393 f_sacch_present(si5);
1394
Harald Welte8b01c792019-05-19 22:51:25 +02001395 f_rsl_chan_deact();
1396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1397}
1398testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1399 var ConnHdlr vc_conn;
1400 var ConnHdlrPars pars;
1401 f_init();
1402
1403 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1404 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1405 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1406 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1407 vc_conn.done;
1408 }
1409 /* TODO: do the above in parallel, rather than sequentially? */
1410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1411}
1412
1413/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1414 * see section 4.1.4 of 3GPP TS 48.058 */
1415private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1416 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001417 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1418
Harald Welte8b01c792019-05-19 22:51:25 +02001419 var RSL_IE_List addl_ies;
1420
1421 f_l1_tune(L1CTL);
1422 RSL.clear;
1423
1424 /* Step 1: Activate SYNC HO channel without MS power IE */
1425
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001426 var integer ho_ref := oct2int(f_rnd_octstring(1));
1427 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1428 RSL_IE_Body:{ handover_ref := ho_ref }));
1429 addl_ies := {
1430 ho_ref_ie
1431 };
1432
Harald Welte8b01c792019-05-19 22:51:25 +02001433 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001434 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 +02001435 /* don't perform immediate assignment here, as we're testing non-IA case */
1436 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001437 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001438
1439 /* Verify that no DL SACCH is being received */
1440 f_sacch_missing(?);
1441
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001442 /* Send handover Access Burst and expect SACCH to start */
1443 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1444
1445 f_sacch_present(si5);
1446
Harald Welte8b01c792019-05-19 22:51:25 +02001447 f_rsl_chan_deact();
1448 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1449
1450
1451 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1452
1453 /* Activate channel on BTS side */
1454 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001455 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001456 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1457 };
1458 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1459 /* don't perform immediate assignment here, as we're testing non-IA case */
1460 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001461 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001462
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001463 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1464 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001465
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001466 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001467 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1468
1469 f_sacch_present(si5);
1470
Harald Welte8b01c792019-05-19 22:51:25 +02001471 f_rsl_chan_deact();
1472 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1473
1474
1475 /* Step 2b: Activate SYNC HO channel with TA IE */
1476
1477 /* Activate channel on BTS side */
1478 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001479 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001480 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1481 };
1482 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1483 /* don't perform immediate assignment here, as we're testing non-IA case */
1484 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001485 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001486
1487 /* Verify that no DL SACCH is being received */
1488 f_sacch_missing(?);
1489
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001490 /* Send handover Access Burst and expect SACCH to start */
1491 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1492
1493 f_sacch_present(si5);
1494
Harald Welte8b01c792019-05-19 22:51:25 +02001495 f_rsl_chan_deact();
1496 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1497
1498
1499 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1500
1501 /* Activate channel on BTS side */
1502 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001503 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001504 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1505 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1506 };
1507 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1508 /* don't perform immediate assignment here, as we're testing non-IA case */
1509 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001510 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001511
1512 /* Verify that DL SACCH is being received */
1513 f_sacch_present(si5);
1514
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001515 /* Send handover Access Burst and expect SACCH to remain present */
1516 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1517
1518 f_sacch_present(si5);
1519
Harald Welte8b01c792019-05-19 22:51:25 +02001520 f_rsl_chan_deact();
1521 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1522}
1523testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1524 var ConnHdlr vc_conn;
1525 var ConnHdlrPars pars;
1526 f_init();
1527
1528 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1529 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1530 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1531 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1532 vc_conn.done;
1533 }
1534 /* TODO: do the above in parallel, rather than sequentially? */
1535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1536}
Harald Welte629cc6b2018-03-11 17:19:05 +01001537
1538
1539/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001540 * RACH Handling
1541 ***********************************************************************/
1542
Harald Welte8c24c2b2018-02-26 08:31:31 +01001543/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001544private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001545 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001546 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001547 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001548
Harald Welte8c24c2b2018-02-26 08:31:31 +01001549 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001550 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001551 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001552 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001553 if (emerg == true) {
1554 ra := f_rnd_ra_emerg();
1555 } else {
1556 ra := f_rnd_ra_cs();
1557 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001558 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1559 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001561 }
1562 fn_last := fn;
1563
1564 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001565 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001566 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001567 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001568 T.stop;
1569 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001570 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001572 }
1573 [] RSL_CCHAN.receive { repeat; }
1574 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001575 test_failed := true;
1576 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001577 }
1578 }
1579 }
Maxba06feb2019-03-05 10:52:46 +01001580 if (test_failed) {
1581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001582 }
Maxba06feb2019-03-05 10:52:46 +01001583 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001585}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001586
Philipp Maier16ade782020-07-08 21:36:00 +02001587/* Normal variant */
1588testcase TC_rach_content() runs on test_CT {
1589 f_TC_rach_content(emerg := false);
1590}
1591
1592/* Emergency call variant */
1593testcase TC_rach_content_emerg() runs on test_CT {
1594 f_TC_rach_content(emerg := true);
1595}
1596
Harald Welte8c24c2b2018-02-26 08:31:31 +01001597/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1598testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001599 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001600 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001601 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001602 f_l1_tune(L1CTL);
1603
1604 var GsmFrameNumber fn_last := 0;
1605 for (var integer i := 0; i < 1000; i := i+1) {
1606 var OCT1 ra := f_rnd_ra_cs();
1607 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1608 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001610 }
1611 fn_last := fn;
1612 }
1613 var integer rsl_chrqd := 0;
1614 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001615 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001616 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001618 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001619 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001620 repeat;
1621 }
1622 [] RSL_CCHAN.receive { repeat; }
1623 [] T.timeout { }
1624 }
1625 if (rsl_chrqd == 1000) {
1626 setverdict(pass);
1627 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001629 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001631}
1632
Harald Welte3453ab42019-05-24 21:19:58 +02001633private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1634 var charstring bts_str := "bts " & int2str(bts_nr);
1635 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1636}
1637
1638/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1639private template integer tr_rach_slots_per_interval := (90 .. 130);
1640
1641/* Expect 0 RACH load on an idle BTS that has just started up */
1642testcase TC_rach_load_idle_thresh0() runs on test_CT {
1643 var ASP_RSL_Unitdata rx_ud;
1644
1645 f_init_vty_bsc();
1646 /* send load indications even at 0% load */
1647 f_vty_load_ind_thresh(0);
1648 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1649 f_sleep(2.0);
1650
1651 f_init();
1652
Harald Weltee37f9a52020-10-11 20:45:23 +02001653 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1654 alt {
1655 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1656 [] RSL_CCHAN.receive { repeat }
1657 }
1658
Harald Welte3453ab42019-05-24 21:19:58 +02001659 timer T := 5.0;
1660 T.start;
1661 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001662 [] 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 +02001663 setverdict(pass);
1664 repeat;
1665 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001666 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001667 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1668 repeat;
1669 }
1670 [] RSL_CCHAN.receive {
1671 repeat;
1672 }
1673 [] T.timeout { }
1674 }
1675
1676 f_vty_load_ind_thresh(10);
1677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1678}
1679
1680/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1681testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1682 var ASP_RSL_Unitdata rx_ud;
1683
1684 f_init_vty_bsc();
1685 f_init();
1686
1687 timer T := 5.0;
1688 T.start;
1689 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001690 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001691 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1692 repeat;
1693 }
1694 [] RSL_CCHAN.receive {
1695 repeat;
1696 }
1697 [] T.timeout {
1698 setverdict(pass);
1699 }
1700 }
1701
1702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1703}
1704
1705/* Expect 0 RACH load on an idle BTS that has just started up */
1706testcase TC_rach_load_count() runs on test_CT {
1707 var ASP_RSL_Unitdata rx_ud;
1708 var integer load_access_count := 0;
1709
1710 f_init_vty_bsc();
1711 /* send load indications even at 0% load */
1712 f_vty_load_ind_thresh(0);
1713 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1714 f_sleep(2.0);
1715 f_init();
1716
1717 f_init_l1ctl();
1718 f_sleep(1.0);
1719 f_l1_tune(L1CTL);
1720
Harald Welte52ae1682020-10-11 20:45:55 +02001721 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1722 alt {
1723 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1724 [] RSL_CCHAN.receive { repeat }
1725 }
1726
Harald Welte3453ab42019-05-24 21:19:58 +02001727 var GsmFrameNumber fn_last := 0;
1728 for (var integer i := 0; i < 1000; i := i+1) {
1729 var OCT1 ra := f_rnd_ra_cs();
1730 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1731 if (fn == fn_last) {
1732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1733 }
1734 fn_last := fn;
1735 }
1736
1737 timer T := 5.0;
1738 T.start;
1739 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001740 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001741 -> value rx_ud {
1742 var RSL_IE_Body ie;
1743 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1744 load_access_count := load_access_count + ie.rach_load.access_count;
1745 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1746 setverdict(fail, "Access count cannot be < Busy count");
1747 }
1748 repeat;
1749 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001750 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001751 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1752 repeat;
1753 }
1754 [] RSL_CCHAN.receive {
1755 repeat;
1756 }
1757 [] T.timeout { }
1758 }
1759 if (load_access_count == 1000) {
1760 setverdict(pass);
1761 } else {
1762 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1763 }
1764
1765 f_vty_load_ind_thresh(10);
1766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1767}
1768
Harald Welte54a2a2d2018-02-26 09:14:05 +01001769private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001770 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001771 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001772 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001773 f_sleep(0.5);
1774
1775 /* Transmit RACH request + wait for confirmation */
1776 var OCT1 ra := f_rnd_ra_cs();
1777 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1778
1779 /* Check for expected result */
1780 timer T := 1.5;
1781 T.start;
1782 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001783 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001784 setverdict(pass);
1785 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001786 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001788 }
1789 [] RSL_CCHAN.receive { repeat; }
1790 [not expect_pass] T.timeout {
1791 setverdict(pass);
1792 }
1793 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001795 }
1796 }
1797}
1798
1799/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1800testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001801 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001802 f_init_l1ctl();
1803 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001804 f_sleep(1.0);
1805
1806 /* default max-ta is 63 (full range of GSM timing advance */
1807
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001808 /* We allow early arrival up to 2 symbols */
1809 f_rach_toffs(-1*256, true);
1810 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001811 f_rach_toffs(-10*256, false);
1812
1813 /* 0 / 32 / 63 bits is legal / permitted */
1814 f_rach_toffs(0, true);
1815 f_rach_toffs(32*256, true);
1816 f_rach_toffs(63*256, true);
1817
1818 /* more than 63 bits is not legal / permitted */
1819 f_rach_toffs(64*256, false);
1820 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001822}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001823
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001824private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001825 var GsmFrameNumber fn;
1826 var RSL_Message rm;
1827
1828 f_l1_tune(L1CTL);
1829 RSL.clear;
1830
1831 /* Generate a random Handover Reference */
1832 var integer ho_ref := oct2int(f_rnd_octstring(1));
1833
1834 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1835 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1836 RSL_IE_Body:{ handover_ref := ho_ref }));
1837
1838 /* Activate a channel on the BTS side (no encryption) */
1839 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1840 act_type := t_RSL_IE_ActType_HO_SYNC);
1841
1842 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1843 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001844 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001845
1846 /* Send handover Access Burst */
1847 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1848
1849 /* TODO: test mismatching Handover Reference, and missing IE */
1850
1851 /* Wait for handover detection */
1852 timer T := 3.0;
1853 T.start;
1854 alt {
1855 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1856 log("Handover RACH has been detected: ", rm);
1857 setverdict(pass);
1858 }
1859 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1861 log2str("RSL_CHAN_RQD was not expected: ", rm));
1862 }
1863 [] RSL.receive { repeat; }
1864 [] T.timeout {
1865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1866 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1867 }
1868 }
1869
1870 /* Release the channel */
1871 f_rsl_chan_deact();
1872 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1873}
1874
1875/* Test handover RACH detection */
1876testcase TC_ho_rach() runs on test_CT {
1877 var ConnHdlrPars pars;
1878 var ConnHdlr vc_conn;
1879
1880 f_init();
1881
1882 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1883 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1884 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1885 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1886 vc_conn.done;
1887 }
1888
1889 /* TODO: do the above in parallel, rather than sequentially? */
1890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1891}
1892
Harald Welte93640c62018-02-25 16:59:33 +01001893/***********************************************************************
1894 * Measurement Processing / Reporting
1895 ***********************************************************************/
1896
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001897private template (value) LapdmAddressField
1898ts_LapdmAddr(template (value) LapdmSapi sapi,
1899 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001900 spare := '0'B,
1901 lpd := 0,
1902 sapi := sapi,
1903 c_r := c_r,
1904 ea := true
1905}
1906
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001907private template (value) LapdmFrameAB
1908ts_LAPDm_AB(template (value) LapdmSapi sapi,
1909 template (value) GsmRrL3Message l3,
1910 template (value) boolean c_r := false,
1911 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001912 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001913 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001914 len := 0, /* overwritten */
1915 m := false,
1916 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03001917 payload := enc_GsmRrL3Message(valueof(l3)),
1918 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01001919}
1920
1921/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001922private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001923 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001924 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001925
Harald Weltef8df4cb2018-03-10 15:15:08 +01001926 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001927 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001928
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001929 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001930 g_pars.l1_pars.meas_ul.full.rxlev,
1931 g_pars.l1_pars.meas_ul.sub.rxlev,
1932 g_pars.l1_pars.meas_ul.full.rxqual,
1933 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001934 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001935
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001936 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1937 g_pars.l1_pars.ms_power_level, false,
1938 g_pars.l1_pars.ms_actual_ta);
1939
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001940 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1941 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001942
1943 log("Sending Measurement Report: ", l1h, l2);
1944 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001945 repeat;
1946 }
1947}
1948
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001949/* handle incoming downlink SACCH, decode the L1 header into the given record */
1950private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1951 boolean do_apply := true)
1952runs on ConnHdlr
1953{
1954 var L1ctlDlMessage l1_dl;
1955
1956 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1957 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1958 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1959 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1960
1961 if (do_apply) {
1962 /* Update TA and MS power to follow what BTS requests */
1963 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1964 }
1965 }
1966}
1967
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001968private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001969 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001970 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001971 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1972 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001973 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1974 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001975 repeat;
1976 }
1977}
1978
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001979private altstep as_l1_tch_loop() runs on ConnHdlr {
1980 var L1ctlDlMessage l1_dl;
1981 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1982 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001983
1984 /* occasionaly inject FACCH frames into the uplink */
1985 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1986 var octetstring pl := '010301'O;
1987 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1988 f_pad_oct(pl, 23, '2B'O)));
1989 } else {
1990 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1991 l1_dl.payload.traffic_ind.data));
1992 }
1993
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001994 repeat;
1995 }
1996}
1997
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001998private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001999 uint6_t rxlev,
2000 uint3_t rxqual
2001}
2002
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002003private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002004 MeasElem full,
2005 MeasElem sub
2006}
2007
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002008private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002009 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002010 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002011 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002012 MeasElemFS meas_ul,
2013 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002014 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002015 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002016 uint8_t ms_actual_ta,
2017 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002018}
2019
2020/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2021private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2022 return 63 + (toffs256s/256);
2023}
2024
Harald Welted5684392018-03-10 18:22:04 +01002025private function f_max(integer a, integer b) return integer {
2026 if (a > b) {
2027 return a;
2028 } else {
2029 return b;
2030 }
2031}
2032
2033private function f_min(integer a, integer b) return integer {
2034 if (a < b) {
2035 return a;
2036 } else {
2037 return b;
2038 }
2039}
2040
2041/* compute negative tolerance val-tolerance, ensure >= min */
2042private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2043 val := val - tolerance;
2044 return f_max(val, min);
2045}
2046
2047/* compute positive tolerance val+tolerance, ensure <= max */
2048private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2049 val := val + tolerance;
2050 return f_min(val, max);
2051}
2052
2053/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2054private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2055return template integer {
2056 var template integer ret;
2057 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2058 return ret;
2059}
2060
2061
Harald Welte70767382018-02-21 12:16:40 +01002062/* build a template for matching measurement results against */
2063private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2064 var ConnL1Pars l1p := g_pars.l1_pars;
2065 var template RSL_IE_UplinkMeas ul_meas := {
2066 len := 3,
2067 rfu := '0'B,
2068 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002069 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002070 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002071 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002072 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002073 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2074 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002075 supp_meas_info := omit
2076 };
Harald Welte685d5982018-02-27 20:42:05 +01002077 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002078 ul_meas.len := (3+8);
2079 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002080 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002081 toa256_min := ?,
2082 toa256_max := ?,
2083 toa256_std_dev := ?
2084 }
Harald Welte685d5982018-02-27 20:42:05 +01002085 }
Harald Welte70767382018-02-21 12:16:40 +01002086 var template RSL_IE_BS_Power bs_power := {
2087 reserved := 0,
2088 epc := false,
2089 fpc := false,
2090 power_level := l1p.bs_power_level
2091 };
2092 var template RSL_IE_L1Info l1_info := {
2093 ms_power_lvl := l1p.ms_power_level,
2094 fpc := false,
2095 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002096 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002097 };
2098 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002099 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002100 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2101 ?, t_toffs);
2102}
2103
Philipp Maierdd841d32019-12-17 14:44:54 +01002104/* build a template for matching measurement results that do not contain any
2105 * MS related measurement (l1_info, l3_info and ms timing offset). */
2106private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2107 var ConnL1Pars l1p := g_pars.l1_pars;
2108 var template RSL_IE_UplinkMeas ul_meas := {
2109 len := 3,
2110 rfu := '0'B,
2111 dtx_d := l1p.dtx_enabled,
2112 rxlev_f_u := ?,
2113 reserved1 := '00'B,
2114 rxlev_s_u := ?,
2115 reserved2 := '00'B,
2116 rxq_f_u := ?,
2117 rxq_s_u := ?,
2118 supp_meas_info := omit
2119 };
2120 if (l1p.toa256_enabled) {
2121 ul_meas.len := (3+8);
2122 ul_meas.supp_meas_info := {
2123 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2124 toa256_min := ?,
2125 toa256_max := ?,
2126 toa256_std_dev := ?
2127 }
2128 }
2129 var template RSL_IE_BS_Power bs_power := {
2130 reserved := 0,
2131 epc := false,
2132 fpc := false,
2133 power_level := l1p.bs_power_level
2134 };
2135
2136 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2137}
2138
Harald Welte70767382018-02-21 12:16:40 +01002139/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002140private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002141 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002142 var boolean chan_est := false;
2143
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002144 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002145
2146 /* Receive osmocom specific measurement reports. This is the normal
2147 * case. Here we verify that the measurement reports we sent are
2148 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002149 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2150 /* increment counter of next to-be-expected meas rep */
2151 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2152 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002153 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002154
2155 /* The following two cases may only happen in the beginning
2156 * of the channel establishment phase. Once we have received
2157 * the "our" measurement report the first time, the channel
2158 * is established and empty or hardcoded TRXCON reports must
2159 * not occur anymore. */
2160 chan_est := true;
2161
2162 repeat;
2163 }
2164
2165 /* When the BTS has established the channel, the MS might need slightly
2166 * more time to establish the channel and actually start sending. The
2167 * result is then a measurement report that just lacks the measurement
2168 * information of the MS. This is normal and we tolerate this behavior. */
2169 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2170 /* increment counter of next to-be-expected meas rep */
2171 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2172 /* Re-start the timer expecting the next MEAS RES */
2173 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002174 repeat;
2175 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002176
2177 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2178 * measurements if the TTCN3 side does not supply measurement input in
2179 * time. In those cases TRXCON will either use a cached measurement
2180 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2181 * report the templates above will not match. We tolerate this
2182 * behavior, but only once. */
2183 [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 +01002184 /* increment counter of next to-be-expected meas rep */
2185 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2186 if (g_first_meas_res) {
2187 g_first_meas_res := false;
2188 repeat;
2189 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002191 }
Harald Welte70767382018-02-21 12:16:40 +01002192 }
2193 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002195 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002196 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002198 }
2199}
2200
Harald Weltee613f962018-04-18 22:38:16 +02002201private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2202 select (rsl_alg_id) {
2203 case (RSL_ALG_ID_A5_0) { return 0; }
2204 case (RSL_ALG_ID_A5_1) { return 1; }
2205 case (RSL_ALG_ID_A5_2) { return 2; }
2206 case (RSL_ALG_ID_A5_3) { return 3; }
2207 case (RSL_ALG_ID_A5_4) { return 4; }
2208 case (RSL_ALG_ID_A5_5) { return 5; }
2209 case (RSL_ALG_ID_A5_6) { return 6; }
2210 case (RSL_ALG_ID_A5_7) { return 7; }
2211 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002212 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2213 /* Make compiler happy by calling mtc.stop here. It is already
2214 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002215 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002216 }
2217 }
2218}
2219
2220private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2221 select (rsl_alg_id) {
2222 case (RSL_ALG_ID_A5_1) { return '000'B; }
2223 case (RSL_ALG_ID_A5_2) { return '001'B; }
2224 case (RSL_ALG_ID_A5_3) { return '010'B; }
2225 case (RSL_ALG_ID_A5_4) { return '011'B; }
2226 case (RSL_ALG_ID_A5_5) { return '100'B; }
2227 case (RSL_ALG_ID_A5_6) { return '101'B; }
2228 case (RSL_ALG_ID_A5_7) { return '110'B; }
2229 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2231 /* Make compiler happy by calling mtc.stop here. It is already
2232 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002233 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002234 }
2235 }
2236}
2237
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002238/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2239private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2240 var GsmFrameNumber fn;
2241 timer T := 8.0;
2242
2243 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2244 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2245
2246 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2247 /* Send the actual RACH */
2248 fn := f_L1CTL_RACH(L1CTL, ra);
2249
2250 T.start;
2251 alt {
2252 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2253 [] T.timeout {
2254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2255 }
2256 }
2257 T.stop
2258 return fn;
2259}
Harald Weltee613f962018-04-18 22:38:16 +02002260
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002261/* Tune to a dedicated channel: L1CTL only */
2262private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002263 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002264 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002265 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002266 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002267 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002268 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002269 pars.fhp.maio_hsn.hsn,
2270 pars.fhp.maio_hsn.maio,
2271 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002272 }
2273}
2274
Harald Welte70767382018-02-21 12:16:40 +01002275/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002276private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002277 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002278
2279 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002280 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002281
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002282 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002283 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002284 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002285 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002286 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2287 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002288 }
2289
Harald Welte70767382018-02-21 12:16:40 +01002290 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002291 f_l1ctl_est_dchan(L1CTL, g_pars);
2292
Harald Weltee613f962018-04-18 22:38:16 +02002293 /* enable encryption, if requested */
2294 if (encr_enable) {
2295 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2296 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2297 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002298
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002299 /* Send TCH Mode Request to the L1 if needed */
2300 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2301 var L1ctlTchMode tch_mode;
2302
2303 select (g_pars.chan_mode.coding_alg_rate) {
2304 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2305 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2306 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2307 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2308 case else {
2309 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2310 " is not supported by the L1, falling back to signalling");
2311 tch_mode := L1CTL_CHAN_MODE_SIGN;
2312 }
2313 }
2314
2315 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2316 }
2317
Harald Weltefa45e9e2018-03-10 18:59:03 +01002318 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002319}
2320
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002321/* Initialize and start the RTP emulation component for a ConnHdlr */
2322friend function f_rtpem_activate(inout octetstring payload,
2323 RtpemConfig cfg := c_RtpemDefaultCfg,
2324 RtpemMode mode := RTPEM_MODE_BIDIR)
2325runs on ConnHdlr {
2326 /* Step 0: initialize, connect and start the emulation component */
2327 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2328 map(vc_RTPEM:RTP, system:RTP);
2329 map(vc_RTPEM:RTCP, system:RTCP);
2330 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2331 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2332 vc_RTPEM.start(RTP_Emulation.f_main());
2333
2334 /* Step 1: configure the RTP parameters */
2335 var integer payload_len := 0;
2336 var octetstring hdr := ''O;
2337
2338 select (g_pars.chan_mode) {
2339 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2340 { payload_len := 33; hdr := 'D0'O; }
2341 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2342 { payload_len := 15; hdr := '00'O; }
2343 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2344 { payload_len := 31; hdr := 'C0'O; }
2345 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2346 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2348 }
2349 }
2350
2351 /* Pad the payload to conform the expected length */
2352 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2353 cfg.tx_fixed_payload := payload;
2354 f_rtpem_configure(RTPEM_CTRL, cfg);
2355
2356 /* Step 2: bind the RTP emulation to the configured address */
2357 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2358 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2359
2360 /* Step 3: send CRCX with the configured address/port to the IUT */
2361 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2362 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2363 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2364 "IPA CRCX ACK");
2365
2366 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2367 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2368 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2369 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2370
2371 /* Step 5: set the given RTP emulation mode */
2372 f_rtpem_mode(RTPEM_CTRL, mode);
2373}
2374
Harald Welte70767382018-02-21 12:16:40 +01002375/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002376private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002377 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002378 RSL.clear;
2379
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002380 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002381 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002382 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002383 }
Harald Welte70767382018-02-21 12:16:40 +01002384
2385 f_est_dchan();
2386
2387 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2388 * RSL measurement reports on Abis side */
2389 timer T := 8.0;
2390 T.start;
2391 alt {
2392 [] as_l1_sacch();
2393 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002394 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002395 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002396 [] L1CTL.receive { repeat; }
2397 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002398 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002399 * of any earlier errors, so if we reach this timeout, we're good */
2400 setverdict(pass);
2401 }
2402 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002404 }
2405 }
2406 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002407 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002408}
Harald Welte0472ab42018-03-12 15:02:26 +01002409
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002410/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2411private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002412 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002413 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2414 timer Tup := 10.0;
2415 Tup.start;
2416 alt {
2417 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2418 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2419 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002420
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002421 if (rx_lvl != max_rx_lvl) {
2422 repeat;
2423 }
2424 Tup.stop;
2425 }
2426 [] L1CTL.receive { repeat; }
2427 [] Tup.timeout {
2428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2429 log2str("Didn't reach full power ", max_rx_lvl));
2430 }
2431 }
2432 return max_rx_lvl;
2433}
2434
2435/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2436private function f_verify_ramp_up() runs on ConnHdlr {
2437 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002438 var integer initial_rx_lvl := -1;
2439 var integer last_rx_lvl := -1;
2440 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2441
2442 timer T := 2.0;
2443 alt {
2444 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2445 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2446 log("Received rx_level=", rx_lvl);
2447 if (initial_rx_lvl == -1) {
2448 initial_rx_lvl := rx_lvl;
2449 last_rx_lvl := rx_lvl;
2450
2451 /* Expect a somehow low value during first received messages */
2452 if (initial_rx_lvl >= max_rx_lvl / 2) {
2453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2454 log2str("Detected high initial tx power during ramp up: ",
2455 initial_rx_lvl , ", full power is", max_rx_lvl));
2456 }
2457 }
2458
2459 /* received Rx level bigger than maximum allowed power by CN */
2460 if (rx_lvl > max_rx_lvl) {
2461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2462 log2str("Detected Tx power higher than full power: ",
2463 rx_lvl , " > ", max_rx_lvl));
2464 }
2465
2466 /* Make sure it never decreases, since we are rumping up */
2467 if (last_rx_lvl > rx_lvl) {
2468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2469 log2str("Detected Tx power decrease during ramp up: ",
2470 last_rx_lvl , " -> ", rx_lvl));
2471 }
2472
2473 if (rx_lvl == max_rx_lvl and not T.running) {
2474 /* We reached the maximum power, start timer and receive
2475 /* a few more to make sure we don't surpass it */
2476 log("Reached full power, wating a bit more until success");
2477 T.start;
2478 }
2479
2480 last_rx_lvl := rx_lvl;
2481 repeat;
2482 }
2483 [] L1CTL.receive { repeat; }
2484 [] T.timeout { }
2485 }
2486
2487 /* We didn't increase tx power during ramp up */
2488 if (initial_rx_lvl < last_rx_lvl) {
2489 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2490 } else {
2491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2492 log2str("No Tx power increase during whole ramp up: ",
2493 initial_rx_lvl , " -> ", last_rx_lvl));
2494 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002495}
2496
2497/* verify BTS ramps power down to rx_level 0 */
2498private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2499 var L1ctlDlMessage l1_dl;
2500 var integer last_rx_lvl := max_rx_lvl;
2501
2502 timer Tdown := 5.0;
2503 Tdown.start;
2504 alt {
2505 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2506 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2507 log("Received rx_level=", rx_lvl);
2508
2509 /* received Rx level bigger than maximum allowed power by CN */
2510 if (rx_lvl > max_rx_lvl) {
2511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2512 log2str("Detected Tx power higher than full power: ",
2513 rx_lvl , " > ", max_rx_lvl));
2514 }
2515
2516 /* Make sure it never increases, since we are rumping down */
2517 if (last_rx_lvl < rx_lvl) {
2518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2519 log2str("Detected Tx power increase during ramp up: ",
2520 last_rx_lvl , " -> ", rx_lvl));
2521 }
2522
2523 last_rx_lvl := rx_lvl;
2524 if (last_rx_lvl != 0) {
2525 repeat;
2526 }
2527 /* we reached power level 0, we are done */
2528 Tdown.stop;
2529 }
2530 [] L1CTL.receive { repeat; }
2531 [] Tdown.timeout { }
2532 }
2533
2534 /* We didn't increase tx power during ramp down */
2535 if (max_rx_lvl > last_rx_lvl) {
2536 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2537 } else {
2538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2539 log2str("No Tx power decrease during whole ramp down: ",
2540 max_rx_lvl , " -> ", last_rx_lvl));
2541 }
2542}
2543
2544/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002545private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002546 f_l1_tune(L1CTL);
2547 RSL.clear;
2548
2549 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002550
2551 setverdict(pass);
2552}
2553testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2554 var ConnHdlr vc_conn;
2555 var ConnHdlrPars pars;
2556 f_init();
2557 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2558 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2559 pcu_comp := false, trxc_comp := true);
2560 vc_conn.done;
2561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2562}
2563
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002564/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002565private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002566 f_connhdlr_init_vty_bsc();
2567
2568 f_l1_tune(L1CTL);
2569 RSL.clear;
2570
2571 /* Wait until BTS is started and at full power */
2572 var integer max_rx_lvl := f_wait_ramp_up();
2573 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2574
2575 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2576 f_verify_ramp_down(max_rx_lvl);
2577
2578 setverdict(pass);
2579}
2580testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2581 var ConnHdlr vc_conn;
2582 var ConnHdlrPars pars;
2583 f_init();
2584 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2585 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2586 pcu_comp := false, trxc_comp := true);
2587 vc_conn.done;
2588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2589}
2590
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002591/* Verify Tx power:
2592 * + ramping down during ADM state UNLOCKED->LOCKED
2593 * + ramping up during ADM state LOCKED->UNLOCKED
2594 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002595private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002596 var L1ctlDlMessage l1_dl;
2597 var integer last_rx_lvl;
2598
2599 f_connhdlr_init_vty_bsc();
2600
2601 f_l1_tune(L1CTL);
2602 RSL.clear;
2603
2604 /* Wait until BTS is started and at full power */
2605 var integer max_rx_lvl := f_wait_ramp_up();
2606 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2607
2608 log("ADM STATE UNLOCKED->LOCKED");
2609 f_vty_enter_cfg_trx(BSCVTY);
2610 f_vty_transceive(BSCVTY, "rf_locked 1");
2611 last_rx_lvl := max_rx_lvl;
2612 f_verify_ramp_down(max_rx_lvl);
2613
2614 /* Let some time after we received 0dBm, then check we don't receive BCCH
2615 * anymore because scheduler has stopped after ramping down */
2616 f_sleep(2.0);
2617 L1CTL.clear;
2618 timer Tlocked := 2.0;
2619 Tlocked.start;
2620 alt {
2621 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2623 log2str("Received data_ind during rf_locked: ", l1_dl));
2624 }
2625 [] L1CTL.receive { repeat; }
2626 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2627 }
2628
2629 log("ADM STATE LOCKED->UNLOCKED");
2630 f_vty_transceive(BSCVTY, "rf_locked 0");
2631 f_verify_ramp_up();
2632 setverdict(pass);
2633}
2634testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2635 var ConnHdlr vc_conn;
2636 var ConnHdlrPars pars;
2637 f_init();
2638 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2639 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2640 pcu_comp := false, trxc_comp := true);
2641 vc_conn.done;
2642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2643}
2644
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002645private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002646 timer T := 8.0;
2647 T.start;
2648 var RSL_Message rsl;
2649 alt {
2650 [] as_l1_sacch();
2651 [] L1CTL.receive { repeat; }
2652 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2653 if (rsl.ies[3].body.bs_power.power_level == level) {
2654 setverdict(pass)
2655 } else {
2656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2657 }
2658 }
2659 [] T.timeout {
2660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2661 }
2662 }
2663}
2664
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002665/* See if the RSL MEASurement RESult contains expeced BS power level
2666 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002667private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002668 f_l1_tune(L1CTL);
2669 RSL.clear;
2670
2671 if (mp_bts_trxc_port != -1) {
2672 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2673 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2674 }
2675
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002676 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002677 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2678 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2679
2680 f_est_dchan(more_ies :={valueof(pwr)});
2681
2682 f_check_meas_bs_power_level(pwr_var);
2683
2684 f_rsl_chan_deact();
2685 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2686}
2687
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002688/* See if the RSL MEASurement RESult contains expeced BS power level
2689 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002690private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002691 f_l1_tune(L1CTL);
2692 RSL.clear;
2693
2694 if (mp_bts_trxc_port != -1) {
2695 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2696 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2697 }
2698
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002699 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002700 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2701
2702 f_est_dchan();
2703
2704 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2705
2706 f_check_meas_bs_power_level(pwr_var);
2707
2708 f_rsl_chan_deact();
2709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2710}
2711
2712testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2713 var ConnHdlr vc_conn;
2714 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002715
Eric Wildae8f2622019-06-18 17:05:11 +02002716 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002717
2718 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2719 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2720 pcu_comp := false, trxc_comp := true);
2721 vc_conn.done;
2722
Eric Wildae8f2622019-06-18 17:05:11 +02002723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2724}
2725
2726testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2727 var ConnHdlr vc_conn;
2728 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002729
Eric Wildae8f2622019-06-18 17:05:11 +02002730 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002731
2732 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2733 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2734 pcu_comp := false, trxc_comp := true);
2735 vc_conn.done;
2736
Eric Wildae8f2622019-06-18 17:05:11 +02002737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2738}
2739
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002740/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2741 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2742 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002743private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002744 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002745 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002746
2747 f_trxc_fake_rssi(rxlev2dbm(10));
2748 f_l1_tune(L1CTL);
2749 RSL.clear;
2750
2751 var RSL_IE_List addl_ies;
2752 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2753
2754 addl_ies := {
2755 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2756 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2757 };
2758
2759 /* establish with power parameters */
2760 f_est_dchan(more_ies := addl_ies);
2761
2762 /* set a high value to ensure L1 power control level increases */
2763 f_trxc_fake_rssi(rxlev2dbm(20));
2764
2765 timer T2 := 6.0;
2766 T2.start;
2767 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002768 [] as_l1_sacch_l1h(l1h) {
2769 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002770 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002771 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002772 T2.stop;
2773 }
2774 [] L1CTL.receive { repeat; }
2775 [] T2.timeout {
2776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2777 "Power Level in L1 header has not increased sufficiently");
2778 }
2779 }
2780
2781 /* set a low value to ensure L1 power control level decreases */
2782 f_trxc_fake_rssi(rxlev2dbm(0));
2783
2784 timer T4 := 6.0;
2785 T4.start;
2786 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002787 [] as_l1_sacch_l1h(l1h) {
2788 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002789 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002790 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002791 T4.stop;
2792 setverdict(pass, "Power level in L1 decreased/increased as expected");
2793 }
2794 [] L1CTL.receive { repeat; }
2795 [] T4.timeout {
2796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2797 "Power Level in L1 header has not decreased sufficiently");
2798 }
2799 }
2800
2801 f_rsl_chan_deact();
2802 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2803
2804}
2805
2806/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002807private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002808 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002809 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002810
2811 /* set a low value to ensure power increases */
2812 f_trxc_fake_rssi(rxlev2dbm(10));
2813 f_l1_tune(L1CTL);
2814 RSL.clear;
2815
2816 var RSL_IE_List addl_ies;
2817 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2818
2819 addl_ies := {
2820 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2821 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2822 };
2823
2824 /* establish with power parameters */
2825 f_est_dchan(more_ies := addl_ies);
2826
2827 timer T1 := 10.0;
2828 T1.start;
2829 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002830 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002831 [] L1CTL.receive { repeat; }
2832 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002833 if (not isbound(l1h)) {
2834 setverdict(fail, "No SACCH blocks were received");
2835 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002836 setverdict(fail, "Power level in L1 header should not have changed");
2837 }
2838 }
2839 }
2840
2841 f_rsl_chan_deact();
2842 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2843
2844}
2845
2846/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002847private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002848 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002849 var uint5_t pwr_var := 15;
2850 var uint5_t pwr_max_var := f_get_max_power_from_band();
2851
2852 /* set a low value to ensure power increases */
2853 f_trxc_fake_rssi(rxlev2dbm(10));
2854 f_l1_tune(L1CTL);
2855 RSL.clear;
2856
2857 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2858 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2859
2860 /* establish with fixed power level */
2861 f_est_dchan(more_ies :={valueof(pwr)});
2862
2863 /* check our initial power level */
2864 f_wait_for_l1_power_level(pwr_var);
2865
2866 /* update power param to enable power loop
2867 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2868 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2869
2870 /* wait, then check that our power level was reduced */
2871 timer T1 := 10.0;
2872 T1.start;
2873 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002874 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002875 [] L1CTL.receive { repeat; }
2876 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002877 if (not isbound(l1h)) {
2878 setverdict(fail, "No SACCH blocks were received");
2879 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002880 setverdict(pass, "Power level in L1 header reduced as expected");
2881 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002882 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2883 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002884 }
2885 }
2886 }
2887
2888 f_rsl_chan_deact();
2889 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2890
2891}
2892
2893/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002894private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002895 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002896
2897 /* set a high value to ensure power decreases */
2898 f_trxc_fake_rssi(rxlev2dbm(50));
2899 f_l1_tune(L1CTL);
2900 RSL.clear;
2901
2902 var uint5_t pwr_var := 5;
2903 var uint5_t pwr_target_val := 15;
2904
2905 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2906 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2907
2908 /* establish with fixed power level */
2909 f_est_dchan(more_ies :={valueof(pwr)});
2910
2911 /* check our initial power level */
2912 f_wait_for_l1_power_level(pwr_var);
2913
2914 /* update power param to enable power loop
2915 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002916 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002917
2918 /* wait, then check that our power level was increased */
2919 timer T1 := 10.0;
2920 T1.start;
2921 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002922 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002923 [] L1CTL.receive { repeat; }
2924 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002925 if (not isbound(l1h)) {
2926 setverdict(fail, "No SACCH blocks were received");
2927 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2928 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002929 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002930 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002931 }
2932 }
2933 }
2934
2935 f_rsl_chan_deact();
2936 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2937
2938}
2939
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002940/* See if the power level remains constant when MS Power Parameters IE
2941 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002942private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002943 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002944
2945 /* set a high value to ensure power decreases */
2946 f_trxc_fake_rssi(rxlev2dbm(50));
2947 f_l1_tune(L1CTL);
2948 RSL.clear;
2949
2950 var uint5_t pwr_var := 5;
2951
2952 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2953 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2954
2955 /* establish with fixed power level */
2956 f_est_dchan(more_ies :={valueof(pwr)});
2957
2958 /* check our initial power level */
2959 f_wait_for_l1_power_level(pwr_var);
2960
2961 /* wait, then check that our power level did not change */
2962 timer T1 := 10.0;
2963 T1.start;
2964 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002965 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2966 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2968 "BS power control should not be active unless we receive a power parameters IE!");
2969 }
2970 repeat;
2971 }
2972 [] L1CTL.receive { repeat; }
2973 [] T1.timeout { setverdict(pass); }
2974 }
2975
2976 f_rsl_chan_deact();
2977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2978
2979}
2980
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002981/* See if the power level remains constant when MS Power Parameters IE
2982 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002983private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002984 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002985
2986 /* set a high value to ensure power decreases */
2987 f_trxc_fake_rssi(rxlev2dbm(50));
2988 f_l1_tune(L1CTL);
2989 RSL.clear;
2990
2991 var uint5_t pwr_var := 5;
2992
2993 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2994 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2995
2996 /* establish with fixed power level */
2997 f_est_dchan(more_ies :={valueof(pwr)});
2998
2999 /* check our initial power level */
3000 f_wait_for_l1_power_level(pwr_var);
3001
3002 /* pwr control without power params IE, should NOT activate MS power control*/
3003 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3004
3005 /* wait, then check that our power level did not change */
3006 timer T1 := 10.0;
3007 T1.start;
3008 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003009 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3010 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3012 "BS power control should not be active unless we receive a power parameters IE!");
3013 }
3014 repeat;
3015 }
3016 [] L1CTL.receive { repeat; }
3017 [] T1.timeout { setverdict(pass); }
3018 }
3019
3020 f_rsl_chan_deact();
3021 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3022
3023}
3024
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003025private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003026 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003027 timer T0 := 10.0;
3028 T0.start;
3029 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003030 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3031 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3033 "Power level in L1 header != signaled (RSL) power level.");
3034 }
3035 }
3036 [] L1CTL.receive { repeat; }
3037 [] T0.timeout {
3038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3039 "Timeout waiting for initial power level");
3040 }
3041 }
3042 T0.stop;
3043}
3044
3045private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3046 var IntegerRecord min_dbm_level;
3047 var IntegerRecord max_dbm_level;
3048 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3049
3050 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3051 if (min_dbm_level[i] == level) {
3052 return true;
3053 }
3054 }
3055 return false;
3056}
3057
3058private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3059 var IntegerRecord min_dbm_level;
3060 var IntegerRecord max_dbm_level;
3061 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3062
3063 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3064 if (max_dbm_level[i] == level) {
3065 return true;
3066 }
3067 }
3068 return false;
3069}
3070
3071private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3072 var IntegerRecord min_dbm_level;
3073 var IntegerRecord max_dbm_level;
3074 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3075 return max_dbm_level[0];
3076}
3077
3078type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003079private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003080private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3081 // 45.005 4.1.1
3082 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3083 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3084 2, 1, 0};
3085 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3086 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3087 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3088 var IntegerRecord rv;
3089
3090 select(band){
3091 case (BtsBand_allGSM){
3092 rv := gsm_power;
3093 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3094 max_dbm_level := {2, 1, 0};
3095 }
3096 case("DCS1800"){
3097 rv := dcs_power;
3098 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3099 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3100 }
3101 case("PCS1900"){
3102 rv := pcs_power;
3103 min_dbm_level := {15};
3104 max_dbm_level := {30};
3105 }
Harald Welte194b6912020-10-11 21:01:55 +02003106 case else {
3107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3108 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003109 }
3110
3111 return rv;
3112}
3113
3114private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003115 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 +02003116}
3117
3118testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3119 var ConnHdlr vc_conn;
3120 var ConnHdlrPars pars;
3121 f_init();
3122 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3123 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3124 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3125 pars.bts0_band := f_vty_get_bts0_band();
3126 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3127 vc_conn.done;
3128 }
3129 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3130 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3131}
3132
3133testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3134 var ConnHdlr vc_conn;
3135 var ConnHdlrPars pars;
3136 f_init();
3137 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3138 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3139 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3140 pars.bts0_band := f_vty_get_bts0_band();
3141 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3142 vc_conn.done;
3143 }
3144 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3146}
3147
3148testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3149 var ConnHdlr vc_conn;
3150 var ConnHdlrPars pars;
3151 f_init();
3152 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3153 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3154 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3155 pars.bts0_band := f_vty_get_bts0_band();
3156 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3157 vc_conn.done;
3158 }
3159 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3161}
3162
3163testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3164 var ConnHdlr vc_conn;
3165 var ConnHdlrPars pars;
3166 f_init();
3167 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3168 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3169 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3170 pars.bts0_band := f_vty_get_bts0_band();
3171 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3172 vc_conn.done;
3173 }
3174 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3176}
3177
Eric Wild280ccb82019-06-17 11:11:52 +02003178testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3179 var ConnHdlr vc_conn;
3180 var ConnHdlrPars pars;
3181 f_init();
3182 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3183 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3184 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3185 pars.bts0_band := f_vty_get_bts0_band();
3186 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3187 vc_conn.done;
3188 }
3189 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3191}
3192
Eric Wild095024b2019-06-17 15:08:57 +02003193testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3194 var ConnHdlr vc_conn;
3195 var ConnHdlrPars pars;
3196 f_init();
3197 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3198 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3199 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3200 pars.bts0_band := f_vty_get_bts0_band();
3201 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3202 vc_conn.done;
3203 }
3204 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3206}
3207
Philipp Maier149c3922020-10-22 17:29:36 +02003208function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003209 var template RSL_IE_ChannelMode ch_mode;
3210 var ConnHdlr vc_conn;
3211 var ConnHdlrPars pars;
3212 f_init();
3213 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3214 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3215 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003216 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003217 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3218 pcu_comp := false, trxc_comp := true);
3219 vc_conn.done;
3220 }
3221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3222}
Philipp Maier149c3922020-10-22 17:29:36 +02003223
3224testcase TC_meas_res_speech_tchf() runs on test_CT {
3225 f_TC_meas_res_speech_tchf(false);
3226}
3227
3228testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3229 f_TC_meas_res_speech_tchf(true);
3230}
3231
3232function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003233 var template RSL_IE_ChannelMode ch_mode;
3234 var ConnHdlr vc_conn;
3235 var ConnHdlrPars pars;
3236 f_init();
3237 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3238 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3239 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003240 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003241 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3242 pcu_comp := false, trxc_comp := true);
3243 vc_conn.done;
3244 }
3245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3246}
Philipp Maier149c3922020-10-22 17:29:36 +02003247
3248testcase TC_meas_res_speech_tchh() runs on test_CT {
3249 f_TC_meas_res_speech_tchh(false)
3250}
3251
3252testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3253 f_TC_meas_res_speech_tchh(true)
3254}
3255
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003256testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3257 var template RSL_IE_ChannelMode ch_mode;
3258 var ConnHdlr vc_conn;
3259 var ConnHdlrPars pars;
3260 f_init();
3261 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3262 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3263 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3264 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3265 pars.l1_pars.toa256_enabled := true;
3266 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3267 pcu_comp := false, trxc_comp := true);
3268 vc_conn.done;
3269 }
3270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3271}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003272
Harald Welte70767382018-02-21 12:16:40 +01003273testcase TC_meas_res_sign_tchf() 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 tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003279 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003280 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}
3286testcase TC_meas_res_sign_tchh() runs on test_CT {
3287 var ConnHdlr vc_conn;
3288 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003289 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003290 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003291 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)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003293 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3294 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003295 vc_conn.done;
3296 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003297 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003298}
3299testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3300 var ConnHdlr vc_conn;
3301 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003302 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003303 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003304 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3305 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003306 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3307 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003308 vc_conn.done;
3309 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003311}
3312testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3313 var ConnHdlr vc_conn;
3314 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003315 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003316 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003317 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3318 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003319 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3320 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003321 vc_conn.done;
3322 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003324}
Harald Welte685d5982018-02-27 20:42:05 +01003325testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3326 var ConnHdlr vc_conn;
3327 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003328 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003329 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3330 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003331 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003332 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003333 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3334 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003335 vc_conn.done;
3336 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003338}
3339
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003340/* Make sure that we always get RSL MEASurement RESult messages regardless
3341 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3342private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3343 timer Texec := 8.0;
3344 timer Timpf := 2.0;
3345 timer Tmr;
3346
3347 f_l1_tune(L1CTL);
3348 RSL.clear;
3349
3350 f_est_dchan();
3351 L1CTL.clear;
3352
3353 /* Establish the main SAPI=0 link on DCCH first */
3354 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3355
3356 /* Give more time for the first RSL MEASurement RESult */
3357 Tmr.start(0.480 * 2.0);
3358 Texec.start; /* EXECution timer */
3359 Timpf.start; /* IMPFung timer */
3360
3361 alt {
3362 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3363 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3364 /* Reschedule the MEAS RES timer */
3365 Tmr.start(0.480 + 0.120);
3366 repeat;
3367 }
3368 [] RSL.receive { repeat; }
3369 [] Tmr.timeout {
3370 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3371 }
3372 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3373 [] Timpf.timeout {
3374 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3375 log("Injected SAPI=3 traffic on SACCH");
3376 Timpf.start;
3377 repeat;
3378 }
3379 /* We're good if survived so far */
3380 [] Texec.timeout {
3381 setverdict(pass);
3382 }
3383 }
3384
3385 f_rsl_chan_deact();
3386 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3387 f_rslem_unregister(0, g_chan_nr);
3388}
3389testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3390 var template RSL_IE_ChannelMode ch_mode;
3391 var template ConnHdlrPars pars;
3392 var ConnHdlr vc_conn;
3393
3394 f_init();
3395
3396 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3397 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3398
3399 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3400 vc_conn.done;
3401
3402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3403}
3404testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3405 var template RSL_IE_ChannelMode ch_mode;
3406 var template ConnHdlrPars pars;
3407 var ConnHdlr vc_conn;
3408
3409 f_init();
3410
3411 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3412 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3413
3414 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3415 vc_conn.done;
3416
3417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3418}
3419
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003420/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3421 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003422private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003423 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003424 var RSL_IE_MS_Power ms_power;
3425 var RSL_Message rsl;
3426 var uint5_t power_level := 0;
3427
3428 f_l1_tune(L1CTL);
3429 RSL.clear;
3430
3431 f_est_dchan();
3432
3433 ms_power.reserved := 0;
3434 ms_power.fpc_epc := false;
3435
3436 /* Send the first power control command. This will disable any BTS/TRX
3437 * internal power control and switch the MS (which is not in scope of
3438 * this test) to a constant power level. We start with a power level
3439 * of 0 */
3440 ms_power.power_level := power_level;
3441 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3442 RSL.send(rsl);
3443
3444 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003445 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3446 if (l1h.ms_power_lvl != power_level) {
3447 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3448 "match the signaled (RSL) power level := ", power_level);
3449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003450 }
3451
3452 /* Signal a new power level via RSL for the next turn. */
3453 if (power_level < 31) {
3454 power_level := power_level + 1;
3455 ms_power.power_level := power_level;
3456 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3457 RSL.send(rsl);
3458 repeat;
3459 }
3460
3461 }
3462
3463 /* Ignore all other blocks */
3464 [] L1CTL.receive { repeat; }
3465
3466 }
3467
3468 f_rsl_chan_deact();
3469 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3470
3471 setverdict(pass);
3472}
3473
3474testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3475 var ConnHdlr vc_conn;
3476 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003477 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003478
3479 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3480 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3481 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3482 vc_conn.done;
3483 }
3484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3485}
Harald Welte70767382018-02-21 12:16:40 +01003486
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003487/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003488TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003489private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003490 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003491 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003492
3493 f_l1_tune(L1CTL);
3494 RSL.clear;
3495
3496 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003497 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003498
3499 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3500
3501
3502 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003503 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3504 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003505 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3506 }
3507
3508 }
3509
3510 /* Ignore all other blocks */
3511 [] L1CTL.receive { repeat; }
3512
3513 }
3514
3515 f_rsl_chan_deact();
3516 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3517
3518 setverdict(pass);
3519}
3520
3521testcase TC_rsl_chan_initial_ta() runs on test_CT {
3522 var ConnHdlr vc_conn;
3523 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003524 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003525 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003526 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3527 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003528 vc_conn.done;
3529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3530}
3531
Eric Wilde57e1a62019-05-28 13:30:55 +02003532/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003533private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003534 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003535 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003536
3537 var RSL_IE_MS_Power ms_power;
3538 ms_power.reserved := 0;
3539 ms_power.fpc_epc := false;
3540 ms_power.power_level := ms_power_level;
3541
3542 f_l1_tune(L1CTL);
3543 RSL.clear;
3544
3545 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3546
3547 timer T := 1.0;
3548 T.start;
3549 alt {
3550 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003551 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3552 if (l1h.ms_power_lvl != ms_power_level) {
3553 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3554 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003555 }
3556 }
3557 /* Ignore all other blocks */
3558 [] L1CTL.receive { repeat; }
3559 [] T.timeout {
3560 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3561 }
3562 }
3563
3564 f_rsl_chan_deact();
3565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3566 setverdict(pass);
3567}
3568
3569testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3570 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3571 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3572}
3573
Harald Welte0472ab42018-03-12 15:02:26 +01003574/* 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 +01003575private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003576 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003577 RSL.clear;
3578
3579 f_est_dchan();
3580 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003581 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003582
3583 timer T := 40.0;
3584 T.start;
3585 alt {
3586 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3587 setverdict(pass)
3588 }
3589 [] RSL.receive { repeat };
3590 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003592 }
3593 }
3594 f_rsl_chan_deact();
3595}
3596testcase TC_conn_fail_crit() runs on test_CT {
3597 var ConnHdlr vc_conn;
3598 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003599 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003600 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3601 pars.t_guard := 60.0;
3602 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3603 vc_conn.done;
3604}
3605
Harald Welte93640c62018-02-25 16:59:33 +01003606/***********************************************************************
3607 * Paging
3608 ***********************************************************************/
3609
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003610private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003611 if (tmsi == 'FFFFFFFF'O) {
3612 return true;
3613 } else {
3614 return false;
3615 }
3616}
Harald Welte70767382018-02-21 12:16:40 +01003617
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003618private type record allowedFn { integer frame_nr }
3619private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3620private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3621private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3622private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3623private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3624private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3625private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3626private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3627private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003628{
3629 var integer frame_nr_51;
3630 frame_nr_51 := frame_nr mod 51
3631
3632 var allowedFn fn_check;
3633 fn_check.frame_nr := frame_nr_51;
3634
3635 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003637 return;
3638 }
3639
3640 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3641 return;
3642 }
3643 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3644 return;
3645 }
3646 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3647 return;
3648 }
3649 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3650 return;
3651 }
3652 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3653 return;
3654 }
3655 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3656 return;
3657 }
3658 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3659 return;
3660 }
3661 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3662 return;
3663 }
3664
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003666 return;
3667}
3668
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003669private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3670 inout integer num_paging_rcv_ids,
3671 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003672runs on test_CT {
3673 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003674 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003675 repeat;
3676 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003677 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003678 var octetstring without_plen :=
3679 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3680 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003681
3682 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3683
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003684 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3685 /* Ignore empty RR Paging Request (PCH filling) messages.
3686 * TODO: does it make sense to count them? */
3687 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003688 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3689 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003690 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003691 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3692 }
3693 } else if (match(rr, tr_PAGING_REQ2)) {
3694 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3695 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3696 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3697 }
3698 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3699 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3700 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003701 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003702 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3703 }
3704 } else if (match(rr, tr_PAGING_REQ3)) {
3705 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3706 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3707 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3708 }
3709 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3710 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3711 }
3712 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3713 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3714 }
3715 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3716 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3717 }
3718 }
3719 repeat;
3720 }
3721}
3722
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003723private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003724 boolean combined_ccch,
3725 integer bs_ag_blks_res,
3726 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003727 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3728 * paging command that is issued via RSL. */
3729 integer ps_load_modulus,
3730 /* Wait until the paging queue inside the BTS is congested before starting to add
3731 * pagings via the PCU socket (0 = disabled) */
3732 boolean ps_wait_cong,
3733 /* Maximum time to wait until the paging queue is drained at the end of the test.
3734 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3735 * to set this value to 18s, however the draining process may take significantly
3736 * longer when the queue contains paging requests for PS as those are implemented
3737 * as immediate assignments and require an entire MAC block alone. */
3738 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003739 boolean exp_load_ind,
3740 boolean exp_overload,
3741 boolean use_tmsi
3742}
3743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003744private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003745 integer num_paging_sent,
3746 integer num_paging_rcv_msgs,
3747 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003748 integer num_overload,
3749 /* When free space inside the paging queue reaches more than 2 thirds
3750 * of its capacity cong_detected is set to true. */
3751 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003752}
3753
Harald Welte68e495b2018-02-25 00:05:57 +01003754/* Helper function for paging related testing */
3755private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003756 /* Using the PCU socket affects the timing of the paging processing. We only
3757 * activate the PCU socket if we do paging load tests that include additional
3758 * paging load that is introduced through the PCU socket. */
3759 if (cfg.ps_load_modulus > 0) {
3760 f_init_with_pcuif();
3761 } else {
3762 f_init();
3763 }
Harald Welte68e495b2018-02-25 00:05:57 +01003764 f_init_l1ctl();
3765 f_l1_tune(L1CTL);
3766
Philipp Maierca058272021-06-23 10:35:23 +02003767 var octetstring imm_ass := f_rnd_octstring(23);
3768 var ASP_RSL_Unitdata load_ind;
3769
Harald Welte68e495b2018-02-25 00:05:57 +01003770 var PagingTestState st := {
3771 num_paging_sent := 0,
3772 num_paging_rcv_msgs := 0,
3773 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003774 num_overload := 0,
3775 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003776 };
3777
3778 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3779 var float max_pch_imsi_per_sec;
3780 if (cfg.use_tmsi) {
3781 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3782 } else {
3783 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3784 }
3785 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3786 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003787 var float time_total := 20.0;
3788 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3789 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003790
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003791 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3792 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003793
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003794 timer T_itv := 0.0;
3795 T_itv.start;
3796 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003797 alt {
3798 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003799 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003800 st.num_overload := st.num_overload + 1;
3801 repeat;
3802 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003803 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003805 }
Philipp Maierca058272021-06-23 10:35:23 +02003806 [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 +01003807 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003808
3809 /* Detect paging congestion: The logic inside the BTS will diagnose the
3810 * paging queue as congested when the fill state is more than 66% (which
3811 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3812 * paging congestion is detected pagings that are issued through the PCU
3813 * socket (PS) are dropped in order to prefer the CS related pagings. */
3814 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3815 st.cong_detected := true;
3816 }
3817
Harald Welte68e495b2018-02-25 00:05:57 +01003818 /* FIXME: analyze/verify interval + contents */
3819 repeat;
3820 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003821 /* ignore other RSL messages like RF RESource INDication */
3822 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003823 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003824 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003825 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003826 /* Only relevant when testing including with PCU sock connected */
3827 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003828 [] T_itv.timeout {
3829 /* Send paging cmds based on elapsed time */
3830 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3831 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003832 var MobileIdentityV mi;
3833
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003834 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003835 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003836 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003837 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003838 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003839 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003840
3841 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003842 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 +02003843
Philipp Maierca058272021-06-23 10:35:23 +02003844 /* Add additional pagings through the PCU socket interface. */
3845 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3846 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3847 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3848 }
3849 }
3850
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003851 st.num_paging_sent := st.num_paging_sent + 1;
3852 }
3853 if (st.num_paging_sent < pkt_total) {
3854 /* Wait for interval to next PAGING COMMAND */
3855 var float time_now := T_total.read;
3856 var float next_sched := int2float(st.num_paging_sent)*interval;
3857 if (next_sched > time_now) {
3858 T_itv.start(next_sched - time_now);
3859 } else {
3860 T_itv.start(0.0);
3861 }
3862 } else {
3863 /* We are done, no need to keep counting */
3864 T_total.stop;
3865 }
3866 }
3867 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003868 }
3869 }
3870
Philipp Maierca058272021-06-23 10:35:23 +02003871 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003872 T_wait.start;
3873 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003874 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003875 [] L1CTL.receive { repeat; }
3876 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003877 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003878 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003879 /* ignore other RSL messages like RF RESource INDication */
3880 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003881 /* Only relevant when testing including with PCU sock connected */
3882 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003883 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003884 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 +01003885 }
Harald Welte68e495b2018-02-25 00:05:57 +01003886 }
3887
3888 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3889 " rcvd_ids=", st.num_paging_rcv_ids);
3890 return st;
3891}
3892
3893/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3894 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3895 * - that CCCH LOAD IND (PCH) are being generated
3896 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3897testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003898 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003899 var PagingTestCfg cfg := {
3900 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003901 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003902 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003903 ps_load_modulus := 0,
3904 ps_wait_cong := false,
3905 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003906 exp_load_ind := true,
3907 exp_overload := false,
3908 use_tmsi := false
3909 };
3910 var PagingTestState st := f_TC_paging(cfg);
3911 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3913 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003914 } else {
3915 setverdict(pass);
3916 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003918}
3919
3920/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3921 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3922 * - that CCCH LOAD IND (PCH) are being generated
3923 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3924testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003925 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003926 var PagingTestCfg cfg := {
3927 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003928 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003929 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003930 ps_load_modulus := 0,
3931 ps_wait_cong := false,
3932 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003933 exp_load_ind := true,
3934 exp_overload := false,
3935 use_tmsi := true
3936 };
3937 var PagingTestState st := f_TC_paging(cfg);
3938 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3940 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003941 } else {
3942 setverdict(pass);
3943 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003945}
3946
3947/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3948 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3949 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3950 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3951testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003952 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003953 var PagingTestCfg cfg := {
3954 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003955 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003956 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003957 ps_load_modulus := 0,
3958 ps_wait_cong := false,
3959 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003960 exp_load_ind := true,
3961 exp_overload := true,
3962 use_tmsi := false
3963 };
3964 var PagingTestState st := f_TC_paging(cfg);
3965 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3966 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003967 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003968 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003969 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 +01003970 } else {
3971 setverdict(pass);
3972 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003974}
3975
3976/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3977 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3978 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3979 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3980testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003981 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003982 var PagingTestCfg cfg := {
3983 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003984 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003985 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003986 ps_load_modulus := 0,
3987 ps_wait_cong := false,
3988 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003989 exp_load_ind := true,
3990 exp_overload := true,
3991 use_tmsi := true
3992 };
3993 var PagingTestState st := f_TC_paging(cfg);
3994 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3995 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003996 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003997 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003998 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 +01003999 } else {
4000 setverdict(pass);
4001 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004003}
4004
Philipp Maierca058272021-06-23 10:35:23 +02004005/* Same as above, but with additional paging load created by PS pagings that
4006 * are issued through the PCU socket. The additional load is introduced when
4007 * the paging queue is already two thirds full. Since the BTS implements a
4008 * prioritization logic that drops the pagings from the PCU under in those
4009 * congestive sitautions the behaviour on the PS side is expected to be
4010 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4011testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4012 var SystemInformation si3 := valueof(ts_SI3_default);
4013 var PagingTestCfg cfg := {
4014 combined_ccch := true,
4015 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4016 load_factor := 2.0,
4017 ps_load_modulus := 16,
4018 ps_wait_cong := true,
4019 queue_drain_timeout := 18.0,
4020 exp_load_ind := true,
4021 exp_overload := true,
4022 use_tmsi := false
4023 };
4024 var PagingTestState st := f_TC_paging(cfg);
4025 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4026 * slots and will fully drain that buffer before returning */
4027 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4028 if (not match(st.num_paging_rcv_ids, tpl)) {
4029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4030 } else {
4031 setverdict(pass);
4032 }
4033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4034}
4035
4036
Harald Welte68e495b2018-02-25 00:05:57 +01004037
Harald Welte93640c62018-02-25 16:59:33 +01004038/***********************************************************************
4039 * Immediate Assignment / AGCH
4040 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004041private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004042 len := 0,
4043 ma := ''B
4044}
Harald Welte93640c62018-02-25 16:59:33 +01004045
Harald Weltee8d750e2018-06-10 21:41:35 +02004046private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4047 return int2str(num_tx) & " sent, "
4048 & int2str(num_rx) & " received, "
4049 & int2str(num_del) & " deleted";
4050}
4051
4052private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4053 var L1ctlDlMessage l1_dl;
4054 timer T := 10.0;
4055 var integer num_tx := 0;
4056 var integer num_rx := 0;
4057 var integer num_del := 0;
4058 var charstring res_str;
4059 var float rx_ratio;
4060
Harald Welte10474062019-05-30 16:48:17 +02004061 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004062 f_init_l1ctl();
4063 f_l1_tune(L1CTL);
4064
4065 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004066 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004067 mp_trx_pars[0].arfcn,
4068 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004069 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4070 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004071 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004072 num_tx := num_tx+1;
4073 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004074 }
4075 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004076 T.start;
4077 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004078 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004079 num_del := num_del+1;
4080 repeat;
4081 }
4082 [] RSL_CCHAN.receive {
4083 repeat;
4084 }
4085 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004086 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4087 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4088 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004089 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004090 } else {
4091 num_rx := num_rx+1;
4092 }
4093 repeat;
4094 }
4095 [] L1CTL.receive { repeat; }
4096 [] T.timeout { }
4097 }
4098 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4099 log("AGCH test: " & res_str);
4100 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004102 }
4103 rx_ratio := int2float(num_rx) / int2float(num_tx);
4104 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004105 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 +02004106 } else {
4107 setverdict(pass);
4108 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004110}
4111
Harald Weltee8d750e2018-06-10 21:41:35 +02004112/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4113testcase TC_imm_ass_1000_20ms() runs on test_CT {
4114 f_TC_imm_ass(1000, 0.02, 0.25);
4115}
4116
4117/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4118testcase TC_imm_ass_200_0ms() runs on test_CT {
4119 f_TC_imm_ass(200, 0.0, 0.05);
4120}
4121
4122/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4123testcase TC_imm_ass_200_76ms() runs on test_CT {
4124 f_TC_imm_ass(150, 0.076, 1.00);
4125}
4126
4127
4128
Harald Welte48494ca2018-02-25 16:59:50 +01004129/***********************************************************************
4130 * BCCH
4131 ***********************************************************************/
4132
4133/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004134private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004135 GsmFrameNumber frame_number,
4136 SystemInformation si
4137}
4138
4139/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004140private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004141
4142/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004143private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004144
4145/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004146private function f_si_vecslot_contains(SystemInformationVector arr,
4147 RrMessageType key,
4148 boolean bcch_ext := false)
4149return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004150 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4151 var integer fn_mod51 := arr[i].frame_number mod 51;
4152 if (not bcch_ext and fn_mod51 == 2 or
4153 bcch_ext and fn_mod51 == 6) {
4154 if (arr[i].si.header.message_type == key) {
4155 return true;
4156 }
4157 }
4158 }
4159 return false;
4160}
4161
4162/* 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 +07004163private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4164 integer tc, RrMessageType key,
4165 boolean ext_bcch := false)
4166{
Harald Welte48494ca2018-02-25 16:59:50 +01004167 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004169 }
4170}
4171
4172/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004173private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4174 RrMessageType key)
4175return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004176 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4177 if (f_si_vecslot_contains(arr[tc], key) or
4178 f_si_vecslot_contains(arr[tc], key, true)) {
4179 return true;
4180 }
4181 }
4182 return false;
4183}
4184
4185/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004186private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4187 RrMessageType key,
4188 boolean bcch_ext := false,
4189 integer n := 1, integer m := 4)
4190return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004191 var integer count := 0;
4192 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4194 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004195 }
4196 for (var integer i:= 0; i < m; i := i + 1) {
4197 var integer fn_mod51 := arr[i].frame_number mod 51;
4198 if (not bcch_ext and fn_mod51 == 2 or
4199 bcch_ext and fn_mod51 == 6) {
4200 if (arr[i].si.header.message_type == key) {
4201 count := count + 1;
4202 }
4203 }
4204 }
4205 if (count >= n) {
4206 return true;
4207 } else {
4208 return false;
4209 }
4210}
4211
4212/* 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 +07004213private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4214 integer tc, RrMessageType key,
4215 boolean ext_bcch := false,
4216 integer n, integer m)
4217{
Harald Welte48494ca2018-02-25 16:59:50 +01004218 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004220 }
4221}
4222
4223/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004224private function f_si_vecslot_contains_only(SystemInformationVector arr,
4225 RrMessageType key,
4226 boolean bcch_ext := false)
4227return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004228 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4229 var integer fn_mod51 := arr[i].frame_number mod 51;
4230 if (not bcch_ext and fn_mod51 == 2 or
4231 bcch_ext and fn_mod51 == 6) {
4232 if (arr[i].si.header.message_type != key) {
4233 return false;
4234 }
4235 }
4236 }
4237 return true;
4238}
4239
4240/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004241private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4242 integer tc, RrMessageType key,
4243 boolean ext_bcch := false)
4244{
Harald Welte48494ca2018-02-25 16:59:50 +01004245 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004247 }
4248}
4249
4250/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004251private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004252 boolean bcch_extended,
4253 boolean si1_present,
4254 boolean si2bis_present,
4255 boolean si2ter_present,
4256 boolean si2quater_present,
4257 boolean si7_present,
4258 boolean si8_present,
4259 boolean si9_present,
4260 boolean si13_present,
4261 boolean si13alt_present,
4262 boolean si15_present,
4263 boolean si16_present,
4264 boolean si17_present,
4265 boolean si2n_present,
4266 boolean si21_present,
4267 boolean si22_present
4268}
4269
4270/* 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 +07004271private function f_validate_si_scheduling(SystemInformationConfig cfg,
4272 SystemInformationVectorPerTc si_per_tc)
4273{
Harald Welte48494ca2018-02-25 16:59:50 +01004274 var integer i;
4275 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4276 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004278 }
4279 }
4280 if (cfg.si1_present) {
4281 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4282 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4283 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4284 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4285 /* make sure *ALL* contain SI1 */
4286 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4287 }
4288 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4289 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4290 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4291 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4292 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4293 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4294
4295 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4296 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4297 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4298 * consecutive occurrences of TC = 4. */
4299 if (cfg.si2bis_present and not cfg.si2ter_present) {
4300 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4301 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4302 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4303 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4304 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4305 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4306 }
4307
4308 if (cfg.si7_present or cfg.si8_present) {
4309 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4310 * if System Information type 4 does not contain all information needed for cell
4311 * selection and reselection. */
4312 if (not cfg.bcch_extended) {
4313 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4314 }
4315 if (cfg.si7_present) {
4316 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4317 }
4318 if (cfg.si8_present) {
4319 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4320 }
4321 }
4322
4323 if (cfg.si2quater_present) {
4324 /* iii) System information type 2 quater is sent if needed, as determined by the system
4325 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4326 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4327 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4328 * within any of 4 consecutive occurrences of TC = 5. */
4329 if (not (cfg.bcch_extended)) {
4330 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4331 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4332 } else {
4333 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4334 }
4335 } else {
4336 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4337 }
4338 }
4339 if (cfg.si9_present) {
4340 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4341 * in system information type 3 as defined in 3GPP TS 44.018. */
4342 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4343 }
4344 if (cfg.si13_present) {
4345 /* vii) System Information type 13 is only related to the GPRS service. System Information
4346 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4347 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4348 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4349 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4350 * within any of 4 consecutive occurrences of TC=4. */
4351 if (not cfg.bcch_extended) {
4352 log("not-bccch-extended");
4353 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4354 } else {
4355 log("bccch-extended");
4356 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4357 }
4358 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004360 }
4361 }
4362 if (cfg.si16_present or cfg.si17_present) {
4363 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4364 * should not be sent in a cell where network sharing is used (see rule xv). */
4365 if (cfg.si22_present) {
4366 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4367 }
4368 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004370 }
4371 if (not cfg.bcch_extended) {
4372 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4373 }
4374 if (cfg.si16_present) {
4375 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4376 }
4377 if (cfg.si17_present) {
4378 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4379 }
4380 }
4381
4382 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4383 * broadcast information. The frequency with which they are sent is determined by the
4384 * system operator. System Information type 9 identifies the scheduling of System
4385 * Information type 18 and 20 messages. */
4386
4387 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4388 * Information Type 19 is present, then its scheduling shall be indicated in System
4389 * Information Type 9. */
4390
4391 if (cfg.si15_present) {
4392 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4393 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4394 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4395 * 4 consecutive occurrences of TC = 1. */
4396 if (not cfg.bcch_extended) {
4397 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4398 } else {
4399 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4400 }
4401 }
4402 if (cfg.si13alt_present) {
4403 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4404 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4405 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4406 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4407 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4408 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4409 * of TC = 4. */
4410 if (cfg.si13_present) {
4411 testcase.stop("Error: Cannot have SI13alt and SI13");
4412 }
4413 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004415 }
4416 if (not cfg.bcch_extended) {
4417 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4418 } else {
4419 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4420 }
4421 }
4422 if (cfg.si2n_present) {
4423 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4424 * as determined by the system operator. In the case that the message is sent on the
4425 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4426 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4427 * consecutive occurrences of TC = 4. */
4428 if (not cfg.bcch_extended) {
4429 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4430 } else {
4431 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4432 }
4433 }
4434 if (cfg.si21_present) {
4435 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4436 * determined by the system operator. If Extended Access Barring is in use in the cell
4437 * then this message is sent at least once within any of 4 consecutive occurrences of
4438 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4439 * cell then this message shall only be sent on BCCH Ext. */
4440 if (not cfg.bcch_extended) {
4441 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4442 } else {
4443 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4444 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004446 }
4447 }
4448 }
4449 if (cfg.si22_present) {
4450 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4451 * should not be sent in a cell where SoLSA is used (see rule viii). System
4452 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4453 * =2 and TC=6. */
4454 if (cfg.si16_present or cfg.si17_present) {
4455 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4456 }
4457 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4458 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004460 }
4461 if (not cfg.bcch_extended) {
4462 testcase.stop("Error: SI22 requires BCCH Extd!");
4463 } else {
4464 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4465 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4466 }
4467 }
4468}
4469
4470/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004471private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4472return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004473 timer T := duration;
4474 var SystemInformationVectorPerTc si_per_tc;
4475 var L1ctlDlMessage l1_dl;
4476
4477 /* initialize all per-TC vectors empty */
4478 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4479 si_per_tc[i] := {};
4480 }
4481
4482 /* flush all previous L1 queued msgs */
4483 pt.clear;
4484
4485 T.start;
4486 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004487 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004488 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4489 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4490 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004491 repeat;
4492 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004493
Harald Welte48494ca2018-02-25 16:59:50 +01004494 var integer tc := f_gsm_compute_tc(sig.frame_number);
4495 log("SI received at TC=", tc, ": ", sig.si);
4496 /* append to the per-TC bucket */
4497 si_per_tc[tc] := si_per_tc[tc] & { sig };
4498 repeat;
4499 }
4500 [] pt.receive { repeat; }
4501 [] T.timeout { }
4502 }
4503
4504 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4505 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4506 }
4507 log("si_per_tc=", si_per_tc);
4508 return si_per_tc;
4509}
4510
4511/* helper function: Set given SI via RSL + validate scheduling.
4512 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004513private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004514 var SystemInformationVectorPerTc si_per_tc;
4515 f_init_l1ctl();
4516 f_l1_tune(L1CTL);
4517
4518 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004519 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004520 f_validate_si_scheduling(si_cfg, si_per_tc);
4521
4522 setverdict(pass);
4523}
4524
4525testcase TC_si_sched_default() runs on test_CT {
4526 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004527 /* 2+3+4 are mandatory and set in f_init() */
4528 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004530}
4531
4532testcase TC_si_sched_1() runs on test_CT {
4533 f_init();
4534 si_cfg.si1_present := true;
4535 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004536 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004538}
4539
4540testcase TC_si_sched_2bis() runs on test_CT {
4541 f_init();
4542 si_cfg.si2bis_present := true;
4543 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4544 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004546}
4547
4548testcase TC_si_sched_2ter() runs on test_CT {
4549 f_init();
4550 si_cfg.si2ter_present := true;
4551 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4552 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004553 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004554}
4555
4556testcase TC_si_sched_2ter_2bis() runs on test_CT {
4557 f_init();
4558 si_cfg.si2bis_present := true;
4559 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4560 si_cfg.si2ter_present := true;
4561 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4562 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004564}
4565
4566testcase TC_si_sched_2quater() runs on test_CT {
4567 f_init();
4568 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004569 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004570 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004572}
4573
4574testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004575 /* NOTE: PCUIF connection is not used in this test case, but
4576 * without it the IUT would not broadcast SI13 (see OS#3075). */
4577 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004578 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004579 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004580 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004582}
4583
4584testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004585 /* NOTE: PCUIF connection is not used in this test case, but
4586 * without it the IUT would not broadcast SI13 (see OS#3075). */
4587 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004588 si_cfg.si2bis_present := true;
4589 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4590 si_cfg.si2ter_present := true;
4591 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4592 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004593 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004594 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004595 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004596 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004598}
4599
4600
Harald Welte68e495b2018-02-25 00:05:57 +01004601testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004602 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004603 /* FIXME: enable / disable individual BCCH info */
4604 //ts_RSL_BCCH_INFO(si_type, info);
4605 /* expect no ERROR REPORT after either of them *
4606 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004608}
4609
Harald Welte93640c62018-02-25 16:59:33 +01004610/***********************************************************************
4611 * Low-Level Protocol Errors / ERROR REPORT
4612 ***********************************************************************/
4613
Harald Welte01d982c2018-02-25 01:31:40 +01004614private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4615 timer T := 5.0;
4616 T.start;
4617 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004618 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004619 setverdict(pass);
4620 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004621 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004623 }
4624 [] RSL_CCHAN.receive {
4625 repeat;
4626 }
4627 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004629 }
4630 }
4631}
4632
4633/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4634testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004635 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004636 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4637 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004638 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004639
4640 f_exp_err_rep(RSL_ERR_PROTO);
4641}
4642
4643/* Provoke a mandatory IE error and match on ERROR REPORT */
4644testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004645 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004646
4647 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4648 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004649 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004650
4651 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4652}
4653
4654/* Provoke an IE content error and match on ERROR REPORT */
4655testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004656 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004657 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4658 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004659 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004660
4661 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4662}
4663
Harald Welteee25aae2019-05-19 14:32:37 +02004664/* attempt to activate channel with wrong RSL Message Discriminator IE */
4665function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4666 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4667 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4668 RSL.send(rsl);
4669 f_rslem_unregister(0, g_chan_nr);
4670}
4671testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4672 var ConnHdlr vc_conn;
4673 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4674
Harald Welte10474062019-05-30 16:48:17 +02004675 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004676
4677 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4678 vc_conn.done;
4679 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4680
4681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4682}
4683
4684/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004685private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004686 var template (value) RSL_Message rsl_tx;
4687 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4688 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4689 RSL.send(rsl_tx);
4690 f_rslem_unregister(0, g_chan_nr);
4691}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004692private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004693 var template (value) RSL_Message rsl_tx;
4694 /* we first have to activate the dedicated channel */
4695 f_rsl_chan_act(g_pars.chan_mode);
4696 /* ... to then send an invalid RLL message */
4697 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4698 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4699 RSL.send(rsl_tx);
4700 f_rslem_unregister(0, g_chan_nr);
4701}
4702testcase TC_err_rep_wrong_msg_type() 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 var template (value) RSL_Message rsl_tx;
4706
Harald Welte10474062019-05-30 16:48:17 +02004707 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004708
4709 /* Common Channel with wrong message type */
4710 RSL_CCHAN.clear;
4711 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4712 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004713 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004714 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4715
4716 /* TRX Management */
4717 RSL_CCHAN.clear;
4718 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4719 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004720 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004721 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4722
4723 /* Dedicated Channel */
4724 RSL_CCHAN.clear;
4725 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4726 vc_conn.done;
4727 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4728
4729 /* RLL */
4730 RSL_CCHAN.clear;
4731 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4732 vc_conn.done;
4733 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4734}
4735
4736/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004737private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004738 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4739 f_rslem_unregister(0, g_chan_nr);
4740}
4741testcase TC_err_rep_wrong_sequence() runs on test_CT {
4742 var ConnHdlr vc_conn;
4743 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4744
Harald Welte10474062019-05-30 16:48:17 +02004745 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004746
4747 RSL_CCHAN.clear;
4748 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4749 vc_conn.done;
4750 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4751}
4752
Harald Welte93640c62018-02-25 16:59:33 +01004753/***********************************************************************
4754 * IPA CRCX/MDCX/DLCS media stream handling
4755 ***********************************************************************/
4756
Harald Weltea871a382018-02-25 02:03:14 +01004757/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004758private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004759 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4760 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004761}
4762testcase TC_ipa_dlcx_not_active() runs on test_CT {
4763 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004764 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004765 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4766 vc_conn.done;
4767}
Harald Welte68e495b2018-02-25 00:05:57 +01004768
Harald Weltea3f1df92018-02-25 12:49:55 +01004769/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004770private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004771 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4772 "IPA CRCX ACK");
4773 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4774 "IPA CRCX NACK");
4775}
4776testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4777 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004778 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004779 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4780 vc_conn.done;
4781}
4782
4783/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004784private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004785 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4786 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004787 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004788 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4789 var uint7_t rtp_pt2 := f_rnd_int(127);
4790 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4791 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4792 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4793 "IPA MDCX ACK");
4794 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4795 "IPA DLCX ACK");
4796}
4797testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4798 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004799 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004800 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4801 vc_conn.done;
4802}
4803
Harald Welte3ae11da2018-02-25 13:36:06 +01004804/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004805private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004806 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4807 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004808 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004809 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4810 var uint7_t rtp_pt2 := f_rnd_int(127);
4811 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4812 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4813 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4814 "IPA MDCX ACK");
4815 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004816 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004817 remote_port := f_rnd_int(c_UINT16_MAX);
4818 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4819 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4820 "IPA MDCX ACK");
4821 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4822 "IPA DLCX ACK");
4823}
4824testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4825 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004826 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004827 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4828 vc_conn.done;
4829}
4830
Harald Welte9912eb52018-02-25 13:30:15 +01004831/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004832private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004833 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4834 "IPA CRCX NACK");
4835}
4836testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4837 var ConnHdlrPars pars;
4838 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004839 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004840
4841 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4842 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4843 vc_conn.done;
4844
4845 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4846 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4847 vc_conn.done;
4848}
4849
Harald Weltea3f1df92018-02-25 12:49:55 +01004850
Harald Welte883340c2018-02-28 18:59:29 +01004851/***********************************************************************
4852 * PCU Socket related tests
4853 ***********************************************************************/
4854
Harald Welte07bd2d22019-05-25 11:03:30 +02004855/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004856friend 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 +01004857runs on test_CT {
4858 timer T := 3.0;
4859
4860 /* we don't expect any RTS.req before PDCH are active */
4861 T.start;
4862 alt {
4863 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004865 }
4866 [] PCU.receive { repeat; }
4867 [] T.timeout { }
4868 }
4869
4870 /* Send PDCH activate request for known PDCH timeslot */
4871 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4872
4873 /* we now expect RTS.req for this timeslot (only) */
4874 T.start;
4875 alt {
4876 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4877 setverdict(pass);
4878 }
4879 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4880 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004882 }
4883 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004885 }
4886 [] PCU.receive { repeat; }
4887 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004889 }
4890 [not exp_success] T.timeout {
4891 setverdict(pass);
4892 }
4893 }
4894}
4895
Harald Welte07bd2d22019-05-25 11:03:30 +02004896/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004897friend 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 +01004898runs on test_CT {
4899 timer T := 3.0;
4900
4901 /* Send PDCH activate request for known PDCH timeslot */
4902 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 +02004903 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4904 * when it will actually have been executed in the BTS */
4905 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004906 PCU.clear;
4907 /* we now expect no RTS.req for this timeslot */
4908 T.start;
4909 alt {
4910 [] 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 +02004911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004912 }
4913 [] PCU.receive { repeat; }
4914 [] T.timeout {
4915 setverdict(pass);
4916 }
4917 }
4918}
4919
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004920friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004921 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004922 map(self:PCU, system:PCU);
4923 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004924 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4925}
4926
Harald Welte883340c2018-02-28 18:59:29 +01004927/* PDCH activation via PCU socket; check for presence of RTS.req */
4928testcase TC_pcu_act_req() 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_act_req(0, 0, 7, true);
4932}
4933
4934/* PDCH activation via PCU socket on non-PDCU timeslot */
4935testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004936 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004937
Harald Welte883340c2018-02-28 18:59:29 +01004938 f_TC_pcu_act_req(0, 0, 1, false);
4939}
4940
4941/* PDCH activation via PCU socket on wrong BTS */
4942testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004943 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004944
Harald Welte883340c2018-02-28 18:59:29 +01004945 f_TC_pcu_act_req(23, 0, 7, false);
4946}
4947
4948/* PDCH activation via PCU socket on wrong TRX */
4949testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004950 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004951
Harald Welte883340c2018-02-28 18:59:29 +01004952 f_TC_pcu_act_req(0, 23, 7, false);
4953}
4954
4955/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4956testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004957 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004958
Harald Welte883340c2018-02-28 18:59:29 +01004959 /* Activate PDCH */
4960 f_TC_pcu_act_req(0, 0, 7, true);
4961 f_sleep(1.0);
4962 /* and De-Activate again */
4963 f_TC_pcu_deact_req(0, 0, 7);
4964}
4965
4966/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4967testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004968 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004969
Harald Welte883340c2018-02-28 18:59:29 +01004970 f_TC_pcu_deact_req(0, 0, 1);
4971}
4972
4973/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004974function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004975 var PCUIF_send_data sd;
4976 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004977 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004978
4979 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004980 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004981
Harald Welte883340c2018-02-28 18:59:29 +01004982 T.start;
4983 alt {
4984 [] 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 +01004985 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004986 setverdict(pass);
4987 } else {
4988 repeat;
4989 }
4990 }
4991 [] PCU.receive { repeat; }
4992 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004994 }
4995 }
4996}
4997
Philipp Maier94c08482021-02-01 17:36:05 +01004998/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4999testcase TC_pcu_ver_si1() runs on test_CT {
5000 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5001 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5002}
5003
5004/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5005testcase TC_pcu_ver_si3() runs on test_CT {
5006 const octetstring si3 := '49012223242526272929AABBCC'O;
5007 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5008}
5009
5010/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5011testcase TC_pcu_ver_si13() runs on test_CT {
5012 const octetstring si13 := '01010203040506070909'O;
5013 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5014}
5015
Harald Welte883340c2018-02-28 18:59:29 +01005016private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5017
5018/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005019friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005020 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5021runs on test_CT
5022{
5023 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5024 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5025}
5026
5027/* 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 +02005028friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5029 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005030runs on test_CT
5031{
5032 var PCUIF_send_data sd;
5033
5034 timer T := 3.0;
5035 T.start;
5036 alt {
5037 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5038 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5039 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5040 sd.data.u.rts_req.fn, sapi, data);
5041 }
5042 [] PCU.receive { repeat; }
5043 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005045 }
5046 }
5047}
5048
5049/* Send DATA.req on invalid BTS */
5050testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005051 var TfiUsfArr tua := f_TfiUsfArrInit();
5052 var octetstring data := '0000'O & f_rnd_octstring(21);
5053
5054 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005055
Harald Welte883340c2018-02-28 18:59:29 +01005056 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005057 f_TfiUsfArrSet(tua, 7, 0);
5058 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5059 f_sleep(1.0);
5060
5061 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005062}
5063
5064/* Send DATA.req on invalid TRX */
5065testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005066 var TfiUsfArr tua := f_TfiUsfArrInit();
5067 var octetstring data := '0000'O & f_rnd_octstring(21);
5068
5069 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005070
Harald Welte883340c2018-02-28 18:59:29 +01005071 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005072 f_TfiUsfArrSet(tua, 7, 0);
5073 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5074 f_sleep(1.0);
5075
5076 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005077}
5078
5079/* Send DATA.req on invalid timeslot */
5080testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005081 var TfiUsfArr tua := f_TfiUsfArrInit();
5082 var octetstring data := '0000'O & f_rnd_octstring(21);
5083
5084 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005085
Harald Welte883340c2018-02-28 18:59:29 +01005086 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005087 f_TfiUsfArrSet(tua, 7, 0);
5088 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5089 f_sleep(1.0);
5090
5091 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005092}
5093
5094/* Send DATA.req on timeslot that hasn't been activated */
5095testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005096 var TfiUsfArr tua := f_TfiUsfArrInit();
5097 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005098
Harald Welte7162a612019-05-26 12:56:09 +02005099 f_virtphy_common();
5100
5101 f_TfiUsfArrSet(tua, 7, 0);
5102 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5103 f_sleep(1.0);
5104
5105 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005106}
5107
Harald Weltead033dc2019-05-25 17:28:16 +02005108private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005109 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5110 boolean wait_rts := true)
5111runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005112 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005113 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005114
5115 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005116 if (wait_rts) {
5117 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5118 } else {
5119 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5120 }
Harald Weltead033dc2019-05-25 17:28:16 +02005121
5122 T.start;
5123 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005124 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005125 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5126 setverdict(pass);
5127 }
Harald Welte7162a612019-05-26 12:56:09 +02005128 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5129 setverdict(fail, "Received unexpected ", rx_dl);
5130 }
Harald Weltead033dc2019-05-25 17:28:16 +02005131 [] L1CTL.receive {
5132 repeat;
5133 }
Harald Welte7162a612019-05-26 12:56:09 +02005134 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005135 setverdict(fail, "Timeout waiting for ", data);
5136 }
Harald Welte7162a612019-05-26 12:56:09 +02005137 [not expect_data] T.timeout {
5138 setverdict(pass);
5139 }
Harald Weltead033dc2019-05-25 17:28:16 +02005140 }
5141}
5142
5143private function f_disable_dynamic_ts() runs on test_CT
5144{
5145 f_init_vty_bsc();
5146 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5147 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5148 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5149 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005150 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005151}
5152
5153private function f_virtphy_common() runs on test_CT {
5154 f_disable_dynamic_ts();
5155 f_init_l1ctl();
5156 f_l1_tune(L1CTL);
5157}
5158
5159testcase TC_pcu_data_req_pdtch() runs on test_CT {
5160 var TfiUsfArr tua := f_TfiUsfArrInit();
5161 var octetstring data := '0000'O & f_rnd_octstring(21);
5162
5163 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005164
Harald Welte883340c2018-02-28 18:59:29 +01005165 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005166 f_TfiUsfArrSet(tua, 7, 0);
5167 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5168 f_sleep(1.0);
5169
5170 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005171}
5172
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005173/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005174testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005175 var TfiUsfArr tua := f_TfiUsfArrInit();
5176 var octetstring data := '0000'O & f_rnd_octstring(21);
5177
5178 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005179
Harald Welte883340c2018-02-28 18:59:29 +01005180 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005181 f_TfiUsfArrSet(tua, 7, 0);
5182 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5183 f_sleep(1.0);
5184
5185 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005186}
5187
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005188private function f_TC_pcu_ptcch_ul(uint16_t ra)
5189runs on test_CT {
5190 var template PCUIF_Message pcu_rach_ind;
5191 var PCUIF_send_data sd;
5192 var GsmFrameNumber fn;
5193 timer T;
5194
5195 /* Send an Access Burst on PTCCH/U over the Um-interface */
5196 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5197 chan_nr := ts_RslChanNr_PDCH(7),
5198 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5199
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005200 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5201 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005202
5203 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5204 T.start(52.0 * 4.615 / 1000.0);
5205 alt {
5206 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5207 log("Rx an Access Burst on the PCU interface: ", sd.data);
5208 setverdict(pass);
5209 T.stop;
5210 }
5211 [] PCU.receive { repeat; }
5212 [] T.timeout {
5213 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5214 /* Keep going, that's not the end of the world */
5215 }
5216 }
5217}
5218
5219testcase TC_pcu_ptcch() runs on test_CT {
5220 var L1ctlDlMessage dl;
5221 var octetstring data;
5222 timer T;
5223
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005224 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005225 f_init_l1ctl();
5226 f_l1_tune(L1CTL);
5227
5228 /* Activate PDCH channel on TS7 */
5229 f_TC_pcu_act_req(0, 0, 7, true);
5230
5231 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005232 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005233 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005234 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005235 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005236
5237 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5238 for (var integer i := 0; i < 16; i := i + 1) {
5239 log("Sending an Access Burst towards the L1CTL interface");
5240 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5241 }
5242
5243 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5244 data := f_rnd_octstring(23);
5245
5246 /* Verify PTCCH/D: send a random data block, make sure it's received */
5247 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5248 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5249
5250 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5251 * let's give it more time in case if we miss the beginning. */
5252 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5253 alt {
5254 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5255 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5256 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5257 frame := data)) -> value dl {
5258 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5259 setverdict(pass);
5260 T.stop;
5261 }
5262 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5263 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5264 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5265 l2_data := data)) -> value dl {
5266 log("Rx PTCCH/D data block on L1CTL: ", dl);
5267 setverdict(pass);
5268 T.stop;
5269 }
5270 [] L1CTL.receive { repeat; }
5271 [] T.timeout {
5272 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5273 }
5274 }
5275}
5276
Harald Welte883340c2018-02-28 18:59:29 +01005277/* Send AGCH from PCU; check it appears on Um side */
5278testcase TC_pcu_data_req_agch() runs on test_CT {
5279 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005280 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005281 f_init_l1ctl();
5282 f_l1_tune(L1CTL);
5283
5284 f_TC_pcu_act_req(0, 0, 7, true);
5285 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5286
5287 T.start;
5288 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005289 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005290 setverdict(pass);
5291 }
5292 [] L1CTL.receive { repeat; }
5293 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005295 }
5296 }
5297}
5298
Harald Welte928622b2019-05-26 13:22:59 +02005299/* Send AGCH from PCU; check it appears on Um side */
5300testcase TC_pcu_data_req_pch() runs on test_CT {
5301 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005302 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005303 f_init_l1ctl();
5304 f_l1_tune(L1CTL);
5305
5306 f_TC_pcu_act_req(0, 0, 7, true);
5307 /* three characters prefix: last 3 digits of IMSI as ASCII */
5308 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5309
5310 T.start;
5311 alt {
5312 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5313 setverdict(pass);
5314 }
5315 [] L1CTL.receive { repeat; }
5316 [] T.timeout {
5317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5318 }
5319 }
5320}
5321
Harald Welte883340c2018-02-28 18:59:29 +01005322/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5323testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5324 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005325 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005326 f_init_l1ctl();
5327 f_l1_tune(L1CTL);
5328
5329 /* append 3 last imsi digits so BTS can compute pagng group */
5330 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5331
5332 timer T := 0.5;
5333 T.start;
5334 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005335 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005336 /* TODO: verify paging group */
5337 setverdict(pass);
5338 }
5339 [] L1CTL.receive { repeat; }
5340 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005342 }
5343 }
5344}
5345
5346/* Send RACH from Um side, expect it to show up on PCU socket */
5347testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005348 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005349 f_init_l1ctl();
5350 f_l1_tune(L1CTL);
5351
5352 var GsmFrameNumber fn_last := 0;
5353 for (var integer i := 0; i < 1000; i := i+1) {
5354 var OCT1 ra := f_rnd_ra_ps();
5355 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5356 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005358 }
5359 fn_last := fn;
5360
5361 timer T := 2.0;
5362 T.start;
5363 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005364 [] 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 +01005365 T.stop;
5366 }
5367 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005369 }
5370 [] PCU.receive { repeat; }
5371 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005373 }
5374 }
5375 }
5376 setverdict(pass);
5377}
5378
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005379/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5380 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5381testcase TC_pcu_ext_rach_content() runs on test_CT {
5382 var template PCUIF_Message pcu_rach_ind;
5383 var GsmFrameNumber fn_last := 0;
5384 var L1ctlRachSynchSeq synch_seq;
5385 var PCUIF_BurstType pcu_bt;
5386 var GsmFrameNumber fn;
5387 var BIT11 ra11;
5388
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005389 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005390 f_init_l1ctl();
5391 f_l1_tune(L1CTL);
5392
5393 for (var integer i := 0; i < 1000; i := i+1) {
5394 /* We need to test both TS1 & TS2 */
5395 if (i rem 2 == 0) {
5396 synch_seq := RACH_SYNCH_SEQ_TS1;
5397 pcu_bt := BURST_TYPE_1;
5398 } else {
5399 synch_seq := RACH_SYNCH_SEQ_TS2;
5400 pcu_bt := BURST_TYPE_2;
5401 }
5402
5403 ra11 := f_rnd_ra11_ps();
5404 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5405 if (fn == fn_last) {
5406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5407 "Two RACH in same FN?!?");
5408 }
5409 fn_last := fn;
5410
5411 /* Compose the expected message */
5412 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005413 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005414 ra := bit2int(ra11),
5415 is_11bit := 1,
5416 burst_type := pcu_bt,
5417 fn := fn);
5418
5419 timer T := 2.0;
5420 T.start;
5421 alt {
5422 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5423 T.stop;
5424 }
5425 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5427 }
5428 [] PCU.receive { repeat; }
5429 [] T.timeout {
5430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5431 }
5432 }
5433 }
5434 setverdict(pass);
5435}
5436
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005437private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5438runs on test_CT {
5439 var template PCUIF_send_data sdt;
5440 var PCUIF_send_data sd;
5441 var int16_t lqual_cb;
5442 timer T := 1.0;
5443
5444 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5445 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5446
5447 /* Send a random PDTCH frame over Um */
5448 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5449 '0000'O & f_rnd_octstring(21)));
5450
5451 T.start;
5452 alt {
5453 /* If expected link quality is above the threshold */
5454 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5455 lqual_cb := sd.data.u.data_ind.lqual_cb;
5456 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5457
5458 /* Make sure the actual link quality matches the expected value */
5459 if (not match(lqual_cb, lqual_cb_exp)) {
5460 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5461 "expected value ", lqual_cb_exp));
5462 } else {
5463 setverdict(pass);
5464 }
5465 }
5466 /* If expected link quality is below the threshold */
5467 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5469 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5470 }
5471 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5472 [] PCU.receive { repeat; }
5473 [lqual_cb_exp < thresh] T.timeout {
5474 log("Rx nothing, as expected");
5475 setverdict(pass);
5476 }
5477 [lqual_cb_exp >= thresh] T.timeout {
5478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5479 "Timeout waiting for PCUIF_DATA.ind");
5480 }
5481 }
5482}
5483
5484/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5485testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005486 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005487 PCU.clear;
5488
5489 f_init_l1ctl();
5490 f_l1_tune(L1CTL);
5491
5492 /* Activate a PDCH channel on TS7 */
5493 f_TC_pcu_act_req(0, 0, 7, true);
5494
5495 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005496 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005497 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005498 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005499 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005500
5501 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5502 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5503 var TrxcMessage ret;
5504
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005505 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005506
5507 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5508 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5509 }
5510}
5511
Harald Welte883340c2018-02-28 18:59:29 +01005512/* Send PAGING via RSL, expect it to shw up on PCU socket */
5513testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005514 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005515
5516 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005517 var MobileIdentityLV mi_lv;
5518 var octetstring mi_lv_enc;
5519 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005520 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005521
Harald Welte883340c2018-02-28 18:59:29 +01005522 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005523 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005524 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005525 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005526 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005527
5528 /* Fancy encoding for PCUIF */
5529 mi_lv := valueof(ts_MI_LV(mi));
5530 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5531 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005532
5533 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005534 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005535 T.start;
5536 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005537 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005538 }
5539 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005541 }
5542 [] PCU.receive { repeat; }
5543 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005545 }
5546 }
5547 }
5548 setverdict(pass);
5549}
5550
Harald Welted66c9b82019-05-25 09:03:15 +02005551/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5552testcase TC_pcu_time_ind() runs on test_CT {
5553 var PCUIF_send_data pcu_sd;
5554 var integer num_time_ind := 0;
5555 var integer first_fn, last_fn;
5556 var float test_duration := 5.0;
5557 timer T;
5558
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005559 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005560 f_TC_pcu_act_req(0, 0, 7, true);
5561
5562 PCU.clear;
5563 T.start(test_duration);
5564 alt {
5565 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5566 num_time_ind := num_time_ind + 1;
5567 if (not isbound(first_fn)) {
5568 first_fn := pcu_sd.data.u.time_ind.fn;
5569 }
5570 last_fn := pcu_sd.data.u.time_ind.fn;
5571 repeat;
5572 }
5573 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5574 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5575 repeat;
5576 }
5577 [] PCU.receive {
5578 repeat;
5579 }
5580 [] T.timeout {}
5581 }
5582 var integer fn_expired := last_fn - first_fn;
5583 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5584
5585 /* verify the number of frames expired matches our expectation */
5586 const float c_GSM_FN_DURATION_MS := 4.61538;
5587 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005588 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005589 if (not match(fn_expired, t_fn_expected)) {
5590 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5591 }
5592
5593 /* There are three TIME.ind in every fn MOD 13 */
5594 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5595 /* Add some tolerance */
5596 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5597 if (not match(num_time_ind, t_time_ind_exp)) {
5598 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5599 }
5600
5601 setverdict(pass);
5602}
5603
Harald Welte4832c862019-05-25 14:57:18 +02005604/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5605testcase TC_pcu_rts_req() runs on test_CT {
5606 var PCUIF_send_data pcu_sd;
5607 var integer first_fn, last_fn;
5608 var integer num_rts_pdtch := 0;
5609 var integer num_rts_ptcch := 0;
5610 var float test_duration := 5.0;
5611 timer T;
5612
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005613 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005614 f_TC_pcu_act_req(0, 0, 7, true);
5615
5616 PCU.clear;
5617 T.start(test_duration);
5618 alt {
5619 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5620 -> value pcu_sd {
5621 num_rts_pdtch := num_rts_pdtch + 1;
5622 if (not isbound(first_fn)) {
5623 first_fn := pcu_sd.data.u.rts_req.fn;
5624 }
5625 last_fn := pcu_sd.data.u.rts_req.fn;
5626 repeat;
5627 }
5628 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5629 -> value pcu_sd {
5630 num_rts_ptcch := num_rts_ptcch + 1;
5631 if (not isbound(first_fn)) {
5632 first_fn := pcu_sd.data.u.rts_req.fn;
5633 }
5634 last_fn := pcu_sd.data.u.rts_req.fn;
5635 repeat;
5636 }
5637 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5638 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5639 repeat;
5640 }
5641 [] PCU.receive {
5642 repeat;
5643 }
5644 [] T.timeout {}
5645 }
5646 var integer fn_expired := last_fn - first_fn;
5647 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5648 ", num_rts_ptcch=", num_rts_ptcch);
5649
5650 /* verify the number of frames expired matches our expectation */
5651 const float c_GSM_FN_DURATION_MS := 4.61538;
5652 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005653 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005654 if (not match(fn_expired, t_fn_expected)) {
5655 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5656 }
5657
5658 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5659 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5660 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5661 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5662 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5663 t_ptcch_exp);
5664 }
5665
5666 /* We have 12 PDTCH blocks every 52-multiframe */
5667 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5668 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5669 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5670 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5671 t_pdtch_exp);
5672 }
5673
5674 setverdict(pass);
5675}
5676
Harald Welte07bd2d22019-05-25 11:03:30 +02005677/* test for generating Abis side OML ALERT from the PCU */
5678testcase TC_pcu_oml_alert() runs on test_CT {
5679 var PCUIF_send_data pcu_sd;
5680 var integer num_time_ind := 0;
5681 var integer first_fn, last_fn;
5682 var float test_duration := 5.0;
5683 timer T;
5684
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005685 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005686 f_TC_pcu_act_req(0, 0, 7, true);
5687
5688 /* re-connect CTRL port from BTS to BSC */
5689 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005690 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005691
5692 /* Send that OML Alert */
5693 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5694
5695 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5696 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5697 setverdict(pass);
5698}
5699
Harald Welteeaa9a862019-05-26 23:01:08 +02005700/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5701private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5702 var PCUIF_Message first_info;
5703 var integer pcu_conn_id := -1;
5704 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5705 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5706 var OCT4 tlli := '01020304'O;
5707 var OCT1 cause := '23'O;
5708 timer T := 5.0;
5709
5710 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5711
5712 f_l1_tune(L1CTL);
5713 RSL.clear;
5714
5715 f_est_dchan();
5716 L1CTL.clear;
5717
5718 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5719
5720 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5721 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5722 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5723
5724 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5725 T.start;
5726 alt {
5727 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5728 setverdict(pass);
5729 }
5730 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5731 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5732 }
5733 [] PCU.receive {
5734 repeat;
5735 }
5736 [] T.timeout {
5737 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5738 }
5739 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005740
5741 /* release the channel */
5742 f_rsl_chan_deact();
5743 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5744 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005745}
5746testcase TC_pcu_rr_suspend() runs on test_CT {
5747 var ConnHdlrPars pars;
5748 var ConnHdlr vc_conn;
5749
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005750 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005751
5752 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5753 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5754 vc_conn.done;
5755}
Harald Welte07bd2d22019-05-25 11:03:30 +02005756
Harald Weltea2e0e942019-05-27 18:12:53 +02005757/* Ensure that PCUIF socket can accept only a single connection */
5758testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005759 var boolean connected := false;
5760 var UD_connect_result cr;
5761 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005762 timer T := 5.0;
5763
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005764 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5765 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5766
Harald Weltea2e0e942019-05-27 18:12:53 +02005767 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005768 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005769
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005770 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005771 PCU.send(UD_connect:{mp_pcu_socket, -1});
5772 T.start;
5773 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005774 /* the IUT will first accept() the new connection, and close() it immediately */
5775 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5776 log("BTS has accept()ed connection");
5777 connected := true;
5778 cid := cr.id;
5779 repeat;
5780 }
5781 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5782 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005783 setverdict(pass);
5784 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005785 /* ignore other messages related to the first connection */
5786 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005787 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005788 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005789 }
5790 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005791
Harald Weltea2e0e942019-05-27 18:12:53 +02005792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5793}
5794
Harald Weltec8effb72019-05-27 18:23:04 +02005795/* Ensure that PCUIF socket can disconnect + reconnect */
5796testcase TC_pcu_socket_reconnect() runs on test_CT {
5797 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005798 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005799
5800 f_sleep(1.0);
5801
5802 f_pcuif_close(PCU, g_pcu_conn_id);
5803 g_pcu_conn_id := -1;
5804
5805 f_sleep(1.0);
5806
5807 /* re-connect */
5808 PCU.clear;
5809 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5810 setverdict(pass);
5811
5812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5813}
5814
Harald Weltebe030482019-05-27 22:29:35 +02005815/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005816private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5817runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005818 var L1ctlDlMessage l1_dl;
5819 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005820 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005821 timer T := 5.0;
5822 T.start;
5823 alt {
5824 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005825 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5826 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005827 repeat;
5828 }
5829 }
5830 [] pt.receive {
5831 repeat;
5832 }
5833 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5835 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005836 }
5837 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005838 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005839}
5840
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005841/* Check if GPRS Indicator is present in RR System Information of a given type */
5842private function f_si_has_gprs_indicator(RrMessageType si_type)
5843runs on test_CT return boolean {
5844 var SystemInformation si := f_get_si(L1CTL, si_type);
5845
5846 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005847 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005848 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005849 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005850 }
5851
5852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5853 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005854}
5855
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005856/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5857private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5858runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005859 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005860 f_init_l1ctl();
5861 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005862 f_sleep(2.0);
5863 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005864
5865 if (f_si_has_gprs_indicator(si_type)) {
5866 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005867 } else {
5868 setverdict(pass);
5869 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005870
Harald Weltebe030482019-05-27 22:29:35 +02005871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5872}
5873
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005874testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5875 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5876}
Harald Weltebe030482019-05-27 22:29:35 +02005877
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005878testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5879 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5880}
5881
5882/* Ensure that GPRS capability is advertised after PCU socket connect */
5883private function f_TC_pcu_socket_connect(RrMessageType si_type)
5884runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005885 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005886 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005887 f_init_l1ctl();
5888 f_l1_tune(L1CTL);
5889
5890 f_sleep(2.0);
5891 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005892
5893 if (not f_si_has_gprs_indicator(si_type)) {
5894 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005895 } else {
5896 setverdict(pass);
5897 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005898
Harald Weltebe030482019-05-27 22:29:35 +02005899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5900}
5901
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005902testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5903 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5904}
Harald Weltebe030482019-05-27 22:29:35 +02005905
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005906testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5907 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5908}
5909
5910/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5911private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5912runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005913 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005914 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005915 f_init_l1ctl();
5916 f_l1_tune(L1CTL);
5917
5918 f_pcuif_close(PCU, g_pcu_conn_id);
5919 g_pcu_conn_id := -1;
5920
5921 f_sleep(1.0);
5922
5923 /* re-connect */
5924 PCU.clear;
5925 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5926
5927 f_sleep(2.0);
5928 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005929
5930 if (f_si_has_gprs_indicator(si_type)) {
5931 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005932 } else {
5933 setverdict(pass);
5934 }
5935
5936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5937}
5938
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005939testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5940 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5941}
5942
5943testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5944 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5945}
5946
Oliver Smithf5239c72019-08-28 10:01:25 +02005947/* 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) */
5948testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5949 var SystemInformation si3 := valueof(ts_SI3_default);
5950
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005951 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005952
Harald Welte76220222020-10-11 20:32:44 +02005953 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5954 * information */
5955 timer T := 2.0;
5956 T.start;
5957 alt {
5958 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5959 [] T.timeout {}
5960 }
5961
Oliver Smithf5239c72019-08-28 10:01:25 +02005962 /* Verify cell_id */
5963 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5964 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5965 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005966 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5967 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5968 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005969 }
5970
5971 /* Verify LAC */
5972 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5973 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5974 if (lac_si3 != lac_pcu) {
5975 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5976 }
5977
5978 setverdict(pass);
5979}
Harald Welted66c9b82019-05-25 09:03:15 +02005980
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005981/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5982testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5983 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005984 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005985
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005986 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005987
5988 info_ind := g_pcu_last_info.u.info_ind;
5989
5990 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5991 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005992 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005993 /* Skip inactive timeslots */
5994 continue;
5995 }
5996
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005997 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005998 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005999 else
6000 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006001
6002 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006003 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006004 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006005 hsn := fhp.maio_hsn.hsn,
6006 maio := fhp.maio_hsn.maio,
6007 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006008 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006009 } else {
6010 tr_ts := tr_PCUIF_InfoTrxTsH0;
6011 }
6012
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006013 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006014 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6015 if (not match(ts, tr_ts)) {
6016 setverdict(fail, "Hopping parameters do not match: ",
6017 "received ", ts, " vs expected ", tr_ts);
6018 } else {
6019 setverdict(pass);
6020 }
6021 }
6022 }
6023}
6024
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006025/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006026testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6027 f_init_vty_bsc();
6028 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6029 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6030
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006031 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006032
6033 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006034 var template PCUIF_RemoteAddr tr_remote_addr := {
6035 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006036 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006037 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006038
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006039 if (not match(remote_addr, tr_remote_addr)) {
6040 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006041 }
6042
6043 setverdict(pass);
6044}
6045
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006046/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006047testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6048 f_init_vty_bsc();
6049 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6050
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006051 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006052
6053 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006054 var template PCUIF_RemoteAddr tr_remote_addr := {
6055 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6056 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6057 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006058
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006059 if (not match(remote_addr, tr_remote_addr)) {
6060 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006061 }
6062
6063 setverdict(pass);
6064}
6065
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006066/* Verify coding of two NSVCs in the INFO.ind message */
6067testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6068 f_init_vty_bsc();
6069
6070 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6071 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6072 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6073 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6074
6075 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6076 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6077 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6078 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6079
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006080 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006081
6082 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6083 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6084 var template PCUIF_RemoteAddr tr_remote_addr := {
6085 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006086 addr := {
6087 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6088 f_inet6_addr("fd00::ca:ff:ee")
6089 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006090 };
6091
6092 if (not match(info_ind.nsvci, { 1234, 5678 }))
6093 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6094 if (not match(remote_addr, tr_remote_addr))
6095 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6096 if (not match(info_ind.local_port, { 1234, 5678 }))
6097 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6098 if (not match(info_ind.remote_port, { 1234, 5678 }))
6099 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6100
6101 setverdict(pass);
6102}
6103
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006104/* Verify periodic interference reports on PDCH */
6105testcase TC_pcu_interf_ind() runs on test_CT {
6106 var template PCUIF_Message tr_interf_ind;
6107 var template PCUIF_interf ts_interf;
6108 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006109 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006110 var PCUIF_send_data sd;
6111 timer T;
6112
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006113 /* Set the averaging/reporting period to 480ms */
6114 f_init_vty_bsc();
6115 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6116 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6117
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006118 f_init_with_pcuif();
6119 f_TC_pcu_act_req(0, 0, 7, true);
6120
6121 /* We need trxcon for NOPE indications */
6122 f_init_l1ctl();
6123 f_l1_tune(L1CTL);
6124
6125 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6126 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6127 tr_interf_ind := tr_PCUIF_INTERF_IND(
6128 bts_nr := 0,
6129 trx_nr := 0,
6130 fn := ?,
6131 interf := ts_interf
6132 );
6133
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006134 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006135 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006136 /* The first interference report may contain unreliable values, so we ignore it */
6137 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6138 /* 4 SACCH periods => 4 reports (plus some guard time) */
6139 T.start(0.480 * 4.0 + 0.480 / 2.0);
6140 first := false;
6141 repeat;
6142 }
6143 /* Subsequent interference reports shall match our expectations */
6144 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006145 /* Check TDMA frame number period */
6146 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6147 setverdict(fail, "Odd TDMA frame number := ",
6148 sd.data.u.interf_ind.fn);
6149 }
6150 interf_ind_num := interf_ind_num + 1;
6151 if (interf_ind_num < 4)
6152 { repeat; }
6153 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006154 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006155 setverdict(fail, "Received unexpected interference report: ", sd.data);
6156 }
6157 [] PCU.receive { repeat; }
6158 [] T.timeout {
6159 setverdict(fail, "Timeout waiting for interference reports");
6160 }
6161 }
6162
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006163 /* Reset the averaging/reporting period back to default */
6164 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6165
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6167}
6168
Harald Welte3d04ae62018-04-04 20:29:05 +02006169/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006170 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006171 ***********************************************************************/
6172
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006173private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6174 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006175runs on ConnHdlr {
6176 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006177
6178 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006179 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006180 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6181 repeat;
6182 }
6183 }
6184}
6185
6186private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6187runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006188 /* Expect BTS to immediately acknowledge activation as PDCH */
6189 PCU.clear;
6190 f_rsl_chan_act(g_pars.chan_mode);
6191 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006192 timer T_wait := 2.0;
6193 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006194 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006195 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006196 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006197 [] T_wait.timeout {
6198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6199 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6200 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006201 }
6202 /* try to activate this PDCH from the PCU point of view */
6203 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6204 /* FIXME: is there a response? */
6205}
6206
6207private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6208runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006209 /* Send RSL CHAN REL (deactivate) */
6210 PCU.clear;
6211 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6212 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006213 timer T_wait := 2.0;
6214 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006215 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006216 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006217 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006218 [] T_wait.timeout {
6219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6220 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6221 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006222 }
6223 /* Emulate PCU asking BTS to deactivate PDCH */
6224 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6225 alt {
6226 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6227 setverdict(pass);
6228 }
6229 [] RSL.receive { repeat; }
6230 }
6231}
6232
6233/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006234private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006235 var PCUIF_Message first_info;
6236 var integer ts_nr := g_chan_nr.tn;
6237 var integer trx_nr := 0;
6238 var integer bts_nr := 0;
6239 var integer pcu_conn_id := -1;
6240
6241 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6242
6243 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6244 f_sleep(3.0);
6245 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6246 setverdict(pass);
6247}
6248testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6249 var ConnHdlrPars pars;
6250 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006251 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006252
6253 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6254 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6255 vc_conn.done;
6256}
6257
6258/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006259private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006260 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006261 var integer pcu_conn_id := -1;
6262
6263 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6264
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006265 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6266 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6267 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006268 setverdict(pass);
6269}
6270testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6271 var ConnHdlrPars pars;
6272 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006273 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006274
6275 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6276 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6277 vc_conn.done;
6278}
6279
6280/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006281private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006282 var PCUIF_Message first_info;
6283 var integer ts_nr := g_chan_nr.tn;
6284 var integer trx_nr := 0;
6285 var integer bts_nr := 0;
6286 var integer pcu_conn_id := -1;
6287
6288 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6289
6290 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006291 /* Send a second Chan Activ and expect it to be NACKed */
6292 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6293 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006294 setverdict(pass);
6295}
6296testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6297 var ConnHdlrPars pars;
6298 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006299 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006300
6301 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6302 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6303 vc_conn.done;
6304}
6305
6306/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006307private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006308 var PCUIF_Message first_info;
6309 var integer ts_nr := g_chan_nr.tn;
6310 var integer trx_nr := 0;
6311 var integer bts_nr := 0;
6312 var integer pcu_conn_id := -1;
6313 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6314
6315 /* register for the TCH/F channel number */
6316 f_rslem_register(0, chan_nr);
6317
6318 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6319
6320 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6321 "RSL CHAN ACT");
6322 setverdict(pass);
6323}
6324testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6325 var ConnHdlrPars pars;
6326 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006327 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006328
6329 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6330 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6331 vc_conn.done;
6332}
6333
6334/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006335private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006336 var PCUIF_Message first_info;
6337 var integer ts_nr := g_chan_nr.tn;
6338 var integer trx_nr := 0;
6339 var integer bts_nr := 0;
6340 var integer pcu_conn_id := -1;
6341 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6342 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6343
6344 /* register for the TCH/H channel numbers */
6345 f_rslem_register(0, chan_nr[0]);
6346 f_rslem_register(0, chan_nr[1]);
6347
6348 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6349
6350 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6351 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6352 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6353 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6354 setverdict(pass);
6355}
6356testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6357 var ConnHdlrPars pars;
6358 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006359 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006360
6361 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6362 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6363 vc_conn.done;
6364}
6365
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006366/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6367private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6368 var PCUIF_Message first_info;
6369 var integer ts_nr := g_chan_nr.tn;
6370 var integer trx_nr := 0;
6371 var integer bts_nr := 0;
6372 var integer pcu_conn_id := -1;
6373 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6374 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6375 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6376 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6377 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6378 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6379 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6380 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6381
6382 /* register for the TCH/H channel numbers */
6383 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6384 f_rslem_register(0, chan_nr[i]);
6385 }
6386
6387 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6388
6389 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6390 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6391 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6392 }
6393 setverdict(pass);
6394}
6395testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6396 var ConnHdlrPars pars;
6397 var ConnHdlr vc_conn;
6398 f_init();
6399
6400 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6401 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6402 vc_conn.done;
6403}
6404
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006405/* Reproduce a race condition described in OS#5245 */
6406private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6407 f_rsl_chan_act(g_pars.chan_mode);
6408 f_sleep(1.0);
6409 f_rsl_chan_deact();
6410 setverdict(pass);
6411}
6412testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6413 var ConnHdlrPars pars[2];
6414 var ConnHdlr vc_conn[2];
6415 var TrxcMessage rsp;
6416
6417 f_init();
6418
6419 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6420 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6421 ts_TRXC_FAKE_TRXC_DELAY(200));
6422
6423 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6424 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6425 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6426 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6427 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6428 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6429 pars[i], l1ctl := false);
6430 }
6431
6432 /* Wait for all components to finish */
6433 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6434 vc_conn[i].done;
6435 }
6436
6437 /* Disable the artificial delay for TRXC RSP messages */
6438 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6439 ts_TRXC_FAKE_TRXC_DELAY(0));
6440}
6441testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6442 var ConnHdlrPars pars[8];
6443 var ConnHdlr vc_conn[8];
6444 var TrxcMessage rsp;
6445
6446 f_init();
6447
6448 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6449 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6450 ts_TRXC_FAKE_TRXC_DELAY(200));
6451
6452 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6453 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6454 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6455 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6456 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6457 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6458 pars[i], l1ctl := false);
6459 }
6460
6461 /* Wait for all components to finish */
6462 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6463 vc_conn[i].done;
6464 }
6465
6466 /* Disable the artificial delay for TRXC RSP messages */
6467 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6468 ts_TRXC_FAKE_TRXC_DELAY(0));
6469}
6470
Harald Welte9bbbfb52018-04-05 09:33:19 +02006471/***********************************************************************
6472 * IPA Style Dynamic Timeslot Support
6473 ***********************************************************************/
6474
6475private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6476runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006477 /* Expect BTS to immediately acknowledge activation as PDCH */
6478 PCU.clear;
6479 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6480 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006481 timer T_wait := 2.0;
6482 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006483 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006484 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006485 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006486 [] T_wait.timeout {
6487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6488 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6489 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006490 }
6491 /* try to activate this PDCH from the PCU point of view */
6492 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6493 /* FIXME: is there a response? */
6494
6495 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6496}
6497
6498private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6499runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006500 /* Send RSL CHAN REL (deactivate) */
6501 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6502 PCU.clear;
6503 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006504 timer T_wait := 2.0;
6505 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006506 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006507 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006508 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006509 [] T_wait.timeout {
6510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6511 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6512 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006513 }
6514 /* Emulate PCU asking BTS to deactivate PDCH */
6515 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6516 alt {
6517 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6518 setverdict(pass);
6519 }
6520 [] RSL.receive { repeat; }
6521 }
6522}
6523
6524/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006525private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006526 var PCUIF_Message first_info;
6527 var integer ts_nr := g_chan_nr.tn;
6528 var integer trx_nr := 0;
6529 var integer bts_nr := 0;
6530 var integer pcu_conn_id := -1;
6531
6532 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6533
6534 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6535 f_sleep(3.0);
6536 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6537
6538 setverdict(pass);
6539
6540}
6541testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6542 var ConnHdlrPars pars;
6543 var ConnHdlr vc_conn;
6544 f_init();
6545
6546 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6547 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6548 vc_conn.done;
6549}
6550
6551/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006552private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006553 var PCUIF_Message first_info;
6554 var integer ts_nr := g_chan_nr.tn;
6555 var integer trx_nr := 0;
6556 var integer bts_nr := 0;
6557 var integer pcu_conn_id := -1;
6558
6559 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6560
6561 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6562 "RSL CHAN ACT");
6563 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6564 "RF CHAN REL", true);
6565 setverdict(pass);
6566}
6567testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6568 var ConnHdlrPars pars;
6569 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006570 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006571
6572 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6573 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6574 vc_conn.done;
6575}
6576
6577/* 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 +07006578private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006579 var PCUIF_Message first_info;
6580 var integer ts_nr := g_chan_nr.tn;
6581 var integer trx_nr := 0;
6582 var integer bts_nr := 0;
6583 var integer pcu_conn_id := -1;
6584
6585 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6586
6587 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6588 "RSL CHAN ACT");
6589
6590 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6591 alt {
6592 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6593 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006595 }
6596 [] RSL.receive { repeat; }
6597 }
6598
6599 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6600 "RF CHAN REL", true);
6601 setverdict(pass);
6602}
6603testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6604 var ConnHdlrPars pars;
6605 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006606 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006607
6608 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6609 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6610 vc_conn.done;
6611}
6612
6613/* 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 +07006614private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006615 var PCUIF_Message first_info;
6616 var integer ts_nr := g_chan_nr.tn;
6617 var integer trx_nr := 0;
6618 var integer bts_nr := 0;
6619 var integer pcu_conn_id := -1;
6620
6621 /* register for the TCH/F channel number */
6622 f_rslem_register(0, g_chan_nr);
6623
6624 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6625
6626 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6627
6628 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6629 "RSL CHAN ACT");
6630
6631 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6632
6633 setverdict(pass);
6634}
6635testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6636 var ConnHdlrPars pars;
6637 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006638 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006639
6640 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6641 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6642 vc_conn.done;
6643}
6644
6645
Harald Welte0472ab42018-03-12 15:02:26 +01006646/***********************************************************************
6647 * LAPDm / RLL related
6648 ***********************************************************************/
6649
6650private function f_tx_lapdm(template (value) LapdmFrame l,
6651 template (value) RslLinkId link_id) runs on ConnHdlr {
6652 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006653 var template (value) SacchL1Header l1h;
6654
6655 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006656 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006657 /* Compose dummy L1 header */
6658 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6659 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 +02006660 } else {
6661 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006662 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 +01006663 }
Harald Welte0472ab42018-03-12 15:02:26 +01006664}
6665
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006666friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006667 uint3_t sapi,
6668 RslLinkId link_id,
6669 octetstring l3,
6670 boolean exp
6671}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006672friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006673friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6674 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006675 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006676 sapi := sapi,
6677 link_id := id,
6678 l3 := l3,
6679 exp := exp
6680}
6681
6682/* execute the same callback function with a set of different parameters (tcs) on a
6683 * variety of logical channels */
6684private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6685 var ConnHdlrPars pars;
6686 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006687 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006688
6689 /* test on each of the channels we have */
6690 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6691 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6692
6693 /* test each of the test cases on the current channel */
6694 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6695 pars.spec.rll := tcs[j];
6696 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6697 vc_conn := f_start_handler(fn, pars);
6698 vc_conn.done;
6699 }
6700 }
6701
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006703}
6704
6705/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6706private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6707 var RllTestCase tc := g_pars.spec.rll;
6708 timer T := 3.0;
6709
6710 f_l1_tune(L1CTL);
6711 RSL.clear;
6712
6713 /* activate the logical channel */
6714 f_est_dchan();
6715 L1CTL.clear;
6716
6717 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6718 T.start;
6719 alt {
6720 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6721 if (tc.exp) {
6722 setverdict(pass);
6723 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006725 }
6726 }
6727 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6728 if (tc.exp) {
6729 setverdict(pass);
6730 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006732 }
6733 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006734 /* We also expect to receive the measurements */
6735 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006736 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006738 }
6739 [not tc.exp] T.timeout {
6740 setverdict(pass);
6741 }
6742 }
6743
6744 f_rsl_chan_deact();
6745 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6746 f_rslem_unregister(0, g_chan_nr);
6747}
6748testcase TC_rll_est_ind() runs on test_CT {
6749 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006750 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006751 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006752 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006753 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006754 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006755 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6756 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006757 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006758 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006759 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006760 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006761 };
6762 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6763}
6764
6765/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6766private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6767 var RllTestCase tc := g_pars.spec.rll;
6768 var L1ctlDlMessage dl;
6769 timer T := 3.0;
6770
6771 f_l1_tune(L1CTL);
6772 RSL.clear;
6773
6774 /* activate the logical channel */
6775 f_est_dchan();
6776 L1CTL.clear;
6777
6778 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6779 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6780 T.start;
6781 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006782 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006783 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006785 }
6786 }
6787
6788 f_rsl_chan_deact();
6789 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6790 f_rslem_unregister(0, g_chan_nr);
6791}
6792testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6793 var RllTestCases tcs := {
6794 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006795 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006796 };
6797 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6798}
6799testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6800 var RllTestCases tcs := {
6801 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006802 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006803 }
6804 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6805}
6806
6807/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006808friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006809 var L1ctlDlMessage dl;
6810 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6811 var LapdmFrame lapdm;
6812 var octetstring l2 := dl.payload.data_ind.payload;
6813 if (dl.dl_info.link_id.c == SACCH) {
6814 /* remove L1 header */
6815 l2 := substr(l2, 2, lengthof(l2)-2);
6816 }
6817 if (ischosen(exp.ab)) {
6818 lapdm.ab := dec_LapdmFrameAB(l2);
6819 } else if (ischosen(exp.b4)) {
6820 lapdm.b4 := dec_LapdmFrameB4(l2);
6821 } else if (ischosen(exp.bbis)) {
6822 lapdm.bbis := dec_LapdmFrameBbis(l2);
6823 }
6824 log("Rx LAPDm ", lapdm);
6825 if (match(lapdm, exp)) {
6826 setverdict(pass);
6827 } else {
6828 repeat;
6829 }
6830 }
6831 [] L1CTL.receive { repeat; }
6832}
6833private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6834 timer T := t;
6835 T.start;
6836 alt {
6837 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006839 }
6840 [] as_l1_exp_lapdm(exp);
6841 }
6842}
6843
6844/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6845private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6846 /* send SABM from MS -> BTS */
6847 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6848 /* expect RLL EST IND on Abis */
6849 alt {
6850 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6851 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6852 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006854 }
6855 [] RSL.receive { repeat; }
6856 }
6857 /* expect UA from BTS -> MS */
6858 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6859}
6860
6861/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6862private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6863 var RllTestCase tc := g_pars.spec.rll;
6864
6865 f_l1_tune(L1CTL);
6866 RSL.clear;
6867
6868 /* activate the logical channel */
6869 f_est_dchan();
6870 L1CTL.clear;
6871
6872 /* first establish the link-layer */
6873 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6874
6875 /* then send the DISC */
6876 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6877 /* ... and expect the REL IND on the RSL side */
6878 alt {
6879 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6880 setverdict(pass);
6881 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006882 /* We also expect to receive the measurements */
6883 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006884 }
6885
6886 /* release the channel */
6887 f_rsl_chan_deact();
6888 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6889 f_rslem_unregister(0, g_chan_nr);
6890}
6891testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6892 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006893 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006894 };
6895 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6896}
6897
6898testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6899 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006900 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006901 };
6902 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6903}
6904testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6905 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006906 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006907 };
6908 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6909}
6910testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6911 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006912 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006913 };
6914 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6915}
6916
6917/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6918private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6919 var RllTestCase tc := g_pars.spec.rll;
6920 f_l1_tune(L1CTL);
6921 RSL.clear;
6922
6923 /* activate the logical channel */
6924 f_est_dchan();
6925 L1CTL.clear;
6926
6927 /* first establish the link-layer */
6928 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6929
6930 /* then send the REL REQ via RSL */
6931 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6932 /* ... and expect the DISC on the Um side */
6933 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006934 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006935 /* FIXME: send a UA in resposne to the DISC */
6936 }
6937 }
6938
6939 /* release the channel */
6940 f_rsl_chan_deact();
6941 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6942 f_rslem_unregister(0, g_chan_nr);
6943}
6944testcase TC_rll_rel_req() runs on test_CT {
6945 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006946 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6947 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6948 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6949 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006950 };
6951 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6952}
6953
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006954/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006955testcase TC_rll_data_req() runs on test_CT {
6956}
6957
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006958/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006959testcase TC_rll_data_ind() runs on test_CT {
6960}
6961
6962/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6963private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6964 var RllTestCase tc := g_pars.spec.rll;
6965
6966 f_l1_tune(L1CTL);
6967 RSL.clear;
6968
6969 f_est_dchan();
6970 L1CTL.clear;
6971
6972 /* Send UNITDATA REQ on RSL side */
6973 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6974 /* Expect it to arrive on the other side */
6975 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006976 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006977 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006978 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006979 }
6980
6981 /* release the channel */
6982 f_rsl_chan_deact();
6983 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6984 f_rslem_unregister(0, g_chan_nr);
6985}
6986testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6987 var octetstring l3 := f_rnd_octstring(15);
6988 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006989 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6990 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006991 };
6992 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6993}
6994testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6995 var octetstring l3 := f_rnd_octstring(19);
6996 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006997 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6998 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006999 };
7000 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7001}
7002
7003/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7004private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7005 var RllTestCase tc := g_pars.spec.rll;
7006
7007 f_l1_tune(L1CTL);
7008 RSL.clear;
7009
7010 f_est_dchan();
7011 L1CTL.clear;
7012
7013 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007014 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007015 /* Expdct RLL UNITDATA IND on RSL side */
7016 alt {
7017 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7018 setverdict(pass);
7019 }
7020 [] RSL.receive { repeat; }
7021 }
7022
7023 /* release the channel */
7024 f_rsl_chan_deact();
7025 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7026 f_rslem_unregister(0, g_chan_nr);
7027}
7028testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007029 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007030 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007031 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7032 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007033 };
7034 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7035}
7036testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7037 var octetstring l3 := f_rnd_octstring(18);
7038 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007039 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7040 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007041 };
7042 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7043}
7044
Harald Weltee613f962018-04-18 22:38:16 +02007045/***********************************************************************
7046 * Encryption Related
7047 ***********************************************************************/
7048
7049/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007050private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007051 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7052 if (link_id.c == SACCH) {
7053 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7054 } else {
7055 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7056 }
7057}
7058
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007059/* Expect (or not expect) other kinds of messages */
7060private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7061 [exp_any] RSL.receive { repeat; }
7062 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007064 }
7065}
7066
Harald Weltee613f962018-04-18 22:38:16 +02007067/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007068private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007069 RslLinkId link_id,
7070 octetstring l3,
7071 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007072 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007073) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007074 timer T := 3.0;
7075 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7076 T.start;
7077 /* Expect RLL UNITDATA IND on RSL side */
7078 alt {
7079 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7080 setverdict(pass);
7081 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007082 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007083 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007084 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007086 }
Harald Weltee613f962018-04-18 22:38:16 +02007087 }
7088}
7089
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007090/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7091private function f_data_mo(
7092 RslLinkId link_id,
7093 boolean p, uint3_t nr, uint3_t ns,
7094 octetstring l3,
7095 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007096 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007097) runs on ConnHdlr {
7098 timer T := 3.0;
7099 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7100 T.start;
7101 /* Expect RLL DATA IND on RSL side */
7102 alt {
7103 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7104 setverdict(pass);
7105 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007106 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007107 [] as_rsl_any_ind(exp_any);
7108 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007110 }
7111 }
7112}
7113
Harald Weltee613f962018-04-18 22:38:16 +02007114/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007115private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007116 f_l1_tune(L1CTL);
7117 f_est_dchan(true);
7118
7119 /* now we actually need to transmit some data both ways to check if the encryption works */
7120 var L1ctlDlMessage dl;
7121
Stefan Sperling603d98e2018-07-25 16:47:28 +02007122 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007123 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7124
7125 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7126 f_unitdata_mt(link_id, l3);
7127
7128 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7129 f_unitdata_mo(link_id, l3);
7130
7131 /* release the channel */
7132 f_rsl_chan_deact();
7133 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7134 f_rslem_unregister(0, g_chan_nr);
7135}
7136testcase TC_chan_act_a51() runs on test_CT {
7137 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7138 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7139 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7140}
7141testcase TC_chan_act_a52() runs on test_CT {
7142 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7143 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7144 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7145}
7146testcase TC_chan_act_a53() runs on test_CT {
7147 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7148 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7149 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7150}
Eric Wildb9260392021-05-15 19:48:22 +02007151testcase TC_chan_act_a54() runs on test_CT {
7152 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7153 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7154 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7155}
Harald Weltee613f962018-04-18 22:38:16 +02007156
Eric Wildf1827a72019-05-28 17:37:35 +02007157/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7158 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 +07007159private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007160 f_l1_tune(L1CTL);
7161 f_est_dchan(true);
7162
7163 /* now we actually need to transmit some data both ways to check if the encryption works */
7164 var L1ctlDlMessage dl;
7165
7166 var octetstring l3 := f_rnd_octstring(20);
7167 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7168
7169 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7170 f_unitdata_mt(link_id, l3);
7171
7172 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7173 f_unitdata_mo(link_id, l3);
7174
7175 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007176 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007177
7178 /* modify key to break proper encryption */
7179 g_pars.encr.key := f_rnd_octstring(8);
7180 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7181 rsl.ies := rsl.ies & { ei };
7182 RSL.send(rsl);
7183
7184 timer T0 := 1.0;
7185 T0.start;
7186 /* Expect RSL MODIFY ACK */
7187 alt {
7188 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7189 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7191 }
7192 [] T0.timeout {
7193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7194 }
7195 }
7196
7197 var octetstring l3msg := f_rnd_octstring(15);
7198 timer T1 := 3.0;
7199 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7200 due to broken encryption */
7201 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7202 T1.start;
7203 alt {
7204 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7206 }
7207 [] T1.timeout {
7208 setverdict(pass);
7209 }
7210 }
7211
7212 /* release the channel */
7213 f_rsl_chan_deact();
7214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7215 f_rslem_unregister(0, g_chan_nr);
7216}
7217testcase TC_rsl_modify_encr() runs on test_CT {
7218 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7219 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7220 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7221}
Harald Weltee613f962018-04-18 22:38:16 +02007222
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007223/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7224private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7225runs on test_CT {
7226 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7227 var ASP_RSL_Unitdata ud;
7228 timer T;
7229
7230 /* Intave is 6 SACCH periods by default */
7231 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7232
7233 T.start(Tval);
7234 alt {
7235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7236 setverdict(pass);
7237 }
7238 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7239 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7240 }
7241 [] RSL_CCHAN.receive { repeat; }
7242 [] T.timeout {
7243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7244 "Timeout waiting for RF RESource INDication");
7245 }
7246 }
7247}
7248testcase TC_rsl_rf_resource_ind() runs on test_CT {
7249 var RSL_ResourceInfo info := { };
7250
7251 f_init(trx_nr := 0);
7252
7253 f_init_l1ctl();
7254 f_l1_tune(L1CTL);
7255
7256 /* g_AllChannels contains all logical channels */
7257 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7258 var RslChannelNr chan_nr := g_AllChannels[i];
7259
7260 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7261 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7262 { continue; }
7263
7264 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7265 }
7266
7267 /* Align to the first interference report */
7268 f_TC_rsl_rf_resource_ind(?);
7269
7270 /* Test 4 consecutive messages */
7271 for (var integer i := 0; i < 4; i := i + 1) {
7272 f_TC_rsl_rf_resource_ind(info);
7273 }
7274
7275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7276}
7277
Harald Weltee613f962018-04-18 22:38:16 +02007278/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007279private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007280 /* L3 payload doesn't matter, as it is passed transparently */
7281 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7282 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7283 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7284
7285 f_l1_tune(L1CTL);
7286
7287 /* first establish a dedicated channel in the clear */
7288 f_est_dchan(false);
7289
7290 /* Establish ABM */
7291 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7292
7293 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7294 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7295 /* expect the L3 to arrive still unencrypted on the MS side */
7296 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7297
7298 /* configure L1 to apply ciphering */
7299 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7300 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7301
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007302 /* send first ciphered I-frame in response and expect it on RSL */
7303 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007304
7305 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7306 * and hence enable encryption also on the downlink */
7307
7308 /* expect bi-directional communication work in encrypted mode */
7309 f_unitdata_mo(link_id, f_rnd_octstring(15));
7310 f_unitdata_mt(link_id, f_rnd_octstring(15));
7311
7312 /* release the channel */
7313 f_rsl_chan_deact();
7314 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7315 f_rslem_unregister(0, g_chan_nr);
7316}
7317testcase TC_encr_cmd_a51() runs on test_CT {
7318 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7319 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7320 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7321}
7322testcase TC_encr_cmd_a52() runs on test_CT {
7323 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7324 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7325 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7326}
7327testcase TC_encr_cmd_a53() runs on test_CT {
7328 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7329 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7330 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7331}
Eric Wildb9260392021-05-15 19:48:22 +02007332testcase TC_encr_cmd_a54() runs on test_CT {
7333 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7334 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7335 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7336}
Harald Weltee613f962018-04-18 22:38:16 +02007337
7338private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7339 var LapdmFrame lf;
7340 var octetstring reenc;
7341
7342 /* decode the LAPDm frame */
7343 if (ischosen(exp_match.ab)) {
7344 lf.ab := dec_LapdmFrameAB(enc);
7345 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007347 }
7348
7349 /* check if decoder result matches expectation */
7350 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007352 } else {
7353 log(name, ": matched");
7354 setverdict(pass);
7355 }
7356
7357 /* test if re-encoded frame equals original input */
7358 reenc := enc_LapdmFrame(lf);
7359 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007361 } else {
7362 setverdict(pass);
7363 }
7364}
7365
7366testcase TC_lapdm_selftest() runs on test_CT {
7367 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7368 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7369 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7370 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7371 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7372 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7373 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7374}
7375
Stefan Sperling4880be42018-08-07 18:12:59 +02007376/***********************************************************************
7377 * DTX Related (see GSM 05.08, section 8.3)
7378 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007379private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007380 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007381 var GsmFrameNumber first_fn;
7382 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007383 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007384 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007385 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7386 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007387 const integer frame_dtx_tchf_mod := 104;
7388 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7389 * which operates in terms of blocks rather than frames. */
7390 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7391 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007392 timer T := 5.0;
7393
7394 f_l1_tune(L1CTL);
7395 RSL.clear;
7396 L1CTL.clear;
7397
7398 /* activate TCHF signalling channel */
7399 f_est_dchan(false);
7400
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007401 /* A template for matching dummy LAPDm func=UA frames */
7402 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7403 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7404 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7405
Stefan Sperling4880be42018-08-07 18:12:59 +02007406 T.start;
7407 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007408 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007409 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007410
7411 if (is_first_frame) {
7412 is_first_frame := false;
7413 first_fn := dl.dl_info.frame_nr;
7414 }
7415
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007416 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007417 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007418 T.stop;
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 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7423 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007424
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007425 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007426 setverdict(fail, "Not enough fill frames received: ",
7427 nfill_frames, " out of ", expected_fill_frames);
7428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007429 } else {
7430 setverdict(pass);
7431 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007432 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007433 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7434 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7435 * we should only see the subset of frames numbers which correspond to a block boundary.
7436 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7437 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7438 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007439 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007440 repeat;
7441 }
7442 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007443 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7444 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7445 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007446 f_rsl_chan_deact();
7447 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007448 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007449 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007450 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007451 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007452 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007453
7454 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007455 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7456 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007457 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7458 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7459 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007460 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7461 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007462 case else {
7463 /* This shall not happen, just to be sure */
7464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7465 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007466 }
7467
7468 f_rsl_chan_deact();
7469 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007470
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007471 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007472 setverdict(pass);
7473 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007474 setverdict(fail, "Not enough fill frames received: ",
7475 nfill_frames, " out of ", expected_fill_frames);
7476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007477 }
7478 } else {
7479 repeat;
7480 }
7481 }
7482 }
7483 [] L1CTL.receive { repeat; }
7484 [] T.timeout {
7485 f_rsl_chan_deact();
7486 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007488 }
7489 }
7490}
7491
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007492private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007493 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007494 var ConnHdlr vc_conn;
7495 var ConnHdlrPars pars;
7496 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007497 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007498 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007499 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007500 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007501 if (dtxd) {
7502 if (i >= 4) { /* DTX is only allowed on TCH/F */
7503 break;
7504 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007505 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007506 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007507 vc_conn.done;
7508 }
7509}
7510
7511/* Verify that L2 fill frames are sent on TCH in signaling mode if
7512 * there is nothing to transmit while DTX is disabled on downlink. */
7513testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7514 f_tch_sign_l2_fill_frame(false);
7515}
7516
7517/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7518 * there is nothing to transmit while DTX is enabled on downlink. */
7519testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7520 f_tch_sign_l2_fill_frame(true);
7521}
Harald Welte0472ab42018-03-12 15:02:26 +01007522
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007523testcase TC_chopped_ipa_ping() runs on test_CT {
7524 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7525}
7526
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007527testcase TC_chopped_ipa_payload() runs on test_CT {
7528 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7529}
7530
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007531
7532/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7533 * Return value: Measurement Report to be sent (encoded octetstring). */
7534type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7535 runs on ConnHdlr return octetstring;
7536
7537private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7538runs on ConnHdlr {
7539 var L1ctlDlMessage l1_dl;
7540 var SacchL1Header l1h;
7541 var octetstring l2;
7542
7543 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7544 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7545 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7546 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7547
7548 /* Pass it to the user specified call-back function */
7549 l2 := cb.apply(l1h, num_blocks);
7550 /* Send a Measurement Report generated by the call-back */
7551 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7552 l1_dl.dl_info.link_id,
7553 l1h, l2));
7554
7555 /* Shall we keep going? */
7556 num_blocks := num_blocks - 1;
7557 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7558 if (num_blocks > 0) { repeat; }
7559 }
7560 [] L1CTL.receive { repeat; }
7561}
7562
7563private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7564runs on ConnHdlr return octetstring {
7565 /* Command the L1 to apply received parameters */
7566 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7567
7568 /* Dummy measurement report (the results are invalid) */
7569 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7570}
7571
7572private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7573runs on ConnHdlr return octetstring {
7574 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7575 setverdict(fail, "Unexpected MS Power level change: ",
7576 g_pars.l1_pars.ms_power_level, " -> ",
7577 l1h.ms_power_lvl);
7578 }
7579
7580 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7581}
7582
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007583private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7584runs on ConnHdlr return octetstring {
7585 /* UL RSSI oscillation driven by SACCH block number */
7586 if (num_blocks rem 2 == 0) {
7587 f_trxc_fake_rssi(-100);
7588 } else {
7589 f_trxc_fake_rssi(-50);
7590 }
7591
7592 /* Make sure that MS power level remains constant */
7593 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7594}
7595
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007596/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7597private function f_TC_ms_pwr_ctrl_constant(charstring id)
7598runs on ConnHdlr {
7599 var integer num_blocks := 8;
7600 timer T := int2float(num_blocks);
7601
7602 f_l1_tune(L1CTL);
7603 RSL.clear;
7604
7605 /* These IEs are needed for autonomous MS power control */
7606 var template (value) RSL_IE_List ies := {
7607 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7608 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7609 }),
7610 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7611 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7612 })
7613 };
7614
7615 /* Ensure that 'rx-current' equals 'rx-target' */
7616 f_trxc_fake_rssi(mp_uplink_power_target);
7617
7618 /* Establish a dedicated channel */
7619 f_est_dchan(more_ies := valueof(ies));
7620
7621 L1CTL.clear;
7622 T.start;
7623 alt {
7624 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7625 [] T.timeout {
7626 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7627 num_blocks, " were not handled");
7628 }
7629 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007630
7631 /* Release the channel */
7632 f_rsl_chan_deact();
7633 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007634}
7635testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7636 var ConnHdlr vc_conn;
7637 var ConnHdlrPars pars;
7638
7639 f_init();
7640
7641 /* Explicitly configure the Uplink power target (in dBm) */
7642 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7643
7644 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7645 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7646 log(testcasename(), ": starting on ", pars.chan_nr);
7647
7648 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7649 pars, trxc_comp := true);
7650 vc_conn.done;
7651 }
7652
7653 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7655}
7656
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007657/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7658private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7659runs on ConnHdlr {
7660 var integer num_blocks := 16;
7661 timer T := int2float(num_blocks);
7662
7663 f_l1_tune(L1CTL);
7664 RSL.clear;
7665
7666 /* These IEs are needed for autonomous MS power control */
7667 var template (value) RSL_IE_List ies := {
7668 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7669 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7670 }),
7671 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7672 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7673 })
7674 };
7675
7676 /* Ensure that 'rx-current' equals 'rx-target' */
7677 f_trxc_fake_rssi(mp_uplink_power_target);
7678
7679 /* Establish a dedicated channel */
7680 f_est_dchan(more_ies := valueof(ies));
7681
7682 L1CTL.clear;
7683 T.start;
7684 alt {
7685 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7686 [] T.timeout {
7687 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7688 num_blocks, " were not handled");
7689 }
7690 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007691
7692 /* Release the channel */
7693 f_rsl_chan_deact();
7694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007695}
7696testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7697 var ConnHdlr vc_conn;
7698 var ConnHdlrPars pars;
7699
7700 f_init();
7701
7702 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7703 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7704 /* Explicitly configure the Uplink power range (target and delte) */
7705 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7706 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7707
7708 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7709 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7710 log(testcasename(), ": starting on ", pars.chan_nr);
7711
7712 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7713 pars, trxc_comp := true);
7714 vc_conn.done;
7715 }
7716
7717 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7719}
7720
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007721private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7722 var template L1ctlDlMessage tr_bad_frame;
7723 var L1ctlDlMessage l1_dl;
7724 timer T := 8.0;
7725
7726 f_l1_tune(L1CTL);
7727 RSL.clear;
7728
7729 f_est_dchan();
7730
7731 /* There may be a few errors right after the channel activation */
7732 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7733 L1CTL.clear;
7734
7735 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7736 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7737 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7738 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7739 tr_bad_frame.payload := ?;
7740
7741 T.start;
7742 alt {
7743 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7744 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7745 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7746 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7747 }
7748 [] as_l1_sacch();
7749 [] L1CTL.receive { repeat; }
7750 [] T.timeout {
7751 /* We're done, break the loop */
7752 setverdict(pass);
7753 }
7754 }
7755
7756 f_rsl_chan_deact();
7757 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7758}
7759testcase TC_speech_no_rtp_tchf() runs on test_CT {
7760 var ConnHdlr vc_conn;
7761 var ConnHdlrPars pars;
7762
7763 f_init();
7764
7765 /* TS1, TCH/F, V1 (FR codec) */
7766 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7767 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7768 vc_conn.done;
7769}
7770testcase TC_speech_no_rtp_tchh() runs on test_CT {
7771 var ConnHdlr vc_conn;
7772 var ConnHdlrPars pars;
7773
7774 f_init();
7775
7776 /* TS5, TCH/H, V1 (HR codec) */
7777 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7778 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7779 vc_conn.done;
7780}
7781
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007782/* Verify handling of Downlink and Uplink speech frames */
7783private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7784 var L1ctlDlMessage l1_dl;
7785 var PDU_RTP rtp_pdu;
7786 var octetstring pl;
7787 timer Td, Tu;
7788
7789 f_l1_tune(L1CTL);
7790 f_est_dchan();
7791
7792 /* Activate the RTP emulation */
7793 pl := f_rnd_octstring(6);
7794 f_rtpem_activate(pl);
7795
7796 /* Give the scheduler some time to fill up the buffers */
7797 f_sleep(2.0);
7798 L1CTL.clear;
7799 RSL.clear;
7800
7801 /* Make sure that Downlink frames are received at the UE */
7802 Td.start(2.0);
7803 alt {
7804 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7805 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7806 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7807 l1_dl.payload.traffic_ind.data));
7808 setverdict(pass);
7809 }
7810 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7811 setverdict(fail, "Rx unexpected Downlink speech frame ",
7812 "(", l1_dl.payload.traffic_ind.data, ") ",
7813 "expected (", pl, ")");
7814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7815 }
7816 [] as_l1_sacch();
7817 [] L1CTL.receive { repeat; }
7818 [] Td.timeout {
7819 setverdict(fail, "Timeout waiting for Downlink speech frames");
7820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7821 }
7822 }
7823
7824 /* Make sure that Uplink frames are received at the BTS */
7825 RTPEM_DATA.clear;
7826 Tu.start(2.0);
7827 alt {
7828 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7829 if (rtp_pdu.data != pl)
7830 { repeat; }
7831 }
7832 [] RTPEM_DATA.receive { repeat; }
7833 [] Tu.timeout {
7834 setverdict(fail, "Timeout waiting for Uplink speech frames");
7835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7836 }
7837 }
7838
7839 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7840 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7841 f_rsl_chan_deact();
7842 f_rslem_unregister(0, g_chan_nr);
7843}
7844testcase TC_speech_rtp_tchf() runs on test_CT {
7845 var ConnHdlr vc_conn;
7846 var ConnHdlrPars pars;
7847
7848 f_init();
7849
7850 /* TS1, TCH/F, V1 (FR codec) */
7851 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7852 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7853 vc_conn.done;
7854
7855 /* TS1, TCH/F, V2 (EFR codec) */
7856 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7857 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7858 vc_conn.done;
7859
7860 /* TODO: also test V3 (AMR codec) */
7861
7862 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7863}
7864testcase TC_speech_rtp_tchh() runs on test_CT {
7865 var ConnHdlr vc_conn;
7866 var ConnHdlrPars pars;
7867
7868 f_init();
7869
7870 /* TS5, TCH/H0, V1 (HR codec) */
7871 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7872 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7873 vc_conn.done;
7874
7875 /* TODO: also test V3 (AMR codec) */
7876
7877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7878}
7879
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007880private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7881 var GsmFrameNumber fn;
7882 var ChannelDescription ch_desc;
7883 var integer ra := 23;
7884
7885 f_l1_tune(L1CTL);
7886 RSL.clear;
7887
7888 /* Send RACH request and wait for ChanReq */
7889 fn := f_rach_req_wait_chan_rqd(ra);
7890
7891 /* The BSC already sends the Immediate Assignment, before the channel is active.
7892 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7893 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7894 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7895 if (g_pars.fhp.enabled) {
7896 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7897 } else {
7898 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7899 }
7900 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7901 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7902
7903 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7904 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7905 var L1ctlDlMessage dl;
7906 var GsmRrMessage rr;
7907
7908 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7909 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7910 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7911 rr_imm_ass.payload.imm_ass.chan_desc := *;
7912
7913 timer T := 1.0;
7914 T.start;
7915 alt {
7916 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7917 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7918 if (match(rr, rr_imm_ass)) {
7919 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7920 mtc.stop;
7921 } else {
7922 repeat;
7923 }
7924 }
7925 [] L1CTL.receive { repeat; }
7926 [] T.timeout;
7927 }
7928 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7929 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7930
7931 /* Now expect the IMM ASS on Um */
7932 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7933 setverdict(pass);
7934
7935 /* Release the channel */
7936 f_rsl_chan_deact();
7937 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7938}
7939
7940testcase TC_early_immediate_assignment() runs on test_CT {
7941 var ConnHdlr vc_conn;
7942 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7943 f_init();
7944 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
7945 vc_conn.done;
7946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7947}
7948
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007949private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
7950 var integer ra := oct2int(f_rnd_ra_cs());
7951 var ChannelDescription ch_desc;
7952
7953 /* Tune the MS to BCCH */
7954 f_l1_tune(L1CTL);
7955
7956 /* Send RACH request and wait for ChanReq */
7957 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
7958
7959 /* Activate channel on the BTS side */
7960 f_rsl_chan_act(g_pars.chan_mode);
7961
7962 /* Craft channel description (with or without frequency hopping parameters) */
7963 if (g_pars.fhp.enabled) {
7964 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7965 } else {
7966 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7967 }
7968
7969 /* Send IMM.ASS via CCHAN */
7970 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7971 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7972
7973 /* Receive IMM.ASS on the MS side */
7974 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7975
7976 /* Match the Channel Description IE in received IMM.ASS */
7977 if (not match(imm_ass.chan_desc, ch_desc)) {
7978 setverdict(fail, "Channel Description IE does not match");
7979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7980 }
7981
7982 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
7983 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
7984
7985 /* Expect SACCH frames on Downlink */
7986 L1CTL.clear;
7987 f_exp_sacch(true);
7988
7989 /* We're done, deactivate and release */
7990 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7991 f_rsl_chan_deact();
7992}
7993testcase TC_est_dchan() runs on test_CT {
7994 var ConnHdlr vc_conn;
7995 var ConnHdlrPars pars;
7996
7997 f_init();
7998
7999 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8000 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8001 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8002 vc_conn.done;
8003 }
8004
8005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8006}
8007
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008008private type record TopTestCase {
8009 RSL_IE_BS_Power bs_power,
8010 RSL_IE_OSMO_TopAcchCap top_cap,
8011 record of TopTestStep steps
8012};
8013private type record TopTestStep {
8014 MeasurementResults meas_res optional,
8015 GsmRxLev overpower_sacch,
8016 GsmRxLev overpower_facch
8017};
8018
8019private function f_rxlev_match(template (present) RslLinkId link_id,
8020 template (present) GsmRxLev rxlev)
8021runs on ConnHdlr {
8022 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8023 if (not match(dl.dl_info.rx_level, rxlev)) {
8024 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8025 " does not match expected RxLev := ", rxlev);
8026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8027 }
8028}
8029
8030private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8031 var TopTestCase tc := g_pars.spec.top;
8032 var GsmRxLev rxlev_dcch;
8033 var L1ctlDlMessage dl;
8034
8035 /* Wait for Pau ramping to complete */
8036 f_sleep(6.0);
8037
8038 f_l1_tune(L1CTL);
8039 L1CTL.clear;
8040 RSL.clear;
8041
8042 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8043 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8044 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8045
8046 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8047 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8048
8049 /* Additional IEs for the CHANnel ACTIVation message */
8050 var template (value) RSL_IE_List ies := {
8051 /* Employ BS power control in static mode */
8052 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8053 bs_power := tc.bs_power
8054 }),
8055 /* Indicate the given Temporary Overpower capability */
8056 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8057 top_acch_cap := tc.top_cap
8058 })
8059 };
8060
8061 /* Establish a dedicated channel */
8062 f_est_dchan(more_ies := valueof(ies));
8063
8064 /* Give it some time to stabilize */
8065 f_sleep(0.480 * 2.0);
8066 L1CTL.clear;
8067 RSL.clear;
8068
8069 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8070 var TopTestStep step := tc.steps[i];
8071 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8072 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8073
8074 log("Executing step[", i, "] := ", step);
8075
8076 /* Send RR Measurement Report (if present) */
8077 if (ispresent(step.meas_res)) {
8078 f_transceive_meas_rep(step.meas_res);
8079 f_sleep(0.480 * 2.0);
8080 L1CTL.clear;
8081 }
8082
8083 /* Check RxLev on both FACCH and SACCH */
8084 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8085 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8086
8087 setverdict(pass);
8088 }
8089}
8090testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8091 var ConnHdlrPars pars;
8092 var ConnHdlr vc_conn;
8093
8094 f_init();
8095
8096 /* Verify lower and upper RxQual thresholds */
8097 var template TopTestCase top := {
8098 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8099 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8100 steps := {
8101 /* Channel established, no overpower */
8102 { meas_res := omit,
8103 overpower_sacch := 0, overpower_facch := 0 },
8104
8105 /* Worst possible RxQual value, overpower of 4dB */
8106 { meas_res := ts_MeasurementResults(rxq_f := 7),
8107 overpower_sacch := 4, overpower_facch := 4 },
8108 /* Worst possible RxQual value, disabling overpower */
8109 { meas_res := ts_MeasurementResults(rxq_f := 0),
8110 overpower_sacch := 0, overpower_facch := 0 },
8111
8112 /* Lower threshold not reached, no overpower */
8113 { meas_res := ts_MeasurementResults(rxq_f := 1),
8114 overpower_sacch := 0, overpower_facch := 0 },
8115 /* Lower threshold not reached, no overpower */
8116 { meas_res := ts_MeasurementResults(rxq_f := 2),
8117 overpower_sacch := 0, overpower_facch := 0 },
8118 /* Lower threshold reached, overpower of 4dB */
8119 { meas_res := ts_MeasurementResults(rxq_f := 4),
8120 overpower_sacch := 4, overpower_facch := 4 },
8121 /* Upper threshold not reached, keeping overpower */
8122 { meas_res := ts_MeasurementResults(rxq_f := 3),
8123 overpower_sacch := 4, overpower_facch := 4 },
8124 /* Upper threshold reached, disabling overpower */
8125 { meas_res := ts_MeasurementResults(rxq_f := 2),
8126 overpower_sacch := 0, overpower_facch := 0 }
8127 }
8128 };
8129
8130 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8131 spec := { top := top }, trx_nr := 1));
8132 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8133 vc_conn.done;
8134
8135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8136}
8137testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8138 var ConnHdlrPars pars;
8139 var ConnHdlr vc_conn;
8140
8141 f_init();
8142
8143 /* Verify handling of FULL and SUB values */
8144 var template TopTestCase top := {
8145 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8146 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8147 steps := {
8148 /* Channel established, no overpower */
8149 { meas_res := omit,
8150 overpower_sacch := 0, overpower_facch := 0 },
8151
8152 /* Invalid measurement results, no overpower */
8153 { meas_res := ts_MeasurementResults(rxq_f := 7,
8154 rxq_s := 7,
8155 valid := false),
8156 overpower_sacch := 0, overpower_facch := 0 },
8157
8158 /* DTXu was in use, no overpower */
8159 { meas_res := ts_MeasurementResults(rxq_f := 7,
8160 rxq_s := 0,
8161 dtx_used := true),
8162 overpower_sacch := 0, overpower_facch := 0 },
8163 /* DTXu was in use, overpower of 4 dB */
8164 { meas_res := ts_MeasurementResults(rxq_f := 0,
8165 rxq_s := 7,
8166 dtx_used := true),
8167 overpower_sacch := 4, overpower_facch := 4 }
8168 }
8169 };
8170
8171 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8172 spec := { top := top }, trx_nr := 1));
8173 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8174 vc_conn.done;
8175
8176 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8177}
8178testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8179 var ConnHdlrPars pars;
8180 var ConnHdlr vc_conn;
8181
8182 f_init();
8183
8184 /* Overpower is always on, SACCH disabled */
8185 var template TopTestCase top := {
8186 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8187 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8188 rxqual := 0, /* always on */
8189 sacch_enable := false),
8190 steps := {
8191 /* Channel established, FACCH overpower */
8192 { meas_res := omit,
8193 overpower_sacch := 0, overpower_facch := 4 },
8194 /* MS indicates good RxQual, no difference */
8195 { meas_res := ts_MeasurementResults(rxq_f := 0),
8196 overpower_sacch := 0, overpower_facch := 4 },
8197 /* MS indicates bad RxQual, no difference */
8198 { meas_res := ts_MeasurementResults(rxq_f := 7),
8199 overpower_sacch := 0, overpower_facch := 4 }
8200 }
8201 };
8202
8203 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8204 spec := { top := top }, trx_nr := 1));
8205 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8206 vc_conn.done;
8207
8208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8209}
8210testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8211 var ConnHdlrPars pars;
8212 var ConnHdlr vc_conn;
8213
8214 f_init();
8215
8216 /* Overpower is always on, FACCH disabled */
8217 var template TopTestCase top := {
8218 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8219 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8220 rxqual := 0, /* always on */
8221 facch_enable := false),
8222 steps := {
8223 /* Channel established, SACCH overpower */
8224 { meas_res := omit,
8225 overpower_sacch := 4, overpower_facch := 0 },
8226 /* MS indicates good RxQual, no difference */
8227 { meas_res := ts_MeasurementResults(rxq_f := 0),
8228 overpower_sacch := 4, overpower_facch := 0 },
8229 /* MS indicates bad RxQual, no difference */
8230 { meas_res := ts_MeasurementResults(rxq_f := 7),
8231 overpower_sacch := 4, overpower_facch := 0 }
8232 }
8233 };
8234
8235 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8236 spec := { top := top }, trx_nr := 1));
8237 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8238 vc_conn.done;
8239
8240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8241}
8242testcase TC_acch_overpower_limit() runs on test_CT {
8243 var ConnHdlrPars pars;
8244 var ConnHdlr vc_conn;
8245
8246 f_init();
8247
8248 /* Overpower higher than current power reduction level (2dB) */
8249 var template TopTestCase top := {
8250 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8251 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8252 rxqual := 0 /* always on */),
8253 steps := {
8254 /* Channel established, ACCH overpower of 2dB */
8255 { meas_res := omit,
8256 overpower_sacch := 2, overpower_facch := 2 },
8257 /* MS indicates good RxQual, no difference */
8258 { meas_res := ts_MeasurementResults(rxq_f := 0),
8259 overpower_sacch := 2, overpower_facch := 2 },
8260 /* MS indicates bad RxQual, no difference */
8261 { meas_res := ts_MeasurementResults(rxq_f := 7),
8262 overpower_sacch := 2, overpower_facch := 2 }
8263 }
8264 };
8265
8266 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8267 spec := { top := top }, trx_nr := 1));
8268 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8269 vc_conn.done;
8270
8271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8272}
8273
Harald Welte0472ab42018-03-12 15:02:26 +01008274/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8275/* protocol error as per 44.006 */
8276/* link layer failure (repetition of I-frame N200 times without ACK */
8277/* repetition of SABM or DISC N200 times without ACK */
8278/* receptiom of SABM in multi-frame established state */
8279
8280
Harald Welte68e495b2018-02-25 00:05:57 +01008281/* TODO Areas:
8282
8283* channel activation
8284** with BS_Power / MS_Power, bypassing power control loop
8285** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008286** with timing advance from initial activation on
8287* mode modify
8288** encryption
8289** multirate
8290* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008291** unsupported algorithm
8292* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01008293* BS Power Control
8294* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008295* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01008296* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008297** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008298* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008299** DATA_IND from BTS->PCU
8300** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008301
8302*/
Harald Welte70767382018-02-21 12:16:40 +01008303
8304control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008305 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008306 execute( TC_chan_act_stress() );
8307 execute( TC_chan_act_react() );
8308 execute( TC_chan_deact_not_active() );
8309 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008310 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008311 execute( TC_sacch_filling() );
8312 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008313 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008314 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008315 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008316 execute( TC_sacch_chan_act_ho_async() );
8317 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008318 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008319 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008320 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008321 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008322 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008323 execute( TC_rach_load_idle_thresh0() );
8324 execute( TC_rach_load_idle_below_thresh() );
8325 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008326 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008327 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008328 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008329 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008330 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008331 execute( TC_meas_res_sign_tchf() );
8332 execute( TC_meas_res_sign_tchh() );
8333 execute( TC_meas_res_sign_sdcch4() );
8334 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008335 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008336 execute( TC_meas_res_speech_tchf_sapi3() );
8337 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008338 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008339 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008340 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008341 execute( TC_rsl_bs_pwr_static_ass() );
8342 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008343 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008344 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008345 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008346 execute( TC_rsl_ms_pwr_dyn_up() );
8347 execute( TC_rsl_ms_pwr_dyn_down() );
8348 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8349 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008350 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008351 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008352 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008353 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008354 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008355 execute( TC_paging_imsi_80percent() );
8356 execute( TC_paging_tmsi_80percent() );
8357 execute( TC_paging_imsi_200percent() );
8358 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008359 execute( TC_rsl_protocol_error() );
8360 execute( TC_rsl_mand_ie_error() );
8361 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008362 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008363 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008364 execute( TC_si_sched_2bis() );
8365 execute( TC_si_sched_2ter() );
8366 execute( TC_si_sched_2ter_2bis() );
8367 execute( TC_si_sched_2quater() );
8368 execute( TC_si_sched_13() );
8369 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008370 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008371 execute( TC_ipa_crcx_twice_not_active() );
8372 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008373 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008374 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008375
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008376 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008377 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008378 execute( TC_pcu_act_req() );
8379 execute( TC_pcu_act_req_wrong_ts() );
8380 execute( TC_pcu_act_req_wrong_bts() );
8381 execute( TC_pcu_act_req_wrong_trx() );
8382 execute( TC_pcu_deact_req() );
8383 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008384 execute( TC_pcu_ver_si1() );
8385 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008386 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008387 if (mp_l1_supports_gprs) {
8388 execute( TC_pcu_data_req_pdtch() );
8389 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008390 execute( TC_pcu_data_req_wrong_bts() );
8391 execute( TC_pcu_data_req_wrong_trx() );
8392 execute( TC_pcu_data_req_wrong_ts() );
8393 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008394 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008395 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008396 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008397 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008398 execute( TC_pcu_data_req_imm_ass_pch() );
8399 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008400 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008401 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008402 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008403 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008404 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008405 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008406 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008407 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008408 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008409 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008410 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008411 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008412 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008413 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008414 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008415 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008416 execute( TC_dyn_osmo_pdch_act_deact() );
8417 execute( TC_dyn_osmo_pdch_double_act() );
8418 execute( TC_dyn_ipa_pdch_act_deact() );
8419 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008420 execute( TC_pcu_info_ind_fh_params() );
8421 execute( TC_pcu_socket_nsvc_ipv4() );
8422 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008423 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008424 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008425 } else {
8426 log("PCU socket path not available, skipping PCU tests");
8427 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008428
Harald Welte3d04ae62018-04-04 20:29:05 +02008429 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008430 execute( TC_dyn_osmo_pdch_tchf_act() );
8431 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008432 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008433 execute( TC_dyn_ipa_pdch_tchf_act() );
8434 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008435
8436 execute( TC_rll_est_ind() );
8437 execute( TC_rll_est_req_DCCH_3() );
8438 execute( TC_rll_est_req_ACCH_3() );
8439 execute( TC_rll_rel_ind_DCCH_0() );
8440 execute( TC_rll_rel_ind_DCCH_3() );
8441 execute( TC_rll_rel_ind_ACCH_0() );
8442 execute( TC_rll_rel_ind_ACCH_3() );
8443 execute( TC_rll_rel_req() );
8444 execute( TC_rll_unit_data_req_DCCH() );
8445 execute( TC_rll_unit_data_req_ACCH() );
8446 execute( TC_rll_unit_data_ind_DCCH() );
8447 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008448
8449 execute( TC_chan_act_a51() );
8450 execute( TC_chan_act_a52() );
8451 execute( TC_chan_act_a53() );
8452 execute( TC_encr_cmd_a51() );
8453 execute( TC_encr_cmd_a52() );
8454 execute( TC_encr_cmd_a53() );
8455
Harald Welteee25aae2019-05-19 14:32:37 +02008456 execute( TC_err_rep_wrong_mdisc() );
8457 execute( TC_err_rep_wrong_msg_type() );
8458 execute( TC_err_rep_wrong_sequence() );
8459
Harald Weltee613f962018-04-18 22:38:16 +02008460 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008461
8462 execute( TC_tch_sign_l2_fill_frame() );
8463 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008464
8465 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008466 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008467
8468 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008469 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008470
8471 execute( TC_speech_no_rtp_tchf() );
8472 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008473 execute( TC_speech_rtp_tchf() );
8474 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008475
8476 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008477
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008478 execute( TC_acch_overpower_rxqual_thresh() );
8479 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8480 execute( TC_acch_overpower_always_on_facch() );
8481 execute( TC_acch_overpower_always_on_sacch() );
8482 execute( TC_acch_overpower_limit() );
8483
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008484 /* BEWARE: these test cases can potentially break the IUT or cause
8485 * weird/unexpected behavior. Ensure that they are executed last. */
8486 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8487 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008488}
8489
8490
8491}