blob: ab7c979c198e89542fcbc645a6d4ce4b8d25b8a0 [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 */
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001077private function f_sacch_present(template octetstring l3_exp,
1078 boolean do_fail := true)
1079runs on ConnHdlr {
Harald Welteea17b912018-03-11 22:29:31 +01001080 var L1ctlDlMessage dl;
Harald Welteea17b912018-03-11 22:29:31 +01001081 timer T_sacch := 3.0;
1082 L1CTL.clear;
1083 T_sacch.start;
1084 alt {
1085 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1086 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1087 if (match(l3, l3_exp)) {
1088 setverdict(pass);
1089 } else {
1090 repeat;
1091 }
1092 }
1093 [] L1CTL.receive { repeat; }
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001094 [not do_fail] T_sacch.timeout {
1095 log("Timeout waiting for SACCH ", l3_exp);
1096 }
1097 [do_fail] T_sacch.timeout {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001098 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
1099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001100 }
1101 }
1102}
1103
Harald Welte55700662018-03-12 13:15:43 +01001104/* verify that given SACCH payload is not present */
1105private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1106 var L1ctlDlMessage dl;
Harald Welte55700662018-03-12 13:15:43 +01001107 timer T_sacch := 3.0;
1108 L1CTL.clear;
1109 T_sacch.start;
1110 alt {
1111 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1112 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1113 if (match(l3, l3_exp)) {
Vadim Yanitskiy77a65f82022-03-11 12:34:47 +03001114 setverdict(fail, "Received unexpected SACCH ", dl);
1115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001116 } else {
1117 repeat;
1118 }
1119 }
1120 [] L1CTL.receive { repeat; }
1121 [] T_sacch.timeout {
1122 setverdict(pass);
1123 }
1124 }
1125}
1126
Harald Welte629cc6b2018-03-11 17:19:05 +01001127/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001128private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1129 /* Set a known default SACCH filling for SI5 */
1130 var octetstring si5 := f_rnd_octstring(19);
1131 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1132
1133 f_l1_tune(L1CTL);
1134 RSL.clear;
1135
1136 /* activate the logical channel */
1137 f_est_dchan();
1138
1139 /* check that the specified SI5 value is actually sent */
1140 f_sacch_present(si5);
1141
1142 /* release the channel */
1143 RSL.clear;
1144 f_rsl_chan_deact();
1145 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1146}
1147testcase TC_sacch_filling() runs on test_CT {
1148 var ConnHdlr vc_conn;
1149 var ConnHdlrPars pars;
1150 f_init();
1151 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1152 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1153 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1154 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1155 vc_conn.done;
1156 }
1157 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001159}
1160
Harald Welte629cc6b2018-03-11 17:19:05 +01001161/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001162private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1163 /* Set a known default SACCH filling for SI5 */
1164 var octetstring si5 := f_rnd_octstring(19);
1165 var octetstring si5_diff := f_rnd_octstring(19);
1166 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1167
1168 f_l1_tune(L1CTL);
1169 RSL.clear;
1170
1171 log("Activating channel, expecting standard SI5");
1172 /* activate the logical channel */
1173 f_est_dchan();
1174 /* check that the specified SI5 value is actually sent */
1175 f_sacch_present(si5);
1176
1177 /* set channel-specific different SI5 */
1178 log("Setting channel specific SACCH INFO, expecting it");
1179 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1180 /* check that the specified lchan-specific value is now used */
1181 f_sacch_present(si5_diff);
1182
1183 /* deactivate the channel and re-activate it, this should result in default SI5 */
1184 log("De-activating and re-activating channel, expecting standard SI5");
1185 f_rsl_chan_deact();
1186 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1187 /* Verify that the TRX-wide default SACCH filling is present again */
1188 f_sacch_present(si5);
1189
1190 /* release the channel */
1191 RSL.clear;
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_info_mod() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1200 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1201 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1202 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1203 vc_conn.done;
1204 }
1205 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001207}
1208
Harald Welte075d84c2018-03-12 13:07:24 +01001209/* Test SACCH scheduling of multiple different SI message types */
1210private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1211 var octetstring si5 := f_rnd_octstring(19);
1212 var octetstring si5bis := f_rnd_octstring(19);
1213 var octetstring si5ter := f_rnd_octstring(19);
1214 var octetstring si6 := f_rnd_octstring(19);
1215
1216 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1217 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1218 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1219 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1220
1221 f_l1_tune(L1CTL);
1222 RSL.clear;
1223
1224 /* activate the logical channel */
1225 f_est_dchan();
1226 L1CTL.clear;
1227
1228 /* check that SACCH actually are received as expected */
1229 f_sacch_present(si5);
1230 f_sacch_present(si5bis);
1231 f_sacch_present(si5ter);
1232 f_sacch_present(si6);
1233
1234 /* release the channel */
1235 f_rsl_chan_deact();
1236 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1237}
1238testcase TC_sacch_multi() runs on test_CT {
1239 var ConnHdlr vc_conn;
1240 var ConnHdlrPars pars;
1241 f_init();
1242 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1243 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1244 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1245 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1246 vc_conn.done;
1247 }
1248 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001250}
1251
Harald Welte55700662018-03-12 13:15:43 +01001252/* Test if SACH information is modified as expected */
1253private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1254 var octetstring si5 := f_rnd_octstring(19);
1255 var octetstring si6 := f_rnd_octstring(19);
1256
1257 /* First, configure both SI5 and SI6 to be transmitted */
1258 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1259 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1260
1261 f_l1_tune(L1CTL);
1262 RSL.clear;
1263
1264 /* activate the logical channel */
1265 f_est_dchan();
1266 L1CTL.clear;
1267
1268 /* check that SACCH actually are received as expected */
1269 f_sacch_present(si5);
1270 f_sacch_present(si6);
1271
1272 /* disable SI6 */
1273 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1274
1275 /* check that SI5 is still transmitted */
1276 f_sacch_present(si5);
1277 /* check if SI6 is now gone */
1278 f_sacch_missing(si6);
1279
1280 /* release the channel */
1281 f_rsl_chan_deact();
1282 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1283}
1284testcase TC_sacch_multi_chg() runs on test_CT {
1285 var ConnHdlr vc_conn;
1286 var ConnHdlrPars pars;
1287 f_init();
1288 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1289 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1290 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1291 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1292 vc_conn.done;
1293 }
1294 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001296}
1297
Harald Weltec8d363c2019-05-19 20:36:48 +02001298/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1299private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1300 var octetstring si5 := f_rnd_octstring(19);
1301 var octetstring si6 := f_rnd_octstring(19);
1302 var octetstring si5_specific := f_rnd_octstring(19);
1303 var octetstring si6_specific := f_rnd_octstring(19);
1304
1305 /* First, configure both SI5 and SI6 to be transmitted */
1306 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1307 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1308
1309 f_l1_tune(L1CTL);
1310 RSL.clear;
1311
1312 /* activate channel with different SACCH filling */
1313 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1314 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1315 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1316 }));
1317 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1318 RSL_IE_Body:{sacch_info := sacch_info})) };
1319 f_est_dchan(more_ies := addl_ies);
1320
1321 /* check that SACCH actually are received as expected */
1322 f_sacch_present(si5_specific);
1323 f_sacch_present(si6_specific);
1324
1325 /* release the channel */
1326 f_rsl_chan_deact();
1327 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1328}
1329testcase TC_sacch_chan_act() runs on test_CT {
1330 var ConnHdlr vc_conn;
1331 var ConnHdlrPars pars;
1332 f_init();
1333
1334 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1335 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1336 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1337 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1338 vc_conn.done;
1339 }
1340 /* TODO: do the above in parallel, rather than sequentially? */
1341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1342}
1343
Harald Welte8b01c792019-05-19 22:51:25 +02001344/* verify that SACCH DL transmission is started only if MS power IE present
1345 * see section 4.1.3 of 3GPP TS 48.058 */
1346private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1347 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001348 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001349
1350 f_l1_tune(L1CTL);
1351 RSL.clear;
1352
1353 /* Step 1: Activate ASYNC HO channel without MS power IE */
1354
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001355 var integer ho_ref := oct2int(f_rnd_octstring(1));
1356 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1357 RSL_IE_Body:{ handover_ref := ho_ref }));
1358 var RSL_IE_List addl_ies := {
1359 ho_ref_ie
1360 };
1361
Harald Welte8b01c792019-05-19 22:51:25 +02001362 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001363 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 +02001364 /* don't perform immediate assignment here, as we're testing non-IA case */
1365 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001366 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001367
1368 /* Verify that no DL SACCH is being received */
1369 f_sacch_missing(?);
1370
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001371 /* Send handover Access Burst and expect SACCH to start */
1372 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1373
1374 f_sacch_present(si5);
1375
Harald Welte8b01c792019-05-19 22:51:25 +02001376 f_rsl_chan_deact();
1377 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1378
1379
1380 /* Step 2: Activate ASYNC HO channel with MS power IE */
1381
1382 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001383 addl_ies := {
1384 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001385 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1386 };
1387 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1388 /* don't perform immediate assignment here, as we're testing non-IA case */
1389 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001390 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001391
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001392 /* 4.1.3 "If the MS Power IE is present the BTS *may* start transmission
1393 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1394 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001395
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001396 /* Send handover Access Burst and expect SACCH to remain present */
1397 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1398
1399 f_sacch_present(si5);
1400
Harald Welte8b01c792019-05-19 22:51:25 +02001401 f_rsl_chan_deact();
1402 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1403}
1404testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1405 var ConnHdlr vc_conn;
1406 var ConnHdlrPars pars;
1407 f_init();
1408
1409 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1410 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1411 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1412 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1413 vc_conn.done;
1414 }
1415 /* TODO: do the above in parallel, rather than sequentially? */
1416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1417}
1418
1419/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1420 * see section 4.1.4 of 3GPP TS 48.058 */
1421private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1422 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001423 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1424
Harald Welte8b01c792019-05-19 22:51:25 +02001425 var RSL_IE_List addl_ies;
1426
1427 f_l1_tune(L1CTL);
1428 RSL.clear;
1429
1430 /* Step 1: Activate SYNC HO channel without MS power IE */
1431
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001432 var integer ho_ref := oct2int(f_rnd_octstring(1));
1433 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1434 RSL_IE_Body:{ handover_ref := ho_ref }));
1435 addl_ies := {
1436 ho_ref_ie
1437 };
1438
Harald Welte8b01c792019-05-19 22:51:25 +02001439 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001440 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 +02001441 /* don't perform immediate assignment here, as we're testing non-IA case */
1442 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001443 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001444
1445 /* Verify that no DL SACCH is being received */
1446 f_sacch_missing(?);
1447
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001448 /* Send handover Access Burst and expect SACCH to start */
1449 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1450
1451 f_sacch_present(si5);
1452
Harald Welte8b01c792019-05-19 22:51:25 +02001453 f_rsl_chan_deact();
1454 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1455
1456
1457 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1458
1459 /* Activate channel on BTS side */
1460 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001461 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001462 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1463 };
1464 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1465 /* don't perform immediate assignment here, as we're testing non-IA case */
1466 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001467 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001468
Vadim Yanitskiyf9136a12022-03-11 14:04:27 +03001469 /* 4.1.4 "If only the MS Power IE is present the BTS *may* start transmission
1470 * also on the SACCH". "May" does not mean "shall", so osmo-bts does not. */
1471 f_sacch_present(si5, do_fail := false);
Harald Welte8b01c792019-05-19 22:51:25 +02001472
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001473 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001474 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1475
1476 f_sacch_present(si5);
1477
Harald Welte8b01c792019-05-19 22:51:25 +02001478 f_rsl_chan_deact();
1479 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1480
1481
1482 /* Step 2b: Activate SYNC HO channel with TA IE */
1483
1484 /* Activate channel on BTS side */
1485 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001486 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001487 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1488 };
1489 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1490 /* don't perform immediate assignment here, as we're testing non-IA case */
1491 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001492 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001493
1494 /* Verify that no DL SACCH is being received */
1495 f_sacch_missing(?);
1496
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001497 /* Send handover Access Burst and expect SACCH to start */
1498 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1499
1500 f_sacch_present(si5);
1501
Harald Welte8b01c792019-05-19 22:51:25 +02001502 f_rsl_chan_deact();
1503 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1504
1505
1506 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1507
1508 /* Activate channel on BTS side */
1509 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001510 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001511 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1512 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1513 };
1514 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1515 /* don't perform immediate assignment here, as we're testing non-IA case */
1516 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001517 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001518
1519 /* Verify that DL SACCH is being received */
1520 f_sacch_present(si5);
1521
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001522 /* Send handover Access Burst and expect SACCH to remain present */
1523 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1524
1525 f_sacch_present(si5);
1526
Harald Welte8b01c792019-05-19 22:51:25 +02001527 f_rsl_chan_deact();
1528 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1529}
1530testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1531 var ConnHdlr vc_conn;
1532 var ConnHdlrPars pars;
1533 f_init();
1534
1535 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1536 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1537 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1538 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1539 vc_conn.done;
1540 }
1541 /* TODO: do the above in parallel, rather than sequentially? */
1542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1543}
Harald Welte629cc6b2018-03-11 17:19:05 +01001544
1545
1546/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001547 * RACH Handling
1548 ***********************************************************************/
1549
Harald Welte8c24c2b2018-02-26 08:31:31 +01001550/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001551private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001552 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001553 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001554 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001555
Harald Welte8c24c2b2018-02-26 08:31:31 +01001556 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001557 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001558 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001559 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001560 if (emerg == true) {
1561 ra := f_rnd_ra_emerg();
1562 } else {
1563 ra := f_rnd_ra_cs();
1564 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001565 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1566 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001568 }
1569 fn_last := fn;
1570
1571 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001572 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001573 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001574 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001575 T.stop;
1576 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001577 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001579 }
1580 [] RSL_CCHAN.receive { repeat; }
1581 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001582 test_failed := true;
1583 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001584 }
1585 }
1586 }
Maxba06feb2019-03-05 10:52:46 +01001587 if (test_failed) {
1588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001589 }
Maxba06feb2019-03-05 10:52:46 +01001590 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001592}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001593
Philipp Maier16ade782020-07-08 21:36:00 +02001594/* Normal variant */
1595testcase TC_rach_content() runs on test_CT {
1596 f_TC_rach_content(emerg := false);
1597}
1598
1599/* Emergency call variant */
1600testcase TC_rach_content_emerg() runs on test_CT {
1601 f_TC_rach_content(emerg := true);
1602}
1603
Harald Welte8c24c2b2018-02-26 08:31:31 +01001604/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1605testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001606 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001607 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001608 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001609 f_l1_tune(L1CTL);
1610
1611 var GsmFrameNumber fn_last := 0;
1612 for (var integer i := 0; i < 1000; i := i+1) {
1613 var OCT1 ra := f_rnd_ra_cs();
1614 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1615 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001617 }
1618 fn_last := fn;
1619 }
1620 var integer rsl_chrqd := 0;
1621 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001622 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001623 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001625 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001626 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001627 repeat;
1628 }
1629 [] RSL_CCHAN.receive { repeat; }
1630 [] T.timeout { }
1631 }
1632 if (rsl_chrqd == 1000) {
1633 setverdict(pass);
1634 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001636 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001638}
1639
Harald Welte3453ab42019-05-24 21:19:58 +02001640private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1641 var charstring bts_str := "bts " & int2str(bts_nr);
1642 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1643}
1644
1645/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1646private template integer tr_rach_slots_per_interval := (90 .. 130);
1647
1648/* Expect 0 RACH load on an idle BTS that has just started up */
1649testcase TC_rach_load_idle_thresh0() runs on test_CT {
1650 var ASP_RSL_Unitdata rx_ud;
1651
1652 f_init_vty_bsc();
1653 /* send load indications even at 0% load */
1654 f_vty_load_ind_thresh(0);
1655 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1656 f_sleep(2.0);
1657
1658 f_init();
1659
Harald Weltee37f9a52020-10-11 20:45:23 +02001660 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1661 alt {
1662 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1663 [] RSL_CCHAN.receive { repeat }
1664 }
1665
Harald Welte3453ab42019-05-24 21:19:58 +02001666 timer T := 5.0;
1667 T.start;
1668 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001669 [] 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 +02001670 setverdict(pass);
1671 repeat;
1672 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001673 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001674 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1675 repeat;
1676 }
1677 [] RSL_CCHAN.receive {
1678 repeat;
1679 }
1680 [] T.timeout { }
1681 }
1682
1683 f_vty_load_ind_thresh(10);
1684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1685}
1686
1687/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1688testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1689 var ASP_RSL_Unitdata rx_ud;
1690
1691 f_init_vty_bsc();
1692 f_init();
1693
1694 timer T := 5.0;
1695 T.start;
1696 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001697 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001698 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1699 repeat;
1700 }
1701 [] RSL_CCHAN.receive {
1702 repeat;
1703 }
1704 [] T.timeout {
1705 setverdict(pass);
1706 }
1707 }
1708
1709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1710}
1711
1712/* Expect 0 RACH load on an idle BTS that has just started up */
1713testcase TC_rach_load_count() runs on test_CT {
1714 var ASP_RSL_Unitdata rx_ud;
1715 var integer load_access_count := 0;
1716
1717 f_init_vty_bsc();
1718 /* send load indications even at 0% load */
1719 f_vty_load_ind_thresh(0);
1720 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1721 f_sleep(2.0);
1722 f_init();
1723
1724 f_init_l1ctl();
1725 f_sleep(1.0);
1726 f_l1_tune(L1CTL);
1727
Harald Welte52ae1682020-10-11 20:45:55 +02001728 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1729 alt {
1730 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1731 [] RSL_CCHAN.receive { repeat }
1732 }
1733
Harald Welte3453ab42019-05-24 21:19:58 +02001734 var GsmFrameNumber fn_last := 0;
1735 for (var integer i := 0; i < 1000; i := i+1) {
1736 var OCT1 ra := f_rnd_ra_cs();
1737 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1738 if (fn == fn_last) {
1739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1740 }
1741 fn_last := fn;
1742 }
1743
1744 timer T := 5.0;
1745 T.start;
1746 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001747 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001748 -> value rx_ud {
1749 var RSL_IE_Body ie;
1750 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1751 load_access_count := load_access_count + ie.rach_load.access_count;
1752 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1753 setverdict(fail, "Access count cannot be < Busy count");
1754 }
1755 repeat;
1756 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001757 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001758 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1759 repeat;
1760 }
1761 [] RSL_CCHAN.receive {
1762 repeat;
1763 }
1764 [] T.timeout { }
1765 }
1766 if (load_access_count == 1000) {
1767 setverdict(pass);
1768 } else {
1769 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1770 }
1771
1772 f_vty_load_ind_thresh(10);
1773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1774}
1775
Harald Welte54a2a2d2018-02-26 09:14:05 +01001776private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001777 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001778 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001779 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001780 f_sleep(0.5);
1781
1782 /* Transmit RACH request + wait for confirmation */
1783 var OCT1 ra := f_rnd_ra_cs();
1784 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1785
1786 /* Check for expected result */
1787 timer T := 1.5;
1788 T.start;
1789 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001790 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001791 setverdict(pass);
1792 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001793 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001795 }
1796 [] RSL_CCHAN.receive { repeat; }
1797 [not expect_pass] T.timeout {
1798 setverdict(pass);
1799 }
1800 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001802 }
1803 }
1804}
1805
1806/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1807testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001808 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001809 f_init_l1ctl();
1810 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001811 f_sleep(1.0);
1812
1813 /* default max-ta is 63 (full range of GSM timing advance */
1814
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001815 /* We allow early arrival up to 2 symbols */
1816 f_rach_toffs(-1*256, true);
1817 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001818 f_rach_toffs(-10*256, false);
1819
1820 /* 0 / 32 / 63 bits is legal / permitted */
1821 f_rach_toffs(0, true);
1822 f_rach_toffs(32*256, true);
1823 f_rach_toffs(63*256, true);
1824
1825 /* more than 63 bits is not legal / permitted */
1826 f_rach_toffs(64*256, false);
1827 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001829}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001830
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001831private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001832 var GsmFrameNumber fn;
1833 var RSL_Message rm;
1834
1835 f_l1_tune(L1CTL);
1836 RSL.clear;
1837
1838 /* Generate a random Handover Reference */
1839 var integer ho_ref := oct2int(f_rnd_octstring(1));
1840
1841 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1842 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1843 RSL_IE_Body:{ handover_ref := ho_ref }));
1844
1845 /* Activate a channel on the BTS side (no encryption) */
1846 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1847 act_type := t_RSL_IE_ActType_HO_SYNC);
1848
1849 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1850 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001851 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001852
1853 /* Send handover Access Burst */
1854 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1855
1856 /* TODO: test mismatching Handover Reference, and missing IE */
1857
1858 /* Wait for handover detection */
1859 timer T := 3.0;
1860 T.start;
1861 alt {
1862 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1863 log("Handover RACH has been detected: ", rm);
1864 setverdict(pass);
1865 }
1866 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1868 log2str("RSL_CHAN_RQD was not expected: ", rm));
1869 }
1870 [] RSL.receive { repeat; }
1871 [] T.timeout {
1872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1873 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1874 }
1875 }
1876
1877 /* Release the channel */
1878 f_rsl_chan_deact();
1879 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1880}
1881
1882/* Test handover RACH detection */
1883testcase TC_ho_rach() runs on test_CT {
1884 var ConnHdlrPars pars;
1885 var ConnHdlr vc_conn;
1886
1887 f_init();
1888
1889 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1890 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1891 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1892 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1893 vc_conn.done;
1894 }
1895
1896 /* TODO: do the above in parallel, rather than sequentially? */
1897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1898}
1899
Harald Welte93640c62018-02-25 16:59:33 +01001900/***********************************************************************
1901 * Measurement Processing / Reporting
1902 ***********************************************************************/
1903
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001904private template (value) LapdmAddressField
1905ts_LapdmAddr(template (value) LapdmSapi sapi,
1906 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001907 spare := '0'B,
1908 lpd := 0,
1909 sapi := sapi,
1910 c_r := c_r,
1911 ea := true
1912}
1913
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001914private template (value) LapdmFrameAB
1915ts_LAPDm_AB(template (value) LapdmSapi sapi,
1916 template (value) GsmRrL3Message l3,
1917 template (value) boolean c_r := false,
1918 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001919 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001920 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001921 len := 0, /* overwritten */
1922 m := false,
1923 el := 1,
Vadim Yanitskiy16e29912022-03-12 13:26:21 +03001924 payload := enc_GsmRrL3Message(valueof(l3)),
1925 padding := ''O
Harald Welte70767382018-02-21 12:16:40 +01001926}
1927
1928/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001929private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001930 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001931 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001932
Harald Weltef8df4cb2018-03-10 15:15:08 +01001933 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001934 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001935
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001936 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001937 g_pars.l1_pars.meas_ul.full.rxlev,
1938 g_pars.l1_pars.meas_ul.sub.rxlev,
1939 g_pars.l1_pars.meas_ul.full.rxqual,
1940 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001941 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001942
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001943 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1944 g_pars.l1_pars.ms_power_level, false,
1945 g_pars.l1_pars.ms_actual_ta);
1946
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001947 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1948 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001949
1950 log("Sending Measurement Report: ", l1h, l2);
1951 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001952 repeat;
1953 }
1954}
1955
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001956/* handle incoming downlink SACCH, decode the L1 header into the given record */
1957private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1958 boolean do_apply := true)
1959runs on ConnHdlr
1960{
1961 var L1ctlDlMessage l1_dl;
1962
1963 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1964 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1965 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1966 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1967
1968 if (do_apply) {
1969 /* Update TA and MS power to follow what BTS requests */
1970 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1971 }
1972 }
1973}
1974
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001975private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001976 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001977 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001978 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1979 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001980 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1981 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001982 repeat;
1983 }
1984}
1985
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001986private altstep as_l1_tch_loop() runs on ConnHdlr {
1987 var L1ctlDlMessage l1_dl;
1988 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1989 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001990
1991 /* occasionaly inject FACCH frames into the uplink */
1992 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1993 var octetstring pl := '010301'O;
1994 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1995 f_pad_oct(pl, 23, '2B'O)));
1996 } else {
1997 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1998 l1_dl.payload.traffic_ind.data));
1999 }
2000
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002001 repeat;
2002 }
2003}
2004
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002005private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01002006 uint6_t rxlev,
2007 uint3_t rxqual
2008}
2009
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002010private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002011 MeasElem full,
2012 MeasElem sub
2013}
2014
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002015private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002016 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002017 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002018 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002019 MeasElemFS meas_ul,
2020 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002021 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002022 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002023 uint8_t ms_actual_ta,
2024 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002025}
2026
2027/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2028private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2029 return 63 + (toffs256s/256);
2030}
2031
Harald Welted5684392018-03-10 18:22:04 +01002032private function f_max(integer a, integer b) return integer {
2033 if (a > b) {
2034 return a;
2035 } else {
2036 return b;
2037 }
2038}
2039
2040private function f_min(integer a, integer b) return integer {
2041 if (a < b) {
2042 return a;
2043 } else {
2044 return b;
2045 }
2046}
2047
2048/* compute negative tolerance val-tolerance, ensure >= min */
2049private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2050 val := val - tolerance;
2051 return f_max(val, min);
2052}
2053
2054/* compute positive tolerance val+tolerance, ensure <= max */
2055private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2056 val := val + tolerance;
2057 return f_min(val, max);
2058}
2059
2060/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2061private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2062return template integer {
2063 var template integer ret;
2064 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2065 return ret;
2066}
2067
2068
Harald Welte70767382018-02-21 12:16:40 +01002069/* build a template for matching measurement results against */
2070private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2071 var ConnL1Pars l1p := g_pars.l1_pars;
2072 var template RSL_IE_UplinkMeas ul_meas := {
2073 len := 3,
2074 rfu := '0'B,
2075 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002076 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002077 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002078 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002079 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002080 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2081 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002082 supp_meas_info := omit
2083 };
Harald Welte685d5982018-02-27 20:42:05 +01002084 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002085 ul_meas.len := (3+8);
2086 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002087 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002088 toa256_min := ?,
2089 toa256_max := ?,
2090 toa256_std_dev := ?
2091 }
Harald Welte685d5982018-02-27 20:42:05 +01002092 }
Harald Welte70767382018-02-21 12:16:40 +01002093 var template RSL_IE_BS_Power bs_power := {
2094 reserved := 0,
2095 epc := false,
2096 fpc := false,
2097 power_level := l1p.bs_power_level
2098 };
2099 var template RSL_IE_L1Info l1_info := {
2100 ms_power_lvl := l1p.ms_power_level,
2101 fpc := false,
2102 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002103 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002104 };
2105 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002106 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002107 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2108 ?, t_toffs);
2109}
2110
Philipp Maierdd841d32019-12-17 14:44:54 +01002111/* build a template for matching measurement results that do not contain any
2112 * MS related measurement (l1_info, l3_info and ms timing offset). */
2113private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2114 var ConnL1Pars l1p := g_pars.l1_pars;
2115 var template RSL_IE_UplinkMeas ul_meas := {
2116 len := 3,
2117 rfu := '0'B,
2118 dtx_d := l1p.dtx_enabled,
2119 rxlev_f_u := ?,
2120 reserved1 := '00'B,
2121 rxlev_s_u := ?,
2122 reserved2 := '00'B,
2123 rxq_f_u := ?,
2124 rxq_s_u := ?,
2125 supp_meas_info := omit
2126 };
2127 if (l1p.toa256_enabled) {
2128 ul_meas.len := (3+8);
2129 ul_meas.supp_meas_info := {
2130 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2131 toa256_min := ?,
2132 toa256_max := ?,
2133 toa256_std_dev := ?
2134 }
2135 }
2136 var template RSL_IE_BS_Power bs_power := {
2137 reserved := 0,
2138 epc := false,
2139 fpc := false,
2140 power_level := l1p.bs_power_level
2141 };
2142
2143 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2144}
2145
Harald Welte70767382018-02-21 12:16:40 +01002146/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002147private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002148 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002149 var boolean chan_est := false;
2150
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002151 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002152
2153 /* Receive osmocom specific measurement reports. This is the normal
2154 * case. Here we verify that the measurement reports we sent are
2155 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002156 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2157 /* increment counter of next to-be-expected meas rep */
2158 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2159 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002160 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002161
2162 /* The following two cases may only happen in the beginning
2163 * of the channel establishment phase. Once we have received
2164 * the "our" measurement report the first time, the channel
2165 * is established and empty or hardcoded TRXCON reports must
2166 * not occur anymore. */
2167 chan_est := true;
2168
2169 repeat;
2170 }
2171
2172 /* When the BTS has established the channel, the MS might need slightly
2173 * more time to establish the channel and actually start sending. The
2174 * result is then a measurement report that just lacks the measurement
2175 * information of the MS. This is normal and we tolerate this behavior. */
2176 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2177 /* increment counter of next to-be-expected meas rep */
2178 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2179 /* Re-start the timer expecting the next MEAS RES */
2180 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002181 repeat;
2182 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002183
2184 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2185 * measurements if the TTCN3 side does not supply measurement input in
2186 * time. In those cases TRXCON will either use a cached measurement
2187 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2188 * report the templates above will not match. We tolerate this
2189 * behavior, but only once. */
2190 [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 +01002191 /* increment counter of next to-be-expected meas rep */
2192 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2193 if (g_first_meas_res) {
2194 g_first_meas_res := false;
2195 repeat;
2196 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002198 }
Harald Welte70767382018-02-21 12:16:40 +01002199 }
2200 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002202 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002203 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002205 }
2206}
2207
Harald Weltee613f962018-04-18 22:38:16 +02002208private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2209 select (rsl_alg_id) {
2210 case (RSL_ALG_ID_A5_0) { return 0; }
2211 case (RSL_ALG_ID_A5_1) { return 1; }
2212 case (RSL_ALG_ID_A5_2) { return 2; }
2213 case (RSL_ALG_ID_A5_3) { return 3; }
2214 case (RSL_ALG_ID_A5_4) { return 4; }
2215 case (RSL_ALG_ID_A5_5) { return 5; }
2216 case (RSL_ALG_ID_A5_6) { return 6; }
2217 case (RSL_ALG_ID_A5_7) { return 7; }
2218 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2220 /* Make compiler happy by calling mtc.stop here. It is already
2221 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002222 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002223 }
2224 }
2225}
2226
2227private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2228 select (rsl_alg_id) {
2229 case (RSL_ALG_ID_A5_1) { return '000'B; }
2230 case (RSL_ALG_ID_A5_2) { return '001'B; }
2231 case (RSL_ALG_ID_A5_3) { return '010'B; }
2232 case (RSL_ALG_ID_A5_4) { return '011'B; }
2233 case (RSL_ALG_ID_A5_5) { return '100'B; }
2234 case (RSL_ALG_ID_A5_6) { return '101'B; }
2235 case (RSL_ALG_ID_A5_7) { return '110'B; }
2236 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2238 /* Make compiler happy by calling mtc.stop here. It is already
2239 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002240 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002241 }
2242 }
2243}
2244
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002245/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2246private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2247 var GsmFrameNumber fn;
2248 timer T := 8.0;
2249
2250 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2251 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2252
2253 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2254 /* Send the actual RACH */
2255 fn := f_L1CTL_RACH(L1CTL, ra);
2256
2257 T.start;
2258 alt {
2259 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2260 [] T.timeout {
2261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2262 }
2263 }
2264 T.stop
2265 return fn;
2266}
Harald Weltee613f962018-04-18 22:38:16 +02002267
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002268/* Tune to a dedicated channel: L1CTL only */
2269private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002270 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002271 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002272 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002273 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002274 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002275 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002276 pars.fhp.maio_hsn.hsn,
2277 pars.fhp.maio_hsn.maio,
2278 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002279 }
2280}
2281
Harald Welte70767382018-02-21 12:16:40 +01002282/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002283private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002284 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002285
2286 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002287 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002288
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002289 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002290 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002291 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002292 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002293 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2294 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002295 }
2296
Harald Welte70767382018-02-21 12:16:40 +01002297 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002298 f_l1ctl_est_dchan(L1CTL, g_pars);
2299
Harald Weltee613f962018-04-18 22:38:16 +02002300 /* enable encryption, if requested */
2301 if (encr_enable) {
2302 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2303 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2304 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002305
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002306 /* Send TCH Mode Request to the L1 if needed */
2307 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2308 var L1ctlTchMode tch_mode;
2309
2310 select (g_pars.chan_mode.coding_alg_rate) {
2311 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2312 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2313 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2314 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2315 case else {
2316 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2317 " is not supported by the L1, falling back to signalling");
2318 tch_mode := L1CTL_CHAN_MODE_SIGN;
2319 }
2320 }
2321
2322 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2323 }
2324
Harald Weltefa45e9e2018-03-10 18:59:03 +01002325 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002326}
2327
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002328/* Initialize and start the RTP emulation component for a ConnHdlr */
2329friend function f_rtpem_activate(inout octetstring payload,
2330 RtpemConfig cfg := c_RtpemDefaultCfg,
2331 RtpemMode mode := RTPEM_MODE_BIDIR)
2332runs on ConnHdlr {
2333 /* Step 0: initialize, connect and start the emulation component */
2334 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2335 map(vc_RTPEM:RTP, system:RTP);
2336 map(vc_RTPEM:RTCP, system:RTCP);
2337 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2338 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2339 vc_RTPEM.start(RTP_Emulation.f_main());
2340
2341 /* Step 1: configure the RTP parameters */
2342 var integer payload_len := 0;
2343 var octetstring hdr := ''O;
2344
2345 select (g_pars.chan_mode) {
2346 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2347 { payload_len := 33; hdr := 'D0'O; }
2348 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2349 { payload_len := 15; hdr := '00'O; }
2350 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2351 { payload_len := 31; hdr := 'C0'O; }
2352 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2353 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2355 }
2356 }
2357
2358 /* Pad the payload to conform the expected length */
2359 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2360 cfg.tx_fixed_payload := payload;
2361 f_rtpem_configure(RTPEM_CTRL, cfg);
2362
2363 /* Step 2: bind the RTP emulation to the configured address */
2364 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2365 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2366
2367 /* Step 3: send CRCX with the configured address/port to the IUT */
2368 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2369 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2370 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2371 "IPA CRCX ACK");
2372
2373 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2374 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2375 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2376 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2377
2378 /* Step 5: set the given RTP emulation mode */
2379 f_rtpem_mode(RTPEM_CTRL, mode);
2380}
2381
Harald Welte70767382018-02-21 12:16:40 +01002382/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002383private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002384 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002385 RSL.clear;
2386
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002387 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002388 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002389 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002390 }
Harald Welte70767382018-02-21 12:16:40 +01002391
2392 f_est_dchan();
2393
2394 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2395 * RSL measurement reports on Abis side */
2396 timer T := 8.0;
2397 T.start;
2398 alt {
2399 [] as_l1_sacch();
2400 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002401 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002402 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002403 [] L1CTL.receive { repeat; }
2404 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002406 * of any earlier errors, so if we reach this timeout, we're good */
2407 setverdict(pass);
2408 }
2409 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002411 }
2412 }
2413 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002415}
Harald Welte0472ab42018-03-12 15:02:26 +01002416
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002417/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2418private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002419 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002420 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2421 timer Tup := 10.0;
2422 Tup.start;
2423 alt {
2424 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2425 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2426 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002427
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002428 if (rx_lvl != max_rx_lvl) {
2429 repeat;
2430 }
2431 Tup.stop;
2432 }
2433 [] L1CTL.receive { repeat; }
2434 [] Tup.timeout {
2435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2436 log2str("Didn't reach full power ", max_rx_lvl));
2437 }
2438 }
2439 return max_rx_lvl;
2440}
2441
2442/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2443private function f_verify_ramp_up() runs on ConnHdlr {
2444 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002445 var integer initial_rx_lvl := -1;
2446 var integer last_rx_lvl := -1;
2447 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2448
2449 timer T := 2.0;
2450 alt {
2451 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2452 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2453 log("Received rx_level=", rx_lvl);
2454 if (initial_rx_lvl == -1) {
2455 initial_rx_lvl := rx_lvl;
2456 last_rx_lvl := rx_lvl;
2457
2458 /* Expect a somehow low value during first received messages */
2459 if (initial_rx_lvl >= max_rx_lvl / 2) {
2460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2461 log2str("Detected high initial tx power during ramp up: ",
2462 initial_rx_lvl , ", full power is", max_rx_lvl));
2463 }
2464 }
2465
2466 /* received Rx level bigger than maximum allowed power by CN */
2467 if (rx_lvl > max_rx_lvl) {
2468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2469 log2str("Detected Tx power higher than full power: ",
2470 rx_lvl , " > ", max_rx_lvl));
2471 }
2472
2473 /* Make sure it never decreases, since we are rumping up */
2474 if (last_rx_lvl > rx_lvl) {
2475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2476 log2str("Detected Tx power decrease during ramp up: ",
2477 last_rx_lvl , " -> ", rx_lvl));
2478 }
2479
2480 if (rx_lvl == max_rx_lvl and not T.running) {
2481 /* We reached the maximum power, start timer and receive
2482 /* a few more to make sure we don't surpass it */
2483 log("Reached full power, wating a bit more until success");
2484 T.start;
2485 }
2486
2487 last_rx_lvl := rx_lvl;
2488 repeat;
2489 }
2490 [] L1CTL.receive { repeat; }
2491 [] T.timeout { }
2492 }
2493
2494 /* We didn't increase tx power during ramp up */
2495 if (initial_rx_lvl < last_rx_lvl) {
2496 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2497 } else {
2498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2499 log2str("No Tx power increase during whole ramp up: ",
2500 initial_rx_lvl , " -> ", last_rx_lvl));
2501 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002502}
2503
2504/* verify BTS ramps power down to rx_level 0 */
2505private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2506 var L1ctlDlMessage l1_dl;
2507 var integer last_rx_lvl := max_rx_lvl;
2508
2509 timer Tdown := 5.0;
2510 Tdown.start;
2511 alt {
2512 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2513 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2514 log("Received rx_level=", rx_lvl);
2515
2516 /* received Rx level bigger than maximum allowed power by CN */
2517 if (rx_lvl > max_rx_lvl) {
2518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2519 log2str("Detected Tx power higher than full power: ",
2520 rx_lvl , " > ", max_rx_lvl));
2521 }
2522
2523 /* Make sure it never increases, since we are rumping down */
2524 if (last_rx_lvl < rx_lvl) {
2525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2526 log2str("Detected Tx power increase during ramp up: ",
2527 last_rx_lvl , " -> ", rx_lvl));
2528 }
2529
2530 last_rx_lvl := rx_lvl;
2531 if (last_rx_lvl != 0) {
2532 repeat;
2533 }
2534 /* we reached power level 0, we are done */
2535 Tdown.stop;
2536 }
2537 [] L1CTL.receive { repeat; }
2538 [] Tdown.timeout { }
2539 }
2540
2541 /* We didn't increase tx power during ramp down */
2542 if (max_rx_lvl > last_rx_lvl) {
2543 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2544 } else {
2545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2546 log2str("No Tx power decrease during whole ramp down: ",
2547 max_rx_lvl , " -> ", last_rx_lvl));
2548 }
2549}
2550
2551/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002552private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002553 f_l1_tune(L1CTL);
2554 RSL.clear;
2555
2556 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002557
2558 setverdict(pass);
2559}
2560testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2561 var ConnHdlr vc_conn;
2562 var ConnHdlrPars pars;
2563 f_init();
2564 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2565 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2566 pcu_comp := false, trxc_comp := true);
2567 vc_conn.done;
2568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2569}
2570
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002571/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002572private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002573 f_connhdlr_init_vty_bsc();
2574
2575 f_l1_tune(L1CTL);
2576 RSL.clear;
2577
2578 /* Wait until BTS is started and at full power */
2579 var integer max_rx_lvl := f_wait_ramp_up();
2580 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2581
2582 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2583 f_verify_ramp_down(max_rx_lvl);
2584
2585 setverdict(pass);
2586}
2587testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2588 var ConnHdlr vc_conn;
2589 var ConnHdlrPars pars;
2590 f_init();
2591 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2592 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2593 pcu_comp := false, trxc_comp := true);
2594 vc_conn.done;
2595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2596}
2597
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002598/* Verify Tx power:
2599 * + ramping down during ADM state UNLOCKED->LOCKED
2600 * + ramping up during ADM state LOCKED->UNLOCKED
2601 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002602private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002603 var L1ctlDlMessage l1_dl;
2604 var integer last_rx_lvl;
2605
2606 f_connhdlr_init_vty_bsc();
2607
2608 f_l1_tune(L1CTL);
2609 RSL.clear;
2610
2611 /* Wait until BTS is started and at full power */
2612 var integer max_rx_lvl := f_wait_ramp_up();
2613 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2614
2615 log("ADM STATE UNLOCKED->LOCKED");
2616 f_vty_enter_cfg_trx(BSCVTY);
2617 f_vty_transceive(BSCVTY, "rf_locked 1");
2618 last_rx_lvl := max_rx_lvl;
2619 f_verify_ramp_down(max_rx_lvl);
2620
2621 /* Let some time after we received 0dBm, then check we don't receive BCCH
2622 * anymore because scheduler has stopped after ramping down */
2623 f_sleep(2.0);
2624 L1CTL.clear;
2625 timer Tlocked := 2.0;
2626 Tlocked.start;
2627 alt {
2628 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2630 log2str("Received data_ind during rf_locked: ", l1_dl));
2631 }
2632 [] L1CTL.receive { repeat; }
2633 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2634 }
2635
2636 log("ADM STATE LOCKED->UNLOCKED");
2637 f_vty_transceive(BSCVTY, "rf_locked 0");
2638 f_verify_ramp_up();
2639 setverdict(pass);
2640}
2641testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2642 var ConnHdlr vc_conn;
2643 var ConnHdlrPars pars;
2644 f_init();
2645 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2646 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2647 pcu_comp := false, trxc_comp := true);
2648 vc_conn.done;
2649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2650}
2651
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002652private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002653 timer T := 8.0;
2654 T.start;
2655 var RSL_Message rsl;
2656 alt {
2657 [] as_l1_sacch();
2658 [] L1CTL.receive { repeat; }
2659 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2660 if (rsl.ies[3].body.bs_power.power_level == level) {
2661 setverdict(pass)
2662 } else {
2663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2664 }
2665 }
2666 [] T.timeout {
2667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2668 }
2669 }
2670}
2671
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002672/* See if the RSL MEASurement RESult contains expeced BS power level
2673 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002674private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002675 f_l1_tune(L1CTL);
2676 RSL.clear;
2677
2678 if (mp_bts_trxc_port != -1) {
2679 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2680 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2681 }
2682
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002683 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002684 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2685 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2686
2687 f_est_dchan(more_ies :={valueof(pwr)});
2688
2689 f_check_meas_bs_power_level(pwr_var);
2690
2691 f_rsl_chan_deact();
2692 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2693}
2694
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002695/* See if the RSL MEASurement RESult contains expeced BS power level
2696 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002697private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002698 f_l1_tune(L1CTL);
2699 RSL.clear;
2700
2701 if (mp_bts_trxc_port != -1) {
2702 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2703 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2704 }
2705
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002706 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002707 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2708
2709 f_est_dchan();
2710
2711 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2712
2713 f_check_meas_bs_power_level(pwr_var);
2714
2715 f_rsl_chan_deact();
2716 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2717}
2718
2719testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2720 var ConnHdlr vc_conn;
2721 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002722
Eric Wildae8f2622019-06-18 17:05:11 +02002723 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002724
2725 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2726 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2727 pcu_comp := false, trxc_comp := true);
2728 vc_conn.done;
2729
Eric Wildae8f2622019-06-18 17:05:11 +02002730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2731}
2732
2733testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2734 var ConnHdlr vc_conn;
2735 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002736
Eric Wildae8f2622019-06-18 17:05:11 +02002737 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002738
2739 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2740 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2741 pcu_comp := false, trxc_comp := true);
2742 vc_conn.done;
2743
Eric Wildae8f2622019-06-18 17:05:11 +02002744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2745}
2746
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002747/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2748 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2749 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002750private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002751 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002752 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002753
2754 f_trxc_fake_rssi(rxlev2dbm(10));
2755 f_l1_tune(L1CTL);
2756 RSL.clear;
2757
2758 var RSL_IE_List addl_ies;
2759 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2760
2761 addl_ies := {
2762 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2763 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2764 };
2765
2766 /* establish with power parameters */
2767 f_est_dchan(more_ies := addl_ies);
2768
2769 /* set a high value to ensure L1 power control level increases */
2770 f_trxc_fake_rssi(rxlev2dbm(20));
2771
2772 timer T2 := 6.0;
2773 T2.start;
2774 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002775 [] as_l1_sacch_l1h(l1h) {
2776 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002777 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002778 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002779 T2.stop;
2780 }
2781 [] L1CTL.receive { repeat; }
2782 [] T2.timeout {
2783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2784 "Power Level in L1 header has not increased sufficiently");
2785 }
2786 }
2787
2788 /* set a low value to ensure L1 power control level decreases */
2789 f_trxc_fake_rssi(rxlev2dbm(0));
2790
2791 timer T4 := 6.0;
2792 T4.start;
2793 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002794 [] as_l1_sacch_l1h(l1h) {
2795 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002796 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002797 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002798 T4.stop;
2799 setverdict(pass, "Power level in L1 decreased/increased as expected");
2800 }
2801 [] L1CTL.receive { repeat; }
2802 [] T4.timeout {
2803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2804 "Power Level in L1 header has not decreased sufficiently");
2805 }
2806 }
2807
2808 f_rsl_chan_deact();
2809 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2810
2811}
2812
2813/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002814private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002815 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002816 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002817
2818 /* set a low value to ensure power increases */
2819 f_trxc_fake_rssi(rxlev2dbm(10));
2820 f_l1_tune(L1CTL);
2821 RSL.clear;
2822
2823 var RSL_IE_List addl_ies;
2824 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2825
2826 addl_ies := {
2827 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2828 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2829 };
2830
2831 /* establish with power parameters */
2832 f_est_dchan(more_ies := addl_ies);
2833
2834 timer T1 := 10.0;
2835 T1.start;
2836 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002837 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002838 [] L1CTL.receive { repeat; }
2839 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002840 if (not isbound(l1h)) {
2841 setverdict(fail, "No SACCH blocks were received");
2842 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002843 setverdict(fail, "Power level in L1 header should not have changed");
2844 }
2845 }
2846 }
2847
2848 f_rsl_chan_deact();
2849 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2850
2851}
2852
2853/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002854private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002855 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002856 var uint5_t pwr_var := 15;
2857 var uint5_t pwr_max_var := f_get_max_power_from_band();
2858
2859 /* set a low value to ensure power increases */
2860 f_trxc_fake_rssi(rxlev2dbm(10));
2861 f_l1_tune(L1CTL);
2862 RSL.clear;
2863
2864 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2865 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2866
2867 /* establish with fixed power level */
2868 f_est_dchan(more_ies :={valueof(pwr)});
2869
2870 /* check our initial power level */
2871 f_wait_for_l1_power_level(pwr_var);
2872
2873 /* update power param to enable power loop
2874 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2875 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2876
2877 /* wait, then check that our power level was reduced */
2878 timer T1 := 10.0;
2879 T1.start;
2880 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002881 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002882 [] L1CTL.receive { repeat; }
2883 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002884 if (not isbound(l1h)) {
2885 setverdict(fail, "No SACCH blocks were received");
2886 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002887 setverdict(pass, "Power level in L1 header reduced as expected");
2888 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002889 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2890 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002891 }
2892 }
2893 }
2894
2895 f_rsl_chan_deact();
2896 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2897
2898}
2899
2900/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002901private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002902 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002903
2904 /* set a high value to ensure power decreases */
2905 f_trxc_fake_rssi(rxlev2dbm(50));
2906 f_l1_tune(L1CTL);
2907 RSL.clear;
2908
2909 var uint5_t pwr_var := 5;
2910 var uint5_t pwr_target_val := 15;
2911
2912 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2913 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2914
2915 /* establish with fixed power level */
2916 f_est_dchan(more_ies :={valueof(pwr)});
2917
2918 /* check our initial power level */
2919 f_wait_for_l1_power_level(pwr_var);
2920
2921 /* update power param to enable power loop
2922 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002923 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002924
2925 /* wait, then check that our power level was increased */
2926 timer T1 := 10.0;
2927 T1.start;
2928 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002929 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002930 [] L1CTL.receive { repeat; }
2931 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002932 if (not isbound(l1h)) {
2933 setverdict(fail, "No SACCH blocks were received");
2934 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2935 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002936 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002937 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002938 }
2939 }
2940 }
2941
2942 f_rsl_chan_deact();
2943 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2944
2945}
2946
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002947/* See if the power level remains constant when MS Power Parameters IE
2948 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002949private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002950 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002951
2952 /* set a high value to ensure power decreases */
2953 f_trxc_fake_rssi(rxlev2dbm(50));
2954 f_l1_tune(L1CTL);
2955 RSL.clear;
2956
2957 var uint5_t pwr_var := 5;
2958
2959 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2960 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2961
2962 /* establish with fixed power level */
2963 f_est_dchan(more_ies :={valueof(pwr)});
2964
2965 /* check our initial power level */
2966 f_wait_for_l1_power_level(pwr_var);
2967
2968 /* wait, then check that our power level did not change */
2969 timer T1 := 10.0;
2970 T1.start;
2971 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002972 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2973 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2975 "BS power control should not be active unless we receive a power parameters IE!");
2976 }
2977 repeat;
2978 }
2979 [] L1CTL.receive { repeat; }
2980 [] T1.timeout { setverdict(pass); }
2981 }
2982
2983 f_rsl_chan_deact();
2984 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2985
2986}
2987
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002988/* See if the power level remains constant when MS Power Parameters IE
2989 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002990private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002991 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002992
2993 /* set a high value to ensure power decreases */
2994 f_trxc_fake_rssi(rxlev2dbm(50));
2995 f_l1_tune(L1CTL);
2996 RSL.clear;
2997
2998 var uint5_t pwr_var := 5;
2999
3000 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
3001 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
3002
3003 /* establish with fixed power level */
3004 f_est_dchan(more_ies :={valueof(pwr)});
3005
3006 /* check our initial power level */
3007 f_wait_for_l1_power_level(pwr_var);
3008
3009 /* pwr control without power params IE, should NOT activate MS power control*/
3010 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3011
3012 /* wait, then check that our power level did not change */
3013 timer T1 := 10.0;
3014 T1.start;
3015 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003016 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3017 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3019 "BS power control should not be active unless we receive a power parameters IE!");
3020 }
3021 repeat;
3022 }
3023 [] L1CTL.receive { repeat; }
3024 [] T1.timeout { setverdict(pass); }
3025 }
3026
3027 f_rsl_chan_deact();
3028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3029
3030}
3031
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003032private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003033 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003034 timer T0 := 10.0;
3035 T0.start;
3036 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003037 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3038 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3040 "Power level in L1 header != signaled (RSL) power level.");
3041 }
3042 }
3043 [] L1CTL.receive { repeat; }
3044 [] T0.timeout {
3045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3046 "Timeout waiting for initial power level");
3047 }
3048 }
3049 T0.stop;
3050}
3051
3052private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3053 var IntegerRecord min_dbm_level;
3054 var IntegerRecord max_dbm_level;
3055 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3056
3057 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3058 if (min_dbm_level[i] == level) {
3059 return true;
3060 }
3061 }
3062 return false;
3063}
3064
3065private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3066 var IntegerRecord min_dbm_level;
3067 var IntegerRecord max_dbm_level;
3068 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3069
3070 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3071 if (max_dbm_level[i] == level) {
3072 return true;
3073 }
3074 }
3075 return false;
3076}
3077
3078private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3079 var IntegerRecord min_dbm_level;
3080 var IntegerRecord max_dbm_level;
3081 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3082 return max_dbm_level[0];
3083}
3084
3085type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003086private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003087private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3088 // 45.005 4.1.1
3089 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3090 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3091 2, 1, 0};
3092 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3093 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3094 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3095 var IntegerRecord rv;
3096
3097 select(band){
3098 case (BtsBand_allGSM){
3099 rv := gsm_power;
3100 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3101 max_dbm_level := {2, 1, 0};
3102 }
3103 case("DCS1800"){
3104 rv := dcs_power;
3105 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3106 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3107 }
3108 case("PCS1900"){
3109 rv := pcs_power;
3110 min_dbm_level := {15};
3111 max_dbm_level := {30};
3112 }
Harald Welte194b6912020-10-11 21:01:55 +02003113 case else {
3114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3115 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003116 }
3117
3118 return rv;
3119}
3120
3121private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003122 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 +02003123}
3124
3125testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3126 var ConnHdlr vc_conn;
3127 var ConnHdlrPars pars;
3128 f_init();
3129 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3130 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3131 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3132 pars.bts0_band := f_vty_get_bts0_band();
3133 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3134 vc_conn.done;
3135 }
3136 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3138}
3139
3140testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3141 var ConnHdlr vc_conn;
3142 var ConnHdlrPars pars;
3143 f_init();
3144 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3145 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3146 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3147 pars.bts0_band := f_vty_get_bts0_band();
3148 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3149 vc_conn.done;
3150 }
3151 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3153}
3154
3155testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3156 var ConnHdlr vc_conn;
3157 var ConnHdlrPars pars;
3158 f_init();
3159 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3160 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3161 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3162 pars.bts0_band := f_vty_get_bts0_band();
3163 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3164 vc_conn.done;
3165 }
3166 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3168}
3169
3170testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3171 var ConnHdlr vc_conn;
3172 var ConnHdlrPars pars;
3173 f_init();
3174 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3175 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3176 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3177 pars.bts0_band := f_vty_get_bts0_band();
3178 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3179 vc_conn.done;
3180 }
3181 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3183}
3184
Eric Wild280ccb82019-06-17 11:11:52 +02003185testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3186 var ConnHdlr vc_conn;
3187 var ConnHdlrPars pars;
3188 f_init();
3189 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3190 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3191 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3192 pars.bts0_band := f_vty_get_bts0_band();
3193 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3194 vc_conn.done;
3195 }
3196 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3198}
3199
Eric Wild095024b2019-06-17 15:08:57 +02003200testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3201 var ConnHdlr vc_conn;
3202 var ConnHdlrPars pars;
3203 f_init();
3204 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3205 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3206 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3207 pars.bts0_band := f_vty_get_bts0_band();
3208 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3209 vc_conn.done;
3210 }
3211 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3212 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3213}
3214
Philipp Maier149c3922020-10-22 17:29:36 +02003215function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003216 var template RSL_IE_ChannelMode ch_mode;
3217 var ConnHdlr vc_conn;
3218 var ConnHdlrPars pars;
3219 f_init();
3220 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3221 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3222 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003223 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003224 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3225 pcu_comp := false, trxc_comp := true);
3226 vc_conn.done;
3227 }
3228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3229}
Philipp Maier149c3922020-10-22 17:29:36 +02003230
3231testcase TC_meas_res_speech_tchf() runs on test_CT {
3232 f_TC_meas_res_speech_tchf(false);
3233}
3234
3235testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3236 f_TC_meas_res_speech_tchf(true);
3237}
3238
3239function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003240 var template RSL_IE_ChannelMode ch_mode;
3241 var ConnHdlr vc_conn;
3242 var ConnHdlrPars pars;
3243 f_init();
3244 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3245 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3246 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003247 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003248 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3249 pcu_comp := false, trxc_comp := true);
3250 vc_conn.done;
3251 }
3252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3253}
Philipp Maier149c3922020-10-22 17:29:36 +02003254
3255testcase TC_meas_res_speech_tchh() runs on test_CT {
3256 f_TC_meas_res_speech_tchh(false)
3257}
3258
3259testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3260 f_TC_meas_res_speech_tchh(true)
3261}
3262
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003263testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3264 var template RSL_IE_ChannelMode ch_mode;
3265 var ConnHdlr vc_conn;
3266 var ConnHdlrPars pars;
3267 f_init();
3268 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3269 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3270 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3271 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3272 pars.l1_pars.toa256_enabled := true;
3273 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3274 pcu_comp := false, trxc_comp := true);
3275 vc_conn.done;
3276 }
3277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3278}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003279
Harald Welte70767382018-02-21 12:16:40 +01003280testcase TC_meas_res_sign_tchf() runs on test_CT {
3281 var ConnHdlr vc_conn;
3282 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003283 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003284 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003285 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003286 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003287 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3288 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003289 vc_conn.done;
3290 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003291 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003292}
3293testcase TC_meas_res_sign_tchh() runs on test_CT {
3294 var ConnHdlr vc_conn;
3295 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003296 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003297 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003298 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003299 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003300 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3301 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003302 vc_conn.done;
3303 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003305}
3306testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3307 var ConnHdlr vc_conn;
3308 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003309 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003310 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003311 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3312 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003313 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3314 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003315 vc_conn.done;
3316 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003318}
3319testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3320 var ConnHdlr vc_conn;
3321 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003322 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003323 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003324 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3325 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003326 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3327 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003328 vc_conn.done;
3329 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003331}
Harald Welte685d5982018-02-27 20:42:05 +01003332testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3333 var ConnHdlr vc_conn;
3334 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003335 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003336 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3337 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003338 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003339 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003340 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3341 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003342 vc_conn.done;
3343 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003345}
3346
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003347/* Make sure that we always get RSL MEASurement RESult messages regardless
3348 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3349private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3350 timer Texec := 8.0;
3351 timer Timpf := 2.0;
3352 timer Tmr;
3353
3354 f_l1_tune(L1CTL);
3355 RSL.clear;
3356
3357 f_est_dchan();
3358 L1CTL.clear;
3359
3360 /* Establish the main SAPI=0 link on DCCH first */
3361 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3362
3363 /* Give more time for the first RSL MEASurement RESult */
3364 Tmr.start(0.480 * 2.0);
3365 Texec.start; /* EXECution timer */
3366 Timpf.start; /* IMPFung timer */
3367
3368 alt {
3369 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3370 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3371 /* Reschedule the MEAS RES timer */
3372 Tmr.start(0.480 + 0.120);
3373 repeat;
3374 }
3375 [] RSL.receive { repeat; }
3376 [] Tmr.timeout {
3377 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3378 }
3379 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3380 [] Timpf.timeout {
3381 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3382 log("Injected SAPI=3 traffic on SACCH");
3383 Timpf.start;
3384 repeat;
3385 }
3386 /* We're good if survived so far */
3387 [] Texec.timeout {
3388 setverdict(pass);
3389 }
3390 }
3391
3392 f_rsl_chan_deact();
3393 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3394 f_rslem_unregister(0, g_chan_nr);
3395}
3396testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3397 var template RSL_IE_ChannelMode ch_mode;
3398 var template ConnHdlrPars pars;
3399 var ConnHdlr vc_conn;
3400
3401 f_init();
3402
3403 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3404 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3405
3406 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3407 vc_conn.done;
3408
3409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3410}
3411testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3412 var template RSL_IE_ChannelMode ch_mode;
3413 var template ConnHdlrPars pars;
3414 var ConnHdlr vc_conn;
3415
3416 f_init();
3417
3418 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3419 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3420
3421 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3422 vc_conn.done;
3423
3424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3425}
3426
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003427/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3428 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003429private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003430 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003431 var RSL_IE_MS_Power ms_power;
3432 var RSL_Message rsl;
3433 var uint5_t power_level := 0;
3434
3435 f_l1_tune(L1CTL);
3436 RSL.clear;
3437
3438 f_est_dchan();
3439
3440 ms_power.reserved := 0;
3441 ms_power.fpc_epc := false;
3442
3443 /* Send the first power control command. This will disable any BTS/TRX
3444 * internal power control and switch the MS (which is not in scope of
3445 * this test) to a constant power level. We start with a power level
3446 * of 0 */
3447 ms_power.power_level := power_level;
3448 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3449 RSL.send(rsl);
3450
3451 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003452 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3453 if (l1h.ms_power_lvl != power_level) {
3454 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3455 "match the signaled (RSL) power level := ", power_level);
3456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003457 }
3458
3459 /* Signal a new power level via RSL for the next turn. */
3460 if (power_level < 31) {
3461 power_level := power_level + 1;
3462 ms_power.power_level := power_level;
3463 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3464 RSL.send(rsl);
3465 repeat;
3466 }
3467
3468 }
3469
3470 /* Ignore all other blocks */
3471 [] L1CTL.receive { repeat; }
3472
3473 }
3474
3475 f_rsl_chan_deact();
3476 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3477
3478 setverdict(pass);
3479}
3480
3481testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3482 var ConnHdlr vc_conn;
3483 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003484 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003485
3486 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3487 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3488 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3489 vc_conn.done;
3490 }
3491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3492}
Harald Welte70767382018-02-21 12:16:40 +01003493
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003494/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003495TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003496private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003497 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003498 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003499
3500 f_l1_tune(L1CTL);
3501 RSL.clear;
3502
3503 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003504 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003505
3506 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3507
3508
3509 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003510 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3511 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003512 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3513 }
3514
3515 }
3516
3517 /* Ignore all other blocks */
3518 [] L1CTL.receive { repeat; }
3519
3520 }
3521
3522 f_rsl_chan_deact();
3523 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3524
3525 setverdict(pass);
3526}
3527
3528testcase TC_rsl_chan_initial_ta() runs on test_CT {
3529 var ConnHdlr vc_conn;
3530 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003531 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003532 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003533 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3534 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003535 vc_conn.done;
3536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3537}
3538
Eric Wilde57e1a62019-05-28 13:30:55 +02003539/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003540private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003541 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003542 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003543
3544 var RSL_IE_MS_Power ms_power;
3545 ms_power.reserved := 0;
3546 ms_power.fpc_epc := false;
3547 ms_power.power_level := ms_power_level;
3548
3549 f_l1_tune(L1CTL);
3550 RSL.clear;
3551
3552 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3553
3554 timer T := 1.0;
3555 T.start;
3556 alt {
3557 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003558 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3559 if (l1h.ms_power_lvl != ms_power_level) {
3560 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3561 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003562 }
3563 }
3564 /* Ignore all other blocks */
3565 [] L1CTL.receive { repeat; }
3566 [] T.timeout {
3567 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3568 }
3569 }
3570
3571 f_rsl_chan_deact();
3572 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3573 setverdict(pass);
3574}
3575
3576testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3577 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3578 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3579}
3580
Harald Welte0472ab42018-03-12 15:02:26 +01003581/* 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 +01003582private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003583 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003584 RSL.clear;
3585
3586 f_est_dchan();
3587 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003588 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003589
3590 timer T := 40.0;
3591 T.start;
3592 alt {
3593 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3594 setverdict(pass)
3595 }
3596 [] RSL.receive { repeat };
3597 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003599 }
3600 }
3601 f_rsl_chan_deact();
3602}
3603testcase TC_conn_fail_crit() runs on test_CT {
3604 var ConnHdlr vc_conn;
3605 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003606 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003607 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3608 pars.t_guard := 60.0;
3609 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3610 vc_conn.done;
3611}
3612
Harald Welte93640c62018-02-25 16:59:33 +01003613/***********************************************************************
3614 * Paging
3615 ***********************************************************************/
3616
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003617private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003618 if (tmsi == 'FFFFFFFF'O) {
3619 return true;
3620 } else {
3621 return false;
3622 }
3623}
Harald Welte70767382018-02-21 12:16:40 +01003624
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003625private type record allowedFn { integer frame_nr }
3626private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3627private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3628private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3629private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3630private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3631private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3632private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3633private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3634private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003635{
3636 var integer frame_nr_51;
3637 frame_nr_51 := frame_nr mod 51
3638
3639 var allowedFn fn_check;
3640 fn_check.frame_nr := frame_nr_51;
3641
3642 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003644 return;
3645 }
3646
3647 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3648 return;
3649 }
3650 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3651 return;
3652 }
3653 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3654 return;
3655 }
3656 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3657 return;
3658 }
3659 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3660 return;
3661 }
3662 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3663 return;
3664 }
3665 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3666 return;
3667 }
3668 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3669 return;
3670 }
3671
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003673 return;
3674}
3675
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003676private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3677 inout integer num_paging_rcv_ids,
3678 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003679runs on test_CT {
3680 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003681 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003682 repeat;
3683 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003684 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003685 var octetstring without_plen :=
3686 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3687 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003688
3689 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3690
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003691 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3692 /* Ignore empty RR Paging Request (PCH filling) messages.
3693 * TODO: does it make sense to count them? */
3694 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003695 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3696 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003697 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003698 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3699 }
3700 } else if (match(rr, tr_PAGING_REQ2)) {
3701 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3702 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3703 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3704 }
3705 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3706 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3707 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003708 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003709 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3710 }
3711 } else if (match(rr, tr_PAGING_REQ3)) {
3712 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3713 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3714 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3715 }
3716 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3717 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3718 }
3719 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3720 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3721 }
3722 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3723 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3724 }
3725 }
3726 repeat;
3727 }
3728}
3729
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003730private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003731 boolean combined_ccch,
3732 integer bs_ag_blks_res,
3733 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003734 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3735 * paging command that is issued via RSL. */
3736 integer ps_load_modulus,
3737 /* Wait until the paging queue inside the BTS is congested before starting to add
3738 * pagings via the PCU socket (0 = disabled) */
3739 boolean ps_wait_cong,
3740 /* Maximum time to wait until the paging queue is drained at the end of the test.
3741 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3742 * to set this value to 18s, however the draining process may take significantly
3743 * longer when the queue contains paging requests for PS as those are implemented
3744 * as immediate assignments and require an entire MAC block alone. */
3745 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003746 boolean exp_load_ind,
3747 boolean exp_overload,
3748 boolean use_tmsi
3749}
3750
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003751private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003752 integer num_paging_sent,
3753 integer num_paging_rcv_msgs,
3754 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003755 integer num_overload,
3756 /* When free space inside the paging queue reaches more than 2 thirds
3757 * of its capacity cong_detected is set to true. */
3758 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003759}
3760
Harald Welte68e495b2018-02-25 00:05:57 +01003761/* Helper function for paging related testing */
3762private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003763 /* Using the PCU socket affects the timing of the paging processing. We only
3764 * activate the PCU socket if we do paging load tests that include additional
3765 * paging load that is introduced through the PCU socket. */
3766 if (cfg.ps_load_modulus > 0) {
3767 f_init_with_pcuif();
3768 } else {
3769 f_init();
3770 }
Harald Welte68e495b2018-02-25 00:05:57 +01003771 f_init_l1ctl();
3772 f_l1_tune(L1CTL);
3773
Philipp Maierca058272021-06-23 10:35:23 +02003774 var octetstring imm_ass := f_rnd_octstring(23);
3775 var ASP_RSL_Unitdata load_ind;
3776
Harald Welte68e495b2018-02-25 00:05:57 +01003777 var PagingTestState st := {
3778 num_paging_sent := 0,
3779 num_paging_rcv_msgs := 0,
3780 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003781 num_overload := 0,
3782 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003783 };
3784
3785 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3786 var float max_pch_imsi_per_sec;
3787 if (cfg.use_tmsi) {
3788 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3789 } else {
3790 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3791 }
3792 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3793 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003794 var float time_total := 20.0;
3795 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3796 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003797
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003798 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3799 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003800
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003801 timer T_itv := 0.0;
3802 T_itv.start;
3803 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003804 alt {
3805 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003806 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003807 st.num_overload := st.num_overload + 1;
3808 repeat;
3809 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003810 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003812 }
Philipp Maierca058272021-06-23 10:35:23 +02003813 [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 +01003814 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003815
3816 /* Detect paging congestion: The logic inside the BTS will diagnose the
3817 * paging queue as congested when the fill state is more than 66% (which
3818 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3819 * paging congestion is detected pagings that are issued through the PCU
3820 * socket (PS) are dropped in order to prefer the CS related pagings. */
3821 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3822 st.cong_detected := true;
3823 }
3824
Harald Welte68e495b2018-02-25 00:05:57 +01003825 /* FIXME: analyze/verify interval + contents */
3826 repeat;
3827 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003828 /* ignore other RSL messages like RF RESource INDication */
3829 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003830 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003831 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003832 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003833 /* Only relevant when testing including with PCU sock connected */
3834 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003835 [] T_itv.timeout {
3836 /* Send paging cmds based on elapsed time */
3837 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3838 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003839 var MobileIdentityV mi;
3840
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003841 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003842 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003843 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003844 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003845 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003846 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003847
3848 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003849 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 +02003850
Philipp Maierca058272021-06-23 10:35:23 +02003851 /* Add additional pagings through the PCU socket interface. */
3852 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3853 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3854 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3855 }
3856 }
3857
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003858 st.num_paging_sent := st.num_paging_sent + 1;
3859 }
3860 if (st.num_paging_sent < pkt_total) {
3861 /* Wait for interval to next PAGING COMMAND */
3862 var float time_now := T_total.read;
3863 var float next_sched := int2float(st.num_paging_sent)*interval;
3864 if (next_sched > time_now) {
3865 T_itv.start(next_sched - time_now);
3866 } else {
3867 T_itv.start(0.0);
3868 }
3869 } else {
3870 /* We are done, no need to keep counting */
3871 T_total.stop;
3872 }
3873 }
3874 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003875 }
3876 }
3877
Philipp Maierca058272021-06-23 10:35:23 +02003878 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003879 T_wait.start;
3880 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003881 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003882 [] L1CTL.receive { repeat; }
3883 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003884 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003885 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003886 /* ignore other RSL messages like RF RESource INDication */
3887 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003888 /* Only relevant when testing including with PCU sock connected */
3889 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003890 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003891 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 +01003892 }
Harald Welte68e495b2018-02-25 00:05:57 +01003893 }
3894
3895 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3896 " rcvd_ids=", st.num_paging_rcv_ids);
3897 return st;
3898}
3899
3900/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3901 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3902 * - that CCCH LOAD IND (PCH) are being generated
3903 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3904testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003905 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003906 var PagingTestCfg cfg := {
3907 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003908 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003909 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003910 ps_load_modulus := 0,
3911 ps_wait_cong := false,
3912 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003913 exp_load_ind := true,
3914 exp_overload := false,
3915 use_tmsi := false
3916 };
3917 var PagingTestState st := f_TC_paging(cfg);
3918 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3920 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003921 } else {
3922 setverdict(pass);
3923 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003925}
3926
3927/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3928 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3929 * - that CCCH LOAD IND (PCH) are being generated
3930 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3931testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003932 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003933 var PagingTestCfg cfg := {
3934 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003935 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003936 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003937 ps_load_modulus := 0,
3938 ps_wait_cong := false,
3939 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003940 exp_load_ind := true,
3941 exp_overload := false,
3942 use_tmsi := true
3943 };
3944 var PagingTestState st := f_TC_paging(cfg);
3945 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3947 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003948 } else {
3949 setverdict(pass);
3950 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003951 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003952}
3953
3954/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3955 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3956 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3957 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3958testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003959 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003960 var PagingTestCfg cfg := {
3961 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003962 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003963 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003964 ps_load_modulus := 0,
3965 ps_wait_cong := false,
3966 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003967 exp_load_ind := true,
3968 exp_overload := true,
3969 use_tmsi := false
3970 };
3971 var PagingTestState st := f_TC_paging(cfg);
3972 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3973 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003974 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003975 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003976 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 +01003977 } else {
3978 setverdict(pass);
3979 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003981}
3982
3983/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3984 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3985 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3986 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3987testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003988 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003989 var PagingTestCfg cfg := {
3990 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003991 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003992 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003993 ps_load_modulus := 0,
3994 ps_wait_cong := false,
3995 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003996 exp_load_ind := true,
3997 exp_overload := true,
3998 use_tmsi := true
3999 };
4000 var PagingTestState st := f_TC_paging(cfg);
4001 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
4002 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02004003 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01004004 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004005 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 +01004006 } else {
4007 setverdict(pass);
4008 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004010}
4011
Philipp Maierca058272021-06-23 10:35:23 +02004012/* Same as above, but with additional paging load created by PS pagings that
4013 * are issued through the PCU socket. The additional load is introduced when
4014 * the paging queue is already two thirds full. Since the BTS implements a
4015 * prioritization logic that drops the pagings from the PCU under in those
4016 * congestive sitautions the behaviour on the PS side is expected to be
4017 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4018testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4019 var SystemInformation si3 := valueof(ts_SI3_default);
4020 var PagingTestCfg cfg := {
4021 combined_ccch := true,
4022 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4023 load_factor := 2.0,
4024 ps_load_modulus := 16,
4025 ps_wait_cong := true,
4026 queue_drain_timeout := 18.0,
4027 exp_load_ind := true,
4028 exp_overload := true,
4029 use_tmsi := false
4030 };
4031 var PagingTestState st := f_TC_paging(cfg);
4032 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4033 * slots and will fully drain that buffer before returning */
4034 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4035 if (not match(st.num_paging_rcv_ids, tpl)) {
4036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4037 } else {
4038 setverdict(pass);
4039 }
4040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4041}
4042
4043
Harald Welte68e495b2018-02-25 00:05:57 +01004044
Harald Welte93640c62018-02-25 16:59:33 +01004045/***********************************************************************
4046 * Immediate Assignment / AGCH
4047 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004048private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004049 len := 0,
4050 ma := ''B
4051}
Harald Welte93640c62018-02-25 16:59:33 +01004052
Harald Weltee8d750e2018-06-10 21:41:35 +02004053private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4054 return int2str(num_tx) & " sent, "
4055 & int2str(num_rx) & " received, "
4056 & int2str(num_del) & " deleted";
4057}
4058
4059private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4060 var L1ctlDlMessage l1_dl;
4061 timer T := 10.0;
4062 var integer num_tx := 0;
4063 var integer num_rx := 0;
4064 var integer num_del := 0;
4065 var charstring res_str;
4066 var float rx_ratio;
4067
Harald Welte10474062019-05-30 16:48:17 +02004068 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004069 f_init_l1ctl();
4070 f_l1_tune(L1CTL);
4071
4072 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004073 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004074 mp_trx_pars[0].arfcn,
4075 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004076 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4077 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004078 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004079 num_tx := num_tx+1;
4080 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004081 }
4082 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004083 T.start;
4084 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004085 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004086 num_del := num_del+1;
4087 repeat;
4088 }
4089 [] RSL_CCHAN.receive {
4090 repeat;
4091 }
4092 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004093 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4094 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4095 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004096 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004097 } else {
4098 num_rx := num_rx+1;
4099 }
4100 repeat;
4101 }
4102 [] L1CTL.receive { repeat; }
4103 [] T.timeout { }
4104 }
4105 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4106 log("AGCH test: " & res_str);
4107 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004109 }
4110 rx_ratio := int2float(num_rx) / int2float(num_tx);
4111 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004112 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 +02004113 } else {
4114 setverdict(pass);
4115 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004117}
4118
Harald Weltee8d750e2018-06-10 21:41:35 +02004119/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4120testcase TC_imm_ass_1000_20ms() runs on test_CT {
4121 f_TC_imm_ass(1000, 0.02, 0.25);
4122}
4123
4124/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4125testcase TC_imm_ass_200_0ms() runs on test_CT {
4126 f_TC_imm_ass(200, 0.0, 0.05);
4127}
4128
4129/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4130testcase TC_imm_ass_200_76ms() runs on test_CT {
4131 f_TC_imm_ass(150, 0.076, 1.00);
4132}
4133
4134
4135
Harald Welte48494ca2018-02-25 16:59:50 +01004136/***********************************************************************
4137 * BCCH
4138 ***********************************************************************/
4139
4140/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004141private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004142 GsmFrameNumber frame_number,
4143 SystemInformation si
4144}
4145
4146/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004147private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004148
4149/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004150private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004151
4152/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004153private function f_si_vecslot_contains(SystemInformationVector arr,
4154 RrMessageType key,
4155 boolean bcch_ext := false)
4156return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004157 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4158 var integer fn_mod51 := arr[i].frame_number mod 51;
4159 if (not bcch_ext and fn_mod51 == 2 or
4160 bcch_ext and fn_mod51 == 6) {
4161 if (arr[i].si.header.message_type == key) {
4162 return true;
4163 }
4164 }
4165 }
4166 return false;
4167}
4168
4169/* 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 +07004170private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4171 integer tc, RrMessageType key,
4172 boolean ext_bcch := false)
4173{
Harald Welte48494ca2018-02-25 16:59:50 +01004174 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004176 }
4177}
4178
4179/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004180private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4181 RrMessageType key)
4182return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004183 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4184 if (f_si_vecslot_contains(arr[tc], key) or
4185 f_si_vecslot_contains(arr[tc], key, true)) {
4186 return true;
4187 }
4188 }
4189 return false;
4190}
4191
4192/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004193private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4194 RrMessageType key,
4195 boolean bcch_ext := false,
4196 integer n := 1, integer m := 4)
4197return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004198 var integer count := 0;
4199 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4201 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004202 }
4203 for (var integer i:= 0; i < m; i := i + 1) {
4204 var integer fn_mod51 := arr[i].frame_number mod 51;
4205 if (not bcch_ext and fn_mod51 == 2 or
4206 bcch_ext and fn_mod51 == 6) {
4207 if (arr[i].si.header.message_type == key) {
4208 count := count + 1;
4209 }
4210 }
4211 }
4212 if (count >= n) {
4213 return true;
4214 } else {
4215 return false;
4216 }
4217}
4218
4219/* 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 +07004220private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4221 integer tc, RrMessageType key,
4222 boolean ext_bcch := false,
4223 integer n, integer m)
4224{
Harald Welte48494ca2018-02-25 16:59:50 +01004225 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004227 }
4228}
4229
4230/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004231private function f_si_vecslot_contains_only(SystemInformationVector arr,
4232 RrMessageType key,
4233 boolean bcch_ext := false)
4234return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004235 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4236 var integer fn_mod51 := arr[i].frame_number mod 51;
4237 if (not bcch_ext and fn_mod51 == 2 or
4238 bcch_ext and fn_mod51 == 6) {
4239 if (arr[i].si.header.message_type != key) {
4240 return false;
4241 }
4242 }
4243 }
4244 return true;
4245}
4246
4247/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004248private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4249 integer tc, RrMessageType key,
4250 boolean ext_bcch := false)
4251{
Harald Welte48494ca2018-02-25 16:59:50 +01004252 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004254 }
4255}
4256
4257/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004258private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004259 boolean bcch_extended,
4260 boolean si1_present,
4261 boolean si2bis_present,
4262 boolean si2ter_present,
4263 boolean si2quater_present,
4264 boolean si7_present,
4265 boolean si8_present,
4266 boolean si9_present,
4267 boolean si13_present,
4268 boolean si13alt_present,
4269 boolean si15_present,
4270 boolean si16_present,
4271 boolean si17_present,
4272 boolean si2n_present,
4273 boolean si21_present,
4274 boolean si22_present
4275}
4276
4277/* 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 +07004278private function f_validate_si_scheduling(SystemInformationConfig cfg,
4279 SystemInformationVectorPerTc si_per_tc)
4280{
Harald Welte48494ca2018-02-25 16:59:50 +01004281 var integer i;
4282 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4283 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004285 }
4286 }
4287 if (cfg.si1_present) {
4288 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4289 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4290 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4291 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4292 /* make sure *ALL* contain SI1 */
4293 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4294 }
4295 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4296 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4297 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4298 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4299 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4300 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4301
4302 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4303 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4304 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4305 * consecutive occurrences of TC = 4. */
4306 if (cfg.si2bis_present and not cfg.si2ter_present) {
4307 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4308 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4309 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4310 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4311 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4312 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4313 }
4314
4315 if (cfg.si7_present or cfg.si8_present) {
4316 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4317 * if System Information type 4 does not contain all information needed for cell
4318 * selection and reselection. */
4319 if (not cfg.bcch_extended) {
4320 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4321 }
4322 if (cfg.si7_present) {
4323 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4324 }
4325 if (cfg.si8_present) {
4326 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4327 }
4328 }
4329
4330 if (cfg.si2quater_present) {
4331 /* iii) System information type 2 quater is sent if needed, as determined by the system
4332 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4333 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4334 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4335 * within any of 4 consecutive occurrences of TC = 5. */
4336 if (not (cfg.bcch_extended)) {
4337 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4338 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4339 } else {
4340 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4341 }
4342 } else {
4343 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4344 }
4345 }
4346 if (cfg.si9_present) {
4347 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4348 * in system information type 3 as defined in 3GPP TS 44.018. */
4349 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4350 }
4351 if (cfg.si13_present) {
4352 /* vii) System Information type 13 is only related to the GPRS service. System Information
4353 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4354 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4355 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4356 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4357 * within any of 4 consecutive occurrences of TC=4. */
4358 if (not cfg.bcch_extended) {
4359 log("not-bccch-extended");
4360 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4361 } else {
4362 log("bccch-extended");
4363 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4364 }
4365 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004367 }
4368 }
4369 if (cfg.si16_present or cfg.si17_present) {
4370 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4371 * should not be sent in a cell where network sharing is used (see rule xv). */
4372 if (cfg.si22_present) {
4373 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4374 }
4375 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004377 }
4378 if (not cfg.bcch_extended) {
4379 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4380 }
4381 if (cfg.si16_present) {
4382 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4383 }
4384 if (cfg.si17_present) {
4385 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4386 }
4387 }
4388
4389 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4390 * broadcast information. The frequency with which they are sent is determined by the
4391 * system operator. System Information type 9 identifies the scheduling of System
4392 * Information type 18 and 20 messages. */
4393
4394 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4395 * Information Type 19 is present, then its scheduling shall be indicated in System
4396 * Information Type 9. */
4397
4398 if (cfg.si15_present) {
4399 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4400 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4401 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4402 * 4 consecutive occurrences of TC = 1. */
4403 if (not cfg.bcch_extended) {
4404 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4405 } else {
4406 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4407 }
4408 }
4409 if (cfg.si13alt_present) {
4410 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4411 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4412 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4413 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4414 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4415 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4416 * of TC = 4. */
4417 if (cfg.si13_present) {
4418 testcase.stop("Error: Cannot have SI13alt and SI13");
4419 }
4420 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004422 }
4423 if (not cfg.bcch_extended) {
4424 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4425 } else {
4426 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4427 }
4428 }
4429 if (cfg.si2n_present) {
4430 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4431 * as determined by the system operator. In the case that the message is sent on the
4432 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4433 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4434 * consecutive occurrences of TC = 4. */
4435 if (not cfg.bcch_extended) {
4436 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4437 } else {
4438 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4439 }
4440 }
4441 if (cfg.si21_present) {
4442 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4443 * determined by the system operator. If Extended Access Barring is in use in the cell
4444 * then this message is sent at least once within any of 4 consecutive occurrences of
4445 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4446 * cell then this message shall only be sent on BCCH Ext. */
4447 if (not cfg.bcch_extended) {
4448 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4449 } else {
4450 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4451 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004453 }
4454 }
4455 }
4456 if (cfg.si22_present) {
4457 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4458 * should not be sent in a cell where SoLSA is used (see rule viii). System
4459 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4460 * =2 and TC=6. */
4461 if (cfg.si16_present or cfg.si17_present) {
4462 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4463 }
4464 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4465 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004467 }
4468 if (not cfg.bcch_extended) {
4469 testcase.stop("Error: SI22 requires BCCH Extd!");
4470 } else {
4471 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4472 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4473 }
4474 }
4475}
4476
4477/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004478private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4479return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004480 timer T := duration;
4481 var SystemInformationVectorPerTc si_per_tc;
4482 var L1ctlDlMessage l1_dl;
4483
4484 /* initialize all per-TC vectors empty */
4485 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4486 si_per_tc[i] := {};
4487 }
4488
4489 /* flush all previous L1 queued msgs */
4490 pt.clear;
4491
4492 T.start;
4493 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004494 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004495 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4496 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4497 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004498 repeat;
4499 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004500
Harald Welte48494ca2018-02-25 16:59:50 +01004501 var integer tc := f_gsm_compute_tc(sig.frame_number);
4502 log("SI received at TC=", tc, ": ", sig.si);
4503 /* append to the per-TC bucket */
4504 si_per_tc[tc] := si_per_tc[tc] & { sig };
4505 repeat;
4506 }
4507 [] pt.receive { repeat; }
4508 [] T.timeout { }
4509 }
4510
4511 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4512 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4513 }
4514 log("si_per_tc=", si_per_tc);
4515 return si_per_tc;
4516}
4517
4518/* helper function: Set given SI via RSL + validate scheduling.
4519 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004520private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004521 var SystemInformationVectorPerTc si_per_tc;
4522 f_init_l1ctl();
4523 f_l1_tune(L1CTL);
4524
4525 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004526 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004527 f_validate_si_scheduling(si_cfg, si_per_tc);
4528
4529 setverdict(pass);
4530}
4531
4532testcase TC_si_sched_default() runs on test_CT {
4533 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004534 /* 2+3+4 are mandatory and set in f_init() */
4535 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004537}
4538
4539testcase TC_si_sched_1() runs on test_CT {
4540 f_init();
4541 si_cfg.si1_present := true;
4542 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004543 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004545}
4546
4547testcase TC_si_sched_2bis() runs on test_CT {
4548 f_init();
4549 si_cfg.si2bis_present := true;
4550 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4551 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004553}
4554
4555testcase TC_si_sched_2ter() runs on test_CT {
4556 f_init();
4557 si_cfg.si2ter_present := true;
4558 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4559 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004561}
4562
4563testcase TC_si_sched_2ter_2bis() runs on test_CT {
4564 f_init();
4565 si_cfg.si2bis_present := true;
4566 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4567 si_cfg.si2ter_present := true;
4568 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4569 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004571}
4572
4573testcase TC_si_sched_2quater() runs on test_CT {
4574 f_init();
4575 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004576 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004577 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004579}
4580
4581testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004582 /* NOTE: PCUIF connection is not used in this test case, but
4583 * without it the IUT would not broadcast SI13 (see OS#3075). */
4584 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004585 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004586 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004587 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004588 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004589}
4590
4591testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004592 /* NOTE: PCUIF connection is not used in this test case, but
4593 * without it the IUT would not broadcast SI13 (see OS#3075). */
4594 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004595 si_cfg.si2bis_present := true;
4596 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4597 si_cfg.si2ter_present := true;
4598 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4599 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004600 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004601 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004602 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004603 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004605}
4606
4607
Harald Welte68e495b2018-02-25 00:05:57 +01004608testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004609 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004610 /* FIXME: enable / disable individual BCCH info */
4611 //ts_RSL_BCCH_INFO(si_type, info);
4612 /* expect no ERROR REPORT after either of them *
4613 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004615}
4616
Harald Welte93640c62018-02-25 16:59:33 +01004617/***********************************************************************
4618 * Low-Level Protocol Errors / ERROR REPORT
4619 ***********************************************************************/
4620
Harald Welte01d982c2018-02-25 01:31:40 +01004621private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4622 timer T := 5.0;
4623 T.start;
4624 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004625 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004626 setverdict(pass);
4627 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004628 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004630 }
4631 [] RSL_CCHAN.receive {
4632 repeat;
4633 }
4634 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004636 }
4637 }
4638}
4639
4640/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4641testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004642 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004643 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4644 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004645 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004646
4647 f_exp_err_rep(RSL_ERR_PROTO);
4648}
4649
4650/* Provoke a mandatory IE error and match on ERROR REPORT */
4651testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004652 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004653
4654 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4655 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004656 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004657
4658 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4659}
4660
4661/* Provoke an IE content error and match on ERROR REPORT */
4662testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004663 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004664 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4665 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004666 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004667
4668 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4669}
4670
Harald Welteee25aae2019-05-19 14:32:37 +02004671/* attempt to activate channel with wrong RSL Message Discriminator IE */
4672function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4673 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4674 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4675 RSL.send(rsl);
4676 f_rslem_unregister(0, g_chan_nr);
4677}
4678testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4679 var ConnHdlr vc_conn;
4680 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4681
Harald Welte10474062019-05-30 16:48:17 +02004682 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004683
4684 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4685 vc_conn.done;
4686 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4687
4688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4689}
4690
4691/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004692private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004693 var template (value) RSL_Message rsl_tx;
4694 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4695 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4696 RSL.send(rsl_tx);
4697 f_rslem_unregister(0, g_chan_nr);
4698}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004699private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004700 var template (value) RSL_Message rsl_tx;
4701 /* we first have to activate the dedicated channel */
4702 f_rsl_chan_act(g_pars.chan_mode);
4703 /* ... to then send an invalid RLL message */
4704 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4705 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4706 RSL.send(rsl_tx);
4707 f_rslem_unregister(0, g_chan_nr);
4708}
4709testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4710 var ConnHdlr vc_conn;
4711 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4712 var template (value) RSL_Message rsl_tx;
4713
Harald Welte10474062019-05-30 16:48:17 +02004714 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004715
4716 /* Common Channel with wrong message type */
4717 RSL_CCHAN.clear;
4718 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4719 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
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 /* TRX Management */
4724 RSL_CCHAN.clear;
4725 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4726 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004727 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004728 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4729
4730 /* Dedicated Channel */
4731 RSL_CCHAN.clear;
4732 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4733 vc_conn.done;
4734 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4735
4736 /* RLL */
4737 RSL_CCHAN.clear;
4738 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4739 vc_conn.done;
4740 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4741}
4742
4743/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004744private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004745 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4746 f_rslem_unregister(0, g_chan_nr);
4747}
4748testcase TC_err_rep_wrong_sequence() runs on test_CT {
4749 var ConnHdlr vc_conn;
4750 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4751
Harald Welte10474062019-05-30 16:48:17 +02004752 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004753
4754 RSL_CCHAN.clear;
4755 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4756 vc_conn.done;
4757 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4758}
4759
Harald Welte93640c62018-02-25 16:59:33 +01004760/***********************************************************************
4761 * IPA CRCX/MDCX/DLCS media stream handling
4762 ***********************************************************************/
4763
Harald Weltea871a382018-02-25 02:03:14 +01004764/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004765private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004766 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4767 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004768}
4769testcase TC_ipa_dlcx_not_active() runs on test_CT {
4770 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004771 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004772 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4773 vc_conn.done;
4774}
Harald Welte68e495b2018-02-25 00:05:57 +01004775
Harald Weltea3f1df92018-02-25 12:49:55 +01004776/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004777private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004778 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4779 "IPA CRCX ACK");
4780 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4781 "IPA CRCX NACK");
4782}
4783testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4784 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004785 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004786 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4787 vc_conn.done;
4788}
4789
4790/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004791private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004792 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4793 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004794 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004795 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4796 var uint7_t rtp_pt2 := f_rnd_int(127);
4797 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4798 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4799 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4800 "IPA MDCX ACK");
4801 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4802 "IPA DLCX ACK");
4803}
4804testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4805 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004806 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004807 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4808 vc_conn.done;
4809}
4810
Harald Welte3ae11da2018-02-25 13:36:06 +01004811/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004812private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004813 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4814 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004815 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004816 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4817 var uint7_t rtp_pt2 := f_rnd_int(127);
4818 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4819 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4820 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4821 "IPA MDCX ACK");
4822 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004823 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004824 remote_port := f_rnd_int(c_UINT16_MAX);
4825 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4826 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4827 "IPA MDCX ACK");
4828 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4829 "IPA DLCX ACK");
4830}
4831testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4832 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004833 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004834 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4835 vc_conn.done;
4836}
4837
Harald Welte9912eb52018-02-25 13:30:15 +01004838/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004839private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004840 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4841 "IPA CRCX NACK");
4842}
4843testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4844 var ConnHdlrPars pars;
4845 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004846 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004847
4848 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4849 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4850 vc_conn.done;
4851
4852 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4853 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4854 vc_conn.done;
4855}
4856
Harald Weltea3f1df92018-02-25 12:49:55 +01004857
Harald Welte883340c2018-02-28 18:59:29 +01004858/***********************************************************************
4859 * PCU Socket related tests
4860 ***********************************************************************/
4861
Harald Welte07bd2d22019-05-25 11:03:30 +02004862/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004863friend 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 +01004864runs on test_CT {
4865 timer T := 3.0;
4866
4867 /* we don't expect any RTS.req before PDCH are active */
4868 T.start;
4869 alt {
4870 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004872 }
4873 [] PCU.receive { repeat; }
4874 [] T.timeout { }
4875 }
4876
4877 /* Send PDCH activate request for known PDCH timeslot */
4878 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4879
4880 /* we now expect RTS.req for this timeslot (only) */
4881 T.start;
4882 alt {
4883 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4884 setverdict(pass);
4885 }
4886 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4887 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004889 }
4890 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004892 }
4893 [] PCU.receive { repeat; }
4894 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004896 }
4897 [not exp_success] T.timeout {
4898 setverdict(pass);
4899 }
4900 }
4901}
4902
Harald Welte07bd2d22019-05-25 11:03:30 +02004903/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004904friend 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 +01004905runs on test_CT {
4906 timer T := 3.0;
4907
4908 /* Send PDCH activate request for known PDCH timeslot */
4909 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 +02004910 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4911 * when it will actually have been executed in the BTS */
4912 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004913 PCU.clear;
4914 /* we now expect no RTS.req for this timeslot */
4915 T.start;
4916 alt {
4917 [] 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 +02004918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004919 }
4920 [] PCU.receive { repeat; }
4921 [] T.timeout {
4922 setverdict(pass);
4923 }
4924 }
4925}
4926
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004927friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004928 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004929 map(self:PCU, system:PCU);
4930 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004931 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4932}
4933
Harald Welte883340c2018-02-28 18:59:29 +01004934/* PDCH activation via PCU socket; check for presence of RTS.req */
4935testcase TC_pcu_act_req() 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, 7, true);
4939}
4940
4941/* PDCH activation via PCU socket on non-PDCU timeslot */
4942testcase TC_pcu_act_req_wrong_ts() 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(0, 0, 1, false);
4946}
4947
4948/* PDCH activation via PCU socket on wrong BTS */
4949testcase TC_pcu_act_req_wrong_bts() 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(23, 0, 7, false);
4953}
4954
4955/* PDCH activation via PCU socket on wrong TRX */
4956testcase TC_pcu_act_req_wrong_trx() 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 f_TC_pcu_act_req(0, 23, 7, false);
4960}
4961
4962/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4963testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004964 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004965
Harald Welte883340c2018-02-28 18:59:29 +01004966 /* Activate PDCH */
4967 f_TC_pcu_act_req(0, 0, 7, true);
4968 f_sleep(1.0);
4969 /* and De-Activate again */
4970 f_TC_pcu_deact_req(0, 0, 7);
4971}
4972
4973/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4974testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004975 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004976
Harald Welte883340c2018-02-28 18:59:29 +01004977 f_TC_pcu_deact_req(0, 0, 1);
4978}
4979
4980/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004981function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004982 var PCUIF_send_data sd;
4983 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004984 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004985
4986 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004987 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004988
Harald Welte883340c2018-02-28 18:59:29 +01004989 T.start;
4990 alt {
4991 [] 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 +01004992 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004993 setverdict(pass);
4994 } else {
4995 repeat;
4996 }
4997 }
4998 [] PCU.receive { repeat; }
4999 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01005000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01005001 }
5002 }
5003}
5004
Philipp Maier94c08482021-02-01 17:36:05 +01005005/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
5006testcase TC_pcu_ver_si1() runs on test_CT {
5007 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5008 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5009}
5010
5011/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5012testcase TC_pcu_ver_si3() runs on test_CT {
5013 const octetstring si3 := '49012223242526272929AABBCC'O;
5014 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5015}
5016
5017/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5018testcase TC_pcu_ver_si13() runs on test_CT {
5019 const octetstring si13 := '01010203040506070909'O;
5020 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5021}
5022
Harald Welte883340c2018-02-28 18:59:29 +01005023private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5024
5025/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005026friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005027 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5028runs on test_CT
5029{
5030 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5031 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5032}
5033
5034/* 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 +02005035friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5036 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005037runs on test_CT
5038{
5039 var PCUIF_send_data sd;
5040
5041 timer T := 3.0;
5042 T.start;
5043 alt {
5044 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5045 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5046 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5047 sd.data.u.rts_req.fn, sapi, data);
5048 }
5049 [] PCU.receive { repeat; }
5050 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005052 }
5053 }
5054}
5055
5056/* Send DATA.req on invalid BTS */
5057testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005058 var TfiUsfArr tua := f_TfiUsfArrInit();
5059 var octetstring data := '0000'O & f_rnd_octstring(21);
5060
5061 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005062
Harald Welte883340c2018-02-28 18:59:29 +01005063 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005064 f_TfiUsfArrSet(tua, 7, 0);
5065 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5066 f_sleep(1.0);
5067
5068 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005069}
5070
5071/* Send DATA.req on invalid TRX */
5072testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005073 var TfiUsfArr tua := f_TfiUsfArrInit();
5074 var octetstring data := '0000'O & f_rnd_octstring(21);
5075
5076 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005077
Harald Welte883340c2018-02-28 18:59:29 +01005078 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005079 f_TfiUsfArrSet(tua, 7, 0);
5080 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5081 f_sleep(1.0);
5082
5083 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005084}
5085
5086/* Send DATA.req on invalid timeslot */
5087testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005088 var TfiUsfArr tua := f_TfiUsfArrInit();
5089 var octetstring data := '0000'O & f_rnd_octstring(21);
5090
5091 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005092
Harald Welte883340c2018-02-28 18:59:29 +01005093 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005094 f_TfiUsfArrSet(tua, 7, 0);
5095 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5096 f_sleep(1.0);
5097
5098 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005099}
5100
5101/* Send DATA.req on timeslot that hasn't been activated */
5102testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005103 var TfiUsfArr tua := f_TfiUsfArrInit();
5104 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005105
Harald Welte7162a612019-05-26 12:56:09 +02005106 f_virtphy_common();
5107
5108 f_TfiUsfArrSet(tua, 7, 0);
5109 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5110 f_sleep(1.0);
5111
5112 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005113}
5114
Harald Weltead033dc2019-05-25 17:28:16 +02005115private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005116 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5117 boolean wait_rts := true)
5118runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005119 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005120 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005121
5122 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005123 if (wait_rts) {
5124 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5125 } else {
5126 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5127 }
Harald Weltead033dc2019-05-25 17:28:16 +02005128
5129 T.start;
5130 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005131 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005132 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5133 setverdict(pass);
5134 }
Harald Welte7162a612019-05-26 12:56:09 +02005135 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5136 setverdict(fail, "Received unexpected ", rx_dl);
5137 }
Harald Weltead033dc2019-05-25 17:28:16 +02005138 [] L1CTL.receive {
5139 repeat;
5140 }
Harald Welte7162a612019-05-26 12:56:09 +02005141 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005142 setverdict(fail, "Timeout waiting for ", data);
5143 }
Harald Welte7162a612019-05-26 12:56:09 +02005144 [not expect_data] T.timeout {
5145 setverdict(pass);
5146 }
Harald Weltead033dc2019-05-25 17:28:16 +02005147 }
5148}
5149
5150private function f_disable_dynamic_ts() runs on test_CT
5151{
5152 f_init_vty_bsc();
5153 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5154 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5155 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5156 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005157 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005158}
5159
5160private function f_virtphy_common() runs on test_CT {
5161 f_disable_dynamic_ts();
5162 f_init_l1ctl();
5163 f_l1_tune(L1CTL);
5164}
5165
5166testcase TC_pcu_data_req_pdtch() runs on test_CT {
5167 var TfiUsfArr tua := f_TfiUsfArrInit();
5168 var octetstring data := '0000'O & f_rnd_octstring(21);
5169
5170 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005171
Harald Welte883340c2018-02-28 18:59:29 +01005172 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005173 f_TfiUsfArrSet(tua, 7, 0);
5174 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5175 f_sleep(1.0);
5176
5177 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005178}
5179
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005180/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005181testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005182 var TfiUsfArr tua := f_TfiUsfArrInit();
5183 var octetstring data := '0000'O & f_rnd_octstring(21);
5184
5185 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005186
Harald Welte883340c2018-02-28 18:59:29 +01005187 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005188 f_TfiUsfArrSet(tua, 7, 0);
5189 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5190 f_sleep(1.0);
5191
5192 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005193}
5194
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005195private function f_TC_pcu_ptcch_ul(uint16_t ra)
5196runs on test_CT {
5197 var template PCUIF_Message pcu_rach_ind;
5198 var PCUIF_send_data sd;
5199 var GsmFrameNumber fn;
5200 timer T;
5201
5202 /* Send an Access Burst on PTCCH/U over the Um-interface */
5203 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5204 chan_nr := ts_RslChanNr_PDCH(7),
5205 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5206
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005207 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5208 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005209
5210 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5211 T.start(52.0 * 4.615 / 1000.0);
5212 alt {
5213 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5214 log("Rx an Access Burst on the PCU interface: ", sd.data);
5215 setverdict(pass);
5216 T.stop;
5217 }
5218 [] PCU.receive { repeat; }
5219 [] T.timeout {
5220 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5221 /* Keep going, that's not the end of the world */
5222 }
5223 }
5224}
5225
5226testcase TC_pcu_ptcch() runs on test_CT {
5227 var L1ctlDlMessage dl;
5228 var octetstring data;
5229 timer T;
5230
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005231 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005232 f_init_l1ctl();
5233 f_l1_tune(L1CTL);
5234
5235 /* Activate PDCH channel on TS7 */
5236 f_TC_pcu_act_req(0, 0, 7, true);
5237
5238 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005239 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005240 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005241 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005242 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005243
5244 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5245 for (var integer i := 0; i < 16; i := i + 1) {
5246 log("Sending an Access Burst towards the L1CTL interface");
5247 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5248 }
5249
5250 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5251 data := f_rnd_octstring(23);
5252
5253 /* Verify PTCCH/D: send a random data block, make sure it's received */
5254 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5255 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5256
5257 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5258 * let's give it more time in case if we miss the beginning. */
5259 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5260 alt {
5261 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5262 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5263 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5264 frame := data)) -> value dl {
5265 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5266 setverdict(pass);
5267 T.stop;
5268 }
5269 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5270 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5271 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5272 l2_data := data)) -> value dl {
5273 log("Rx PTCCH/D data block on L1CTL: ", dl);
5274 setverdict(pass);
5275 T.stop;
5276 }
5277 [] L1CTL.receive { repeat; }
5278 [] T.timeout {
5279 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5280 }
5281 }
5282}
5283
Harald Welte883340c2018-02-28 18:59:29 +01005284/* Send AGCH from PCU; check it appears on Um side */
5285testcase TC_pcu_data_req_agch() runs on test_CT {
5286 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005287 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005288 f_init_l1ctl();
5289 f_l1_tune(L1CTL);
5290
5291 f_TC_pcu_act_req(0, 0, 7, true);
5292 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5293
5294 T.start;
5295 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005296 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005297 setverdict(pass);
5298 }
5299 [] L1CTL.receive { repeat; }
5300 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005302 }
5303 }
5304}
5305
Harald Welte928622b2019-05-26 13:22:59 +02005306/* Send AGCH from PCU; check it appears on Um side */
5307testcase TC_pcu_data_req_pch() runs on test_CT {
5308 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005309 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005310 f_init_l1ctl();
5311 f_l1_tune(L1CTL);
5312
5313 f_TC_pcu_act_req(0, 0, 7, true);
5314 /* three characters prefix: last 3 digits of IMSI as ASCII */
5315 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5316
5317 T.start;
5318 alt {
5319 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5320 setverdict(pass);
5321 }
5322 [] L1CTL.receive { repeat; }
5323 [] T.timeout {
5324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5325 }
5326 }
5327}
5328
Harald Welte883340c2018-02-28 18:59:29 +01005329/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5330testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5331 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005332 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005333 f_init_l1ctl();
5334 f_l1_tune(L1CTL);
5335
5336 /* append 3 last imsi digits so BTS can compute pagng group */
5337 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5338
5339 timer T := 0.5;
5340 T.start;
5341 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005342 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005343 /* TODO: verify paging group */
5344 setverdict(pass);
5345 }
5346 [] L1CTL.receive { repeat; }
5347 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005349 }
5350 }
5351}
5352
5353/* Send RACH from Um side, expect it to show up on PCU socket */
5354testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005355 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005356 f_init_l1ctl();
5357 f_l1_tune(L1CTL);
5358
5359 var GsmFrameNumber fn_last := 0;
5360 for (var integer i := 0; i < 1000; i := i+1) {
5361 var OCT1 ra := f_rnd_ra_ps();
5362 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5363 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005365 }
5366 fn_last := fn;
5367
5368 timer T := 2.0;
5369 T.start;
5370 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005371 [] 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 +01005372 T.stop;
5373 }
5374 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005376 }
5377 [] PCU.receive { repeat; }
5378 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005380 }
5381 }
5382 }
5383 setverdict(pass);
5384}
5385
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005386/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5387 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5388testcase TC_pcu_ext_rach_content() runs on test_CT {
5389 var template PCUIF_Message pcu_rach_ind;
5390 var GsmFrameNumber fn_last := 0;
5391 var L1ctlRachSynchSeq synch_seq;
5392 var PCUIF_BurstType pcu_bt;
5393 var GsmFrameNumber fn;
5394 var BIT11 ra11;
5395
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005396 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005397 f_init_l1ctl();
5398 f_l1_tune(L1CTL);
5399
5400 for (var integer i := 0; i < 1000; i := i+1) {
5401 /* We need to test both TS1 & TS2 */
5402 if (i rem 2 == 0) {
5403 synch_seq := RACH_SYNCH_SEQ_TS1;
5404 pcu_bt := BURST_TYPE_1;
5405 } else {
5406 synch_seq := RACH_SYNCH_SEQ_TS2;
5407 pcu_bt := BURST_TYPE_2;
5408 }
5409
5410 ra11 := f_rnd_ra11_ps();
5411 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5412 if (fn == fn_last) {
5413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5414 "Two RACH in same FN?!?");
5415 }
5416 fn_last := fn;
5417
5418 /* Compose the expected message */
5419 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005420 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005421 ra := bit2int(ra11),
5422 is_11bit := 1,
5423 burst_type := pcu_bt,
5424 fn := fn);
5425
5426 timer T := 2.0;
5427 T.start;
5428 alt {
5429 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5430 T.stop;
5431 }
5432 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5434 }
5435 [] PCU.receive { repeat; }
5436 [] T.timeout {
5437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5438 }
5439 }
5440 }
5441 setverdict(pass);
5442}
5443
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005444private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5445runs on test_CT {
5446 var template PCUIF_send_data sdt;
5447 var PCUIF_send_data sd;
5448 var int16_t lqual_cb;
5449 timer T := 1.0;
5450
5451 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5452 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5453
5454 /* Send a random PDTCH frame over Um */
5455 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5456 '0000'O & f_rnd_octstring(21)));
5457
5458 T.start;
5459 alt {
5460 /* If expected link quality is above the threshold */
5461 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5462 lqual_cb := sd.data.u.data_ind.lqual_cb;
5463 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5464
5465 /* Make sure the actual link quality matches the expected value */
5466 if (not match(lqual_cb, lqual_cb_exp)) {
5467 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5468 "expected value ", lqual_cb_exp));
5469 } else {
5470 setverdict(pass);
5471 }
5472 }
5473 /* If expected link quality is below the threshold */
5474 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5476 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5477 }
5478 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5479 [] PCU.receive { repeat; }
5480 [lqual_cb_exp < thresh] T.timeout {
5481 log("Rx nothing, as expected");
5482 setverdict(pass);
5483 }
5484 [lqual_cb_exp >= thresh] T.timeout {
5485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5486 "Timeout waiting for PCUIF_DATA.ind");
5487 }
5488 }
5489}
5490
5491/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5492testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005493 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005494 PCU.clear;
5495
5496 f_init_l1ctl();
5497 f_l1_tune(L1CTL);
5498
5499 /* Activate a PDCH channel on TS7 */
5500 f_TC_pcu_act_req(0, 0, 7, true);
5501
5502 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005503 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005504 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005505 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005506 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005507
5508 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5509 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5510 var TrxcMessage ret;
5511
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005512 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005513
5514 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5515 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5516 }
5517}
5518
Harald Welte883340c2018-02-28 18:59:29 +01005519/* Send PAGING via RSL, expect it to shw up on PCU socket */
5520testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005521 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005522
5523 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005524 var MobileIdentityLV mi_lv;
5525 var octetstring mi_lv_enc;
5526 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005527 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005528
Harald Welte883340c2018-02-28 18:59:29 +01005529 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005530 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005531 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005532 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005533 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005534
5535 /* Fancy encoding for PCUIF */
5536 mi_lv := valueof(ts_MI_LV(mi));
5537 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5538 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005539
5540 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005541 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005542 T.start;
5543 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005544 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005545 }
5546 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005548 }
5549 [] PCU.receive { repeat; }
5550 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005552 }
5553 }
5554 }
5555 setverdict(pass);
5556}
5557
Harald Welted66c9b82019-05-25 09:03:15 +02005558/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5559testcase TC_pcu_time_ind() runs on test_CT {
5560 var PCUIF_send_data pcu_sd;
5561 var integer num_time_ind := 0;
5562 var integer first_fn, last_fn;
5563 var float test_duration := 5.0;
5564 timer T;
5565
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005566 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005567 f_TC_pcu_act_req(0, 0, 7, true);
5568
5569 PCU.clear;
5570 T.start(test_duration);
5571 alt {
5572 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5573 num_time_ind := num_time_ind + 1;
5574 if (not isbound(first_fn)) {
5575 first_fn := pcu_sd.data.u.time_ind.fn;
5576 }
5577 last_fn := pcu_sd.data.u.time_ind.fn;
5578 repeat;
5579 }
5580 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5581 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5582 repeat;
5583 }
5584 [] PCU.receive {
5585 repeat;
5586 }
5587 [] T.timeout {}
5588 }
5589 var integer fn_expired := last_fn - first_fn;
5590 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5591
5592 /* verify the number of frames expired matches our expectation */
5593 const float c_GSM_FN_DURATION_MS := 4.61538;
5594 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005595 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005596 if (not match(fn_expired, t_fn_expected)) {
5597 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5598 }
5599
5600 /* There are three TIME.ind in every fn MOD 13 */
5601 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5602 /* Add some tolerance */
5603 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5604 if (not match(num_time_ind, t_time_ind_exp)) {
5605 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5606 }
5607
5608 setverdict(pass);
5609}
5610
Harald Welte4832c862019-05-25 14:57:18 +02005611/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5612testcase TC_pcu_rts_req() runs on test_CT {
5613 var PCUIF_send_data pcu_sd;
5614 var integer first_fn, last_fn;
5615 var integer num_rts_pdtch := 0;
5616 var integer num_rts_ptcch := 0;
5617 var float test_duration := 5.0;
5618 timer T;
5619
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005620 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005621 f_TC_pcu_act_req(0, 0, 7, true);
5622
5623 PCU.clear;
5624 T.start(test_duration);
5625 alt {
5626 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5627 -> value pcu_sd {
5628 num_rts_pdtch := num_rts_pdtch + 1;
5629 if (not isbound(first_fn)) {
5630 first_fn := pcu_sd.data.u.rts_req.fn;
5631 }
5632 last_fn := pcu_sd.data.u.rts_req.fn;
5633 repeat;
5634 }
5635 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5636 -> value pcu_sd {
5637 num_rts_ptcch := num_rts_ptcch + 1;
5638 if (not isbound(first_fn)) {
5639 first_fn := pcu_sd.data.u.rts_req.fn;
5640 }
5641 last_fn := pcu_sd.data.u.rts_req.fn;
5642 repeat;
5643 }
5644 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5645 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5646 repeat;
5647 }
5648 [] PCU.receive {
5649 repeat;
5650 }
5651 [] T.timeout {}
5652 }
5653 var integer fn_expired := last_fn - first_fn;
5654 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5655 ", num_rts_ptcch=", num_rts_ptcch);
5656
5657 /* verify the number of frames expired matches our expectation */
5658 const float c_GSM_FN_DURATION_MS := 4.61538;
5659 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005660 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005661 if (not match(fn_expired, t_fn_expected)) {
5662 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5663 }
5664
5665 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5666 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5667 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5668 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5669 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5670 t_ptcch_exp);
5671 }
5672
5673 /* We have 12 PDTCH blocks every 52-multiframe */
5674 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5675 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5676 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5677 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5678 t_pdtch_exp);
5679 }
5680
5681 setverdict(pass);
5682}
5683
Harald Welte07bd2d22019-05-25 11:03:30 +02005684/* test for generating Abis side OML ALERT from the PCU */
5685testcase TC_pcu_oml_alert() runs on test_CT {
5686 var PCUIF_send_data pcu_sd;
5687 var integer num_time_ind := 0;
5688 var integer first_fn, last_fn;
5689 var float test_duration := 5.0;
5690 timer T;
5691
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005692 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005693 f_TC_pcu_act_req(0, 0, 7, true);
5694
5695 /* re-connect CTRL port from BTS to BSC */
5696 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005697 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005698
5699 /* Send that OML Alert */
5700 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5701
5702 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5703 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5704 setverdict(pass);
5705}
5706
Harald Welteeaa9a862019-05-26 23:01:08 +02005707/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5708private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5709 var PCUIF_Message first_info;
5710 var integer pcu_conn_id := -1;
5711 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5712 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5713 var OCT4 tlli := '01020304'O;
5714 var OCT1 cause := '23'O;
5715 timer T := 5.0;
5716
5717 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5718
5719 f_l1_tune(L1CTL);
5720 RSL.clear;
5721
5722 f_est_dchan();
5723 L1CTL.clear;
5724
5725 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5726
5727 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5728 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5729 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5730
5731 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5732 T.start;
5733 alt {
5734 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5735 setverdict(pass);
5736 }
5737 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5738 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5739 }
5740 [] PCU.receive {
5741 repeat;
5742 }
5743 [] T.timeout {
5744 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5745 }
5746 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005747
5748 /* release the channel */
5749 f_rsl_chan_deact();
5750 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5751 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005752}
5753testcase TC_pcu_rr_suspend() runs on test_CT {
5754 var ConnHdlrPars pars;
5755 var ConnHdlr vc_conn;
5756
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005757 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005758
5759 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5760 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5761 vc_conn.done;
5762}
Harald Welte07bd2d22019-05-25 11:03:30 +02005763
Harald Weltea2e0e942019-05-27 18:12:53 +02005764/* Ensure that PCUIF socket can accept only a single connection */
5765testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005766 var boolean connected := false;
5767 var UD_connect_result cr;
5768 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005769 timer T := 5.0;
5770
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005771 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5772 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5773
Harald Weltea2e0e942019-05-27 18:12:53 +02005774 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005775 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005776
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005777 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005778 PCU.send(UD_connect:{mp_pcu_socket, -1});
5779 T.start;
5780 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005781 /* the IUT will first accept() the new connection, and close() it immediately */
5782 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5783 log("BTS has accept()ed connection");
5784 connected := true;
5785 cid := cr.id;
5786 repeat;
5787 }
5788 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5789 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005790 setverdict(pass);
5791 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005792 /* ignore other messages related to the first connection */
5793 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005794 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005795 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005796 }
5797 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005798
Harald Weltea2e0e942019-05-27 18:12:53 +02005799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5800}
5801
Harald Weltec8effb72019-05-27 18:23:04 +02005802/* Ensure that PCUIF socket can disconnect + reconnect */
5803testcase TC_pcu_socket_reconnect() runs on test_CT {
5804 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005805 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005806
5807 f_sleep(1.0);
5808
5809 f_pcuif_close(PCU, g_pcu_conn_id);
5810 g_pcu_conn_id := -1;
5811
5812 f_sleep(1.0);
5813
5814 /* re-connect */
5815 PCU.clear;
5816 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5817 setverdict(pass);
5818
5819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5820}
5821
Harald Weltebe030482019-05-27 22:29:35 +02005822/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005823private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5824runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005825 var L1ctlDlMessage l1_dl;
5826 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005827 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005828 timer T := 5.0;
5829 T.start;
5830 alt {
5831 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005832 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5833 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005834 repeat;
5835 }
5836 }
5837 [] pt.receive {
5838 repeat;
5839 }
5840 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5842 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005843 }
5844 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005845 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005846}
5847
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005848/* Check if GPRS Indicator is present in RR System Information of a given type */
5849private function f_si_has_gprs_indicator(RrMessageType si_type)
5850runs on test_CT return boolean {
5851 var SystemInformation si := f_get_si(L1CTL, si_type);
5852
5853 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005854 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005855 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005856 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005857 }
5858
5859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5860 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005861}
5862
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005863/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5864private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5865runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005866 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005867 f_init_l1ctl();
5868 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005869 f_sleep(2.0);
5870 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005871
5872 if (f_si_has_gprs_indicator(si_type)) {
5873 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005874 } else {
5875 setverdict(pass);
5876 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005877
Harald Weltebe030482019-05-27 22:29:35 +02005878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5879}
5880
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005881testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5882 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5883}
Harald Weltebe030482019-05-27 22:29:35 +02005884
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005885testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5886 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5887}
5888
5889/* Ensure that GPRS capability is advertised after PCU socket connect */
5890private function f_TC_pcu_socket_connect(RrMessageType si_type)
5891runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005892 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005893 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005894 f_init_l1ctl();
5895 f_l1_tune(L1CTL);
5896
5897 f_sleep(2.0);
5898 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005899
5900 if (not f_si_has_gprs_indicator(si_type)) {
5901 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005902 } else {
5903 setverdict(pass);
5904 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005905
Harald Weltebe030482019-05-27 22:29:35 +02005906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5907}
5908
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005909testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5910 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5911}
Harald Weltebe030482019-05-27 22:29:35 +02005912
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005913testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5914 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5915}
5916
5917/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5918private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5919runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005920 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005921 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005922 f_init_l1ctl();
5923 f_l1_tune(L1CTL);
5924
5925 f_pcuif_close(PCU, g_pcu_conn_id);
5926 g_pcu_conn_id := -1;
5927
5928 f_sleep(1.0);
5929
5930 /* re-connect */
5931 PCU.clear;
5932 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5933
5934 f_sleep(2.0);
5935 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005936
5937 if (f_si_has_gprs_indicator(si_type)) {
5938 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005939 } else {
5940 setverdict(pass);
5941 }
5942
5943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5944}
5945
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005946testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5947 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5948}
5949
5950testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5951 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5952}
5953
Oliver Smithf5239c72019-08-28 10:01:25 +02005954/* 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) */
5955testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5956 var SystemInformation si3 := valueof(ts_SI3_default);
5957
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005958 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005959
Harald Welte76220222020-10-11 20:32:44 +02005960 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5961 * information */
5962 timer T := 2.0;
5963 T.start;
5964 alt {
5965 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5966 [] T.timeout {}
5967 }
5968
Oliver Smithf5239c72019-08-28 10:01:25 +02005969 /* Verify cell_id */
5970 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5971 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5972 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005973 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5974 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5975 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005976 }
5977
5978 /* Verify LAC */
5979 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5980 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5981 if (lac_si3 != lac_pcu) {
5982 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5983 }
5984
5985 setverdict(pass);
5986}
Harald Welted66c9b82019-05-25 09:03:15 +02005987
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005988/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5989testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5990 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005991 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005992
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005993 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005994
5995 info_ind := g_pcu_last_info.u.info_ind;
5996
5997 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5998 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005999 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006000 /* Skip inactive timeslots */
6001 continue;
6002 }
6003
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006004 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07006005 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006006 else
6007 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006008
6009 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006010 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006011 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006012 hsn := fhp.maio_hsn.hsn,
6013 maio := fhp.maio_hsn.maio,
6014 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006015 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006016 } else {
6017 tr_ts := tr_PCUIF_InfoTrxTsH0;
6018 }
6019
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006020 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006021 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6022 if (not match(ts, tr_ts)) {
6023 setverdict(fail, "Hopping parameters do not match: ",
6024 "received ", ts, " vs expected ", tr_ts);
6025 } else {
6026 setverdict(pass);
6027 }
6028 }
6029 }
6030}
6031
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006032/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006033testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6034 f_init_vty_bsc();
6035 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6036 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6037
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006038 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006039
6040 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006041 var template PCUIF_RemoteAddr tr_remote_addr := {
6042 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006043 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006044 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006045
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006046 if (not match(remote_addr, tr_remote_addr)) {
6047 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006048 }
6049
6050 setverdict(pass);
6051}
6052
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006053/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006054testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6055 f_init_vty_bsc();
6056 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6057
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006058 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006059
6060 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006061 var template PCUIF_RemoteAddr tr_remote_addr := {
6062 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6063 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6064 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006065
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006066 if (not match(remote_addr, tr_remote_addr)) {
6067 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006068 }
6069
6070 setverdict(pass);
6071}
6072
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006073/* Verify coding of two NSVCs in the INFO.ind message */
6074testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6075 f_init_vty_bsc();
6076
6077 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6078 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6079 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6080 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6081
6082 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6083 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6084 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6085 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6086
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006087 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006088
6089 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6090 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6091 var template PCUIF_RemoteAddr tr_remote_addr := {
6092 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006093 addr := {
6094 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6095 f_inet6_addr("fd00::ca:ff:ee")
6096 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006097 };
6098
6099 if (not match(info_ind.nsvci, { 1234, 5678 }))
6100 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6101 if (not match(remote_addr, tr_remote_addr))
6102 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6103 if (not match(info_ind.local_port, { 1234, 5678 }))
6104 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6105 if (not match(info_ind.remote_port, { 1234, 5678 }))
6106 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6107
6108 setverdict(pass);
6109}
6110
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006111/* Verify periodic interference reports on PDCH */
6112testcase TC_pcu_interf_ind() runs on test_CT {
6113 var template PCUIF_Message tr_interf_ind;
6114 var template PCUIF_interf ts_interf;
6115 var integer interf_ind_num := 0;
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006116 var boolean first := true;
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006117 var PCUIF_send_data sd;
6118 timer T;
6119
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006120 /* Set the averaging/reporting period to 480ms */
6121 f_init_vty_bsc();
6122 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6123 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6124
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006125 f_init_with_pcuif();
6126 f_TC_pcu_act_req(0, 0, 7, true);
6127
6128 /* We need trxcon for NOPE indications */
6129 f_init_l1ctl();
6130 f_l1_tune(L1CTL);
6131
6132 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6133 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6134 tr_interf_ind := tr_PCUIF_INTERF_IND(
6135 bts_nr := 0,
6136 trx_nr := 0,
6137 fn := ?,
6138 interf := ts_interf
6139 );
6140
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006141 T.start(0.480 * 1.5);
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006142 alt {
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006143 /* The first interference report may contain unreliable values, so we ignore it */
6144 [first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) {
6145 /* 4 SACCH periods => 4 reports (plus some guard time) */
6146 T.start(0.480 * 4.0 + 0.480 / 2.0);
6147 first := false;
6148 repeat;
6149 }
6150 /* Subsequent interference reports shall match our expectations */
6151 [not first] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006152 /* Check TDMA frame number period */
6153 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6154 setverdict(fail, "Odd TDMA frame number := ",
6155 sd.data.u.interf_ind.fn);
6156 }
6157 interf_ind_num := interf_ind_num + 1;
6158 if (interf_ind_num < 4)
6159 { repeat; }
6160 }
Vadim Yanitskiy3b868cb2021-11-10 04:10:48 +03006161 [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 +02006162 setverdict(fail, "Received unexpected interference report: ", sd.data);
6163 }
6164 [] PCU.receive { repeat; }
6165 [] T.timeout {
6166 setverdict(fail, "Timeout waiting for interference reports");
6167 }
6168 }
6169
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006170 /* Reset the averaging/reporting period back to default */
6171 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6172
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6174}
6175
Harald Welte3d04ae62018-04-04 20:29:05 +02006176/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006177 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006178 ***********************************************************************/
6179
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006180private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6181 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006182runs on ConnHdlr {
6183 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006184
6185 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006186 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006187 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6188 repeat;
6189 }
6190 }
6191}
6192
6193private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6194runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006195 /* Expect BTS to immediately acknowledge activation as PDCH */
6196 PCU.clear;
6197 f_rsl_chan_act(g_pars.chan_mode);
6198 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006199 timer T_wait := 2.0;
6200 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006201 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006202 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006203 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006204 [] T_wait.timeout {
6205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6206 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6207 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006208 }
6209 /* try to activate this PDCH from the PCU point of view */
6210 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6211 /* FIXME: is there a response? */
6212}
6213
6214private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6215runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006216 /* Send RSL CHAN REL (deactivate) */
6217 PCU.clear;
6218 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6219 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006220 timer T_wait := 2.0;
6221 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006222 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006223 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006224 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006225 [] T_wait.timeout {
6226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6227 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6228 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006229 }
6230 /* Emulate PCU asking BTS to deactivate PDCH */
6231 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6232 alt {
6233 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6234 setverdict(pass);
6235 }
6236 [] RSL.receive { repeat; }
6237 }
6238}
6239
6240/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006241private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006242 var PCUIF_Message first_info;
6243 var integer ts_nr := g_chan_nr.tn;
6244 var integer trx_nr := 0;
6245 var integer bts_nr := 0;
6246 var integer pcu_conn_id := -1;
6247
6248 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6249
6250 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6251 f_sleep(3.0);
6252 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6253 setverdict(pass);
6254}
6255testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6256 var ConnHdlrPars pars;
6257 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006258 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006259
6260 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6261 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6262 vc_conn.done;
6263}
6264
6265/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006266private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006267 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006268 var integer pcu_conn_id := -1;
6269
6270 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6271
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006272 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6273 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6274 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006275 setverdict(pass);
6276}
6277testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6278 var ConnHdlrPars pars;
6279 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006280 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006281
6282 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6283 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6284 vc_conn.done;
6285}
6286
6287/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006288private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006289 var PCUIF_Message first_info;
6290 var integer ts_nr := g_chan_nr.tn;
6291 var integer trx_nr := 0;
6292 var integer bts_nr := 0;
6293 var integer pcu_conn_id := -1;
6294
6295 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6296
6297 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006298 /* Send a second Chan Activ and expect it to be NACKed */
6299 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6300 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006301 setverdict(pass);
6302}
6303testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6304 var ConnHdlrPars pars;
6305 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006306 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006307
6308 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6309 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6310 vc_conn.done;
6311}
6312
6313/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006314private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006315 var PCUIF_Message first_info;
6316 var integer ts_nr := g_chan_nr.tn;
6317 var integer trx_nr := 0;
6318 var integer bts_nr := 0;
6319 var integer pcu_conn_id := -1;
6320 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6321
6322 /* register for the TCH/F channel number */
6323 f_rslem_register(0, chan_nr);
6324
6325 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6326
6327 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6328 "RSL CHAN ACT");
6329 setverdict(pass);
6330}
6331testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6332 var ConnHdlrPars pars;
6333 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006334 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006335
6336 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6337 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6338 vc_conn.done;
6339}
6340
6341/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006342private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006343 var PCUIF_Message first_info;
6344 var integer ts_nr := g_chan_nr.tn;
6345 var integer trx_nr := 0;
6346 var integer bts_nr := 0;
6347 var integer pcu_conn_id := -1;
6348 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6349 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6350
6351 /* register for the TCH/H channel numbers */
6352 f_rslem_register(0, chan_nr[0]);
6353 f_rslem_register(0, chan_nr[1]);
6354
6355 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6356
6357 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6358 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6359 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6360 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6361 setverdict(pass);
6362}
6363testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6364 var ConnHdlrPars pars;
6365 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006366 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006367
6368 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6369 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6370 vc_conn.done;
6371}
6372
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006373/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6374private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6375 var PCUIF_Message first_info;
6376 var integer ts_nr := g_chan_nr.tn;
6377 var integer trx_nr := 0;
6378 var integer bts_nr := 0;
6379 var integer pcu_conn_id := -1;
6380 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6381 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6382 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6383 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6384 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6385 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6386 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6387 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6388
6389 /* register for the TCH/H channel numbers */
6390 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6391 f_rslem_register(0, chan_nr[i]);
6392 }
6393
6394 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6395
6396 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6397 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6398 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6399 }
6400 setverdict(pass);
6401}
6402testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6403 var ConnHdlrPars pars;
6404 var ConnHdlr vc_conn;
6405 f_init();
6406
6407 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6408 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6409 vc_conn.done;
6410}
6411
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006412/* Reproduce a race condition described in OS#5245 */
6413private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6414 f_rsl_chan_act(g_pars.chan_mode);
6415 f_sleep(1.0);
6416 f_rsl_chan_deact();
6417 setverdict(pass);
6418}
6419testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6420 var ConnHdlrPars pars[2];
6421 var ConnHdlr vc_conn[2];
6422 var TrxcMessage rsp;
6423
6424 f_init();
6425
6426 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6427 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6428 ts_TRXC_FAKE_TRXC_DELAY(200));
6429
6430 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6431 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6432 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6433 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6434 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6435 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6436 pars[i], l1ctl := false);
6437 }
6438
6439 /* Wait for all components to finish */
6440 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6441 vc_conn[i].done;
6442 }
6443
6444 /* Disable the artificial delay for TRXC RSP messages */
6445 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6446 ts_TRXC_FAKE_TRXC_DELAY(0));
6447}
6448testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6449 var ConnHdlrPars pars[8];
6450 var ConnHdlr vc_conn[8];
6451 var TrxcMessage rsp;
6452
6453 f_init();
6454
6455 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6456 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6457 ts_TRXC_FAKE_TRXC_DELAY(200));
6458
6459 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6460 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6461 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6462 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6463 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6464 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6465 pars[i], l1ctl := false);
6466 }
6467
6468 /* Wait for all components to finish */
6469 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6470 vc_conn[i].done;
6471 }
6472
6473 /* Disable the artificial delay for TRXC RSP messages */
6474 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6475 ts_TRXC_FAKE_TRXC_DELAY(0));
6476}
6477
Harald Welte9bbbfb52018-04-05 09:33:19 +02006478/***********************************************************************
6479 * IPA Style Dynamic Timeslot Support
6480 ***********************************************************************/
6481
6482private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6483runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006484 /* Expect BTS to immediately acknowledge activation as PDCH */
6485 PCU.clear;
6486 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6487 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006488 timer T_wait := 2.0;
6489 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006490 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006491 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006492 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006493 [] T_wait.timeout {
6494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6495 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6496 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006497 }
6498 /* try to activate this PDCH from the PCU point of view */
6499 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6500 /* FIXME: is there a response? */
6501
6502 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6503}
6504
6505private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6506runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006507 /* Send RSL CHAN REL (deactivate) */
6508 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6509 PCU.clear;
6510 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006511 timer T_wait := 2.0;
6512 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006513 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006514 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006515 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006516 [] T_wait.timeout {
6517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6518 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6519 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006520 }
6521 /* Emulate PCU asking BTS to deactivate PDCH */
6522 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6523 alt {
6524 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6525 setverdict(pass);
6526 }
6527 [] RSL.receive { repeat; }
6528 }
6529}
6530
6531/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006532private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006533 var PCUIF_Message first_info;
6534 var integer ts_nr := g_chan_nr.tn;
6535 var integer trx_nr := 0;
6536 var integer bts_nr := 0;
6537 var integer pcu_conn_id := -1;
6538
6539 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6540
6541 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6542 f_sleep(3.0);
6543 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6544
6545 setverdict(pass);
6546
6547}
6548testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6549 var ConnHdlrPars pars;
6550 var ConnHdlr vc_conn;
6551 f_init();
6552
6553 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6554 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6555 vc_conn.done;
6556}
6557
6558/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006559private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006560 var PCUIF_Message first_info;
6561 var integer ts_nr := g_chan_nr.tn;
6562 var integer trx_nr := 0;
6563 var integer bts_nr := 0;
6564 var integer pcu_conn_id := -1;
6565
6566 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6567
6568 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6569 "RSL CHAN ACT");
6570 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6571 "RF CHAN REL", true);
6572 setverdict(pass);
6573}
6574testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6575 var ConnHdlrPars pars;
6576 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006577 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006578
6579 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6580 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6581 vc_conn.done;
6582}
6583
6584/* 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 +07006585private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006586 var PCUIF_Message first_info;
6587 var integer ts_nr := g_chan_nr.tn;
6588 var integer trx_nr := 0;
6589 var integer bts_nr := 0;
6590 var integer pcu_conn_id := -1;
6591
6592 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6593
6594 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6595 "RSL CHAN ACT");
6596
6597 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6598 alt {
6599 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6600 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006602 }
6603 [] RSL.receive { repeat; }
6604 }
6605
6606 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6607 "RF CHAN REL", true);
6608 setverdict(pass);
6609}
6610testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6611 var ConnHdlrPars pars;
6612 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006613 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006614
6615 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6616 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6617 vc_conn.done;
6618}
6619
6620/* 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 +07006621private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006622 var PCUIF_Message first_info;
6623 var integer ts_nr := g_chan_nr.tn;
6624 var integer trx_nr := 0;
6625 var integer bts_nr := 0;
6626 var integer pcu_conn_id := -1;
6627
6628 /* register for the TCH/F channel number */
6629 f_rslem_register(0, g_chan_nr);
6630
6631 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6632
6633 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6634
6635 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6636 "RSL CHAN ACT");
6637
6638 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6639
6640 setverdict(pass);
6641}
6642testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6643 var ConnHdlrPars pars;
6644 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006645 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006646
6647 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6648 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6649 vc_conn.done;
6650}
6651
6652
Harald Welte0472ab42018-03-12 15:02:26 +01006653/***********************************************************************
6654 * LAPDm / RLL related
6655 ***********************************************************************/
6656
6657private function f_tx_lapdm(template (value) LapdmFrame l,
6658 template (value) RslLinkId link_id) runs on ConnHdlr {
6659 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006660 var template (value) SacchL1Header l1h;
6661
6662 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006663 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006664 /* Compose dummy L1 header */
6665 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6666 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 +02006667 } else {
6668 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006669 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 +01006670 }
Harald Welte0472ab42018-03-12 15:02:26 +01006671}
6672
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006673friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006674 uint3_t sapi,
6675 RslLinkId link_id,
6676 octetstring l3,
6677 boolean exp
6678}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006679friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006680friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6681 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006682 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006683 sapi := sapi,
6684 link_id := id,
6685 l3 := l3,
6686 exp := exp
6687}
6688
6689/* execute the same callback function with a set of different parameters (tcs) on a
6690 * variety of logical channels */
6691private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6692 var ConnHdlrPars pars;
6693 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006694 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006695
6696 /* test on each of the channels we have */
6697 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6698 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6699
6700 /* test each of the test cases on the current channel */
6701 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6702 pars.spec.rll := tcs[j];
6703 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6704 vc_conn := f_start_handler(fn, pars);
6705 vc_conn.done;
6706 }
6707 }
6708
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006710}
6711
6712/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6713private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6714 var RllTestCase tc := g_pars.spec.rll;
6715 timer T := 3.0;
6716
6717 f_l1_tune(L1CTL);
6718 RSL.clear;
6719
6720 /* activate the logical channel */
6721 f_est_dchan();
6722 L1CTL.clear;
6723
6724 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6725 T.start;
6726 alt {
6727 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
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 with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006732 }
6733 }
6734 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6735 if (tc.exp) {
6736 setverdict(pass);
6737 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006739 }
6740 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006741 /* We also expect to receive the measurements */
6742 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006743 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006745 }
6746 [not tc.exp] T.timeout {
6747 setverdict(pass);
6748 }
6749 }
6750
6751 f_rsl_chan_deact();
6752 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6753 f_rslem_unregister(0, g_chan_nr);
6754}
6755testcase TC_rll_est_ind() runs on test_CT {
6756 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006757 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006758 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006759 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006760 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006761 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006762 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6763 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006764 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006765 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006766 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006767 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006768 };
6769 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6770}
6771
6772/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6773private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6774 var RllTestCase tc := g_pars.spec.rll;
6775 var L1ctlDlMessage dl;
6776 timer T := 3.0;
6777
6778 f_l1_tune(L1CTL);
6779 RSL.clear;
6780
6781 /* activate the logical channel */
6782 f_est_dchan();
6783 L1CTL.clear;
6784
6785 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6786 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6787 T.start;
6788 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006789 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006790 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006792 }
6793 }
6794
6795 f_rsl_chan_deact();
6796 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6797 f_rslem_unregister(0, g_chan_nr);
6798}
6799testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6800 var RllTestCases tcs := {
6801 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006802 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006803 };
6804 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6805}
6806testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6807 var RllTestCases tcs := {
6808 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006809 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006810 }
6811 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6812}
6813
6814/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006815friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006816 var L1ctlDlMessage dl;
6817 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6818 var LapdmFrame lapdm;
6819 var octetstring l2 := dl.payload.data_ind.payload;
6820 if (dl.dl_info.link_id.c == SACCH) {
6821 /* remove L1 header */
6822 l2 := substr(l2, 2, lengthof(l2)-2);
6823 }
6824 if (ischosen(exp.ab)) {
6825 lapdm.ab := dec_LapdmFrameAB(l2);
6826 } else if (ischosen(exp.b4)) {
6827 lapdm.b4 := dec_LapdmFrameB4(l2);
6828 } else if (ischosen(exp.bbis)) {
6829 lapdm.bbis := dec_LapdmFrameBbis(l2);
6830 }
6831 log("Rx LAPDm ", lapdm);
6832 if (match(lapdm, exp)) {
6833 setverdict(pass);
6834 } else {
6835 repeat;
6836 }
6837 }
6838 [] L1CTL.receive { repeat; }
6839}
6840private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6841 timer T := t;
6842 T.start;
6843 alt {
6844 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006846 }
6847 [] as_l1_exp_lapdm(exp);
6848 }
6849}
6850
6851/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6852private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6853 /* send SABM from MS -> BTS */
6854 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6855 /* expect RLL EST IND on Abis */
6856 alt {
6857 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6858 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6859 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006861 }
6862 [] RSL.receive { repeat; }
6863 }
6864 /* expect UA from BTS -> MS */
6865 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6866}
6867
6868/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6869private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6870 var RllTestCase tc := g_pars.spec.rll;
6871
6872 f_l1_tune(L1CTL);
6873 RSL.clear;
6874
6875 /* activate the logical channel */
6876 f_est_dchan();
6877 L1CTL.clear;
6878
6879 /* first establish the link-layer */
6880 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6881
6882 /* then send the DISC */
6883 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6884 /* ... and expect the REL IND on the RSL side */
6885 alt {
6886 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6887 setverdict(pass);
6888 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006889 /* We also expect to receive the measurements */
6890 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006891 }
6892
6893 /* release the channel */
6894 f_rsl_chan_deact();
6895 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6896 f_rslem_unregister(0, g_chan_nr);
6897}
6898testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6899 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006900 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006901 };
6902 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6903}
6904
6905testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6906 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006907 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006908 };
6909 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6910}
6911testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6912 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006913 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006914 };
6915 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6916}
6917testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6918 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006919 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006920 };
6921 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6922}
6923
6924/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6925private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6926 var RllTestCase tc := g_pars.spec.rll;
6927 f_l1_tune(L1CTL);
6928 RSL.clear;
6929
6930 /* activate the logical channel */
6931 f_est_dchan();
6932 L1CTL.clear;
6933
6934 /* first establish the link-layer */
6935 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6936
6937 /* then send the REL REQ via RSL */
6938 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6939 /* ... and expect the DISC on the Um side */
6940 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006941 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006942 /* FIXME: send a UA in resposne to the DISC */
6943 }
6944 }
6945
6946 /* release the channel */
6947 f_rsl_chan_deact();
6948 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6949 f_rslem_unregister(0, g_chan_nr);
6950}
6951testcase TC_rll_rel_req() runs on test_CT {
6952 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006953 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6954 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6955 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6956 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006957 };
6958 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6959}
6960
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006961/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006962testcase TC_rll_data_req() runs on test_CT {
6963}
6964
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006965/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006966testcase TC_rll_data_ind() runs on test_CT {
6967}
6968
6969/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6970private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6971 var RllTestCase tc := g_pars.spec.rll;
6972
6973 f_l1_tune(L1CTL);
6974 RSL.clear;
6975
6976 f_est_dchan();
6977 L1CTL.clear;
6978
6979 /* Send UNITDATA REQ on RSL side */
6980 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6981 /* Expect it to arrive on the other side */
6982 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006983 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006984 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006985 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006986 }
6987
6988 /* release the channel */
6989 f_rsl_chan_deact();
6990 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6991 f_rslem_unregister(0, g_chan_nr);
6992}
6993testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6994 var octetstring l3 := f_rnd_octstring(15);
6995 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006996 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6997 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006998 };
6999 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7000}
7001testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
7002 var octetstring l3 := f_rnd_octstring(19);
7003 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007004 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7005 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007006 };
7007 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
7008}
7009
7010/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7011private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7012 var RllTestCase tc := g_pars.spec.rll;
7013
7014 f_l1_tune(L1CTL);
7015 RSL.clear;
7016
7017 f_est_dchan();
7018 L1CTL.clear;
7019
7020 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007021 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007022 /* Expdct RLL UNITDATA IND on RSL side */
7023 alt {
7024 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7025 setverdict(pass);
7026 }
7027 [] RSL.receive { repeat; }
7028 }
7029
7030 /* release the channel */
7031 f_rsl_chan_deact();
7032 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7033 f_rslem_unregister(0, g_chan_nr);
7034}
7035testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007036 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007037 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007038 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7039 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007040 };
7041 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7042}
7043testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7044 var octetstring l3 := f_rnd_octstring(18);
7045 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007046 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7047 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007048 };
7049 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7050}
7051
Harald Weltee613f962018-04-18 22:38:16 +02007052/***********************************************************************
7053 * Encryption Related
7054 ***********************************************************************/
7055
7056/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007057private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007058 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7059 if (link_id.c == SACCH) {
7060 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7061 } else {
7062 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7063 }
7064}
7065
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007066/* Expect (or not expect) other kinds of messages */
7067private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7068 [exp_any] RSL.receive { repeat; }
7069 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007071 }
7072}
7073
Harald Weltee613f962018-04-18 22:38:16 +02007074/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007075private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007076 RslLinkId link_id,
7077 octetstring l3,
7078 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007079 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007080) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007081 timer T := 3.0;
7082 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7083 T.start;
7084 /* Expect RLL UNITDATA IND on RSL side */
7085 alt {
7086 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7087 setverdict(pass);
7088 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007089 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007090 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007091 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007093 }
Harald Weltee613f962018-04-18 22:38:16 +02007094 }
7095}
7096
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007097/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7098private function f_data_mo(
7099 RslLinkId link_id,
7100 boolean p, uint3_t nr, uint3_t ns,
7101 octetstring l3,
7102 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007103 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007104) runs on ConnHdlr {
7105 timer T := 3.0;
7106 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7107 T.start;
7108 /* Expect RLL DATA IND on RSL side */
7109 alt {
7110 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7111 setverdict(pass);
7112 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007113 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007114 [] as_rsl_any_ind(exp_any);
7115 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007117 }
7118 }
7119}
7120
Harald Weltee613f962018-04-18 22:38:16 +02007121/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007122private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007123 f_l1_tune(L1CTL);
7124 f_est_dchan(true);
7125
7126 /* now we actually need to transmit some data both ways to check if the encryption works */
7127 var L1ctlDlMessage dl;
7128
Stefan Sperling603d98e2018-07-25 16:47:28 +02007129 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007130 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7131
7132 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7133 f_unitdata_mt(link_id, l3);
7134
7135 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7136 f_unitdata_mo(link_id, l3);
7137
7138 /* release the channel */
7139 f_rsl_chan_deact();
7140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7141 f_rslem_unregister(0, g_chan_nr);
7142}
7143testcase TC_chan_act_a51() runs on test_CT {
7144 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7145 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7146 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7147}
7148testcase TC_chan_act_a52() runs on test_CT {
7149 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7150 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7151 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7152}
7153testcase TC_chan_act_a53() runs on test_CT {
7154 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7155 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7156 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7157}
Eric Wildb9260392021-05-15 19:48:22 +02007158testcase TC_chan_act_a54() runs on test_CT {
7159 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7160 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7161 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7162}
Harald Weltee613f962018-04-18 22:38:16 +02007163
Eric Wildf1827a72019-05-28 17:37:35 +02007164/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7165 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 +07007166private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007167 f_l1_tune(L1CTL);
7168 f_est_dchan(true);
7169
7170 /* now we actually need to transmit some data both ways to check if the encryption works */
7171 var L1ctlDlMessage dl;
7172
7173 var octetstring l3 := f_rnd_octstring(20);
7174 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7175
7176 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7177 f_unitdata_mt(link_id, l3);
7178
7179 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7180 f_unitdata_mo(link_id, l3);
7181
7182 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007183 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007184
7185 /* modify key to break proper encryption */
7186 g_pars.encr.key := f_rnd_octstring(8);
7187 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7188 rsl.ies := rsl.ies & { ei };
7189 RSL.send(rsl);
7190
7191 timer T0 := 1.0;
7192 T0.start;
7193 /* Expect RSL MODIFY ACK */
7194 alt {
7195 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7196 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7198 }
7199 [] T0.timeout {
7200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7201 }
7202 }
7203
7204 var octetstring l3msg := f_rnd_octstring(15);
7205 timer T1 := 3.0;
7206 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7207 due to broken encryption */
7208 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7209 T1.start;
7210 alt {
7211 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7212 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7213 }
7214 [] T1.timeout {
7215 setverdict(pass);
7216 }
7217 }
7218
7219 /* release the channel */
7220 f_rsl_chan_deact();
7221 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7222 f_rslem_unregister(0, g_chan_nr);
7223}
7224testcase TC_rsl_modify_encr() runs on test_CT {
7225 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7226 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7227 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7228}
Harald Weltee613f962018-04-18 22:38:16 +02007229
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007230/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7231private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7232runs on test_CT {
7233 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7234 var ASP_RSL_Unitdata ud;
7235 timer T;
7236
7237 /* Intave is 6 SACCH periods by default */
7238 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7239
7240 T.start(Tval);
7241 alt {
7242 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7243 setverdict(pass);
7244 }
7245 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7246 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7247 }
7248 [] RSL_CCHAN.receive { repeat; }
7249 [] T.timeout {
7250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7251 "Timeout waiting for RF RESource INDication");
7252 }
7253 }
7254}
7255testcase TC_rsl_rf_resource_ind() runs on test_CT {
7256 var RSL_ResourceInfo info := { };
7257
7258 f_init(trx_nr := 0);
7259
7260 f_init_l1ctl();
7261 f_l1_tune(L1CTL);
7262
7263 /* g_AllChannels contains all logical channels */
7264 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7265 var RslChannelNr chan_nr := g_AllChannels[i];
7266
7267 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7268 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7269 { continue; }
7270
7271 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7272 }
7273
7274 /* Align to the first interference report */
7275 f_TC_rsl_rf_resource_ind(?);
7276
7277 /* Test 4 consecutive messages */
7278 for (var integer i := 0; i < 4; i := i + 1) {
7279 f_TC_rsl_rf_resource_ind(info);
7280 }
7281
7282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7283}
7284
Harald Weltee613f962018-04-18 22:38:16 +02007285/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007286private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007287 /* L3 payload doesn't matter, as it is passed transparently */
7288 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7289 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7290 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7291
7292 f_l1_tune(L1CTL);
7293
7294 /* first establish a dedicated channel in the clear */
7295 f_est_dchan(false);
7296
7297 /* Establish ABM */
7298 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7299
7300 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7301 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7302 /* expect the L3 to arrive still unencrypted on the MS side */
7303 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7304
7305 /* configure L1 to apply ciphering */
7306 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7307 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7308
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007309 /* send first ciphered I-frame in response and expect it on RSL */
7310 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007311
7312 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7313 * and hence enable encryption also on the downlink */
7314
7315 /* expect bi-directional communication work in encrypted mode */
7316 f_unitdata_mo(link_id, f_rnd_octstring(15));
7317 f_unitdata_mt(link_id, f_rnd_octstring(15));
7318
7319 /* release the channel */
7320 f_rsl_chan_deact();
7321 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7322 f_rslem_unregister(0, g_chan_nr);
7323}
7324testcase TC_encr_cmd_a51() runs on test_CT {
7325 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7326 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7327 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7328}
7329testcase TC_encr_cmd_a52() runs on test_CT {
7330 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7331 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7332 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7333}
7334testcase TC_encr_cmd_a53() runs on test_CT {
7335 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7336 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7337 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7338}
Eric Wildb9260392021-05-15 19:48:22 +02007339testcase TC_encr_cmd_a54() runs on test_CT {
7340 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7341 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7342 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7343}
Harald Weltee613f962018-04-18 22:38:16 +02007344
7345private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7346 var LapdmFrame lf;
7347 var octetstring reenc;
7348
7349 /* decode the LAPDm frame */
7350 if (ischosen(exp_match.ab)) {
7351 lf.ab := dec_LapdmFrameAB(enc);
7352 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007354 }
7355
7356 /* check if decoder result matches expectation */
7357 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007359 } else {
7360 log(name, ": matched");
7361 setverdict(pass);
7362 }
7363
7364 /* test if re-encoded frame equals original input */
7365 reenc := enc_LapdmFrame(lf);
7366 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007368 } else {
7369 setverdict(pass);
7370 }
7371}
7372
7373testcase TC_lapdm_selftest() runs on test_CT {
7374 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7375 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7376 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7377 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7378 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7379 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7380 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7381}
7382
Stefan Sperling4880be42018-08-07 18:12:59 +02007383/***********************************************************************
7384 * DTX Related (see GSM 05.08, section 8.3)
7385 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007386private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007387 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007388 var GsmFrameNumber first_fn;
7389 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007390 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007391 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007392 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7393 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007394 const integer frame_dtx_tchf_mod := 104;
7395 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7396 * which operates in terms of blocks rather than frames. */
7397 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7398 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007399 timer T := 5.0;
7400
7401 f_l1_tune(L1CTL);
7402 RSL.clear;
7403 L1CTL.clear;
7404
7405 /* activate TCHF signalling channel */
7406 f_est_dchan(false);
7407
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007408 /* A template for matching dummy LAPDm func=UA frames */
7409 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7410 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7411 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7412
Stefan Sperling4880be42018-08-07 18:12:59 +02007413 T.start;
7414 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007415 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007416 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007417
7418 if (is_first_frame) {
7419 is_first_frame := false;
7420 first_fn := dl.dl_info.frame_nr;
7421 }
7422
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007423 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007424 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007425 T.stop;
7426 f_rsl_chan_deact();
7427 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007428
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007429 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7430 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007431
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007432 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007433 setverdict(fail, "Not enough fill frames received: ",
7434 nfill_frames, " out of ", expected_fill_frames);
7435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007436 } else {
7437 setverdict(pass);
7438 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007439 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007440 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7441 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7442 * we should only see the subset of frames numbers which correspond to a block boundary.
7443 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7444 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7445 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007446 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007447 repeat;
7448 }
7449 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007450 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7451 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7452 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007453 f_rsl_chan_deact();
7454 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007455 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007456 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007457 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007458 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007459 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007460
7461 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007462 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7463 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007464 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7465 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7466 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007467 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7468 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007469 case else {
7470 /* This shall not happen, just to be sure */
7471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7472 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007473 }
7474
7475 f_rsl_chan_deact();
7476 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007477
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007478 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007479 setverdict(pass);
7480 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007481 setverdict(fail, "Not enough fill frames received: ",
7482 nfill_frames, " out of ", expected_fill_frames);
7483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007484 }
7485 } else {
7486 repeat;
7487 }
7488 }
7489 }
7490 [] L1CTL.receive { repeat; }
7491 [] T.timeout {
7492 f_rsl_chan_deact();
7493 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007495 }
7496 }
7497}
7498
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007499private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007500 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007501 var ConnHdlr vc_conn;
7502 var ConnHdlrPars pars;
7503 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007504 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007505 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007506 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007507 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007508 if (dtxd) {
7509 if (i >= 4) { /* DTX is only allowed on TCH/F */
7510 break;
7511 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007512 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007513 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007514 vc_conn.done;
7515 }
7516}
7517
7518/* Verify that L2 fill frames are sent on TCH in signaling mode if
7519 * there is nothing to transmit while DTX is disabled on downlink. */
7520testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7521 f_tch_sign_l2_fill_frame(false);
7522}
7523
7524/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7525 * there is nothing to transmit while DTX is enabled on downlink. */
7526testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7527 f_tch_sign_l2_fill_frame(true);
7528}
Harald Welte0472ab42018-03-12 15:02:26 +01007529
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007530testcase TC_chopped_ipa_ping() runs on test_CT {
7531 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7532}
7533
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007534testcase TC_chopped_ipa_payload() runs on test_CT {
7535 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7536}
7537
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007538
7539/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7540 * Return value: Measurement Report to be sent (encoded octetstring). */
7541type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7542 runs on ConnHdlr return octetstring;
7543
7544private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7545runs on ConnHdlr {
7546 var L1ctlDlMessage l1_dl;
7547 var SacchL1Header l1h;
7548 var octetstring l2;
7549
7550 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7551 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7552 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7553 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7554
7555 /* Pass it to the user specified call-back function */
7556 l2 := cb.apply(l1h, num_blocks);
7557 /* Send a Measurement Report generated by the call-back */
7558 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7559 l1_dl.dl_info.link_id,
7560 l1h, l2));
7561
7562 /* Shall we keep going? */
7563 num_blocks := num_blocks - 1;
7564 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7565 if (num_blocks > 0) { repeat; }
7566 }
7567 [] L1CTL.receive { repeat; }
7568}
7569
7570private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7571runs on ConnHdlr return octetstring {
7572 /* Command the L1 to apply received parameters */
7573 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7574
7575 /* Dummy measurement report (the results are invalid) */
7576 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7577}
7578
7579private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7580runs on ConnHdlr return octetstring {
7581 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7582 setverdict(fail, "Unexpected MS Power level change: ",
7583 g_pars.l1_pars.ms_power_level, " -> ",
7584 l1h.ms_power_lvl);
7585 }
7586
7587 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7588}
7589
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007590private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7591runs on ConnHdlr return octetstring {
7592 /* UL RSSI oscillation driven by SACCH block number */
7593 if (num_blocks rem 2 == 0) {
7594 f_trxc_fake_rssi(-100);
7595 } else {
7596 f_trxc_fake_rssi(-50);
7597 }
7598
7599 /* Make sure that MS power level remains constant */
7600 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7601}
7602
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007603/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7604private function f_TC_ms_pwr_ctrl_constant(charstring id)
7605runs on ConnHdlr {
7606 var integer num_blocks := 8;
7607 timer T := int2float(num_blocks);
7608
7609 f_l1_tune(L1CTL);
7610 RSL.clear;
7611
7612 /* These IEs are needed for autonomous MS power control */
7613 var template (value) RSL_IE_List ies := {
7614 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7615 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7616 }),
7617 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7618 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7619 })
7620 };
7621
7622 /* Ensure that 'rx-current' equals 'rx-target' */
7623 f_trxc_fake_rssi(mp_uplink_power_target);
7624
7625 /* Establish a dedicated channel */
7626 f_est_dchan(more_ies := valueof(ies));
7627
7628 L1CTL.clear;
7629 T.start;
7630 alt {
7631 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7632 [] T.timeout {
7633 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7634 num_blocks, " were not handled");
7635 }
7636 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007637
7638 /* Release the channel */
7639 f_rsl_chan_deact();
7640 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007641}
7642testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7643 var ConnHdlr vc_conn;
7644 var ConnHdlrPars pars;
7645
7646 f_init();
7647
7648 /* Explicitly configure the Uplink power target (in dBm) */
7649 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7650
7651 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7652 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7653 log(testcasename(), ": starting on ", pars.chan_nr);
7654
7655 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7656 pars, trxc_comp := true);
7657 vc_conn.done;
7658 }
7659
7660 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7662}
7663
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007664/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7665private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7666runs on ConnHdlr {
7667 var integer num_blocks := 16;
7668 timer T := int2float(num_blocks);
7669
7670 f_l1_tune(L1CTL);
7671 RSL.clear;
7672
7673 /* These IEs are needed for autonomous MS power control */
7674 var template (value) RSL_IE_List ies := {
7675 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7676 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7677 }),
7678 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7679 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7680 })
7681 };
7682
7683 /* Ensure that 'rx-current' equals 'rx-target' */
7684 f_trxc_fake_rssi(mp_uplink_power_target);
7685
7686 /* Establish a dedicated channel */
7687 f_est_dchan(more_ies := valueof(ies));
7688
7689 L1CTL.clear;
7690 T.start;
7691 alt {
7692 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7693 [] T.timeout {
7694 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7695 num_blocks, " were not handled");
7696 }
7697 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007698
7699 /* Release the channel */
7700 f_rsl_chan_deact();
7701 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007702}
7703testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7704 var ConnHdlr vc_conn;
7705 var ConnHdlrPars pars;
7706
7707 f_init();
7708
7709 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7710 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7711 /* Explicitly configure the Uplink power range (target and delte) */
7712 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7713 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7714
7715 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7716 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7717 log(testcasename(), ": starting on ", pars.chan_nr);
7718
7719 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7720 pars, trxc_comp := true);
7721 vc_conn.done;
7722 }
7723
7724 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7726}
7727
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007728private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7729 var template L1ctlDlMessage tr_bad_frame;
7730 var L1ctlDlMessage l1_dl;
7731 timer T := 8.0;
7732
7733 f_l1_tune(L1CTL);
7734 RSL.clear;
7735
7736 f_est_dchan();
7737
7738 /* There may be a few errors right after the channel activation */
7739 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7740 L1CTL.clear;
7741
7742 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7743 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7744 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7745 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7746 tr_bad_frame.payload := ?;
7747
7748 T.start;
7749 alt {
7750 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7751 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7752 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7753 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7754 }
7755 [] as_l1_sacch();
7756 [] L1CTL.receive { repeat; }
7757 [] T.timeout {
7758 /* We're done, break the loop */
7759 setverdict(pass);
7760 }
7761 }
7762
7763 f_rsl_chan_deact();
7764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7765}
7766testcase TC_speech_no_rtp_tchf() runs on test_CT {
7767 var ConnHdlr vc_conn;
7768 var ConnHdlrPars pars;
7769
7770 f_init();
7771
7772 /* TS1, TCH/F, V1 (FR codec) */
7773 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7774 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7775 vc_conn.done;
7776}
7777testcase TC_speech_no_rtp_tchh() runs on test_CT {
7778 var ConnHdlr vc_conn;
7779 var ConnHdlrPars pars;
7780
7781 f_init();
7782
7783 /* TS5, TCH/H, V1 (HR codec) */
7784 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7785 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7786 vc_conn.done;
7787}
7788
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007789/* Verify handling of Downlink and Uplink speech frames */
7790private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7791 var L1ctlDlMessage l1_dl;
7792 var PDU_RTP rtp_pdu;
7793 var octetstring pl;
7794 timer Td, Tu;
7795
7796 f_l1_tune(L1CTL);
7797 f_est_dchan();
7798
7799 /* Activate the RTP emulation */
7800 pl := f_rnd_octstring(6);
7801 f_rtpem_activate(pl);
7802
7803 /* Give the scheduler some time to fill up the buffers */
7804 f_sleep(2.0);
7805 L1CTL.clear;
7806 RSL.clear;
7807
7808 /* Make sure that Downlink frames are received at the UE */
7809 Td.start(2.0);
7810 alt {
7811 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7812 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7813 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7814 l1_dl.payload.traffic_ind.data));
7815 setverdict(pass);
7816 }
7817 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7818 setverdict(fail, "Rx unexpected Downlink speech frame ",
7819 "(", l1_dl.payload.traffic_ind.data, ") ",
7820 "expected (", pl, ")");
7821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7822 }
7823 [] as_l1_sacch();
7824 [] L1CTL.receive { repeat; }
7825 [] Td.timeout {
7826 setverdict(fail, "Timeout waiting for Downlink speech frames");
7827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7828 }
7829 }
7830
7831 /* Make sure that Uplink frames are received at the BTS */
7832 RTPEM_DATA.clear;
7833 Tu.start(2.0);
7834 alt {
7835 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7836 if (rtp_pdu.data != pl)
7837 { repeat; }
7838 }
7839 [] RTPEM_DATA.receive { repeat; }
7840 [] Tu.timeout {
7841 setverdict(fail, "Timeout waiting for Uplink speech frames");
7842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7843 }
7844 }
7845
7846 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7847 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7848 f_rsl_chan_deact();
7849 f_rslem_unregister(0, g_chan_nr);
7850}
7851testcase TC_speech_rtp_tchf() runs on test_CT {
7852 var ConnHdlr vc_conn;
7853 var ConnHdlrPars pars;
7854
7855 f_init();
7856
7857 /* TS1, TCH/F, V1 (FR codec) */
7858 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7859 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7860 vc_conn.done;
7861
7862 /* TS1, TCH/F, V2 (EFR codec) */
7863 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7864 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7865 vc_conn.done;
7866
7867 /* TODO: also test V3 (AMR codec) */
7868
7869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7870}
7871testcase TC_speech_rtp_tchh() runs on test_CT {
7872 var ConnHdlr vc_conn;
7873 var ConnHdlrPars pars;
7874
7875 f_init();
7876
7877 /* TS5, TCH/H0, V1 (HR codec) */
7878 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7879 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7880 vc_conn.done;
7881
7882 /* TODO: also test V3 (AMR codec) */
7883
7884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7885}
7886
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007887private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7888 var GsmFrameNumber fn;
7889 var ChannelDescription ch_desc;
7890 var integer ra := 23;
7891
7892 f_l1_tune(L1CTL);
7893 RSL.clear;
7894
7895 /* Send RACH request and wait for ChanReq */
7896 fn := f_rach_req_wait_chan_rqd(ra);
7897
7898 /* The BSC already sends the Immediate Assignment, before the channel is active.
7899 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7900 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7901 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7902 if (g_pars.fhp.enabled) {
7903 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7904 } else {
7905 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7906 }
7907 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7908 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7909
7910 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7911 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7912 var L1ctlDlMessage dl;
7913 var GsmRrMessage rr;
7914
7915 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7916 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7917 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7918 rr_imm_ass.payload.imm_ass.chan_desc := *;
7919
7920 timer T := 1.0;
7921 T.start;
7922 alt {
7923 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7924 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7925 if (match(rr, rr_imm_ass)) {
7926 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7927 mtc.stop;
7928 } else {
7929 repeat;
7930 }
7931 }
7932 [] L1CTL.receive { repeat; }
7933 [] T.timeout;
7934 }
7935 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7936 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7937
7938 /* Now expect the IMM ASS on Um */
7939 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7940 setverdict(pass);
7941
7942 /* Release the channel */
7943 f_rsl_chan_deact();
7944 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7945}
7946
7947testcase TC_early_immediate_assignment() runs on test_CT {
7948 var ConnHdlr vc_conn;
7949 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7950 f_init();
7951 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
7952 vc_conn.done;
7953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7954}
7955
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007956private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
7957 var integer ra := oct2int(f_rnd_ra_cs());
7958 var ChannelDescription ch_desc;
7959
7960 /* Tune the MS to BCCH */
7961 f_l1_tune(L1CTL);
7962
7963 /* Send RACH request and wait for ChanReq */
7964 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
7965
7966 /* Activate channel on the BTS side */
7967 f_rsl_chan_act(g_pars.chan_mode);
7968
7969 /* Craft channel description (with or without frequency hopping parameters) */
7970 if (g_pars.fhp.enabled) {
7971 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7972 } else {
7973 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7974 }
7975
7976 /* Send IMM.ASS via CCHAN */
7977 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7978 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7979
7980 /* Receive IMM.ASS on the MS side */
7981 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7982
7983 /* Match the Channel Description IE in received IMM.ASS */
7984 if (not match(imm_ass.chan_desc, ch_desc)) {
7985 setverdict(fail, "Channel Description IE does not match");
7986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7987 }
7988
7989 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
7990 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
7991
7992 /* Expect SACCH frames on Downlink */
7993 L1CTL.clear;
7994 f_exp_sacch(true);
7995
7996 /* We're done, deactivate and release */
7997 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7998 f_rsl_chan_deact();
7999}
8000testcase TC_est_dchan() runs on test_CT {
8001 var ConnHdlr vc_conn;
8002 var ConnHdlrPars pars;
8003
8004 f_init();
8005
8006 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
8007 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
8008 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
8009 vc_conn.done;
8010 }
8011
8012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8013}
8014
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008015private type record TopTestCase {
8016 RSL_IE_BS_Power bs_power,
8017 RSL_IE_OSMO_TopAcchCap top_cap,
8018 record of TopTestStep steps
8019};
8020private type record TopTestStep {
8021 MeasurementResults meas_res optional,
8022 GsmRxLev overpower_sacch,
8023 GsmRxLev overpower_facch
8024};
8025
8026private function f_rxlev_match(template (present) RslLinkId link_id,
8027 template (present) GsmRxLev rxlev)
8028runs on ConnHdlr {
8029 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8030 if (not match(dl.dl_info.rx_level, rxlev)) {
8031 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8032 " does not match expected RxLev := ", rxlev);
8033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8034 }
8035}
8036
8037private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8038 var TopTestCase tc := g_pars.spec.top;
8039 var GsmRxLev rxlev_dcch;
8040 var L1ctlDlMessage dl;
8041
8042 /* Wait for Pau ramping to complete */
8043 f_sleep(6.0);
8044
8045 f_l1_tune(L1CTL);
8046 L1CTL.clear;
8047 RSL.clear;
8048
8049 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8050 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8051 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8052
8053 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8054 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8055
8056 /* Additional IEs for the CHANnel ACTIVation message */
8057 var template (value) RSL_IE_List ies := {
8058 /* Employ BS power control in static mode */
8059 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8060 bs_power := tc.bs_power
8061 }),
8062 /* Indicate the given Temporary Overpower capability */
8063 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8064 top_acch_cap := tc.top_cap
8065 })
8066 };
8067
8068 /* Establish a dedicated channel */
8069 f_est_dchan(more_ies := valueof(ies));
8070
8071 /* Give it some time to stabilize */
8072 f_sleep(0.480 * 2.0);
8073 L1CTL.clear;
8074 RSL.clear;
8075
8076 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8077 var TopTestStep step := tc.steps[i];
8078 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8079 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8080
8081 log("Executing step[", i, "] := ", step);
8082
8083 /* Send RR Measurement Report (if present) */
8084 if (ispresent(step.meas_res)) {
8085 f_transceive_meas_rep(step.meas_res);
8086 f_sleep(0.480 * 2.0);
8087 L1CTL.clear;
8088 }
8089
8090 /* Check RxLev on both FACCH and SACCH */
8091 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8092 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8093
8094 setverdict(pass);
8095 }
8096}
8097testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8098 var ConnHdlrPars pars;
8099 var ConnHdlr vc_conn;
8100
8101 f_init();
8102
8103 /* Verify lower and upper RxQual thresholds */
8104 var template TopTestCase top := {
8105 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8106 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8107 steps := {
8108 /* Channel established, no overpower */
8109 { meas_res := omit,
8110 overpower_sacch := 0, overpower_facch := 0 },
8111
8112 /* Worst possible RxQual value, overpower of 4dB */
8113 { meas_res := ts_MeasurementResults(rxq_f := 7),
8114 overpower_sacch := 4, overpower_facch := 4 },
8115 /* Worst possible RxQual value, disabling overpower */
8116 { meas_res := ts_MeasurementResults(rxq_f := 0),
8117 overpower_sacch := 0, overpower_facch := 0 },
8118
8119 /* Lower threshold not reached, no overpower */
8120 { meas_res := ts_MeasurementResults(rxq_f := 1),
8121 overpower_sacch := 0, overpower_facch := 0 },
8122 /* Lower threshold not reached, no overpower */
8123 { meas_res := ts_MeasurementResults(rxq_f := 2),
8124 overpower_sacch := 0, overpower_facch := 0 },
8125 /* Lower threshold reached, overpower of 4dB */
8126 { meas_res := ts_MeasurementResults(rxq_f := 4),
8127 overpower_sacch := 4, overpower_facch := 4 },
8128 /* Upper threshold not reached, keeping overpower */
8129 { meas_res := ts_MeasurementResults(rxq_f := 3),
8130 overpower_sacch := 4, overpower_facch := 4 },
8131 /* Upper threshold reached, disabling overpower */
8132 { meas_res := ts_MeasurementResults(rxq_f := 2),
8133 overpower_sacch := 0, overpower_facch := 0 }
8134 }
8135 };
8136
8137 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8138 spec := { top := top }, trx_nr := 1));
8139 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8140 vc_conn.done;
8141
8142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8143}
8144testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8145 var ConnHdlrPars pars;
8146 var ConnHdlr vc_conn;
8147
8148 f_init();
8149
8150 /* Verify handling of FULL and SUB values */
8151 var template TopTestCase top := {
8152 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8153 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8154 steps := {
8155 /* Channel established, no overpower */
8156 { meas_res := omit,
8157 overpower_sacch := 0, overpower_facch := 0 },
8158
8159 /* Invalid measurement results, no overpower */
8160 { meas_res := ts_MeasurementResults(rxq_f := 7,
8161 rxq_s := 7,
8162 valid := false),
8163 overpower_sacch := 0, overpower_facch := 0 },
8164
8165 /* DTXu was in use, no overpower */
8166 { meas_res := ts_MeasurementResults(rxq_f := 7,
8167 rxq_s := 0,
8168 dtx_used := true),
8169 overpower_sacch := 0, overpower_facch := 0 },
8170 /* DTXu was in use, overpower of 4 dB */
8171 { meas_res := ts_MeasurementResults(rxq_f := 0,
8172 rxq_s := 7,
8173 dtx_used := true),
8174 overpower_sacch := 4, overpower_facch := 4 }
8175 }
8176 };
8177
8178 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8179 spec := { top := top }, trx_nr := 1));
8180 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8181 vc_conn.done;
8182
8183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8184}
8185testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8186 var ConnHdlrPars pars;
8187 var ConnHdlr vc_conn;
8188
8189 f_init();
8190
8191 /* Overpower is always on, SACCH disabled */
8192 var template TopTestCase top := {
8193 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8194 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8195 rxqual := 0, /* always on */
8196 sacch_enable := false),
8197 steps := {
8198 /* Channel established, FACCH overpower */
8199 { meas_res := omit,
8200 overpower_sacch := 0, overpower_facch := 4 },
8201 /* MS indicates good RxQual, no difference */
8202 { meas_res := ts_MeasurementResults(rxq_f := 0),
8203 overpower_sacch := 0, overpower_facch := 4 },
8204 /* MS indicates bad RxQual, no difference */
8205 { meas_res := ts_MeasurementResults(rxq_f := 7),
8206 overpower_sacch := 0, overpower_facch := 4 }
8207 }
8208 };
8209
8210 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8211 spec := { top := top }, trx_nr := 1));
8212 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8213 vc_conn.done;
8214
8215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8216}
8217testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8218 var ConnHdlrPars pars;
8219 var ConnHdlr vc_conn;
8220
8221 f_init();
8222
8223 /* Overpower is always on, FACCH disabled */
8224 var template TopTestCase top := {
8225 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8226 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8227 rxqual := 0, /* always on */
8228 facch_enable := false),
8229 steps := {
8230 /* Channel established, SACCH overpower */
8231 { meas_res := omit,
8232 overpower_sacch := 4, overpower_facch := 0 },
8233 /* MS indicates good RxQual, no difference */
8234 { meas_res := ts_MeasurementResults(rxq_f := 0),
8235 overpower_sacch := 4, overpower_facch := 0 },
8236 /* MS indicates bad RxQual, no difference */
8237 { meas_res := ts_MeasurementResults(rxq_f := 7),
8238 overpower_sacch := 4, overpower_facch := 0 }
8239 }
8240 };
8241
8242 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8243 spec := { top := top }, trx_nr := 1));
8244 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8245 vc_conn.done;
8246
8247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8248}
8249testcase TC_acch_overpower_limit() runs on test_CT {
8250 var ConnHdlrPars pars;
8251 var ConnHdlr vc_conn;
8252
8253 f_init();
8254
8255 /* Overpower higher than current power reduction level (2dB) */
8256 var template TopTestCase top := {
8257 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8258 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8259 rxqual := 0 /* always on */),
8260 steps := {
8261 /* Channel established, ACCH overpower of 2dB */
8262 { meas_res := omit,
8263 overpower_sacch := 2, overpower_facch := 2 },
8264 /* MS indicates good RxQual, no difference */
8265 { meas_res := ts_MeasurementResults(rxq_f := 0),
8266 overpower_sacch := 2, overpower_facch := 2 },
8267 /* MS indicates bad RxQual, no difference */
8268 { meas_res := ts_MeasurementResults(rxq_f := 7),
8269 overpower_sacch := 2, overpower_facch := 2 }
8270 }
8271 };
8272
8273 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8274 spec := { top := top }, trx_nr := 1));
8275 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8276 vc_conn.done;
8277
8278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8279}
8280
Harald Welte0472ab42018-03-12 15:02:26 +01008281/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8282/* protocol error as per 44.006 */
8283/* link layer failure (repetition of I-frame N200 times without ACK */
8284/* repetition of SABM or DISC N200 times without ACK */
8285/* receptiom of SABM in multi-frame established state */
8286
8287
Harald Welte68e495b2018-02-25 00:05:57 +01008288/* TODO Areas:
8289
8290* channel activation
8291** with BS_Power / MS_Power, bypassing power control loop
8292** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008293** with timing advance from initial activation on
8294* mode modify
8295** encryption
8296** multirate
8297* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008298** unsupported algorithm
Harald Welte68e495b2018-02-25 00:05:57 +01008299* BS Power Control
8300* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008301* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008302** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008303* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008304** DATA_IND from BTS->PCU
8305** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008306
8307*/
Harald Welte70767382018-02-21 12:16:40 +01008308
8309control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008310 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008311 execute( TC_chan_act_stress() );
8312 execute( TC_chan_act_react() );
8313 execute( TC_chan_deact_not_active() );
8314 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008315 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008316 execute( TC_sacch_filling() );
8317 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008318 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008319 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008320 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008321 execute( TC_sacch_chan_act_ho_async() );
8322 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008323 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008324 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008325 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008326 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008327 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008328 execute( TC_rach_load_idle_thresh0() );
8329 execute( TC_rach_load_idle_below_thresh() );
8330 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008331 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008332 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008333 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008334 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008335 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008336 execute( TC_meas_res_sign_tchf() );
8337 execute( TC_meas_res_sign_tchh() );
8338 execute( TC_meas_res_sign_sdcch4() );
8339 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008340 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008341 execute( TC_meas_res_speech_tchf_sapi3() );
8342 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008343 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008344 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008345 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008346 execute( TC_rsl_bs_pwr_static_ass() );
8347 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008348 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008349 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008350 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008351 execute( TC_rsl_ms_pwr_dyn_up() );
8352 execute( TC_rsl_ms_pwr_dyn_down() );
8353 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8354 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008355 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008356 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008357 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008358 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008359 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008360 execute( TC_paging_imsi_80percent() );
8361 execute( TC_paging_tmsi_80percent() );
8362 execute( TC_paging_imsi_200percent() );
8363 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008364 execute( TC_rsl_protocol_error() );
8365 execute( TC_rsl_mand_ie_error() );
8366 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008367 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008368 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008369 execute( TC_si_sched_2bis() );
8370 execute( TC_si_sched_2ter() );
8371 execute( TC_si_sched_2ter_2bis() );
8372 execute( TC_si_sched_2quater() );
8373 execute( TC_si_sched_13() );
8374 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008375 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008376 execute( TC_ipa_crcx_twice_not_active() );
8377 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008378 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008379 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008380
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008381 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008382 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008383 execute( TC_pcu_act_req() );
8384 execute( TC_pcu_act_req_wrong_ts() );
8385 execute( TC_pcu_act_req_wrong_bts() );
8386 execute( TC_pcu_act_req_wrong_trx() );
8387 execute( TC_pcu_deact_req() );
8388 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008389 execute( TC_pcu_ver_si1() );
8390 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008391 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008392 if (mp_l1_supports_gprs) {
8393 execute( TC_pcu_data_req_pdtch() );
8394 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008395 execute( TC_pcu_data_req_wrong_bts() );
8396 execute( TC_pcu_data_req_wrong_trx() );
8397 execute( TC_pcu_data_req_wrong_ts() );
8398 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008399 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008400 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008401 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008402 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008403 execute( TC_pcu_data_req_imm_ass_pch() );
8404 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008405 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008406 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008407 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008408 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008409 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008410 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008411 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008412 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008413 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008414 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008415 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008416 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008417 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008418 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008419 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008420 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008421 execute( TC_dyn_osmo_pdch_act_deact() );
8422 execute( TC_dyn_osmo_pdch_double_act() );
8423 execute( TC_dyn_ipa_pdch_act_deact() );
8424 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008425 execute( TC_pcu_info_ind_fh_params() );
8426 execute( TC_pcu_socket_nsvc_ipv4() );
8427 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008428 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008429 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008430 } else {
8431 log("PCU socket path not available, skipping PCU tests");
8432 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008433
Harald Welte3d04ae62018-04-04 20:29:05 +02008434 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008435 execute( TC_dyn_osmo_pdch_tchf_act() );
8436 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008437 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008438 execute( TC_dyn_ipa_pdch_tchf_act() );
8439 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008440
8441 execute( TC_rll_est_ind() );
8442 execute( TC_rll_est_req_DCCH_3() );
8443 execute( TC_rll_est_req_ACCH_3() );
8444 execute( TC_rll_rel_ind_DCCH_0() );
8445 execute( TC_rll_rel_ind_DCCH_3() );
8446 execute( TC_rll_rel_ind_ACCH_0() );
8447 execute( TC_rll_rel_ind_ACCH_3() );
8448 execute( TC_rll_rel_req() );
8449 execute( TC_rll_unit_data_req_DCCH() );
8450 execute( TC_rll_unit_data_req_ACCH() );
8451 execute( TC_rll_unit_data_ind_DCCH() );
8452 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008453
8454 execute( TC_chan_act_a51() );
8455 execute( TC_chan_act_a52() );
8456 execute( TC_chan_act_a53() );
8457 execute( TC_encr_cmd_a51() );
8458 execute( TC_encr_cmd_a52() );
8459 execute( TC_encr_cmd_a53() );
8460
Harald Welteee25aae2019-05-19 14:32:37 +02008461 execute( TC_err_rep_wrong_mdisc() );
8462 execute( TC_err_rep_wrong_msg_type() );
8463 execute( TC_err_rep_wrong_sequence() );
8464
Harald Weltee613f962018-04-18 22:38:16 +02008465 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008466
8467 execute( TC_tch_sign_l2_fill_frame() );
8468 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008469
8470 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008471 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008472
8473 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008474 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008475
8476 execute( TC_speech_no_rtp_tchf() );
8477 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008478 execute( TC_speech_rtp_tchf() );
8479 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008480
8481 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008482
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008483 execute( TC_acch_overpower_rxqual_thresh() );
8484 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8485 execute( TC_acch_overpower_always_on_facch() );
8486 execute( TC_acch_overpower_always_on_sacch() );
8487 execute( TC_acch_overpower_limit() );
8488
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008489 /* BEWARE: these test cases can potentially break the IUT or cause
8490 * weird/unexpected behavior. Ensure that they are executed last. */
8491 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8492 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008493}
8494
8495
8496}