blob: 72d011d0989b9430f264e5470d48474245a521ed [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Harald Welte70767382018-02-21 12:16:40 +0100138}
139
Harald Welte629cc6b2018-03-11 17:19:05 +0100140type record of RslChannelNr ChannelNrs;
141
Harald Welte70767382018-02-21 12:16:40 +0100142type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100143 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100144 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100145 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100146 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100148 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100149
150 /* L1CTL port (for classic tests) */
151 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100152
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700153 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700154 port TRXC_CODEC_PT BTS_TRXC;
155 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100156
Harald Weltef50e3ae2018-09-10 10:27:56 +0200157 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100158 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200159 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100160
Harald Welte883340c2018-02-28 18:59:29 +0100161 /* PCU Interface of BTS */
162 port PCUIF_CODEC_PT PCU;
163 var integer g_pcu_conn_id;
164 /* Last PCU INFO IND we received */
165 var PCUIF_Message g_pcu_last_info;
166
Harald Welte48494ca2018-02-25 16:59:50 +0100167 /* SI configuration */
168 var SystemInformationConfig si_cfg := {
169 bcch_extended := false,
170 si1_present := false,
171 si2bis_present := false,
172 si2ter_present := false,
173 si2quater_present := false,
174 si7_present := false,
175 si8_present := false,
176 si9_present := false,
177 si13_present := false,
178 si13alt_present := false,
179 si15_present := false,
180 si16_present := false,
181 si17_present := false,
182 si2n_present := false,
183 si21_present := false,
184 si22_present := false
185 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100186
187 /* all logical channels available on the BTS */
188 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100189 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100190}
191
192/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200193type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100194 port L1CTL_PT L1CTL;
195
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700196 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700197 port TRXC_CODEC_PT BTS_TRXC;
198 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100199
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200200 /* port to be initialized optionally to access BSC VTY */
201 port TELNETasp_PT BSCVTY;
202
Harald Welte70767382018-02-21 12:16:40 +0100203 timer g_Tguard;
204 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
205
206 var ConnHdlrPars g_pars;
207 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100208 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200209
210 /* PCU Interface of BTS */
211 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200212
213 var RTP_Emulation_CT vc_RTPEM;
214 port RTPEM_CTRL_PT RTPEM_CTRL;
215 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100216}
217
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700218private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200220 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200222 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 timer T;
226
Harald Welte70767382018-02-21 12:16:40 +0100227 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
228 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
229
230 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
231 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
232 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
233
234 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
235 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700236
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700237 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700238 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700239 T.start(mp_ipa_up_timeout);
240 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700241 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700242 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
243 /* Make sure that all transceivers use unique stream ID */
244 if (trx_mask[enum2int(ev.sid)] == '1'B) {
245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
246 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
247 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700248
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 trx_mask[enum2int(ev.sid)] := '1'B;
250 trx_count := trx_count + 1;
251
252 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200253 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700254 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200255 /* This message (RF RESource INDication) is sent by the IUT itself */
256 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
257 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
259 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
260 }
261 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
264 }
265
266 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
267 rfind_count := rfind_count + 1;
268 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
269 if (rfind_count < mp_transceiver_num) { repeat; }
270 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700271 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
272 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
273 [] T.timeout {
274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
275 "Timeout waiting for RSL bring up");
276 }
277 }
Harald Welte70767382018-02-21 12:16:40 +0100278}
279
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700280friend type record length(1 .. 256) of TrxParsItem TrxPars;
281friend type record TrxParsItem {
282 GsmArfcn arfcn,
283 TrxTsPars ts
284};
285
286friend type record length(8) of TrxTsParsItem TrxTsPars;
287friend type record TrxTsParsItem {
288 PchanConfig config
289};
290
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700291friend type record FreqHopPars {
292 /* Whether frequency hopping is in use */
293 boolean enabled,
294 /* Mobile Allocation Index Offset / Hopping Sequence Number */
295 MaioHsn maio_hsn,
296 /* MA bitmap to be indicated in RR Immediate Assignment */
297 MobileAllocationLV ma_map,
298 /* The actual Mobile Allocation (ARFCN list) to be used */
299 L1ctlMA ma
300};
301
Harald Welte70767382018-02-21 12:16:40 +0100302type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700303 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100304 RslChannelNr chan_nr,
305 RSL_IE_ChannelMode chan_mode,
306 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100307 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200308 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200309 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700310 BtsBand bts0_band optional,
311
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700312 /* Training Sequence Code */
313 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700314 /* Frequency hopping parameters */
315 FreqHopPars fhp
316};
Harald Welte0472ab42018-03-12 15:02:26 +0100317
318/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200319friend type union TestSpecUnion {
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300320 RllTestCase rll,
321 TopTestCase top
Harald Welte70767382018-02-21 12:16:40 +0100322}
323
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700324private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100325 max_retrans := RACH_MAX_RETRANS_7,
326 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100327 cell_barr_access := false,
328 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100329 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100330};
331
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700332private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100333 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200334 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 acs := '0'B,
336 neci := true,
337 rxlev_access_min := 0
338}
339
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700340private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100341 mcc_mnc := '262F42'H,
342 lac := 42
343}
344
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700345private template (value) GPRSIndicator ts_GPRSIndicator_def := {
346 ra_colour := 0,
347 si13_pos := '0'B
348}
349
350private template (value) SI3RestOctets ts_SI3RestOctets_def
351modifies ts_SI3RestOctets := {
352 gprs_ind := {
353 presence := CSN1_H,
354 ind := ts_GPRSIndicator_def
355 }
356}
357
358private template (value) SI4RestOctets ts_SI4RestOctets_def
359modifies ts_SI4RestOctets := {
360 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700361 presence := CSN1_H,
362 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700363 }
364}
365
Harald Welte7484fc42018-02-24 14:09:45 +0100366/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700367private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100368 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100369 payload := {
370 si3 := {
371 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100372 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100373 ctrl_chan_desc := {
374 msc_r99 := true,
375 att := true,
376 bs_ag_blks_res := 1,
377 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100378 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100379 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
380 spare := '00'B,
381 bs_pa_mfrms := 0, /* 2 multiframes */
382 t3212 := 1 /* 6 minutes */
383 },
Harald Welte82ccef72018-02-25 16:17:33 +0100384 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100385 dn_ind := false,
386 pwrc := false,
387 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100388 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100389 },
Harald Weltef10153f2018-02-25 16:34:05 +0100390 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100391 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200392 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100393 }
394 }
395}
Harald Welte70767382018-02-21 12:16:40 +0100396
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700397private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100398 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100399 payload := {
400 si2 := {
401 bcch_freq_list := '00000000000000000000000000000000'O,
402 ncc_permitted := '11111111'B,
403 rach_control := ts_RachCtrl_default
404 }
405 }
406}
407
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700408private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100409 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100410 payload := {
411 si4 := {
412 lai := ts_LAI_default,
413 cell_sel_par := ts_CellSelPar_default,
414 rach_control := ts_RachCtrl_default,
415 cbch_chan_desc := omit,
416 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200417 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100418 }
419 }
420}
421
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700422private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100423runs on test_CT {
424 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700425 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100426}
427
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700428private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100429runs on test_CT {
430 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
431 log("Setting ", rsl_si_type, ": ", si_dec);
432 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
433}
434
Harald Welte505cf9b2018-09-15 17:47:23 +0300435friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100436 map(self:BTSVTY, system:BTSVTY);
437 f_vty_set_prompts(BTSVTY);
438 f_vty_transceive(BTSVTY, "enable");
439}
440
Harald Welte505cf9b2018-09-15 17:47:23 +0300441friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200442 map(self:BSCVTY, system:BSCVTY);
443 f_vty_set_prompts(BSCVTY, "OsmoBSC");
444 f_vty_transceive(BSCVTY, "enable");
445}
446
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200447friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
448 map(self:BSCVTY, system:BSCVTY);
449 f_vty_set_prompts(BSCVTY, "OsmoBSC");
450 f_vty_transceive(BSCVTY, "enable");
451}
452
Harald Welte883340c2018-02-28 18:59:29 +0100453/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200454friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100456 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200457 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
458 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100459 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200460 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100462 }
463}
464
Harald Weltef26de0b2018-04-04 20:28:05 +0200465private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
466 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100467 timer T := 2.0;
468 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100469 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200470 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100471 return;
472 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200473 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100474
475 T.start;
476 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200477 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100478 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100480 }
481 }
482}
483
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700484private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
485 out integer trxc_conn_id) {
486 var Result res;
487
488 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
489 "", -1, -1, { udp := {} }, {});
490 if (not ispresent(res.connId)) {
491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
492 "Could not connect to the control (TRXC) interface " &
493 "of FakeTRX, check your configuration");
494 }
495 trxc_conn_id := res.connId;
496}
497
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100498/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700499friend function f_init(uint8_t trx_nr := 0)
500runs on test_CT
501{
502 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200503 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100504
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700505 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
506 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700507 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200508 g_AllChanTypes := {
509 /* TS 1..4: TCH/F */
510 valueof(ts_RslChanNr_Bm(1)),
511 /* TS 5: TCH/H */
512 valueof(ts_RslChanNr_Lm(5,1)),
513 /* TS 0: SDCCH/4 */
514 valueof(ts_RslChanNr_SDCCH4(0,2)),
515 /* TS 6: SDCCH/8 */
516 valueof(ts_RslChanNr_SDCCH8(6,4))
517 };
518 } else {
519 g_AllChanTypes := {
520 /* TS 1..4: TCH/F */
521 valueof(ts_RslChanNr_Bm(1)),
522 /* TS 0: SDCCH/4 */
523 valueof(ts_RslChanNr_SDCCH4(0,2)),
524 /* TS 6: SDCCH/8 */
525 valueof(ts_RslChanNr_SDCCH8(6,4))
526 };
527 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700528
529 g_AllChannels := { };
530
531 /* Generate list of all logical channels from module parameters */
532 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
533 select (trx_pars.ts[tn].config) {
534 case (GSM_PCHAN_CCCH_SDCCH4) {
535 g_AllChannels := g_AllChannels &
536 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
537 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
538 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
539 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
540 }
541 case (GSM_PCHAN_SDCCH8) {
542 g_AllChannels := g_AllChannels &
543 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
544 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
545 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
546 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
547 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
550 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
551 }
552 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
553 g_AllChannels := g_AllChannels &
554 { valueof(ts_RslChanNr_Lm(tn, 0)),
555 valueof(ts_RslChanNr_Lm(tn, 1)),
556 valueof(ts_RslChanNr_Bm(tn)) };
557 }
558 case (GSM_PCHAN_TCHH) {
559 g_AllChannels := g_AllChannels &
560 { valueof(ts_RslChanNr_Lm(tn, 0)),
561 valueof(ts_RslChanNr_Lm(tn, 1)) };
562 }
563 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
564 g_AllChannels := g_AllChannels &
565 { valueof(ts_RslChanNr_Bm(tn)) };
566 }
567 }
568 }
569
Harald Welte70767382018-02-21 12:16:40 +0100570 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100571 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100572 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100573 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100574
575 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100576 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
577 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
578 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
579 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100580
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700581 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100582 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700583
584 /* Init TRXC interface to FakeTRX */
585 map(self:BTS_TRXC, system:BTS_TRXC);
586 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
587
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700588 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600589 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
590 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700591 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600592 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100593 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200594
595 /* Wait some extra time to make sure the BTS emits a stable carrier.
596 * (this is only relevant when running the tests with a physical BTS.) */
597 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
Harald Welte68e495b2018-02-25 00:05:57 +0100600/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700601friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100602 map(self:L1CTL, system:L1CTL);
603 f_connect_reset(L1CTL);
604}
605
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200606friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100607
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700608private type record length(8) of FreqHopGroups FreqHopConfig;
609
610private type record of FreqHopGroup FreqHopGroups;
611private type record FreqHopGroup {
612 uint6_t hsn,
613 FreqHopGroupItems trx_maio
614};
615
616private type record of FreqHopGroupItem FreqHopGroupItems;
617private type record FreqHopGroupItem {
618 uint8_t trx_nr,
619 uint6_t maio
620};
621
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700622friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
623 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700625 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700626 var integer i, j;
627
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700628 fhp.enabled := false;
629
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700630 for (i := 0; i < lengthof(groups); i := i + 1) {
631 var FreqHopGroup g := groups[i];
632 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
633 var FreqHopGroupItem gi := g.trx_maio[j];
634 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700635 fhp.maio_hsn.maio := gi.maio;
636 fhp.maio_hsn.hsn := g.hsn;
637 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700638 break;
639 }
640 }
641
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700642 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700643 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700644 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
645 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
646 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700647
648 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700649 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
650 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700651 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700652 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700653 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700654 }
655
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700656 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700657 break; /* We're done */
658 }
659 }
660}
661
Harald Welte70767382018-02-21 12:16:40 +0100662/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700663friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
664 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200665 boolean trxc_comp := false,
666 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100667runs on test_CT return ConnHdlr {
668 var charstring id := testcasename();
669 var ConnHdlr vc_conn;
670
671 vc_conn := ConnHdlr.create(id);
672 /* connect to RSL Emulation main component */
673 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
674 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700675
676 /* The ConnHdlr component may want to talk to some ports directly,
677 * so we disconnect it from the test_CT and connect it to the component.
678 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200679 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200680 unmap(self:PCU, system:PCU);
681 map(vc_conn:PCU, system:PCU);
682 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700683 if (trxc_comp) {
684 unmap(self:BTS_TRXC, system:BTS_TRXC);
685 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
686 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200687 if (l1ctl) {
688 map(vc_conn:L1CTL, system:L1CTL);
689 }
Harald Welte70767382018-02-21 12:16:40 +0100690
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700691 /* Obtain frequency hopping parameters for a given timeslot */
692 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700693 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700694 }
695
Harald Welte70767382018-02-21 12:16:40 +0100696 vc_conn.start(f_handler_init(fn, id, pars));
697 return vc_conn;
698}
699
Harald Welte70767382018-02-21 12:16:40 +0100700private altstep as_Tguard() runs on ConnHdlr {
701 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100703 }
704}
705
Harald Welte990a3612019-05-27 14:02:13 +0200706friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700707 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700708 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100709}
710
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700711private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100712 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600713 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100714}
715
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700716private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100717 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600718 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100719}
720
721/* first function started in ConnHdlr component */
722private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
723runs on ConnHdlr {
724 g_pars := pars;
725 g_chan_nr := pars.chan_nr;
726
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200727 if (L1CTL.checkstate("Mapped")) {
728 f_connect_reset(L1CTL);
729 }
Harald Welte70767382018-02-21 12:16:40 +0100730
Harald Welted48c0c72019-06-05 10:01:15 +0200731 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700732 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100733 }
Harald Welte70767382018-02-21 12:16:40 +0100734
735 g_Tguard.start(pars.t_guard);
736 activate(as_Tguard());
737
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700738 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100739
740 /* call the user-supplied test case function */
741 fn.apply(id);
742}
743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700744private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
745 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200746runs on ConnHdlr return RSL_Message {
747 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100748 timer T := 3.0;
749 RSL.send(tx);
750 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100751 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200752 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100753 T.stop;
754 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100755 }
Harald Welte1eba3742018-02-25 12:48:14 +0100756 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100758 }
Harald Welte21240e62018-03-11 21:43:35 +0100759 [not ignore_other] as_l1_sacch();
760 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700761 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700762 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100763 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100765 }
Harald Welte21240e62018-03-11 21:43:35 +0100766 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100767 }
Harald Welteb1726c92018-03-30 11:56:38 +0200768 return rx;
769}
770
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700771friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
772 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200773runs on ConnHdlr {
774 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100775}
776
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300777/* Send the given measurement results to the IUT over the Um interface,
778 * wait for the IUT to receive then and forward over the A-bis/RSL interface. */
779friend function f_transceive_meas_rep(template (value) MeasurementResults meas_res)
780runs on ConnHdlr {
781 var template (value) SacchL1Header l1h;
782 var octetstring l2, l3;
783 timer T;
784
785 /* RR Measurement Report to be sent */
786 var GsmRrL3Message meas_rep := {
787 header := valueof(t_RrL3Header(MEASUREMENT_REPORT)),
788 payload := { meas_rep := { meas_res := valueof(meas_res) } }
789 };
790
791 /* TITAN has weird (and often unusable) padding model, so we pad here manaully */
792 l3 := f_pad_oct(enc_GsmRrL3Message(meas_rep), 18, '00'O);
793 l2 := f_pad_oct(enc_LapdmFrameAB(valueof(ts_LAPDm_AB(0, meas_rep))), 21, '00'O);
794 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false,
795 g_pars.l1_pars.ms_actual_ta);
796
797 /* Send RR Measurement Report over the Um interface */
798 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
799
800 /* Expect MEASurement RESult on the A-bis/RSL interface */
801 T.start(2.0);
802 alt {
803 [] RSL.receive(tr_RSL_MEAS_RES_OSMO(g_chan_nr, l3_info := l3)) {
804 setverdict(pass);
805 }
806 [] RSL.receive { repeat; }
807 [] T.timeout {
808 setverdict(fail, "Timeout waiting for RSL MEASurement RESult");
809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
810 }
811 }
812}
813
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700814friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
815 boolean encr_enable := false,
816 RSL_IE_List more_ies := {},
817 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
818runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200819 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200820 if (encr_enable) {
821 /* append encryption related IEs, if requested */
822 var RSL_IE_EncryptionInfo encr_info;
823 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
824 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
825encr_info})) };
826 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200827 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200828 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100829}
830
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700831friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100832 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100833 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100834}
835
Harald Welte2f2b2b72019-05-31 22:24:57 +0200836friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200837 template RSL_IE_ChannelMode chan_mode,
838 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700839 uint8_t trx_nr := 0, float t_guard := 20.0) := {
840 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100841 chan_nr := valueof(chan_nr),
842 chan_mode := valueof(chan_mode),
843 t_guard := t_guard,
844 l1_pars := {
845 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100846 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100847 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100848 meas_ul := {
849 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200850 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100851 rxqual := 0
852 },
853 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200854 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100855 rxqual := 0
856 }
857 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200858 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100859 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200860 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200861 ms_actual_ta := mp_ms_actual_ta_exp,
862 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100863 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200864 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200865 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700866 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700867 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700868 fhp := {
869 enabled := false,
870 maio_hsn := ts_HsnMaio(0, 0),
871 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700872 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700873 }
Harald Welte70767382018-02-21 12:16:40 +0100874}
875
Harald Welte93640c62018-02-25 16:59:33 +0100876/***********************************************************************
877 * Channel Activation / Deactivation
878 ***********************************************************************/
879
Harald Welte70767382018-02-21 12:16:40 +0100880/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700881private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100882 for (var integer i := 0; i < 500; i := i+1) {
883 f_rsl_chan_act(g_pars.chan_mode);
884 f_rsl_chan_deact();
885 }
886 setverdict(pass);
887}
888testcase TC_chan_act_stress() runs on test_CT {
889 var ConnHdlr vc_conn;
890 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200891 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100892 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
893 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100895}
896
897/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700898private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100899 f_rsl_chan_act(g_pars.chan_mode);
900 /* attempt to activate the same lchan again -> expect reject */
901 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
902 alt {
903 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100905 }
906 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
907 setverdict(pass);
908 }
909 }
910 f_rsl_chan_deact();
911}
912testcase TC_chan_act_react() runs on test_CT {
913 var ConnHdlr vc_conn;
914 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100915 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100916 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
917 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100919}
920
921/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700922private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100923 timer T := 3.0;
924 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
925 T.start;
926 alt {
927 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
928 setverdict(pass);
929 }
930 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100932 }
933 }
934}
935testcase TC_chan_deact_not_active() runs on test_CT {
936 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100937 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100938 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
939 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100941}
942
943/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700944private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100945 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
946 alt {
947 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100949 }
950 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
951 setverdict(pass);
952 }
953 }
954}
955private type record WrongChanNrCase {
956 RslChannelNr chan_nr,
957 charstring description
958}
959private type record of WrongChanNrCase WrongChanNrCases;
960private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
961 chan_nr := chan_nr,
962 description := desc
963}
964
965testcase TC_chan_act_wrong_nr() runs on test_CT {
966 var ConnHdlr vc_conn;
967 var ConnHdlrPars pars;
968
Harald Welte294b0a22018-03-10 23:26:48 +0100969 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100970
971 var WrongChanNrCases wrong := {
972 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
973 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
974 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
975 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
976 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
977 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
978 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
979 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
980 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
981 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
982 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
983 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
984 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
985 };
986
987 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
988 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
989 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
990 vc_conn.done;
991 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100993}
994
Harald Weltee613f962018-04-18 22:38:16 +0200995/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200996friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200997 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200998 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200999
1000 /* test on each of the channels we have */
1001 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
1002 pars.chan_nr := valueof(g_AllChanTypes[i]);
1003
1004 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
1005 vc_conn := f_start_handler(fn, pars);
1006 vc_conn.done;
1007 }
1008
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +02001010}
1011
Harald Welte93640c62018-02-25 16:59:33 +01001012/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +01001013 * SACCH handling
1014 ***********************************************************************/
1015
1016private function f_exp_sacch(boolean exp) runs on ConnHdlr {
1017 timer T_sacch := 3.0;
1018 T_sacch.start;
1019 alt {
1020 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +01001022 }
1023 [not exp] T_sacch.timeout {
1024 setverdict(pass);
1025 }
1026 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
1027 setverdict(pass);
1028 }
1029 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +01001031 }
1032 [] L1CTL.receive { repeat; }
1033 [] RSL.receive { repeat; }
1034 }
1035}
1036
1037/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1038private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1039 f_l1_tune(L1CTL);
1040 RSL.clear;
1041
1042 /* activate the logical channel */
1043 f_est_dchan();
1044 L1CTL.clear;
1045
1046 /* check that SACCH actually are received as expected */
1047 f_exp_sacch(true);
1048
1049 /* deactivate SACCH on the logical channel */
1050 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1051 f_sleep(1.0);
1052 L1CTL.clear;
1053
1054 /* check that no SACCH are received anymore */
1055 f_exp_sacch(false);
1056
1057 /* release the channel */
1058 f_rsl_chan_deact();
1059 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1060}
1061testcase TC_deact_sacch() runs on test_CT {
1062 var ConnHdlr vc_conn;
1063 var ConnHdlrPars pars;
1064 f_init();
1065 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1066 //for (var integer i := 0; i < 1; i := i+1) {
1067 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1068 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1069 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1070 vc_conn.done;
1071 }
1072 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001074}
1075
Harald Welte55700662018-03-12 13:15:43 +01001076/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001077private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1078 var L1ctlDlMessage dl;
1079 /* check that the specified SI5 value is actually sent */
1080 timer T_sacch := 3.0;
1081 L1CTL.clear;
1082 T_sacch.start;
1083 alt {
1084 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1085 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1086 if (match(l3, l3_exp)) {
1087 setverdict(pass);
1088 } else {
1089 repeat;
1090 }
1091 }
1092 [] L1CTL.receive { repeat; }
1093 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001095 }
1096 }
1097}
1098
Harald Welte55700662018-03-12 13:15:43 +01001099/* verify that given SACCH payload is not present */
1100private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1101 var L1ctlDlMessage dl;
1102 /* check that the specified SI5 value is actually sent */
1103 timer T_sacch := 3.0;
1104 L1CTL.clear;
1105 T_sacch.start;
1106 alt {
1107 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1108 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1109 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001111 } else {
1112 repeat;
1113 }
1114 }
1115 [] L1CTL.receive { repeat; }
1116 [] T_sacch.timeout {
1117 setverdict(pass);
1118 }
1119 }
1120}
1121
Harald Welte629cc6b2018-03-11 17:19:05 +01001122/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001123private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1124 /* Set a known default SACCH filling for SI5 */
1125 var octetstring si5 := f_rnd_octstring(19);
1126 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1127
1128 f_l1_tune(L1CTL);
1129 RSL.clear;
1130
1131 /* activate the logical channel */
1132 f_est_dchan();
1133
1134 /* check that the specified SI5 value is actually sent */
1135 f_sacch_present(si5);
1136
1137 /* release the channel */
1138 RSL.clear;
1139 f_rsl_chan_deact();
1140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1141}
1142testcase TC_sacch_filling() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144 var ConnHdlrPars pars;
1145 f_init();
1146 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1147 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1148 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1149 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1150 vc_conn.done;
1151 }
1152 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001154}
1155
Harald Welte629cc6b2018-03-11 17:19:05 +01001156/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001157private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1158 /* Set a known default SACCH filling for SI5 */
1159 var octetstring si5 := f_rnd_octstring(19);
1160 var octetstring si5_diff := f_rnd_octstring(19);
1161 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1162
1163 f_l1_tune(L1CTL);
1164 RSL.clear;
1165
1166 log("Activating channel, expecting standard SI5");
1167 /* activate the logical channel */
1168 f_est_dchan();
1169 /* check that the specified SI5 value is actually sent */
1170 f_sacch_present(si5);
1171
1172 /* set channel-specific different SI5 */
1173 log("Setting channel specific SACCH INFO, expecting it");
1174 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1175 /* check that the specified lchan-specific value is now used */
1176 f_sacch_present(si5_diff);
1177
1178 /* deactivate the channel and re-activate it, this should result in default SI5 */
1179 log("De-activating and re-activating channel, expecting standard SI5");
1180 f_rsl_chan_deact();
1181 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1182 /* Verify that the TRX-wide default SACCH filling is present again */
1183 f_sacch_present(si5);
1184
1185 /* release the channel */
1186 RSL.clear;
1187 f_rsl_chan_deact();
1188 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1189}
1190testcase TC_sacch_info_mod() runs on test_CT {
1191 var ConnHdlr vc_conn;
1192 var ConnHdlrPars pars;
1193 f_init();
1194 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1195 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1196 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1197 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1198 vc_conn.done;
1199 }
1200 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001202}
1203
Harald Welte075d84c2018-03-12 13:07:24 +01001204/* Test SACCH scheduling of multiple different SI message types */
1205private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1206 var octetstring si5 := f_rnd_octstring(19);
1207 var octetstring si5bis := f_rnd_octstring(19);
1208 var octetstring si5ter := f_rnd_octstring(19);
1209 var octetstring si6 := f_rnd_octstring(19);
1210
1211 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1212 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1213 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1214 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1215
1216 f_l1_tune(L1CTL);
1217 RSL.clear;
1218
1219 /* activate the logical channel */
1220 f_est_dchan();
1221 L1CTL.clear;
1222
1223 /* check that SACCH actually are received as expected */
1224 f_sacch_present(si5);
1225 f_sacch_present(si5bis);
1226 f_sacch_present(si5ter);
1227 f_sacch_present(si6);
1228
1229 /* release the channel */
1230 f_rsl_chan_deact();
1231 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1232}
1233testcase TC_sacch_multi() runs on test_CT {
1234 var ConnHdlr vc_conn;
1235 var ConnHdlrPars pars;
1236 f_init();
1237 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1238 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1239 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1240 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1241 vc_conn.done;
1242 }
1243 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001245}
1246
Harald Welte55700662018-03-12 13:15:43 +01001247/* Test if SACH information is modified as expected */
1248private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1249 var octetstring si5 := f_rnd_octstring(19);
1250 var octetstring si6 := f_rnd_octstring(19);
1251
1252 /* First, configure both SI5 and SI6 to be transmitted */
1253 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1254 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1255
1256 f_l1_tune(L1CTL);
1257 RSL.clear;
1258
1259 /* activate the logical channel */
1260 f_est_dchan();
1261 L1CTL.clear;
1262
1263 /* check that SACCH actually are received as expected */
1264 f_sacch_present(si5);
1265 f_sacch_present(si6);
1266
1267 /* disable SI6 */
1268 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1269
1270 /* check that SI5 is still transmitted */
1271 f_sacch_present(si5);
1272 /* check if SI6 is now gone */
1273 f_sacch_missing(si6);
1274
1275 /* release the channel */
1276 f_rsl_chan_deact();
1277 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1278}
1279testcase TC_sacch_multi_chg() runs on test_CT {
1280 var ConnHdlr vc_conn;
1281 var ConnHdlrPars pars;
1282 f_init();
1283 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1284 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1285 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1286 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1287 vc_conn.done;
1288 }
1289 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001291}
1292
Harald Weltec8d363c2019-05-19 20:36:48 +02001293/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1294private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1295 var octetstring si5 := f_rnd_octstring(19);
1296 var octetstring si6 := f_rnd_octstring(19);
1297 var octetstring si5_specific := f_rnd_octstring(19);
1298 var octetstring si6_specific := f_rnd_octstring(19);
1299
1300 /* First, configure both SI5 and SI6 to be transmitted */
1301 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1302 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1303
1304 f_l1_tune(L1CTL);
1305 RSL.clear;
1306
1307 /* activate channel with different SACCH filling */
1308 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1309 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1310 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1311 }));
1312 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1313 RSL_IE_Body:{sacch_info := sacch_info})) };
1314 f_est_dchan(more_ies := addl_ies);
1315
1316 /* check that SACCH actually are received as expected */
1317 f_sacch_present(si5_specific);
1318 f_sacch_present(si6_specific);
1319
1320 /* release the channel */
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323}
1324testcase TC_sacch_chan_act() runs on test_CT {
1325 var ConnHdlr vc_conn;
1326 var ConnHdlrPars pars;
1327 f_init();
1328
1329 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1330 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1331 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1332 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1333 vc_conn.done;
1334 }
1335 /* TODO: do the above in parallel, rather than sequentially? */
1336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1337}
1338
Harald Welte8b01c792019-05-19 22:51:25 +02001339/* verify that SACCH DL transmission is started only if MS power IE present
1340 * see section 4.1.3 of 3GPP TS 48.058 */
1341private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1342 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001343 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001344
1345 f_l1_tune(L1CTL);
1346 RSL.clear;
1347
1348 /* Step 1: Activate ASYNC HO channel without MS power IE */
1349
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001350 var integer ho_ref := oct2int(f_rnd_octstring(1));
1351 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1352 RSL_IE_Body:{ handover_ref := ho_ref }));
1353 var RSL_IE_List addl_ies := {
1354 ho_ref_ie
1355 };
1356
Harald Welte8b01c792019-05-19 22:51:25 +02001357 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001358 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001359 /* don't perform immediate assignment here, as we're testing non-IA case */
1360 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001361 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001362
1363 /* Verify that no DL SACCH is being received */
1364 f_sacch_missing(?);
1365
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001366 /* Send handover Access Burst and expect SACCH to start */
1367 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1368
1369 f_sacch_present(si5);
1370
Harald Welte8b01c792019-05-19 22:51:25 +02001371 f_rsl_chan_deact();
1372 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1373
1374
1375 /* Step 2: Activate ASYNC HO channel with MS power IE */
1376
1377 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001378 addl_ies := {
1379 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001380 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1381 };
1382 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1383 /* don't perform immediate assignment here, as we're testing non-IA case */
1384 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001385 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001386
1387 /* Verify that DL SACCH is being received */
1388 f_sacch_present(si5);
1389
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001390 /* Send handover Access Burst and expect SACCH to remain present */
1391 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1392
1393 f_sacch_present(si5);
1394
Harald Welte8b01c792019-05-19 22:51:25 +02001395 f_rsl_chan_deact();
1396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1397}
1398testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1399 var ConnHdlr vc_conn;
1400 var ConnHdlrPars pars;
1401 f_init();
1402
1403 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1404 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1405 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1406 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1407 vc_conn.done;
1408 }
1409 /* TODO: do the above in parallel, rather than sequentially? */
1410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1411}
1412
1413/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1414 * see section 4.1.4 of 3GPP TS 48.058 */
1415private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1416 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001417 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1418
Harald Welte8b01c792019-05-19 22:51:25 +02001419 var RSL_IE_List addl_ies;
1420
1421 f_l1_tune(L1CTL);
1422 RSL.clear;
1423
1424 /* Step 1: Activate SYNC HO channel without MS power IE */
1425
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001426 var integer ho_ref := oct2int(f_rnd_octstring(1));
1427 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1428 RSL_IE_Body:{ handover_ref := ho_ref }));
1429 addl_ies := {
1430 ho_ref_ie
1431 };
1432
Harald Welte8b01c792019-05-19 22:51:25 +02001433 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001434 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001435 /* don't perform immediate assignment here, as we're testing non-IA case */
1436 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001437 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001438
1439 /* Verify that no DL SACCH is being received */
1440 f_sacch_missing(?);
1441
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001442 /* Send handover Access Burst and expect SACCH to start */
1443 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1444
1445 f_sacch_present(si5);
1446
Harald Welte8b01c792019-05-19 22:51:25 +02001447 f_rsl_chan_deact();
1448 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1449
1450
1451 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1452
1453 /* Activate channel on BTS side */
1454 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001455 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001456 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1457 };
1458 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1459 /* don't perform immediate assignment here, as we're testing non-IA case */
1460 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001461 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001462
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001463 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1464 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001465
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001466 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001467 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1468
1469 f_sacch_present(si5);
1470
Harald Welte8b01c792019-05-19 22:51:25 +02001471 f_rsl_chan_deact();
1472 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1473
1474
1475 /* Step 2b: Activate SYNC HO channel with TA IE */
1476
1477 /* Activate channel on BTS side */
1478 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001479 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001480 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1481 };
1482 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1483 /* don't perform immediate assignment here, as we're testing non-IA case */
1484 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001485 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001486
1487 /* Verify that no DL SACCH is being received */
1488 f_sacch_missing(?);
1489
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001490 /* Send handover Access Burst and expect SACCH to start */
1491 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1492
1493 f_sacch_present(si5);
1494
Harald Welte8b01c792019-05-19 22:51:25 +02001495 f_rsl_chan_deact();
1496 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1497
1498
1499 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1500
1501 /* Activate channel on BTS side */
1502 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001503 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001504 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1505 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1506 };
1507 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1508 /* don't perform immediate assignment here, as we're testing non-IA case */
1509 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001510 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001511
1512 /* Verify that DL SACCH is being received */
1513 f_sacch_present(si5);
1514
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001515 /* Send handover Access Burst and expect SACCH to remain present */
1516 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1517
1518 f_sacch_present(si5);
1519
Harald Welte8b01c792019-05-19 22:51:25 +02001520 f_rsl_chan_deact();
1521 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1522}
1523testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1524 var ConnHdlr vc_conn;
1525 var ConnHdlrPars pars;
1526 f_init();
1527
1528 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1529 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1530 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1531 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1532 vc_conn.done;
1533 }
1534 /* TODO: do the above in parallel, rather than sequentially? */
1535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1536}
Harald Welte629cc6b2018-03-11 17:19:05 +01001537
1538
1539/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001540 * RACH Handling
1541 ***********************************************************************/
1542
Harald Welte8c24c2b2018-02-26 08:31:31 +01001543/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001544private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001545 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001546 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001547 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001548
Harald Welte8c24c2b2018-02-26 08:31:31 +01001549 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001550 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001551 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001552 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001553 if (emerg == true) {
1554 ra := f_rnd_ra_emerg();
1555 } else {
1556 ra := f_rnd_ra_cs();
1557 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001558 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1559 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001561 }
1562 fn_last := fn;
1563
1564 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001565 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001566 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001567 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001568 T.stop;
1569 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001570 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001572 }
1573 [] RSL_CCHAN.receive { repeat; }
1574 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001575 test_failed := true;
1576 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001577 }
1578 }
1579 }
Maxba06feb2019-03-05 10:52:46 +01001580 if (test_failed) {
1581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001582 }
Maxba06feb2019-03-05 10:52:46 +01001583 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001585}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001586
Philipp Maier16ade782020-07-08 21:36:00 +02001587/* Normal variant */
1588testcase TC_rach_content() runs on test_CT {
1589 f_TC_rach_content(emerg := false);
1590}
1591
1592/* Emergency call variant */
1593testcase TC_rach_content_emerg() runs on test_CT {
1594 f_TC_rach_content(emerg := true);
1595}
1596
Harald Welte8c24c2b2018-02-26 08:31:31 +01001597/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1598testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001599 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001600 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001601 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001602 f_l1_tune(L1CTL);
1603
1604 var GsmFrameNumber fn_last := 0;
1605 for (var integer i := 0; i < 1000; i := i+1) {
1606 var OCT1 ra := f_rnd_ra_cs();
1607 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1608 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001610 }
1611 fn_last := fn;
1612 }
1613 var integer rsl_chrqd := 0;
1614 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001615 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001616 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001618 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001619 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001620 repeat;
1621 }
1622 [] RSL_CCHAN.receive { repeat; }
1623 [] T.timeout { }
1624 }
1625 if (rsl_chrqd == 1000) {
1626 setverdict(pass);
1627 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001629 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001631}
1632
Harald Welte3453ab42019-05-24 21:19:58 +02001633private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1634 var charstring bts_str := "bts " & int2str(bts_nr);
1635 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1636}
1637
1638/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1639private template integer tr_rach_slots_per_interval := (90 .. 130);
1640
1641/* Expect 0 RACH load on an idle BTS that has just started up */
1642testcase TC_rach_load_idle_thresh0() runs on test_CT {
1643 var ASP_RSL_Unitdata rx_ud;
1644
1645 f_init_vty_bsc();
1646 /* send load indications even at 0% load */
1647 f_vty_load_ind_thresh(0);
1648 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1649 f_sleep(2.0);
1650
1651 f_init();
1652
Harald Weltee37f9a52020-10-11 20:45:23 +02001653 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1654 alt {
1655 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1656 [] RSL_CCHAN.receive { repeat }
1657 }
1658
Harald Welte3453ab42019-05-24 21:19:58 +02001659 timer T := 5.0;
1660 T.start;
1661 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001662 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001663 setverdict(pass);
1664 repeat;
1665 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001666 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001667 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1668 repeat;
1669 }
1670 [] RSL_CCHAN.receive {
1671 repeat;
1672 }
1673 [] T.timeout { }
1674 }
1675
1676 f_vty_load_ind_thresh(10);
1677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1678}
1679
1680/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1681testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1682 var ASP_RSL_Unitdata rx_ud;
1683
1684 f_init_vty_bsc();
1685 f_init();
1686
1687 timer T := 5.0;
1688 T.start;
1689 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001690 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001691 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1692 repeat;
1693 }
1694 [] RSL_CCHAN.receive {
1695 repeat;
1696 }
1697 [] T.timeout {
1698 setverdict(pass);
1699 }
1700 }
1701
1702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1703}
1704
1705/* Expect 0 RACH load on an idle BTS that has just started up */
1706testcase TC_rach_load_count() runs on test_CT {
1707 var ASP_RSL_Unitdata rx_ud;
1708 var integer load_access_count := 0;
1709
1710 f_init_vty_bsc();
1711 /* send load indications even at 0% load */
1712 f_vty_load_ind_thresh(0);
1713 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1714 f_sleep(2.0);
1715 f_init();
1716
1717 f_init_l1ctl();
1718 f_sleep(1.0);
1719 f_l1_tune(L1CTL);
1720
Harald Welte52ae1682020-10-11 20:45:55 +02001721 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1722 alt {
1723 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1724 [] RSL_CCHAN.receive { repeat }
1725 }
1726
Harald Welte3453ab42019-05-24 21:19:58 +02001727 var GsmFrameNumber fn_last := 0;
1728 for (var integer i := 0; i < 1000; i := i+1) {
1729 var OCT1 ra := f_rnd_ra_cs();
1730 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1731 if (fn == fn_last) {
1732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1733 }
1734 fn_last := fn;
1735 }
1736
1737 timer T := 5.0;
1738 T.start;
1739 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001740 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001741 -> value rx_ud {
1742 var RSL_IE_Body ie;
1743 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1744 load_access_count := load_access_count + ie.rach_load.access_count;
1745 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1746 setverdict(fail, "Access count cannot be < Busy count");
1747 }
1748 repeat;
1749 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001750 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001751 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1752 repeat;
1753 }
1754 [] RSL_CCHAN.receive {
1755 repeat;
1756 }
1757 [] T.timeout { }
1758 }
1759 if (load_access_count == 1000) {
1760 setverdict(pass);
1761 } else {
1762 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1763 }
1764
1765 f_vty_load_ind_thresh(10);
1766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1767}
1768
Harald Welte54a2a2d2018-02-26 09:14:05 +01001769private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001770 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001771 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001772 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001773 f_sleep(0.5);
1774
1775 /* Transmit RACH request + wait for confirmation */
1776 var OCT1 ra := f_rnd_ra_cs();
1777 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1778
1779 /* Check for expected result */
1780 timer T := 1.5;
1781 T.start;
1782 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001783 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001784 setverdict(pass);
1785 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001786 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001788 }
1789 [] RSL_CCHAN.receive { repeat; }
1790 [not expect_pass] T.timeout {
1791 setverdict(pass);
1792 }
1793 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001795 }
1796 }
1797}
1798
1799/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1800testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001801 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001802 f_init_l1ctl();
1803 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001804 f_sleep(1.0);
1805
1806 /* default max-ta is 63 (full range of GSM timing advance */
1807
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001808 /* We allow early arrival up to 2 symbols */
1809 f_rach_toffs(-1*256, true);
1810 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001811 f_rach_toffs(-10*256, false);
1812
1813 /* 0 / 32 / 63 bits is legal / permitted */
1814 f_rach_toffs(0, true);
1815 f_rach_toffs(32*256, true);
1816 f_rach_toffs(63*256, true);
1817
1818 /* more than 63 bits is not legal / permitted */
1819 f_rach_toffs(64*256, false);
1820 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001822}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001823
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001824private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001825 var GsmFrameNumber fn;
1826 var RSL_Message rm;
1827
1828 f_l1_tune(L1CTL);
1829 RSL.clear;
1830
1831 /* Generate a random Handover Reference */
1832 var integer ho_ref := oct2int(f_rnd_octstring(1));
1833
1834 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1835 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1836 RSL_IE_Body:{ handover_ref := ho_ref }));
1837
1838 /* Activate a channel on the BTS side (no encryption) */
1839 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1840 act_type := t_RSL_IE_ActType_HO_SYNC);
1841
1842 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1843 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001844 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001845
1846 /* Send handover Access Burst */
1847 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1848
1849 /* TODO: test mismatching Handover Reference, and missing IE */
1850
1851 /* Wait for handover detection */
1852 timer T := 3.0;
1853 T.start;
1854 alt {
1855 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1856 log("Handover RACH has been detected: ", rm);
1857 setverdict(pass);
1858 }
1859 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1861 log2str("RSL_CHAN_RQD was not expected: ", rm));
1862 }
1863 [] RSL.receive { repeat; }
1864 [] T.timeout {
1865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1866 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1867 }
1868 }
1869
1870 /* Release the channel */
1871 f_rsl_chan_deact();
1872 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1873}
1874
1875/* Test handover RACH detection */
1876testcase TC_ho_rach() runs on test_CT {
1877 var ConnHdlrPars pars;
1878 var ConnHdlr vc_conn;
1879
1880 f_init();
1881
1882 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1883 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1884 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1885 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1886 vc_conn.done;
1887 }
1888
1889 /* TODO: do the above in parallel, rather than sequentially? */
1890 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1891}
1892
Harald Welte93640c62018-02-25 16:59:33 +01001893/***********************************************************************
1894 * Measurement Processing / Reporting
1895 ***********************************************************************/
1896
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001897private template (value) LapdmAddressField
1898ts_LapdmAddr(template (value) LapdmSapi sapi,
1899 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001900 spare := '0'B,
1901 lpd := 0,
1902 sapi := sapi,
1903 c_r := c_r,
1904 ea := true
1905}
1906
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001907private template (value) LapdmFrameAB
1908ts_LAPDm_AB(template (value) LapdmSapi sapi,
1909 template (value) GsmRrL3Message l3,
1910 template (value) boolean c_r := false,
1911 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001912 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001913 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001914 len := 0, /* overwritten */
1915 m := false,
1916 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001917 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001918}
1919
1920/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001921private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001922 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001923 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001924
Harald Weltef8df4cb2018-03-10 15:15:08 +01001925 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001926 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001927
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001928 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001929 g_pars.l1_pars.meas_ul.full.rxlev,
1930 g_pars.l1_pars.meas_ul.sub.rxlev,
1931 g_pars.l1_pars.meas_ul.full.rxqual,
1932 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001933 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001934
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001935 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1936 g_pars.l1_pars.ms_power_level, false,
1937 g_pars.l1_pars.ms_actual_ta);
1938
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001939 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1940 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001941
1942 log("Sending Measurement Report: ", l1h, l2);
1943 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001944 repeat;
1945 }
1946}
1947
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001948/* handle incoming downlink SACCH, decode the L1 header into the given record */
1949private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1950 boolean do_apply := true)
1951runs on ConnHdlr
1952{
1953 var L1ctlDlMessage l1_dl;
1954
1955 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1956 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1957 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1958 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1959
1960 if (do_apply) {
1961 /* Update TA and MS power to follow what BTS requests */
1962 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1963 }
1964 }
1965}
1966
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001967private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001968 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001969 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001970 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1971 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001972 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1973 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001974 repeat;
1975 }
1976}
1977
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001978private altstep as_l1_tch_loop() runs on ConnHdlr {
1979 var L1ctlDlMessage l1_dl;
1980 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1981 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001982
1983 /* occasionaly inject FACCH frames into the uplink */
1984 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1985 var octetstring pl := '010301'O;
1986 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1987 f_pad_oct(pl, 23, '2B'O)));
1988 } else {
1989 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1990 l1_dl.payload.traffic_ind.data));
1991 }
1992
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001993 repeat;
1994 }
1995}
1996
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001997private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001998 uint6_t rxlev,
1999 uint3_t rxqual
2000}
2001
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002002private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01002003 MeasElem full,
2004 MeasElem sub
2005}
2006
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002007private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01002008 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01002009 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01002010 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01002011 MeasElemFS meas_ul,
2012 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002013 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01002014 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02002015 uint8_t ms_actual_ta,
2016 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01002017}
2018
2019/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
2020private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
2021 return 63 + (toffs256s/256);
2022}
2023
Harald Welted5684392018-03-10 18:22:04 +01002024private function f_max(integer a, integer b) return integer {
2025 if (a > b) {
2026 return a;
2027 } else {
2028 return b;
2029 }
2030}
2031
2032private function f_min(integer a, integer b) return integer {
2033 if (a < b) {
2034 return a;
2035 } else {
2036 return b;
2037 }
2038}
2039
2040/* compute negative tolerance val-tolerance, ensure >= min */
2041private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2042 val := val - tolerance;
2043 return f_max(val, min);
2044}
2045
2046/* compute positive tolerance val+tolerance, ensure <= max */
2047private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2048 val := val + tolerance;
2049 return f_min(val, max);
2050}
2051
2052/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2053private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2054return template integer {
2055 var template integer ret;
2056 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2057 return ret;
2058}
2059
2060
Harald Welte70767382018-02-21 12:16:40 +01002061/* build a template for matching measurement results against */
2062private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2063 var ConnL1Pars l1p := g_pars.l1_pars;
2064 var template RSL_IE_UplinkMeas ul_meas := {
2065 len := 3,
2066 rfu := '0'B,
2067 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002068 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002069 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002070 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002071 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002072 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2073 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002074 supp_meas_info := omit
2075 };
Harald Welte685d5982018-02-27 20:42:05 +01002076 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002077 ul_meas.len := (3+8);
2078 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002079 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002080 toa256_min := ?,
2081 toa256_max := ?,
2082 toa256_std_dev := ?
2083 }
Harald Welte685d5982018-02-27 20:42:05 +01002084 }
Harald Welte70767382018-02-21 12:16:40 +01002085 var template RSL_IE_BS_Power bs_power := {
2086 reserved := 0,
2087 epc := false,
2088 fpc := false,
2089 power_level := l1p.bs_power_level
2090 };
2091 var template RSL_IE_L1Info l1_info := {
2092 ms_power_lvl := l1p.ms_power_level,
2093 fpc := false,
2094 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002095 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002096 };
2097 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002098 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002099 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2100 ?, t_toffs);
2101}
2102
Philipp Maierdd841d32019-12-17 14:44:54 +01002103/* build a template for matching measurement results that do not contain any
2104 * MS related measurement (l1_info, l3_info and ms timing offset). */
2105private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2106 var ConnL1Pars l1p := g_pars.l1_pars;
2107 var template RSL_IE_UplinkMeas ul_meas := {
2108 len := 3,
2109 rfu := '0'B,
2110 dtx_d := l1p.dtx_enabled,
2111 rxlev_f_u := ?,
2112 reserved1 := '00'B,
2113 rxlev_s_u := ?,
2114 reserved2 := '00'B,
2115 rxq_f_u := ?,
2116 rxq_s_u := ?,
2117 supp_meas_info := omit
2118 };
2119 if (l1p.toa256_enabled) {
2120 ul_meas.len := (3+8);
2121 ul_meas.supp_meas_info := {
2122 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2123 toa256_min := ?,
2124 toa256_max := ?,
2125 toa256_std_dev := ?
2126 }
2127 }
2128 var template RSL_IE_BS_Power bs_power := {
2129 reserved := 0,
2130 epc := false,
2131 fpc := false,
2132 power_level := l1p.bs_power_level
2133 };
2134
2135 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2136}
2137
Harald Welte70767382018-02-21 12:16:40 +01002138/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002139private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002140 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002141 var boolean chan_est := false;
2142
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002143 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002144
2145 /* Receive osmocom specific measurement reports. This is the normal
2146 * case. Here we verify that the measurement reports we sent are
2147 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002148 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2149 /* increment counter of next to-be-expected meas rep */
2150 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2151 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002152 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002153
2154 /* The following two cases may only happen in the beginning
2155 * of the channel establishment phase. Once we have received
2156 * the "our" measurement report the first time, the channel
2157 * is established and empty or hardcoded TRXCON reports must
2158 * not occur anymore. */
2159 chan_est := true;
2160
2161 repeat;
2162 }
2163
2164 /* When the BTS has established the channel, the MS might need slightly
2165 * more time to establish the channel and actually start sending. The
2166 * result is then a measurement report that just lacks the measurement
2167 * information of the MS. This is normal and we tolerate this behavior. */
2168 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2169 /* increment counter of next to-be-expected meas rep */
2170 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2171 /* Re-start the timer expecting the next MEAS RES */
2172 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002173 repeat;
2174 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002175
2176 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2177 * measurements if the TTCN3 side does not supply measurement input in
2178 * time. In those cases TRXCON will either use a cached measurement
2179 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2180 * report the templates above will not match. We tolerate this
2181 * behavior, but only once. */
2182 [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 +01002183 /* increment counter of next to-be-expected meas rep */
2184 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2185 if (g_first_meas_res) {
2186 g_first_meas_res := false;
2187 repeat;
2188 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002190 }
Harald Welte70767382018-02-21 12:16:40 +01002191 }
2192 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002194 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002195 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002197 }
2198}
2199
Harald Weltee613f962018-04-18 22:38:16 +02002200private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2201 select (rsl_alg_id) {
2202 case (RSL_ALG_ID_A5_0) { return 0; }
2203 case (RSL_ALG_ID_A5_1) { return 1; }
2204 case (RSL_ALG_ID_A5_2) { return 2; }
2205 case (RSL_ALG_ID_A5_3) { return 3; }
2206 case (RSL_ALG_ID_A5_4) { return 4; }
2207 case (RSL_ALG_ID_A5_5) { return 5; }
2208 case (RSL_ALG_ID_A5_6) { return 6; }
2209 case (RSL_ALG_ID_A5_7) { return 7; }
2210 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002211 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2212 /* Make compiler happy by calling mtc.stop here. It is already
2213 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002214 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002215 }
2216 }
2217}
2218
2219private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2220 select (rsl_alg_id) {
2221 case (RSL_ALG_ID_A5_1) { return '000'B; }
2222 case (RSL_ALG_ID_A5_2) { return '001'B; }
2223 case (RSL_ALG_ID_A5_3) { return '010'B; }
2224 case (RSL_ALG_ID_A5_4) { return '011'B; }
2225 case (RSL_ALG_ID_A5_5) { return '100'B; }
2226 case (RSL_ALG_ID_A5_6) { return '101'B; }
2227 case (RSL_ALG_ID_A5_7) { return '110'B; }
2228 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2230 /* Make compiler happy by calling mtc.stop here. It is already
2231 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002232 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002233 }
2234 }
2235}
2236
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002237/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2238private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2239 var GsmFrameNumber fn;
2240 timer T := 8.0;
2241
2242 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2243 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2244
2245 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2246 /* Send the actual RACH */
2247 fn := f_L1CTL_RACH(L1CTL, ra);
2248
2249 T.start;
2250 alt {
2251 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2252 [] T.timeout {
2253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2254 }
2255 }
2256 T.stop
2257 return fn;
2258}
Harald Weltee613f962018-04-18 22:38:16 +02002259
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002260/* Tune to a dedicated channel: L1CTL only */
2261private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002262 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002263 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002264 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002265 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002266 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002267 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002268 pars.fhp.maio_hsn.hsn,
2269 pars.fhp.maio_hsn.maio,
2270 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002271 }
2272}
2273
Harald Welte70767382018-02-21 12:16:40 +01002274/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002275private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002276 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002277
2278 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002279 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002280
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002281 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002282 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002283 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002284 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002285 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2286 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002287 }
2288
Harald Welte70767382018-02-21 12:16:40 +01002289 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002290 f_l1ctl_est_dchan(L1CTL, g_pars);
2291
Harald Weltee613f962018-04-18 22:38:16 +02002292 /* enable encryption, if requested */
2293 if (encr_enable) {
2294 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2295 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2296 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002297
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002298 /* Send TCH Mode Request to the L1 if needed */
2299 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2300 var L1ctlTchMode tch_mode;
2301
2302 select (g_pars.chan_mode.coding_alg_rate) {
2303 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2304 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2305 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2306 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2307 case else {
2308 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2309 " is not supported by the L1, falling back to signalling");
2310 tch_mode := L1CTL_CHAN_MODE_SIGN;
2311 }
2312 }
2313
2314 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2315 }
2316
Harald Weltefa45e9e2018-03-10 18:59:03 +01002317 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002318}
2319
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002320/* Initialize and start the RTP emulation component for a ConnHdlr */
2321friend function f_rtpem_activate(inout octetstring payload,
2322 RtpemConfig cfg := c_RtpemDefaultCfg,
2323 RtpemMode mode := RTPEM_MODE_BIDIR)
2324runs on ConnHdlr {
2325 /* Step 0: initialize, connect and start the emulation component */
2326 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2327 map(vc_RTPEM:RTP, system:RTP);
2328 map(vc_RTPEM:RTCP, system:RTCP);
2329 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2330 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2331 vc_RTPEM.start(RTP_Emulation.f_main());
2332
2333 /* Step 1: configure the RTP parameters */
2334 var integer payload_len := 0;
2335 var octetstring hdr := ''O;
2336
2337 select (g_pars.chan_mode) {
2338 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2339 { payload_len := 33; hdr := 'D0'O; }
2340 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2341 { payload_len := 15; hdr := '00'O; }
2342 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2343 { payload_len := 31; hdr := 'C0'O; }
2344 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2345 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2346 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2347 }
2348 }
2349
2350 /* Pad the payload to conform the expected length */
2351 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2352 cfg.tx_fixed_payload := payload;
2353 f_rtpem_configure(RTPEM_CTRL, cfg);
2354
2355 /* Step 2: bind the RTP emulation to the configured address */
2356 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2357 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2358
2359 /* Step 3: send CRCX with the configured address/port to the IUT */
2360 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2361 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2362 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2363 "IPA CRCX ACK");
2364
2365 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2366 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2367 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2368 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2369
2370 /* Step 5: set the given RTP emulation mode */
2371 f_rtpem_mode(RTPEM_CTRL, mode);
2372}
2373
Harald Welte70767382018-02-21 12:16:40 +01002374/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002375private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002376 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002377 RSL.clear;
2378
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002379 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002380 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002381 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002382 }
Harald Welte70767382018-02-21 12:16:40 +01002383
2384 f_est_dchan();
2385
2386 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2387 * RSL measurement reports on Abis side */
2388 timer T := 8.0;
2389 T.start;
2390 alt {
2391 [] as_l1_sacch();
2392 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002393 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002394 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002395 [] L1CTL.receive { repeat; }
2396 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002397 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002398 * of any earlier errors, so if we reach this timeout, we're good */
2399 setverdict(pass);
2400 }
2401 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002403 }
2404 }
2405 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002406 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002407}
Harald Welte0472ab42018-03-12 15:02:26 +01002408
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002409/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2410private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002411 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002412 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2413 timer Tup := 10.0;
2414 Tup.start;
2415 alt {
2416 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2417 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2418 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002419
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002420 if (rx_lvl != max_rx_lvl) {
2421 repeat;
2422 }
2423 Tup.stop;
2424 }
2425 [] L1CTL.receive { repeat; }
2426 [] Tup.timeout {
2427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2428 log2str("Didn't reach full power ", max_rx_lvl));
2429 }
2430 }
2431 return max_rx_lvl;
2432}
2433
2434/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2435private function f_verify_ramp_up() runs on ConnHdlr {
2436 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002437 var integer initial_rx_lvl := -1;
2438 var integer last_rx_lvl := -1;
2439 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2440
2441 timer T := 2.0;
2442 alt {
2443 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2444 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2445 log("Received rx_level=", rx_lvl);
2446 if (initial_rx_lvl == -1) {
2447 initial_rx_lvl := rx_lvl;
2448 last_rx_lvl := rx_lvl;
2449
2450 /* Expect a somehow low value during first received messages */
2451 if (initial_rx_lvl >= max_rx_lvl / 2) {
2452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2453 log2str("Detected high initial tx power during ramp up: ",
2454 initial_rx_lvl , ", full power is", max_rx_lvl));
2455 }
2456 }
2457
2458 /* received Rx level bigger than maximum allowed power by CN */
2459 if (rx_lvl > max_rx_lvl) {
2460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2461 log2str("Detected Tx power higher than full power: ",
2462 rx_lvl , " > ", max_rx_lvl));
2463 }
2464
2465 /* Make sure it never decreases, since we are rumping up */
2466 if (last_rx_lvl > rx_lvl) {
2467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2468 log2str("Detected Tx power decrease during ramp up: ",
2469 last_rx_lvl , " -> ", rx_lvl));
2470 }
2471
2472 if (rx_lvl == max_rx_lvl and not T.running) {
2473 /* We reached the maximum power, start timer and receive
2474 /* a few more to make sure we don't surpass it */
2475 log("Reached full power, wating a bit more until success");
2476 T.start;
2477 }
2478
2479 last_rx_lvl := rx_lvl;
2480 repeat;
2481 }
2482 [] L1CTL.receive { repeat; }
2483 [] T.timeout { }
2484 }
2485
2486 /* We didn't increase tx power during ramp up */
2487 if (initial_rx_lvl < last_rx_lvl) {
2488 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2489 } else {
2490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2491 log2str("No Tx power increase during whole ramp up: ",
2492 initial_rx_lvl , " -> ", last_rx_lvl));
2493 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002494}
2495
2496/* verify BTS ramps power down to rx_level 0 */
2497private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2498 var L1ctlDlMessage l1_dl;
2499 var integer last_rx_lvl := max_rx_lvl;
2500
2501 timer Tdown := 5.0;
2502 Tdown.start;
2503 alt {
2504 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2505 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2506 log("Received rx_level=", rx_lvl);
2507
2508 /* received Rx level bigger than maximum allowed power by CN */
2509 if (rx_lvl > max_rx_lvl) {
2510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2511 log2str("Detected Tx power higher than full power: ",
2512 rx_lvl , " > ", max_rx_lvl));
2513 }
2514
2515 /* Make sure it never increases, since we are rumping down */
2516 if (last_rx_lvl < rx_lvl) {
2517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2518 log2str("Detected Tx power increase during ramp up: ",
2519 last_rx_lvl , " -> ", rx_lvl));
2520 }
2521
2522 last_rx_lvl := rx_lvl;
2523 if (last_rx_lvl != 0) {
2524 repeat;
2525 }
2526 /* we reached power level 0, we are done */
2527 Tdown.stop;
2528 }
2529 [] L1CTL.receive { repeat; }
2530 [] Tdown.timeout { }
2531 }
2532
2533 /* We didn't increase tx power during ramp down */
2534 if (max_rx_lvl > last_rx_lvl) {
2535 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2536 } else {
2537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2538 log2str("No Tx power decrease during whole ramp down: ",
2539 max_rx_lvl , " -> ", last_rx_lvl));
2540 }
2541}
2542
2543/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002544private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002545 f_l1_tune(L1CTL);
2546 RSL.clear;
2547
2548 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002549
2550 setverdict(pass);
2551}
2552testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2553 var ConnHdlr vc_conn;
2554 var ConnHdlrPars pars;
2555 f_init();
2556 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2557 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2558 pcu_comp := false, trxc_comp := true);
2559 vc_conn.done;
2560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2561}
2562
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002563/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002564private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002565 f_connhdlr_init_vty_bsc();
2566
2567 f_l1_tune(L1CTL);
2568 RSL.clear;
2569
2570 /* Wait until BTS is started and at full power */
2571 var integer max_rx_lvl := f_wait_ramp_up();
2572 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2573
2574 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2575 f_verify_ramp_down(max_rx_lvl);
2576
2577 setverdict(pass);
2578}
2579testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2580 var ConnHdlr vc_conn;
2581 var ConnHdlrPars pars;
2582 f_init();
2583 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2584 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2585 pcu_comp := false, trxc_comp := true);
2586 vc_conn.done;
2587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2588}
2589
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002590/* Verify Tx power:
2591 * + ramping down during ADM state UNLOCKED->LOCKED
2592 * + ramping up during ADM state LOCKED->UNLOCKED
2593 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002594private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002595 var L1ctlDlMessage l1_dl;
2596 var integer last_rx_lvl;
2597
2598 f_connhdlr_init_vty_bsc();
2599
2600 f_l1_tune(L1CTL);
2601 RSL.clear;
2602
2603 /* Wait until BTS is started and at full power */
2604 var integer max_rx_lvl := f_wait_ramp_up();
2605 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2606
2607 log("ADM STATE UNLOCKED->LOCKED");
2608 f_vty_enter_cfg_trx(BSCVTY);
2609 f_vty_transceive(BSCVTY, "rf_locked 1");
2610 last_rx_lvl := max_rx_lvl;
2611 f_verify_ramp_down(max_rx_lvl);
2612
2613 /* Let some time after we received 0dBm, then check we don't receive BCCH
2614 * anymore because scheduler has stopped after ramping down */
2615 f_sleep(2.0);
2616 L1CTL.clear;
2617 timer Tlocked := 2.0;
2618 Tlocked.start;
2619 alt {
2620 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2622 log2str("Received data_ind during rf_locked: ", l1_dl));
2623 }
2624 [] L1CTL.receive { repeat; }
2625 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2626 }
2627
2628 log("ADM STATE LOCKED->UNLOCKED");
2629 f_vty_transceive(BSCVTY, "rf_locked 0");
2630 f_verify_ramp_up();
2631 setverdict(pass);
2632}
2633testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2634 var ConnHdlr vc_conn;
2635 var ConnHdlrPars pars;
2636 f_init();
2637 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2638 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2639 pcu_comp := false, trxc_comp := true);
2640 vc_conn.done;
2641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2642}
2643
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002644private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002645 timer T := 8.0;
2646 T.start;
2647 var RSL_Message rsl;
2648 alt {
2649 [] as_l1_sacch();
2650 [] L1CTL.receive { repeat; }
2651 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2652 if (rsl.ies[3].body.bs_power.power_level == level) {
2653 setverdict(pass)
2654 } else {
2655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2656 }
2657 }
2658 [] T.timeout {
2659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2660 }
2661 }
2662}
2663
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002664/* See if the RSL MEASurement RESult contains expeced BS power level
2665 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002666private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002667 f_l1_tune(L1CTL);
2668 RSL.clear;
2669
2670 if (mp_bts_trxc_port != -1) {
2671 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2672 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2673 }
2674
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002675 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002676 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2677 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2678
2679 f_est_dchan(more_ies :={valueof(pwr)});
2680
2681 f_check_meas_bs_power_level(pwr_var);
2682
2683 f_rsl_chan_deact();
2684 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2685}
2686
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002687/* See if the RSL MEASurement RESult contains expeced BS power level
2688 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002689private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002690 f_l1_tune(L1CTL);
2691 RSL.clear;
2692
2693 if (mp_bts_trxc_port != -1) {
2694 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2695 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2696 }
2697
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002698 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002699 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2700
2701 f_est_dchan();
2702
2703 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2704
2705 f_check_meas_bs_power_level(pwr_var);
2706
2707 f_rsl_chan_deact();
2708 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2709}
2710
2711testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2712 var ConnHdlr vc_conn;
2713 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002714
Eric Wildae8f2622019-06-18 17:05:11 +02002715 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002716
2717 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2718 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2719 pcu_comp := false, trxc_comp := true);
2720 vc_conn.done;
2721
Eric Wildae8f2622019-06-18 17:05:11 +02002722 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2723}
2724
2725testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2726 var ConnHdlr vc_conn;
2727 var ConnHdlrPars pars;
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002728
Eric Wildae8f2622019-06-18 17:05:11 +02002729 f_init();
Vadim Yanitskiyda5964d2021-10-23 16:27:27 +03002730
2731 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN, trx_nr := 1));
2732 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2733 pcu_comp := false, trxc_comp := true);
2734 vc_conn.done;
2735
Eric Wildae8f2622019-06-18 17:05:11 +02002736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2737}
2738
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002739/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2740 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2741 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002742private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002743 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002744 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002745
2746 f_trxc_fake_rssi(rxlev2dbm(10));
2747 f_l1_tune(L1CTL);
2748 RSL.clear;
2749
2750 var RSL_IE_List addl_ies;
2751 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2752
2753 addl_ies := {
2754 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2755 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2756 };
2757
2758 /* establish with power parameters */
2759 f_est_dchan(more_ies := addl_ies);
2760
2761 /* set a high value to ensure L1 power control level increases */
2762 f_trxc_fake_rssi(rxlev2dbm(20));
2763
2764 timer T2 := 6.0;
2765 T2.start;
2766 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002767 [] as_l1_sacch_l1h(l1h) {
2768 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002769 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002770 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002771 T2.stop;
2772 }
2773 [] L1CTL.receive { repeat; }
2774 [] T2.timeout {
2775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2776 "Power Level in L1 header has not increased sufficiently");
2777 }
2778 }
2779
2780 /* set a low value to ensure L1 power control level decreases */
2781 f_trxc_fake_rssi(rxlev2dbm(0));
2782
2783 timer T4 := 6.0;
2784 T4.start;
2785 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002786 [] as_l1_sacch_l1h(l1h) {
2787 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002788 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002789 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002790 T4.stop;
2791 setverdict(pass, "Power level in L1 decreased/increased as expected");
2792 }
2793 [] L1CTL.receive { repeat; }
2794 [] T4.timeout {
2795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2796 "Power Level in L1 header has not decreased sufficiently");
2797 }
2798 }
2799
2800 f_rsl_chan_deact();
2801 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2802
2803}
2804
2805/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002806private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002807 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002808 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002809
2810 /* set a low value to ensure power increases */
2811 f_trxc_fake_rssi(rxlev2dbm(10));
2812 f_l1_tune(L1CTL);
2813 RSL.clear;
2814
2815 var RSL_IE_List addl_ies;
2816 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2817
2818 addl_ies := {
2819 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2820 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2821 };
2822
2823 /* establish with power parameters */
2824 f_est_dchan(more_ies := addl_ies);
2825
2826 timer T1 := 10.0;
2827 T1.start;
2828 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002829 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002830 [] L1CTL.receive { repeat; }
2831 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002832 if (not isbound(l1h)) {
2833 setverdict(fail, "No SACCH blocks were received");
2834 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002835 setverdict(fail, "Power level in L1 header should not have changed");
2836 }
2837 }
2838 }
2839
2840 f_rsl_chan_deact();
2841 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2842
2843}
2844
2845/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002846private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002847 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002848 var uint5_t pwr_var := 15;
2849 var uint5_t pwr_max_var := f_get_max_power_from_band();
2850
2851 /* set a low value to ensure power increases */
2852 f_trxc_fake_rssi(rxlev2dbm(10));
2853 f_l1_tune(L1CTL);
2854 RSL.clear;
2855
2856 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2857 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2858
2859 /* establish with fixed power level */
2860 f_est_dchan(more_ies :={valueof(pwr)});
2861
2862 /* check our initial power level */
2863 f_wait_for_l1_power_level(pwr_var);
2864
2865 /* update power param to enable power loop
2866 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2867 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2868
2869 /* wait, then check that our power level was reduced */
2870 timer T1 := 10.0;
2871 T1.start;
2872 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002873 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002874 [] L1CTL.receive { repeat; }
2875 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002876 if (not isbound(l1h)) {
2877 setverdict(fail, "No SACCH blocks were received");
2878 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002879 setverdict(pass, "Power level in L1 header reduced as expected");
2880 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002881 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2882 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002883 }
2884 }
2885 }
2886
2887 f_rsl_chan_deact();
2888 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2889
2890}
2891
2892/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002893private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002894 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002895
2896 /* set a high value to ensure power decreases */
2897 f_trxc_fake_rssi(rxlev2dbm(50));
2898 f_l1_tune(L1CTL);
2899 RSL.clear;
2900
2901 var uint5_t pwr_var := 5;
2902 var uint5_t pwr_target_val := 15;
2903
2904 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2905 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2906
2907 /* establish with fixed power level */
2908 f_est_dchan(more_ies :={valueof(pwr)});
2909
2910 /* check our initial power level */
2911 f_wait_for_l1_power_level(pwr_var);
2912
2913 /* update power param to enable power loop
2914 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002915 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002916
2917 /* wait, then check that our power level was increased */
2918 timer T1 := 10.0;
2919 T1.start;
2920 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002921 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002922 [] L1CTL.receive { repeat; }
2923 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002924 if (not isbound(l1h)) {
2925 setverdict(fail, "No SACCH blocks were received");
2926 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2927 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002928 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002929 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002930 }
2931 }
2932 }
2933
2934 f_rsl_chan_deact();
2935 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2936
2937}
2938
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002939/* See if the power level remains constant when MS Power Parameters IE
2940 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002941private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002942 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002943
2944 /* set a high value to ensure power decreases */
2945 f_trxc_fake_rssi(rxlev2dbm(50));
2946 f_l1_tune(L1CTL);
2947 RSL.clear;
2948
2949 var uint5_t pwr_var := 5;
2950
2951 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2952 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2953
2954 /* establish with fixed power level */
2955 f_est_dchan(more_ies :={valueof(pwr)});
2956
2957 /* check our initial power level */
2958 f_wait_for_l1_power_level(pwr_var);
2959
2960 /* wait, then check that our power level did not change */
2961 timer T1 := 10.0;
2962 T1.start;
2963 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002964 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2965 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2967 "BS power control should not be active unless we receive a power parameters IE!");
2968 }
2969 repeat;
2970 }
2971 [] L1CTL.receive { repeat; }
2972 [] T1.timeout { setverdict(pass); }
2973 }
2974
2975 f_rsl_chan_deact();
2976 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2977
2978}
2979
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002980/* See if the power level remains constant when MS Power Parameters IE
2981 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002982private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002983 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002984
2985 /* set a high value to ensure power decreases */
2986 f_trxc_fake_rssi(rxlev2dbm(50));
2987 f_l1_tune(L1CTL);
2988 RSL.clear;
2989
2990 var uint5_t pwr_var := 5;
2991
2992 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2993 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2994
2995 /* establish with fixed power level */
2996 f_est_dchan(more_ies :={valueof(pwr)});
2997
2998 /* check our initial power level */
2999 f_wait_for_l1_power_level(pwr_var);
3000
3001 /* pwr control without power params IE, should NOT activate MS power control*/
3002 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3003
3004 /* wait, then check that our power level did not change */
3005 timer T1 := 10.0;
3006 T1.start;
3007 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003008 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3009 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02003010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3011 "BS power control should not be active unless we receive a power parameters IE!");
3012 }
3013 repeat;
3014 }
3015 [] L1CTL.receive { repeat; }
3016 [] T1.timeout { setverdict(pass); }
3017 }
3018
3019 f_rsl_chan_deact();
3020 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3021
3022}
3023
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003024private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003025 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02003026 timer T0 := 10.0;
3027 T0.start;
3028 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003029 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3030 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02003031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3032 "Power level in L1 header != signaled (RSL) power level.");
3033 }
3034 }
3035 [] L1CTL.receive { repeat; }
3036 [] T0.timeout {
3037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3038 "Timeout waiting for initial power level");
3039 }
3040 }
3041 T0.stop;
3042}
3043
3044private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3045 var IntegerRecord min_dbm_level;
3046 var IntegerRecord max_dbm_level;
3047 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3048
3049 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3050 if (min_dbm_level[i] == level) {
3051 return true;
3052 }
3053 }
3054 return false;
3055}
3056
3057private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3058 var IntegerRecord min_dbm_level;
3059 var IntegerRecord max_dbm_level;
3060 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3061
3062 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3063 if (max_dbm_level[i] == level) {
3064 return true;
3065 }
3066 }
3067 return false;
3068}
3069
3070private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3071 var IntegerRecord min_dbm_level;
3072 var IntegerRecord max_dbm_level;
3073 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3074 return max_dbm_level[0];
3075}
3076
3077type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003078private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003079private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3080 // 45.005 4.1.1
3081 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3082 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3083 2, 1, 0};
3084 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3085 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3086 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3087 var IntegerRecord rv;
3088
3089 select(band){
3090 case (BtsBand_allGSM){
3091 rv := gsm_power;
3092 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3093 max_dbm_level := {2, 1, 0};
3094 }
3095 case("DCS1800"){
3096 rv := dcs_power;
3097 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3098 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3099 }
3100 case("PCS1900"){
3101 rv := pcs_power;
3102 min_dbm_level := {15};
3103 max_dbm_level := {30};
3104 }
Harald Welte194b6912020-10-11 21:01:55 +02003105 case else {
3106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3107 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003108 }
3109
3110 return rv;
3111}
3112
3113private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003114 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 +02003115}
3116
3117testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3118 var ConnHdlr vc_conn;
3119 var ConnHdlrPars pars;
3120 f_init();
3121 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3122 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3123 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3124 pars.bts0_band := f_vty_get_bts0_band();
3125 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3126 vc_conn.done;
3127 }
3128 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3130}
3131
3132testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3133 var ConnHdlr vc_conn;
3134 var ConnHdlrPars pars;
3135 f_init();
3136 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3137 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3138 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3139 pars.bts0_band := f_vty_get_bts0_band();
3140 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3141 vc_conn.done;
3142 }
3143 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3145}
3146
3147testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3148 var ConnHdlr vc_conn;
3149 var ConnHdlrPars pars;
3150 f_init();
3151 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3152 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3153 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3154 pars.bts0_band := f_vty_get_bts0_band();
3155 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3156 vc_conn.done;
3157 }
3158 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3160}
3161
3162testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3163 var ConnHdlr vc_conn;
3164 var ConnHdlrPars pars;
3165 f_init();
3166 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3167 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3168 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3169 pars.bts0_band := f_vty_get_bts0_band();
3170 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3171 vc_conn.done;
3172 }
3173 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3175}
3176
Eric Wild280ccb82019-06-17 11:11:52 +02003177testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3178 var ConnHdlr vc_conn;
3179 var ConnHdlrPars pars;
3180 f_init();
3181 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3182 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3183 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3184 pars.bts0_band := f_vty_get_bts0_band();
3185 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3186 vc_conn.done;
3187 }
3188 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3190}
3191
Eric Wild095024b2019-06-17 15:08:57 +02003192testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3193 var ConnHdlr vc_conn;
3194 var ConnHdlrPars pars;
3195 f_init();
3196 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3197 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3198 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3199 pars.bts0_band := f_vty_get_bts0_band();
3200 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3201 vc_conn.done;
3202 }
3203 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3205}
3206
Philipp Maier149c3922020-10-22 17:29:36 +02003207function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003208 var template RSL_IE_ChannelMode ch_mode;
3209 var ConnHdlr vc_conn;
3210 var ConnHdlrPars pars;
3211 f_init();
3212 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3213 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3214 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003215 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003216 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3217 pcu_comp := false, trxc_comp := true);
3218 vc_conn.done;
3219 }
3220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3221}
Philipp Maier149c3922020-10-22 17:29:36 +02003222
3223testcase TC_meas_res_speech_tchf() runs on test_CT {
3224 f_TC_meas_res_speech_tchf(false);
3225}
3226
3227testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3228 f_TC_meas_res_speech_tchf(true);
3229}
3230
3231function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003232 var template RSL_IE_ChannelMode ch_mode;
3233 var ConnHdlr vc_conn;
3234 var ConnHdlrPars pars;
3235 f_init();
3236 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3237 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3238 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003239 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003240 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3241 pcu_comp := false, trxc_comp := true);
3242 vc_conn.done;
3243 }
3244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3245}
Philipp Maier149c3922020-10-22 17:29:36 +02003246
3247testcase TC_meas_res_speech_tchh() runs on test_CT {
3248 f_TC_meas_res_speech_tchh(false)
3249}
3250
3251testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3252 f_TC_meas_res_speech_tchh(true)
3253}
3254
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003255testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3256 var template RSL_IE_ChannelMode ch_mode;
3257 var ConnHdlr vc_conn;
3258 var ConnHdlrPars pars;
3259 f_init();
3260 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3261 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3262 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3263 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3264 pars.l1_pars.toa256_enabled := true;
3265 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3266 pcu_comp := false, trxc_comp := true);
3267 vc_conn.done;
3268 }
3269 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3270}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003271
Harald Welte70767382018-02-21 12:16:40 +01003272testcase TC_meas_res_sign_tchf() runs on test_CT {
3273 var ConnHdlr vc_conn;
3274 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003275 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003276 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003277 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003278 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003279 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3280 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003281 vc_conn.done;
3282 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003284}
3285testcase TC_meas_res_sign_tchh() runs on test_CT {
3286 var ConnHdlr vc_conn;
3287 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003288 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003289 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003290 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003291 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003292 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3293 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003294 vc_conn.done;
3295 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003297}
3298testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3299 var ConnHdlr vc_conn;
3300 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003301 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003302 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003303 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3304 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003305 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3306 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003307 vc_conn.done;
3308 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003310}
3311testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3312 var ConnHdlr vc_conn;
3313 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003314 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003315 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003316 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3317 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003318 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3319 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003320 vc_conn.done;
3321 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003323}
Harald Welte685d5982018-02-27 20:42:05 +01003324testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3325 var ConnHdlr vc_conn;
3326 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003327 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003328 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3329 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003330 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003331 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003332 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3333 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003334 vc_conn.done;
3335 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003337}
3338
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003339/* Make sure that we always get RSL MEASurement RESult messages regardless
3340 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3341private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3342 timer Texec := 8.0;
3343 timer Timpf := 2.0;
3344 timer Tmr;
3345
3346 f_l1_tune(L1CTL);
3347 RSL.clear;
3348
3349 f_est_dchan();
3350 L1CTL.clear;
3351
3352 /* Establish the main SAPI=0 link on DCCH first */
3353 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3354
3355 /* Give more time for the first RSL MEASurement RESult */
3356 Tmr.start(0.480 * 2.0);
3357 Texec.start; /* EXECution timer */
3358 Timpf.start; /* IMPFung timer */
3359
3360 alt {
3361 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3362 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3363 /* Reschedule the MEAS RES timer */
3364 Tmr.start(0.480 + 0.120);
3365 repeat;
3366 }
3367 [] RSL.receive { repeat; }
3368 [] Tmr.timeout {
3369 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3370 }
3371 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3372 [] Timpf.timeout {
3373 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3374 log("Injected SAPI=3 traffic on SACCH");
3375 Timpf.start;
3376 repeat;
3377 }
3378 /* We're good if survived so far */
3379 [] Texec.timeout {
3380 setverdict(pass);
3381 }
3382 }
3383
3384 f_rsl_chan_deact();
3385 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3386 f_rslem_unregister(0, g_chan_nr);
3387}
3388testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3389 var template RSL_IE_ChannelMode ch_mode;
3390 var template ConnHdlrPars pars;
3391 var ConnHdlr vc_conn;
3392
3393 f_init();
3394
3395 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3396 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3397
3398 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3399 vc_conn.done;
3400
3401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3402}
3403testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3404 var template RSL_IE_ChannelMode ch_mode;
3405 var template ConnHdlrPars pars;
3406 var ConnHdlr vc_conn;
3407
3408 f_init();
3409
3410 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3411 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3412
3413 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3414 vc_conn.done;
3415
3416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3417}
3418
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003419/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3420 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003421private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003422 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003423 var RSL_IE_MS_Power ms_power;
3424 var RSL_Message rsl;
3425 var uint5_t power_level := 0;
3426
3427 f_l1_tune(L1CTL);
3428 RSL.clear;
3429
3430 f_est_dchan();
3431
3432 ms_power.reserved := 0;
3433 ms_power.fpc_epc := false;
3434
3435 /* Send the first power control command. This will disable any BTS/TRX
3436 * internal power control and switch the MS (which is not in scope of
3437 * this test) to a constant power level. We start with a power level
3438 * of 0 */
3439 ms_power.power_level := power_level;
3440 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3441 RSL.send(rsl);
3442
3443 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003444 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3445 if (l1h.ms_power_lvl != power_level) {
3446 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3447 "match the signaled (RSL) power level := ", power_level);
3448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003449 }
3450
3451 /* Signal a new power level via RSL for the next turn. */
3452 if (power_level < 31) {
3453 power_level := power_level + 1;
3454 ms_power.power_level := power_level;
3455 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3456 RSL.send(rsl);
3457 repeat;
3458 }
3459
3460 }
3461
3462 /* Ignore all other blocks */
3463 [] L1CTL.receive { repeat; }
3464
3465 }
3466
3467 f_rsl_chan_deact();
3468 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3469
3470 setverdict(pass);
3471}
3472
3473testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3474 var ConnHdlr vc_conn;
3475 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003476 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003477
3478 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3479 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3480 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3481 vc_conn.done;
3482 }
3483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3484}
Harald Welte70767382018-02-21 12:16:40 +01003485
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003486/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003487TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003488private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003489 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003490 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003491
3492 f_l1_tune(L1CTL);
3493 RSL.clear;
3494
3495 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003496 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003497
3498 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3499
3500
3501 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003502 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3503 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003504 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3505 }
3506
3507 }
3508
3509 /* Ignore all other blocks */
3510 [] L1CTL.receive { repeat; }
3511
3512 }
3513
3514 f_rsl_chan_deact();
3515 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3516
3517 setverdict(pass);
3518}
3519
3520testcase TC_rsl_chan_initial_ta() runs on test_CT {
3521 var ConnHdlr vc_conn;
3522 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003523 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003524 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003525 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3526 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003527 vc_conn.done;
3528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3529}
3530
Eric Wilde57e1a62019-05-28 13:30:55 +02003531/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003532private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003533 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003534 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003535
3536 var RSL_IE_MS_Power ms_power;
3537 ms_power.reserved := 0;
3538 ms_power.fpc_epc := false;
3539 ms_power.power_level := ms_power_level;
3540
3541 f_l1_tune(L1CTL);
3542 RSL.clear;
3543
3544 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3545
3546 timer T := 1.0;
3547 T.start;
3548 alt {
3549 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003550 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3551 if (l1h.ms_power_lvl != ms_power_level) {
3552 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3553 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003554 }
3555 }
3556 /* Ignore all other blocks */
3557 [] L1CTL.receive { repeat; }
3558 [] T.timeout {
3559 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3560 }
3561 }
3562
3563 f_rsl_chan_deact();
3564 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3565 setverdict(pass);
3566}
3567
3568testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3569 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3570 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3571}
3572
Harald Welte0472ab42018-03-12 15:02:26 +01003573/* 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 +01003574private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003575 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003576 RSL.clear;
3577
3578 f_est_dchan();
3579 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003580 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003581
3582 timer T := 40.0;
3583 T.start;
3584 alt {
3585 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3586 setverdict(pass)
3587 }
3588 [] RSL.receive { repeat };
3589 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003591 }
3592 }
3593 f_rsl_chan_deact();
3594}
3595testcase TC_conn_fail_crit() runs on test_CT {
3596 var ConnHdlr vc_conn;
3597 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003598 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003599 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3600 pars.t_guard := 60.0;
3601 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3602 vc_conn.done;
3603}
3604
Harald Welte93640c62018-02-25 16:59:33 +01003605/***********************************************************************
3606 * Paging
3607 ***********************************************************************/
3608
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003609private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003610 if (tmsi == 'FFFFFFFF'O) {
3611 return true;
3612 } else {
3613 return false;
3614 }
3615}
Harald Welte70767382018-02-21 12:16:40 +01003616
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003617private type record allowedFn { integer frame_nr }
3618private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3619private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3620private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3621private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3622private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3623private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3624private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3625private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3626private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003627{
3628 var integer frame_nr_51;
3629 frame_nr_51 := frame_nr mod 51
3630
3631 var allowedFn fn_check;
3632 fn_check.frame_nr := frame_nr_51;
3633
3634 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003636 return;
3637 }
3638
3639 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3640 return;
3641 }
3642 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3643 return;
3644 }
3645 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3646 return;
3647 }
3648 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3649 return;
3650 }
3651 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3652 return;
3653 }
3654 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3655 return;
3656 }
3657 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3658 return;
3659 }
3660 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3661 return;
3662 }
3663
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003665 return;
3666}
3667
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003668private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3669 inout integer num_paging_rcv_ids,
3670 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003671runs on test_CT {
3672 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003673 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003674 repeat;
3675 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003676 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003677 var octetstring without_plen :=
3678 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3679 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003680
3681 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3682
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003683 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3684 /* Ignore empty RR Paging Request (PCH filling) messages.
3685 * TODO: does it make sense to count them? */
3686 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003687 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3688 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003689 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003690 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3691 }
3692 } else if (match(rr, tr_PAGING_REQ2)) {
3693 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3694 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3695 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3696 }
3697 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3698 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3699 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003700 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003701 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3702 }
3703 } else if (match(rr, tr_PAGING_REQ3)) {
3704 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3705 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3706 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3707 }
3708 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3709 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3710 }
3711 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3712 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3713 }
3714 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3715 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3716 }
3717 }
3718 repeat;
3719 }
3720}
3721
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003722private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003723 boolean combined_ccch,
3724 integer bs_ag_blks_res,
3725 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003726 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3727 * paging command that is issued via RSL. */
3728 integer ps_load_modulus,
3729 /* Wait until the paging queue inside the BTS is congested before starting to add
3730 * pagings via the PCU socket (0 = disabled) */
3731 boolean ps_wait_cong,
3732 /* Maximum time to wait until the paging queue is drained at the end of the test.
3733 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3734 * to set this value to 18s, however the draining process may take significantly
3735 * longer when the queue contains paging requests for PS as those are implemented
3736 * as immediate assignments and require an entire MAC block alone. */
3737 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003738 boolean exp_load_ind,
3739 boolean exp_overload,
3740 boolean use_tmsi
3741}
3742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003743private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003744 integer num_paging_sent,
3745 integer num_paging_rcv_msgs,
3746 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003747 integer num_overload,
3748 /* When free space inside the paging queue reaches more than 2 thirds
3749 * of its capacity cong_detected is set to true. */
3750 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003751}
3752
Harald Welte68e495b2018-02-25 00:05:57 +01003753/* Helper function for paging related testing */
3754private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003755 /* Using the PCU socket affects the timing of the paging processing. We only
3756 * activate the PCU socket if we do paging load tests that include additional
3757 * paging load that is introduced through the PCU socket. */
3758 if (cfg.ps_load_modulus > 0) {
3759 f_init_with_pcuif();
3760 } else {
3761 f_init();
3762 }
Harald Welte68e495b2018-02-25 00:05:57 +01003763 f_init_l1ctl();
3764 f_l1_tune(L1CTL);
3765
Philipp Maierca058272021-06-23 10:35:23 +02003766 var octetstring imm_ass := f_rnd_octstring(23);
3767 var ASP_RSL_Unitdata load_ind;
3768
Harald Welte68e495b2018-02-25 00:05:57 +01003769 var PagingTestState st := {
3770 num_paging_sent := 0,
3771 num_paging_rcv_msgs := 0,
3772 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003773 num_overload := 0,
3774 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003775 };
3776
3777 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3778 var float max_pch_imsi_per_sec;
3779 if (cfg.use_tmsi) {
3780 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3781 } else {
3782 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3783 }
3784 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3785 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003786 var float time_total := 20.0;
3787 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3788 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003789
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003790 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3791 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003792
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003793 timer T_itv := 0.0;
3794 T_itv.start;
3795 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003796 alt {
3797 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003798 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003799 st.num_overload := st.num_overload + 1;
3800 repeat;
3801 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003802 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003804 }
Philipp Maierca058272021-06-23 10:35:23 +02003805 [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 +01003806 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003807
3808 /* Detect paging congestion: The logic inside the BTS will diagnose the
3809 * paging queue as congested when the fill state is more than 66% (which
3810 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3811 * paging congestion is detected pagings that are issued through the PCU
3812 * socket (PS) are dropped in order to prefer the CS related pagings. */
3813 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3814 st.cong_detected := true;
3815 }
3816
Harald Welte68e495b2018-02-25 00:05:57 +01003817 /* FIXME: analyze/verify interval + contents */
3818 repeat;
3819 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003820 /* ignore other RSL messages like RF RESource INDication */
3821 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003822 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003823 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003824 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003825 /* Only relevant when testing including with PCU sock connected */
3826 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003827 [] T_itv.timeout {
3828 /* Send paging cmds based on elapsed time */
3829 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3830 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003831 var MobileIdentityV mi;
3832
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003833 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003834 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003835 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003836 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003837 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003838 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003839
3840 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003841 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 +02003842
Philipp Maierca058272021-06-23 10:35:23 +02003843 /* Add additional pagings through the PCU socket interface. */
3844 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3845 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3846 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3847 }
3848 }
3849
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003850 st.num_paging_sent := st.num_paging_sent + 1;
3851 }
3852 if (st.num_paging_sent < pkt_total) {
3853 /* Wait for interval to next PAGING COMMAND */
3854 var float time_now := T_total.read;
3855 var float next_sched := int2float(st.num_paging_sent)*interval;
3856 if (next_sched > time_now) {
3857 T_itv.start(next_sched - time_now);
3858 } else {
3859 T_itv.start(0.0);
3860 }
3861 } else {
3862 /* We are done, no need to keep counting */
3863 T_total.stop;
3864 }
3865 }
3866 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003867 }
3868 }
3869
Philipp Maierca058272021-06-23 10:35:23 +02003870 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003871 T_wait.start;
3872 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003873 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003874 [] L1CTL.receive { repeat; }
3875 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003876 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003877 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003878 /* ignore other RSL messages like RF RESource INDication */
3879 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003880 /* Only relevant when testing including with PCU sock connected */
3881 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003882 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003883 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 +01003884 }
Harald Welte68e495b2018-02-25 00:05:57 +01003885 }
3886
3887 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3888 " rcvd_ids=", st.num_paging_rcv_ids);
3889 return st;
3890}
3891
3892/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3893 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3894 * - that CCCH LOAD IND (PCH) are being generated
3895 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3896testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003897 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003898 var PagingTestCfg cfg := {
3899 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003900 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003901 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003902 ps_load_modulus := 0,
3903 ps_wait_cong := false,
3904 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003905 exp_load_ind := true,
3906 exp_overload := false,
3907 use_tmsi := false
3908 };
3909 var PagingTestState st := f_TC_paging(cfg);
3910 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3912 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003913 } else {
3914 setverdict(pass);
3915 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003917}
3918
3919/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3920 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3921 * - that CCCH LOAD IND (PCH) are being generated
3922 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3923testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003924 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003925 var PagingTestCfg cfg := {
3926 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003927 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003928 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003929 ps_load_modulus := 0,
3930 ps_wait_cong := false,
3931 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003932 exp_load_ind := true,
3933 exp_overload := false,
3934 use_tmsi := true
3935 };
3936 var PagingTestState st := f_TC_paging(cfg);
3937 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3939 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003940 } else {
3941 setverdict(pass);
3942 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003944}
3945
3946/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3947 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3948 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3949 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3950testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003951 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003952 var PagingTestCfg cfg := {
3953 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003954 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003955 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003956 ps_load_modulus := 0,
3957 ps_wait_cong := false,
3958 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003959 exp_load_ind := true,
3960 exp_overload := true,
3961 use_tmsi := false
3962 };
3963 var PagingTestState st := f_TC_paging(cfg);
3964 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3965 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003966 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003967 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003968 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 +01003969 } else {
3970 setverdict(pass);
3971 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003973}
3974
3975/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3976 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3977 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3978 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3979testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003980 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003981 var PagingTestCfg cfg := {
3982 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003983 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003984 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003985 ps_load_modulus := 0,
3986 ps_wait_cong := false,
3987 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003988 exp_load_ind := true,
3989 exp_overload := true,
3990 use_tmsi := true
3991 };
3992 var PagingTestState st := f_TC_paging(cfg);
3993 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3994 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003995 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003996 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003997 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 +01003998 } else {
3999 setverdict(pass);
4000 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004002}
4003
Philipp Maierca058272021-06-23 10:35:23 +02004004/* Same as above, but with additional paging load created by PS pagings that
4005 * are issued through the PCU socket. The additional load is introduced when
4006 * the paging queue is already two thirds full. Since the BTS implements a
4007 * prioritization logic that drops the pagings from the PCU under in those
4008 * congestive sitautions the behaviour on the PS side is expected to be
4009 * unaffected and match the behavior of TC_paging_imsi_200percent() */
4010testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
4011 var SystemInformation si3 := valueof(ts_SI3_default);
4012 var PagingTestCfg cfg := {
4013 combined_ccch := true,
4014 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
4015 load_factor := 2.0,
4016 ps_load_modulus := 16,
4017 ps_wait_cong := true,
4018 queue_drain_timeout := 18.0,
4019 exp_load_ind := true,
4020 exp_overload := true,
4021 use_tmsi := false
4022 };
4023 var PagingTestState st := f_TC_paging(cfg);
4024 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
4025 * slots and will fully drain that buffer before returning */
4026 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
4027 if (not match(st.num_paging_rcv_ids, tpl)) {
4028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
4029 } else {
4030 setverdict(pass);
4031 }
4032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4033}
4034
4035
Harald Welte68e495b2018-02-25 00:05:57 +01004036
Harald Welte93640c62018-02-25 16:59:33 +01004037/***********************************************************************
4038 * Immediate Assignment / AGCH
4039 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004040private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004041 len := 0,
4042 ma := ''B
4043}
Harald Welte93640c62018-02-25 16:59:33 +01004044
Harald Weltee8d750e2018-06-10 21:41:35 +02004045private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4046 return int2str(num_tx) & " sent, "
4047 & int2str(num_rx) & " received, "
4048 & int2str(num_del) & " deleted";
4049}
4050
4051private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4052 var L1ctlDlMessage l1_dl;
4053 timer T := 10.0;
4054 var integer num_tx := 0;
4055 var integer num_rx := 0;
4056 var integer num_del := 0;
4057 var charstring res_str;
4058 var float rx_ratio;
4059
Harald Welte10474062019-05-30 16:48:17 +02004060 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004061 f_init_l1ctl();
4062 f_l1_tune(L1CTL);
4063
4064 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004065 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004066 mp_trx_pars[0].arfcn,
4067 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004068 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4069 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004070 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004071 num_tx := num_tx+1;
4072 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004073 }
4074 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004075 T.start;
4076 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004077 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004078 num_del := num_del+1;
4079 repeat;
4080 }
4081 [] RSL_CCHAN.receive {
4082 repeat;
4083 }
4084 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004085 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4086 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4087 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004088 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004089 } else {
4090 num_rx := num_rx+1;
4091 }
4092 repeat;
4093 }
4094 [] L1CTL.receive { repeat; }
4095 [] T.timeout { }
4096 }
4097 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4098 log("AGCH test: " & res_str);
4099 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004101 }
4102 rx_ratio := int2float(num_rx) / int2float(num_tx);
4103 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 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 +02004105 } else {
4106 setverdict(pass);
4107 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004109}
4110
Harald Weltee8d750e2018-06-10 21:41:35 +02004111/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4112testcase TC_imm_ass_1000_20ms() runs on test_CT {
4113 f_TC_imm_ass(1000, 0.02, 0.25);
4114}
4115
4116/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4117testcase TC_imm_ass_200_0ms() runs on test_CT {
4118 f_TC_imm_ass(200, 0.0, 0.05);
4119}
4120
4121/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4122testcase TC_imm_ass_200_76ms() runs on test_CT {
4123 f_TC_imm_ass(150, 0.076, 1.00);
4124}
4125
4126
4127
Harald Welte48494ca2018-02-25 16:59:50 +01004128/***********************************************************************
4129 * BCCH
4130 ***********************************************************************/
4131
4132/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004133private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004134 GsmFrameNumber frame_number,
4135 SystemInformation si
4136}
4137
4138/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004139private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004140
4141/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004142private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004143
4144/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004145private function f_si_vecslot_contains(SystemInformationVector arr,
4146 RrMessageType key,
4147 boolean bcch_ext := false)
4148return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004149 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4150 var integer fn_mod51 := arr[i].frame_number mod 51;
4151 if (not bcch_ext and fn_mod51 == 2 or
4152 bcch_ext and fn_mod51 == 6) {
4153 if (arr[i].si.header.message_type == key) {
4154 return true;
4155 }
4156 }
4157 }
4158 return false;
4159}
4160
4161/* 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 +07004162private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4163 integer tc, RrMessageType key,
4164 boolean ext_bcch := false)
4165{
Harald Welte48494ca2018-02-25 16:59:50 +01004166 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004168 }
4169}
4170
4171/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004172private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4173 RrMessageType key)
4174return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004175 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4176 if (f_si_vecslot_contains(arr[tc], key) or
4177 f_si_vecslot_contains(arr[tc], key, true)) {
4178 return true;
4179 }
4180 }
4181 return false;
4182}
4183
4184/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004185private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4186 RrMessageType key,
4187 boolean bcch_ext := false,
4188 integer n := 1, integer m := 4)
4189return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004190 var integer count := 0;
4191 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4193 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004194 }
4195 for (var integer i:= 0; i < m; i := i + 1) {
4196 var integer fn_mod51 := arr[i].frame_number mod 51;
4197 if (not bcch_ext and fn_mod51 == 2 or
4198 bcch_ext and fn_mod51 == 6) {
4199 if (arr[i].si.header.message_type == key) {
4200 count := count + 1;
4201 }
4202 }
4203 }
4204 if (count >= n) {
4205 return true;
4206 } else {
4207 return false;
4208 }
4209}
4210
4211/* 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 +07004212private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4213 integer tc, RrMessageType key,
4214 boolean ext_bcch := false,
4215 integer n, integer m)
4216{
Harald Welte48494ca2018-02-25 16:59:50 +01004217 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004219 }
4220}
4221
4222/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004223private function f_si_vecslot_contains_only(SystemInformationVector arr,
4224 RrMessageType key,
4225 boolean bcch_ext := false)
4226return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004227 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4228 var integer fn_mod51 := arr[i].frame_number mod 51;
4229 if (not bcch_ext and fn_mod51 == 2 or
4230 bcch_ext and fn_mod51 == 6) {
4231 if (arr[i].si.header.message_type != key) {
4232 return false;
4233 }
4234 }
4235 }
4236 return true;
4237}
4238
4239/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004240private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4241 integer tc, RrMessageType key,
4242 boolean ext_bcch := false)
4243{
Harald Welte48494ca2018-02-25 16:59:50 +01004244 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004246 }
4247}
4248
4249/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004250private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004251 boolean bcch_extended,
4252 boolean si1_present,
4253 boolean si2bis_present,
4254 boolean si2ter_present,
4255 boolean si2quater_present,
4256 boolean si7_present,
4257 boolean si8_present,
4258 boolean si9_present,
4259 boolean si13_present,
4260 boolean si13alt_present,
4261 boolean si15_present,
4262 boolean si16_present,
4263 boolean si17_present,
4264 boolean si2n_present,
4265 boolean si21_present,
4266 boolean si22_present
4267}
4268
4269/* 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 +07004270private function f_validate_si_scheduling(SystemInformationConfig cfg,
4271 SystemInformationVectorPerTc si_per_tc)
4272{
Harald Welte48494ca2018-02-25 16:59:50 +01004273 var integer i;
4274 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4275 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004277 }
4278 }
4279 if (cfg.si1_present) {
4280 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4281 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4282 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4283 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4284 /* make sure *ALL* contain SI1 */
4285 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4286 }
4287 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4288 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4289 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4290 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4291 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4292 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4293
4294 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4295 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4296 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4297 * consecutive occurrences of TC = 4. */
4298 if (cfg.si2bis_present and not cfg.si2ter_present) {
4299 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4300 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4301 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4302 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4303 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4304 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4305 }
4306
4307 if (cfg.si7_present or cfg.si8_present) {
4308 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4309 * if System Information type 4 does not contain all information needed for cell
4310 * selection and reselection. */
4311 if (not cfg.bcch_extended) {
4312 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4313 }
4314 if (cfg.si7_present) {
4315 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4316 }
4317 if (cfg.si8_present) {
4318 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4319 }
4320 }
4321
4322 if (cfg.si2quater_present) {
4323 /* iii) System information type 2 quater is sent if needed, as determined by the system
4324 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4325 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4326 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4327 * within any of 4 consecutive occurrences of TC = 5. */
4328 if (not (cfg.bcch_extended)) {
4329 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4330 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4331 } else {
4332 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4333 }
4334 } else {
4335 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4336 }
4337 }
4338 if (cfg.si9_present) {
4339 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4340 * in system information type 3 as defined in 3GPP TS 44.018. */
4341 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4342 }
4343 if (cfg.si13_present) {
4344 /* vii) System Information type 13 is only related to the GPRS service. System Information
4345 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4346 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4347 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4348 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4349 * within any of 4 consecutive occurrences of TC=4. */
4350 if (not cfg.bcch_extended) {
4351 log("not-bccch-extended");
4352 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4353 } else {
4354 log("bccch-extended");
4355 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4356 }
4357 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004359 }
4360 }
4361 if (cfg.si16_present or cfg.si17_present) {
4362 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4363 * should not be sent in a cell where network sharing is used (see rule xv). */
4364 if (cfg.si22_present) {
4365 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4366 }
4367 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004369 }
4370 if (not cfg.bcch_extended) {
4371 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4372 }
4373 if (cfg.si16_present) {
4374 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4375 }
4376 if (cfg.si17_present) {
4377 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4378 }
4379 }
4380
4381 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4382 * broadcast information. The frequency with which they are sent is determined by the
4383 * system operator. System Information type 9 identifies the scheduling of System
4384 * Information type 18 and 20 messages. */
4385
4386 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4387 * Information Type 19 is present, then its scheduling shall be indicated in System
4388 * Information Type 9. */
4389
4390 if (cfg.si15_present) {
4391 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4392 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4393 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4394 * 4 consecutive occurrences of TC = 1. */
4395 if (not cfg.bcch_extended) {
4396 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4397 } else {
4398 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4399 }
4400 }
4401 if (cfg.si13alt_present) {
4402 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4403 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4404 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4405 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4406 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4407 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4408 * of TC = 4. */
4409 if (cfg.si13_present) {
4410 testcase.stop("Error: Cannot have SI13alt and SI13");
4411 }
4412 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004414 }
4415 if (not cfg.bcch_extended) {
4416 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4417 } else {
4418 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4419 }
4420 }
4421 if (cfg.si2n_present) {
4422 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4423 * as determined by the system operator. In the case that the message is sent on the
4424 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4425 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4426 * consecutive occurrences of TC = 4. */
4427 if (not cfg.bcch_extended) {
4428 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4429 } else {
4430 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4431 }
4432 }
4433 if (cfg.si21_present) {
4434 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4435 * determined by the system operator. If Extended Access Barring is in use in the cell
4436 * then this message is sent at least once within any of 4 consecutive occurrences of
4437 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4438 * cell then this message shall only be sent on BCCH Ext. */
4439 if (not cfg.bcch_extended) {
4440 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4441 } else {
4442 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4443 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004445 }
4446 }
4447 }
4448 if (cfg.si22_present) {
4449 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4450 * should not be sent in a cell where SoLSA is used (see rule viii). System
4451 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4452 * =2 and TC=6. */
4453 if (cfg.si16_present or cfg.si17_present) {
4454 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4455 }
4456 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4457 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004459 }
4460 if (not cfg.bcch_extended) {
4461 testcase.stop("Error: SI22 requires BCCH Extd!");
4462 } else {
4463 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4464 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4465 }
4466 }
4467}
4468
4469/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004470private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4471return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004472 timer T := duration;
4473 var SystemInformationVectorPerTc si_per_tc;
4474 var L1ctlDlMessage l1_dl;
4475
4476 /* initialize all per-TC vectors empty */
4477 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4478 si_per_tc[i] := {};
4479 }
4480
4481 /* flush all previous L1 queued msgs */
4482 pt.clear;
4483
4484 T.start;
4485 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004486 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004487 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4488 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4489 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004490 repeat;
4491 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004492
Harald Welte48494ca2018-02-25 16:59:50 +01004493 var integer tc := f_gsm_compute_tc(sig.frame_number);
4494 log("SI received at TC=", tc, ": ", sig.si);
4495 /* append to the per-TC bucket */
4496 si_per_tc[tc] := si_per_tc[tc] & { sig };
4497 repeat;
4498 }
4499 [] pt.receive { repeat; }
4500 [] T.timeout { }
4501 }
4502
4503 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4504 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4505 }
4506 log("si_per_tc=", si_per_tc);
4507 return si_per_tc;
4508}
4509
4510/* helper function: Set given SI via RSL + validate scheduling.
4511 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004512private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004513 var SystemInformationVectorPerTc si_per_tc;
4514 f_init_l1ctl();
4515 f_l1_tune(L1CTL);
4516
4517 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004518 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004519 f_validate_si_scheduling(si_cfg, si_per_tc);
4520
4521 setverdict(pass);
4522}
4523
4524testcase TC_si_sched_default() runs on test_CT {
4525 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004526 /* 2+3+4 are mandatory and set in f_init() */
4527 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004529}
4530
4531testcase TC_si_sched_1() runs on test_CT {
4532 f_init();
4533 si_cfg.si1_present := true;
4534 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004535 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004537}
4538
4539testcase TC_si_sched_2bis() runs on test_CT {
4540 f_init();
4541 si_cfg.si2bis_present := true;
4542 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4543 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_2ter() runs on test_CT {
4548 f_init();
4549 si_cfg.si2ter_present := true;
4550 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'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_2bis() runs on test_CT {
4556 f_init();
4557 si_cfg.si2bis_present := true;
4558 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4559 si_cfg.si2ter_present := true;
4560 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4561 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004562 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004563}
4564
4565testcase TC_si_sched_2quater() runs on test_CT {
4566 f_init();
4567 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004568 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004569 f_TC_si_sched(16.0);
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_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004574 /* NOTE: PCUIF connection is not used in this test case, but
4575 * without it the IUT would not broadcast SI13 (see OS#3075). */
4576 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004577 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004578 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004579 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004581}
4582
4583testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004584 /* NOTE: PCUIF connection is not used in this test case, but
4585 * without it the IUT would not broadcast SI13 (see OS#3075). */
4586 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004587 si_cfg.si2bis_present := true;
4588 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4589 si_cfg.si2ter_present := true;
4590 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4591 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004592 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004593 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004594 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004595 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004597}
4598
4599
Harald Welte68e495b2018-02-25 00:05:57 +01004600testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004601 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004602 /* FIXME: enable / disable individual BCCH info */
4603 //ts_RSL_BCCH_INFO(si_type, info);
4604 /* expect no ERROR REPORT after either of them *
4605 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004607}
4608
Harald Welte93640c62018-02-25 16:59:33 +01004609/***********************************************************************
4610 * Low-Level Protocol Errors / ERROR REPORT
4611 ***********************************************************************/
4612
Harald Welte01d982c2018-02-25 01:31:40 +01004613private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4614 timer T := 5.0;
4615 T.start;
4616 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004618 setverdict(pass);
4619 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004620 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004622 }
4623 [] RSL_CCHAN.receive {
4624 repeat;
4625 }
4626 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004628 }
4629 }
4630}
4631
4632/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4633testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004634 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004635 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4636 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004637 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004638
4639 f_exp_err_rep(RSL_ERR_PROTO);
4640}
4641
4642/* Provoke a mandatory IE error and match on ERROR REPORT */
4643testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004644 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004645
4646 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4647 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004648 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004649
4650 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4651}
4652
4653/* Provoke an IE content error and match on ERROR REPORT */
4654testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004655 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004656 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4657 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004658 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004659
4660 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4661}
4662
Harald Welteee25aae2019-05-19 14:32:37 +02004663/* attempt to activate channel with wrong RSL Message Discriminator IE */
4664function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4665 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4666 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4667 RSL.send(rsl);
4668 f_rslem_unregister(0, g_chan_nr);
4669}
4670testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4671 var ConnHdlr vc_conn;
4672 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4673
Harald Welte10474062019-05-30 16:48:17 +02004674 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004675
4676 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4677 vc_conn.done;
4678 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4679
4680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4681}
4682
4683/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004684private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004685 var template (value) RSL_Message rsl_tx;
4686 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4687 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4688 RSL.send(rsl_tx);
4689 f_rslem_unregister(0, g_chan_nr);
4690}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004691private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004692 var template (value) RSL_Message rsl_tx;
4693 /* we first have to activate the dedicated channel */
4694 f_rsl_chan_act(g_pars.chan_mode);
4695 /* ... to then send an invalid RLL message */
4696 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4697 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4698 RSL.send(rsl_tx);
4699 f_rslem_unregister(0, g_chan_nr);
4700}
4701testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4702 var ConnHdlr vc_conn;
4703 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4704 var template (value) RSL_Message rsl_tx;
4705
Harald Welte10474062019-05-30 16:48:17 +02004706 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004707
4708 /* Common Channel with wrong message type */
4709 RSL_CCHAN.clear;
4710 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4711 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004712 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004713 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4714
4715 /* TRX Management */
4716 RSL_CCHAN.clear;
4717 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4718 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004719 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004720 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4721
4722 /* Dedicated Channel */
4723 RSL_CCHAN.clear;
4724 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4725 vc_conn.done;
4726 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4727
4728 /* RLL */
4729 RSL_CCHAN.clear;
4730 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4731 vc_conn.done;
4732 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4733}
4734
4735/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004736private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004737 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4738 f_rslem_unregister(0, g_chan_nr);
4739}
4740testcase TC_err_rep_wrong_sequence() runs on test_CT {
4741 var ConnHdlr vc_conn;
4742 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4743
Harald Welte10474062019-05-30 16:48:17 +02004744 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004745
4746 RSL_CCHAN.clear;
4747 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4748 vc_conn.done;
4749 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4750}
4751
Harald Welte93640c62018-02-25 16:59:33 +01004752/***********************************************************************
4753 * IPA CRCX/MDCX/DLCS media stream handling
4754 ***********************************************************************/
4755
Harald Weltea871a382018-02-25 02:03:14 +01004756/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004757private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004758 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4759 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004760}
4761testcase TC_ipa_dlcx_not_active() runs on test_CT {
4762 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004763 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004764 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4765 vc_conn.done;
4766}
Harald Welte68e495b2018-02-25 00:05:57 +01004767
Harald Weltea3f1df92018-02-25 12:49:55 +01004768/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004769private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004770 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4771 "IPA CRCX ACK");
4772 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4773 "IPA CRCX NACK");
4774}
4775testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4776 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004777 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004778 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4779 vc_conn.done;
4780}
4781
4782/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004783private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004784 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4785 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004786 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004787 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4788 var uint7_t rtp_pt2 := f_rnd_int(127);
4789 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4790 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4791 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4792 "IPA MDCX ACK");
4793 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4794 "IPA DLCX ACK");
4795}
4796testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4797 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004798 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004799 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4800 vc_conn.done;
4801}
4802
Harald Welte3ae11da2018-02-25 13:36:06 +01004803/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004804private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004805 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4806 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004807 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004808 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4809 var uint7_t rtp_pt2 := f_rnd_int(127);
4810 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4811 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4812 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4813 "IPA MDCX ACK");
4814 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004815 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004816 remote_port := f_rnd_int(c_UINT16_MAX);
4817 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4818 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4819 "IPA MDCX ACK");
4820 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4821 "IPA DLCX ACK");
4822}
4823testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4824 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004825 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004826 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4827 vc_conn.done;
4828}
4829
Harald Welte9912eb52018-02-25 13:30:15 +01004830/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004831private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004832 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4833 "IPA CRCX NACK");
4834}
4835testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4836 var ConnHdlrPars pars;
4837 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004838 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004839
4840 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4841 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4842 vc_conn.done;
4843
4844 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4845 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4846 vc_conn.done;
4847}
4848
Harald Weltea3f1df92018-02-25 12:49:55 +01004849
Harald Welte883340c2018-02-28 18:59:29 +01004850/***********************************************************************
4851 * PCU Socket related tests
4852 ***********************************************************************/
4853
Harald Welte07bd2d22019-05-25 11:03:30 +02004854/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004855friend 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 +01004856runs on test_CT {
4857 timer T := 3.0;
4858
4859 /* we don't expect any RTS.req before PDCH are active */
4860 T.start;
4861 alt {
4862 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004863 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004864 }
4865 [] PCU.receive { repeat; }
4866 [] T.timeout { }
4867 }
4868
4869 /* Send PDCH activate request for known PDCH timeslot */
4870 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4871
4872 /* we now expect RTS.req for this timeslot (only) */
4873 T.start;
4874 alt {
4875 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4876 setverdict(pass);
4877 }
4878 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4879 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004881 }
4882 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004884 }
4885 [] PCU.receive { repeat; }
4886 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004888 }
4889 [not exp_success] T.timeout {
4890 setverdict(pass);
4891 }
4892 }
4893}
4894
Harald Welte07bd2d22019-05-25 11:03:30 +02004895/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004896friend 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 +01004897runs on test_CT {
4898 timer T := 3.0;
4899
4900 /* Send PDCH activate request for known PDCH timeslot */
4901 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 +02004902 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4903 * when it will actually have been executed in the BTS */
4904 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004905 PCU.clear;
4906 /* we now expect no RTS.req for this timeslot */
4907 T.start;
4908 alt {
4909 [] 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 +02004910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004911 }
4912 [] PCU.receive { repeat; }
4913 [] T.timeout {
4914 setverdict(pass);
4915 }
4916 }
4917}
4918
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004919friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004920 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004921 map(self:PCU, system:PCU);
4922 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004923 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4924}
4925
Harald Welte883340c2018-02-28 18:59:29 +01004926/* PDCH activation via PCU socket; check for presence of RTS.req */
4927testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004928 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004929
Harald Welte883340c2018-02-28 18:59:29 +01004930 f_TC_pcu_act_req(0, 0, 7, true);
4931}
4932
4933/* PDCH activation via PCU socket on non-PDCU timeslot */
4934testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004935 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004936
Harald Welte883340c2018-02-28 18:59:29 +01004937 f_TC_pcu_act_req(0, 0, 1, false);
4938}
4939
4940/* PDCH activation via PCU socket on wrong BTS */
4941testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004942 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004943
Harald Welte883340c2018-02-28 18:59:29 +01004944 f_TC_pcu_act_req(23, 0, 7, false);
4945}
4946
4947/* PDCH activation via PCU socket on wrong TRX */
4948testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004949 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004950
Harald Welte883340c2018-02-28 18:59:29 +01004951 f_TC_pcu_act_req(0, 23, 7, false);
4952}
4953
4954/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4955testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004956 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004957
Harald Welte883340c2018-02-28 18:59:29 +01004958 /* Activate PDCH */
4959 f_TC_pcu_act_req(0, 0, 7, true);
4960 f_sleep(1.0);
4961 /* and De-Activate again */
4962 f_TC_pcu_deact_req(0, 0, 7);
4963}
4964
4965/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4966testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004967 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004968
Harald Welte883340c2018-02-28 18:59:29 +01004969 f_TC_pcu_deact_req(0, 0, 1);
4970}
4971
4972/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004973function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004974 var PCUIF_send_data sd;
4975 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004976 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004977
4978 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004979 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004980
Harald Welte883340c2018-02-28 18:59:29 +01004981 T.start;
4982 alt {
4983 [] 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 +01004984 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004985 setverdict(pass);
4986 } else {
4987 repeat;
4988 }
4989 }
4990 [] PCU.receive { repeat; }
4991 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004993 }
4994 }
4995}
4996
Philipp Maier94c08482021-02-01 17:36:05 +01004997/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4998testcase TC_pcu_ver_si1() runs on test_CT {
4999 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
5000 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
5001}
5002
5003/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
5004testcase TC_pcu_ver_si3() runs on test_CT {
5005 const octetstring si3 := '49012223242526272929AABBCC'O;
5006 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
5007}
5008
5009/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
5010testcase TC_pcu_ver_si13() runs on test_CT {
5011 const octetstring si13 := '01010203040506070909'O;
5012 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
5013}
5014
Harald Welte883340c2018-02-28 18:59:29 +01005015private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
5016
5017/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02005018friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01005019 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
5020runs on test_CT
5021{
5022 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
5023 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
5024}
5025
5026/* 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 +02005027friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
5028 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01005029runs on test_CT
5030{
5031 var PCUIF_send_data sd;
5032
5033 timer T := 3.0;
5034 T.start;
5035 alt {
5036 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
5037 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
5038 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
5039 sd.data.u.rts_req.fn, sapi, data);
5040 }
5041 [] PCU.receive { repeat; }
5042 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005044 }
5045 }
5046}
5047
5048/* Send DATA.req on invalid BTS */
5049testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005050 var TfiUsfArr tua := f_TfiUsfArrInit();
5051 var octetstring data := '0000'O & f_rnd_octstring(21);
5052
5053 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005054
Harald Welte883340c2018-02-28 18:59:29 +01005055 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005056 f_TfiUsfArrSet(tua, 7, 0);
5057 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5058 f_sleep(1.0);
5059
5060 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005061}
5062
5063/* Send DATA.req on invalid TRX */
5064testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005065 var TfiUsfArr tua := f_TfiUsfArrInit();
5066 var octetstring data := '0000'O & f_rnd_octstring(21);
5067
5068 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005069
Harald Welte883340c2018-02-28 18:59:29 +01005070 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005071 f_TfiUsfArrSet(tua, 7, 0);
5072 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5073 f_sleep(1.0);
5074
5075 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005076}
5077
5078/* Send DATA.req on invalid timeslot */
5079testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005080 var TfiUsfArr tua := f_TfiUsfArrInit();
5081 var octetstring data := '0000'O & f_rnd_octstring(21);
5082
5083 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005084
Harald Welte883340c2018-02-28 18:59:29 +01005085 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005086 f_TfiUsfArrSet(tua, 7, 0);
5087 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5088 f_sleep(1.0);
5089
5090 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005091}
5092
5093/* Send DATA.req on timeslot that hasn't been activated */
5094testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005095 var TfiUsfArr tua := f_TfiUsfArrInit();
5096 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005097
Harald Welte7162a612019-05-26 12:56:09 +02005098 f_virtphy_common();
5099
5100 f_TfiUsfArrSet(tua, 7, 0);
5101 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5102 f_sleep(1.0);
5103
5104 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005105}
5106
Harald Weltead033dc2019-05-25 17:28:16 +02005107private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005108 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5109 boolean wait_rts := true)
5110runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005111 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005112 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005113
5114 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005115 if (wait_rts) {
5116 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5117 } else {
5118 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5119 }
Harald Weltead033dc2019-05-25 17:28:16 +02005120
5121 T.start;
5122 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005123 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005124 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5125 setverdict(pass);
5126 }
Harald Welte7162a612019-05-26 12:56:09 +02005127 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5128 setverdict(fail, "Received unexpected ", rx_dl);
5129 }
Harald Weltead033dc2019-05-25 17:28:16 +02005130 [] L1CTL.receive {
5131 repeat;
5132 }
Harald Welte7162a612019-05-26 12:56:09 +02005133 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005134 setverdict(fail, "Timeout waiting for ", data);
5135 }
Harald Welte7162a612019-05-26 12:56:09 +02005136 [not expect_data] T.timeout {
5137 setverdict(pass);
5138 }
Harald Weltead033dc2019-05-25 17:28:16 +02005139 }
5140}
5141
5142private function f_disable_dynamic_ts() runs on test_CT
5143{
5144 f_init_vty_bsc();
5145 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5146 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5147 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5148 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005149 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005150}
5151
5152private function f_virtphy_common() runs on test_CT {
5153 f_disable_dynamic_ts();
5154 f_init_l1ctl();
5155 f_l1_tune(L1CTL);
5156}
5157
5158testcase TC_pcu_data_req_pdtch() runs on test_CT {
5159 var TfiUsfArr tua := f_TfiUsfArrInit();
5160 var octetstring data := '0000'O & f_rnd_octstring(21);
5161
5162 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005163
Harald Welte883340c2018-02-28 18:59:29 +01005164 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005165 f_TfiUsfArrSet(tua, 7, 0);
5166 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5167 f_sleep(1.0);
5168
5169 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005170}
5171
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005172/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005173testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005174 var TfiUsfArr tua := f_TfiUsfArrInit();
5175 var octetstring data := '0000'O & f_rnd_octstring(21);
5176
5177 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005178
Harald Welte883340c2018-02-28 18:59:29 +01005179 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005180 f_TfiUsfArrSet(tua, 7, 0);
5181 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5182 f_sleep(1.0);
5183
5184 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005185}
5186
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005187private function f_TC_pcu_ptcch_ul(uint16_t ra)
5188runs on test_CT {
5189 var template PCUIF_Message pcu_rach_ind;
5190 var PCUIF_send_data sd;
5191 var GsmFrameNumber fn;
5192 timer T;
5193
5194 /* Send an Access Burst on PTCCH/U over the Um-interface */
5195 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5196 chan_nr := ts_RslChanNr_PDCH(7),
5197 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5198
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005199 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5200 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005201
5202 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5203 T.start(52.0 * 4.615 / 1000.0);
5204 alt {
5205 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5206 log("Rx an Access Burst on the PCU interface: ", sd.data);
5207 setverdict(pass);
5208 T.stop;
5209 }
5210 [] PCU.receive { repeat; }
5211 [] T.timeout {
5212 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5213 /* Keep going, that's not the end of the world */
5214 }
5215 }
5216}
5217
5218testcase TC_pcu_ptcch() runs on test_CT {
5219 var L1ctlDlMessage dl;
5220 var octetstring data;
5221 timer T;
5222
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005223 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005224 f_init_l1ctl();
5225 f_l1_tune(L1CTL);
5226
5227 /* Activate PDCH channel on TS7 */
5228 f_TC_pcu_act_req(0, 0, 7, true);
5229
5230 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005231 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005232 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005233 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005234 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005235
5236 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5237 for (var integer i := 0; i < 16; i := i + 1) {
5238 log("Sending an Access Burst towards the L1CTL interface");
5239 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5240 }
5241
5242 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5243 data := f_rnd_octstring(23);
5244
5245 /* Verify PTCCH/D: send a random data block, make sure it's received */
5246 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5247 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5248
5249 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5250 * let's give it more time in case if we miss the beginning. */
5251 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5252 alt {
5253 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5254 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5255 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5256 frame := data)) -> value dl {
5257 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5258 setverdict(pass);
5259 T.stop;
5260 }
5261 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5262 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5263 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5264 l2_data := data)) -> value dl {
5265 log("Rx PTCCH/D data block on L1CTL: ", dl);
5266 setverdict(pass);
5267 T.stop;
5268 }
5269 [] L1CTL.receive { repeat; }
5270 [] T.timeout {
5271 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5272 }
5273 }
5274}
5275
Harald Welte883340c2018-02-28 18:59:29 +01005276/* Send AGCH from PCU; check it appears on Um side */
5277testcase TC_pcu_data_req_agch() runs on test_CT {
5278 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005279 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005280 f_init_l1ctl();
5281 f_l1_tune(L1CTL);
5282
5283 f_TC_pcu_act_req(0, 0, 7, true);
5284 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5285
5286 T.start;
5287 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005288 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005289 setverdict(pass);
5290 }
5291 [] L1CTL.receive { repeat; }
5292 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005294 }
5295 }
5296}
5297
Harald Welte928622b2019-05-26 13:22:59 +02005298/* Send AGCH from PCU; check it appears on Um side */
5299testcase TC_pcu_data_req_pch() runs on test_CT {
5300 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005301 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005302 f_init_l1ctl();
5303 f_l1_tune(L1CTL);
5304
5305 f_TC_pcu_act_req(0, 0, 7, true);
5306 /* three characters prefix: last 3 digits of IMSI as ASCII */
5307 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5308
5309 T.start;
5310 alt {
5311 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5312 setverdict(pass);
5313 }
5314 [] L1CTL.receive { repeat; }
5315 [] T.timeout {
5316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5317 }
5318 }
5319}
5320
Harald Welte883340c2018-02-28 18:59:29 +01005321/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5322testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5323 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005324 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005325 f_init_l1ctl();
5326 f_l1_tune(L1CTL);
5327
5328 /* append 3 last imsi digits so BTS can compute pagng group */
5329 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5330
5331 timer T := 0.5;
5332 T.start;
5333 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005334 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005335 /* TODO: verify paging group */
5336 setverdict(pass);
5337 }
5338 [] L1CTL.receive { repeat; }
5339 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005341 }
5342 }
5343}
5344
5345/* Send RACH from Um side, expect it to show up on PCU socket */
5346testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005347 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005348 f_init_l1ctl();
5349 f_l1_tune(L1CTL);
5350
5351 var GsmFrameNumber fn_last := 0;
5352 for (var integer i := 0; i < 1000; i := i+1) {
5353 var OCT1 ra := f_rnd_ra_ps();
5354 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5355 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005357 }
5358 fn_last := fn;
5359
5360 timer T := 2.0;
5361 T.start;
5362 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005363 [] 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 +01005364 T.stop;
5365 }
5366 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005368 }
5369 [] PCU.receive { repeat; }
5370 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005372 }
5373 }
5374 }
5375 setverdict(pass);
5376}
5377
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005378/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5379 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5380testcase TC_pcu_ext_rach_content() runs on test_CT {
5381 var template PCUIF_Message pcu_rach_ind;
5382 var GsmFrameNumber fn_last := 0;
5383 var L1ctlRachSynchSeq synch_seq;
5384 var PCUIF_BurstType pcu_bt;
5385 var GsmFrameNumber fn;
5386 var BIT11 ra11;
5387
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005388 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005389 f_init_l1ctl();
5390 f_l1_tune(L1CTL);
5391
5392 for (var integer i := 0; i < 1000; i := i+1) {
5393 /* We need to test both TS1 & TS2 */
5394 if (i rem 2 == 0) {
5395 synch_seq := RACH_SYNCH_SEQ_TS1;
5396 pcu_bt := BURST_TYPE_1;
5397 } else {
5398 synch_seq := RACH_SYNCH_SEQ_TS2;
5399 pcu_bt := BURST_TYPE_2;
5400 }
5401
5402 ra11 := f_rnd_ra11_ps();
5403 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5404 if (fn == fn_last) {
5405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5406 "Two RACH in same FN?!?");
5407 }
5408 fn_last := fn;
5409
5410 /* Compose the expected message */
5411 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005412 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005413 ra := bit2int(ra11),
5414 is_11bit := 1,
5415 burst_type := pcu_bt,
5416 fn := fn);
5417
5418 timer T := 2.0;
5419 T.start;
5420 alt {
5421 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5422 T.stop;
5423 }
5424 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5426 }
5427 [] PCU.receive { repeat; }
5428 [] T.timeout {
5429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5430 }
5431 }
5432 }
5433 setverdict(pass);
5434}
5435
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005436private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5437runs on test_CT {
5438 var template PCUIF_send_data sdt;
5439 var PCUIF_send_data sd;
5440 var int16_t lqual_cb;
5441 timer T := 1.0;
5442
5443 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5444 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5445
5446 /* Send a random PDTCH frame over Um */
5447 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5448 '0000'O & f_rnd_octstring(21)));
5449
5450 T.start;
5451 alt {
5452 /* If expected link quality is above the threshold */
5453 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5454 lqual_cb := sd.data.u.data_ind.lqual_cb;
5455 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5456
5457 /* Make sure the actual link quality matches the expected value */
5458 if (not match(lqual_cb, lqual_cb_exp)) {
5459 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5460 "expected value ", lqual_cb_exp));
5461 } else {
5462 setverdict(pass);
5463 }
5464 }
5465 /* If expected link quality is below the threshold */
5466 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5468 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5469 }
5470 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5471 [] PCU.receive { repeat; }
5472 [lqual_cb_exp < thresh] T.timeout {
5473 log("Rx nothing, as expected");
5474 setverdict(pass);
5475 }
5476 [lqual_cb_exp >= thresh] T.timeout {
5477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5478 "Timeout waiting for PCUIF_DATA.ind");
5479 }
5480 }
5481}
5482
5483/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5484testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005485 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005486 PCU.clear;
5487
5488 f_init_l1ctl();
5489 f_l1_tune(L1CTL);
5490
5491 /* Activate a PDCH channel on TS7 */
5492 f_TC_pcu_act_req(0, 0, 7, true);
5493
5494 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005495 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005496 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005497 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005498 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005499
5500 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5501 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5502 var TrxcMessage ret;
5503
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005504 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005505
5506 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5507 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5508 }
5509}
5510
Harald Welte883340c2018-02-28 18:59:29 +01005511/* Send PAGING via RSL, expect it to shw up on PCU socket */
5512testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005513 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005514
5515 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005516 var MobileIdentityLV mi_lv;
5517 var octetstring mi_lv_enc;
5518 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005519 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005520
Harald Welte883340c2018-02-28 18:59:29 +01005521 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005522 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005523 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005524 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005525 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005526
5527 /* Fancy encoding for PCUIF */
5528 mi_lv := valueof(ts_MI_LV(mi));
5529 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5530 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005531
5532 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005533 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005534 T.start;
5535 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005536 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005537 }
5538 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005540 }
5541 [] PCU.receive { repeat; }
5542 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005544 }
5545 }
5546 }
5547 setverdict(pass);
5548}
5549
Harald Welted66c9b82019-05-25 09:03:15 +02005550/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5551testcase TC_pcu_time_ind() runs on test_CT {
5552 var PCUIF_send_data pcu_sd;
5553 var integer num_time_ind := 0;
5554 var integer first_fn, last_fn;
5555 var float test_duration := 5.0;
5556 timer T;
5557
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005558 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005559 f_TC_pcu_act_req(0, 0, 7, true);
5560
5561 PCU.clear;
5562 T.start(test_duration);
5563 alt {
5564 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5565 num_time_ind := num_time_ind + 1;
5566 if (not isbound(first_fn)) {
5567 first_fn := pcu_sd.data.u.time_ind.fn;
5568 }
5569 last_fn := pcu_sd.data.u.time_ind.fn;
5570 repeat;
5571 }
5572 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5573 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5574 repeat;
5575 }
5576 [] PCU.receive {
5577 repeat;
5578 }
5579 [] T.timeout {}
5580 }
5581 var integer fn_expired := last_fn - first_fn;
5582 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5583
5584 /* verify the number of frames expired matches our expectation */
5585 const float c_GSM_FN_DURATION_MS := 4.61538;
5586 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005587 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005588 if (not match(fn_expired, t_fn_expected)) {
5589 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5590 }
5591
5592 /* There are three TIME.ind in every fn MOD 13 */
5593 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5594 /* Add some tolerance */
5595 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5596 if (not match(num_time_ind, t_time_ind_exp)) {
5597 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5598 }
5599
5600 setverdict(pass);
5601}
5602
Harald Welte4832c862019-05-25 14:57:18 +02005603/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5604testcase TC_pcu_rts_req() runs on test_CT {
5605 var PCUIF_send_data pcu_sd;
5606 var integer first_fn, last_fn;
5607 var integer num_rts_pdtch := 0;
5608 var integer num_rts_ptcch := 0;
5609 var float test_duration := 5.0;
5610 timer T;
5611
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005612 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005613 f_TC_pcu_act_req(0, 0, 7, true);
5614
5615 PCU.clear;
5616 T.start(test_duration);
5617 alt {
5618 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5619 -> value pcu_sd {
5620 num_rts_pdtch := num_rts_pdtch + 1;
5621 if (not isbound(first_fn)) {
5622 first_fn := pcu_sd.data.u.rts_req.fn;
5623 }
5624 last_fn := pcu_sd.data.u.rts_req.fn;
5625 repeat;
5626 }
5627 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5628 -> value pcu_sd {
5629 num_rts_ptcch := num_rts_ptcch + 1;
5630 if (not isbound(first_fn)) {
5631 first_fn := pcu_sd.data.u.rts_req.fn;
5632 }
5633 last_fn := pcu_sd.data.u.rts_req.fn;
5634 repeat;
5635 }
5636 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5637 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5638 repeat;
5639 }
5640 [] PCU.receive {
5641 repeat;
5642 }
5643 [] T.timeout {}
5644 }
5645 var integer fn_expired := last_fn - first_fn;
5646 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5647 ", num_rts_ptcch=", num_rts_ptcch);
5648
5649 /* verify the number of frames expired matches our expectation */
5650 const float c_GSM_FN_DURATION_MS := 4.61538;
5651 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005652 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005653 if (not match(fn_expired, t_fn_expected)) {
5654 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5655 }
5656
5657 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5658 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5659 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5660 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5661 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5662 t_ptcch_exp);
5663 }
5664
5665 /* We have 12 PDTCH blocks every 52-multiframe */
5666 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5667 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5668 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5669 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5670 t_pdtch_exp);
5671 }
5672
5673 setverdict(pass);
5674}
5675
Harald Welte07bd2d22019-05-25 11:03:30 +02005676/* test for generating Abis side OML ALERT from the PCU */
5677testcase TC_pcu_oml_alert() runs on test_CT {
5678 var PCUIF_send_data pcu_sd;
5679 var integer num_time_ind := 0;
5680 var integer first_fn, last_fn;
5681 var float test_duration := 5.0;
5682 timer T;
5683
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005684 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005685 f_TC_pcu_act_req(0, 0, 7, true);
5686
5687 /* re-connect CTRL port from BTS to BSC */
5688 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005689 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005690
5691 /* Send that OML Alert */
5692 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5693
5694 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5695 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5696 setverdict(pass);
5697}
5698
Harald Welteeaa9a862019-05-26 23:01:08 +02005699/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5700private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5701 var PCUIF_Message first_info;
5702 var integer pcu_conn_id := -1;
5703 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5704 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5705 var OCT4 tlli := '01020304'O;
5706 var OCT1 cause := '23'O;
5707 timer T := 5.0;
5708
5709 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5710
5711 f_l1_tune(L1CTL);
5712 RSL.clear;
5713
5714 f_est_dchan();
5715 L1CTL.clear;
5716
5717 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5718
5719 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5720 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5721 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5722
5723 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5724 T.start;
5725 alt {
5726 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5727 setverdict(pass);
5728 }
5729 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5730 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5731 }
5732 [] PCU.receive {
5733 repeat;
5734 }
5735 [] T.timeout {
5736 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5737 }
5738 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005739
5740 /* release the channel */
5741 f_rsl_chan_deact();
5742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5743 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005744}
5745testcase TC_pcu_rr_suspend() runs on test_CT {
5746 var ConnHdlrPars pars;
5747 var ConnHdlr vc_conn;
5748
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005749 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005750
5751 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5752 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5753 vc_conn.done;
5754}
Harald Welte07bd2d22019-05-25 11:03:30 +02005755
Harald Weltea2e0e942019-05-27 18:12:53 +02005756/* Ensure that PCUIF socket can accept only a single connection */
5757testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005758 var boolean connected := false;
5759 var UD_connect_result cr;
5760 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005761 timer T := 5.0;
5762
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005763 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5764 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5765
Harald Weltea2e0e942019-05-27 18:12:53 +02005766 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005767 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005768
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005769 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005770 PCU.send(UD_connect:{mp_pcu_socket, -1});
5771 T.start;
5772 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005773 /* the IUT will first accept() the new connection, and close() it immediately */
5774 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5775 log("BTS has accept()ed connection");
5776 connected := true;
5777 cid := cr.id;
5778 repeat;
5779 }
5780 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5781 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005782 setverdict(pass);
5783 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005784 /* ignore other messages related to the first connection */
5785 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005786 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005787 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005788 }
5789 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005790
Harald Weltea2e0e942019-05-27 18:12:53 +02005791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5792}
5793
Harald Weltec8effb72019-05-27 18:23:04 +02005794/* Ensure that PCUIF socket can disconnect + reconnect */
5795testcase TC_pcu_socket_reconnect() runs on test_CT {
5796 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005797 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005798
5799 f_sleep(1.0);
5800
5801 f_pcuif_close(PCU, g_pcu_conn_id);
5802 g_pcu_conn_id := -1;
5803
5804 f_sleep(1.0);
5805
5806 /* re-connect */
5807 PCU.clear;
5808 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5809 setverdict(pass);
5810
5811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5812}
5813
Harald Weltebe030482019-05-27 22:29:35 +02005814/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005815private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5816runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005817 var L1ctlDlMessage l1_dl;
5818 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005819 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005820 timer T := 5.0;
5821 T.start;
5822 alt {
5823 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005824 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5825 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005826 repeat;
5827 }
5828 }
5829 [] pt.receive {
5830 repeat;
5831 }
5832 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5834 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005835 }
5836 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005837 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005838}
5839
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005840/* Check if GPRS Indicator is present in RR System Information of a given type */
5841private function f_si_has_gprs_indicator(RrMessageType si_type)
5842runs on test_CT return boolean {
5843 var SystemInformation si := f_get_si(L1CTL, si_type);
5844
5845 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005846 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005847 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005848 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005849 }
5850
5851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5852 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005853}
5854
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005855/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5856private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5857runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005858 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005859 f_init_l1ctl();
5860 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005861 f_sleep(2.0);
5862 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005863
5864 if (f_si_has_gprs_indicator(si_type)) {
5865 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005866 } else {
5867 setverdict(pass);
5868 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005869
Harald Weltebe030482019-05-27 22:29:35 +02005870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5871}
5872
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005873testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5874 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5875}
Harald Weltebe030482019-05-27 22:29:35 +02005876
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005877testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5878 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5879}
5880
5881/* Ensure that GPRS capability is advertised after PCU socket connect */
5882private function f_TC_pcu_socket_connect(RrMessageType si_type)
5883runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005884 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005885 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005886 f_init_l1ctl();
5887 f_l1_tune(L1CTL);
5888
5889 f_sleep(2.0);
5890 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005891
5892 if (not f_si_has_gprs_indicator(si_type)) {
5893 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005894 } else {
5895 setverdict(pass);
5896 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005897
Harald Weltebe030482019-05-27 22:29:35 +02005898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5899}
5900
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005901testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5902 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5903}
Harald Weltebe030482019-05-27 22:29:35 +02005904
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005905testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5906 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5907}
5908
5909/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5910private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5911runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005912 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005913 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005914 f_init_l1ctl();
5915 f_l1_tune(L1CTL);
5916
5917 f_pcuif_close(PCU, g_pcu_conn_id);
5918 g_pcu_conn_id := -1;
5919
5920 f_sleep(1.0);
5921
5922 /* re-connect */
5923 PCU.clear;
5924 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5925
5926 f_sleep(2.0);
5927 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005928
5929 if (f_si_has_gprs_indicator(si_type)) {
5930 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005931 } else {
5932 setverdict(pass);
5933 }
5934
5935 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5936}
5937
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005938testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5939 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5940}
5941
5942testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5943 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5944}
5945
Oliver Smithf5239c72019-08-28 10:01:25 +02005946/* 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) */
5947testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5948 var SystemInformation si3 := valueof(ts_SI3_default);
5949
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005950 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005951
Harald Welte76220222020-10-11 20:32:44 +02005952 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5953 * information */
5954 timer T := 2.0;
5955 T.start;
5956 alt {
5957 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5958 [] T.timeout {}
5959 }
5960
Oliver Smithf5239c72019-08-28 10:01:25 +02005961 /* Verify cell_id */
5962 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5963 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5964 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005965 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5966 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5967 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005968 }
5969
5970 /* Verify LAC */
5971 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5972 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5973 if (lac_si3 != lac_pcu) {
5974 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5975 }
5976
5977 setverdict(pass);
5978}
Harald Welted66c9b82019-05-25 09:03:15 +02005979
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005980/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5981testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5982 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005983 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005984
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005985 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005986
5987 info_ind := g_pcu_last_info.u.info_ind;
5988
5989 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5990 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005991 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005992 /* Skip inactive timeslots */
5993 continue;
5994 }
5995
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005996 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005997 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005998 else
5999 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006000
6001 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006002 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006003 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07006004 hsn := fhp.maio_hsn.hsn,
6005 maio := fhp.maio_hsn.maio,
6006 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07006007 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006008 } else {
6009 tr_ts := tr_PCUIF_InfoTrxTsH0;
6010 }
6011
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006012 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006013 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
6014 if (not match(ts, tr_ts)) {
6015 setverdict(fail, "Hopping parameters do not match: ",
6016 "received ", ts, " vs expected ", tr_ts);
6017 } else {
6018 setverdict(pass);
6019 }
6020 }
6021 }
6022}
6023
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006024/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006025testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
6026 f_init_vty_bsc();
6027 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6028 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6029
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006030 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006031
6032 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006033 var template PCUIF_RemoteAddr tr_remote_addr := {
6034 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006035 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006036 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006037
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006038 if (not match(remote_addr, tr_remote_addr)) {
6039 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006040 }
6041
6042 setverdict(pass);
6043}
6044
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006045/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006046testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6047 f_init_vty_bsc();
6048 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6049
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006050 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006051
6052 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006053 var template PCUIF_RemoteAddr tr_remote_addr := {
6054 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6055 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6056 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006057
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006058 if (not match(remote_addr, tr_remote_addr)) {
6059 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006060 }
6061
6062 setverdict(pass);
6063}
6064
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006065/* Verify coding of two NSVCs in the INFO.ind message */
6066testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6067 f_init_vty_bsc();
6068
6069 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6070 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6071 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6072 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6073
6074 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6075 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6076 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6077 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6078
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006079 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006080
6081 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6082 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6083 var template PCUIF_RemoteAddr tr_remote_addr := {
6084 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006085 addr := {
6086 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6087 f_inet6_addr("fd00::ca:ff:ee")
6088 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006089 };
6090
6091 if (not match(info_ind.nsvci, { 1234, 5678 }))
6092 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6093 if (not match(remote_addr, tr_remote_addr))
6094 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6095 if (not match(info_ind.local_port, { 1234, 5678 }))
6096 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6097 if (not match(info_ind.remote_port, { 1234, 5678 }))
6098 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6099
6100 setverdict(pass);
6101}
6102
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006103/* Verify periodic interference reports on PDCH */
6104testcase TC_pcu_interf_ind() runs on test_CT {
6105 var template PCUIF_Message tr_interf_ind;
6106 var template PCUIF_interf ts_interf;
6107 var integer interf_ind_num := 0;
6108 var PCUIF_send_data sd;
6109 timer T;
6110
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006111 /* Set the averaging/reporting period to 480ms */
6112 f_init_vty_bsc();
6113 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 1" });
6114 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6115
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006116 f_init_with_pcuif();
6117 f_TC_pcu_act_req(0, 0, 7, true);
6118
6119 /* We need trxcon for NOPE indications */
6120 f_init_l1ctl();
6121 f_l1_tune(L1CTL);
6122
6123 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6124 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6125 tr_interf_ind := tr_PCUIF_INTERF_IND(
6126 bts_nr := 0,
6127 trx_nr := 0,
6128 fn := ?,
6129 interf := ts_interf
6130 );
6131
6132 /* 4 SACCH periods => 4 reports (plus some guard time) */
6133 var float Tval := int2float(4 * 480) / 1000.0 + 0.5;
6134
6135 /* Let it some time to stabilize */
6136 f_sleep(0.5);
6137 PCU.clear;
6138
6139 T.start(Tval);
6140 alt {
6141 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
6142 /* Check TDMA frame number period */
6143 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6144 setverdict(fail, "Odd TDMA frame number := ",
6145 sd.data.u.interf_ind.fn);
6146 }
6147 interf_ind_num := interf_ind_num + 1;
6148 if (interf_ind_num < 4)
6149 { repeat; }
6150 }
6151 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
6152 setverdict(fail, "Received unexpected interference report: ", sd.data);
6153 }
6154 [] PCU.receive { repeat; }
6155 [] T.timeout {
6156 setverdict(fail, "Timeout waiting for interference reports");
6157 }
6158 }
6159
Vadim Yanitskiyd9b60e62021-11-10 03:58:31 +03006160 /* Reset the averaging/reporting period back to default */
6161 f_vty_cfg_bts(BSCVTY, 0, { "interference-meas avg-period 6" });
6162
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6164}
6165
Harald Welte3d04ae62018-04-04 20:29:05 +02006166/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006167 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006168 ***********************************************************************/
6169
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006170private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6171 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006172runs on ConnHdlr {
6173 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006174
6175 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006176 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006177 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6178 repeat;
6179 }
6180 }
6181}
6182
6183private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6184runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006185 /* Expect BTS to immediately acknowledge activation as PDCH */
6186 PCU.clear;
6187 f_rsl_chan_act(g_pars.chan_mode);
6188 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006189 timer T_wait := 2.0;
6190 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006191 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006192 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006193 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006194 [] T_wait.timeout {
6195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6196 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6197 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006198 }
6199 /* try to activate this PDCH from the PCU point of view */
6200 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6201 /* FIXME: is there a response? */
6202}
6203
6204private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6205runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006206 /* Send RSL CHAN REL (deactivate) */
6207 PCU.clear;
6208 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6209 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006210 timer T_wait := 2.0;
6211 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006212 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006213 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006214 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006215 [] T_wait.timeout {
6216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6217 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6218 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006219 }
6220 /* Emulate PCU asking BTS to deactivate PDCH */
6221 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6222 alt {
6223 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6224 setverdict(pass);
6225 }
6226 [] RSL.receive { repeat; }
6227 }
6228}
6229
6230/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006231private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006232 var PCUIF_Message first_info;
6233 var integer ts_nr := g_chan_nr.tn;
6234 var integer trx_nr := 0;
6235 var integer bts_nr := 0;
6236 var integer pcu_conn_id := -1;
6237
6238 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6239
6240 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6241 f_sleep(3.0);
6242 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6243 setverdict(pass);
6244}
6245testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6246 var ConnHdlrPars pars;
6247 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006248 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006249
6250 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6251 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6252 vc_conn.done;
6253}
6254
6255/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006256private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006257 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006258 var integer pcu_conn_id := -1;
6259
6260 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6261
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006262 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6263 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6264 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006265 setverdict(pass);
6266}
6267testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6268 var ConnHdlrPars pars;
6269 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006270 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006271
6272 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6273 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6274 vc_conn.done;
6275}
6276
6277/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006278private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006279 var PCUIF_Message first_info;
6280 var integer ts_nr := g_chan_nr.tn;
6281 var integer trx_nr := 0;
6282 var integer bts_nr := 0;
6283 var integer pcu_conn_id := -1;
6284
6285 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6286
6287 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006288 /* Send a second Chan Activ and expect it to be NACKed */
6289 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6290 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006291 setverdict(pass);
6292}
6293testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
6294 var ConnHdlrPars pars;
6295 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006296 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006297
6298 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6299 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
6300 vc_conn.done;
6301}
6302
6303/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006304private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006305 var PCUIF_Message first_info;
6306 var integer ts_nr := g_chan_nr.tn;
6307 var integer trx_nr := 0;
6308 var integer bts_nr := 0;
6309 var integer pcu_conn_id := -1;
6310 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6311
6312 /* register for the TCH/F channel number */
6313 f_rslem_register(0, chan_nr);
6314
6315 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6316
6317 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6318 "RSL CHAN ACT");
6319 setverdict(pass);
6320}
6321testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6322 var ConnHdlrPars pars;
6323 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006324 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006325
6326 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6327 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6328 vc_conn.done;
6329}
6330
6331/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006332private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006333 var PCUIF_Message first_info;
6334 var integer ts_nr := g_chan_nr.tn;
6335 var integer trx_nr := 0;
6336 var integer bts_nr := 0;
6337 var integer pcu_conn_id := -1;
6338 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6339 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6340
6341 /* register for the TCH/H channel numbers */
6342 f_rslem_register(0, chan_nr[0]);
6343 f_rslem_register(0, chan_nr[1]);
6344
6345 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6346
6347 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6348 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6349 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6350 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6351 setverdict(pass);
6352}
6353testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6354 var ConnHdlrPars pars;
6355 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006356 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006357
6358 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6359 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6360 vc_conn.done;
6361}
6362
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006363/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6364private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6365 var PCUIF_Message first_info;
6366 var integer ts_nr := g_chan_nr.tn;
6367 var integer trx_nr := 0;
6368 var integer bts_nr := 0;
6369 var integer pcu_conn_id := -1;
6370 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6371 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6372 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6373 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6374 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6375 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6376 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6377 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6378
6379 /* register for the TCH/H channel numbers */
6380 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6381 f_rslem_register(0, chan_nr[i]);
6382 }
6383
6384 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6385
6386 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6387 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6388 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6389 }
6390 setverdict(pass);
6391}
6392testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6393 var ConnHdlrPars pars;
6394 var ConnHdlr vc_conn;
6395 f_init();
6396
6397 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6398 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6399 vc_conn.done;
6400}
6401
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006402/* Reproduce a race condition described in OS#5245 */
6403private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6404 f_rsl_chan_act(g_pars.chan_mode);
6405 f_sleep(1.0);
6406 f_rsl_chan_deact();
6407 setverdict(pass);
6408}
6409testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6410 var ConnHdlrPars pars[2];
6411 var ConnHdlr vc_conn[2];
6412 var TrxcMessage rsp;
6413
6414 f_init();
6415
6416 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6417 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6418 ts_TRXC_FAKE_TRXC_DELAY(200));
6419
6420 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6421 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6422 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6423 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6424 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6425 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6426 pars[i], l1ctl := false);
6427 }
6428
6429 /* Wait for all components to finish */
6430 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6431 vc_conn[i].done;
6432 }
6433
6434 /* Disable the artificial delay for TRXC RSP messages */
6435 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6436 ts_TRXC_FAKE_TRXC_DELAY(0));
6437}
6438testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6439 var ConnHdlrPars pars[8];
6440 var ConnHdlr vc_conn[8];
6441 var TrxcMessage rsp;
6442
6443 f_init();
6444
6445 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6446 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6447 ts_TRXC_FAKE_TRXC_DELAY(200));
6448
6449 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6450 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6451 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6452 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6453 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6454 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6455 pars[i], l1ctl := false);
6456 }
6457
6458 /* Wait for all components to finish */
6459 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6460 vc_conn[i].done;
6461 }
6462
6463 /* Disable the artificial delay for TRXC RSP messages */
6464 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6465 ts_TRXC_FAKE_TRXC_DELAY(0));
6466}
6467
Harald Welte9bbbfb52018-04-05 09:33:19 +02006468/***********************************************************************
6469 * IPA Style Dynamic Timeslot Support
6470 ***********************************************************************/
6471
6472private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6473runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006474 /* Expect BTS to immediately acknowledge activation as PDCH */
6475 PCU.clear;
6476 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6477 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006478 timer T_wait := 2.0;
6479 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006480 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006481 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006482 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006483 [] T_wait.timeout {
6484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6485 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6486 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006487 }
6488 /* try to activate this PDCH from the PCU point of view */
6489 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6490 /* FIXME: is there a response? */
6491
6492 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6493}
6494
6495private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6496runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006497 /* Send RSL CHAN REL (deactivate) */
6498 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6499 PCU.clear;
6500 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006501 timer T_wait := 2.0;
6502 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006503 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006504 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006505 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006506 [] T_wait.timeout {
6507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6508 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6509 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006510 }
6511 /* Emulate PCU asking BTS to deactivate PDCH */
6512 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6513 alt {
6514 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6515 setverdict(pass);
6516 }
6517 [] RSL.receive { repeat; }
6518 }
6519}
6520
6521/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006522private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006523 var PCUIF_Message first_info;
6524 var integer ts_nr := g_chan_nr.tn;
6525 var integer trx_nr := 0;
6526 var integer bts_nr := 0;
6527 var integer pcu_conn_id := -1;
6528
6529 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6530
6531 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6532 f_sleep(3.0);
6533 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6534
6535 setverdict(pass);
6536
6537}
6538testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6539 var ConnHdlrPars pars;
6540 var ConnHdlr vc_conn;
6541 f_init();
6542
6543 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6544 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6545 vc_conn.done;
6546}
6547
6548/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006549private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006550 var PCUIF_Message first_info;
6551 var integer ts_nr := g_chan_nr.tn;
6552 var integer trx_nr := 0;
6553 var integer bts_nr := 0;
6554 var integer pcu_conn_id := -1;
6555
6556 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6557
6558 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6559 "RSL CHAN ACT");
6560 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6561 "RF CHAN REL", true);
6562 setverdict(pass);
6563}
6564testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6565 var ConnHdlrPars pars;
6566 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006567 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006568
6569 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6570 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6571 vc_conn.done;
6572}
6573
6574/* 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 +07006575private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006576 var PCUIF_Message first_info;
6577 var integer ts_nr := g_chan_nr.tn;
6578 var integer trx_nr := 0;
6579 var integer bts_nr := 0;
6580 var integer pcu_conn_id := -1;
6581
6582 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6583
6584 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6585 "RSL CHAN ACT");
6586
6587 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6588 alt {
6589 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6590 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006592 }
6593 [] RSL.receive { repeat; }
6594 }
6595
6596 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6597 "RF CHAN REL", true);
6598 setverdict(pass);
6599}
6600testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6601 var ConnHdlrPars pars;
6602 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006603 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006604
6605 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6606 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6607 vc_conn.done;
6608}
6609
6610/* 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 +07006611private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006612 var PCUIF_Message first_info;
6613 var integer ts_nr := g_chan_nr.tn;
6614 var integer trx_nr := 0;
6615 var integer bts_nr := 0;
6616 var integer pcu_conn_id := -1;
6617
6618 /* register for the TCH/F channel number */
6619 f_rslem_register(0, g_chan_nr);
6620
6621 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6622
6623 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6624
6625 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6626 "RSL CHAN ACT");
6627
6628 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6629
6630 setverdict(pass);
6631}
6632testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6633 var ConnHdlrPars pars;
6634 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006635 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006636
6637 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6638 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6639 vc_conn.done;
6640}
6641
6642
Harald Welte0472ab42018-03-12 15:02:26 +01006643/***********************************************************************
6644 * LAPDm / RLL related
6645 ***********************************************************************/
6646
6647private function f_tx_lapdm(template (value) LapdmFrame l,
6648 template (value) RslLinkId link_id) runs on ConnHdlr {
6649 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006650 var template (value) SacchL1Header l1h;
6651
6652 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006653 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006654 /* Compose dummy L1 header */
6655 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6656 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 +02006657 } else {
6658 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006659 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 +01006660 }
Harald Welte0472ab42018-03-12 15:02:26 +01006661}
6662
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006663friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006664 uint3_t sapi,
6665 RslLinkId link_id,
6666 octetstring l3,
6667 boolean exp
6668}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006669friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006670friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6671 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006672 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006673 sapi := sapi,
6674 link_id := id,
6675 l3 := l3,
6676 exp := exp
6677}
6678
6679/* execute the same callback function with a set of different parameters (tcs) on a
6680 * variety of logical channels */
6681private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6682 var ConnHdlrPars pars;
6683 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006684 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006685
6686 /* test on each of the channels we have */
6687 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6688 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6689
6690 /* test each of the test cases on the current channel */
6691 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6692 pars.spec.rll := tcs[j];
6693 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6694 vc_conn := f_start_handler(fn, pars);
6695 vc_conn.done;
6696 }
6697 }
6698
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006700}
6701
6702/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6703private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6704 var RllTestCase tc := g_pars.spec.rll;
6705 timer T := 3.0;
6706
6707 f_l1_tune(L1CTL);
6708 RSL.clear;
6709
6710 /* activate the logical channel */
6711 f_est_dchan();
6712 L1CTL.clear;
6713
6714 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6715 T.start;
6716 alt {
6717 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6718 if (tc.exp) {
6719 setverdict(pass);
6720 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006721 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006722 }
6723 }
6724 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6725 if (tc.exp) {
6726 setverdict(pass);
6727 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006729 }
6730 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006731 /* We also expect to receive the measurements */
6732 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006733 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006735 }
6736 [not tc.exp] T.timeout {
6737 setverdict(pass);
6738 }
6739 }
6740
6741 f_rsl_chan_deact();
6742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6743 f_rslem_unregister(0, g_chan_nr);
6744}
6745testcase TC_rll_est_ind() runs on test_CT {
6746 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006747 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006748 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006749 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006750 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006751 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006752 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6753 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006754 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006755 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006756 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006757 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006758 };
6759 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6760}
6761
6762/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6763private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6764 var RllTestCase tc := g_pars.spec.rll;
6765 var L1ctlDlMessage dl;
6766 timer T := 3.0;
6767
6768 f_l1_tune(L1CTL);
6769 RSL.clear;
6770
6771 /* activate the logical channel */
6772 f_est_dchan();
6773 L1CTL.clear;
6774
6775 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6776 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6777 T.start;
6778 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006779 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006780 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006782 }
6783 }
6784
6785 f_rsl_chan_deact();
6786 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6787 f_rslem_unregister(0, g_chan_nr);
6788}
6789testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6790 var RllTestCases tcs := {
6791 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006792 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006793 };
6794 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6795}
6796testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6797 var RllTestCases tcs := {
6798 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006799 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006800 }
6801 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6802}
6803
6804/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006805friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006806 var L1ctlDlMessage dl;
6807 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6808 var LapdmFrame lapdm;
6809 var octetstring l2 := dl.payload.data_ind.payload;
6810 if (dl.dl_info.link_id.c == SACCH) {
6811 /* remove L1 header */
6812 l2 := substr(l2, 2, lengthof(l2)-2);
6813 }
6814 if (ischosen(exp.ab)) {
6815 lapdm.ab := dec_LapdmFrameAB(l2);
6816 } else if (ischosen(exp.b4)) {
6817 lapdm.b4 := dec_LapdmFrameB4(l2);
6818 } else if (ischosen(exp.bbis)) {
6819 lapdm.bbis := dec_LapdmFrameBbis(l2);
6820 }
6821 log("Rx LAPDm ", lapdm);
6822 if (match(lapdm, exp)) {
6823 setverdict(pass);
6824 } else {
6825 repeat;
6826 }
6827 }
6828 [] L1CTL.receive { repeat; }
6829}
6830private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6831 timer T := t;
6832 T.start;
6833 alt {
6834 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006836 }
6837 [] as_l1_exp_lapdm(exp);
6838 }
6839}
6840
6841/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6842private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6843 /* send SABM from MS -> BTS */
6844 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6845 /* expect RLL EST IND on Abis */
6846 alt {
6847 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6848 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6849 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006851 }
6852 [] RSL.receive { repeat; }
6853 }
6854 /* expect UA from BTS -> MS */
6855 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6856}
6857
6858/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6859private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6860 var RllTestCase tc := g_pars.spec.rll;
6861
6862 f_l1_tune(L1CTL);
6863 RSL.clear;
6864
6865 /* activate the logical channel */
6866 f_est_dchan();
6867 L1CTL.clear;
6868
6869 /* first establish the link-layer */
6870 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6871
6872 /* then send the DISC */
6873 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6874 /* ... and expect the REL IND on the RSL side */
6875 alt {
6876 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6877 setverdict(pass);
6878 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006879 /* We also expect to receive the measurements */
6880 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006881 }
6882
6883 /* release the channel */
6884 f_rsl_chan_deact();
6885 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6886 f_rslem_unregister(0, g_chan_nr);
6887}
6888testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6889 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006890 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006891 };
6892 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6893}
6894
6895testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6896 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006897 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006898 };
6899 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6900}
6901testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6902 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006903 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006904 };
6905 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6906}
6907testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6908 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006909 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006910 };
6911 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6912}
6913
6914/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6915private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6916 var RllTestCase tc := g_pars.spec.rll;
6917 f_l1_tune(L1CTL);
6918 RSL.clear;
6919
6920 /* activate the logical channel */
6921 f_est_dchan();
6922 L1CTL.clear;
6923
6924 /* first establish the link-layer */
6925 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6926
6927 /* then send the REL REQ via RSL */
6928 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6929 /* ... and expect the DISC on the Um side */
6930 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006931 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006932 /* FIXME: send a UA in resposne to the DISC */
6933 }
6934 }
6935
6936 /* release the channel */
6937 f_rsl_chan_deact();
6938 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6939 f_rslem_unregister(0, g_chan_nr);
6940}
6941testcase TC_rll_rel_req() runs on test_CT {
6942 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006943 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6944 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6945 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6946 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006947 };
6948 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6949}
6950
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006951/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006952testcase TC_rll_data_req() runs on test_CT {
6953}
6954
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006955/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006956testcase TC_rll_data_ind() runs on test_CT {
6957}
6958
6959/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6960private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6961 var RllTestCase tc := g_pars.spec.rll;
6962
6963 f_l1_tune(L1CTL);
6964 RSL.clear;
6965
6966 f_est_dchan();
6967 L1CTL.clear;
6968
6969 /* Send UNITDATA REQ on RSL side */
6970 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6971 /* Expect it to arrive on the other side */
6972 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006973 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006974 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006975 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006976 }
6977
6978 /* release the channel */
6979 f_rsl_chan_deact();
6980 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6981 f_rslem_unregister(0, g_chan_nr);
6982}
6983testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6984 var octetstring l3 := f_rnd_octstring(15);
6985 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006986 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6987 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006988 };
6989 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6990}
6991testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6992 var octetstring l3 := f_rnd_octstring(19);
6993 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006994 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6995 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006996 };
6997 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6998}
6999
7000/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
7001private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
7002 var RllTestCase tc := g_pars.spec.rll;
7003
7004 f_l1_tune(L1CTL);
7005 RSL.clear;
7006
7007 f_est_dchan();
7008 L1CTL.clear;
7009
7010 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02007011 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01007012 /* Expdct RLL UNITDATA IND on RSL side */
7013 alt {
7014 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
7015 setverdict(pass);
7016 }
7017 [] RSL.receive { repeat; }
7018 }
7019
7020 /* release the channel */
7021 f_rsl_chan_deact();
7022 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7023 f_rslem_unregister(0, g_chan_nr);
7024}
7025testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02007026 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01007027 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007028 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
7029 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007030 };
7031 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7032}
7033testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
7034 var octetstring l3 := f_rnd_octstring(18);
7035 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02007036 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
7037 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01007038 };
7039 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
7040}
7041
Harald Weltee613f962018-04-18 22:38:16 +02007042/***********************************************************************
7043 * Encryption Related
7044 ***********************************************************************/
7045
7046/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07007047private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007048 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7049 if (link_id.c == SACCH) {
7050 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7051 } else {
7052 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7053 }
7054}
7055
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007056/* Expect (or not expect) other kinds of messages */
7057private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7058 [exp_any] RSL.receive { repeat; }
7059 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007061 }
7062}
7063
Harald Weltee613f962018-04-18 22:38:16 +02007064/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007065private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007066 RslLinkId link_id,
7067 octetstring l3,
7068 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007069 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007070) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007071 timer T := 3.0;
7072 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7073 T.start;
7074 /* Expect RLL UNITDATA IND on RSL side */
7075 alt {
7076 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7077 setverdict(pass);
7078 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007079 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007080 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007081 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007083 }
Harald Weltee613f962018-04-18 22:38:16 +02007084 }
7085}
7086
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007087/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7088private function f_data_mo(
7089 RslLinkId link_id,
7090 boolean p, uint3_t nr, uint3_t ns,
7091 octetstring l3,
7092 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007093 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007094) runs on ConnHdlr {
7095 timer T := 3.0;
7096 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7097 T.start;
7098 /* Expect RLL DATA IND on RSL side */
7099 alt {
7100 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7101 setverdict(pass);
7102 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007103 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007104 [] as_rsl_any_ind(exp_any);
7105 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007107 }
7108 }
7109}
7110
Harald Weltee613f962018-04-18 22:38:16 +02007111/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007112private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007113 f_l1_tune(L1CTL);
7114 f_est_dchan(true);
7115
7116 /* now we actually need to transmit some data both ways to check if the encryption works */
7117 var L1ctlDlMessage dl;
7118
Stefan Sperling603d98e2018-07-25 16:47:28 +02007119 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007120 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7121
7122 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7123 f_unitdata_mt(link_id, l3);
7124
7125 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7126 f_unitdata_mo(link_id, l3);
7127
7128 /* release the channel */
7129 f_rsl_chan_deact();
7130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7131 f_rslem_unregister(0, g_chan_nr);
7132}
7133testcase TC_chan_act_a51() runs on test_CT {
7134 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7135 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7136 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7137}
7138testcase TC_chan_act_a52() runs on test_CT {
7139 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7140 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7141 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7142}
7143testcase TC_chan_act_a53() 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_3, f_rnd_octstring(8)));
7146 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7147}
Eric Wildb9260392021-05-15 19:48:22 +02007148testcase TC_chan_act_a54() 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_4, f_rnd_octstring(16)));
7151 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7152}
Harald Weltee613f962018-04-18 22:38:16 +02007153
Eric Wildf1827a72019-05-28 17:37:35 +02007154/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7155 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 +07007156private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007157 f_l1_tune(L1CTL);
7158 f_est_dchan(true);
7159
7160 /* now we actually need to transmit some data both ways to check if the encryption works */
7161 var L1ctlDlMessage dl;
7162
7163 var octetstring l3 := f_rnd_octstring(20);
7164 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7165
7166 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7167 f_unitdata_mt(link_id, l3);
7168
7169 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7170 f_unitdata_mo(link_id, l3);
7171
7172 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007173 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007174
7175 /* modify key to break proper encryption */
7176 g_pars.encr.key := f_rnd_octstring(8);
7177 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7178 rsl.ies := rsl.ies & { ei };
7179 RSL.send(rsl);
7180
7181 timer T0 := 1.0;
7182 T0.start;
7183 /* Expect RSL MODIFY ACK */
7184 alt {
7185 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7186 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7188 }
7189 [] T0.timeout {
7190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7191 }
7192 }
7193
7194 var octetstring l3msg := f_rnd_octstring(15);
7195 timer T1 := 3.0;
7196 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7197 due to broken encryption */
7198 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7199 T1.start;
7200 alt {
7201 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7203 }
7204 [] T1.timeout {
7205 setverdict(pass);
7206 }
7207 }
7208
7209 /* release the channel */
7210 f_rsl_chan_deact();
7211 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7212 f_rslem_unregister(0, g_chan_nr);
7213}
7214testcase TC_rsl_modify_encr() runs on test_CT {
7215 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7216 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7217 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7218}
Harald Weltee613f962018-04-18 22:38:16 +02007219
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007220/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7221private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7222runs on test_CT {
7223 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7224 var ASP_RSL_Unitdata ud;
7225 timer T;
7226
7227 /* Intave is 6 SACCH periods by default */
7228 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7229
7230 T.start(Tval);
7231 alt {
7232 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7233 setverdict(pass);
7234 }
7235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7236 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7237 }
7238 [] RSL_CCHAN.receive { repeat; }
7239 [] T.timeout {
7240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7241 "Timeout waiting for RF RESource INDication");
7242 }
7243 }
7244}
7245testcase TC_rsl_rf_resource_ind() runs on test_CT {
7246 var RSL_ResourceInfo info := { };
7247
7248 f_init(trx_nr := 0);
7249
7250 f_init_l1ctl();
7251 f_l1_tune(L1CTL);
7252
7253 /* g_AllChannels contains all logical channels */
7254 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7255 var RslChannelNr chan_nr := g_AllChannels[i];
7256
7257 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7258 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7259 { continue; }
7260
7261 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7262 }
7263
7264 /* Align to the first interference report */
7265 f_TC_rsl_rf_resource_ind(?);
7266
7267 /* Test 4 consecutive messages */
7268 for (var integer i := 0; i < 4; i := i + 1) {
7269 f_TC_rsl_rf_resource_ind(info);
7270 }
7271
7272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7273}
7274
Harald Weltee613f962018-04-18 22:38:16 +02007275/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007276private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007277 /* L3 payload doesn't matter, as it is passed transparently */
7278 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7279 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7280 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7281
7282 f_l1_tune(L1CTL);
7283
7284 /* first establish a dedicated channel in the clear */
7285 f_est_dchan(false);
7286
7287 /* Establish ABM */
7288 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7289
7290 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7291 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7292 /* expect the L3 to arrive still unencrypted on the MS side */
7293 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7294
7295 /* configure L1 to apply ciphering */
7296 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7297 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7298
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007299 /* send first ciphered I-frame in response and expect it on RSL */
7300 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007301
7302 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7303 * and hence enable encryption also on the downlink */
7304
7305 /* expect bi-directional communication work in encrypted mode */
7306 f_unitdata_mo(link_id, f_rnd_octstring(15));
7307 f_unitdata_mt(link_id, f_rnd_octstring(15));
7308
7309 /* release the channel */
7310 f_rsl_chan_deact();
7311 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7312 f_rslem_unregister(0, g_chan_nr);
7313}
7314testcase TC_encr_cmd_a51() runs on test_CT {
7315 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7316 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7317 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7318}
7319testcase TC_encr_cmd_a52() runs on test_CT {
7320 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7321 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7322 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7323}
7324testcase TC_encr_cmd_a53() 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_3, f_rnd_octstring(8)));
7327 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7328}
Eric Wildb9260392021-05-15 19:48:22 +02007329testcase TC_encr_cmd_a54() 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_4, f_rnd_octstring(16)));
7332 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7333}
Harald Weltee613f962018-04-18 22:38:16 +02007334
7335private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7336 var LapdmFrame lf;
7337 var octetstring reenc;
7338
7339 /* decode the LAPDm frame */
7340 if (ischosen(exp_match.ab)) {
7341 lf.ab := dec_LapdmFrameAB(enc);
7342 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007344 }
7345
7346 /* check if decoder result matches expectation */
7347 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007349 } else {
7350 log(name, ": matched");
7351 setverdict(pass);
7352 }
7353
7354 /* test if re-encoded frame equals original input */
7355 reenc := enc_LapdmFrame(lf);
7356 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007358 } else {
7359 setverdict(pass);
7360 }
7361}
7362
7363testcase TC_lapdm_selftest() runs on test_CT {
7364 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7365 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7366 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7367 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7368 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7369 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7370 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7371}
7372
Stefan Sperling4880be42018-08-07 18:12:59 +02007373/***********************************************************************
7374 * DTX Related (see GSM 05.08, section 8.3)
7375 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007376private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007377 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007378 var GsmFrameNumber first_fn;
7379 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007380 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007381 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007382 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7383 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007384 const integer frame_dtx_tchf_mod := 104;
7385 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7386 * which operates in terms of blocks rather than frames. */
7387 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7388 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007389 timer T := 5.0;
7390
7391 f_l1_tune(L1CTL);
7392 RSL.clear;
7393 L1CTL.clear;
7394
7395 /* activate TCHF signalling channel */
7396 f_est_dchan(false);
7397
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007398 /* A template for matching dummy LAPDm func=UA frames */
7399 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7400 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7401 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7402
Stefan Sperling4880be42018-08-07 18:12:59 +02007403 T.start;
7404 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007405 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007406 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007407
7408 if (is_first_frame) {
7409 is_first_frame := false;
7410 first_fn := dl.dl_info.frame_nr;
7411 }
7412
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007413 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007414 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007415 T.stop;
7416 f_rsl_chan_deact();
7417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007418
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007419 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7420 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007421
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007422 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007423 setverdict(fail, "Not enough fill frames received: ",
7424 nfill_frames, " out of ", expected_fill_frames);
7425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007426 } else {
7427 setverdict(pass);
7428 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007429 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007430 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7431 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7432 * we should only see the subset of frames numbers which correspond to a block boundary.
7433 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7434 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7435 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007436 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007437 repeat;
7438 }
7439 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007440 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7441 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7442 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007443 f_rsl_chan_deact();
7444 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007445 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007446 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007447 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007448 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007449 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007450
7451 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007452 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7453 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007454 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7455 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7456 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007457 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7458 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007459 case else {
7460 /* This shall not happen, just to be sure */
7461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7462 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007463 }
7464
7465 f_rsl_chan_deact();
7466 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007467
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007468 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007469 setverdict(pass);
7470 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007471 setverdict(fail, "Not enough fill frames received: ",
7472 nfill_frames, " out of ", expected_fill_frames);
7473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007474 }
7475 } else {
7476 repeat;
7477 }
7478 }
7479 }
7480 [] L1CTL.receive { repeat; }
7481 [] T.timeout {
7482 f_rsl_chan_deact();
7483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007485 }
7486 }
7487}
7488
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007489private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007490 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007491 var ConnHdlr vc_conn;
7492 var ConnHdlrPars pars;
7493 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007494 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007495 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007496 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007497 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007498 if (dtxd) {
7499 if (i >= 4) { /* DTX is only allowed on TCH/F */
7500 break;
7501 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007502 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007503 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007504 vc_conn.done;
7505 }
7506}
7507
7508/* Verify that L2 fill frames are sent on TCH in signaling mode if
7509 * there is nothing to transmit while DTX is disabled on downlink. */
7510testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7511 f_tch_sign_l2_fill_frame(false);
7512}
7513
7514/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7515 * there is nothing to transmit while DTX is enabled on downlink. */
7516testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7517 f_tch_sign_l2_fill_frame(true);
7518}
Harald Welte0472ab42018-03-12 15:02:26 +01007519
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007520testcase TC_chopped_ipa_ping() runs on test_CT {
7521 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7522}
7523
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007524testcase TC_chopped_ipa_payload() runs on test_CT {
7525 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7526}
7527
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007528
7529/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7530 * Return value: Measurement Report to be sent (encoded octetstring). */
7531type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7532 runs on ConnHdlr return octetstring;
7533
7534private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7535runs on ConnHdlr {
7536 var L1ctlDlMessage l1_dl;
7537 var SacchL1Header l1h;
7538 var octetstring l2;
7539
7540 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7541 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7542 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7543 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7544
7545 /* Pass it to the user specified call-back function */
7546 l2 := cb.apply(l1h, num_blocks);
7547 /* Send a Measurement Report generated by the call-back */
7548 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7549 l1_dl.dl_info.link_id,
7550 l1h, l2));
7551
7552 /* Shall we keep going? */
7553 num_blocks := num_blocks - 1;
7554 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7555 if (num_blocks > 0) { repeat; }
7556 }
7557 [] L1CTL.receive { repeat; }
7558}
7559
7560private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7561runs on ConnHdlr return octetstring {
7562 /* Command the L1 to apply received parameters */
7563 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7564
7565 /* Dummy measurement report (the results are invalid) */
7566 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7567}
7568
7569private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7570runs on ConnHdlr return octetstring {
7571 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7572 setverdict(fail, "Unexpected MS Power level change: ",
7573 g_pars.l1_pars.ms_power_level, " -> ",
7574 l1h.ms_power_lvl);
7575 }
7576
7577 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7578}
7579
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007580private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7581runs on ConnHdlr return octetstring {
7582 /* UL RSSI oscillation driven by SACCH block number */
7583 if (num_blocks rem 2 == 0) {
7584 f_trxc_fake_rssi(-100);
7585 } else {
7586 f_trxc_fake_rssi(-50);
7587 }
7588
7589 /* Make sure that MS power level remains constant */
7590 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7591}
7592
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007593/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7594private function f_TC_ms_pwr_ctrl_constant(charstring id)
7595runs on ConnHdlr {
7596 var integer num_blocks := 8;
7597 timer T := int2float(num_blocks);
7598
7599 f_l1_tune(L1CTL);
7600 RSL.clear;
7601
7602 /* These IEs are needed for autonomous MS power control */
7603 var template (value) RSL_IE_List ies := {
7604 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7605 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7606 }),
7607 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7608 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7609 })
7610 };
7611
7612 /* Ensure that 'rx-current' equals 'rx-target' */
7613 f_trxc_fake_rssi(mp_uplink_power_target);
7614
7615 /* Establish a dedicated channel */
7616 f_est_dchan(more_ies := valueof(ies));
7617
7618 L1CTL.clear;
7619 T.start;
7620 alt {
7621 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7622 [] T.timeout {
7623 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7624 num_blocks, " were not handled");
7625 }
7626 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007627
7628 /* Release the channel */
7629 f_rsl_chan_deact();
7630 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007631}
7632testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7633 var ConnHdlr vc_conn;
7634 var ConnHdlrPars pars;
7635
7636 f_init();
7637
7638 /* Explicitly configure the Uplink power target (in dBm) */
7639 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7640
7641 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7642 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7643 log(testcasename(), ": starting on ", pars.chan_nr);
7644
7645 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7646 pars, trxc_comp := true);
7647 vc_conn.done;
7648 }
7649
7650 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7652}
7653
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007654/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7655private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7656runs on ConnHdlr {
7657 var integer num_blocks := 16;
7658 timer T := int2float(num_blocks);
7659
7660 f_l1_tune(L1CTL);
7661 RSL.clear;
7662
7663 /* These IEs are needed for autonomous MS power control */
7664 var template (value) RSL_IE_List ies := {
7665 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7666 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7667 }),
7668 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7669 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7670 })
7671 };
7672
7673 /* Ensure that 'rx-current' equals 'rx-target' */
7674 f_trxc_fake_rssi(mp_uplink_power_target);
7675
7676 /* Establish a dedicated channel */
7677 f_est_dchan(more_ies := valueof(ies));
7678
7679 L1CTL.clear;
7680 T.start;
7681 alt {
7682 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7683 [] T.timeout {
7684 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7685 num_blocks, " were not handled");
7686 }
7687 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007688
7689 /* Release the channel */
7690 f_rsl_chan_deact();
7691 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007692}
7693testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7694 var ConnHdlr vc_conn;
7695 var ConnHdlrPars pars;
7696
7697 f_init();
7698
7699 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7700 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7701 /* Explicitly configure the Uplink power range (target and delte) */
7702 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7703 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7704
7705 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7706 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7707 log(testcasename(), ": starting on ", pars.chan_nr);
7708
7709 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7710 pars, trxc_comp := true);
7711 vc_conn.done;
7712 }
7713
7714 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7716}
7717
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007718private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7719 var template L1ctlDlMessage tr_bad_frame;
7720 var L1ctlDlMessage l1_dl;
7721 timer T := 8.0;
7722
7723 f_l1_tune(L1CTL);
7724 RSL.clear;
7725
7726 f_est_dchan();
7727
7728 /* There may be a few errors right after the channel activation */
7729 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7730 L1CTL.clear;
7731
7732 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7733 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7734 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7735 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7736 tr_bad_frame.payload := ?;
7737
7738 T.start;
7739 alt {
7740 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7741 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7742 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7743 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7744 }
7745 [] as_l1_sacch();
7746 [] L1CTL.receive { repeat; }
7747 [] T.timeout {
7748 /* We're done, break the loop */
7749 setverdict(pass);
7750 }
7751 }
7752
7753 f_rsl_chan_deact();
7754 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7755}
7756testcase TC_speech_no_rtp_tchf() runs on test_CT {
7757 var ConnHdlr vc_conn;
7758 var ConnHdlrPars pars;
7759
7760 f_init();
7761
7762 /* TS1, TCH/F, V1 (FR codec) */
7763 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7764 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7765 vc_conn.done;
7766}
7767testcase TC_speech_no_rtp_tchh() runs on test_CT {
7768 var ConnHdlr vc_conn;
7769 var ConnHdlrPars pars;
7770
7771 f_init();
7772
7773 /* TS5, TCH/H, V1 (HR codec) */
7774 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7775 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7776 vc_conn.done;
7777}
7778
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007779/* Verify handling of Downlink and Uplink speech frames */
7780private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7781 var L1ctlDlMessage l1_dl;
7782 var PDU_RTP rtp_pdu;
7783 var octetstring pl;
7784 timer Td, Tu;
7785
7786 f_l1_tune(L1CTL);
7787 f_est_dchan();
7788
7789 /* Activate the RTP emulation */
7790 pl := f_rnd_octstring(6);
7791 f_rtpem_activate(pl);
7792
7793 /* Give the scheduler some time to fill up the buffers */
7794 f_sleep(2.0);
7795 L1CTL.clear;
7796 RSL.clear;
7797
7798 /* Make sure that Downlink frames are received at the UE */
7799 Td.start(2.0);
7800 alt {
7801 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7802 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7803 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7804 l1_dl.payload.traffic_ind.data));
7805 setverdict(pass);
7806 }
7807 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7808 setverdict(fail, "Rx unexpected Downlink speech frame ",
7809 "(", l1_dl.payload.traffic_ind.data, ") ",
7810 "expected (", pl, ")");
7811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7812 }
7813 [] as_l1_sacch();
7814 [] L1CTL.receive { repeat; }
7815 [] Td.timeout {
7816 setverdict(fail, "Timeout waiting for Downlink speech frames");
7817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7818 }
7819 }
7820
7821 /* Make sure that Uplink frames are received at the BTS */
7822 RTPEM_DATA.clear;
7823 Tu.start(2.0);
7824 alt {
7825 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7826 if (rtp_pdu.data != pl)
7827 { repeat; }
7828 }
7829 [] RTPEM_DATA.receive { repeat; }
7830 [] Tu.timeout {
7831 setverdict(fail, "Timeout waiting for Uplink speech frames");
7832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7833 }
7834 }
7835
7836 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7837 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7838 f_rsl_chan_deact();
7839 f_rslem_unregister(0, g_chan_nr);
7840}
7841testcase TC_speech_rtp_tchf() runs on test_CT {
7842 var ConnHdlr vc_conn;
7843 var ConnHdlrPars pars;
7844
7845 f_init();
7846
7847 /* TS1, TCH/F, V1 (FR codec) */
7848 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7849 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7850 vc_conn.done;
7851
7852 /* TS1, TCH/F, V2 (EFR codec) */
7853 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7854 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7855 vc_conn.done;
7856
7857 /* TODO: also test V3 (AMR codec) */
7858
7859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7860}
7861testcase TC_speech_rtp_tchh() runs on test_CT {
7862 var ConnHdlr vc_conn;
7863 var ConnHdlrPars pars;
7864
7865 f_init();
7866
7867 /* TS5, TCH/H0, V1 (HR codec) */
7868 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7869 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7870 vc_conn.done;
7871
7872 /* TODO: also test V3 (AMR codec) */
7873
7874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7875}
7876
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007877private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7878 var GsmFrameNumber fn;
7879 var ChannelDescription ch_desc;
7880 var integer ra := 23;
7881
7882 f_l1_tune(L1CTL);
7883 RSL.clear;
7884
7885 /* Send RACH request and wait for ChanReq */
7886 fn := f_rach_req_wait_chan_rqd(ra);
7887
7888 /* The BSC already sends the Immediate Assignment, before the channel is active.
7889 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7890 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7891 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7892 if (g_pars.fhp.enabled) {
7893 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7894 } else {
7895 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7896 }
7897 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7898 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7899
7900 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7901 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7902 var L1ctlDlMessage dl;
7903 var GsmRrMessage rr;
7904
7905 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7906 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7907 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7908 rr_imm_ass.payload.imm_ass.chan_desc := *;
7909
7910 timer T := 1.0;
7911 T.start;
7912 alt {
7913 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7914 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7915 if (match(rr, rr_imm_ass)) {
7916 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7917 mtc.stop;
7918 } else {
7919 repeat;
7920 }
7921 }
7922 [] L1CTL.receive { repeat; }
7923 [] T.timeout;
7924 }
7925 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7926 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7927
7928 /* Now expect the IMM ASS on Um */
7929 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7930 setverdict(pass);
7931
7932 /* Release the channel */
7933 f_rsl_chan_deact();
7934 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7935}
7936
7937testcase TC_early_immediate_assignment() runs on test_CT {
7938 var ConnHdlr vc_conn;
7939 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7940 f_init();
7941 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
7942 vc_conn.done;
7943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7944}
7945
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007946private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
7947 var integer ra := oct2int(f_rnd_ra_cs());
7948 var ChannelDescription ch_desc;
7949
7950 /* Tune the MS to BCCH */
7951 f_l1_tune(L1CTL);
7952
7953 /* Send RACH request and wait for ChanReq */
7954 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
7955
7956 /* Activate channel on the BTS side */
7957 f_rsl_chan_act(g_pars.chan_mode);
7958
7959 /* Craft channel description (with or without frequency hopping parameters) */
7960 if (g_pars.fhp.enabled) {
7961 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7962 } else {
7963 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7964 }
7965
7966 /* Send IMM.ASS via CCHAN */
7967 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7968 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7969
7970 /* Receive IMM.ASS on the MS side */
7971 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7972
7973 /* Match the Channel Description IE in received IMM.ASS */
7974 if (not match(imm_ass.chan_desc, ch_desc)) {
7975 setverdict(fail, "Channel Description IE does not match");
7976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7977 }
7978
7979 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
7980 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
7981
7982 /* Expect SACCH frames on Downlink */
7983 L1CTL.clear;
7984 f_exp_sacch(true);
7985
7986 /* We're done, deactivate and release */
7987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7988 f_rsl_chan_deact();
7989}
7990testcase TC_est_dchan() runs on test_CT {
7991 var ConnHdlr vc_conn;
7992 var ConnHdlrPars pars;
7993
7994 f_init();
7995
7996 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
7997 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
7998 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
7999 vc_conn.done;
8000 }
8001
8002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8003}
8004
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008005private type record TopTestCase {
8006 RSL_IE_BS_Power bs_power,
8007 RSL_IE_OSMO_TopAcchCap top_cap,
8008 record of TopTestStep steps
8009};
8010private type record TopTestStep {
8011 MeasurementResults meas_res optional,
8012 GsmRxLev overpower_sacch,
8013 GsmRxLev overpower_facch
8014};
8015
8016private function f_rxlev_match(template (present) RslLinkId link_id,
8017 template (present) GsmRxLev rxlev)
8018runs on ConnHdlr {
8019 var L1ctlDlMessage dl := f_L1CTL_rx_data(L1CTL, g_chan_nr, link_id);
8020 if (not match(dl.dl_info.rx_level, rxlev)) {
8021 setverdict(fail, "RxLev(", link_id, ") := ", dl.dl_info.rx_level,
8022 " does not match expected RxLev := ", rxlev);
8023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8024 }
8025}
8026
8027private function f_TC_acch_overpower(charstring id) runs on ConnHdlr {
8028 var TopTestCase tc := g_pars.spec.top;
8029 var GsmRxLev rxlev_dcch;
8030 var L1ctlDlMessage dl;
8031
8032 /* Wait for Pau ramping to complete */
8033 f_sleep(6.0);
8034
8035 f_l1_tune(L1CTL);
8036 L1CTL.clear;
8037 RSL.clear;
8038
8039 /* Measure RxLev(BCCH), calculate RxLev(DCCH) */
8040 dl := f_L1CTL_rx_data(L1CTL, t_RslChanNr_BCCH(0));
8041 rxlev_dcch := dl.dl_info.rx_level - (tc.bs_power.power_level * 2);
8042
8043 log("RxLev(BCCH) := ", dl.dl_info.rx_level);
8044 log("Expected RxLev(DCCH) := ", rxlev_dcch);
8045
8046 /* Additional IEs for the CHANnel ACTIVation message */
8047 var template (value) RSL_IE_List ies := {
8048 /* Employ BS power control in static mode */
8049 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
8050 bs_power := tc.bs_power
8051 }),
8052 /* Indicate the given Temporary Overpower capability */
8053 t_RSL_IE(RSL_IE_OSMO_TOP_ACCH_CAP, RSL_IE_Body:{
8054 top_acch_cap := tc.top_cap
8055 })
8056 };
8057
8058 /* Establish a dedicated channel */
8059 f_est_dchan(more_ies := valueof(ies));
8060
8061 /* Give it some time to stabilize */
8062 f_sleep(0.480 * 2.0);
8063 L1CTL.clear;
8064 RSL.clear;
8065
8066 for (var integer i := 0; i < lengthof(tc.steps); i := i + 1) {
8067 var TopTestStep step := tc.steps[i];
8068 var GsmRxLev rxlev_facch := rxlev_dcch + step.overpower_facch;
8069 var GsmRxLev rxlev_sacch := rxlev_dcch + step.overpower_sacch;
8070
8071 log("Executing step[", i, "] := ", step);
8072
8073 /* Send RR Measurement Report (if present) */
8074 if (ispresent(step.meas_res)) {
8075 f_transceive_meas_rep(step.meas_res);
8076 f_sleep(0.480 * 2.0);
8077 L1CTL.clear;
8078 }
8079
8080 /* Check RxLev on both FACCH and SACCH */
8081 f_rxlev_match(tr_RslLinkID_DCCH(?), rxlev_facch);
8082 f_rxlev_match(tr_RslLinkID_SACCH(?), rxlev_sacch);
8083
8084 setverdict(pass);
8085 }
8086}
8087testcase TC_acch_overpower_rxqual_thresh() runs on test_CT {
8088 var ConnHdlrPars pars;
8089 var ConnHdlr vc_conn;
8090
8091 f_init();
8092
8093 /* Verify lower and upper RxQual thresholds */
8094 var template TopTestCase top := {
8095 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8096 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8097 steps := {
8098 /* Channel established, no overpower */
8099 { meas_res := omit,
8100 overpower_sacch := 0, overpower_facch := 0 },
8101
8102 /* Worst possible RxQual value, overpower of 4dB */
8103 { meas_res := ts_MeasurementResults(rxq_f := 7),
8104 overpower_sacch := 4, overpower_facch := 4 },
8105 /* Worst possible RxQual value, disabling overpower */
8106 { meas_res := ts_MeasurementResults(rxq_f := 0),
8107 overpower_sacch := 0, overpower_facch := 0 },
8108
8109 /* Lower threshold not reached, no overpower */
8110 { meas_res := ts_MeasurementResults(rxq_f := 1),
8111 overpower_sacch := 0, overpower_facch := 0 },
8112 /* Lower threshold not reached, no overpower */
8113 { meas_res := ts_MeasurementResults(rxq_f := 2),
8114 overpower_sacch := 0, overpower_facch := 0 },
8115 /* Lower threshold reached, overpower of 4dB */
8116 { meas_res := ts_MeasurementResults(rxq_f := 4),
8117 overpower_sacch := 4, overpower_facch := 4 },
8118 /* Upper threshold not reached, keeping overpower */
8119 { meas_res := ts_MeasurementResults(rxq_f := 3),
8120 overpower_sacch := 4, overpower_facch := 4 },
8121 /* Upper threshold reached, disabling overpower */
8122 { meas_res := ts_MeasurementResults(rxq_f := 2),
8123 overpower_sacch := 0, overpower_facch := 0 }
8124 }
8125 };
8126
8127 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8128 spec := { top := top }, trx_nr := 1));
8129 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8130 vc_conn.done;
8131
8132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8133}
8134testcase TC_acch_overpower_rxqual_thresh_dtx() runs on test_CT {
8135 var ConnHdlrPars pars;
8136 var ConnHdlr vc_conn;
8137
8138 f_init();
8139
8140 /* Verify handling of FULL and SUB values */
8141 var template TopTestCase top := {
8142 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8143 top_cap := ts_RSL_IE_OSMO_TopAcchCap(4), /* 4dB */
8144 steps := {
8145 /* Channel established, no overpower */
8146 { meas_res := omit,
8147 overpower_sacch := 0, overpower_facch := 0 },
8148
8149 /* Invalid measurement results, no overpower */
8150 { meas_res := ts_MeasurementResults(rxq_f := 7,
8151 rxq_s := 7,
8152 valid := false),
8153 overpower_sacch := 0, overpower_facch := 0 },
8154
8155 /* DTXu was in use, no overpower */
8156 { meas_res := ts_MeasurementResults(rxq_f := 7,
8157 rxq_s := 0,
8158 dtx_used := true),
8159 overpower_sacch := 0, overpower_facch := 0 },
8160 /* DTXu was in use, overpower of 4 dB */
8161 { meas_res := ts_MeasurementResults(rxq_f := 0,
8162 rxq_s := 7,
8163 dtx_used := true),
8164 overpower_sacch := 4, overpower_facch := 4 }
8165 }
8166 };
8167
8168 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8169 spec := { top := top }, trx_nr := 1));
8170 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8171 vc_conn.done;
8172
8173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8174}
8175testcase TC_acch_overpower_always_on_facch() runs on test_CT {
8176 var ConnHdlrPars pars;
8177 var ConnHdlr vc_conn;
8178
8179 f_init();
8180
8181 /* Overpower is always on, SACCH disabled */
8182 var template TopTestCase top := {
8183 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8184 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8185 rxqual := 0, /* always on */
8186 sacch_enable := false),
8187 steps := {
8188 /* Channel established, FACCH overpower */
8189 { meas_res := omit,
8190 overpower_sacch := 0, overpower_facch := 4 },
8191 /* MS indicates good RxQual, no difference */
8192 { meas_res := ts_MeasurementResults(rxq_f := 0),
8193 overpower_sacch := 0, overpower_facch := 4 },
8194 /* MS indicates bad RxQual, no difference */
8195 { meas_res := ts_MeasurementResults(rxq_f := 7),
8196 overpower_sacch := 0, overpower_facch := 4 }
8197 }
8198 };
8199
8200 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8201 spec := { top := top }, trx_nr := 1));
8202 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8203 vc_conn.done;
8204
8205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8206}
8207testcase TC_acch_overpower_always_on_sacch() runs on test_CT {
8208 var ConnHdlrPars pars;
8209 var ConnHdlr vc_conn;
8210
8211 f_init();
8212
8213 /* Overpower is always on, FACCH disabled */
8214 var template TopTestCase top := {
8215 bs_power := ts_RSL_IE_BS_Power(4), /* 4 x 2dB = 8dB */
8216 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8217 rxqual := 0, /* always on */
8218 facch_enable := false),
8219 steps := {
8220 /* Channel established, SACCH overpower */
8221 { meas_res := omit,
8222 overpower_sacch := 4, overpower_facch := 0 },
8223 /* MS indicates good RxQual, no difference */
8224 { meas_res := ts_MeasurementResults(rxq_f := 0),
8225 overpower_sacch := 4, overpower_facch := 0 },
8226 /* MS indicates bad RxQual, no difference */
8227 { meas_res := ts_MeasurementResults(rxq_f := 7),
8228 overpower_sacch := 4, overpower_facch := 0 }
8229 }
8230 };
8231
8232 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8233 spec := { top := top }, trx_nr := 1));
8234 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8235 vc_conn.done;
8236
8237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8238}
8239testcase TC_acch_overpower_limit() runs on test_CT {
8240 var ConnHdlrPars pars;
8241 var ConnHdlr vc_conn;
8242
8243 f_init();
8244
8245 /* Overpower higher than current power reduction level (2dB) */
8246 var template TopTestCase top := {
8247 bs_power := ts_RSL_IE_BS_Power(1), /* 1 x 2dB = 2dB */
8248 top_cap := ts_RSL_IE_OSMO_TopAcchCap(overpower := 4, /* 4dB */
8249 rxqual := 0 /* always on */),
8250 steps := {
8251 /* Channel established, ACCH overpower of 2dB */
8252 { meas_res := omit,
8253 overpower_sacch := 2, overpower_facch := 2 },
8254 /* MS indicates good RxQual, no difference */
8255 { meas_res := ts_MeasurementResults(rxq_f := 0),
8256 overpower_sacch := 2, overpower_facch := 2 },
8257 /* MS indicates bad RxQual, no difference */
8258 { meas_res := ts_MeasurementResults(rxq_f := 7),
8259 overpower_sacch := 2, overpower_facch := 2 }
8260 }
8261 };
8262
8263 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN,
8264 spec := { top := top }, trx_nr := 1));
8265 vc_conn := f_start_handler(refers(f_TC_acch_overpower), pars);
8266 vc_conn.done;
8267
8268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
8269}
8270
Harald Welte0472ab42018-03-12 15:02:26 +01008271/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
8272/* protocol error as per 44.006 */
8273/* link layer failure (repetition of I-frame N200 times without ACK */
8274/* repetition of SABM or DISC N200 times without ACK */
8275/* receptiom of SABM in multi-frame established state */
8276
8277
Harald Welte68e495b2018-02-25 00:05:57 +01008278/* TODO Areas:
8279
8280* channel activation
8281** with BS_Power / MS_Power, bypassing power control loop
8282** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01008283** with timing advance from initial activation on
8284* mode modify
8285** encryption
8286** multirate
8287* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01008288** unsupported algorithm
8289* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01008290* BS Power Control
8291* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01008292* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01008293* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01008294** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01008295* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01008296** DATA_IND from BTS->PCU
8297** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01008298
8299*/
Harald Welte70767382018-02-21 12:16:40 +01008300
8301control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06008302 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01008303 execute( TC_chan_act_stress() );
8304 execute( TC_chan_act_react() );
8305 execute( TC_chan_deact_not_active() );
8306 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01008307 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01008308 execute( TC_sacch_filling() );
8309 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01008310 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01008311 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02008312 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02008313 execute( TC_sacch_chan_act_ho_async() );
8314 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008315 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008316 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008317 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008318 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008319 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008320 execute( TC_rach_load_idle_thresh0() );
8321 execute( TC_rach_load_idle_below_thresh() );
8322 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008323 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008324 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008325 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008326 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008327 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008328 execute( TC_meas_res_sign_tchf() );
8329 execute( TC_meas_res_sign_tchh() );
8330 execute( TC_meas_res_sign_sdcch4() );
8331 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008332 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008333 execute( TC_meas_res_speech_tchf_sapi3() );
8334 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008335 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008336 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008337 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008338 execute( TC_rsl_bs_pwr_static_ass() );
8339 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008340 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008341 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008342 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008343 execute( TC_rsl_ms_pwr_dyn_up() );
8344 execute( TC_rsl_ms_pwr_dyn_down() );
8345 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8346 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008347 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008348 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008349 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008350 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008351 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008352 execute( TC_paging_imsi_80percent() );
8353 execute( TC_paging_tmsi_80percent() );
8354 execute( TC_paging_imsi_200percent() );
8355 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008356 execute( TC_rsl_protocol_error() );
8357 execute( TC_rsl_mand_ie_error() );
8358 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008359 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008360 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008361 execute( TC_si_sched_2bis() );
8362 execute( TC_si_sched_2ter() );
8363 execute( TC_si_sched_2ter_2bis() );
8364 execute( TC_si_sched_2quater() );
8365 execute( TC_si_sched_13() );
8366 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008367 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008368 execute( TC_ipa_crcx_twice_not_active() );
8369 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008370 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008371 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008372
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008373 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008374 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008375 execute( TC_pcu_act_req() );
8376 execute( TC_pcu_act_req_wrong_ts() );
8377 execute( TC_pcu_act_req_wrong_bts() );
8378 execute( TC_pcu_act_req_wrong_trx() );
8379 execute( TC_pcu_deact_req() );
8380 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008381 execute( TC_pcu_ver_si1() );
8382 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008383 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008384 if (mp_l1_supports_gprs) {
8385 execute( TC_pcu_data_req_pdtch() );
8386 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008387 execute( TC_pcu_data_req_wrong_bts() );
8388 execute( TC_pcu_data_req_wrong_trx() );
8389 execute( TC_pcu_data_req_wrong_ts() );
8390 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008391 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008392 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008393 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008394 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008395 execute( TC_pcu_data_req_imm_ass_pch() );
8396 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008397 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008398 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008399 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008400 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008401 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008402 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008403 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008404 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008405 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008406 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008407 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008408 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008409 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008410 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008411 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008412 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008413 execute( TC_dyn_osmo_pdch_act_deact() );
8414 execute( TC_dyn_osmo_pdch_double_act() );
8415 execute( TC_dyn_ipa_pdch_act_deact() );
8416 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008417 execute( TC_pcu_info_ind_fh_params() );
8418 execute( TC_pcu_socket_nsvc_ipv4() );
8419 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008420 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008421 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008422 } else {
8423 log("PCU socket path not available, skipping PCU tests");
8424 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008425
Harald Welte3d04ae62018-04-04 20:29:05 +02008426 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008427 execute( TC_dyn_osmo_pdch_tchf_act() );
8428 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008429 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008430 execute( TC_dyn_ipa_pdch_tchf_act() );
8431 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008432
8433 execute( TC_rll_est_ind() );
8434 execute( TC_rll_est_req_DCCH_3() );
8435 execute( TC_rll_est_req_ACCH_3() );
8436 execute( TC_rll_rel_ind_DCCH_0() );
8437 execute( TC_rll_rel_ind_DCCH_3() );
8438 execute( TC_rll_rel_ind_ACCH_0() );
8439 execute( TC_rll_rel_ind_ACCH_3() );
8440 execute( TC_rll_rel_req() );
8441 execute( TC_rll_unit_data_req_DCCH() );
8442 execute( TC_rll_unit_data_req_ACCH() );
8443 execute( TC_rll_unit_data_ind_DCCH() );
8444 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008445
8446 execute( TC_chan_act_a51() );
8447 execute( TC_chan_act_a52() );
8448 execute( TC_chan_act_a53() );
8449 execute( TC_encr_cmd_a51() );
8450 execute( TC_encr_cmd_a52() );
8451 execute( TC_encr_cmd_a53() );
8452
Harald Welteee25aae2019-05-19 14:32:37 +02008453 execute( TC_err_rep_wrong_mdisc() );
8454 execute( TC_err_rep_wrong_msg_type() );
8455 execute( TC_err_rep_wrong_sequence() );
8456
Harald Weltee613f962018-04-18 22:38:16 +02008457 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008458
8459 execute( TC_tch_sign_l2_fill_frame() );
8460 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008461
8462 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008463 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008464
8465 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008466 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008467
8468 execute( TC_speech_no_rtp_tchf() );
8469 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008470 execute( TC_speech_rtp_tchf() );
8471 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008472
8473 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008474
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +03008475 execute( TC_acch_overpower_rxqual_thresh() );
8476 execute( TC_acch_overpower_rxqual_thresh_dtx() );
8477 execute( TC_acch_overpower_always_on_facch() );
8478 execute( TC_acch_overpower_always_on_sacch() );
8479 execute( TC_acch_overpower_limit() );
8480
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008481 /* BEWARE: these test cases can potentially break the IUT or cause
8482 * weird/unexpected behavior. Ensure that they are executed last. */
8483 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8484 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008485}
8486
8487
8488}